add 2nd parameter to SkFontHost::NextLogicalFont()

needed by android to map different styles of fallback fonts



git-svn-id: http://skia.googlecode.com/svn/trunk@1562 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-06-13 13:01:10 +00:00
parent 80afbf08eb
commit 7d26c590f6
12 changed files with 32 additions and 23 deletions

View File

@ -150,14 +150,22 @@ public:
*/
static SkScalerContext* CreateScalerContext(const SkDescriptor* desc);
/** Given a "current" fontID, return the next logical fontID to use
when searching fonts for a given unicode value. Typically the caller
will query a given font, and if a unicode value is not supported, they
will call this, and if 0 is not returned, will search that font, and so
on. This process must be finite, and when the fonthost sees a
font with no logical successor, it must return 0.
*/
static uint32_t NextLogicalFont(SkFontID fontID);
/**
* Given a "current" fontID, return the next logical fontID to use
* when searching fonts for a given unicode value. Typically the caller
* will query a given font, and if a unicode value is not supported, they
* will call this, and if 0 is not returned, will search that font, and so
* on. This process must be finite, and when the fonthost sees a
* font with no logical successor, it must return 0.
*
* The original fontID is also provided. This is the initial font that was
* stored in the typeface of the caller. It is provided as an aid to choose
* the best next logical font. e.g. If the original font was bold or serif,
* but the 2nd in the logical chain was plain, then a subsequent call to
* get the 3rd can still inspect the original, and try to match its
* stylistic attributes.
*/
static SkFontID NextLogicalFont(SkFontID currFontID, SkFontID origFontID);
///////////////////////////////////////////////////////////////////////////

View File

@ -189,6 +189,7 @@ private:
};
public:
struct Rec {
uint32_t fOrigFontID;
uint32_t fFontID;
SkScalar fTextSize, fPreScaleX, fPreSkewX;
SkScalar fPost2x2[2][2];

View File

@ -1234,7 +1234,8 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
const SkMatrix* deviceMatrix, Rec* rec) {
SkASSERT(deviceMatrix == NULL || !deviceMatrix->hasPerspective());
rec->fFontID = SkTypeface::UniqueID(paint.getTypeface());
rec->fOrigFontID = SkTypeface::UniqueID(paint.getTypeface());
rec->fFontID = rec->fOrigFontID;
rec->fTextSize = paint.getTextSize();
rec->fPreScaleX = paint.getTextScaleX();
rec->fPreSkewX = paint.getTextSkewX();

View File

@ -180,7 +180,7 @@ static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) {
// fonthost will determine the next possible font to search, based
// on the current font in fRec. It will return NULL if ctx is our
// last font that can be searched (i.e. ultimate fallback font)
uint32_t newFontID = SkFontHost::NextLogicalFont(rec.fFontID);
uint32_t newFontID = SkFontHost::NextLogicalFont(rec.fFontID, rec.fOrigFontID);
if (0 == newFontID) {
return NULL;
}

View File

@ -632,7 +632,7 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
}
}
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
load_system_fonts();
/* First see if fontID is already one of our fallbacks. If so, return
@ -642,7 +642,7 @@ uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
*/
const uint32_t* list = gFallbackFonts;
for (int i = 0; list[i] != 0; i++) {
if (list[i] == fontID) {
if (list[i] == currFontID) {
return list[i+1];
}
}

View File

@ -364,8 +364,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
return NULL;
}
// static
uint32_t SkFontHost::NextLogicalFont(SkFontID fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
// We don't handle font fallback, WebKit does.
return 0;
}

View File

@ -578,7 +578,7 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
return 0;
}
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
return 0;
}

View File

@ -491,9 +491,9 @@ SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
return new SkScalerContext_Mac(desc);
}
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
uint32_t newFontID = find_default_fontID();
if (newFontID == fontID) {
if (newFontID == currFontID) {
newFontID = 0;
}
return newFontID;

View File

@ -887,10 +887,10 @@ SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
return new SkScalerContext_Mac(desc);
}
SkFontID SkFontHost::NextLogicalFont(SkFontID fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
SkFontID nextFontID = 0;
SkTypeface* face = GetDefaultFace();
if (face->uniqueID() != fontID) {
if (face->uniqueID() != currFontID) {
nextFontID = face->uniqueID();
}
return nextFontID;

View File

@ -80,7 +80,7 @@ SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
return NULL;
}
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
return 0;
}

View File

@ -620,7 +620,7 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
}
}
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
load_system_fonts();
/* First see if fontID is already one of our fallbacks. If so, return
@ -630,7 +630,7 @@ uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
*/
const uint32_t* list = gFallbackFonts;
for (int i = 0; list[i] != 0; i++) {
if (list[i] == fontID) {
if (list[i] == currFontID) {
return list[i+1];
}
}

View File

@ -179,7 +179,7 @@ SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF) {
return face;
}
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
// Zero means that we don't have any fallback fonts for this fontID.
// This function is implemented on Android, but doesn't have much
// meaning here.