109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/* 209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2014 Google Inc. All rights reserved. 309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modification, are permitted provided that the following conditions are 609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * met: 709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * in the documentation and/or other materials provided with the 1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * distribution. 1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * this software without specific prior written permission. 1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */ 3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#ifndef Character_h 3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#define Character_h 3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/PlatformExport.h" 3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/text/TextDirection.h" 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/text/TextPath.h" 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/HashSet.h" 3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/text/WTFString.h" 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/unicode/CharacterNames.h" 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 41c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)class PLATFORM_EXPORT Character { 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)public: 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static CodePath characterRangeCodePath(const LChar*, unsigned) { return SimplePath; } 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static CodePath characterRangeCodePath(const UChar*, unsigned len); 4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static bool isCJKIdeograph(UChar32); 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static bool isCJKIdeographOrSymbol(UChar32); 5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static unsigned expansionOpportunityCount(const LChar*, size_t length, TextDirection, bool& isAfterExpansion); 5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static unsigned expansionOpportunityCount(const UChar*, size_t length, TextDirection, bool& isAfterExpansion); 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci static bool treatAsSpace(UChar c) { return c == space || c == characterTabulation || c == newlineCharacter || c == noBreakSpace; } 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static bool treatAsZeroWidthSpace(UChar c) { return treatAsZeroWidthSpaceInComplexScript(c) || c == 0x200c || c == 0x200d; } 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static bool treatAsZeroWidthSpaceInComplexScript(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == softHyphen || c == zeroWidthSpace || (c >= 0x200e && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == zeroWidthNoBreakSpace || c == objectReplacementCharacter; } 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static bool canReceiveTextEmphasis(UChar32); 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static inline UChar normalizeSpaces(UChar character) 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) { 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (treatAsSpace(character)) 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return space; 6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (treatAsZeroWidthSpace(character)) 6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return zeroWidthSpace; 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return character; 6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 707242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci static inline bool isNormalizedCanvasSpaceCharacter(UChar c) 717242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci { 727242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // According to specification all space characters should be replaced with 0x0020 space character. 737242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-preparation-algorithm 747242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // The space characters according to specification are : U+0020, U+0009, U+000A, U+000C, and U+000D. 757242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character 767242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // This function returns true for 0x000B also, so that this is backward compatible. 777242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // Otherwise, the test LayoutTests/canvas/philip/tests/2d.text.draw.space.collapse.space.html will fail 787242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci return c == 0x0009 || (c >= 0x000A && c <= 0x000D); 797242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci } 807242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci 8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static String normalizeSpaces(const LChar*, unsigned length); 8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static String normalizeSpaces(const UChar*, unsigned length); 8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)private: 8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) Character(); 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}; 8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 88e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)} // namespace blink 8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#endif 91