aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkFontHost.h28
-rw-r--r--include/core/SkTypeface.h5
-rw-r--r--src/core/SkScalerContext.cpp24
-rw-r--r--src/core/SkScalerContext.h14
-rw-r--r--src/core/SkTypeface.cpp10
-rw-r--r--src/ports/SkFontHost_FreeType.cpp32
-rw-r--r--src/ports/SkFontHost_FreeType_common.h29
-rw-r--r--src/ports/SkFontHost_android.cpp17
-rw-r--r--src/ports/SkFontHost_fontconfig.cpp13
-rw-r--r--src/ports/SkFontHost_freetype_mac.cpp4
-rw-r--r--src/ports/SkFontHost_linux.cpp4
-rwxr-xr-xsrc/ports/SkFontHost_mac.cpp32
-rw-r--r--src/ports/SkFontHost_none.cpp11
-rw-r--r--src/ports/SkFontHost_simple.cpp8
-rwxr-xr-xsrc/ports/SkFontHost_win.cpp24
-rw-r--r--src/ports/SkFontHost_win_dw.cpp25
16 files changed, 134 insertions, 146 deletions
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index 132e0db09e..b48c565352 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -110,20 +110,14 @@ public:
static void EnsureTypefaceAccessible(const SkTypeface& typeface);
/**
- * Return a subclass of SkScalarContext
- * DEPRECATED -- will be moved to SkTypeface
- */
- static SkScalerContext* CreateScalerContext(const SkDescriptor* desc);
-
- /**
* DEPRECATED -- will be DESTROYED
*
- * Given a "current" fontID, return the next logical fontID to use
+ * Given a "current" fontID, return a ref to the next logical typeface
* 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.
+ * font with no logical successor, it must return NULL.
*
* 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
@@ -132,7 +126,7 @@ public:
* get the 3rd can still inspect the original, and try to match its
* stylistic attributes.
*/
- static SkFontID NextLogicalFont(SkFontID currFontID, SkFontID origFontID);
+ static SkTypeface* NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID);
///// public HACK FOR FREETYPE -- will be fixed
@@ -224,22 +218,6 @@ private:
///////////////////////////////////////////////////////////////////////////
- /** Given a filled-out rec, the fonthost may decide to modify it to reflect
- what the host is actually capable of fulfilling. For example, if the
- rec is requesting a level of hinting that, for this host, maps some
- other level (e.g. kFull -> kNormal), it should update the rec to reflect
- what will actually be done. This is an optimization so that the font
- cache does not contain different recs (i.e. keys) that in reality map to
- the same output.
-
- A lazy (but valid) fonthost can do nothing in its FilterRec routine.
-
- The provided typeface corresponds to the fFontID field.
- */
- static void FilterRec(SkScalerContextRec* rec, SkTypeface* typeface);
-
- ///////////////////////////////////////////////////////////////////////////
-
/** Retrieve detailed typeface metrics. Used by the PDF backend.
@param perGlyphInfo Indicate what glyph specific information (advances,
names, etc.) should be populated.
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 45779dcf1a..50a724a8e9 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -205,12 +205,13 @@ protected:
friend class SkScalerContext;
static SkTypeface* GetDefaultTypeface();
+ virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0;
+ virtual void onFilterRec(SkScalerContextRec*) const = 0;
+
virtual int onGetUPEM() const;
virtual int onGetTableTags(SkFontTableTag tags[]) const;
virtual size_t onGetTableData(SkFontTableTag, size_t offset,
size_t length, void* data) const;
- virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const;
- virtual void onFilterRec(SkScalerContextRec*) const;
virtual void onGetFontDescriptor(SkFontDescriptor*) const;
private:
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 56dcb9b7cc..109f632fd2 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -75,11 +75,11 @@ static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag) {
return obj;
}
-SkScalerContext::SkScalerContext(const SkDescriptor* desc)
+SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
: fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)))
, fBaseGlyphCount(0)
-
+ , fTypeface(SkRef(typeface))
, fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag)))
, fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag)))
, fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag)))
@@ -117,14 +117,16 @@ SkScalerContext::~SkScalerContext() {
SkSafeUnref(fRasterizer);
}
+// Return the context associated with the next logical typeface, or NULL if
+// there are no more entries in the fallback chain.
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, rec.fOrigFontID);
- if (0 == newFontID) {
+ SkTypeface* newFace = SkFontHost::NextLogicalTypeface(rec.fFontID, rec.fOrigFontID);
+ if (0 == newFace) {
return NULL;
}
+
+ SkAutoTUnref<SkTypeface> aur(newFace);
+ uint32_t newFontID = newFace->uniqueID();
SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1));
SkDescriptor* desc = ad.getDesc();
@@ -136,7 +138,7 @@ static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) {
newRec->fFontID = newFontID;
desc->computeChecksum();
- return SkFontHost::CreateScalerContext(desc);
+ return newFace->createScalerContext(desc);
}
/* Return the next context, creating it if its not already created, but return
@@ -740,7 +742,8 @@ SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix) {
class SkScalerContext_Empty : public SkScalerContext {
public:
- SkScalerContext_Empty(const SkDescriptor* desc) : SkScalerContext(desc) {}
+ SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc)
+ : SkScalerContext(face, desc) {}
protected:
virtual unsigned generateGlyphCount() SK_OVERRIDE {
@@ -776,7 +779,8 @@ SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc) const
c = this->onCreateScalerContext(desc);
}
if (NULL == c) {
- c = SkNEW_ARGS(SkScalerContext_Empty, (desc));
+ c = SkNEW_ARGS(SkScalerContext_Empty,
+ (const_cast<SkTypeface*>(this), desc));
}
return c;
}
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index a4f2ea681e..fba3e1e20d 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -12,11 +12,7 @@
#include "SkMaskGamma.h"
#include "SkMatrix.h"
#include "SkPaint.h"
-
-#ifdef SK_BUILD_FOR_ANDROID
- //For SkFontID
- #include "SkTypeface.h"
-#endif
+#include "SkTypeface.h"
struct SkGlyph;
class SkDescriptor;
@@ -149,9 +145,11 @@ public:
};
- SkScalerContext(const SkDescriptor* desc);
+ SkScalerContext(SkTypeface*, const SkDescriptor*);
virtual ~SkScalerContext();
+ SkTypeface* getTypeface() const { return fTypeface.get(); }
+
SkMask::Format getMaskFormat() const {
return (SkMask::Format)fRec.fMaskFormat;
}
@@ -217,6 +215,10 @@ protected:
void forceGenerateImageFromPath() { fGenerateImageFromPath = true; }
private:
+ // never null
+ SkAutoTUnref<SkTypeface> fTypeface;
+
+ // optional object, which may be null
SkPathEffect* fPathEffect;
SkMaskFilter* fMaskFilter;
SkRasterizer* fRasterizer;
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 80fa43825d..832a153670 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -152,16 +152,6 @@ int SkTypeface::getUnitsPerEm() const {
return upem;
}
-// TODO: move this impl into the subclass
-SkScalerContext* SkTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
- return SkFontHost::CreateScalerContext(desc);
-}
-
-// TODO: move this impl into the subclass
-void SkTypeface::onFilterRec(SkScalerContextRec* rec) const {
- SkFontHost::FilterRec(rec, const_cast<SkTypeface*>(this));
-}
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 40d939c17c..a009fc9c99 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -159,7 +159,7 @@ static bool is_lcd_supported() {
class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base {
public:
- SkScalerContext_FreeType(const SkDescriptor* desc);
+ SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc);
virtual ~SkScalerContext_FreeType();
bool success() const {
@@ -650,7 +650,19 @@ static bool isAxisAligned(const SkScalerContext::Rec& rec) {
bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1]));
}
-void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) {
+SkScalerContext* SkTypeface_FreeType::onCreateScalerContext(
+ const SkDescriptor* desc) const {
+ SkScalerContext_FreeType* c = SkNEW_ARGS(SkScalerContext_FreeType,
+ (const_cast<SkTypeface_FreeType*>(this),
+ desc));
+ if (!c->success()) {
+ SkDELETE(c);
+ c = NULL;
+ }
+ return c;
+}
+
+void SkTypeface_FreeType::onFilterRec(SkScalerContextRec* rec) const {
//BOGUS: http://code.google.com/p/chromium/issues/detail?id=121119
//Cap the requested size as larger sizes give bogus values.
//Remove when http://code.google.com/p/skia/issues/detail?id=554 is fixed.
@@ -710,8 +722,9 @@ uint32_t SkFontHost::GetUnitsPerEm(SkFontID fontID) {
}
#endif
-SkScalerContext_FreeType::SkScalerContext_FreeType(const SkDescriptor* desc)
- : SkScalerContext_FreeType_Base(desc) {
+SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface,
+ const SkDescriptor* desc)
+ : SkScalerContext_FreeType_Base(typeface, desc) {
SkAutoMutexAcquire ac(gFTMutex);
if (gFTCount == 0) {
@@ -1300,17 +1313,6 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx,
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
- SkScalerContext_FreeType* c = SkNEW_ARGS(SkScalerContext_FreeType, (desc));
- if (!c->success()) {
- SkDELETE(c);
- c = NULL;
- }
- return c;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
/* Export this so that other parts of our FonttHost port can make use of our
ability to extract the name+style from a stream, using FreeType's api.
*/
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index db32bc8256..efc74be8d7 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -11,6 +11,8 @@
#include "SkGlyph.h"
#include "SkScalerContext.h"
+#include "SkTypeface.h"
+
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -26,19 +28,34 @@
class SkScalerContext_FreeType_Base : public SkScalerContext {
-public:
+protected:
// See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
// This value was chosen by eyeballing the result in Firefox and trying to match it.
static const FT_Pos kBitmapEmboldenStrength = 1 << 6;
-
- SkScalerContext_FreeType_Base(const SkDescriptor *desc)
- : SkScalerContext(desc)
+
+ SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkDescriptor *desc)
+ : INHERITED(typeface, desc)
{}
-
-protected:
+
void generateGlyphImage(FT_Face face, const SkGlyph& glyph);
void generateGlyphPath(FT_Face face, SkPath* path);
void emboldenOutline(FT_Face face, FT_Outline* outline);
+
+private:
+ typedef SkScalerContext INHERITED;
+};
+
+class SkTypeface_FreeType : public SkTypeface {
+protected:
+ SkTypeface_FreeType(Style style, SkFontID uniqueID, bool isFixedWidth)
+ : INHERITED(style, uniqueID, isFixedWidth) {}
+
+ virtual SkScalerContext* onCreateScalerContext(
+ const SkDescriptor*) const SK_OVERRIDE;
+ virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
+
+private:
+ typedef SkTypeface INHERITED;
};
#endif // SKFONTHOST_FREETYPE_COMMON_H_
diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp
index a955b6313b..416d61d661 100644
--- a/src/ports/SkFontHost_android.cpp
+++ b/src/ports/SkFontHost_android.cpp
@@ -6,6 +6,7 @@
*/
#include "SkFontHost.h"
+#include "SkFontHost_FreeType_common.h"
#include "SkFontDescriptor.h"
#include "SkGraphics.h"
#include "SkDescriptor.h"
@@ -280,11 +281,11 @@ static void remove_from_names(FamilyRec* emptyFamily) {
///////////////////////////////////////////////////////////////////////////////
-class FamilyTypeface : public SkTypeface {
+class FamilyTypeface : public SkTypeface_FreeType {
public:
FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember,
bool isFixedWidth)
- : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) {
+ : INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) {
fIsSysFont = sysFont;
// our caller has acquired the gFamilyHeadAndNameListMutex so this is safe
@@ -319,7 +320,7 @@ public:
private:
bool fIsSysFont;
- typedef SkTypeface INHERITED;
+ typedef SkTypeface_FreeType INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
@@ -866,13 +867,13 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
}
}
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
// Skia does not support font fallback for ndk applications in order to
// enable clients such as WebKit to customize their font selection.
// Clients can use GetFallbackFamilyNameForChar() to get the fallback
// font for individual characters.
- return 0;
+ return NULL;
#else
SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
@@ -898,9 +899,9 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
for (int i = 0; list[i] != 0; i++) {
if (list[i] == currFontID) {
if (list[i+1] == 0)
- return 0;
+ return NULL;
const SkTypeface* nextTypeface = find_from_uniqueID(list[i+1]);
- return find_typeface(nextTypeface, origTypeface->style())->uniqueID();
+ return SkRef(find_typeface(nextTypeface, origTypeface->style()));
}
}
@@ -908,7 +909,7 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
// beginning of our list. Assuming there is at least one fallback font,
// i.e. gFallbackFonts[0] != 0.
const SkTypeface* firstTypeface = find_from_uniqueID(list[0]);
- return find_typeface(firstTypeface, origTypeface->style())->uniqueID();
+ return SkRef(find_typeface(firstTypeface, origTypeface->style()));
#endif
}
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index 4dd18880d2..93a93c12ad 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -8,6 +8,7 @@
#include "SkFontConfigInterface.h"
#include "SkFontDescriptor.h"
#include "SkFontHost.h"
+#include "SkFontHost_FreeType_common.h"
#include "SkFontStream.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -46,7 +47,7 @@ static SkFontConfigInterface* RefFCI() {
}
}
-class FontConfigTypeface : public SkTypeface {
+class FontConfigTypeface : public SkTypeface_FreeType {
SkFontConfigInterface::FontIdentity fIdentity;
SkString fFamilyName;
SkStream* fLocalStream;
@@ -55,13 +56,13 @@ public:
FontConfigTypeface(Style style,
const SkFontConfigInterface::FontIdentity& fi,
const SkString& familyName)
- : SkTypeface(style, SkTypefaceCache::NewFontID())
+ : INHERITED(style, SkTypefaceCache::NewFontID(), false)
, fIdentity(fi)
, fFamilyName(familyName)
, fLocalStream(NULL) {}
FontConfigTypeface(Style style, SkStream* localStream)
- : SkTypeface(style, SkTypefaceCache::NewFontID()) {
+ : INHERITED(style, SkTypefaceCache::NewFontID(), false) {
// we default to empty fFamilyName and fIdentity
fLocalStream = localStream;
SkSafeRef(localStream);
@@ -91,7 +92,7 @@ protected:
virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE;
private:
- typedef SkTypeface INHERITED;
+ typedef SkTypeface_FreeType INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
@@ -199,9 +200,9 @@ size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag,
}
// DEPRECATED
-uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) {
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) {
// We don't handle font fallback.
- return 0;
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontHost_freetype_mac.cpp b/src/ports/SkFontHost_freetype_mac.cpp
index 3d89bc613a..fb67993b77 100644
--- a/src/ports/SkFontHost_freetype_mac.cpp
+++ b/src/ports/SkFontHost_freetype_mac.cpp
@@ -96,8 +96,8 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
return NULL;
}
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
- return 0;
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
+ return NULL;
}
#include "SkTypeface_mac.h"
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index f409cd4041..e27473e771 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -545,8 +545,8 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
return 0;
}
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
- return 0;
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index ae1e75e4de..674f1fd729 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -610,8 +610,8 @@ struct GlyphRect {
class SkScalerContext_Mac : public SkScalerContext {
public:
- SkScalerContext_Mac(const SkDescriptor* desc);
- virtual ~SkScalerContext_Mac(void);
+ SkScalerContext_Mac(SkTypeface_Mac*, const SkDescriptor*);
+ virtual ~SkScalerContext_Mac();
protected:
@@ -646,10 +646,13 @@ private:
bool fVertical;
friend class Offscreen;
+
+ typedef SkScalerContext INHERITED;
};
-SkScalerContext_Mac::SkScalerContext_Mac(const SkDescriptor* desc)
- : SkScalerContext(desc)
+SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
+ const SkDescriptor* desc)
+ : INHERITED(typeface, desc)
, fFBoundingBoxes(NULL)
, fFBoundingBoxesGlyphOffset(0)
, fGeneratedFBoundingBoxes(false)
@@ -1713,23 +1716,12 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
///////////////////////////////////////////////////////////////////////////////
// DEPRECATED
-SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
- return new SkScalerContext_Mac(desc);
-}
-
-// DEPRECATED
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
- SkFontID nextFontID = 0;
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
SkTypeface* face = GetDefaultFace();
- if (face->uniqueID() != currFontID) {
- nextFontID = face->uniqueID();
+ if (face->uniqueID() == currFontID) {
+ face = NULL;
}
- return nextFontID;
-}
-
-// DEPRECATED
-void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface* face) {
- face->onFilterRec(rec);
+ return SkSafeRef(face);
}
// DEPRECATED
@@ -1815,7 +1807,7 @@ size_t SkTypeface_Mac::onGetTableData(SkFontTableTag tag, size_t offset,
}
SkScalerContext* SkTypeface_Mac::onCreateScalerContext(const SkDescriptor* desc) const {
- return new SkScalerContext_Mac(desc);
+ return new SkScalerContext_Mac(const_cast<SkTypeface_Mac*>(this), desc);
}
void SkTypeface_Mac::onFilterRec(SkScalerContextRec* rec) const {
diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp
index 6475c09deb..a0aedba7eb 100644
--- a/src/ports/SkFontHost_none.cpp
+++ b/src/ports/SkFontHost_none.cpp
@@ -37,9 +37,6 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
return NULL;
}
-void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) {
-}
-
///////////////////////////////////////////////////////////////////////////////
SkStream* SkFontHost::OpenStream(uint32_t uniqueID) {
@@ -66,11 +63,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
///////////////////////////////////////////////////////////////////////////////
-SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
- SkDEBUGFAIL("SkFontHost::CreateScalarContext unimplemented");
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID,
+ SkFontID origFontID) {
return NULL;
}
-
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
- return 0;
-}
diff --git a/src/ports/SkFontHost_simple.cpp b/src/ports/SkFontHost_simple.cpp
index b4f6ce0f1d..7d9cf6d7ff 100644
--- a/src/ports/SkFontHost_simple.cpp
+++ b/src/ports/SkFontHost_simple.cpp
@@ -394,7 +394,7 @@ static SkTypeface* gDefaultNormal;
fontIDs that can be used for fallback consideration, in sorted order (sorted
meaning element[0] should be used first, then element[1], etc. When we hit
a fontID==0 in the array, the list is done, hence our allocation size is
- +1 the total number of possible system fonts. Also see NextLogicalFont().
+ +1 the total number of possible system fonts. Also see NextLogicalTypeface().
*/
static uint32_t gFallbackFonts[SK_ARRAY_COUNT(gSystemFonts)+1];
@@ -584,7 +584,7 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
}
}
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
+SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
load_system_fonts();
/* First see if fontID is already one of our fallbacks. If so, return
@@ -595,10 +595,10 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
const uint32_t* list = gFallbackFonts;
for (int i = 0; list[i] != 0; i++) {
if (list[i] == currFontID) {
- return list[i+1];
+ return SkSafeRef(find_from_uniqueID(list[i+1]));
}
}
- return list[0];
+ return SkSafeRef(list[0]);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 383aecd78b..6c937192c6 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -190,6 +190,10 @@ public:
SkFontID fontID = SkTypefaceCache::NewFontID();
return new LogFontTypeface(style, fontID, lf);
}
+
+protected:
+ virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
+ virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
};
class FontMemResourceTypeface : public LogFontTypeface {
@@ -274,11 +278,11 @@ void SkLOGFONTFromTypeface(const SkTypeface* face, LOGFONT* lf) {
}
}
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
+SkTypeface* SkFontHost::NextLogicalTypeface(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.
- return 0;
+ return NULL;
}
static void ensure_typeface_accessible(SkFontID fontID) {
@@ -481,7 +485,7 @@ const void* HDCOffscreen::draw(const SkGlyph& glyph, bool isBW,
class SkScalerContext_Windows : public SkScalerContext {
public:
- SkScalerContext_Windows(const SkDescriptor* desc);
+ SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc);
virtual ~SkScalerContext_Windows();
protected:
@@ -549,8 +553,9 @@ static BYTE compute_quality(const SkScalerContext::Rec& rec) {
}
}
-SkScalerContext_Windows::SkScalerContext_Windows(const SkDescriptor* desc)
- : SkScalerContext(desc), fDDC(0), fFont(0), fSavefont(0), fSC(0)
+SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* typeface,
+ const SkDescriptor* desc)
+ : SkScalerContext(typeface, desc), fDDC(0), fFont(0), fSavefont(0), fSC(0)
, fGlyphCount(-1) {
SkAutoMutexAcquire ac(gFTMutex);
@@ -1608,8 +1613,8 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int3
return 0;
}
-SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
- return SkNEW_ARGS(SkScalerContext_Windows, (desc));
+SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
+ return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(this), desc));
}
/** Return the closest matching typeface given either an existing family
@@ -1642,7 +1647,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
}
-void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface* typeface) {
+void LogFontTypeface::onFilterRec(SkScalerContextRec* rec) const {
unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag |
SkScalerContext::kAutohinting_Flag |
SkScalerContext::kEmbeddedBitmapText_Flag |
@@ -1682,8 +1687,7 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface* typeface) {
}
#endif
- LogFontTypeface* logfontTypeface = static_cast<LogFontTypeface*>(typeface);
- if (!logfontTypeface->fCanBeLCD && isLCD(*rec)) {
+ if (!fCanBeLCD && isLCD(*rec)) {
rec->fMaskFormat = SkMask::kA8_Format;
rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag;
}
diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp
index f0e2002d68..1e06e381da 100644
--- a/src/ports/SkFontHost_win_dw.cpp
+++ b/src/ports/SkFontHost_win_dw.cpp
@@ -41,11 +41,11 @@ static bool isLCD(const SkScalerContext::Rec& rec) {
SkMask::kLCD32_Format == rec.fMaskFormat;
}
-SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
+SkTypeface* SkFontHost::NextLogicalTypeface(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.
- return 0;
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
@@ -477,11 +477,15 @@ public:
HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader.get()));
HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get()));
}
+
+protected:
+ virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
+ virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
};
class SkScalerContext_Windows : public SkScalerContext {
public:
- SkScalerContext_Windows(const SkDescriptor* desc);
+ SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc);
virtual ~SkScalerContext_Windows();
protected:
@@ -707,8 +711,10 @@ static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) {
return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID));
}
-SkScalerContext_Windows::SkScalerContext_Windows(const SkDescriptor* desc)
- : SkScalerContext(desc)
+SkScalerContext_Windows::SkScalerContext_Windows(DWriteFontTypeface* typeface,
+ const SkDescriptor* desc)
+ : SkScalerContext(typeface, desc)
+ , fTypeface(SkRef(typeface))
, fGlyphCount(-1) {
SkAutoMutexAcquire ac(gFTMutex);
@@ -719,9 +725,6 @@ SkScalerContext_Windows::SkScalerContext_Windows(const SkDescriptor* desc)
fXform.dx = 0;
fXform.dy = 0;
- fTypeface.reset(GetDWriteFontByID(fRec.fFontID));
- fTypeface.get()->ref();
-
fOffscreen.init(fTypeface->fDWriteFontFace.get(), fXform, SkScalarToFloat(fRec.fTextSize));
}
@@ -1162,8 +1165,8 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int3
return 0;
}
-SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
- return SkNEW_ARGS(SkScalerContext_Windows, (desc));
+SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
+ return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<DWriteFontTypeface*>(this), desc));
}
static HRESULT get_by_family_name(const char familyName[], IDWriteFontFamily** fontFamily) {
@@ -1258,7 +1261,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return NULL;
}
-void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) {
+void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag |
SkScalerContext::kAutohinting_Flag |
SkScalerContext::kEmbeddedBitmapText_Flag |