aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-28 15:40:26 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-28 15:40:26 +0000
commit7c18351d1f9f8fe4c5cbebf1852cd4f7bb5e026f (patch)
treecd704d07bcb1cf1118ea4ebc2fd762e6606d0dff /src/ports
parent5889e309961b865fbb2c4ed7f704c315c005a63c (diff)
Better handling of bitmaps in DirectWrite.
R=reed@google.com Review URL: https://codereview.chromium.org/303773002 git-svn-id: http://skia.googlecode.com/svn/trunk@14915 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkFontHost_win_dw.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp
index e024b465aa..ea41d86209 100644
--- a/src/ports/SkFontHost_win_dw.cpp
+++ b/src/ports/SkFontHost_win_dw.cpp
@@ -741,31 +741,46 @@ SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface,
// If the scale is negative, this means the matrix will do the flip anyway.
SkScalar realTextSize = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
// Due to floating point math, the lower bits are suspect. Round carefully.
- SkScalar roundedTextSize = SkScalarRoundToScalar(realTextSize * 64.0f) / 64.0f;
- SkScalar gdiTextSize = SkScalarFloorToScalar(roundedTextSize);
+ SkScalar gdiTextSize = SkScalarRoundToScalar(realTextSize * 64.0f) / 64.0f;
if (gdiTextSize == 0) {
gdiTextSize = SK_Scalar1;
}
- bool hasBitmap = fRec.fFlags & SkScalerContext::kEmbeddedBitmapText_Flag &&
- hasBitmapStrike(typeface, SkScalarTruncToInt(gdiTextSize));
- bool axisAligned = isAxisAligned(fRec);
- bool isBiLevel = SkMask::kBW_Format == fRec.fMaskFormat || (hasBitmap && axisAligned);
+ bool bitmapRequested = SkToBool(fRec.fFlags & SkScalerContext::kEmbeddedBitmapText_Flag);
+ bool hasBitmap = false;
+ bool axisAlignedBitmap = false;
+ if (bitmapRequested) {
+ hasBitmap = hasBitmapStrike(typeface, SkScalarTruncToInt(gdiTextSize));
+ axisAlignedBitmap = isAxisAligned(fRec);
+ }
- if (isBiLevel) {
+ // If the user requested aliased, do so with aliased compatible metrics.
+ if (SkMask::kBW_Format == fRec.fMaskFormat) {
fTextSizeRender = gdiTextSize;
fRenderingMode = DWRITE_RENDERING_MODE_ALIASED;
fTextureType = DWRITE_TEXTURE_ALIASED_1x1;
fTextSizeMeasure = gdiTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
+
+ // If we can use a bitmap, use gdi classic rendering and measurement.
+ // This will not always provide a bitmap, but matches expected behavior.
+ } else if (hasBitmap && axisAlignedBitmap) {
+ fTextSizeRender = gdiTextSize;
+ fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC;
+ fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
+ fTextSizeMeasure = gdiTextSize;
+ fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
+
+ // If rotated but the horizontal text could have used a bitmap,
+ // render high quality rotated glyphs but measure using bitmap metrics.
} else if (hasBitmap) {
- // If rotated but the horizontal text would have used a bitmap,
- // render high quality rotated glyphs using the bitmap metrics.
fTextSizeRender = gdiTextSize;
fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
fTextSizeMeasure = gdiTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
+
+ // The normal case is to use natural symmetric rendering and linear metrics.
} else {
fTextSizeRender = realTextSize;
fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;