aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-03-21 06:55:52 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-21 06:55:52 -0700
commitfe7ada7f0dc109cc8cf220607c2bd8c09bd1fa5e (patch)
tree53bec3fd08a6537b34bec413af86135545000669
parenta6359365887048ef055196de75591311d7a015f0 (diff)
Make FreeType usable on Windows.
Add missing functionality so that pdfium can use FreeType from Windows. Add an empty custom font manager so pdfium can use FreeType without any local fonts. R=bungeman@google.com Review URL: https://codereview.chromium.org/1817633002
-rw-r--r--include/ports/SkFontMgr_custom.h3
-rw-r--r--src/core/SkAdvancedTypefaceMetrics.cpp16
-rw-r--r--src/ports/SkFontHost_FreeType.cpp7
-rw-r--r--src/ports/SkFontMgr_custom.cpp20
-rw-r--r--src/ports/SkFontMgr_custom_empty_factory.cpp13
5 files changed, 47 insertions, 12 deletions
diff --git a/include/ports/SkFontMgr_custom.h b/include/ports/SkFontMgr_custom.h
index ad37686ebb..53be63db1b 100644
--- a/include/ports/SkFontMgr_custom.h
+++ b/include/ports/SkFontMgr_custom.h
@@ -15,4 +15,7 @@ class SkFontMgr;
/** Create a custom font manager which scans a given directory for font files. */
SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir);
+/** Create a custom font manager that contains no built-in fonts. */
+SK_API SkFontMgr* SkFontMgr_New_Custom_Empty();
+
#endif // SkFontMgr_custom_DEFINED
diff --git a/src/core/SkAdvancedTypefaceMetrics.cpp b/src/core/SkAdvancedTypefaceMetrics.cpp
index 28079f98e9..48b2cd73f7 100644
--- a/src/core/SkAdvancedTypefaceMetrics.cpp
+++ b/src/core/SkAdvancedTypefaceMetrics.cpp
@@ -14,11 +14,9 @@
#include <dwrite.h>
#endif
-#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
// forward declare structs needed for getAdvanceData() template for freetype
struct FT_FaceRec_;
typedef struct FT_FaceRec_* FT_Face;
-#endif
#ifdef SK_BUILD_FOR_MAC
#import <ApplicationServices/ApplicationServices.h>
@@ -255,6 +253,13 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
// Make AdvanceMetric template functions available for linking with typename
// WidthRange and VerticalAdvanceRange.
+template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
+ FT_Face face,
+ int num_glyphs,
+ const uint32_t* subsetGlyphIDs,
+ uint32_t subsetGlyphIDsLength,
+ bool (*getAdvance)(FT_Face face, int gId, int16_t* data));
+
#if defined(SK_BUILD_FOR_WIN)
template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
HDC hdc,
@@ -268,13 +273,6 @@ template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
const uint32_t* subsetGlyphIDs,
uint32_t subsetGlyphIDsLength,
bool (*getAdvance)(IDWriteFontFace* fontFace, int gId, int16_t* data));
-#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
-template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
- FT_Face face,
- int num_glyphs,
- const uint32_t* subsetGlyphIDs,
- uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(FT_Face face, int gId, int16_t* data));
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
CTFontRef ctFont,
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index f01c7d7cc5..e7cb6d2963 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -361,7 +361,8 @@ static FT_Face ref_ft_face(const SkTypeface* typeface) {
}
// Caller must lock gFTMutex before calling this function.
-static void unref_ft_face(FT_Face face) {
+extern void unref_ft_face(FT_Face face);
+void unref_ft_face(FT_Face face) {
gFTMutex.assertHeld();
SkFaceRec* rec = gFaceRecHead;
@@ -1284,7 +1285,6 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* metrics
SkAutoMutexAcquire ac(gFTMutex);
if (this->setupSize()) {
- ERROR:
sk_bzero(metrics, sizeof(*metrics));
return;
}
@@ -1376,7 +1376,8 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* metrics
metrics->fFlags &= ~SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag;
metrics->fFlags &= ~SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
} else {
- goto ERROR;
+ sk_bzero(metrics, sizeof(*metrics));
+ return;
}
// synthesize elements that were not provided by the os/2 table or format-specific metrics
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index 158ba006d4..c77fe394b1 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -506,3 +506,23 @@ private:
SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header));
}
+
+///////////////////////////////////////////////////////////////////////////////
+
+class EmptyFontLoader : public SkFontMgr_Custom::SystemFontLoader {
+public:
+ EmptyFontLoader() { }
+
+ void loadSystemFonts(const SkTypeface_FreeType::Scanner& scanner,
+ SkFontMgr_Custom::Families* families) const override
+ {
+ SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
+ families->push_back().reset(family);
+ family->appendTypeface(new SkTypeface_Empty);
+ }
+
+};
+
+SK_API SkFontMgr* SkFontMgr_New_Custom_Empty() {
+ return new SkFontMgr_Custom(EmptyFontLoader());
+}
diff --git a/src/ports/SkFontMgr_custom_empty_factory.cpp b/src/ports/SkFontMgr_custom_empty_factory.cpp
new file mode 100644
index 0000000000..c9487cdcc7
--- /dev/null
+++ b/src/ports/SkFontMgr_custom_empty_factory.cpp
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkFontMgr.h"
+#include "SkFontMgr_custom.h"
+
+SkFontMgr* SkFontMgr::Factory() {
+ return SkFontMgr_New_Custom_Empty();
+}