aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-15 19:42:57 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-15 19:42:57 +0000
commit7bdd614a1940935d3badeb54f7aae75d76ea830d (patch)
treeaeb3d7e8d8b68cb9d1fb77a0def97f689a2876d7 /src
parent78b38b130deb8bcfa41611039875ce0162542ac1 (diff)
Implement onCountGlyphs and onGetUPEM on Windows.
R=vandebo@chromium.org Review URL: https://codereview.chromium.org/19231003 git-svn-id: http://skia.googlecode.com/svn/trunk@10089 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkTypeface.cpp5
-rwxr-xr-xsrc/ports/SkFontHost_win.cpp78
-rw-r--r--src/ports/SkFontHost_win_dw.cpp12
3 files changed, 81 insertions, 14 deletions
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index dcdd5e29f3..294323841c 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -214,11 +214,6 @@ int SkTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
return 0;
}
-int SkTypeface::onCountGlyphs() const {
- SkDebugf("onCountGlyphs unimplemented\n");
- return 0;
-}
-
int SkTypeface::onGetUPEM() const {
int upem = 0;
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index d07307e6fd..22385934ed 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -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,21 @@ static inline FIXED SkScalarToFIXED(SkScalar x) {
return SkFixedToFIXED(SkScalarToFixed(x));
}
-static unsigned calculateOutlineGlyphCount(HDC hdc) {
+static unsigned calculateGlyphCount(HDC hdc, const LOGFONT& lf) {
+ TEXTMETRIC textMetric;
+ if (0 == GetTextMetrics(hdc, &textMetric)) {
+ textMetric.tmPitchAndFamily = TMPF_VECTOR;
+ call_ensure_accessible(lf);
+ GetTextMetrics(hdc, &textMetric);
+ }
+
+ 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 +177,28 @@ static unsigned calculateOutlineGlyphCount(HDC hdc) {
return min;
}
+static unsigned calculateUPEM(HDC hdc, const LOGFONT& lf) {
+ TEXTMETRIC textMetric;
+ if (0 == GetTextMetrics(hdc, &textMetric)) {
+ textMetric.tmPitchAndFamily = TMPF_VECTOR;
+ call_ensure_accessible(lf);
+ GetTextMetrics(hdc, &textMetric);
+ }
+
+ 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 +260,8 @@ protected:
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 +758,8 @@ bool SkScalerContext_Windows::isValid() const {
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 +1478,7 @@ SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics(
if (!GetOutlineTextMetrics(hdc, sizeof(otm), &otm)) {
goto Error;
}
- glyphCount = calculateOutlineGlyphCount(hdc);
+ glyphCount = calculateGlyphCount(hdc, fLogFont);
info = new SkAdvancedTypefaceMetrics;
info->fEmSize = otm.otmEMSquare;
@@ -1684,6 +1716,34 @@ SkStream* LogFontTypeface::onOpenStream(int* ttcIndex) const {
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));
diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp
index 29fa09857b..3772a092d3 100644
--- a/src/ports/SkFontHost_win_dw.cpp
+++ b/src/ports/SkFontHost_win_dw.cpp
@@ -492,6 +492,8 @@ protected:
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 SkScalerContext_Windows : public SkScalerContext {
@@ -1071,6 +1073,16 @@ void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
*isLocalStream = SkToBool(fDWriteFontFileLoader.get());
}
+int DWriteFontTypeface::onCountGlyphs() const {
+ return fDWriteFontFace->GetGlyphCount();
+}
+
+int DWriteFontTypeface::onGetUPEM() const {
+ DWRITE_FONT_METRICS metrics;
+ fDWriteFontFace->GetMetrics(&metrics);
+ return metrics.designUnitsPerEm;
+}
+
template <typename T> class SkAutoIDWriteUnregister {
public:
SkAutoIDWriteUnregister(IDWriteFactory* factory, T* unregister)