| 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 // Despite the name and location, this is portable code. | 8 // Despite the name and location, this is portable code. |
| 9 | 9 |
| 10 #include "SkFontMgr_android_parser.h" | 10 #include "SkFontMgr_android_parser.h" |
| 11 #include "SkStream.h" | 11 #include "SkStream.h" |
| 12 #include "SkTDArray.h" | 12 #include "SkTDArray.h" |
| 13 #include "SkTSearch.h" | 13 #include "SkTSearch.h" |
| 14 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
| 15 #include "SkTLogic.h" |
| 15 | 16 |
| 16 #include <dirent.h> | 17 #include <dirent.h> |
| 17 #include <expat.h> | 18 #include <expat.h> |
| 18 | 19 |
| 19 #include <stdlib.h> | 20 #include <stdlib.h> |
| 20 #include <string.h> | 21 #include <string.h> |
| 21 | 22 |
| 22 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml" | 23 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml" |
| 23 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" | 24 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" |
| 24 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" | 25 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 SK_FONTCONFIGPARSER_WARNING("'%s' entity declaration found, stopping process
ing", entityName); | 573 SK_FONTCONFIGPARSER_WARNING("'%s' entity declaration found, stopping process
ing", entityName); |
| 573 XML_StopParser(self->fParser, XML_FALSE); | 574 XML_StopParser(self->fParser, XML_FALSE); |
| 574 } | 575 } |
| 575 | 576 |
| 576 static const XML_Memory_Handling_Suite sk_XML_alloc = { | 577 static const XML_Memory_Handling_Suite sk_XML_alloc = { |
| 577 sk_malloc_throw, | 578 sk_malloc_throw, |
| 578 sk_realloc_throw, | 579 sk_realloc_throw, |
| 579 sk_free | 580 sk_free |
| 580 }; | 581 }; |
| 581 | 582 |
| 582 template<typename T> struct remove_ptr {typedef T type;}; | |
| 583 template<typename T> struct remove_ptr<T*> {typedef T type;}; | |
| 584 | |
| 585 /** | 583 /** |
| 586 * This function parses the given filename and stores the results in the given | 584 * This function parses the given filename and stores the results in the given |
| 587 * families array. Returns the version of the file, negative if the file does no
t exist. | 585 * families array. Returns the version of the file, negative if the file does no
t exist. |
| 588 */ | 586 */ |
| 589 static int parse_config_file(const char* filename, SkTDArray<FontFamily*>& famil
ies, | 587 static int parse_config_file(const char* filename, SkTDArray<FontFamily*>& famil
ies, |
| 590 const SkString& basePath, bool isFallback) | 588 const SkString& basePath, bool isFallback) |
| 591 { | 589 { |
| 592 SkFILEStream file(filename); | 590 SkFILEStream file(filename); |
| 593 | 591 |
| 594 // Some of the files we attempt to parse (in particular, /vendor/etc/fallbac
k_fonts.xml) | 592 // Some of the files we attempt to parse (in particular, /vendor/etc/fallbac
k_fonts.xml) |
| 595 // are optional - failure here is okay because one of these optional files m
ay not exist. | 593 // are optional - failure here is okay because one of these optional files m
ay not exist. |
| 596 if (!file.isValid()) { | 594 if (!file.isValid()) { |
| 597 SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "'%s' could not be opened\n",
filename); | 595 SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "'%s' could not be opened\n",
filename); |
| 598 return -1; | 596 return -1; |
| 599 } | 597 } |
| 600 | 598 |
| 601 SkAutoTCallVProc<remove_ptr<XML_Parser>::type, XML_ParserFree> parser( | 599 SkAutoTCallVProc<skstd::remove_pointer_t<XML_Parser>, XML_ParserFree> parser
( |
| 602 XML_ParserCreate_MM(nullptr, &sk_XML_alloc, nullptr)); | 600 XML_ParserCreate_MM(nullptr, &sk_XML_alloc, nullptr)); |
| 603 if (!parser) { | 601 if (!parser) { |
| 604 SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "could not create XML parser\n
"); | 602 SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "could not create XML parser\n
"); |
| 605 return -1; | 603 return -1; |
| 606 } | 604 } |
| 607 | 605 |
| 608 FamilyData self(parser, families, basePath, isFallback, filename, &topLevelH
andler); | 606 FamilyData self(parser, families, basePath, isFallback, filename, &topLevelH
andler); |
| 609 XML_SetUserData(parser, &self); | 607 XML_SetUserData(parser, &self); |
| 610 | 608 |
| 611 // Disable entity processing, to inhibit internal entity expansion. See expa
t CVE-2013-0340 | 609 // Disable entity processing, to inhibit internal entity expansion. See expa
t CVE-2013-0340 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 const char* tag = fTag.c_str(); | 788 const char* tag = fTag.c_str(); |
| 791 | 789 |
| 792 // strip off the rightmost "-.*" | 790 // strip off the rightmost "-.*" |
| 793 const char* parentTagEnd = strrchr(tag, '-'); | 791 const char* parentTagEnd = strrchr(tag, '-'); |
| 794 if (parentTagEnd == nullptr) { | 792 if (parentTagEnd == nullptr) { |
| 795 return SkLanguage(); | 793 return SkLanguage(); |
| 796 } | 794 } |
| 797 size_t parentTagLen = parentTagEnd - tag; | 795 size_t parentTagLen = parentTagEnd - tag; |
| 798 return SkLanguage(tag, parentTagLen); | 796 return SkLanguage(tag, parentTagLen); |
| 799 } | 797 } |
| OLD | NEW |