OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 while (glyphIndex != 0) { | 999 while (glyphIndex != 0) { |
1000 if (glyphIndex == glyph) { | 1000 if (glyphIndex == glyph) { |
1001 return charCode; | 1001 return charCode; |
1002 } | 1002 } |
1003 charCode = FT_Get_Next_Char( fFace, charCode, &glyphIndex ); | 1003 charCode = FT_Get_Next_Char( fFace, charCode, &glyphIndex ); |
1004 } | 1004 } |
1005 | 1005 |
1006 return 0; | 1006 return 0; |
1007 } | 1007 } |
1008 | 1008 |
| 1009 static SkScalar SkFT_FixedToScalar(FT_Fixed x) { |
| 1010 return SkFixedToScalar(x); |
| 1011 } |
| 1012 |
1009 void SkScalerContext_FreeType::generateAdvance(SkGlyph* glyph) { | 1013 void SkScalerContext_FreeType::generateAdvance(SkGlyph* glyph) { |
1010 /* unhinted and light hinted text have linearly scaled advances | 1014 /* unhinted and light hinted text have linearly scaled advances |
1011 * which are very cheap to compute with some font formats... | 1015 * which are very cheap to compute with some font formats... |
1012 */ | 1016 */ |
1013 if (fDoLinearMetrics) { | 1017 if (fDoLinearMetrics) { |
1014 SkAutoMutexAcquire ac(gFTMutex); | 1018 SkAutoMutexAcquire ac(gFTMutex); |
1015 | 1019 |
1016 if (this->setupSize()) { | 1020 if (this->setupSize()) { |
1017 glyph->zeroMetrics(); | 1021 glyph->zeroMetrics(); |
1018 return; | 1022 return; |
1019 } | 1023 } |
1020 | 1024 |
1021 FT_Error error; | 1025 FT_Error error; |
1022 FT_Fixed advance; | 1026 FT_Fixed advance; |
1023 | 1027 |
1024 error = FT_Get_Advance( fFace, glyph->getGlyphID(), | 1028 error = FT_Get_Advance( fFace, glyph->getGlyphID(), |
1025 fLoadGlyphFlags | FT_ADVANCE_FLAG_FAST_ONLY, | 1029 fLoadGlyphFlags | FT_ADVANCE_FLAG_FAST_ONLY, |
1026 &advance ); | 1030 &advance ); |
1027 if (0 == error) { | 1031 if (0 == error) { |
1028 glyph->fRsbDelta = 0; | 1032 glyph->fRsbDelta = 0; |
1029 glyph->fLsbDelta = 0; | 1033 glyph->fLsbDelta = 0; |
1030 glyph->fAdvanceX = SkFixedMul(fMatrix22.xx, advance); | 1034 const SkScalar advanceScalar = SkFT_FixedToScalar(advance); |
1031 glyph->fAdvanceY = - SkFixedMul(fMatrix22.yx, advance); | 1035 glyph->fAdvanceX = SkScalarToFloat(fMatrix22Scalar.getScaleX() * adv
anceScalar); |
| 1036 glyph->fAdvanceY = -SkScalarToFloat(fMatrix22Scalar.getSkewY() * adv
anceScalar); |
1032 return; | 1037 return; |
1033 } | 1038 } |
1034 } | 1039 } |
1035 | 1040 |
1036 /* otherwise, we need to load/hint the glyph, which is slower */ | 1041 /* otherwise, we need to load/hint the glyph, which is slower */ |
1037 this->generateMetrics(glyph); | 1042 this->generateMetrics(glyph); |
1038 return; | 1043 return; |
1039 } | 1044 } |
1040 | 1045 |
1041 void SkScalerContext_FreeType::getBBoxForCurrentGlyph(SkGlyph* glyph, | 1046 void SkScalerContext_FreeType::getBBoxForCurrentGlyph(SkGlyph* glyph, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 } | 1106 } |
1102 } | 1107 } |
1103 } | 1108 } |
1104 | 1109 |
1105 inline void scaleGlyphMetrics(SkGlyph& glyph, SkScalar scale) { | 1110 inline void scaleGlyphMetrics(SkGlyph& glyph, SkScalar scale) { |
1106 glyph.fWidth *= scale; | 1111 glyph.fWidth *= scale; |
1107 glyph.fHeight *= scale; | 1112 glyph.fHeight *= scale; |
1108 glyph.fTop *= scale; | 1113 glyph.fTop *= scale; |
1109 glyph.fLeft *= scale; | 1114 glyph.fLeft *= scale; |
1110 | 1115 |
1111 SkFixed fixedScale = SkScalarToFixed(scale); | 1116 float floatScale = SkScalarToFloat(scale); |
1112 glyph.fAdvanceX = SkFixedMul(glyph.fAdvanceX, fixedScale); | 1117 glyph.fAdvanceX *= floatScale; |
1113 glyph.fAdvanceY = SkFixedMul(glyph.fAdvanceY, fixedScale); | 1118 glyph.fAdvanceY *= floatScale; |
1114 } | 1119 } |
1115 | 1120 |
1116 void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) { | 1121 void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) { |
1117 SkAutoMutexAcquire ac(gFTMutex); | 1122 SkAutoMutexAcquire ac(gFTMutex); |
1118 | 1123 |
1119 glyph->fRsbDelta = 0; | 1124 glyph->fRsbDelta = 0; |
1120 glyph->fLsbDelta = 0; | 1125 glyph->fLsbDelta = 0; |
1121 | 1126 |
1122 FT_Error err; | 1127 FT_Error err; |
1123 | 1128 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 break; | 1179 break; |
1175 | 1180 |
1176 default: | 1181 default: |
1177 SkDEBUGFAIL("unknown glyph format"); | 1182 SkDEBUGFAIL("unknown glyph format"); |
1178 glyph->zeroMetrics(); | 1183 glyph->zeroMetrics(); |
1179 return; | 1184 return; |
1180 } | 1185 } |
1181 | 1186 |
1182 if (fRec.fFlags & SkScalerContext::kVertical_Flag) { | 1187 if (fRec.fFlags & SkScalerContext::kVertical_Flag) { |
1183 if (fDoLinearMetrics) { | 1188 if (fDoLinearMetrics) { |
1184 glyph->fAdvanceX = -SkFixedMul(fMatrix22.xy, fFace->glyph->linearVer
tAdvance); | 1189 const SkScalar advanceScalar = SkFT_FixedToScalar(fFace->glyph->line
arVertAdvance); |
1185 glyph->fAdvanceY = SkFixedMul(fMatrix22.yy, fFace->glyph->linearVert
Advance); | 1190 glyph->fAdvanceX = -SkScalarToFloat(fMatrix22Scalar.getSkewX() * adv
anceScalar); |
| 1191 glyph->fAdvanceY = SkScalarToFloat(fMatrix22Scalar.getScaleY() * adv
anceScalar); |
1186 } else { | 1192 } else { |
1187 glyph->fAdvanceX = -SkFDot6ToFixed(fFace->glyph->advance.x); | 1193 glyph->fAdvanceX = -SkFDot6ToFloat(fFace->glyph->advance.x); |
1188 glyph->fAdvanceY = SkFDot6ToFixed(fFace->glyph->advance.y); | 1194 glyph->fAdvanceY = SkFDot6ToFloat(fFace->glyph->advance.y); |
1189 } | 1195 } |
1190 } else { | 1196 } else { |
1191 if (fDoLinearMetrics) { | 1197 if (fDoLinearMetrics) { |
1192 glyph->fAdvanceX = SkFixedMul(fMatrix22.xx, fFace->glyph->linearHori
Advance); | 1198 const SkScalar advanceScalar = SkFT_FixedToScalar(fFace->glyph->line
arHoriAdvance); |
1193 glyph->fAdvanceY = -SkFixedMul(fMatrix22.yx, fFace->glyph->linearHor
iAdvance); | 1199 glyph->fAdvanceX = SkScalarToFloat(fMatrix22Scalar.getScaleX() * adv
anceScalar); |
| 1200 glyph->fAdvanceY = -SkScalarToFloat(fMatrix22Scalar.getSkewY() * adv
anceScalar); |
1194 } else { | 1201 } else { |
1195 glyph->fAdvanceX = SkFDot6ToFixed(fFace->glyph->advance.x); | 1202 glyph->fAdvanceX = SkFDot6ToFloat(fFace->glyph->advance.x); |
1196 glyph->fAdvanceY = -SkFDot6ToFixed(fFace->glyph->advance.y); | 1203 glyph->fAdvanceY = -SkFDot6ToFloat(fFace->glyph->advance.y); |
1197 | 1204 |
1198 if (fRec.fFlags & kDevKernText_Flag) { | 1205 if (fRec.fFlags & kDevKernText_Flag) { |
1199 glyph->fRsbDelta = SkToS8(fFace->glyph->rsb_delta); | 1206 glyph->fRsbDelta = SkToS8(fFace->glyph->rsb_delta); |
1200 glyph->fLsbDelta = SkToS8(fFace->glyph->lsb_delta); | 1207 glyph->fLsbDelta = SkToS8(fFace->glyph->lsb_delta); |
1201 } | 1208 } |
1202 } | 1209 } |
1203 } | 1210 } |
1204 | 1211 |
1205 // If the font isn't scalable, scale the metrics from the non-scalable strik
e. | 1212 // If the font isn't scalable, scale the metrics from the non-scalable strik
e. |
1206 // This means do not try to scale embedded bitmaps; only scale bitmaps in bi
tmap only fonts. | 1213 // This means do not try to scale embedded bitmaps; only scale bitmaps in bi
tmap only fonts. |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", | 1814 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", |
1808 name.c_str(), | 1815 name.c_str(), |
1809 (skTag >> 24) & 0xFF, | 1816 (skTag >> 24) & 0xFF, |
1810 (skTag >> 16) & 0xFF, | 1817 (skTag >> 16) & 0xFF, |
1811 (skTag >> 8) & 0xFF, | 1818 (skTag >> 8) & 0xFF, |
1812 (skTag) & 0xFF)); | 1819 (skTag) & 0xFF)); |
1813 } | 1820 } |
1814 } | 1821 } |
1815 ) | 1822 ) |
1816 } | 1823 } |
OLD | NEW |