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

Unified Diff: src/ports/SkFontHost_win.cpp

Issue 19231003: Implement onCountGlyphs and onGetUPEM on Windows. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: src/ports/SkFontHost_win.cpp
===================================================================
--- src/ports/SkFontHost_win.cpp (revision 10083)
+++ src/ports/SkFontHost_win.cpp (working copy)
@@ -15,6 +15,7 @@
#include "SkFontHost.h"
#include "SkGlyph.h"
#include "SkMaskGamma.h"
+#include "SkOTTable_maxp.h"
#include "SkOTUtils.h"
#include "SkPath.h"
#include "SkStream.h"
@@ -140,12 +141,22 @@
return SkFixedToFIXED(SkScalarToFixed(x));
}
-static unsigned calculateOutlineGlyphCount(HDC hdc) {
+static unsigned calculateGlyphCount(HDC hdc, const LOGFONT& lf) {
+ TEXTMETRIC textMetric;
+ if (0 == GetTextMetrics(hdc, &textMetric)) {
+ call_ensure_accessible(lf);
+ if (0 == GetTextMetrics(hdc, &textMetric)) {
+ textMetric.tmPitchAndFamily = TMPF_TRUETYPE;
vandebo (ex-Chrome) 2013/07/15 17:32:56 Maybe put this on line 146 to make it more obvious
bungeman-skia 2013/07/15 18:21:36 Done. I dislike unneeded stores, but I suppose I d
+ }
+ }
+
+ if (!(textMetric.tmPitchAndFamily & TMPF_VECTOR)) {
+ return textMetric.tmLastChar;
+ }
+
// The 'maxp' table stores the number of glyphs at offset 4, in 2 bytes.
- const DWORD maxpTag =
- SkEndian_SwapBE32(SkSetFourByteTag('m', 'a', 'x', 'p'));
uint16_t glyphs;
- if (GetFontData(hdc, maxpTag, 4, &glyphs, sizeof(glyphs)) != GDI_ERROR) {
+ if (GDI_ERROR != GetFontData(hdc, SkOTTableMaximumProfile::TAG, 4, &glyphs, sizeof(glyphs))) {
return SkEndian_SwapBE16(glyphs);
}
@@ -167,6 +178,29 @@
return min;
}
+static unsigned calculateUPEM(HDC hdc, const LOGFONT& lf) {
+ TEXTMETRIC textMetric;
vandebo (ex-Chrome) 2013/07/15 17:32:56 If you pull this out into a helper function you co
bungeman-skia 2013/07/15 18:21:36 This doesn't want to be in a helper, it wants to b
+ if (0 == GetTextMetrics(hdc, &textMetric)) {
+ call_ensure_accessible(lf);
+ if (0 == GetTextMetrics(hdc, &textMetric)) {
+ textMetric.tmPitchAndFamily = TMPF_TRUETYPE;
+ }
+ }
+
+ if (!(textMetric.tmPitchAndFamily & TMPF_VECTOR)) {
+ return textMetric.tmMaxCharWidth;
+ }
+
+ OUTLINETEXTMETRIC otm;
+ unsigned int otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm);
+ if (0 == otmRet) {
+ call_ensure_accessible(lf);
+ otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm);
+ }
+
+ return (0 == otmRet) ? 0 : otm.otmEMSquare;
+}
+
class LogFontTypeface : public SkTypeface {
public:
LogFontTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, bool serializeAsStream = false) :
@@ -228,6 +262,8 @@
SkAdvancedTypefaceMetrics::PerGlyphInfo,
const uint32_t*, uint32_t) const SK_OVERRIDE;
virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE;
+ virtual int onCountGlyphs() const SK_OVERRIDE;
+ virtual int onGetUPEM() const SK_OVERRIDE;
};
class FontMemResourceTypeface : public LogFontTypeface {
@@ -724,10 +760,8 @@
unsigned SkScalerContext_Windows::generateGlyphCount() {
if (fGlyphCount < 0) {
- if (fType == SkScalerContext_Windows::kBitmap_Type) {
- return fTM.tmLastChar;
- }
- fGlyphCount = calculateOutlineGlyphCount(fDDC);
+ fGlyphCount = calculateGlyphCount(
+ fDDC, static_cast<const LogFontTypeface*>(this->getTypeface())->fLogFont);
}
return fGlyphCount;
}
@@ -1446,7 +1480,7 @@
if (!GetOutlineTextMetrics(hdc, sizeof(otm), &otm)) {
goto Error;
}
- glyphCount = calculateOutlineGlyphCount(hdc);
+ glyphCount = calculateGlyphCount(hdc, fLogFont);
info = new SkAdvancedTypefaceMetrics;
info->fEmSize = otm.otmEMSquare;
@@ -1684,6 +1718,34 @@
return stream;
}
+int LogFontTypeface::onCountGlyphs() const {
+ HDC hdc = ::CreateCompatibleDC(NULL);
+ HFONT font = CreateFontIndirect(&fLogFont);
+ HFONT savefont = (HFONT)SelectObject(hdc, font);
+
+ unsigned int glyphCount = calculateGlyphCount(hdc, fLogFont);
+
+ SelectObject(hdc, savefont);
+ DeleteObject(font);
+ DeleteDC(hdc);
+
+ return glyphCount;
+}
+
+int LogFontTypeface::onGetUPEM() const {
+ HDC hdc = ::CreateCompatibleDC(NULL);
+ HFONT font = CreateFontIndirect(&fLogFont);
+ HFONT savefont = (HFONT)SelectObject(hdc, font);
+
+ unsigned int upem = calculateUPEM(hdc, fLogFont);
+
+ SelectObject(hdc, savefont);
+ DeleteObject(font);
+ DeleteDC(hdc);
+
+ return upem;
+}
+
SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
SkScalerContext_Windows* ctx = SkNEW_ARGS(SkScalerContext_Windows,
(const_cast<LogFontTypeface*>(this), desc));

Powered by Google App Engine
This is Rietveld 408576698