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

Unified Diff: third_party/WebKit/Source/platform/text/TextRun.cpp

Issue 2507063010: Moving string normalization out of HarfBuzz (Closed)
Patch Set: Merge w/HEAD Created 4 years, 1 month 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 | « third_party/WebKit/Source/platform/text/TextRun.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/text/TextRun.cpp
diff --git a/third_party/WebKit/Source/platform/text/TextRun.cpp b/third_party/WebKit/Source/platform/text/TextRun.cpp
index 88c7d5f45a00c061425bde7e140ca24583d301df..36dfef09461fb05a7e6bb92acdd48696758c9b70 100644
--- a/third_party/WebKit/Source/platform/text/TextRun.cpp
+++ b/third_party/WebKit/Source/platform/text/TextRun.cpp
@@ -25,6 +25,7 @@
#include "platform/text/TextRun.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "platform/text/Character.h"
namespace blink {
@@ -57,4 +58,47 @@ void TextRun::setText(const String& string) {
m_data.characters16 = string.characters16();
}
+std::unique_ptr<UChar[]> TextRun::normalizedUTF16(
+ unsigned* resultLength) const {
+ const UChar* source;
+ String stringFor8BitRun;
+ if (is8Bit()) {
+ stringFor8BitRun = String::make16BitFrom8BitSource(characters8(), length());
+ source = stringFor8BitRun.characters16();
+ } else {
+ source = characters16();
+ }
+
+ UChar* buffer = new UChar[m_len + 1];
+ *resultLength = 0;
+
+ bool error = false;
+ unsigned position = 0;
+ while (position < m_len) {
+ UChar32 character;
+ U16_NEXT(source, position, m_len, character);
+ // Don't normalize tabs as they are not treated as spaces for word-end.
+ if (normalizeSpace() &&
+ Character::isNormalizedCanvasSpaceCharacter(character)) {
+ character = spaceCharacter;
+ } else if (Character::treatAsSpace(character) &&
+ character != noBreakSpaceCharacter) {
+ character = spaceCharacter;
+ } else if (!RuntimeEnabledFeatures::
+ renderUnicodeControlCharactersEnabled() &&
+ Character::legacyTreatAsZeroWidthSpaceInComplexScript(
+ character)) {
+ character = zeroWidthSpaceCharacter;
+ } else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) {
+ character = zeroWidthSpaceCharacter;
+ }
+
+ U16_APPEND(buffer, *resultLength, m_len, character, error);
+ DCHECK(!error);
+ }
+
+ DCHECK(*resultLength <= m_len);
+ return wrapArrayUnique(buffer);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/text/TextRun.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698