Skip to content

Commit 3632b7f

Browse files
author
Fabrice Di Meglio
committed
Improve char mirroring in TextLayoutCache
- now use ICU u_isMirrored() instead of a small hardcoded list of unicode points see bug #5961254 Harfbuzz should be able to support Bidi_mirrored unicode attribute Change-Id: I3243a58558a97930f0e7fdf5e9c1d5695d9393de
1 parent 003952b commit 3632b7f

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() {
@@ -577,7 +559,7 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
577559
#if DEBUG_GLYPHS
578560
ALOGD("Found main code point at index %d", int(j));
579561
#endif
580-
// We found the main code point, so we can normalize the "chunck" and fill
562+
// We found the main code point, so we can normalize the "chunk" and fill
581563
// the remaining with ZWSP so that the Paint.getTextWidth() APIs will still be able
582564
// to get one advance per char
583565
mBuffer.remove();
@@ -608,17 +590,13 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
608590
// script-run splitting with Harfbuzz is splitting on parenthesis
609591
if (isRTL) {
610592
for (ssize_t i = 0; i < ssize_t(count); i++) {
611-
UChar ch = chars[i];
612-
ssize_t index = gBidiMirrored.indexOfKey(ch);
613-
// Skip non "BiDi mirrored" chars
614-
if (index < 0) {
615-
continue;
616-
}
593+
UChar32 ch = chars[i];
594+
if (!u_isMirrored(ch)) continue;
617595
if (!useNormalizedString) {
618596
useNormalizedString = true;
619597
mNormalizedString.setTo(false /* not terminated*/, chars, count);
620598
}
621-
UChar result = gBidiMirrored.valueAt(index);
599+
UChar result = (UChar) u_charMirror(ch);
622600
mNormalizedString.setCharAt(i, result);
623601
#if DEBUG_GLYPHS
624602
ALOGD("Rewriting codepoint '%d' to '%d' at position %d",

0 commit comments

Comments
 (0)