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

Side by Side Diff: src/ports/SkFontConfigParser_android.cpp

Issue 1139123008: Revert of Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
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 "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontMgr_android.h" 9 #include "SkFontMgr_android.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
11 #include "SkTDArray.h" 11 #include "SkTDArray.h"
12 #include "SkTSearch.h" 12 #include "SkTSearch.h"
13 #include "SkTypeface.h" 13 #include "SkTypeface.h"
14 14
15 #include <expat.h> 15 #include <expat.h>
16 #include <dirent.h> 16 #include <dirent.h>
17 #include <stdio.h>
17 18
19 #include <limits>
18 #include <stdlib.h> 20 #include <stdlib.h>
19 21
20 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml" 22 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml"
21 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" 23 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml"
22 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" 24 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml"
23 #define VENDOR_FONTS_FILE "/vendor/etc/fallback_fonts.xml" 25 #define VENDOR_FONTS_FILE "/vendor/etc/fallback_fonts.xml"
24 26
25 #define LOCALE_FALLBACK_FONTS_SYSTEM_DIR "/system/etc" 27 #define LOCALE_FALLBACK_FONTS_SYSTEM_DIR "/system/etc"
26 #define LOCALE_FALLBACK_FONTS_VENDOR_DIR "/vendor/etc" 28 #define LOCALE_FALLBACK_FONTS_VENDOR_DIR "/vendor/etc"
27 #define LOCALE_FALLBACK_FONTS_PREFIX "fallback_fonts-" 29 #define LOCALE_FALLBACK_FONTS_PREFIX "fallback_fonts-"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 int fVersion; // The version of the file parsed. 104 int fVersion; // The version of the file parsed.
103 const SkString& fBasePath; // The current base path. 105 const SkString& fBasePath; // The current base path.
104 const bool fIsFallback; // Indicates the file being parsed is a fallback file 106 const bool fIsFallback; // Indicates the file being parsed is a fallback file
105 const char* fFilename; // The name of the file currently being parsed. 107 const char* fFilename; // The name of the file currently being parsed.
106 108
107 int fDepth; // The current element depth of th e parse. 109 int fDepth; // The current element depth of th e parse.
108 int fSkip; // The depth to stop skipping, 0 i f not skipping. 110 int fSkip; // The depth to stop skipping, 0 i f not skipping.
109 SkTDArray<const TagHandler*> fHandler; // The stack of current tag handle rs. 111 SkTDArray<const TagHandler*> fHandler; // The stack of current tag handle rs.
110 }; 112 };
111 113
114 /** Parses a null terminated string into an integer type, checking for overflow.
115 * http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-nega tive-def
116 *
117 * If the string cannot be parsed into 'value', returns false and does not chan ge 'value'.
118 */
119 template <typename T> static bool parse_non_negative_integer(const char* s, T* v alue) {
120 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, T_must_be_integer);
121 const T nMax = std::numeric_limits<T>::max() / 10;
122 const T dMax = std::numeric_limits<T>::max() - (nMax * 10);
123 T n = 0;
124 for (; *s; ++s) {
125 // Check if digit
126 if (*s < '0' || '9' < *s) {
127 return false;
128 }
129 int d = *s - '0';
130 // Check for overflow
131 if (n > nMax || (n == nMax && d > dMax)) {
132 return false;
133 }
134 n = (n * 10) + d;
135 }
136 *value = n;
137 return true;
138 }
139
112 static bool memeq(const char* s1, const char* s2, size_t n1, size_t n2) { 140 static bool memeq(const char* s1, const char* s2, size_t n1, size_t n2) {
113 return n1 == n2 && 0 == memcmp(s1, s2, n1); 141 return n1 == n2 && 0 == memcmp(s1, s2, n1);
114 } 142 }
115 #define MEMEQ(c, s, n) memeq(c, s, sizeof(c) - 1, n) 143 #define MEMEQ(c, s, n) memeq(c, s, sizeof(c) - 1, n)
116 144
117 #define ATTS_NON_NULL(a, i) (a[i] != NULL && a[i+1] != NULL) 145 #define ATTS_NON_NULL(a, i) (a[i] != NULL && a[i+1] != NULL)
118 146
119 #define SK_FONTCONFIGPARSER_PREFIX "[SkFontConfigParser] " 147 #define SK_FONTCONFIGPARSER_PREFIX "[SkFontConfigParser] "
120 148
121 #define SK_FONTCONFIGPARSER_WARNING(message, ...) SkDebugf( \ 149 #define SK_FONTCONFIGPARSER_WARNING(message, ...) SkDebugf( \
(...skipping 17 matching lines...) Expand all
139 while (is_whitespace(*end)) { --end; } 167 while (is_whitespace(*end)) { --end; }
140 ++end; // make end exclusive 168 ++end; // make end exclusive
141 } 169 }
142 size_t len = end - start; 170 size_t len = end - start;
143 memmove(str, start, len); 171 memmove(str, start, len);
144 s->resize(len); 172 s->resize(len);
145 } 173 }
146 174
147 namespace lmpParser { 175 namespace lmpParser {
148 176
149 static const TagHandler axisHandler = {
150 /*start*/[](FamilyData* self, const char* tag, const char** attributes) {
151 FontFileInfo& file = *self->fCurrentFontInfo;
152 FontFileInfo::Axis& axis = file.fAxes.push_back();
153 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
154 const char* name = attributes[i];
155 const char* value = attributes[i+1];
156 size_t nameLen = strlen(name);
157 if (MEMEQ("tag", name, nameLen)) {
158 size_t valueLen = strlen(value);
159 if (valueLen == 4) {
160 SkFourByteTag tag = SkSetFourByteTag(value[0], value[1], val ue[2], value[3]);
161 for (int j = 0; j < file.fAxes.count() - 1; ++j) {
162 if (file.fAxes[j].fTag == tag) {
163 SK_FONTCONFIGPARSER_WARNING("'%c%c%c%c' axis specifi ed more than once",
164 (tag >> 24) & 0xFF,
165 (tag >> 16) & 0xFF,
166 (tag >> 8) & 0xFF,
167 (tag ) & 0xFF);
168 }
169 }
170 axis.fTag = SkSetFourByteTag(value[0], value[1], value[2], v alue[3]);
171 } else {
172 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis tag", v alue);
173 }
174 } else if (MEMEQ("stylevalue", name, nameLen)) {
175 if (!parse_fixed<16>(value, &axis.fValue)) {
176 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis styleva lue", value);
177 }
178 }
179 }
180 },
181 /*end*/NULL,
182 /*tag*/NULL,
183 /*chars*/NULL,
184 };
185
186 static const TagHandler fontHandler = { 177 static const TagHandler fontHandler = {
187 /*start*/[](FamilyData* self, const char* tag, const char** attributes) { 178 /*start*/[](FamilyData* self, const char* tag, const char** attributes) {
188 // 'weight' (non-negative integer) [default 0] 179 // 'weight' (non-negative integer) [default 0]
189 // 'style' ("normal", "italic") [default "auto"] 180 // 'style' ("normal", "italic") [default "auto"]
190 // 'index' (non-negative integer) [default 0] 181 // 'index' (non-negative integer) [default 0]
191 // The character data should be a filename. 182 // The character data should be a filename.
192 FontFileInfo& file = self->fCurrentFamily->fFonts.push_back(); 183 FontFileInfo& file = self->fCurrentFamily->fFonts.push_back();
193 self->fCurrentFontInfo = &file; 184 self->fCurrentFontInfo = &file;
194 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) { 185 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
195 const char* name = attributes[i]; 186 const char* name = attributes[i];
(...skipping 13 matching lines...) Expand all
209 } else if (MEMEQ("index", name, nameLen)) { 200 } else if (MEMEQ("index", name, nameLen)) {
210 if (!parse_non_negative_integer(value, &file.fIndex)) { 201 if (!parse_non_negative_integer(value, &file.fIndex)) {
211 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid index", valu e); 202 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid index", valu e);
212 } 203 }
213 } 204 }
214 } 205 }
215 }, 206 },
216 /*end*/[](FamilyData* self, const char* tag) { 207 /*end*/[](FamilyData* self, const char* tag) {
217 trim_string(&self->fCurrentFontInfo->fFileName); 208 trim_string(&self->fCurrentFontInfo->fFileName);
218 }, 209 },
219 /*tag*/[](FamilyData* self, const char* tag, const char** attributes) -> con st TagHandler* { 210 /*tag*/NULL,
220 size_t len = strlen(tag);
221 if (MEMEQ("axis", tag, len)) {
222 return &axisHandler;
223 }
224 return NULL;
225 },
226 /*chars*/[](void* data, const char* s, int len) { 211 /*chars*/[](void* data, const char* s, int len) {
227 FamilyData* self = static_cast<FamilyData*>(data); 212 FamilyData* self = static_cast<FamilyData*>(data);
228 self->fCurrentFontInfo->fFileName.append(s, len); 213 self->fCurrentFontInfo->fFileName.append(s, len);
229 } 214 }
230 }; 215 };
231 216
232 static const TagHandler familyHandler = { 217 static const TagHandler familyHandler = {
233 /*start*/[](FamilyData* self, const char* tag, const char** attributes) { 218 /*start*/[](FamilyData* self, const char* tag, const char** attributes) {
234 // 'name' (string) [optional] 219 // 'name' (string) [optional]
235 // 'lang' (string) [default ""] 220 // 'lang' (string) [default ""]
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 const char* tag = fTag.c_str(); 773 const char* tag = fTag.c_str();
789 774
790 // strip off the rightmost "-.*" 775 // strip off the rightmost "-.*"
791 const char* parentTagEnd = strrchr(tag, '-'); 776 const char* parentTagEnd = strrchr(tag, '-');
792 if (parentTagEnd == NULL) { 777 if (parentTagEnd == NULL) {
793 return SkLanguage(); 778 return SkLanguage();
794 } 779 }
795 size_t parentTagLen = parentTagEnd - tag; 780 size_t parentTagLen = parentTagEnd - tag;
796 return SkLanguage(tag, parentTagLen); 781 return SkLanguage(tag, parentTagLen);
797 } 782 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698