Skip to content

Commit 66556c7

Browse files
raphlinusAndroid (Google) Code Review
authored andcommitted
Merge "Improve char mirroring in TextLayoutCache"
2 parents d3d3bec + 3632b7f commit 66556c7

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "SkFontHost.h"
2222
#include <unicode/unistr.h>
2323
#include <unicode/normlzr.h>
24+
#include <unicode/uchar.h>
2425

2526
extern "C" {
2627
#include "harfbuzz-unicode.h"
@@ -39,8 +40,6 @@ namespace android {
3940

4041
ANDROID_SINGLETON_STATIC_INSTANCE(TextLayoutEngine);
4142

42-
static KeyedVector<UChar, UChar> gBidiMirrored;
43-
4443
//--------------------------------------------------------------------------------------------------
4544

4645
TextLayoutCache::TextLayoutCache(TextLayoutShaper* shaper) :
@@ -356,23 +355,6 @@ TextLayoutShaper::TextLayoutShaper() : mShaperItemGlyphArraySize(0) {
356355

357356
mShaperItem.font = &mFontRec;
358357
mShaperItem.font->userData = &mShapingPaint;
359-
360-
// Fill the BiDi mirrored chars map
361-
// See: http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBinaryProperties.txt
362-
gBidiMirrored.add('(', ')');
363-
gBidiMirrored.add(')', '(');
364-
gBidiMirrored.add('[', ']');
365-
gBidiMirrored.add(']', '[');
366-
gBidiMirrored.add('{', '}');
367-
gBidiMirrored.add('}', '{');
368-
gBidiMirrored.add('<', '>');
369-
gBidiMirrored.add('>', '<');
370-
gBidiMirrored.add(0x00ab, 0x00bb); // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
371-
gBidiMirrored.add(0x00bb, 0x00ab); // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
372-
gBidiMirrored.add(0x2039, 0x203a); // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
373-
gBidiMirrored.add(0x203a, 0x2039); // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
374-
gBidiMirrored.add(0x2264, 0x2265); // LESS-THAN OR EQUAL TO
375-
gBidiMirrored.add(0x2265, 0x2264); // GREATER-THAN OR EQUAL TO
376358
}
377359

378360
TextLayoutShaper::~TextLayoutShaper() {
@@ -581,7 +563,7 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
581563
#if DEBUG_GLYPHS
582564
ALOGD("Found main code point at index %d", int(j));
583565
#endif
584-
// We found the main code point, so we can normalize the "chunck" and fill
566+
// We found the main code point, so we can normalize the "chunk" and fill
585567
// the remaining with ZWSP so that the Paint.getTextWidth() APIs will still be able
586568
// to get one advance per char
587569
mBuffer.remove();
@@ -612,17 +594,13 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
612594
// script-run splitting with Harfbuzz is splitting on parenthesis
613595
if (isRTL) {
614596
for (ssize_t i = 0; i < ssize_t(count); i++) {
615-
UChar ch = chars[i];
616-
ssize_t index = gBidiMirrored.indexOfKey(ch);
617-
// Skip non "BiDi mirrored" chars
618-
if (index < 0) {
619-
continue;
620-
}
597+
UChar32 ch = chars[i];
598+
if (!u_isMirrored(ch)) continue;
621599
if (!useNormalizedString) {
622600
useNormalizedString = true;
623601
mNormalizedString.setTo(false /* not terminated*/, chars, count);
624602
}
625-
UChar result = gBidiMirrored.valueAt(index);
603+
UChar result = (UChar) u_charMirror(ch);
626604
mNormalizedString.setCharAt(i, result);
627605
#if DEBUG_GLYPHS
628606
ALOGD("Rewriting codepoint '%d' to '%d' at position %d",

0 commit comments

Comments
 (0)