| OLD | NEW |
| 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" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 size_t len = strlen(tag); | 256 size_t len = strlen(tag); |
| 257 if (MEMEQ("family", tag, len)) { | 257 if (MEMEQ("family", tag, len)) { |
| 258 family_element_handler(self, attributes); | 258 family_element_handler(self, attributes); |
| 259 } else if (MEMEQ("font", tag, len)) { | 259 } else if (MEMEQ("font", tag, len)) { |
| 260 font_element_handler(self, attributes); | 260 font_element_handler(self, attributes); |
| 261 } else if (MEMEQ("alias", tag, len)) { | 261 } else if (MEMEQ("alias", tag, len)) { |
| 262 alias_element_handler(self, attributes); | 262 alias_element_handler(self, attributes); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 | 265 |
| 266 static bool is_whitespace(char c) { |
| 267 return c == ' ' || c == '\n'|| c == '\r' || c == '\t'; |
| 268 } |
| 269 |
| 270 static void trim_string(SkString* s) { |
| 271 char* str = s->writable_str(); |
| 272 const char* start = str; // start is inclusive |
| 273 const char* end = start + s->size(); // end is exclusive |
| 274 while (is_whitespace(*start)) { ++start; } |
| 275 if (start != end) { |
| 276 --end; // make end inclusive |
| 277 while (is_whitespace(*end)) { --end; } |
| 278 ++end; // make end exclusive |
| 279 } |
| 280 size_t len = end - start; |
| 281 memmove(str, start, len); |
| 282 s->resize(len); |
| 283 } |
| 284 |
| 266 static void XMLCALL end_element_handler(void* data, const char* tag) { | 285 static void XMLCALL end_element_handler(void* data, const char* tag) { |
| 267 FamilyData* self = static_cast<FamilyData*>(data); | 286 FamilyData* self = static_cast<FamilyData*>(data); |
| 268 size_t len = strlen(tag); | 287 size_t len = strlen(tag); |
| 269 if (MEMEQ("family", tag, len)) { | 288 if (MEMEQ("family", tag, len)) { |
| 270 *self->fFamilies.append() = self->fCurrentFamily.detach(); | 289 *self->fFamilies.append() = self->fCurrentFamily.detach(); |
| 271 } else if (MEMEQ("font", tag, len)) { | 290 } else if (MEMEQ("font", tag, len)) { |
| 272 XML_SetCharacterDataHandler(self->fParser, NULL); | 291 XML_SetCharacterDataHandler(self->fParser, NULL); |
| 292 trim_string(&self->fCurrentFontInfo->fFileName); |
| 273 } | 293 } |
| 274 } | 294 } |
| 275 | 295 |
| 276 } // lmpParser | 296 } // lmpParser |
| 277 | 297 |
| 278 namespace jbParser { | 298 namespace jbParser { |
| 279 | 299 |
| 280 /** | 300 /** |
| 281 * Handler for arbitrary text. This is used to parse the text inside each name | 301 * Handler for arbitrary text. This is used to parse the text inside each name |
| 282 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar
rays. | 302 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar
rays. |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 const char* tag = fTag.c_str(); | 670 const char* tag = fTag.c_str(); |
| 651 | 671 |
| 652 // strip off the rightmost "-.*" | 672 // strip off the rightmost "-.*" |
| 653 const char* parentTagEnd = strrchr(tag, '-'); | 673 const char* parentTagEnd = strrchr(tag, '-'); |
| 654 if (parentTagEnd == NULL) { | 674 if (parentTagEnd == NULL) { |
| 655 return SkLanguage(); | 675 return SkLanguage(); |
| 656 } | 676 } |
| 657 size_t parentTagLen = parentTagEnd - tag; | 677 size_t parentTagLen = parentTagEnd - tag; |
| 658 return SkLanguage(tag, parentTagLen); | 678 return SkLanguage(tag, parentTagLen); |
| 659 } | 679 } |
| OLD | NEW |