aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2014-07-11 08:52:26 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-11 08:52:26 -0700
commit3a21d61668e0ac6529f9930669dd47be123ec333 (patch)
tree565b0873ebfdc37c75a4f8b4129aea7f878f6d04
parentf94bdb84ef267fade449bd154f8c3cef7011896e (diff)
Update find_name_and_attributes to take ttc index and rename to SkTypeface_FreeType::ScanFont.
The name 'ScanFont' is to mirror the naming convention of similar functions in FontConfig. R=tomhudson@google.com Author: bungeman@google.com Review URL: https://codereview.chromium.org/382053003
-rw-r--r--src/fonts/SkFontMgr_fontconfig.cpp7
-rw-r--r--src/ports/SkFontConfigInterface_android.cpp10
-rw-r--r--src/ports/SkFontHost_FreeType.cpp10
-rw-r--r--src/ports/SkFontHost_FreeType_common.h8
-rw-r--r--src/ports/SkFontHost_fontconfig.cpp6
-rw-r--r--src/ports/SkFontHost_linux.cpp35
6 files changed, 34 insertions, 42 deletions
diff --git a/src/fonts/SkFontMgr_fontconfig.cpp b/src/fonts/SkFontMgr_fontconfig.cpp
index 2ffe8e3e86..a7f81281c3 100644
--- a/src/fonts/SkFontMgr_fontconfig.cpp
+++ b/src/fonts/SkFontMgr_fontconfig.cpp
@@ -50,11 +50,6 @@ private:
} // namespace
-
-// Defined in SkFontHost_FreeType.cpp
-bool find_name_and_attributes(SkStream* stream, SkString* name,
- SkTypeface::Style* style, bool* isFixedWidth);
-
// borrow this global from SkFontHost_fontconfig. eventually that file should
// go away, and be replaced with this one.
extern SkFontConfigInterface* SkFontHost_fontconfig_ref_global();
@@ -307,7 +302,7 @@ protected:
// TODO should the caller give us the style or should we get it from freetype?
SkTypeface::Style style = SkTypeface::kNormal;
bool isFixedWidth = false;
- if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
+ if (!SkTypeface_FreeType::ScanFont(stream, 0, NULL, &style, &isFixedWidth)) {
return NULL;
}
diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp
index 1f901b9fa9..236f62b808 100644
--- a/src/ports/SkFontConfigInterface_android.cpp
+++ b/src/ports/SkFontConfigInterface_android.cpp
@@ -11,6 +11,7 @@
#include "SkFontConfigParser_android.h"
#include "SkFontConfigTypeface.h"
+#include "SkFontHost_FreeType_common.h"
#include "SkFontMgr.h"
#include "SkGlyphCache.h"
#include "SkPaint.h"
@@ -196,10 +197,6 @@ static void insert_into_name_dict(SkTDict<FamilyRecID>& familyNameDict,
}
}
-// Defined in SkFontHost_FreeType.cpp
-bool find_name_and_attributes(SkStream* stream, SkString* name,
- SkTypeface::Style* style, bool* isFixedWidth);
-
///////////////////////////////////////////////////////////////////////////////
SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies) :
@@ -241,8 +238,9 @@ SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*
if (stream.get() != NULL) {
bool isFixedWidth;
SkString name;
- fontRec.fIsValid = find_name_and_attributes(stream.get(), &name,
- &fontRec.fStyle, &isFixedWidth);
+ fontRec.fIsValid = SkTypeface_FreeType::ScanFont(stream.get(), 0,
+ &name, &fontRec.fStyle,
+ &isFixedWidth);
} else {
if (!family->fIsFallbackFont) {
SkDebugf("---- failed to open <%s> as a font\n", filename.c_str());
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 6448beb89b..e2b0fe9ae6 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1670,11 +1670,9 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-/* 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.
-*/
-bool find_name_and_attributes(SkStream* stream, SkString* name,
- SkTypeface::Style* style, bool* isFixedPitch) {
+/*static*/ bool SkTypeface_FreeType::ScanFont(
+ SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bool* isFixedPitch)
+{
FT_Library library;
if (FT_Init_FreeType(&library)) {
return false;
@@ -1702,7 +1700,7 @@ bool find_name_and_attributes(SkStream* stream, SkString* name,
}
FT_Face face;
- if (FT_Open_Face(library, &args, 0, &face)) {
+ if (FT_Open_Face(library, &args, ttcIndex, &face)) {
FT_Done_FreeType(library);
return false;
}
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index aef4d82044..f093dba8a5 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -26,7 +26,6 @@
#define SkASSERT_CONTINUE(pred)
#endif
-
class SkScalerContext_FreeType_Base : public SkScalerContext {
protected:
// See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
@@ -45,6 +44,13 @@ private:
};
class SkTypeface_FreeType : public SkTypeface {
+public:
+ /** For SkFontMgrs to make use of our ability to extract
+ * name and style from a stream, using FreeType's API.
+ */
+ static bool ScanFont(SkStream* stream, int ttcIndex,
+ SkString* name, SkTypeface::Style* style, bool* isFixedPitch);
+
protected:
SkTypeface_FreeType(Style style, SkFontID uniqueID, bool isFixedPitch)
: INHERITED(style, uniqueID, isFixedPitch)
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index 8abf5cf7f0..6f24afc573 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -15,10 +15,6 @@
#include "SkTypeface.h"
#include "SkTypefaceCache.h"
-// Defined in SkFontHost_FreeType.cpp
-bool find_name_and_attributes(SkStream* stream, SkString* name,
- SkTypeface::Style* style, bool* isFixedWidth);
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -148,7 +144,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
// ask freetype for reported style and if it is a fixed width font
SkTypeface::Style style = SkTypeface::kNormal;
bool isFixedWidth = false;
- if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
+ if (!SkTypeface_FreeType::ScanFont(stream, 0, NULL, &style, &isFixedWidth)) {
return NULL;
}
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index d6a020067b..498d69ffe0 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -25,15 +25,12 @@
# define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/"
#endif
-bool find_name_and_attributes(SkStream* stream, SkString* name,
- SkTypeface::Style* style, bool* isFixedPitch);
-
///////////////////////////////////////////////////////////////////////////////
/** The base SkTypeface implementation for the custom font manager. */
class SkTypeface_Custom : public SkTypeface_FreeType {
public:
- SkTypeface_Custom(Style style, bool sysFont, bool isFixedPitch, const SkString familyName)
+ SkTypeface_Custom(Style style, bool isFixedPitch, bool sysFont, const SkString familyName)
: INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
, fIsSysFont(sysFont), fFamilyName(familyName)
{ }
@@ -61,7 +58,7 @@ private:
*/
class SkTypeface_Empty : public SkTypeface_Custom {
public:
- SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, true, false, SkString()) {}
+ SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, false, true, SkString()) {}
virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
@@ -75,10 +72,10 @@ private:
/** The stream SkTypeface implementation for the custom font manager. */
class SkTypeface_Stream : public SkTypeface_Custom {
public:
- SkTypeface_Stream(Style style, bool sysFont, SkStream* stream,
- bool isFixedPitch, const SkString familyName)
- : INHERITED(style, sysFont, isFixedPitch, familyName)
- , fStream(SkRef(stream))
+ SkTypeface_Stream(Style style, bool isFixedPitch, bool sysFont, const SkString familyName,
+ SkStream* stream, int ttcIndex)
+ : INHERITED(style, isFixedPitch, sysFont, familyName)
+ , fStream(SkRef(stream)), fTtcIndex(ttcIndex)
{ }
virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
@@ -91,6 +88,7 @@ protected:
private:
SkAutoTUnref<SkStream> fStream;
+ int fTtcIndex;
typedef SkTypeface_Custom INHERITED;
};
@@ -98,9 +96,9 @@ private:
/** The file SkTypeface implementation for the custom font manager. */
class SkTypeface_File : public SkTypeface_Custom {
public:
- SkTypeface_File(Style style, bool sysFont, const char path[],
- bool isFixedPitch, const SkString familyName)
- : INHERITED(style, sysFont, isFixedPitch, familyName)
+ SkTypeface_File(Style style, bool isFixedPitch, bool sysFont, const SkString familyName,
+ const char path[])
+ : INHERITED(style, isFixedPitch, sysFont, familyName)
, fPath(path)
{ }
@@ -269,8 +267,9 @@ protected:
bool isFixedPitch;
SkTypeface::Style style;
SkString name;
- if (find_name_and_attributes(stream, &name, &style, &isFixedPitch)) {
- return SkNEW_ARGS(SkTypeface_Stream, (style, false, stream, isFixedPitch, name));
+ if (SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
+ return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, name,
+ stream, ttcIndex));
} else {
return NULL;
}
@@ -311,7 +310,7 @@ private:
SkTypeface::Style* style, bool* isFixedPitch) {
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get()) {
- return find_name_and_attributes(stream, name, style, isFixedPitch);
+ return SkTypeface_FreeType::ScanFont(stream, 0, name, style, isFixedPitch);
} else {
SkDebugf("---- failed to open <%s> as a font\n", path);
return false;
@@ -337,10 +336,10 @@ private:
SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, (
style,
- true, // system-font (cannot delete)
- filename.c_str(),
isFixedPitch,
- realname));
+ true, // system-font (cannot delete)
+ realname,
+ filename.c_str()));
SkFontStyleSet_Custom* addTo = this->onMatchFamily(realname.c_str());
if (NULL == addTo) {