Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / fonts / ScriptRunIterator.h
blob1fd6ae7912ace9c68ae50dfac759600b3cc9639c
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.
5 #ifndef ScriptRunIterator_h
6 #define ScriptRunIterator_h
8 #include "platform/PlatformExport.h"
9 #include "wtf/Deque.h"
10 #include "wtf/Vector.h"
11 #include "wtf/dtoa/utils.h"
13 #include <unicode/uchar.h>
14 #include <unicode/uscript.h>
16 namespace blink {
18 class ScriptData;
20 class PLATFORM_EXPORT ScriptRunIterator {
21 public:
22 ScriptRunIterator(const UChar* text, size_t length);
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*);
29 bool consume(unsigned& limit, UScriptCode&);
31 private:
32 struct BracketRec {
33 UChar32 ch;
34 UScriptCode script;
36 void openBracket(UChar32);
37 void closeBracket(UChar32);
38 bool mergeSets();
39 void fixupStack(UScriptCode resolvedScript);
40 bool fetch(size_t* pos, UChar32*);
42 UScriptCode resolveCurrentScript() const;
44 const UChar* m_text;
45 const size_t m_length;
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;
53 Vector<UScriptCode> m_currentSet;
54 Vector<UScriptCode> m_nextSet;
55 Vector<UScriptCode> m_aheadSet;
57 UChar32 m_aheadCharacter;
58 size_t m_aheadPos;
60 UScriptCode m_commonPreferred;
62 const ScriptData* m_scriptData;
64 DISALLOW_COPY_AND_ASSIGN(ScriptRunIterator);
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;
76 public:
77 virtual ~ScriptData();
79 enum PairedBracketType {
80 BracketTypeNone,
81 BracketTypeOpen,
82 BracketTypeClose,
83 BracketTypeCount
86 static const int kMaxScriptCount;
88 virtual void getScripts(UChar32, Vector<UScriptCode>& dst) const = 0;
90 virtual UChar32 getPairedBracket(UChar32) const = 0;
92 virtual PairedBracketType getPairedBracketType(UChar32) const = 0;
94 private:
95 DISALLOW_COPY_AND_ASSIGN(ScriptData);
98 class PLATFORM_EXPORT ICUScriptData : public ScriptData {
99 public:
100 ~ICUScriptData() override
104 static const ICUScriptData* instance();
106 void getScripts(UChar32, Vector<UScriptCode>& dst) const override;
108 UChar32 getPairedBracket(UChar32) const override;
110 PairedBracketType getPairedBracketType(UChar32) const override;
112 private:
113 ICUScriptData()
117 DISALLOW_COPY_AND_ASSIGN(ICUScriptData);
121 #endif