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: 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;
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;
1395 // we may be able to synthesize x_height and cap_height from outline 1397 // we may be able to synthesize x_height and cap_height from outline
1396 if (!x_height) { 1398 if (!x_height) {
1397 FT_BBox bbox; 1399 FT_BBox bbox;
1398 if (getCBoxForLetter('x', &bbox)) { 1400 if (getCBoxForLetter('x', &bbox)) {
1399 x_height = SkIntToScalar(bbox.yMax) / 64.0f; 1401 x_height = SkIntToScalar(bbox.yMax) / 64.0f;
1400 } 1402 }
1401 } 1403 }
1402 if (!cap_height) { 1404 if (!cap_height) {
1403 FT_BBox bbox; 1405 FT_BBox bbox;
1404 if (getCBoxForLetter('H', &bbox)) { 1406 if (getCBoxForLetter('H', &bbox)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 mx->fTop = ymax * mxy; 1442 mx->fTop = ymax * mxy;
1441 mx->fAscent = ascent * mxy; 1443 mx->fAscent = ascent * mxy;
1442 mx->fDescent = descent * mxy; 1444 mx->fDescent = descent * mxy;
1443 mx->fBottom = ymin * mxy; 1445 mx->fBottom = ymin * mxy;
1444 mx->fLeading = leading * mxy; 1446 mx->fLeading = leading * mxy;
1445 mx->fAvgCharWidth = avgCharWidth * mxy; 1447 mx->fAvgCharWidth = avgCharWidth * mxy;
1446 mx->fXMin = xmin; 1448 mx->fXMin = xmin;
1447 mx->fXMax = xmax; 1449 mx->fXMax = xmax;
1448 mx->fXHeight = x_height; 1450 mx->fXHeight = x_height;
1449 mx->fCapHeight = cap_height; 1451 mx->fCapHeight = cap_height;
1452 mx->fUnderlineThickness = underlineThickness;
1450 } 1453 }
1451 if (my) { 1454 if (my) {
1452 my->fTop = ymax * myy; 1455 my->fTop = ymax * myy;
1453 my->fAscent = ascent * myy; 1456 my->fAscent = ascent * myy;
1454 my->fDescent = descent * myy; 1457 my->fDescent = descent * myy;
1455 my->fBottom = ymin * myy; 1458 my->fBottom = ymin * myy;
1456 my->fLeading = leading * myy; 1459 my->fLeading = leading * myy;
1457 my->fAvgCharWidth = avgCharWidth * myy; 1460 my->fAvgCharWidth = avgCharWidth * myy;
1458 my->fXMin = xmin; 1461 my->fXMin = xmin;
1459 my->fXMax = xmax; 1462 my->fXMax = xmax;
1460 my->fXHeight = x_height; 1463 my->fXHeight = x_height;
1461 my->fCapHeight = cap_height; 1464 my->fCapHeight = cap_height;
1465 my->fUnderlineThickness = underlineThickness;
1462 } 1466 }
1463 } 1467 }
1464 1468
1465 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph ) 1469 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph )
1466 { 1470 {
1467 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) { 1471 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) {
1468 switch ( glyph->format ) { 1472 switch ( glyph->format ) {
1469 case FT_GLYPH_FORMAT_OUTLINE: 1473 case FT_GLYPH_FORMAT_OUTLINE:
1470 FT_Pos strength; 1474 FT_Pos strength;
1471 strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_s cale) / 24; 1475 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; 1681 *style = (SkTypeface::Style) tempStyle;
1678 } 1682 }
1679 if (isFixedPitch) { 1683 if (isFixedPitch) {
1680 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1684 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1681 } 1685 }
1682 1686
1683 FT_Done_Face(face); 1687 FT_Done_Face(face);
1684 FT_Done_FreeType(library); 1688 FT_Done_FreeType(library);
1685 return true; 1689 return true;
1686 } 1690 }
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