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

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: Updating files as per HEAD Created 6 years, 9 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
« no previous file with comments | « src/core/SkPaint.cpp ('k') | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
1404
1405 if(mx) {
1406 mx->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag;
1407 mx->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1408 }
1409 if(my){
1410 my->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag;
1411 my->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1412 }
1401 // we may be able to synthesize x_height and cap_height from outline 1413 // we may be able to synthesize x_height and cap_height from outline
1402 if (!x_height) { 1414 if (!x_height) {
1403 FT_BBox bbox; 1415 FT_BBox bbox;
1404 if (getCBoxForLetter('x', &bbox)) { 1416 if (getCBoxForLetter('x', &bbox)) {
1405 x_height = SkIntToScalar(bbox.yMax) / 64.0f; 1417 x_height = SkIntToScalar(bbox.yMax) / 64.0f;
1406 } 1418 }
1407 } 1419 }
1408 if (!cap_height) { 1420 if (!cap_height) {
1409 FT_BBox bbox; 1421 FT_BBox bbox;
1410 if (getCBoxForLetter('H', &bbox)) { 1422 if (getCBoxForLetter('H', &bbox)) {
1411 cap_height = SkIntToScalar(bbox.yMax) / 64.0f; 1423 cap_height = SkIntToScalar(bbox.yMax) / 64.0f;
1412 } 1424 }
1413 } 1425 }
1414 } else if (fStrikeIndex != -1) { // bitmap strike metrics 1426 } else if (fStrikeIndex != -1) { // bitmap strike metrics
1415 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem); 1427 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem);
1416 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem); 1428 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem);
1417 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f); 1429 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f);
1418 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f ); 1430 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f );
1419 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f)) 1431 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f))
1420 + ascent - descent; 1432 + ascent - descent;
1421 xmin = 0.0f; 1433 xmin = 0.0f;
1422 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem; 1434 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem;
1423 ymin = descent + leading; 1435 ymin = descent + leading;
1424 ymax = ascent - descent; 1436 ymax = ascent - descent;
1437 underlineThickness = 0;
1438 underlinePosition = 0;
1439
1440 if(mx) {
1441 mx->fFlags &= ~SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag ;
1442 mx->fFlags &= ~SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1443 }
1444 if(my){
1445 my->fFlags &= ~SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag ;
1446 my->fFlags &= ~SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1447 }
1425 } else { 1448 } else {
1426 goto ERROR; 1449 goto ERROR;
1427 } 1450 }
1428 1451
1429 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics 1452 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics
1430 if (!x_height) { 1453 if (!x_height) {
1431 x_height = -ascent; 1454 x_height = -ascent;
1432 } 1455 }
1433 if (!avgCharWidth) { 1456 if (!avgCharWidth) {
1434 avgCharWidth = xmax - xmin; 1457 avgCharWidth = xmax - xmin;
(...skipping 11 matching lines...) Expand all
1446 mx->fTop = ymax * mxy; 1469 mx->fTop = ymax * mxy;
1447 mx->fAscent = ascent * mxy; 1470 mx->fAscent = ascent * mxy;
1448 mx->fDescent = descent * mxy; 1471 mx->fDescent = descent * mxy;
1449 mx->fBottom = ymin * mxy; 1472 mx->fBottom = ymin * mxy;
1450 mx->fLeading = leading * mxy; 1473 mx->fLeading = leading * mxy;
1451 mx->fAvgCharWidth = avgCharWidth * mxy; 1474 mx->fAvgCharWidth = avgCharWidth * mxy;
1452 mx->fXMin = xmin; 1475 mx->fXMin = xmin;
1453 mx->fXMax = xmax; 1476 mx->fXMax = xmax;
1454 mx->fXHeight = x_height; 1477 mx->fXHeight = x_height;
1455 mx->fCapHeight = cap_height; 1478 mx->fCapHeight = cap_height;
1479 mx->fUnderlineThickness = underlineThickness;
1480 mx->fUnderlinePosition = underlinePosition;
1456 } 1481 }
1457 if (my) { 1482 if (my) {
1458 my->fTop = ymax * myy; 1483 my->fTop = ymax * myy;
1459 my->fAscent = ascent * myy; 1484 my->fAscent = ascent * myy;
1460 my->fDescent = descent * myy; 1485 my->fDescent = descent * myy;
1461 my->fBottom = ymin * myy; 1486 my->fBottom = ymin * myy;
1462 my->fLeading = leading * myy; 1487 my->fLeading = leading * myy;
1463 my->fAvgCharWidth = avgCharWidth * myy; 1488 my->fAvgCharWidth = avgCharWidth * myy;
1464 my->fXMin = xmin; 1489 my->fXMin = xmin;
1465 my->fXMax = xmax; 1490 my->fXMax = xmax;
1466 my->fXHeight = x_height; 1491 my->fXHeight = x_height;
1467 my->fCapHeight = cap_height; 1492 my->fCapHeight = cap_height;
1493 my->fUnderlineThickness = underlineThickness;
1494 my->fUnderlinePosition = underlinePosition;
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
« no previous file with comments | « 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