PdfSimpleFont extends PdfFont { @Override public byte[] convertToBytes(String text) { byte[] bytes = fontEncoding.convertToBytes(text); for (byte b : bytes) { shortTag[b & 0xff] = 1; } return bytes; } 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 convertGlyphLineToBytesWithSpecificEncodingTest() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createFontSpecificEncoding()); List<Glyph> glyphs = new ArrayList<>(); glyphs.add(T_GLYPH_FONT_SPECIFIC); glyphs.add(E_GLYPH_FONT_SPECIFIC); GlyphLine glyphLine = new GlyphLine(glyphs, 0, 2); byte[] bytes = fontToTest.convertToBytes(glyphLine); Assert.assertArrayEquals(new byte[]{T_CODE, E_CODE}, bytes); }
@Test public void convertGlyphLineToBytesWithEmptyEncodingTest() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createEmptyFontEncoding()); List<Glyph> glyphs = new ArrayList<>(); glyphs.add(T_GLYPH_FONT_SPECIFIC); glyphs.add(E_GLYPH_FONT_SPECIFIC); GlyphLine glyphLine = new GlyphLine(glyphs, 0, 2); byte[] bytes = fontToTest.convertToBytes(glyphLine); Assert.assertArrayEquals(new byte[0], bytes); }
@Test public void convertToBytesWithNullEntry() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createEmptyFontEncoding()); byte[] bytes = fontToTest.convertToBytes((GlyphLine) null); Assert.assertArrayEquals(new byte[0], bytes); }
@Test public void convertGlyphToBytesWithSpecificEncodingTest() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createFontSpecificEncoding()); byte[] bytes = fontToTest.convertToBytes(E_GLYPH_FONT_SPECIFIC); Assert.assertArrayEquals(new byte[]{E_CODE}, bytes); }
@Test public void convertGlyphToBytesWithCustomEncodingTest() throws IOException { FontEncoding emptyFontEncoding = FontEncoding.createEmptyFontEncoding(); emptyFontEncoding.addSymbol(E_CUSTOM_CODE, E_CODE); PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(emptyFontEncoding); byte[] bytes = fontToTest.convertToBytes(E_GLYPH_FONT_SPECIFIC); Assert.assertArrayEquals(new byte[]{E_CUSTOM_CODE}, bytes); }
@Test public void convertGlyphToBytesWithEmptyEncodingTest() throws IOException { PdfSimpleFont<FontProgram> fontToTest = new TestSimpleFont(FontEncoding.createEmptyFontEncoding()); byte[] bytes = fontToTest.convertToBytes(E_GLYPH_FONT_SPECIFIC); Assert.assertArrayEquals(new byte[0], bytes); }