Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: src/ports/SkFontHost_FreeType.cpp

Issue 672723002: Extend SkFontMgr_Custom to cover ttc, otf, pfb. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Keep FT_Stream alive, protect library with mutex. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/fonts/SkFontMgr_fontconfig.cpp ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_FreeType.cpp
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index ba0ce14560a53666a5c1b491c24a9253d15f7533..9acabbb5c26dbc688464d750bd044713b9c1f163 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1669,39 +1669,74 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-#include "SkTSearch.h"
-/*static*/ bool SkTypeface_FreeType::ScanFont(
- SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* isFixedPitch)
+
+SkTypeface_FreeType::Scanner::Scanner() {
+ if (FT_Init_FreeType(&fLibrary)) {
+ fLibrary = NULL;
+ }
+}
+SkTypeface_FreeType::Scanner::~Scanner() {
+ FT_Done_FreeType(fLibrary);
+}
+
+FT_Face SkTypeface_FreeType::Scanner::openFace(SkStream* stream, int ttcIndex,
+ FT_Stream ftStream) const
{
- FT_Library library;
- if (FT_Init_FreeType(&library)) {
- return false;
+ if (fLibrary == NULL) {
+ return NULL;
}
- FT_Open_Args args;
+ FT_Open_Args args;
memset(&args, 0, sizeof(args));
const void* memoryBase = stream->getMemoryBase();
- FT_StreamRec streamRec;
if (memoryBase) {
args.flags = FT_OPEN_MEMORY;
args.memory_base = (const FT_Byte*)memoryBase;
args.memory_size = stream->getLength();
} else {
- memset(&streamRec, 0, sizeof(streamRec));
- streamRec.size = stream->getLength();
- streamRec.descriptor.pointer = stream;
- streamRec.read = sk_stream_read;
- streamRec.close = sk_stream_close;
+ memset(ftStream, 0, sizeof(*ftStream));
+ ftStream->size = stream->getLength();
+ ftStream->descriptor.pointer = stream;
+ ftStream->read = sk_stream_read;
+ ftStream->close = sk_stream_close;
args.flags = FT_OPEN_STREAM;
- args.stream = &streamRec;
+ args.stream = ftStream;
}
FT_Face face;
- if (FT_Open_Face(library, &args, ttcIndex, &face)) {
- FT_Done_FreeType(library);
+ if (FT_Open_Face(fLibrary, &args, ttcIndex, &face)) {
+ return NULL;
+ }
+ return face;
+}
+
+bool SkTypeface_FreeType::Scanner::recognizedFont(SkStream* stream, int* numFaces) const {
+ SkAutoMutexAcquire libraryLock(fLibraryMutex);
+
+ FT_StreamRec streamRec;
+ FT_Face face = this->openFace(stream, -1, &streamRec);
+ if (NULL == face) {
+ return false;
+ }
+
+ *numFaces = face->num_faces;
+
+ FT_Done_Face(face);
+ return true;
+}
+
+#include "SkTSearch.h"
+bool SkTypeface_FreeType::Scanner::scanFont(
+ SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* isFixedPitch) const
+{
+ SkAutoMutexAcquire libraryLock(fLibraryMutex);
+
+ FT_StreamRec streamRec;
+ FT_Face face = this->openFace(stream, ttcIndex, &streamRec);
+ if (NULL == face) {
return false;
}
@@ -1731,14 +1766,19 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
{ "book", (SkFontStyle::kNormal_Weight + SkFontStyle::kLight_Weight)/2 },
{ "demi", SkFontStyle::kSemiBold_Weight },
{ "demibold", SkFontStyle::kSemiBold_Weight },
+ { "extra", SkFontStyle::kExtraBold_Weight },
{ "extrabold", SkFontStyle::kExtraBold_Weight },
{ "extralight", SkFontStyle::kExtraLight_Weight },
+ { "hairline", SkFontStyle::kThin_Weight },
{ "heavy", SkFontStyle::kBlack_Weight },
{ "light", SkFontStyle::kLight_Weight },
{ "medium", SkFontStyle::kMedium_Weight },
{ "normal", SkFontStyle::kNormal_Weight },
+ { "plain", SkFontStyle::kNormal_Weight },
{ "regular", SkFontStyle::kNormal_Weight },
+ { "roman", SkFontStyle::kNormal_Weight },
{ "semibold", SkFontStyle::kSemiBold_Weight },
+ { "standard", SkFontStyle::kNormal_Weight },
{ "thin", SkFontStyle::kThin_Weight },
{ "ultra", SkFontStyle::kExtraBold_Weight },
{ "ultrablack", 1000 },
@@ -1751,7 +1791,7 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
if (index >= 0) {
weight = commonWeights[index].weight;
} else {
- SkDEBUGF(("Do not know weight for: %s\n", psFontInfo.weight));
+ SkDEBUGF(("Do not know weight for: %s (%s) \n", face->family_name, psFontInfo.weight));
}
}
@@ -1766,6 +1806,5 @@ size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
}
FT_Done_Face(face);
- FT_Done_FreeType(library);
return true;
}
« no previous file with comments | « src/fonts/SkFontMgr_fontconfig.cpp ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698