Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3e5c7a3

Browse files
author
Raj Seshasankaran
authored
Merge pull request #1309 from rajsesh-msft/cherry_pick_11_02
Cherry pick 11 02
2 parents 4bf6f6e + 4a5dbd6 commit 3e5c7a3

40 files changed

+393
-124
lines changed

Frameworks/CoreGraphics/CGBitmapImage.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@
389389
}
390390

391391
CGBitmapImageBacking::~CGBitmapImageBacking() {
392+
// release the render target first as it may hold locks on the image
393+
if (_renderTarget != nullptr) {
394+
_renderTarget->Release();
395+
}
396+
392397
if (_cairoLocks != 0 || _imageLocks != 0) {
393398
TraceWarning(TAG, L"Warning: Image data not unlocked (refcnt=%d, %d)", _cairoLocks, _imageLocks);
394399

@@ -400,10 +405,6 @@
400405
}
401406
}
402407

403-
if (_renderTarget != nullptr) {
404-
_renderTarget->Release();
405-
}
406-
407408
_data->_refCount--;
408409

409410
if (_data->_refCount == 0) {

Frameworks/CoreGraphics/CGContext.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,8 @@ bool CGContextIsPointInPath(CGContextRef c, bool eoFill, CGFloat x, CGFloat y) {
12391239
return c->Backing()->CGContextIsPointInPath(eoFill, x, y);
12401240
}
12411241

1242-
void CGContextDrawGlyphRun(CGContextRef ctx, const DWRITE_GLYPH_RUN* glyphRun, float lineAscent) {
1243-
ctx->Backing()->CGContextDrawGlyphRun(glyphRun, lineAscent);
1242+
void CGContextDrawGlyphRun(CGContextRef ctx, const DWRITE_GLYPH_RUN* glyphRun) {
1243+
ctx->Backing()->CGContextDrawGlyphRun(glyphRun);
12441244
}
12451245
// TODO 1077:: Remove once D2D render target is implemented
12461246
void _CGContextSetScaleFactor(CGContextRef ctx, float scale) {

Frameworks/CoreGraphics/CGContextCairo.mm

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@
18321832
*
18331833
* @parameter glyphRun DWRITE_GLYPH_RUN object to render
18341834
*/
1835-
void CGContextCairo::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun, float lineAscent) {
1835+
void CGContextCairo::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun) {
18361836
ObtainLock();
18371837

18381838
CGContextStrokePath();
@@ -1853,33 +1853,25 @@
18531853

18541854
// Apply the text transformation (text position, text matrix) in text space rather than user space
18551855
// This means flipping the coordinate system,
1856-
// and applying the transformation about the center of the glyph run rather than about the baseline
1857-
// Flip and translate by the difference between the center and the baseline, apply text transforms, then flip and translate back
1856+
// Apply text position, where it will be translated to correct position given text matrix value
1857+
CGAffineTransform textTransform =
1858+
CGAffineTransformTranslate(curState->curTextMatrix, curState->curTextPosition.x, curState->curTextPosition.y);
18581859

1859-
// Transform to text space
1860-
// Technically there should be a horizontal translation to the center as well,
1861-
// but it's to the center of _each individual glyph_, as the reference platform applies the text matrix to each glyph individually
1862-
// Uncertain whether it's ever going to be worth it to support this using DWrite, so just ignore it for now
1863-
CGAffineTransform transform = CGAffineTransformMake(1, 0, 0, -1, 0, -lineAscent / 2.0f);
1864-
1865-
// Apply text transforms
1866-
transform = CGAffineTransformConcat(curState->curTextMatrix, transform);
1867-
1868-
// Undo transform to text space
1869-
transform = CGAffineTransformConcat(CGAffineTransformMake(1, 0, 0, -1, 0, lineAscent / 2.0f), transform);
1870-
1871-
transform = CGAffineTransformTranslate(transform, curState->curTextPosition.x, curState->curTextPosition.y);
1860+
// Undo assumed inversion about Y axis
1861+
textTransform = CGAffineTransformConcat(CGAffineTransformMake(1, 0, 0, -1, 0, 0), textTransform);
18721862

18731863
// Find transform that user created by multiplying given transform by necessary transforms to draw with CoreText
1864+
// First multiply by inverse scale to get properly scaled values
1865+
// Then undo assumed inversion about Y axis
1866+
// Finally inverse translate by height
1867+
// All of which are rolled into one concatenation
18741868
float height = _imgDest->Backing()->Height();
18751869
CGAffineTransform userTransform =
1876-
CGAffineTransformConcat(curState->curTransform, CGAffineTransformMake(1.0f / _scale, 0, 0, 1.0f / _scale, 0, -height / _scale));
1877-
1878-
// Apply the context CTM
1879-
transform = CGAffineTransformConcat(transform, userTransform);
1870+
CGAffineTransformConcat(curState->curTransform, CGAffineTransformMake(1.0f / _scale, 0, 0, -1.0f / _scale, 0, height / _scale));
18801871

1881-
// Perform anti-clockwise rotation required to match the reference platform.
1882-
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, -transform.b, transform.c, transform.d, transform.tx, -transform.ty));
1872+
// Apply the two transforms giving us the final result
1873+
CGAffineTransform transform = CGAffineTransformConcat(textTransform, userTransform);
1874+
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty));
18831875

18841876
// Draw the glyph using ID2D1RenderTarget
18851877
ComPtr<ID2D1SolidColorBrush> brush;

Frameworks/CoreGraphics/CGContextImpl.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@
779779
return NULL;
780780
}
781781

782-
void CGContextImpl::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun, float lineAscent) {
782+
void CGContextImpl::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun) {
783783
}
784784

785785
// TODO 1077:: Remove once D2D render target is implemented

Frameworks/CoreText/CTFont.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,4 +902,31 @@ CFDataRef CTFontCopyTable(CTFontRef font, CTFontTableTag table, CTFontTableOptio
902902
CFTypeID CTFontGetTypeID() {
903903
static CFTypeID __kCTFontTypeID = _CFRuntimeRegisterClass(&__CTFontClass);
904904
return __kCTFontTypeID;
905+
}
906+
907+
// Private function for getting font weight for XAML
908+
DWRITE_FONT_WEIGHT _CTFontGetDWriteWeight(CTFontRef font) {
909+
ComPtr<IDWriteFontFace3> fontFace3;
910+
if (font && SUCCEEDED(font->_dwriteFontFace.As(&fontFace3))) {
911+
return fontFace3->GetWeight();
912+
}
913+
return DWRITE_FONT_WEIGHT_NORMAL;
914+
}
915+
916+
// Private function for getting font stretch for XAML
917+
DWRITE_FONT_STRETCH _CTFontGetDWriteStretch(CTFontRef font) {
918+
ComPtr<IDWriteFontFace3> fontFace3;
919+
if (font && SUCCEEDED(font->_dwriteFontFace.As(&fontFace3))) {
920+
return fontFace3->GetStretch();
921+
}
922+
return DWRITE_FONT_STRETCH_NORMAL;
923+
}
924+
925+
// Private function for getting font style for XAML
926+
DWRITE_FONT_STYLE _CTFontGetDWriteStyle(CTFontRef font) {
927+
ComPtr<IDWriteFontFace3> fontFace3;
928+
if (font && SUCCEEDED(font->_dwriteFontFace.As(&fontFace3))) {
929+
return fontFace3->GetStyle();
930+
}
931+
return DWRITE_FONT_STYLE_NORMAL;
905932
}

Frameworks/CoreText/CTFrame.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ void CTFrameDraw(CTFrameRef frameRef, CGContextRef ctx) {
122122
CGContextScaleCTM(ctx, 1.0f, -1.0f);
123123

124124
for (_CTLine* line in static_cast<id<NSFastEnumeration>>(frame->_lines)) {
125+
// Y position must be negative because the context is inverted
125126
CGContextSetTextPosition(ctx, line->_lineOrigin.x, -line->_lineOrigin.y);
126-
_CTLineDraw(static_cast<CTLineRef>(line), ctx, false);
127+
CTLineDraw(static_cast<CTLineRef>(line), ctx);
127128
}
128129

129130
// Restore CTM and Text Matrix to values before we modified them

Frameworks/CoreText/CTLine.mm

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,40 +215,28 @@ CTLineRef CTLineCreateJustifiedLine(CTLineRef line, CGFloat justificationFactor,
215215
return StubReturn();
216216
}
217217

218-
void _CTLineDraw(CTLineRef lineRef, CGContextRef ctx, bool adjustTextPosition) {
219-
if (!lineRef) {
218+
/**
219+
@Status Interoperable
220+
*/
221+
void CTLineDraw(CTLineRef lineRef, CGContextRef ctx) {
222+
if (lineRef == nil || ctx == nil) {
220223
return;
221224
}
222225

223226
_CTLine* line = static_cast<_CTLine*>(lineRef);
224-
CGPoint curTextPos = {};
225-
if (adjustTextPosition) {
226-
curTextPos = CGContextGetTextPosition(ctx);
227-
CGContextSetTextPosition(ctx, curTextPos.x, curTextPos.y + line->_relativeYOffset);
228-
}
229227

230228
for (size_t i = 0; i < [line->_runs count]; ++i) {
231229
_CTRun* curRun = [line->_runs objectAtIndex:i];
232230
if (i > 0) {
233231
// Adjusts x position relative to the last run drawn
234-
curTextPos = CGContextGetTextPosition(ctx);
232+
CGPoint curTextPos = CGContextGetTextPosition(ctx);
235233
CGContextSetTextPosition(ctx, curTextPos.x + curRun->_relativeXOffset, curTextPos.y);
236234
}
237235

238-
// Get height of the line so we draw with the correct baseline for each run
239-
CGFloat ascent;
240-
CTLineGetTypographicBounds(lineRef, &ascent, nullptr, nullptr);
241-
_CTRunDraw(static_cast<CTRunRef>(curRun), ctx, CFRange{}, false, ascent);
236+
CTRunDraw(static_cast<CTRunRef>(curRun), ctx, CFRange{});
242237
}
243238
}
244239

245-
/**
246-
@Status Interoperable
247-
*/
248-
void CTLineDraw(CTLineRef lineRef, CGContextRef ctx) {
249-
_CTLineDraw(lineRef, ctx, true);
250-
}
251-
252240
/**
253241
@Status Interoperable
254242
*/

Frameworks/CoreText/CTRun.mm

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,17 @@ CGRect CTRunGetImageBounds(CTRunRef run, CGContextRef context, CFRange range) {
268268
return StubReturn();
269269
}
270270

271-
void _CTRunDraw(CTRunRef run, CGContextRef ctx, CFRange textRange, bool adjustTextPosition, CGFloat lineAscent) {
271+
/**
272+
@Status Interoperable
273+
@Notes
274+
*/
275+
void CTRunDraw(CTRunRef run, CGContextRef ctx, CFRange textRange) {
272276
_CTRun* curRun = static_cast<_CTRun*>(run);
273277
if (!curRun || textRange.length < 0L || textRange.location < 0L ||
274278
textRange.location + textRange.length > curRun->_dwriteGlyphRun.glyphCount) {
275279
return;
276280
}
277281

278-
if (adjustTextPosition) {
279-
CGPoint curTextPos = CGContextGetTextPosition(ctx);
280-
CGContextSetTextPosition(ctx, curTextPos.x, curTextPos.y + curRun->_relativeYOffset);
281-
}
282-
283282
id fontColor = [curRun->_attributes objectForKey:(id)kCTForegroundColorAttributeName];
284283
if (fontColor == nil) {
285284
CFBooleanRef useContextColor =
@@ -294,27 +293,15 @@ void _CTRunDraw(CTRunRef run, CGContextRef ctx, CFRange textRange, bool adjustTe
294293

295294
if (textRange.location == 0L && (textRange.length == 0L || textRange.length == curRun->_dwriteGlyphRun.glyphCount)) {
296295
// Print the whole glyph run
297-
CGContextDrawGlyphRun(ctx, &curRun->_dwriteGlyphRun, lineAscent);
296+
CGContextDrawGlyphRun(ctx, &curRun->_dwriteGlyphRun);
298297
} else {
299298
if (textRange.length == 0L) {
300299
textRange.length = curRun->_dwriteGlyphRun.glyphCount - textRange.location;
301300
}
302301

303302
// Only print glyphs in range
304303
DWRITE_GLYPH_RUN runInRange = __GetGlyphRunForDrawingInRange(curRun->_dwriteGlyphRun, textRange);
305-
CGContextDrawGlyphRun(ctx, &runInRange, lineAscent);
306-
}
307-
}
308-
309-
/**
310-
@Status Interoperable
311-
@Notes
312-
*/
313-
void CTRunDraw(CTRunRef run, CGContextRef ctx, CFRange textRange) {
314-
if (run && ctx) {
315-
CGFloat ascent;
316-
CTRunGetTypographicBounds(run, {}, &ascent, nullptr, nullptr);
317-
_CTRunDraw(run, ctx, textRange, true, ascent);
304+
CGContextDrawGlyphRun(ctx, &runInRange);
318305
}
319306
}
320307

Frameworks/CoreText/DWriteWrapper_CoreText.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ bool _CloneDWriteGlyphRun(_In_ DWRITE_GLYPH_RUN const* src, _Out_ DWRITE_GLYPH_R
204204
for (size_t i = 0; i < [subString length]; i += attributeRange.length) {
205205
NSDictionary* attribs = [static_cast<NSAttributedString*>(string) attributesAtIndex:i + range.location
206206
longestEffectiveRange:&attributeRange
207-
inRange:{ i, [subString length] }];
207+
inRange:{ i + range.location, [subString length] }];
208208

209209
const DWRITE_TEXT_RANGE dwriteRange = { attributeRange.location, attributeRange.length };
210210

Frameworks/QuartzCore/CALayer.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ - (void)display {
574574
if (useVector) {
575575
// target = new CGVectorImage(width, height, _ColorBGR);
576576
} else {
577-
drawContext = _CGBitmapContextCreateWithFormat(width, height, _ColorBGR);
577+
drawContext = _CGBitmapContextCreateWithFormat(width, height, _ColorBGRX);
578578
}
579579
priv->drewOpaque = TRUE;
580580
} else {

0 commit comments

Comments
 (0)