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 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 avgCharWidth = SkIntToScalar(os2->xAvgCharWidth) / upem; | 1308 avgCharWidth = SkIntToScalar(os2->xAvgCharWidth) / upem; |
1309 if (os2->version != 0xFFFF && os2->version >= 2) { | 1309 if (os2->version != 0xFFFF && os2->version >= 2) { |
1310 cap_height = scaleX * SkIntToScalar(os2->sCapHeight) / upem; | 1310 cap_height = scaleX * SkIntToScalar(os2->sCapHeight) / upem; |
1311 } | 1311 } |
1312 } | 1312 } |
1313 | 1313 |
1314 // pull from format-specific metrics as needed | 1314 // pull from format-specific metrics as needed |
1315 SkScalar ascent, descent, leading, xmin, xmax, ymin, ymax; | 1315 SkScalar ascent, descent, leading, xmin, xmax, ymin, ymax; |
1316 SkScalar underlineThickness, underlinePosition; | 1316 SkScalar underlineThickness, underlinePosition; |
1317 if (face->face_flags & FT_FACE_FLAG_SCALABLE) { // scalable outline font | 1317 if (face->face_flags & FT_FACE_FLAG_SCALABLE) { // scalable outline font |
1318 ascent = -SkIntToScalar(face->ascender) / upem; | 1318 // FreeType will always use HHEA metrics if they're not zero. |
1319 descent = -SkIntToScalar(face->descender) / upem; | 1319 // It completely ignores the OS/2 fsSelection::UseTypoMetrics bit. |
1320 leading = SkIntToScalar(face->height + (face->descender - face->ascender
)) / upem; | 1320 // It also ignores the VDMX tables, which are also of interest here |
| 1321 // (and override everything else when they apply). |
| 1322 static const int kUseTypoMetricsMask = (1 << 7); |
| 1323 if (os2 && os2->version != 0xFFFF && (os2->fsSelection & kUseTypoMetrics
Mask)) { |
| 1324 ascent = -SkIntToScalar(os2->sTypoAscender) / upem; |
| 1325 descent = -SkIntToScalar(os2->sTypoDescender) / upem; |
| 1326 leading = SkIntToScalar(os2->sTypoLineGap) / upem; |
| 1327 } else { |
| 1328 ascent = -SkIntToScalar(face->ascender) / upem; |
| 1329 descent = -SkIntToScalar(face->descender) / upem; |
| 1330 leading = SkIntToScalar(face->height + (face->descender - face->asce
nder)) / upem; |
| 1331 } |
1321 xmin = SkIntToScalar(face->bbox.xMin) / upem; | 1332 xmin = SkIntToScalar(face->bbox.xMin) / upem; |
1322 xmax = SkIntToScalar(face->bbox.xMax) / upem; | 1333 xmax = SkIntToScalar(face->bbox.xMax) / upem; |
1323 ymin = -SkIntToScalar(face->bbox.yMin) / upem; | 1334 ymin = -SkIntToScalar(face->bbox.yMin) / upem; |
1324 ymax = -SkIntToScalar(face->bbox.yMax) / upem; | 1335 ymax = -SkIntToScalar(face->bbox.yMax) / upem; |
1325 underlineThickness = SkIntToScalar(face->underline_thickness) / upem; | 1336 underlineThickness = SkIntToScalar(face->underline_thickness) / upem; |
1326 underlinePosition = -SkIntToScalar(face->underline_position + | 1337 underlinePosition = -SkIntToScalar(face->underline_position + |
1327 face->underline_thickness / 2) / upem
; | 1338 face->underline_thickness / 2) / upem
; |
1328 | 1339 |
1329 metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag
; | 1340 metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag
; |
1330 metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag; | 1341 metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 if (style) { | 1721 if (style) { |
1711 *style = SkFontStyle(weight, width, slant); | 1722 *style = SkFontStyle(weight, width, slant); |
1712 } | 1723 } |
1713 if (isFixedPitch) { | 1724 if (isFixedPitch) { |
1714 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1725 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
1715 } | 1726 } |
1716 | 1727 |
1717 FT_Done_Face(face); | 1728 FT_Done_Face(face); |
1718 return true; | 1729 return true; |
1719 } | 1730 } |
OLD | NEW |