OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 if (os2) { | 1377 if (os2) { |
1378 x_height = scaleX * SkIntToScalar(os2->sxHeight) / upem; | 1378 x_height = scaleX * SkIntToScalar(os2->sxHeight) / upem; |
1379 avgCharWidth = SkIntToScalar(os2->xAvgCharWidth) / upem; | 1379 avgCharWidth = SkIntToScalar(os2->xAvgCharWidth) / upem; |
1380 if (os2->version != 0xFFFF && os2->version >= 2) { | 1380 if (os2->version != 0xFFFF && os2->version >= 2) { |
1381 cap_height = scaleX * SkIntToScalar(os2->sCapHeight) / upem; | 1381 cap_height = scaleX * SkIntToScalar(os2->sCapHeight) / upem; |
1382 } | 1382 } |
1383 } | 1383 } |
1384 | 1384 |
1385 // pull from format-specific metrics as needed | 1385 // pull from format-specific metrics as needed |
1386 SkScalar ascent, descent, leading, xmin, xmax, ymin, ymax; | 1386 SkScalar ascent, descent, leading, xmin, xmax, ymin, ymax; |
| 1387 SkScalar underlineThickness, underlinePosition; |
1387 if (face->face_flags & FT_FACE_FLAG_SCALABLE) { // scalable outline font | 1388 if (face->face_flags & FT_FACE_FLAG_SCALABLE) { // scalable outline font |
1388 ascent = -SkIntToScalar(face->ascender) / upem; | 1389 ascent = -SkIntToScalar(face->ascender) / upem; |
1389 descent = -SkIntToScalar(face->descender) / upem; | 1390 descent = -SkIntToScalar(face->descender) / upem; |
1390 leading = SkIntToScalar(face->height + (face->descender - face->ascender
)) / upem; | 1391 leading = SkIntToScalar(face->height + (face->descender - face->ascender
)) / upem; |
1391 xmin = SkIntToScalar(face->bbox.xMin) / upem; | 1392 xmin = SkIntToScalar(face->bbox.xMin) / upem; |
1392 xmax = SkIntToScalar(face->bbox.xMax) / upem; | 1393 xmax = SkIntToScalar(face->bbox.xMax) / upem; |
1393 ymin = -SkIntToScalar(face->bbox.yMin) / upem; | 1394 ymin = -SkIntToScalar(face->bbox.yMin) / upem; |
1394 ymax = -SkIntToScalar(face->bbox.yMax) / upem; | 1395 ymax = -SkIntToScalar(face->bbox.yMax) / upem; |
| 1396 underlineThickness = SkIntToScalar(face->underline_thickness) / upem; |
| 1397 underlinePosition = SkIntToScalar(face->underline_position) / upem; |
| 1398 |
| 1399 if(mx) { |
| 1400 mx->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIsVa
lid_FontMetricFlag); |
| 1401 mx->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsVal
id_FontMetricsflag); |
| 1402 } |
| 1403 if(my){ |
| 1404 my->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIsVa
lid_FontMetricFlag); |
| 1405 my->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsVal
id_FontMetricsflag); |
| 1406 } |
1395 // we may be able to synthesize x_height and cap_height from outline | 1407 // we may be able to synthesize x_height and cap_height from outline |
1396 if (!x_height) { | 1408 if (!x_height) { |
1397 FT_BBox bbox; | 1409 FT_BBox bbox; |
1398 if (getCBoxForLetter('x', &bbox)) { | 1410 if (getCBoxForLetter('x', &bbox)) { |
1399 x_height = SkIntToScalar(bbox.yMax) / 64.0f; | 1411 x_height = SkIntToScalar(bbox.yMax) / 64.0f; |
1400 } | 1412 } |
1401 } | 1413 } |
1402 if (!cap_height) { | 1414 if (!cap_height) { |
1403 FT_BBox bbox; | 1415 FT_BBox bbox; |
1404 if (getCBoxForLetter('H', &bbox)) { | 1416 if (getCBoxForLetter('H', &bbox)) { |
1405 cap_height = SkIntToScalar(bbox.yMax) / 64.0f; | 1417 cap_height = SkIntToScalar(bbox.yMax) / 64.0f; |
1406 } | 1418 } |
1407 } | 1419 } |
1408 } else if (fStrikeIndex != -1) { // bitmap strike metrics | 1420 } else if (fStrikeIndex != -1) { // bitmap strike metrics |
1409 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem); | 1421 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem); |
1410 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem); | 1422 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem); |
1411 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f); | 1423 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f); |
1412 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f
); | 1424 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f
); |
1413 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f)) | 1425 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f)) |
1414 + ascent - descent; | 1426 + ascent - descent; |
1415 xmin = 0.0f; | 1427 xmin = 0.0f; |
1416 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem; | 1428 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem; |
1417 ymin = descent + leading; | 1429 ymin = descent + leading; |
1418 ymax = ascent - descent; | 1430 ymax = ascent - descent; |
| 1431 underlineThickness = 0; |
| 1432 underlinePosition = 0; |
| 1433 |
| 1434 if(mx) { |
| 1435 mx->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIs
Valid_FontMetricFlag); |
| 1436 mx->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsV
alid_FontMetricsflag); |
| 1437 } |
| 1438 if(my){ |
| 1439 my->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIs
Valid_FontMetricFlag); |
| 1440 my->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsV
alid_FontMetricsflag); |
| 1441 } |
1419 } else { | 1442 } else { |
1420 goto ERROR; | 1443 goto ERROR; |
1421 } | 1444 } |
1422 | 1445 |
1423 // synthesize elements that were not provided by the os/2 table or format-sp
ecific metrics | 1446 // synthesize elements that were not provided by the os/2 table or format-sp
ecific metrics |
1424 if (!x_height) { | 1447 if (!x_height) { |
1425 x_height = -ascent; | 1448 x_height = -ascent; |
1426 } | 1449 } |
1427 if (!avgCharWidth) { | 1450 if (!avgCharWidth) { |
1428 avgCharWidth = xmax - xmin; | 1451 avgCharWidth = xmax - xmin; |
(...skipping 11 matching lines...) Expand all Loading... |
1440 mx->fTop = ymax * mxy; | 1463 mx->fTop = ymax * mxy; |
1441 mx->fAscent = ascent * mxy; | 1464 mx->fAscent = ascent * mxy; |
1442 mx->fDescent = descent * mxy; | 1465 mx->fDescent = descent * mxy; |
1443 mx->fBottom = ymin * mxy; | 1466 mx->fBottom = ymin * mxy; |
1444 mx->fLeading = leading * mxy; | 1467 mx->fLeading = leading * mxy; |
1445 mx->fAvgCharWidth = avgCharWidth * mxy; | 1468 mx->fAvgCharWidth = avgCharWidth * mxy; |
1446 mx->fXMin = xmin; | 1469 mx->fXMin = xmin; |
1447 mx->fXMax = xmax; | 1470 mx->fXMax = xmax; |
1448 mx->fXHeight = x_height; | 1471 mx->fXHeight = x_height; |
1449 mx->fCapHeight = cap_height; | 1472 mx->fCapHeight = cap_height; |
| 1473 mx->fUnderlineThickness = underlineThickness; |
| 1474 mx->fUnderlinePosition = underlinePosition; |
1450 } | 1475 } |
1451 if (my) { | 1476 if (my) { |
1452 my->fTop = ymax * myy; | 1477 my->fTop = ymax * myy; |
1453 my->fAscent = ascent * myy; | 1478 my->fAscent = ascent * myy; |
1454 my->fDescent = descent * myy; | 1479 my->fDescent = descent * myy; |
1455 my->fBottom = ymin * myy; | 1480 my->fBottom = ymin * myy; |
1456 my->fLeading = leading * myy; | 1481 my->fLeading = leading * myy; |
1457 my->fAvgCharWidth = avgCharWidth * myy; | 1482 my->fAvgCharWidth = avgCharWidth * myy; |
1458 my->fXMin = xmin; | 1483 my->fXMin = xmin; |
1459 my->fXMax = xmax; | 1484 my->fXMax = xmax; |
1460 my->fXHeight = x_height; | 1485 my->fXHeight = x_height; |
1461 my->fCapHeight = cap_height; | 1486 my->fCapHeight = cap_height; |
| 1487 my->fUnderlineThickness = underlineThickness; |
| 1488 my->fUnderlinePosition = underlinePosition; |
1462 } | 1489 } |
1463 } | 1490 } |
1464 | 1491 |
1465 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph
) | 1492 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph
) |
1466 { | 1493 { |
1467 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) { | 1494 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) { |
1468 switch ( glyph->format ) { | 1495 switch ( glyph->format ) { |
1469 case FT_GLYPH_FORMAT_OUTLINE: | 1496 case FT_GLYPH_FORMAT_OUTLINE: |
1470 FT_Pos strength; | 1497 FT_Pos strength; |
1471 strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_s
cale) / 24; | 1498 strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_s
cale) / 24; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 *style = (SkTypeface::Style) tempStyle; | 1704 *style = (SkTypeface::Style) tempStyle; |
1678 } | 1705 } |
1679 if (isFixedPitch) { | 1706 if (isFixedPitch) { |
1680 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1707 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
1681 } | 1708 } |
1682 | 1709 |
1683 FT_Done_Face(face); | 1710 FT_Done_Face(face); |
1684 FT_Done_FreeType(library); | 1711 FT_Done_FreeType(library); |
1685 return true; | 1712 return true; |
1686 } | 1713 } |
OLD | NEW |