aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontHost_win.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@google.com>2014-10-20 12:54:31 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-20 12:54:31 -0700
commit802ad83dca2efd57fde6c7ba666555ea78b5324c (patch)
treede3ef90d0e9906ee2c16388b58e17e12976d833b /src/ports/SkFontHost_win.cpp
parent43b8b36b20ae00e2d78421c4cda1f3f922983a20 (diff)
Revert of Replace SkTypeface::Style with SkFontStyle. (patchset #9 id:160001 of https://codereview.chromium.org/488143002/)
Reason for revert: CrOS GM failures: [*] 2 ExpectationsMismatch: fontmgr_iter_565.png fontmgr_iter_8888.png Original issue's description: > Replace SkTypeface::Style with SkFontStyle. > > Committed: https://skia.googlesource.com/skia/+/43b8b36b20ae00e2d78421c4cda1f3f922983a20 TBR=reed@google.com,bungeman@google.com NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/667023002
Diffstat (limited to 'src/ports/SkFontHost_win.cpp')
-rwxr-xr-xsrc/ports/SkFontHost_win.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 348246b893..1290c007a5 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -126,10 +126,20 @@ static void make_canonical(LOGFONT* lf) {
// 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 @@ static unsigned calculateUPEM(HDC hdc, const LOGFONT& lf) {
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 @@ public:
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 @@ public:
* 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 @@ private:
/**
* 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 @@ static const LOGFONT& get_default_font() {
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 @@ static int CALLBACK enum_family_proc(const LOGFONT* lf, const TEXTMETRIC*,
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 @@ public:
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 @@ protected:
} 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);
}