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

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: Adding Bitfield to Font Metrics Structure 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 "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
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;
1395 // we may be able to synthesize x_height and cap_height from outline 1398 // we may be able to synthesize x_height and cap_height from outline
1396 if (!x_height) { 1399 if (!x_height) {
1397 FT_BBox bbox; 1400 FT_BBox bbox;
1398 if (getCBoxForLetter('x', &bbox)) { 1401 if (getCBoxForLetter('x', &bbox)) {
1399 x_height = SkIntToScalar(bbox.yMax) / 64.0f; 1402 x_height = SkIntToScalar(bbox.yMax) / 64.0f;
1400 } 1403 }
1401 } 1404 }
1402 if (!cap_height) { 1405 if (!cap_height) {
1403 FT_BBox bbox; 1406 FT_BBox bbox;
1404 if (getCBoxForLetter('H', &bbox)) { 1407 if (getCBoxForLetter('H', &bbox)) {
1405 cap_height = SkIntToScalar(bbox.yMax) / 64.0f; 1408 cap_height = SkIntToScalar(bbox.yMax) / 64.0f;
1406 } 1409 }
1407 } 1410 }
1408 } else if (fStrikeIndex != -1) { // bitmap strike metrics 1411 } else if (fStrikeIndex != -1) { // bitmap strike metrics
1409 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem); 1412 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem);
1410 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem); 1413 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem);
1411 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f); 1414 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f);
1412 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f ); 1415 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f );
1413 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f)) 1416 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f))
1414 + ascent - descent; 1417 + ascent - descent;
1415 xmin = 0.0f; 1418 xmin = 0.0f;
1416 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem; 1419 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem;
1417 ymin = descent + leading; 1420 ymin = descent + leading;
1418 ymax = ascent - descent; 1421 ymax = ascent - descent;
1422 underlineThickness = 0;
bungeman-skia 2014/02/17 19:10:06 Here is where the 'unknown' flag should be set (or
h.joshi 2014/02/18 05:48:48 Okey, will make required changes. On 2014/02/17 1
1423 underlinePosition = 0;
1419 } else { 1424 } else {
1420 goto ERROR; 1425 goto ERROR;
1421 } 1426 }
1422 1427
1423 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics 1428 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics
1424 if (!x_height) { 1429 if (!x_height) {
1425 x_height = -ascent; 1430 x_height = -ascent;
1426 } 1431 }
1427 if (!avgCharWidth) { 1432 if (!avgCharWidth) {
1428 avgCharWidth = xmax - xmin; 1433 avgCharWidth = xmax - xmin;
(...skipping 11 matching lines...) Expand all
1440 mx->fTop = ymax * mxy; 1445 mx->fTop = ymax * mxy;
1441 mx->fAscent = ascent * mxy; 1446 mx->fAscent = ascent * mxy;
1442 mx->fDescent = descent * mxy; 1447 mx->fDescent = descent * mxy;
1443 mx->fBottom = ymin * mxy; 1448 mx->fBottom = ymin * mxy;
1444 mx->fLeading = leading * mxy; 1449 mx->fLeading = leading * mxy;
1445 mx->fAvgCharWidth = avgCharWidth * mxy; 1450 mx->fAvgCharWidth = avgCharWidth * mxy;
1446 mx->fXMin = xmin; 1451 mx->fXMin = xmin;
1447 mx->fXMax = xmax; 1452 mx->fXMax = xmax;
1448 mx->fXHeight = x_height; 1453 mx->fXHeight = x_height;
1449 mx->fCapHeight = cap_height; 1454 mx->fCapHeight = cap_height;
1455 mx->fUnderlineThickness = underlineThickness;
1456 mx->fUnderlinePosition = underlinePosition;
1450 } 1457 }
1451 if (my) { 1458 if (my) {
1452 my->fTop = ymax * myy; 1459 my->fTop = ymax * myy;
1453 my->fAscent = ascent * myy; 1460 my->fAscent = ascent * myy;
1454 my->fDescent = descent * myy; 1461 my->fDescent = descent * myy;
1455 my->fBottom = ymin * myy; 1462 my->fBottom = ymin * myy;
1456 my->fLeading = leading * myy; 1463 my->fLeading = leading * myy;
1457 my->fAvgCharWidth = avgCharWidth * myy; 1464 my->fAvgCharWidth = avgCharWidth * myy;
1458 my->fXMin = xmin; 1465 my->fXMin = xmin;
1459 my->fXMax = xmax; 1466 my->fXMax = xmax;
1460 my->fXHeight = x_height; 1467 my->fXHeight = x_height;
1461 my->fCapHeight = cap_height; 1468 my->fCapHeight = cap_height;
1469 my->fUnderlineThickness = underlineThickness;
1470 my->fUnderlinePosition = underlinePosition;
1462 } 1471 }
1463 } 1472 }
1464 1473
1465 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph ) 1474 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph )
1466 { 1475 {
1467 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) { 1476 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) {
1468 switch ( glyph->format ) { 1477 switch ( glyph->format ) {
1469 case FT_GLYPH_FORMAT_OUTLINE: 1478 case FT_GLYPH_FORMAT_OUTLINE:
1470 FT_Pos strength; 1479 FT_Pos strength;
1471 strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_s cale) / 24; 1480 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
1677 *style = (SkTypeface::Style) tempStyle; 1686 *style = (SkTypeface::Style) tempStyle;
1678 } 1687 }
1679 if (isFixedPitch) { 1688 if (isFixedPitch) {
1680 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1689 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1681 } 1690 }
1682 1691
1683 FT_Done_Face(face); 1692 FT_Done_Face(face);
1684 FT_Done_FreeType(library); 1693 FT_Done_FreeType(library);
1685 return true; 1694 return true;
1686 } 1695 }
OLDNEW
« src/core/SkPaint.cpp ('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