void (MyGlyphVector gv, int... expectedPositions) { FontLayoutService.setInstance(new MockFontLayoutService(TEST_CHAR_WIDTH, TEST_LINE_HEIGHT, TEST_DESCENT) { @NotNull @Override public GlyphVector layoutGlyphVector(@NotNull Font font, @NotNull FontRenderContext fontRenderContext, char @NotNull [] chars, int start, int end, boolean isRtl) { return gv; } }); try { int length = gv.getNumChars(); char[] text = new char[length]; FontInfo fontInfo = new FontInfo(Font.MONOSPACED, 1, Font.PLAIN, false, new FontRenderContext(null, false, false)); ComplexTextFragment fragment = new ComplexTextFragment(text, 0, length, (gv.getLayoutFlags() & GlyphVector.FLAG_RUN_RTL) != 0, fontInfo); int[] charPositions = new int[length]; for (int i = 0; i < length; i++) { charPositions[i] = (int)fragment.visualColumnToX(0, i + 1); } assertArrayEquals(expectedPositions, charPositions); } finally { FontLayoutService.setInstance(null); } }