TextLayout (String text, Font basefont, FontRenderContext fontRenderContext) { AttributedString string = new AttributedString(text); int length = text.length(); Font currentFont = basefont; int currentIndex = 0; for (int pos = 0; pos < length; pos = text.offsetByCodePoints(pos, 1)) { int codePoint = text.codePointAt(pos); Font font = basefont; if (!font.canDisplay(codePoint)) { for (SuitableFontProvider provider : SuitableFontProvider.EP_NAME.getExtensionsIfPointIsRegistered()) { font = provider.getFontAbleToDisplay(codePoint, basefont.getSize(), basefont.getStyle(), basefont.getFamily()); if (font != null) break; } } if (!Comparing.equal(currentFont, font)) { if (pos > currentIndex) { string.addAttribute(TextAttribute.FONT, currentFont, currentIndex, pos); } currentFont = font; currentIndex = pos; } } if (currentIndex < length) { string.addAttribute(TextAttribute.FONT, currentFont, currentIndex, length); } return new TextLayout(string.getIterator(), fontRenderContext); }