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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/Character.cpp

Issue 1742293002: Support src/build/linux/unbundle in CharacterDataGenerator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/fonts/Character.h" 31 #include "platform/fonts/Character.h"
32 32
33 #include "wtf/StdLibExtras.h" 33 #include "wtf/StdLibExtras.h"
34 #include "wtf/text/StringBuilder.h" 34 #include "wtf/text/StringBuilder.h"
35 #include <algorithm> 35 #include <algorithm>
36 #include <unicode/uobject.h> 36 #include <unicode/uobject.h>
37 #include <unicode/uscript.h> 37 #include <unicode/uscript.h>
38
39 #if defined(USING_SYSTEM_ICU)
40 #include "CharacterData.h"
41 #include <unicode/uniset.h>
42 #else
38 #define MUTEX_H // Prevent compile failure of utrie2.h on Windows 43 #define MUTEX_H // Prevent compile failure of utrie2.h on Windows
39 #include <utrie2.h> 44 #include <utrie2.h>
45 #endif
40 46
41 using namespace WTF; 47 using namespace WTF;
42 using namespace Unicode; 48 using namespace Unicode;
43 49
44 namespace blink { 50 namespace blink {
45 51
52 #if defined(USING_SYSTEM_ICU)
53 static icu::UnicodeSet* createUnicodeSet(
54 const UChar32* characters, size_t charactersCount,
55 const UChar32* ranges, size_t rangesCount)
56 {
57 icu::UnicodeSet* unicodeSet = new icu::UnicodeSet();
58 for (size_t i = 0; i < charactersCount; i++)
59 unicodeSet->add(characters[i]);
60 for (size_t i = 0; i < rangesCount; i += 2)
61 unicodeSet->add(ranges[i], ranges[i + 1]);
62 unicodeSet->freeze();
63 return unicodeSet;
64 }
65
66 #define CREATE_UNICODE_SET(name) \
67 createUnicodeSet( \
68 name##Array, WTF_ARRAY_LENGTH(name##Array), \
69 name##Ranges, WTF_ARRAY_LENGTH(name##Ranges))
70
71 #define RETURN_HAS_PROPERTY(c, name) \
72 static icu::UnicodeSet* unicodeSet = nullptr; \
73 if (!unicodeSet) \
74 unicodeSet = CREATE_UNICODE_SET(name); \
75 return unicodeSet->contains(c);
76 #else
46 // Freezed trie tree, see CharacterDataGenerator.cpp. 77 // Freezed trie tree, see CharacterDataGenerator.cpp.
47 extern int32_t serializedCharacterDataSize; 78 extern int32_t serializedCharacterDataSize;
48 extern uint8_t serializedCharacterData[]; 79 extern uint8_t serializedCharacterData[];
49 80
50 static UTrie2* createTrie() 81 static UTrie2* createTrie()
51 { 82 {
52 // Create a Trie from the value array. 83 // Create a Trie from the value array.
53 UErrorCode error = U_ZERO_ERROR; 84 UErrorCode error = U_ZERO_ERROR;
54 UTrie2* trie = utrie2_openFromSerialized( 85 UTrie2* trie = utrie2_openFromSerialized(
55 UTrie2ValueBits::UTRIE2_16_VALUE_BITS, 86 UTrie2ValueBits::UTRIE2_16_VALUE_BITS,
56 serializedCharacterData, serializedCharacterDataSize, 87 serializedCharacterData, serializedCharacterDataSize,
57 nullptr, &error); 88 nullptr, &error);
58 ASSERT(error == U_ZERO_ERROR); 89 ASSERT(error == U_ZERO_ERROR);
59 return trie; 90 return trie;
60 } 91 }
61 92
62 bool Character::hasProperty(UChar32 c, CharacterProperty property) 93 static bool hasProperty(UChar32 c, CharacterProperty property)
63 { 94 {
64 static UTrie2* trie = nullptr; 95 static UTrie2* trie = nullptr;
65 if (!trie) 96 if (!trie)
66 trie = createTrie(); 97 trie = createTrie();
67 return UTRIE2_GET16(trie, c) 98 return UTRIE2_GET16(trie, c)
68 & static_cast<CharacterPropertyType>(property); 99 & static_cast<CharacterPropertyType>(property);
69 } 100 }
70 101
102 #define RETURN_HAS_PROPERTY(c, name) \
103 return hasProperty(c, CharacterProperty::name);
104 #endif
105
71 // Takes a flattened list of closed intervals 106 // Takes a flattened list of closed intervals
72 template <class T, size_t size> 107 template <class T, size_t size>
73 bool valueInIntervalList(const T (&intervalList)[size], const T& value) 108 bool valueInIntervalList(const T (&intervalList)[size], const T& value)
74 { 109 {
75 const T* bound = std::upper_bound(&intervalList[0], &intervalList[size], val ue); 110 const T* bound = std::upper_bound(&intervalList[0], &intervalList[size], val ue);
76 if ((bound - intervalList) % 2 == 1) 111 if ((bound - intervalList) % 2 == 1)
77 return true; 112 return true;
78 return bound > intervalList && *(bound - 1) == value; 113 return bound > intervalList && *(bound - 1) == value;
79 } 114 }
80 115
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Search for other Complex cases 212 // Search for other Complex cases
178 if (valueInIntervalList(complexCodePathRanges, c)) 213 if (valueInIntervalList(complexCodePathRanges, c))
179 return ComplexPath; 214 return ComplexPath;
180 } 215 }
181 216
182 return result; 217 return result;
183 } 218 }
184 219
185 bool Character::isUprightInMixedVertical(UChar32 character) 220 bool Character::isUprightInMixedVertical(UChar32 character)
186 { 221 {
187 return hasProperty(character, CharacterProperty::isUprightInMixedVertical); 222 RETURN_HAS_PROPERTY(character, isUprightInMixedVertical)
188 } 223 }
189 224
190 bool Character::isCJKIdeographOrSymbol(UChar32 c) 225 bool Character::isCJKIdeographOrSymbol(UChar32 c)
191 { 226 {
192 // Likely common case 227 // Likely common case
193 if (c < 0x2C7) 228 if (c < 0x2C7)
194 return false; 229 return false;
195 230
196 return hasProperty(c, CharacterProperty::isCJKIdeographOrSymbol); 231 RETURN_HAS_PROPERTY(c, isCJKIdeographOrSymbol)
197 } 232 }
198 233
199 unsigned Character::expansionOpportunityCount(const LChar* characters, size_t le ngth, TextDirection direction, bool& isAfterExpansion, const TextJustify textJus tify) 234 unsigned Character::expansionOpportunityCount(const LChar* characters, size_t le ngth, TextDirection direction, bool& isAfterExpansion, const TextJustify textJus tify)
200 { 235 {
201 unsigned count = 0; 236 unsigned count = 0;
202 if (textJustify == TextJustifyDistribute) { 237 if (textJustify == TextJustifyDistribute) {
203 isAfterExpansion = true; 238 isAfterExpansion = true;
204 return length; 239 return length;
205 } 240 }
206 241
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 348 }
314 349
315 bool Character::isCommonOrInheritedScript(UChar32 character) 350 bool Character::isCommonOrInheritedScript(UChar32 character)
316 { 351 {
317 UErrorCode status = U_ZERO_ERROR; 352 UErrorCode status = U_ZERO_ERROR;
318 UScriptCode script = uscript_getScript(character, &status); 353 UScriptCode script = uscript_getScript(character, &status);
319 return U_SUCCESS(status) && (script == USCRIPT_COMMON || script == USCRIPT_I NHERITED); 354 return U_SUCCESS(status) && (script == USCRIPT_COMMON || script == USCRIPT_I NHERITED);
320 } 355 }
321 356
322 } // namespace blink 357 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/Character.h ('k') | third_party/WebKit/Source/platform/fonts/CharacterData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698