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

Side by Side Diff: Source/platform/fonts/ScriptRunIterator.h

Issue 1323513006: Upstream ScriptRunIterator for segmenting text runs by script (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Additional review comments addressed, new linkage attempt for kMaxScripts constant Created 5 years, 3 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 | « Source/platform/blink_platform.gypi ('k') | Source/platform/fonts/ScriptRunIterator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ScriptRunIterator_h
6 #define ScriptRunIterator_h
7
8 #include "platform/PlatformExport.h"
9 #include "wtf/Deque.h"
10 #include "wtf/Vector.h"
11 #include "wtf/dtoa/utils.h"
12
13 #include <unicode/uchar.h>
14 #include <unicode/uscript.h>
15
16 namespace blink {
17
18 class ScriptData;
19
20 class PLATFORM_EXPORT ScriptRunIterator {
21 public:
22 ScriptRunIterator(const UChar* text, size_t length);
23
24 // This maintains a reference to data. It must exist for the lifetime of
25 // this object. Typically data is a singleton that exists for the life of
26 // the process.
27 ScriptRunIterator(const UChar* text, size_t length, const ScriptData*);
28
29 bool consume(unsigned& limit, UScriptCode&);
30
31 private:
32 struct BracketRec {
33 UChar32 ch;
34 UScriptCode script;
35 };
36 void openBracket(UChar32);
37 void closeBracket(UChar32);
38 bool mergeSets();
39 void fixupStack(UScriptCode resolvedScript);
40 bool fetch(size_t* pos, UChar32*);
41
42 UScriptCode resolveCurrentScript() const;
43
44 const UChar* m_text;
45 const size_t m_length;
46
47 Deque<BracketRec> m_brackets;
48 size_t m_bracketsFixupDepth;
49 // Limit max brackets so that the bracket tracking buffer does not grow
50 // excessively large when processing long runs of text.
51 static const int kMaxBrackets = 32;
52
53 Vector<UScriptCode> m_currentSet;
54 Vector<UScriptCode> m_nextSet;
55 Vector<UScriptCode> m_aheadSet;
56
57 UChar32 m_aheadCharacter;
58 size_t m_aheadPos;
59
60 UScriptCode m_commonPreferred;
61
62 const ScriptData* m_scriptData;
63
64 DISALLOW_COPY_AND_ASSIGN(ScriptRunIterator);
65 };
66
67 // ScriptData is a wrapper which returns a set of scripts for a particular
68 // character retrieved from the character's primary script and script extensions ,
69 // as per ICU / Unicode data. ScriptData maintains a certain priority order of
70 // the returned values, which are essential for mergeSets method to work
71 // correctly.
72 class PLATFORM_EXPORT ScriptData {
73 protected:
74 ScriptData() = default;
75
76 public:
77 virtual ~ScriptData();
78
79 enum PairedBracketType {
80 BracketTypeNone,
81 BracketTypeOpen,
82 BracketTypeClose,
83 BracketTypeCount
84 };
85
86 static const int kMaxScriptCount;
87
88 virtual void getScripts(UChar32, Vector<UScriptCode>& dst) const = 0;
89
90 virtual UChar32 getPairedBracket(UChar32) const = 0;
91
92 virtual PairedBracketType getPairedBracketType(UChar32) const = 0;
93
94 private:
95 DISALLOW_COPY_AND_ASSIGN(ScriptData);
96 };
97
98 class PLATFORM_EXPORT ICUScriptData : public ScriptData {
99 public:
100 ~ICUScriptData() override
101 {
102 }
103
104 static const ICUScriptData* instance();
105
106 void getScripts(UChar32, Vector<UScriptCode>& dst) const override;
107
108 UChar32 getPairedBracket(UChar32) const override;
109
110 PairedBracketType getPairedBracketType(UChar32) const override;
111
112 private:
113 ICUScriptData()
114 {
115 }
116
117 DISALLOW_COPY_AND_ASSIGN(ICUScriptData);
118 };
119 }
120
121 #endif
OLDNEW
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | Source/platform/fonts/ScriptRunIterator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698