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

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

Issue 370463002: Remove vertical/horizontal metrics selection. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix Mac. Created 6 years, 5 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/fonts/SkTestScalerContext.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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 fFace != NULL; 193 fFace != NULL;
194 } 194 }
195 195
196 protected: 196 protected:
197 virtual unsigned generateGlyphCount() SK_OVERRIDE; 197 virtual unsigned generateGlyphCount() SK_OVERRIDE;
198 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; 198 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE;
199 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; 199 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE;
200 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; 200 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE;
201 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; 201 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE;
202 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; 202 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE;
203 virtual void generateFontMetrics(SkPaint::FontMetrics* mx, 203 virtual void generateFontMetrics(SkPaint::FontMetrics*) SK_OVERRIDE;
204 SkPaint::FontMetrics* my) SK_OVERRIDE;
205 virtual SkUnichar generateGlyphToChar(uint16_t glyph) SK_OVERRIDE; 204 virtual SkUnichar generateGlyphToChar(uint16_t glyph) SK_OVERRIDE;
206 205
207 private: 206 private:
208 SkFaceRec* fFaceRec; 207 SkFaceRec* fFaceRec;
209 FT_Face fFace; // reference to shared face in gFaceRecHead 208 FT_Face fFace; // reference to shared face in gFaceRecHead
210 FT_Size fFTSize; // our own copy 209 FT_Size fFTSize; // our own copy
211 FT_Int fStrikeIndex; 210 FT_Int fStrikeIndex;
212 SkFixed fScaleX, fScaleY; 211 SkFixed fScaleX, fScaleY;
213 FT_Matrix fMatrix22; 212 FT_Matrix fMatrix22;
214 uint32_t fLoadGlyphFlags; 213 uint32_t fLoadGlyphFlags;
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 // Offset the path so that it is relative to the vertical origin if needed. 1364 // Offset the path so that it is relative to the vertical origin if needed.
1366 if (fRec.fFlags & SkScalerContext::kVertical_Flag) { 1365 if (fRec.fFlags & SkScalerContext::kVertical_Flag) {
1367 FT_Vector vector; 1366 FT_Vector vector;
1368 vector.x = fFace->glyph->metrics.vertBearingX - fFace->glyph->metrics.ho riBearingX; 1367 vector.x = fFace->glyph->metrics.vertBearingX - fFace->glyph->metrics.ho riBearingX;
1369 vector.y = -fFace->glyph->metrics.vertBearingY - fFace->glyph->metrics.h oriBearingY; 1368 vector.y = -fFace->glyph->metrics.vertBearingY - fFace->glyph->metrics.h oriBearingY;
1370 FT_Vector_Transform(&vector, &fMatrix22); 1369 FT_Vector_Transform(&vector, &fMatrix22);
1371 path->offset(SkFDot6ToScalar(vector.x), -SkFDot6ToScalar(vector.y)); 1370 path->offset(SkFDot6ToScalar(vector.x), -SkFDot6ToScalar(vector.y));
1372 } 1371 }
1373 } 1372 }
1374 1373
1375 void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, 1374 void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* metrics ) {
1376 SkPaint::FontMetrics* my) { 1375 if (NULL == metrics) {
1377 if (NULL == mx && NULL == my) {
1378 return; 1376 return;
1379 } 1377 }
1380 1378
1381 SkAutoMutexAcquire ac(gFTMutex); 1379 SkAutoMutexAcquire ac(gFTMutex);
1382 1380
1383 if (this->setupSize()) { 1381 if (this->setupSize()) {
1384 ERROR: 1382 ERROR:
1385 if (mx) { 1383 sk_bzero(metrics, sizeof(*metrics));
1386 sk_bzero(mx, sizeof(SkPaint::FontMetrics));
1387 }
1388 if (my) {
1389 sk_bzero(my, sizeof(SkPaint::FontMetrics));
1390 }
1391 return; 1384 return;
1392 } 1385 }
1393 1386
1394 FT_Face face = fFace; 1387 FT_Face face = fFace;
1395 SkScalar scaleX = fScale.x(); 1388 SkScalar scaleX = fScale.x();
1396 SkScalar scaleY = fScale.y(); 1389 SkScalar scaleY = fScale.y();
1397 SkScalar mxy = fMatrix22Scalar.getSkewX() * scaleY; 1390 SkScalar mxy = fMatrix22Scalar.getSkewX() * scaleY;
1398 SkScalar myy = fMatrix22Scalar.getScaleY() * scaleY; 1391 SkScalar myy = fMatrix22Scalar.getScaleY() * scaleY;
1399 1392
1400 // fetch units/EM from "head" table if needed (ie for bitmap fonts) 1393 // fetch units/EM from "head" table if needed (ie for bitmap fonts)
(...skipping 26 matching lines...) Expand all
1427 descent = -SkIntToScalar(face->descender) / upem; 1420 descent = -SkIntToScalar(face->descender) / upem;
1428 leading = SkIntToScalar(face->height + (face->descender - face->ascender )) / upem; 1421 leading = SkIntToScalar(face->height + (face->descender - face->ascender )) / upem;
1429 xmin = SkIntToScalar(face->bbox.xMin) / upem; 1422 xmin = SkIntToScalar(face->bbox.xMin) / upem;
1430 xmax = SkIntToScalar(face->bbox.xMax) / upem; 1423 xmax = SkIntToScalar(face->bbox.xMax) / upem;
1431 ymin = -SkIntToScalar(face->bbox.yMin) / upem; 1424 ymin = -SkIntToScalar(face->bbox.yMin) / upem;
1432 ymax = -SkIntToScalar(face->bbox.yMax) / upem; 1425 ymax = -SkIntToScalar(face->bbox.yMax) / upem;
1433 underlineThickness = SkIntToScalar(face->underline_thickness) / upem; 1426 underlineThickness = SkIntToScalar(face->underline_thickness) / upem;
1434 underlinePosition = -SkIntToScalar(face->underline_position + 1427 underlinePosition = -SkIntToScalar(face->underline_position +
1435 face->underline_thickness / 2) / upem ; 1428 face->underline_thickness / 2) / upem ;
1436 1429
1437 if(mx) { 1430 metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag ;
1438 mx->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag; 1431 metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1439 mx->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag; 1432
1440 }
1441 if(my){
1442 my->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag;
1443 my->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1444 }
1445 // we may be able to synthesize x_height and cap_height from outline 1433 // we may be able to synthesize x_height and cap_height from outline
1446 if (!x_height) { 1434 if (!x_height) {
1447 FT_BBox bbox; 1435 FT_BBox bbox;
1448 if (getCBoxForLetter('x', &bbox)) { 1436 if (getCBoxForLetter('x', &bbox)) {
1449 x_height = SkIntToScalar(bbox.yMax) / 64.0f; 1437 x_height = SkIntToScalar(bbox.yMax) / 64.0f;
1450 } 1438 }
1451 } 1439 }
1452 if (!cap_height) { 1440 if (!cap_height) {
1453 FT_BBox bbox; 1441 FT_BBox bbox;
1454 if (getCBoxForLetter('H', &bbox)) { 1442 if (getCBoxForLetter('H', &bbox)) {
1455 cap_height = SkIntToScalar(bbox.yMax) / 64.0f; 1443 cap_height = SkIntToScalar(bbox.yMax) / 64.0f;
1456 } 1444 }
1457 } 1445 }
1458 } else if (fStrikeIndex != -1) { // bitmap strike metrics 1446 } else if (fStrikeIndex != -1) { // bitmap strike metrics
1459 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem); 1447 SkScalar xppem = SkIntToScalar(face->size->metrics.x_ppem);
1460 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem); 1448 SkScalar yppem = SkIntToScalar(face->size->metrics.y_ppem);
1461 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f); 1449 ascent = -SkIntToScalar(face->size->metrics.ascender) / (yppem * 64.0f);
1462 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f ); 1450 descent = -SkIntToScalar(face->size->metrics.descender) / (yppem * 64.0f );
1463 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f)) 1451 leading = (SkIntToScalar(face->size->metrics.height) / (yppem * 64.0f))
1464 + ascent - descent; 1452 + ascent - descent;
1465 xmin = 0.0f; 1453 xmin = 0.0f;
1466 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem; 1454 xmax = SkIntToScalar(face->available_sizes[fStrikeIndex].width) / xppem;
1467 ymin = descent + leading; 1455 ymin = descent + leading;
1468 ymax = ascent - descent; 1456 ymax = ascent - descent;
1469 underlineThickness = 0; 1457 underlineThickness = 0;
1470 underlinePosition = 0; 1458 underlinePosition = 0;
1471 1459
1472 if(mx) { 1460 metrics->fFlags &= ~SkPaint::FontMetrics::kUnderlineThinknessIsValid_Fla g;
1473 mx->fFlags &= ~SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag ; 1461 metrics->fFlags &= ~SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag ;
1474 mx->fFlags &= ~SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1475 }
1476 if(my){
1477 my->fFlags &= ~SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag ;
1478 my->fFlags &= ~SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
1479 }
1480 } else { 1462 } else {
1481 goto ERROR; 1463 goto ERROR;
1482 } 1464 }
1483 1465
1484 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics 1466 // synthesize elements that were not provided by the os/2 table or format-sp ecific metrics
1485 if (!x_height) { 1467 if (!x_height) {
1486 x_height = -ascent; 1468 x_height = -ascent;
1487 } 1469 }
1488 if (!avgCharWidth) { 1470 if (!avgCharWidth) {
1489 avgCharWidth = xmax - xmin; 1471 avgCharWidth = xmax - xmin;
1490 } 1472 }
1491 if (!cap_height) { 1473 if (!cap_height) {
1492 cap_height = -ascent; 1474 cap_height = -ascent;
1493 } 1475 }
1494 1476
1495 // disallow negative linespacing 1477 // disallow negative linespacing
1496 if (leading < 0.0f) { 1478 if (leading < 0.0f) {
1497 leading = 0.0f; 1479 leading = 0.0f;
1498 } 1480 }
1499 1481
1500 if (mx) { 1482 SkScalar scale = myy;
1501 mx->fTop = ymax * mxy; 1483 if (this->isVertical()) {
1502 mx->fAscent = ascent * mxy; 1484 scale = mxy;
1503 mx->fDescent = descent * mxy;
1504 mx->fBottom = ymin * mxy;
1505 mx->fLeading = leading * mxy;
1506 mx->fAvgCharWidth = avgCharWidth * mxy;
1507 mx->fXMin = xmin;
1508 mx->fXMax = xmax;
1509 mx->fXHeight = x_height;
1510 mx->fCapHeight = cap_height;
1511 mx->fUnderlineThickness = underlineThickness * mxy;
1512 mx->fUnderlinePosition = underlinePosition * mxy;
1513 } 1485 }
1514 if (my) { 1486 metrics->fTop = ymax * scale;
1515 my->fTop = ymax * myy; 1487 metrics->fAscent = ascent * scale;
1516 my->fAscent = ascent * myy; 1488 metrics->fDescent = descent * scale;
1517 my->fDescent = descent * myy; 1489 metrics->fBottom = ymin * scale;
1518 my->fBottom = ymin * myy; 1490 metrics->fLeading = leading * scale;
1519 my->fLeading = leading * myy; 1491 metrics->fAvgCharWidth = avgCharWidth * scale;
1520 my->fAvgCharWidth = avgCharWidth * myy; 1492 metrics->fXMin = xmin;
1521 my->fXMin = xmin; 1493 metrics->fXMax = xmax;
1522 my->fXMax = xmax; 1494 metrics->fXHeight = x_height;
1523 my->fXHeight = x_height; 1495 metrics->fCapHeight = cap_height;
1524 my->fCapHeight = cap_height; 1496 metrics->fUnderlineThickness = underlineThickness * scale;
1525 my->fUnderlineThickness = underlineThickness * myy; 1497 metrics->fUnderlinePosition = underlinePosition * scale;
1526 my->fUnderlinePosition = underlinePosition * myy;
1527 }
1528 } 1498 }
1529 1499
1530 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph ) 1500 void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph )
1531 { 1501 {
1532 // check to see if the embolden bit is set 1502 // check to see if the embolden bit is set
1533 if (0 == (fRec.fFlags & SkScalerContext::kEmbolden_Flag)) { 1503 if (0 == (fRec.fFlags & SkScalerContext::kEmbolden_Flag)) {
1534 return; 1504 return;
1535 } 1505 }
1536 1506
1537 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 1507 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 *style = (SkTypeface::Style) tempStyle; 1722 *style = (SkTypeface::Style) tempStyle;
1753 } 1723 }
1754 if (isFixedPitch) { 1724 if (isFixedPitch) {
1755 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1725 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1756 } 1726 }
1757 1727
1758 FT_Done_Face(face); 1728 FT_Done_Face(face);
1759 FT_Done_FreeType(library); 1729 FT_Done_FreeType(library);
1760 return true; 1730 return true;
1761 } 1731 }
OLDNEW
« no previous file with comments | « src/fonts/SkTestScalerContext.cpp ('k') | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698