OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "SkFontMgr.h" | 9 #include "SkFontMgr.h" |
10 #include "SkMutex.h" | 10 #include "SkMutex.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } else { | 61 } else { |
62 font = SkNEW_ARGS(SkTestFont, (*fontData)); | 62 font = SkNEW_ARGS(SkTestFont, (*fontData)); |
63 SkDEBUGCODE(font->fDebugName = sub->fName); | 63 SkDEBUGCODE(font->fDebugName = sub->fName); |
64 SkDEBUGCODE(font->fDebugStyle = sub->fStyle); | 64 SkDEBUGCODE(font->fDebugStyle = sub->fStyle); |
65 fontData->fFontCache = SkSafeRef(font); | 65 fontData->fFontCache = SkSafeRef(font); |
66 } | 66 } |
67 } | 67 } |
68 return SkNEW_ARGS(SkTestTypeface, (font, SkFontStyle(style))); | 68 return SkNEW_ARGS(SkTestTypeface, (font, SkFontStyle(style))); |
69 } | 69 } |
70 | 70 |
71 | |
72 SkTypeface* resource_font(const char* name, SkTypeface::Style style) { | |
73 const char* file = NULL; | |
74 if (name) { | |
75 for (int index = 0; index < gSubFontsCount; ++index) { | |
76 const SubFont& sub = gSubFonts[index]; | |
77 if (!strcmp(name, sub.fName) && sub.fStyle == style) { | |
78 file = sub.fFile; | |
79 break; | |
80 } | |
81 } | |
82 if (!file) { | |
83 return SkTypeface::CreateFromName(name, style); | |
84 } | |
85 } else { | |
86 file = gSubFonts[gDefaultFontIndex].fFile; | |
87 } | |
88 SkString filepath(GetResourcePath(file)); | |
89 if (sk_exists(filepath.c_str())) { | |
90 return SkTypeface::CreateFromFile(filepath.c_str()); | |
91 } | |
92 return SkTypeface::CreateFromName(name, style); | |
93 } | 71 } |
94 | |
95 #ifdef SK_DEBUG | |
96 #include <stdio.h> | |
97 | |
98 char const * const gStyleName[] = { | |
99 "", | |
100 "_Bold", | |
101 "_Italic", | |
102 "_BoldItalic", | |
103 }; | |
104 | |
105 static SkString strip_spaces(const char* str) { | |
106 SkString result; | |
107 int count = (int) strlen(str); | |
108 for (int index = 0; index < count; ++index) { | |
109 char c = str[index]; | |
110 if (c != ' ' && c != '-') { | |
111 result += c; | |
112 } | |
113 } | |
114 return result; | |
115 } | |
116 | |
117 const char gHeader[] = | |
118 "/*\n" | |
119 " * Copyright 2014 Google Inc.\n" | |
120 " *\n" | |
121 " * Use of this source code is governed by a BSD-style license that can be\n" | |
122 " * found in the LICENSE file.\n" | |
123 " */\n" | |
124 "\n" | |
125 "// Auto-generated by "; | |
126 | |
127 static FILE* font_header() { | |
128 SkString pathStr(GetResourcePath()); | |
129 pathStr = SkOSPath::Join(pathStr.c_str(), ".."); | |
130 pathStr = SkOSPath::Join(pathStr.c_str(), "tools"); | |
131 pathStr = SkOSPath::Join(pathStr.c_str(), "test_font_data_chars.cpp"); | |
132 FILE* out = fopen(pathStr.c_str(), "w"); | |
133 fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str()); | |
134 return out; | |
135 } | |
136 | |
137 void report_used_chars() { | |
138 FILE* out = font_header(); | |
139 for (int index = 0; index < gTestFontsCount; ++index) { | |
140 SkTestFontData& fontData = gTestFonts[index]; | |
141 SkTestFont* font = fontData.fFontCache; | |
142 if (!font) { | |
143 continue; | |
144 } | |
145 SkString name(strip_spaces(font->debugFontName())); | |
146 fprintf(out, "const char g%s%s[] =\n", name.c_str(), gStyleName[font->fD
ebugStyle]); | |
147 SkString used(" \""); | |
148 for (int c = ' '; c <= '~'; ++c) { | |
149 int bitOffset = c - ' '; | |
150 if (font->fDebugBits[bitOffset >> 3] & (1 << (bitOffset & 7))) { | |
151 if (c == '"' || c == '\\') { | |
152 used += '\\'; | |
153 } | |
154 used += c; | |
155 } | |
156 } | |
157 if (used.size() > 1) { | |
158 fprintf(out, "%s\"", used.c_str()); | |
159 } | |
160 int oIndex = 0; | |
161 while (font->fDebugOverage[oIndex]) { | |
162 uint16_t uni = font->fDebugOverage[oIndex]; | |
163 size_t byteCount = SkUTF16_ToUTF8(&uni, 1, NULL); | |
164 SkAutoSTMalloc<10, char> utf8(byteCount); | |
165 SkUTF16_ToUTF8(&uni, 1, utf8); | |
166 for (unsigned byteIndex = 0; byteIndex < byteCount; ++byteIndex) { | |
167 char unibyte = utf8[byteIndex]; | |
168 fprintf(out, " \"\\x%02X\"", (unsigned char) unibyte); | |
169 } | |
170 if (++oIndex >= (int) sizeof(font->fDebugOverage)) { | |
171 break; | |
172 } | |
173 } | |
174 fprintf(out, ";\n"); | |
175 } | |
176 fclose(out); | |
177 } | |
178 #endif | |
179 | |
180 } | |
OLD | NEW |