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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | Source/platform/fonts/ScriptRunIterator.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/ScriptRunIterator.h
diff --git a/Source/platform/fonts/ScriptRunIterator.h b/Source/platform/fonts/ScriptRunIterator.h
new file mode 100644
index 0000000000000000000000000000000000000000..1fd6ae7912ace9c68ae50dfac759600b3cc9639c
--- /dev/null
+++ b/Source/platform/fonts/ScriptRunIterator.h
@@ -0,0 +1,121 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ScriptRunIterator_h
+#define ScriptRunIterator_h
+
+#include "platform/PlatformExport.h"
+#include "wtf/Deque.h"
+#include "wtf/Vector.h"
+#include "wtf/dtoa/utils.h"
+
+#include <unicode/uchar.h>
+#include <unicode/uscript.h>
+
+namespace blink {
+
+class ScriptData;
+
+class PLATFORM_EXPORT ScriptRunIterator {
+public:
+ ScriptRunIterator(const UChar* text, size_t length);
+
+ // This maintains a reference to data. It must exist for the lifetime of
+ // this object. Typically data is a singleton that exists for the life of
+ // the process.
+ ScriptRunIterator(const UChar* text, size_t length, const ScriptData*);
+
+ bool consume(unsigned& limit, UScriptCode&);
+
+private:
+ struct BracketRec {
+ UChar32 ch;
+ UScriptCode script;
+ };
+ void openBracket(UChar32);
+ void closeBracket(UChar32);
+ bool mergeSets();
+ void fixupStack(UScriptCode resolvedScript);
+ bool fetch(size_t* pos, UChar32*);
+
+ UScriptCode resolveCurrentScript() const;
+
+ const UChar* m_text;
+ const size_t m_length;
+
+ Deque<BracketRec> m_brackets;
+ size_t m_bracketsFixupDepth;
+ // Limit max brackets so that the bracket tracking buffer does not grow
+ // excessively large when processing long runs of text.
+ static const int kMaxBrackets = 32;
+
+ Vector<UScriptCode> m_currentSet;
+ Vector<UScriptCode> m_nextSet;
+ Vector<UScriptCode> m_aheadSet;
+
+ UChar32 m_aheadCharacter;
+ size_t m_aheadPos;
+
+ UScriptCode m_commonPreferred;
+
+ const ScriptData* m_scriptData;
+
+ DISALLOW_COPY_AND_ASSIGN(ScriptRunIterator);
+};
+
+// ScriptData is a wrapper which returns a set of scripts for a particular
+// character retrieved from the character's primary script and script extensions,
+// as per ICU / Unicode data. ScriptData maintains a certain priority order of
+// the returned values, which are essential for mergeSets method to work
+// correctly.
+class PLATFORM_EXPORT ScriptData {
+protected:
+ ScriptData() = default;
+
+public:
+ virtual ~ScriptData();
+
+ enum PairedBracketType {
+ BracketTypeNone,
+ BracketTypeOpen,
+ BracketTypeClose,
+ BracketTypeCount
+ };
+
+ static const int kMaxScriptCount;
+
+ virtual void getScripts(UChar32, Vector<UScriptCode>& dst) const = 0;
+
+ virtual UChar32 getPairedBracket(UChar32) const = 0;
+
+ virtual PairedBracketType getPairedBracketType(UChar32) const = 0;
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ScriptData);
+};
+
+class PLATFORM_EXPORT ICUScriptData : public ScriptData {
+public:
+ ~ICUScriptData() override
+ {
+ }
+
+ static const ICUScriptData* instance();
+
+ void getScripts(UChar32, Vector<UScriptCode>& dst) const override;
+
+ UChar32 getPairedBracket(UChar32) const override;
+
+ PairedBracketType getPairedBracketType(UChar32) const override;
+
+private:
+ ICUScriptData()
+ {
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ICUScriptData);
+};
+}
+
+#endif
« 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