void (List<? super LineFragment> fragments, char[] lineChars, int start, int end, boolean isRtl, FontInfo fontInfo) { boolean needsLayout = isRtl || fontInfo.getFont().hasLayoutAttributes(); boolean nonLatinText = false; if (!needsLayout && (containsSurrogatePairs(lineChars, start, end) || Font.textRequiresLayout(lineChars, start, end))) { needsLayout = true; nonLatinText = true; } if (needsLayout) { int lastOffset = start; if (nonLatinText || containsNonLatinText(lineChars, start, end)) { // Split text by scripts. JDK does this as well inside 'Font.layoutGlyphVector', // but doing it here effectively disables brace matching logic in 'layoutGlyphVector', // which breaks ligatures in some cases (see JBR-10). UnicodeScript lastScript = UnicodeScript.COMMON; for (int i = start; i < end; i++) { int c = Character.codePointAt(lineChars, i, end); if (Character.isSupplementaryCodePoint(c)) { //noinspection AssignmentToForLoopParameter i++; } UnicodeScript script = UnicodeScript.of(c); if (script != UnicodeScript.COMMON && script != UnicodeScript.INHERITED && script != UnicodeScript.UNKNOWN) { if (lastScript != script && lastScript != UnicodeScript.COMMON) { fragments.add(new ComplexTextFragment(lineChars, lastOffset, i, isRtl, fontInfo)); lastOffset = i; } lastScript = script; } } } fragments.add(new ComplexTextFragment(lineChars, lastOffset, end, isRtl, fontInfo)); } else { fragments.add(new SimpleTextFragment(lineChars, start, end, fontInfo)); } }