PdfSimpleFont extends PdfFont { @Override public int appendGlyphs(String text, int from, int to, List<Glyph> glyphs) { int processed = 0; if (fontEncoding.isFontSpecific()) { for (int i = from; i <= to; i++) { Glyph glyph = fontProgram.getGlyphByCode(text.charAt(i) & 0xFF); if (glyph != null) { glyphs.add(glyph); processed++; } else { break; } } } else { for (int i = from; i <= to; i++) { Glyph glyph = getGlyph((int) text.charAt(i)); if (glyph != null && (containsGlyph(glyph.getUnicode()) || isAppendableGlyph(glyph))) { glyphs.add(glyph); processed++; } else if (glyph == null && TextUtil.isWhitespaceOrNonPrintable((int) text.charAt(i))) { processed++; } else { break; } } } return processed; } protected  PdfSimpleFont(PdfDictionary fontDictionary); protected  PdfSimpleFont(); @Override boolean isBuiltWith(String fontProgram, String encoding); @Override GlyphLine createGlyphLine(String content); @Override int appendGlyphs(String text, int from, int to, List<Glyph> glyphs); @Override int appendAnyGlyph(String text, int from, List<Glyph> glyphs); FontEncoding getFontEncoding(); @Override byte[] convertToBytes(String text); @Override byte[] convertToBytes(GlyphLine glyphLine); @Override byte[] convertToBytes(Glyph glyph); @Override void writeText(GlyphLine text, int from, int to, PdfOutputStream stream); @Override void writeText(String text, PdfOutputStream stream); @Override String decode(PdfString content); @Override GlyphLine decodeIntoGlyphLine(PdfString content); @Override float getContentWidth(PdfString content); boolean isForceWidthsOutput(); void setForceWidthsOutput(boolean forceWidthsOutput);  }
@Test public void appendGlyphsWithSpecificEncodingTest() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createFontSpecificEncoding()); List<Glyph> toAppend = new ArrayList<>(); int processed = fontToTest.appendGlyphs("te", 0, 1, toAppend); Assert.assertEquals(2, processed); List<Glyph> glyphs = new ArrayList<>(); glyphs.add(T_GLYPH_FONT_SPECIFIC); glyphs.add(E_GLYPH_FONT_SPECIFIC); Assert.assertEquals(glyphs, toAppend); }
@Test public void appendGlyphsWithEmptyEncodingTest() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createEmptyFontEncoding()); List<Glyph> toAppend = new ArrayList<>(); int processed = fontToTest.appendGlyphs("e ete", 0, 4, toAppend); Assert.assertEquals(3, processed); List<Glyph> glyphs = new ArrayList<>(); glyphs.add(E_GLYPH_CUSTOM_MAPPED); glyphs.add(E_GLYPH_CUSTOM_MAPPED); Assert.assertEquals(glyphs, toAppend); }