Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: src/ports/SkFontHost_FreeType.cpp

Issue 152073003: Adding code to calculate Underline Thickness from Font Metrics, this will be useful when Skia is us… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Comment fix and addition of underline position Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkAdvancedTypefaceMetrics.h" 9 #include "SkAdvancedTypefaceMetrics.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 if (os2) { 1383 if (os2) {
1384 x_height = scaleX * SkIntToScalar(os2->sxHeight) / upem; 1384 x_height = scaleX * SkIntToScalar(os2->sxHeight) / upem;
1385 avgCharWidth = SkIntToScalar(os2->xAvgCharWidth) / upem; 1385 avgCharWidth = SkIntToScalar(os2->xAvgCharWidth) / upem;
1386 if (os2->version != 0xFFFF && os2->version >= 2) { 1386 if (os2->version != 0xFFFF && os2->version >= 2) {
1387 cap_height = scaleX * SkIntToScalar(os2->sCapHeight) / upem; 1387 cap_height = scaleX * SkIntToScalar(os2->sCapHeight) / upem;
1388 } 1388 }
1389 } 1389 }
1390 1390
1391 // pull from format-specific metrics as needed 1391 // pull from format-specific metrics as needed
1392 SkScalar ascent, descent, leading, xmin, xmax, ymin, ymax; 1392 SkScalar ascent, descent, leading, xmin, xmax, ymin, ymax;
1393 SkScalar underlineThickness, underlinePosition;
1393 if (face->face_flags & FT_FACE_FLAG_SCALABLE) { // scalable outline font 1394 if (face->face_flags & FT_FACE_FLAG_SCALABLE) { // scalable outline font
1394 ascent = -SkIntToScalar(face->ascender) / upem; 1395 ascent = -SkIntToScalar(face->ascender) / upem;
1395 descent = -SkIntToScalar(face->descender) / upem; 1396 descent = -SkIntToScalar(face->descender) / upem;
1396 leading = SkIntToScalar(face->height + (face->descender - face->ascender )) / upem; 1397 leading = SkIntToScalar(face->height + (face->descender - face->ascender )) / upem;
1397 xmin = SkIntToScalar(face->bbox.xMin) / upem; 1398 xmin = SkIntToScalar(face->bbox.xMin) / upem;
1398 xmax = SkIntToScalar(face->bbox.xMax) / upem; 1399 xmax = SkIntToScalar(face->bbox.xMax) / upem;
1399 ymin = -SkIntToScalar(face->bbox.yMin) / upem; 1400 ymin = -SkIntToScalar(face->bbox.yMin) / upem;
1400 ymax = -SkIntToScalar(face->bbox.yMax) / upem; 1401 ymax = -SkIntToScalar(face->bbox.yMax) / upem;
1402 underlineThickness = SkIntToScalar(face->underline_thickness) / upem;
1403 underlinePosition = SkIntToScalar(face->underline_position) / upem;
1401 // we may be able to synthesize x_height and cap_height from outline 1404 // we may be able to synthesize x_height and cap_height from outline
1402 if (!x_height) { 1405 if (!x_height) {
1403 FT_BBox bbox; 1406 FT_BBox bbox;
1404 if (getCBoxForLetter('x', &bbox)) { 1407 if (getCBoxForLetter('x', &bbox)) {
1405 x_height = SkIntToScalar(bbox.yMax) / 64.0f; 1408 x_height = SkIntToScalar(bbox.yMax) / 64.0f;
1406 } 1409 }
1407 } 1410 }
1408 if (!cap_height) { 1411 if (!cap_height) {
1409 FT_BBox bbox; 1412 FT_BBox bbox;
1410 if (getCBoxForLetter('H', &bbox)) { 1413 if (getCBoxForLetter('H', &bbox)) {
1411 cap_height = SkIntToScalar(bbox.yMax) / 64.0f; 1414 cap_height = SkIntToScalar(bbox.yMax) / 64.0f;
1412 } 1415 }
1413 } 1416 }
1414 } else if (fStrikeIndex != -1) { // bitmap strike metrics 1417 } else if (fStrikeIndex != -1) { // bitmap strike metrics
1415 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem); 1418 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem);
1416 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem); 1419 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem);
1417 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f); 1420 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f);
1418 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f ); 1421 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f );
1419 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f)) 1422 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f))
1420 + ascent - descent; 1423 + ascent - descent;
1421 xmin = 0.0f; 1424 xmin = 0.0f;
1422 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem; 1425 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem;
1423 ymin = descent + leading; 1426 ymin = descent + leading;
1424 ymax = ascent - descent; 1427 ymax = ascent - descent;
1428 underlineThickness = 0;
1429 underlinePosition = 0;
1425 } else { 1430 } else {
1426 goto ERROR; 1431 goto ERROR;
1427 } 1432 }
1428 1433
1429 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics 1434 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics
1430 if (!x_height) { 1435 if (!x_height) {
1431 x_height = -ascent; 1436 x_height = -ascent;
1432 } 1437 }
1433 if (!avgCharWidth) { 1438 if (!avgCharWidth) {
1434 avgCharWidth = xmax - xmin; 1439 avgCharWidth = xmax - xmin;
(...skipping 11 matching lines...) Expand all
1446 mx->fTop = ymax * mxy; 1451 mx->fTop = ymax * mxy;
1447 mx->fAscent = ascent * mxy; 1452 mx->fAscent = ascent * mxy;
1448 mx->fDescent = descent * mxy; 1453 mx->fDescent = descent * mxy;
1449 mx->fBottom = ymin * mxy; 1454 mx->fBottom = ymin * mxy;
1450 mx->fLeading = leading * mxy; 1455 mx->fLeading = leading * mxy;
1451 mx->fAvgCharWidth = avgCharWidth * mxy; 1456 mx->fAvgCharWidth = avgCharWidth * mxy;
1452 mx->fXMin = xmin; 1457 mx->fXMin = xmin;
1453 mx->fXMax = xmax; 1458 mx->fXMax = xmax;
1454 mx->fXHeight = x_height; 1459 mx->fXHeight = x_height;
1455 mx->fCapHeight = cap_height; 1460 mx->fCapHeight = cap_height;
1461 mx->fUnderlineThickness = underlineThickness;
1462 mx->fUnderlinePosition = underlinePosition;
1456 } 1463 }
1457 if (my) { 1464 if (my) {
1458 my->fTop = ymax * myy; 1465 my->fTop = ymax * myy;
1459 my->fAscent = ascent * myy; 1466 my->fAscent = ascent * myy;
1460 my->fDescent = descent * myy; 1467 my->fDescent = descent * myy;
1461 my->fBottom = ymin * myy; 1468 my->fBottom = ymin * myy;
1462 my->fLeading = leading * myy; 1469 my->fLeading = leading * myy;
1463 my->fAvgCharWidth = avgCharWidth * myy; 1470 my->fAvgCharWidth = avgCharWidth * myy;
1464 my->fXMin = xmin; 1471 my->fXMin = xmin;
1465 my->fXMax = xmax; 1472 my->fXMax = xmax;
1466 my->fXHeight = x_height; 1473 my->fXHeight = x_height;
1467 my->fCapHeight = cap_height; 1474 my->fCapHeight = cap_height;
1475 my->fUnderlineThickness = underlineThickness;
1476 my->fUnderlinePosition = underlinePosition;
1468 } 1477 }
1469 } 1478 }
1470 1479
1471 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph ) 1480 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph )
1472 { 1481 {
1473 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) { 1482 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) {
1474 switch ( glyph->format ) { 1483 switch ( glyph->format ) {
1475 case FT_GLYPH_FORMAT_OUTLINE: 1484 case FT_GLYPH_FORMAT_OUTLINE:
1476 FT_Pos strength; 1485 FT_Pos strength;
1477 strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_s cale) / 24; 1486 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
1683 *style = (SkTypeface::Style) tempStyle; 1692 *style = (SkTypeface::Style) tempStyle;
1684 } 1693 }
1685 if (isFixedPitch) { 1694 if (isFixedPitch) {
1686 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1695 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1687 } 1696 }
1688 1697
1689 FT_Done_Face(face); 1698 FT_Done_Face(face);
1690 FT_Done_FreeType(library); 1699 FT_Done_FreeType(library);
1691 return true; 1700 return true;
1692 } 1701 }
OLDNEW
« include/core/SkPaint.h ('K') | « src/core/SkPaint.cpp ('k') | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698