Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac2ef619 authored by chenjean's avatar chenjean
Browse files

fix(HCT): HCT background is disruptive with when only Emoji

Bug: 385167023
Flag: com.android.graphics.hwui.flags.high_contrast_text_small_text_rect
Test: atest core/tests/coretests/src/android/text/LayoutTest.java
Change-Id: If5593f869272580a06cfc502585bad6ac9eee7d6
parent 1beb2830
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,20 @@ public abstract class Layout {
                            return;
                        }

                        // To avoid highlighting emoji sequences, we use Extended_Pictgraphs as a
                        // heuristic. Highlighting is skipped based on code points, not glyph type
                        // (text vs. color), so emojis with default text presentation are
                        // intentionally not highlighted (numeric representation with emoji
                        // presentation are manually excluded). Although we process ZWJ and
                        // variation selectors within emoji sequences, they should not affect
                        // highlighting due to their zero-width nature.
                        var codePoint = Character.codePointAt(mText, index);
                        var isEmoji = Character.isEmojiComponent(codePoint)
                                || Character.isExtendedPictographic(codePoint);
                        if (isEmoji && !isStandardNumber(index)) {
                            return;
                        }

                        if (lineNum != mLastLineNum || hasBgColorChanged) {
                            // Draw what we have so far, then reset the rect and update its color
                            drawRect();
@@ -1090,6 +1104,16 @@ public abstract class Layout {
                        drawRect();
                    }

                    private boolean isStandardNumber(int index) {
                        var codePoint = Character.codePointAt(mText, index);
                        var isNumberSignOrAsterisk = (codePoint >= '0' && codePoint <= '9')
                                || codePoint == '#' || codePoint == '*';
                        var isColoredGlyph = index + 1 < mText.length()
                                && Character.codePointAt(mText, index + 1) == 0xFE0F;

                        return isNumberSignOrAsterisk && !isColoredGlyph;
                    }

                    private void drawRect() {
                        if (!mLineBackground.isEmpty()) {
                            mLineBackground.inset(-padding, -padding);