Skip to content

Commit

Permalink
Change CT/CG text rendering to default on DWRITE_RENDERING/MEASURING_…
Browse files Browse the repository at this point in the history
…MODE_GDI_NATURAL

Fixes microsoft#1594
  • Loading branch information
ms-jihua committed Jan 6, 2017
1 parent 56d9135 commit 0c6b8ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Frameworks/CoreGraphics/CGBitmapImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,20 @@
THROW_IF_FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &d2dFactory));
ComPtr<ID2D1RenderTarget> renderTarget;
THROW_IF_FAILED(d2dFactory->CreateWicBitmapRenderTarget(wicBitmap.Get(), D2D1::RenderTargetProperties(), &renderTarget));

ComPtr<IDWriteFactory> dwriteFactory;
THROW_IF_FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &dwriteFactory));
ComPtr<IDWriteRenderingParams> defaultTextRenderParams;
THROW_IF_FAILED(dwriteFactory->CreateRenderingParams(&defaultTextRenderParams));
ComPtr<IDWriteRenderingParams> textRenderParams;
THROW_IF_FAILED(dwriteFactory->CreateCustomRenderingParams(defaultTextRenderParams->GetClearTypeLevel(),
defaultTextRenderParams->GetEnhancedContrast(),
defaultTextRenderParams->GetGamma(),
defaultTextRenderParams->GetPixelGeometry(),
DWRITE_RENDERING_MODE_GDI_NATURAL,
&textRenderParams));
renderTarget->SetTextRenderingParams(textRenderParams.Get());

_renderTarget = renderTarget.Detach();
ReleaseImageData();
}
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/CoreGraphics/CGContextCairo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@
// Apply the two transforms giving us the final result
imgRenderTarget->SetTransform(
D2D1::Matrix3x2F(finalTransform.a, finalTransform.b, finalTransform.c, finalTransform.d, finalTransform.tx, finalTransform.ty));
imgRenderTarget->DrawGlyphRun(D2D1::Point2F(0, 0), glyphRun, brush.Get(), DWRITE_MEASURING_MODE_NATURAL);
imgRenderTarget->DrawGlyphRun(D2D1::Point2F(0, 0), glyphRun, brush.Get(), DWRITE_MEASURING_MODE_GDI_NATURAL);
} else {
// Text scaling and rotation apply to each glyph relative to its origin, so we must draw each glyph transformed independently
DWRITE_GLYPH_RUN individualGlyphRun{ glyphRun->fontFace,
Expand All @@ -1925,7 +1925,7 @@
for (uint32_t i = 0; i < glyphRun->glyphCount; ++i, ++(individualGlyphRun.glyphIndices)) {
CGAffineTransform transform = CGAffineTransformConcat(textTransform, userTransform);
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty));
imgRenderTarget->DrawGlyphRun(origin, &individualGlyphRun, brush.Get(), DWRITE_MEASURING_MODE_NATURAL);
imgRenderTarget->DrawGlyphRun(origin, &individualGlyphRun, brush.Get(), DWRITE_MEASURING_MODE_GDI_NATURAL);

// Uses glyphAdvances to move each glyph
userTransform = CGAffineTransformTranslate(userTransform, glyphRun->glyphAdvances[i], 0);
Expand Down
14 changes: 14 additions & 0 deletions Frameworks/CoreGraphics/CGGraphicBufferImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@
THROW_IF_FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &d2dFactory));
ComPtr<ID2D1RenderTarget> renderTarget;
THROW_IF_FAILED(d2dFactory->CreateWicBitmapRenderTarget(wicBitmap.Get(), D2D1::RenderTargetProperties(), &renderTarget));

ComPtr<IDWriteFactory> dwriteFactory;
THROW_IF_FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &dwriteFactory));
ComPtr<IDWriteRenderingParams> defaultTextRenderParams;
THROW_IF_FAILED(dwriteFactory->CreateRenderingParams(&defaultTextRenderParams));
ComPtr<IDWriteRenderingParams> textRenderParams;
THROW_IF_FAILED(dwriteFactory->CreateCustomRenderingParams(defaultTextRenderParams->GetClearTypeLevel(),
defaultTextRenderParams->GetEnhancedContrast(),
defaultTextRenderParams->GetGamma(),
defaultTextRenderParams->GetPixelGeometry(),
DWRITE_RENDERING_MODE_GDI_NATURAL,
&textRenderParams));
renderTarget->SetTextRenderingParams(textRenderParams.Get());

_renderTarget = renderTarget.Detach();
ReleaseImageData();
}
Expand Down

0 comments on commit 0c6b8ff

Please sign in to comment.