| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef Character_h | |
| 32 #define Character_h | |
| 33 | |
| 34 #include "platform/PlatformExport.h" | |
| 35 #include "platform/fonts/CharacterProperty.h" | |
| 36 #include "platform/text/TextDirection.h" | |
| 37 #include "platform/text/TextPath.h" | |
| 38 #include "platform/text/TextRun.h" | |
| 39 #include "wtf/Allocator.h" | |
| 40 #include "wtf/HashSet.h" | |
| 41 #include "wtf/text/CharacterNames.h" | |
| 42 #include "wtf/text/WTFString.h" | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 class PLATFORM_EXPORT Character { | |
| 47 STATIC_ONLY(Character); | |
| 48 public: | |
| 49 static CodePath characterRangeCodePath(const LChar*, unsigned) { return Simp
lePath; } | |
| 50 static CodePath characterRangeCodePath(const UChar*, unsigned len); | |
| 51 | |
| 52 static inline bool isInRange(UChar32 character, UChar32 lowerBound, UChar32
upperBound) | |
| 53 { | |
| 54 return character >= lowerBound && character <= upperBound; | |
| 55 } | |
| 56 | |
| 57 static inline bool isUnicodeVariationSelector(UChar32 character) | |
| 58 { | |
| 59 // http://www.unicode.org/Public/UCD/latest/ucd/StandardizedVariants.htm
l | |
| 60 return isInRange(character, 0x180B, 0x180D) // MONGOLIAN FREE VARIATION
SELECTOR ONE to THREE | |
| 61 || isInRange(character, 0xFE00, 0xFE0F) // VARIATION SELECTOR-1 to 1
6 | |
| 62 || isInRange(character, 0xE0100, 0xE01EF); // VARIATION SELECTOR-17
to 256 | |
| 63 } | |
| 64 | |
| 65 static bool isCJKIdeographOrSymbol(UChar32); | |
| 66 static bool isCJKIdeographOrSymbolBase(UChar32 c) | |
| 67 { | |
| 68 return isCJKIdeographOrSymbol(c) | |
| 69 && !(U_GET_GC_MASK(c) & (U_GC_M_MASK | U_GC_LM_MASK | U_GC_SK_MASK))
; | |
| 70 } | |
| 71 | |
| 72 static unsigned expansionOpportunityCount(const LChar*, size_t length, TextD
irection, bool& isAfterExpansion, const TextJustify); | |
| 73 static unsigned expansionOpportunityCount(const UChar*, size_t length, TextD
irection, bool& isAfterExpansion, const TextJustify); | |
| 74 static unsigned expansionOpportunityCount(const TextRun& run, bool& isAfterE
xpansion) | |
| 75 { | |
| 76 if (run.is8Bit()) | |
| 77 return expansionOpportunityCount(run.characters8(), run.length(), ru
n.direction(), isAfterExpansion, run.getTextJustify()); | |
| 78 return expansionOpportunityCount(run.characters16(), run.length(), run.d
irection(), isAfterExpansion, run.getTextJustify()); | |
| 79 } | |
| 80 | |
| 81 static bool isUprightInMixedVertical(UChar32 character); | |
| 82 | |
| 83 static bool treatAsSpace(UChar32 c) | |
| 84 { | |
| 85 return c == spaceCharacter | |
| 86 || c == tabulationCharacter | |
| 87 || c == newlineCharacter | |
| 88 || c == noBreakSpaceCharacter; | |
| 89 } | |
| 90 static bool treatAsZeroWidthSpace(UChar32 c) | |
| 91 { | |
| 92 return treatAsZeroWidthSpaceInComplexScript(c) | |
| 93 || c == zeroWidthNonJoinerCharacter | |
| 94 || c == zeroWidthJoinerCharacter; | |
| 95 } | |
| 96 static bool treatAsZeroWidthSpaceInComplexScript(UChar32 c) | |
| 97 { | |
| 98 return c < 0x20 // ASCII Control Characters | |
| 99 || (c >= 0x7F && c < 0xA0) // ASCII Delete .. No-break spaceCharacte
r | |
| 100 || c == softHyphenCharacter | |
| 101 || c == zeroWidthSpaceCharacter | |
| 102 || (c >= leftToRightMarkCharacter && c <= rightToLeftMarkCharacter) | |
| 103 || (c >= leftToRightEmbedCharacter && c <= rightToLeftOverrideCharac
ter) | |
| 104 || c == zeroWidthNoBreakSpaceCharacter | |
| 105 || c == objectReplacementCharacter; | |
| 106 } | |
| 107 static bool canReceiveTextEmphasis(UChar32); | |
| 108 | |
| 109 static bool isGraphemeExtended(UChar32 c) | |
| 110 { | |
| 111 // http://unicode.org/reports/tr29/#Extend | |
| 112 return u_hasBinaryProperty(c, UCHAR_GRAPHEME_EXTEND); | |
| 113 } | |
| 114 | |
| 115 // Default presentation style according to: | |
| 116 // http://www.unicode.org/reports/tr51/#Presentation_Style | |
| 117 static bool isEmojiTextDefault(UChar32); | |
| 118 static bool isEmojiEmojiDefault(UChar32); | |
| 119 static bool isEmojiModifierBase(UChar32); | |
| 120 static bool isEmojiKeycapBase(UChar32); | |
| 121 static bool isRegionalIndicator(UChar32); | |
| 122 static bool isModifier(UChar32 c) | |
| 123 { | |
| 124 return c >= 0x1F3FB && c <= 0x1F3FF; | |
| 125 } | |
| 126 | |
| 127 static inline UChar normalizeSpaces(UChar character) | |
| 128 { | |
| 129 | |
| 130 if (treatAsSpace(character)) | |
| 131 return spaceCharacter; | |
| 132 | |
| 133 if (treatAsZeroWidthSpace(character)) | |
| 134 return zeroWidthSpaceCharacter; | |
| 135 | |
| 136 return character; | |
| 137 } | |
| 138 | |
| 139 static inline bool isNormalizedCanvasSpaceCharacter(UChar32 c) | |
| 140 { | |
| 141 // According to specification all space characters should be replaced wi
th 0x0020 space character. | |
| 142 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canva
s-element.html#text-preparation-algorithm | |
| 143 // The space characters according to specification are : U+0020, U+0009,
U+000A, U+000C, and U+000D. | |
| 144 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-mi
crosyntaxes.html#space-character | |
| 145 // This function returns true for 0x000B also, so that this is backward
compatible. | |
| 146 // Otherwise, the test LayoutTests/canvas/philip/tests/2d.text.draw.spac
e.collapse.space.html will fail | |
| 147 return c == 0x0009 || (c >= 0x000A && c <= 0x000D); | |
| 148 } | |
| 149 | |
| 150 static String normalizeSpaces(const LChar*, unsigned length); | |
| 151 static String normalizeSpaces(const UChar*, unsigned length); | |
| 152 | |
| 153 static bool isCommonOrInheritedScript(UChar32); | |
| 154 }; | |
| 155 | |
| 156 } // namespace blink | |
| 157 | |
| 158 #endif | |
| OLD | NEW |