OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 #undef GetGlyphIndices | 9 #undef GetGlyphIndices |
10 | 10 |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 734 |
735 // GA is the matrix A with rotation removed. | 735 // GA is the matrix A with rotation removed. |
736 SkMatrix GA(G); | 736 SkMatrix GA(G); |
737 GA.preConcat(A); | 737 GA.preConcat(A); |
738 | 738 |
739 // realTextSize is the actual device size we want (as opposed to the size th
e user requested). | 739 // realTextSize is the actual device size we want (as opposed to the size th
e user requested). |
740 // gdiTextSize is the size we request when GDI compatible. | 740 // gdiTextSize is the size we request when GDI compatible. |
741 // If the scale is negative, this means the matrix will do the flip anyway. | 741 // If the scale is negative, this means the matrix will do the flip anyway. |
742 SkScalar realTextSize = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); | 742 SkScalar realTextSize = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); |
743 // Due to floating point math, the lower bits are suspect. Round carefully. | 743 // Due to floating point math, the lower bits are suspect. Round carefully. |
744 SkScalar roundedTextSize = SkScalarRoundToScalar(realTextSize * 64.0f) / 64.
0f; | 744 SkScalar gdiTextSize = SkScalarRoundToScalar(realTextSize * 64.0f) / 64.0f; |
745 SkScalar gdiTextSize = SkScalarFloorToScalar(roundedTextSize); | |
746 if (gdiTextSize == 0) { | 745 if (gdiTextSize == 0) { |
747 gdiTextSize = SK_Scalar1; | 746 gdiTextSize = SK_Scalar1; |
748 } | 747 } |
749 | 748 |
750 bool hasBitmap = fRec.fFlags & SkScalerContext::kEmbeddedBitmapText_Flag && | 749 bool bitmapRequested = SkToBool(fRec.fFlags & SkScalerContext::kEmbeddedBitm
apText_Flag); |
751 hasBitmapStrike(typeface, SkScalarTruncToInt(gdiTextSize)); | 750 bool hasBitmap = false; |
752 bool axisAligned = isAxisAligned(fRec); | 751 bool axisAlignedBitmap = false; |
753 bool isBiLevel = SkMask::kBW_Format == fRec.fMaskFormat || (hasBitmap && axi
sAligned); | 752 if (bitmapRequested) { |
| 753 hasBitmap = hasBitmapStrike(typeface, SkScalarTruncToInt(gdiTextSize)); |
| 754 axisAlignedBitmap = isAxisAligned(fRec); |
| 755 } |
754 | 756 |
755 if (isBiLevel) { | 757 // If the user requested aliased, do so with aliased compatible metrics. |
| 758 if (SkMask::kBW_Format == fRec.fMaskFormat) { |
756 fTextSizeRender = gdiTextSize; | 759 fTextSizeRender = gdiTextSize; |
757 fRenderingMode = DWRITE_RENDERING_MODE_ALIASED; | 760 fRenderingMode = DWRITE_RENDERING_MODE_ALIASED; |
758 fTextureType = DWRITE_TEXTURE_ALIASED_1x1; | 761 fTextureType = DWRITE_TEXTURE_ALIASED_1x1; |
759 fTextSizeMeasure = gdiTextSize; | 762 fTextSizeMeasure = gdiTextSize; |
760 fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC; | 763 fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC; |
| 764 |
| 765 // If we can use a bitmap, use gdi classic rendering and measurement. |
| 766 // This will not always provide a bitmap, but matches expected behavior. |
| 767 } else if (hasBitmap && axisAlignedBitmap) { |
| 768 fTextSizeRender = gdiTextSize; |
| 769 fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC; |
| 770 fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1; |
| 771 fTextSizeMeasure = gdiTextSize; |
| 772 fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC; |
| 773 |
| 774 // If rotated but the horizontal text could have used a bitmap, |
| 775 // render high quality rotated glyphs but measure using bitmap metrics. |
761 } else if (hasBitmap) { | 776 } else if (hasBitmap) { |
762 // If rotated but the horizontal text would have used a bitmap, | |
763 // render high quality rotated glyphs using the bitmap metrics. | |
764 fTextSizeRender = gdiTextSize; | 777 fTextSizeRender = gdiTextSize; |
765 fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | 778 fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; |
766 fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1; | 779 fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1; |
767 fTextSizeMeasure = gdiTextSize; | 780 fTextSizeMeasure = gdiTextSize; |
768 fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC; | 781 fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC; |
| 782 |
| 783 // The normal case is to use natural symmetric rendering and linear metrics. |
769 } else { | 784 } else { |
770 fTextSizeRender = realTextSize; | 785 fTextSizeRender = realTextSize; |
771 fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | 786 fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; |
772 fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1; | 787 fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1; |
773 fTextSizeMeasure = realTextSize; | 788 fTextSizeMeasure = realTextSize; |
774 fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL; | 789 fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL; |
775 } | 790 } |
776 | 791 |
777 if (this->isSubpixel()) { | 792 if (this->isSubpixel()) { |
778 fTextSizeMeasure = realTextSize; | 793 fTextSizeMeasure = realTextSize; |
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2004 } | 2019 } |
2005 | 2020 |
2006 #include "SkFontMgr_indirect.h" | 2021 #include "SkFontMgr_indirect.h" |
2007 SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 2022 SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
2008 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 2023 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
2009 if (impl.get() == NULL) { | 2024 if (impl.get() == NULL) { |
2010 return NULL; | 2025 return NULL; |
2011 } | 2026 } |
2012 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); | 2027 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); |
2013 } | 2028 } |
OLD | NEW |