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

Unified Diff: src/ports/SkFontHost_FreeType.cpp

Issue 488143002: Replace SkTypeface::Style with SkFontStyle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add expectations, remove whitespace. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_FreeType.cpp
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 85f8ab94693ba3a7f0eadef6faf0184b9a3ab3b7..f3a87e52aae82fc3efb1a1122b6662f5b2cd5805 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1669,8 +1669,9 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+#include "SkTSearch.h"
/*static*/ bool SkTypeface_FreeType::ScanFont(
- SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bool* isFixedPitch)
+ SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* isFixedPitch)
{
FT_Library library;
if (FT_Init_FreeType(&library)) {
@@ -1704,19 +1705,61 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
return false;
}
- int tempStyle = SkTypeface::kNormal;
+ int weight = SkFontStyle::kNormal_Weight;
+ int width = SkFontStyle::kNormal_Width;
+ SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
if (face->style_flags & FT_STYLE_FLAG_BOLD) {
- tempStyle |= SkTypeface::kBold;
+ weight = SkFontStyle::kBold_Weight;
}
if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
- tempStyle |= SkTypeface::kItalic;
+ slant = SkFontStyle::kItalic_Slant;
+ }
+
+ PS_FontInfoRec psFontInfo;
+ TT_OS2* os2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(face, ft_sfnt_os2));
+ if (os2 && os2->version != 0xffff) {
+ weight = os2->usWeightClass;
+ width = os2->usWidthClass;
+ } else if (0 == FT_Get_PS_Font_Info(face, &psFontInfo) && psFontInfo.weight) {
+ static const struct {
+ char const * const name;
+ int const weight;
+ } commonWeights [] = {
+ // There are probably more common names, but these are known to exist.
+ { "black", SkFontStyle::kBlack_Weight },
+ { "bold", SkFontStyle::kBold_Weight },
+ { "book", (SkFontStyle::kNormal_Weight + SkFontStyle::kLight_Weight)/2 },
+ { "demi", SkFontStyle::kSemiBold_Weight },
+ { "demibold", SkFontStyle::kSemiBold_Weight },
+ { "extrabold", SkFontStyle::kExtraBold_Weight },
+ { "extralight", SkFontStyle::kExtraLight_Weight },
+ { "heavy", SkFontStyle::kBlack_Weight },
+ { "light", SkFontStyle::kLight_Weight },
+ { "medium", SkFontStyle::kMedium_Weight },
+ { "normal", SkFontStyle::kNormal_Weight },
+ { "regular", SkFontStyle::kNormal_Weight },
+ { "semibold", SkFontStyle::kSemiBold_Weight },
+ { "thin", SkFontStyle::kThin_Weight },
+ { "ultra", SkFontStyle::kExtraBold_Weight },
+ { "ultrablack", 1000 },
+ { "ultrabold", SkFontStyle::kExtraBold_Weight },
+ { "ultraheavy", 1000 },
+ { "ultralight", SkFontStyle::kExtraLight_Weight },
+ };
+ int const index = SkStrLCSearch(&commonWeights[0].name, SK_ARRAY_COUNT(commonWeights),
+ psFontInfo.weight, sizeof(commonWeights));
+ if (index >= 0) {
+ weight = commonWeights[index].weight;
+ } else {
+ SkDEBUGF(("Do not know weight for: %s\n", psFontInfo.weight));
+ }
}
if (name) {
name->set(face->family_name);
}
if (style) {
- *style = (SkTypeface::Style) tempStyle;
+ *style = SkFontStyle(weight, width, slant);
}
if (isFixedPitch) {
*isFixedPitch = FT_IS_FIXED_WIDTH(face);
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698