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

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: Fixing comments for Underline patch 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;
bungeman-skia 2014/02/19 15:39:17 At this point we know that these values are truste
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;
bungeman-skia 2014/02/19 15:39:17 At this point we know these values are not trusted
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 if(!underlineThickness)
bungeman-skia 2014/02/19 15:39:17 These checks here (and below) are incorrect and th
h.joshi 2014/02/19 17:12:03 Okey, Added these checks below as "face->underline
1463 mx->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIs Valid_FontMetricFlag);
1464 else
1465 mx->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIsVa lid_FontMetricFlag);
1466
1467 mx->fUnderlinePosition = underlinePosition;
1468 if(!underlinePosition)
1469 mx->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsV alid_FontMetricsflag);
1470 else
1471 mx->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsVal id_FontMetricsflag);
1456 } 1472 }
1457 if (my) { 1473 if (my) {
1458 my->fTop = ymax * myy; 1474 my->fTop = ymax * myy;
1459 my->fAscent = ascent * myy; 1475 my->fAscent = ascent * myy;
1460 my->fDescent = descent * myy; 1476 my->fDescent = descent * myy;
1461 my->fBottom = ymin * myy; 1477 my->fBottom = ymin * myy;
1462 my->fLeading = leading * myy; 1478 my->fLeading = leading * myy;
1463 my->fAvgCharWidth = avgCharWidth * myy; 1479 my->fAvgCharWidth = avgCharWidth * myy;
1464 my->fXMin = xmin; 1480 my->fXMin = xmin;
1465 my->fXMax = xmax; 1481 my->fXMax = xmax;
1466 my->fXHeight = x_height; 1482 my->fXHeight = x_height;
1467 my->fCapHeight = cap_height; 1483 my->fCapHeight = cap_height;
1484 my->fUnderlineThickness = underlineThickness;
1485 if(!underlineThickness)
1486 my->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIs Valid_FontMetricFlag);
1487 else
1488 my->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlineThinknessIsVa lid_FontMetricFlag);
1489
1490 my->fUnderlinePosition = underlinePosition;
1491 if(!underlinePosition)
1492 my->unsetFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsV alid_FontMetricsflag);
1493 else
1494 my->setFontMetricsFlag(SkPaint::FontMetrics::kUnderlinePositionIsVal id_FontMetricsflag);
1468 } 1495 }
1469 } 1496 }
1470 1497
1471 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph ) 1498 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph )
1472 { 1499 {
1473 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) { 1500 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) {
1474 switch ( glyph->format ) { 1501 switch ( glyph->format ) {
1475 case FT_GLYPH_FORMAT_OUTLINE: 1502 case FT_GLYPH_FORMAT_OUTLINE:
1476 FT_Pos strength; 1503 FT_Pos strength;
1477 strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_s cale) / 24; 1504 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; 1710 *style = (SkTypeface::Style) tempStyle;
1684 } 1711 }
1685 if (isFixedPitch) { 1712 if (isFixedPitch) {
1686 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1713 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1687 } 1714 }
1688 1715
1689 FT_Done_Face(face); 1716 FT_Done_Face(face);
1690 FT_Done_FreeType(library); 1717 FT_Done_FreeType(library);
1691 return true; 1718 return true;
1692 } 1719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698