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

Side by Side Diff: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp

Issue 214413002: Add a port of hb_icu_script_to_script to HarfbuzzShaper (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address eae's review comments/nits Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 15 matching lines...) Expand all
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "platform/fonts/harfbuzz/HarfBuzzShaper.h" 33 #include "platform/fonts/harfbuzz/HarfBuzzShaper.h"
34 34
35 #include "RuntimeEnabledFeatures.h" 35 #include "RuntimeEnabledFeatures.h"
36 #include "hb-icu.h" 36 #include "hb.h"
37 #include "platform/fonts/Character.h" 37 #include "platform/fonts/Character.h"
38 #include "platform/fonts/Font.h" 38 #include "platform/fonts/Font.h"
39 #include "platform/fonts/harfbuzz/HarfBuzzFace.h" 39 #include "platform/fonts/harfbuzz/HarfBuzzFace.h"
40 #include "platform/text/SurrogatePairAwareTextIterator.h" 40 #include "platform/text/SurrogatePairAwareTextIterator.h"
41 #include "platform/text/TextBreakIterator.h" 41 #include "platform/text/TextBreakIterator.h"
42 #include "wtf/Compiler.h"
42 #include "wtf/MathExtras.h" 43 #include "wtf/MathExtras.h"
43 #include "wtf/unicode/Unicode.h" 44 #include "wtf/unicode/Unicode.h"
44 #include <unicode/normlzr.h> 45 #include <unicode/normlzr.h>
45 #include <unicode/uchar.h> 46 #include <unicode/uchar.h>
47 #include <unicode/uscript.h>
46 48
47 #include <list> 49 #include <list>
48 #include <map> 50 #include <map>
49 #include <string> 51 #include <string>
50 52
51 namespace WebCore { 53 namespace WebCore {
52 54
53 template<typename T> 55 template<typename T>
54 class HarfBuzzScopedPtr { 56 class HarfBuzzScopedPtr {
55 public: 57 public:
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 if (candidateRuns[i].script != run.script 750 if (candidateRuns[i].script != run.script
749 || candidateRuns[i].fontData != run.fontData) 751 || candidateRuns[i].fontData != run.fontData)
750 break; 752 break;
751 lastMatchingRun = candidateRuns[i]; 753 lastMatchingRun = candidateRuns[i];
752 } 754 }
753 addHarfBuzzRun(run.start, lastMatchingRun.end, run.fontData, run.script) ; 755 addHarfBuzzRun(run.start, lastMatchingRun.end, run.fontData, run.script) ;
754 } 756 }
755 return !m_harfBuzzRuns.isEmpty(); 757 return !m_harfBuzzRuns.isEmpty();
756 } 758 }
757 759
760 // A port of hb_icu_script_to_script because harfbuzz on CrOS is built
761 // without hb-icu. See http://crbug.com/356929
762 static inline hb_script_t ICUScriptToHBScript(UScriptCode script)
763 {
764 if (UNLIKELY(script == USCRIPT_INVALID_CODE))
765 return HB_SCRIPT_INVALID;
766
767 return hb_script_from_string(uscript_getShortName(script), -1);
768 }
769
770
758 void HarfBuzzShaper::addHarfBuzzRun(unsigned startCharacter, 771 void HarfBuzzShaper::addHarfBuzzRun(unsigned startCharacter,
759 unsigned endCharacter, const SimpleFontData* fontData, 772 unsigned endCharacter, const SimpleFontData* fontData,
760 UScriptCode script) 773 UScriptCode script)
761 { 774 {
762 ASSERT(endCharacter > startCharacter); 775 ASSERT(endCharacter > startCharacter);
763 ASSERT(script != USCRIPT_INVALID_CODE); 776 ASSERT(script != USCRIPT_INVALID_CODE);
764 return m_harfBuzzRuns.append(HarfBuzzRun::create(fontData, 777 return m_harfBuzzRuns.append(HarfBuzzRun::create(fontData,
765 startCharacter, endCharacter - startCharacter, 778 startCharacter, endCharacter - startCharacter,
766 m_run.direction(), hb_icu_script_to_script(script))); 779 m_run.direction(), ICUScriptToHBScript(script)));
767 } 780 }
768 781
769 static const uint16_t* toUint16(const UChar* src) 782 static const uint16_t* toUint16(const UChar* src)
770 { 783 {
771 // FIXME: This relies on undefined behavior however it works on the 784 // FIXME: This relies on undefined behavior however it works on the
772 // current versions of all compilers we care about and avoids making 785 // current versions of all compilers we care about and avoids making
773 // a copy of the string. 786 // a copy of the string.
774 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_ uint16_t); 787 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_ uint16_t);
775 return reinterpret_cast<const uint16_t*>(src); 788 return reinterpret_cast<const uint16_t*>(src);
776 } 789 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 if (!foundToX) 1105 if (!foundToX)
1093 toX = m_run.rtl() ? 0 : m_totalWidth; 1106 toX = m_run.rtl() ? 0 : m_totalWidth;
1094 1107
1095 // Using floorf() and roundf() as the same as mac port. 1108 // Using floorf() and roundf() as the same as mac port.
1096 if (fromX < toX) 1109 if (fromX < toX)
1097 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from X), height); 1110 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from X), height);
1098 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he ight); 1111 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he ight);
1099 } 1112 }
1100 1113
1101 } // namespace WebCore 1114 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698