public static int[] convertToUtf32(String text) { if (text == null) { return null; } List<Integer> charCodes = new ArrayList<>(text.length()); int pos = 0; while (pos < text.length()) { if (isSurrogatePair(text, pos)) { charCodes.add(convertToUtf32(text, pos)); pos += 2; } else { charCodes.add((int) text.charAt(pos)); pos++; } } return ArrayUtil.toIntArray(charCodes); }
public static int[] convertToUtf32(String text) { if (text == null) { return null; } List<Integer> charCodes = new ArrayList<>(text.length()); int pos = 0; while (pos < text.length()) { if (isSurrogatePair(text, pos)) { charCodes.add(convertToUtf32(text, pos)); pos += 2; } else { charCodes.add((int) text.charAt(pos)); pos++; } } return ArrayUtil.toIntArray(charCodes); }
private void updateBidiLevels(int totalNumberOfTrimmedGlyphs, BaseDirection baseDirection) { if (totalNumberOfTrimmedGlyphs != 0 && levels != null) { levels = Arrays.copyOfRange(levels, totalNumberOfTrimmedGlyphs, levels.length); } List<Integer> unicodeIdsReorderingList = null; if (levels == null && baseDirection != null && baseDirection != BaseDirection.NO_BIDI) { unicodeIdsReorderingList = new ArrayList<>(); boolean newLineFound = false; for (IRenderer child : childRenderers) { if (newLineFound) { break; } if (child instanceof TextRenderer) { GlyphLine text = ((TextRenderer) child).getText(); for (int i = text.start; i < text.end; i++) { Glyph glyph = text.get(i); if (TextUtil.isNewLine(glyph)) { newLineFound = true; break; } // we assume all the chars will have the same bidi group // we also assume pairing symbols won't get merged with other ones int unicode = glyph.hasValidUnicode() ? glyph.getUnicode() : glyph.getUnicodeChars()[0]; unicodeIdsReorderingList.add(unicode); } } } levels = unicodeIdsReorderingList.size() > 0 ? TypographyUtils.getBidiLevels(baseDirection, ArrayUtil.toIntArray(unicodeIdsReorderingList)) : null; } }
private void updateBidiLevels(int totalNumberOfTrimmedGlyphs, BaseDirection baseDirection) { if (totalNumberOfTrimmedGlyphs != 0 && levels != null) { levels = Arrays.copyOfRange(levels, totalNumberOfTrimmedGlyphs, levels.length); } List<Integer> unicodeIdsReorderingList = null; if (levels == null && baseDirection != null && baseDirection != BaseDirection.NO_BIDI) { unicodeIdsReorderingList = new ArrayList<>(); boolean newLineFound = false; for (IRenderer child : childRenderers) { if (newLineFound) { break; } if (child instanceof TextRenderer) { GlyphLine text = ((TextRenderer) child).getText(); for (int i = text.start; i < text.end; i++) { Glyph glyph = text.get(i); if (TextUtil.isNewLine(glyph)) { newLineFound = true; break; } // we assume all the chars will have the same bidi group // we also assume pairing symbols won't get merged with other ones int unicode = glyph.hasValidUnicode() ? glyph.getUnicode() : glyph.getUnicodeChars()[0]; unicodeIdsReorderingList.add(unicode); } } } levels = unicodeIdsReorderingList.size() > 0 ? TypographyUtils.getBidiLevels(baseDirection, ArrayUtil.toIntArray(unicodeIdsReorderingList)) : null; } }