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

Unified Diff: src/ports/SkFontHost_win.cpp

Issue 667023002: Revert of Replace SkTypeface::Style with SkFontStyle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkFontHost_mac.cpp ('k') | src/ports/SkFontMgr_android.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_win.cpp
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 348246b89329d49fb481aafe9365ecd1139f1cdc..1290c007a5fd5217d20f4d9fc31ee55d53d3e423 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -126,10 +126,20 @@
// lf->lfClipPrecision = 64;
}
-static SkFontStyle get_style(const LOGFONT& lf) {
- return SkFontStyle(lf.lfWeight,
- lf.lfWidth,
- lf.lfItalic ? SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant);
+static SkTypeface::Style get_style(const LOGFONT& lf) {
+ unsigned style = 0;
+ if (lf.lfWeight >= FW_BOLD) {
+ style |= SkTypeface::kBold;
+ }
+ if (lf.lfItalic) {
+ style |= SkTypeface::kItalic;
+ }
+ return static_cast<SkTypeface::Style>(style);
+}
+
+static void setStyle(LOGFONT* lf, SkTypeface::Style style) {
+ lf->lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL ;
+ lf->lfItalic = ((style & SkTypeface::kItalic) != 0);
}
static inline FIXED SkFixedToFIXED(SkFixed x) {
@@ -207,11 +217,8 @@
class LogFontTypeface : public SkTypeface {
public:
- LogFontTypeface(const SkFontStyle& style, const LOGFONT& lf, bool serializeAsStream)
- : SkTypeface(style, SkTypefaceCache::NewFontID(), false)
- , fLogFont(lf)
- , fSerializeAsStream(serializeAsStream)
- {
+ LogFontTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, bool serializeAsStream = false) :
+ SkTypeface(style, fontID, false), fLogFont(lf), fSerializeAsStream(serializeAsStream) {
// If the font has cubic outlines, it will not be rendered with ClearType.
HFONT font = CreateFontIndirect(&lf);
@@ -248,7 +255,9 @@
bool fCanBeLCD;
static LogFontTypeface* Create(const LOGFONT& lf) {
- return new LogFontTypeface(get_style(lf), lf, false);
+ SkTypeface::Style style = get_style(lf);
+ SkFontID fontID = SkTypefaceCache::NewFontID();
+ return new LogFontTypeface(style, fontID, lf);
}
static void EnsureAccessible(const SkTypeface* face) {
@@ -280,7 +289,9 @@
* The created FontMemResourceTypeface takes ownership of fontMemResource.
*/
static FontMemResourceTypeface* Create(const LOGFONT& lf, HANDLE fontMemResource) {
- return new FontMemResourceTypeface(get_style(lf), lf, fontMemResource);
+ SkTypeface::Style style = get_style(lf);
+ SkFontID fontID = SkTypefaceCache::NewFontID();
+ return new FontMemResourceTypeface(style, fontID, lf, fontMemResource);
}
protected:
@@ -294,9 +305,9 @@
/**
* Takes ownership of fontMemResource.
*/
- FontMemResourceTypeface(const SkFontStyle& style, const LOGFONT& lf, HANDLE fontMemResource)
- : LogFontTypeface(style, lf, true), fFontMemResource(fontMemResource)
- { }
+ FontMemResourceTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, HANDLE fontMemResource) :
+ LogFontTypeface(style, fontID, lf, true), fFontMemResource(fontMemResource) {
+ }
HANDLE fFontMemResource;
@@ -308,7 +319,7 @@
return gDefaultFont;
}
-static bool FindByLogFont(SkTypeface* face, const SkFontStyle& requestedStyle, void* ctx) {
+static bool FindByLogFont(SkTypeface* face, SkTypeface::Style requestedStyle, void* ctx) {
LogFontTypeface* lface = static_cast<LogFontTypeface*>(face);
const LOGFONT* lf = reinterpret_cast<const LOGFONT*>(ctx);
@@ -2446,6 +2457,12 @@
return 1; // non-zero means continue
}
+static SkFontStyle compute_fontstyle(const LOGFONT& lf) {
+ return SkFontStyle(lf.lfWeight, SkFontStyle::kNormal_Width,
+ lf.lfItalic ? SkFontStyle::kItalic_Slant
+ : SkFontStyle::kUpright_Slant);
+}
+
class SkFontStyleSetGDI : public SkFontStyleSet {
public:
SkFontStyleSetGDI(const TCHAR familyName[]) {
@@ -2465,7 +2482,7 @@
virtual void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OVERRIDE {
if (fs) {
- *fs = get_style(fArray[index].elfLogFont);
+ *fs = compute_fontstyle(fArray[index].elfLogFont);
}
if (styleName) {
const ENUMLOGFONTEX& ref = fArray[index];
@@ -2568,10 +2585,7 @@
} else {
logfont_for_name(familyName, &lf);
}
-
- SkTypeface::Style style = (SkTypeface::Style)styleBits;
- lf.lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL;
- lf.lfItalic = ((style & SkTypeface::kItalic) != 0);
+ setStyle(&lf, (SkTypeface::Style)styleBits);
return SkCreateTypefaceFromLOGFONT(lf);
}
« no previous file with comments | « src/ports/SkFontHost_mac.cpp ('k') | src/ports/SkFontMgr_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698