TextPreprocessingUtil { public static GlyphLine replaceSpecialWhitespaceGlyphs(GlyphLine line, PdfFont font) { if (null != line) { boolean isMonospaceFont = font.getFontProgram().getFontMetrics().isFixedPitch(); Glyph space = font.getGlyph('\u0020'); int spaceWidth = space.getWidth(); Glyph glyph; int lineSize = line.size(); for (int i = 0; i < lineSize; i++) { glyph = line.get(i); int xAdvance = 0; boolean isSpecialWhitespaceGlyph = false; if (glyph.getCode() <= 0) { switch (glyph.getUnicode()) { case '\u2002': { xAdvance = isMonospaceFont ? 0 : 500 - spaceWidth; isSpecialWhitespaceGlyph = true; break; } case '\u2003': { xAdvance = isMonospaceFont ? 0 : 1000 - spaceWidth; isSpecialWhitespaceGlyph = true; break; } case '\u2009': { xAdvance = isMonospaceFont ? 0 : 200 - spaceWidth; isSpecialWhitespaceGlyph = true; break; } case '\t': { xAdvance = 3 * spaceWidth; isSpecialWhitespaceGlyph = true; break; } } } if (isSpecialWhitespaceGlyph) { Glyph newGlyph = new Glyph(space, glyph.getUnicode()); assert xAdvance <= Short.MAX_VALUE && xAdvance >= Short.MIN_VALUE; newGlyph.setXAdvance((short) xAdvance); line.set(i, newGlyph); } } } return line; } private  TextPreprocessingUtil(); static GlyphLine replaceSpecialWhitespaceGlyphs(GlyphLine line, PdfFont font);  }
@Test public void regularSymbolTest() { GlyphLine glyphLine = new GlyphLine(); Glyph regularGlyph = pdfFont.getGlyph('a'); glyphLine.add(0, regularGlyph); TextPreprocessingUtil.replaceSpecialWhitespaceGlyphs(glyphLine, pdfFont); Glyph glyph = glyphLine.get(0); Assert.assertEquals(regularGlyph, glyph); }