Implement SkScalerContext_Windows::generateGlyphCount() and provide access via SkGlyphCache interface.

* This will be used by PDF font code.

Review URL: http://codereview.appspot.com/4261042

git-svn-id: http://skia.googlecode.com/svn/trunk@888 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
ctguil@chromium.org 2011-03-04 19:04:57 +00:00
Родитель ee8c3176e5
Коммит 0bc7bf5fe4
9 изменённых файлов: 55 добавлений и 16 удалений

Просмотреть файл

@ -230,7 +230,7 @@ public:
*/
SkUnichar glyphIDToChar(uint16_t glyphID);
unsigned getGlyphCount() const { return this->generateGlyphCount(); }
unsigned getGlyphCount() { return this->generateGlyphCount(); }
void getAdvance(SkGlyph*);
void getMetrics(SkGlyph*);
void getImage(const SkGlyph&);
@ -245,7 +245,7 @@ protected:
Rec fRec;
unsigned fBaseGlyphCount;
virtual unsigned generateGlyphCount() const = 0;
virtual unsigned generateGlyphCount() = 0;
virtual uint16_t generateCharToGlyph(SkUnichar) = 0;
virtual void generateAdvance(SkGlyph*) = 0;
virtual void generateMetrics(SkGlyph*) = 0;

Просмотреть файл

@ -117,6 +117,10 @@ SkUnichar SkGlyphCache::glyphToUnichar(uint16_t glyphID) {
return fScalerContext->glyphIDToChar(glyphID);
}
unsigned SkGlyphCache::getGlyphCount() {
return fScalerContext->getGlyphCount();
}
///////////////////////////////////////////////////////////////////////////////
const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) {

Просмотреть файл

@ -77,6 +77,10 @@ public:
*/
SkUnichar glyphToUnichar(uint16_t);
/** Returns the number of glyphs for this strike.
*/
unsigned getGlyphCount();
/** Return the image associated with the glyph. If it has not been generated
this will trigger that.
*/

Просмотреть файл

@ -645,7 +645,7 @@ public:
SkScalerContext_Empty(const SkDescriptor* desc) : SkScalerContext(desc) {}
protected:
virtual unsigned generateGlyphCount() const {
virtual unsigned generateGlyphCount() {
return 0;
}
virtual uint16_t generateCharToGlyph(SkUnichar uni) {

Просмотреть файл

@ -121,7 +121,7 @@ public:
}
protected:
virtual unsigned generateGlyphCount() const;
virtual unsigned generateGlyphCount();
virtual uint16_t generateCharToGlyph(SkUnichar uni);
virtual void generateAdvance(SkGlyph* glyph);
virtual void generateMetrics(SkGlyph* glyph);
@ -731,7 +731,7 @@ void SkScalerContext_FreeType::emboldenOutline(FT_Outline* outline) {
FT_Outline_Embolden(outline, strength);
}
unsigned SkScalerContext_FreeType::generateGlyphCount() const {
unsigned SkScalerContext_FreeType::generateGlyphCount() {
return fFace->num_glyphs;
}

Просмотреть файл

@ -22,7 +22,7 @@ public:
virtual ~SkScalerContext_Ascender();
protected:
virtual unsigned generateGlyphCount() const;
virtual unsigned generateGlyphCount();
virtual uint16_t generateCharToGlyph(SkUnichar uni);
virtual void generateMetrics(SkGlyph* glyph);
virtual void generateImage(const SkGlyph& glyph);
@ -102,7 +102,7 @@ SkScalerContext_Ascender::~SkScalerContext_Ascender()
sk_free(fHandle);
}
unsigned SkScalerContext_Ascender::generateGlyphCount() const
unsigned SkScalerContext_Ascender::generateGlyphCount()
{
return 1000;
}

Просмотреть файл

@ -87,7 +87,7 @@ public:
virtual ~SkScalerContext_Mac();
protected:
virtual unsigned generateGlyphCount() const;
virtual unsigned generateGlyphCount();
virtual uint16_t generateCharToGlyph(SkUnichar uni);
virtual void generateAdvance(SkGlyph* glyph);
virtual void generateMetrics(SkGlyph* glyph);
@ -184,7 +184,7 @@ SkScalerContext_Mac::~SkScalerContext_Mac() {
// man, we need to consider caching this, since it is just dependent on
// fFontID, and not on any of the other settings like matrix or flags
unsigned SkScalerContext_Mac::generateGlyphCount() const {
unsigned SkScalerContext_Mac::generateGlyphCount() {
// The 'maxp' table stores the number of glyphs a offset 4, in 2 bytes
uint16_t numGlyphs;
if (SkFontHost::GetTableData(fRec.fFontID,

Просмотреть файл

@ -314,7 +314,7 @@ public:
protected:
unsigned generateGlyphCount(void) const;
unsigned generateGlyphCount(void);
uint16_t generateCharToGlyph(SkUnichar uni);
void generateAdvance(SkGlyph* glyph);
void generateMetrics(SkGlyph* glyph);
@ -373,7 +373,7 @@ SkScalerContext_Mac::~SkScalerContext_Mac(void)
CFSafeRelease(mFont);
}
unsigned SkScalerContext_Mac::generateGlyphCount(void) const
unsigned SkScalerContext_Mac::generateGlyphCount(void)
{
return(mGlyphCount);
}

Просмотреть файл

@ -17,6 +17,7 @@
#include "SkString.h"
//#include "SkStream.h"
#include "SkEndian.h"
#include "SkFontHost.h"
#include "SkDescriptor.h"
#include "SkAdvancedTypefaceMetrics.h"
@ -63,6 +64,32 @@ static inline FIXED SkScalarToFIXED(SkScalar x) {
return SkFixedToFIXED(SkScalarToFixed(x));
}
static unsigned calculateGlyphCount(HDC hdc) {
// The 'maxp' table stores the number of glyphs at offset 4, in 2 bytes.
const DWORD maxpTag = *(DWORD*) "maxp";
uint16_t glyphs;
if (GetFontData(hdc, maxpTag, 4, &glyphs, sizeof(glyphs)) != GDI_ERROR) {
return SkEndian_SwapBE16(glyphs);
}
// Binary search for glyph count.
static const MAT2 mat2 = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
int32_t max = SK_MaxU16 + 1;
int32_t min = 0;
GLYPHMETRICS gm;
while (min < max) {
int32_t mid = min + ((max - min) / 2);
if (GetGlyphOutlineW(hdc, mid, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0,
NULL, &mat2) == GDI_ERROR) {
max = mid;
} else {
min = mid + 1;
}
}
SkASSERT(min == max);
return min;
}
static SkTypeface::Style GetFontStyle(const LOGFONT& lf) {
int style = SkTypeface::kNormal;
if (lf.lfWeight == FW_SEMIBOLD || lf.lfWeight == FW_DEMIBOLD || lf.lfWeight == FW_BOLD)
@ -188,7 +215,7 @@ public:
virtual ~SkScalerContext_Windows();
protected:
virtual unsigned generateGlyphCount() const;
virtual unsigned generateGlyphCount();
virtual uint16_t generateCharToGlyph(SkUnichar uni);
virtual void generateAdvance(SkGlyph* glyph);
virtual void generateMetrics(SkGlyph* glyph);
@ -203,10 +230,12 @@ private:
HFONT fSavefont;
HFONT fFont;
SCRIPT_CACHE fSC;
int fGlyphCount;
};
SkScalerContext_Windows::SkScalerContext_Windows(const SkDescriptor* desc)
: SkScalerContext(desc), fDDC(0), fFont(0), fSavefont(0), fSC(0) {
: SkScalerContext(desc), fDDC(0), fFont(0), fSavefont(0), fSC(0)
, fGlyphCount(-1) {
SkAutoMutexAcquire ac(gFTMutex);
fScale = fRec.fTextSize / gCanonicalTextSize;
@ -239,9 +268,11 @@ SkScalerContext_Windows::~SkScalerContext_Windows() {
}
}
unsigned SkScalerContext_Windows::generateGlyphCount() const {
return 0xFFFF;
// return fFace->num_glyphs;
unsigned SkScalerContext_Windows::generateGlyphCount() {
if (fGlyphCount < 0) {
fGlyphCount = calculateGlyphCount(fDDC);
}
return fGlyphCount;
}
uint16_t SkScalerContext_Windows::generateCharToGlyph(SkUnichar uni) {