aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--resources/fonts/SpiderSymbol.ttfbin0 -> 15604 bytes
-rw-r--r--src/ports/SkFontHost_FreeType.cpp64
-rw-r--r--tests/FontHostTest.cpp17
3 files changed, 36 insertions, 45 deletions
diff --git a/resources/fonts/SpiderSymbol.ttf b/resources/fonts/SpiderSymbol.ttf
new file mode 100644
index 0000000000..ed651eaded
--- /dev/null
+++ b/resources/fonts/SpiderSymbol.ttf
Binary files differ
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index a4305bfa87..b3a65e1985 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -352,6 +352,16 @@ static SkFaceRec* ref_ft_face(const SkTypeface* typeface) {
ft_face_setup_axes(rec->fFace, *data);
+ // FreeType will set the charmap to the "most unicode" cmap if it exists.
+ // If there are no unicode cmaps, the charmap is set to NULL.
+ // However, "symbol" cmaps should also be considered "fallback unicode" cmaps
+ // because they are effectively private use area only (even if they aren't).
+ // This is the last on the fallback list at
+ // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html
+ if (!rec->fFace->charmap) {
+ FT_Select_Charmap(rec->fFace, FT_ENCODING_MS_SYMBOL);
+ }
+
rec->fNext = gFaceRecHead;
gFaceRecHead = rec;
return rec;
@@ -446,51 +456,14 @@ static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) {
}
static void populate_glyph_to_unicode(FT_Face& face, SkTDArray<SkUnichar>* glyphToUnicode) {
- // Check and see if we have Unicode cmaps.
- for (int i = 0; i < face->num_charmaps; ++i) {
- // CMaps known to support Unicode:
- // Platform ID Encoding ID Name
- // ----------- ----------- -----------------------------------
- // 0 0,1 Apple Unicode
- // 0 3 Apple Unicode 2.0 (preferred)
- // 3 1 Microsoft Unicode UCS-2
- // 3 10 Microsoft Unicode UCS-4 (preferred)
- //
- // See Apple TrueType Reference Manual
- // http://developer.apple.com/fonts/TTRefMan/RM06/Chap6cmap.html
- // http://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html#ID
- // Microsoft OpenType Specification
- // http://www.microsoft.com/typography/otspec/cmap.htm
-
- FT_UShort platformId = face->charmaps[i]->platform_id;
- FT_UShort encodingId = face->charmaps[i]->encoding_id;
-
- if (platformId != 0 && platformId != 3) {
- continue;
- }
- if (platformId == 3 && encodingId != 1 && encodingId != 10) {
- continue;
- }
- bool preferredMap = ((platformId == 3 && encodingId == 10) ||
- (platformId == 0 && encodingId == 3));
-
- FT_Set_Charmap(face, face->charmaps[i]);
- if (glyphToUnicode->isEmpty()) {
- glyphToUnicode->setCount(face->num_glyphs);
- memset(glyphToUnicode->begin(), 0,
- sizeof(SkUnichar) * face->num_glyphs);
- }
+ glyphToUnicode->setCount(face->num_glyphs);
+ sk_bzero(glyphToUnicode->begin(), sizeof((*glyphToUnicode)[0]) * face->num_glyphs);
- // Iterate through each cmap entry.
- FT_UInt glyphIndex;
- for (SkUnichar charCode = FT_Get_First_Char(face, &glyphIndex);
- glyphIndex != 0;
- charCode = FT_Get_Next_Char(face, charCode, &glyphIndex)) {
- if (charCode &&
- ((*glyphToUnicode)[glyphIndex] == 0 || preferredMap)) {
- (*glyphToUnicode)[glyphIndex] = charCode;
- }
- }
+ FT_UInt glyphIndex;
+ SkUnichar charCode = FT_Get_First_Char(face, &glyphIndex);
+ while (glyphIndex) {
+ (*glyphToUnicode)[glyphIndex] = charCode;
+ charCode = FT_Get_Next_Char(face, charCode, &glyphIndex);
}
}
@@ -1507,7 +1480,8 @@ static EncodingProc find_encoding_proc(SkTypeface::Encoding enc) {
}
int SkTypeface_FreeType::onCharsToGlyphs(const void* chars, Encoding encoding,
- uint16_t glyphs[], int glyphCount) const {
+ uint16_t glyphs[], int glyphCount) const
+{
AutoFTAccess fta(this);
FT_Face face = fta.face();
if (!face) {
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index ff275e2ad5..db83e06b62 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -153,6 +153,22 @@ static void test_fontstream(skiatest::Reporter* reporter) {
}
}
+static void test_symbolfont(skiatest::Reporter* reporter) {
+ SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/SpiderSymbol.ttf"));
+ if (!typeface) {
+ SkDebugf("Skipping FontHostTest::test_symbolfont\n");
+ return;
+ }
+
+ SkUnichar c = 0xf021;
+ uint16_t g;
+ SkPaint paint;
+ paint.setTypeface(typeface);
+ paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+ paint.textToGlyphs(&c, 4, &g);
+ REPORTER_ASSERT(reporter, g == 3);
+}
+
static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
if (false) { // avoid bit rot, suppress warning
SkFontID fontID = face->uniqueID();
@@ -295,6 +311,7 @@ DEF_TEST(FontHost, reporter) {
test_tables(reporter);
test_fontstream(reporter);
test_advances(reporter);
+ test_symbolfont(reporter);
}
// need tests for SkStrSearch