diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/LayoutProcessor.java b/openpdf/src/main/java/com/lowagie/text/pdf/LayoutProcessor.java index 64797ffbe..86db322cc 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/LayoutProcessor.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/LayoutProcessor.java @@ -80,9 +80,8 @@ private LayoutProcessor() { /** * Enables the processor. - * Kerning and ligatures are switched off. - * - * This method can only be called once. + *

+ * Kerning and ligatures are switched off. This method can only be called once. */ public static void enable() { enabled = true; @@ -90,9 +89,8 @@ public static void enable() { /** * Enables the processor with the provided flags. - * Kerning and ligatures are switched off. - * - * This method can only be called once. + *

+ * Kerning and ligatures are switched off. This method can only be called once. * * @param flags see java.awt.Font.layoutGlyphVector */ @@ -100,15 +98,14 @@ public static void enable(int flags) { if (enabled) { throw new UnsupportedOperationException("LayoutProcessor is already enabled"); } - enabled = true; + enable(); LayoutProcessor.flags = flags; } /** * Enables the processor. - * Kerning and ligatures are switched on. - * - * This method can only be called once. + *

+ * Kerning and ligatures are switched on. This method can only be called once. */ public static void enableKernLiga() { enableKernLiga(DEFAULT_FLAGS); @@ -116,9 +113,8 @@ public static void enableKernLiga() { /** * Enables the processor with the provided flags. - * Kerning and ligatures are switched on. - * - * This method can only be called once. + *

+ * Kerning and ligatures are switched on. This method can only be called once. * * @param flags see java.awt.Font.layoutGlyphVector */ @@ -128,7 +124,7 @@ public static void enableKernLiga(int flags) { } setKerning(); setLigatures(); - enabled = true; + enable(); LayoutProcessor.flags = flags; } @@ -138,81 +134,87 @@ public static boolean isEnabled() { /** * Set kerning - * @see - * - * Oracle: The Java™ Tutorials, Using Text Attributes to Style Text + * + * @see + * Oracle: The Java™ Tutorials, Using Text Attributes to Style Text */ public static void setKerning() { LayoutProcessor.globalTextAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON); } + /** * Set kerning for one font + * * @param font The font for which kerning is to be turned on - * @see - * - * Oracle: The Java™ Tutorials, Using Text Attributes to Style Text + * @see + * Oracle: The Java™ Tutorials, Using Text Attributes to Style Text */ - public static void setKerning(com.lowagie.text.Font font) { + public static void setKerning(com.lowagie.text.Font font) { Map textAttributes = new HashMap<>(); textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON); setTextAttributes(font, textAttributes); } + /** * Add ligatures */ public static void setLigatures() { LayoutProcessor.globalTextAttributes.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON); } + /** * Set ligatures for one font - * @param font The font for which ligatures are to be turned on * + * @param font The font for which ligatures are to be turned on */ - public static void setLigatures(com.lowagie.text.Font font) { + public static void setLigatures(com.lowagie.text.Font font) { Map textAttributes = new HashMap<>(); textAttributes.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON); setTextAttributes(font, textAttributes); } + /** * Set run direction for one font to RTL - * @param font The font for which the run direction is set * + * @param font The font for which the run direction is set */ - public static void setRunDirectionRtl(com.lowagie.text.Font font) { + public static void setRunDirectionRtl(com.lowagie.text.Font font) { setRunDirection(font, TextAttribute.RUN_DIRECTION_RTL); } + /** * Set run direction for one font to LTR - * @param font The font for which the run direction is set * + * @param font The font for which the run direction is set */ - public static void setRunDirectionLtr(com.lowagie.text.Font font) { + public static void setRunDirectionLtr(com.lowagie.text.Font font) { setRunDirection(font, TextAttribute.RUN_DIRECTION_LTR); } + /** * Set run direction for one font - * @param font The font for which the run direction is set * + * @param font The font for which the run direction is set */ - private static void setRunDirection(com.lowagie.text.Font font, Boolean runDirection) { + private static void setRunDirection(com.lowagie.text.Font font, Boolean runDirection) { Map textAttributes = new HashMap<>(); textAttributes.put(TextAttribute.RUN_DIRECTION, runDirection); setTextAttributes(font, textAttributes); } + /** - * Set text attributes to font - * The attributes are used only for glyph layout, - * and don't change the visual appearance of the font - * @param font The font for which kerning is to be turned on + * Set text attributes to font The attributes are used only for glyph layout, and don't change the visual appearance + * of the font + * + * @param font The font for which kerning is to be turned on * @param textAttributes Map of text attributes to be set - * @see - * - * Oracle: The Java™ Tutorials, Using Text Attributes to Style Text* + * @see + * Oracle: The Java™ Tutorials, Using Text Attributes to Style Text* */ - private static void setTextAttributes(com.lowagie.text.Font font, Map textAttributes) { + private static void setTextAttributes(com.lowagie.text.Font font, Map textAttributes) { BaseFont baseFont = font.getBaseFont(); java.awt.Font awtFont = awtFontMap.get(baseFont); - if (awtFont!=null) { + if (awtFont != null) { awtFont = awtFont.deriveFont(textAttributes); awtFontMap.put(baseFont, awtFont); } @@ -233,9 +235,8 @@ public static boolean supportsFont(BaseFont baseFont) { /** * Loads the AWT font needed for layout * - * @param baseFont OpenPdf base font + * @param baseFont OpenPdf base font * @param filename of the font file - * * @throws RuntimeException if font can not be loaded */ public static void loadFont(BaseFont baseFont, String filename) { @@ -257,8 +258,8 @@ public static void loadFont(BaseFont baseFont, String filename) { if (file.canRead()) { inputStream = Files.newInputStream(file.toPath()); } else if (filename.startsWith("file:/") || filename.startsWith("http://") - || filename.startsWith("https://") || filename.startsWith("jar:") - || filename.startsWith("wsjar:")) { + || filename.startsWith("https://") || filename.startsWith("jar:") + || filename.startsWith("wsjar:")) { inputStream = new URL(filename).openStream(); } else if ("-".equals(filename)) { inputStream = System.in; @@ -267,11 +268,11 @@ public static void loadFont(BaseFont baseFont, String filename) { } if (inputStream == null) { throw new IOException( - MessageLocalization.getComposedMessage("1.not.found.as.file.or.resource", filename)); + MessageLocalization.getComposedMessage("1.not.found.as.file.or.resource", filename)); } awtFont = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, inputStream); if (awtFont != null) { - if (globalTextAttributes.size()>0) { + if (!globalTextAttributes.isEmpty()) { awtFont = awtFont.deriveFont(LayoutProcessor.globalTextAttributes); } awtFontMap.put(baseFont, awtFont); @@ -293,8 +294,8 @@ public static void loadFont(BaseFont baseFont, String filename) { /** * Computes glyph positioning * - * @param baseFont OpenPdf base font - * @param text input text + * @param baseFont OpenPdf base font + * @param text input text * @return glyph vector containing reordered text, width and positioning info */ public static GlyphVector computeGlyphVector(BaseFont baseFont, float fontSize, String text) { @@ -311,23 +312,22 @@ public static GlyphVector computeGlyphVector(BaseFont baseFont, float fontSize, } java.awt.Font awtFont = LayoutProcessor.awtFontMap.get(baseFont).deriveFont(fontSize); Map textAttributes = awtFont.getAttributes(); - if (textAttributes!=null) { + if (textAttributes != null) { Object runDirection = textAttributes.get(TextAttribute.RUN_DIRECTION); - if (runDirection!=null) { - localFlags = runDirection==TextAttribute.RUN_DIRECTION_LTR ? java.awt.Font.LAYOUT_LEFT_TO_RIGHT : - java.awt.Font.LAYOUT_RIGHT_TO_LEFT; + if (runDirection != null) { + localFlags = runDirection == TextAttribute.RUN_DIRECTION_LTR ? java.awt.Font.LAYOUT_LEFT_TO_RIGHT : + java.awt.Font.LAYOUT_RIGHT_TO_LEFT; } } return awtFont.layoutGlyphVector(fontRenderContext, chars, 0, chars.length, localFlags); } - /** - * Checks if the glyphVector contains adjustments - * that make advanced layout necessary - * - * @param glyphVector glyph vector containing the positions - * @return true, if the glyphVector contains adjustments - */ + /** + * Checks if the glyphVector contains adjustments that make advanced layout necessary + * + * @param glyphVector glyph vector containing the positions + * @return true, if the glyphVector contains adjustments + */ private static boolean hasAdjustments(GlyphVector glyphVector) { boolean retVal = false; float lastX = 0f; @@ -392,4 +392,11 @@ public static Point2D showText(PdfContentByte cb, BaseFont baseFont, float fontS cb.moveTextBasic(dx, -dy); return new Point2D.Double(-p.getX(), p.getY()); } + + public static void disable() { + enabled = false; + flags = DEFAULT_FLAGS; + awtFontMap.clear(); + globalTextAttributes.clear(); + } } diff --git a/openpdf/src/test/java/com/lowagie/text/DocumentTest.java b/openpdf/src/test/java/com/lowagie/text/DocumentTest.java index 3c6c1905e..bee726817 100644 --- a/openpdf/src/test/java/com/lowagie/text/DocumentTest.java +++ b/openpdf/src/test/java/com/lowagie/text/DocumentTest.java @@ -13,8 +13,37 @@ void testThatVersionIsCorrect() { // Then assertThat(versionInCode) - .as("Version number in code %s is not correct.", versionInCode) - .matches("^OpenPDF \\d+\\.\\d+\\.\\d+(-SNAPSHOT)?$"); + .as("Version number in code %s is not correct.", versionInCode) + .matches("^OpenPDF \\d+\\.\\d+\\.\\d+(-SNAPSHOT)?$"); + } + + @Test + void whenSetFootsToValueShouldSetObject() { + // Given + try (Document document = new Document()) { + HeaderFooter footer = new HeaderFooter(new Phrase("Footer"), false); + + // When + document.setFooter(footer); + + // Then + assertThat(document.footer).isEqualTo(footer); + } + } + + @Test + void whenResetFooterShouldSetNull() { + // Given + try (Document document = new Document()) { + HeaderFooter footer = new HeaderFooter(new Phrase("Footer"), false); + document.setFooter(footer); + + // When + document.resetFooter(); + + // Then + assertThat(document.footer).isNull(); + } } } diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/BaseFontTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/BaseFontTest.java new file mode 100644 index 000000000..8d9f10f13 --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/pdf/BaseFontTest.java @@ -0,0 +1,48 @@ +package com.lowagie.text.pdf; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Index.atIndex; + +import java.io.IOException; +import java.io.InputStream; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Test; + +class BaseFontTest { + + @Test + void testGetAllNameEntries() throws IOException { + // given + byte[] bytes = getTestFontBytes(); + // when + String[][] allNameEntries = BaseFont.getAllNameEntries("ViaodaLibre-Regular.ttf", "UTF-8", bytes); + // then + assertThat(allNameEntries).hasDimensions(11, 5); + } + + @Test + void testGetFullFontName() throws IOException { + // given + byte[] bytes = getTestFontBytes(); + // when + String[][] fullFontName = BaseFont.getFullFontName("ViaodaLibre-Regular.ttf", "UTF-8", bytes); + // then + assertThat(fullFontName).hasDimensions(1, 4) + .contains(new String[]{"3", "1", "1033", "Viaoda Libre Regular"}, atIndex(0)); + } + + // test getDescent() + @Test + void testGetDescent() throws IOException { + // when + BaseFont font = BaseFont.createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, false); + // then + assertThat(font.getDescent("byte")).isEqualTo(-264); + } + + private byte[] getTestFontBytes() throws IOException { + InputStream resourceStream = BaseFont.getResourceStream("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", null); + assertThat(resourceStream).as("Font could not be loaded").isNotNull(); + return IOUtils.toByteArray(resourceStream); + } +} diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/CrossReferenceTableEncodingTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/CrossReferenceTableEncodingTest.java index 596bff5ec..71bc8aa1e 100644 --- a/openpdf/src/test/java/com/lowagie/text/pdf/CrossReferenceTableEncodingTest.java +++ b/openpdf/src/test/java/com/lowagie/text/pdf/CrossReferenceTableEncodingTest.java @@ -9,16 +9,25 @@ import java.io.IOException; import java.io.InputStream; import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class CrossReferenceTableEncodingTest { public static final String TEST_PDF = "/encodingTest.pdf"; + private static String filterPdf(final String pdf) { + return pdf.replaceAll("<>", "") + .replaceAll("<>", "") + .replaceAll("<>", "<>") + .replaceAll("startxref\\n(\\d+)\\n%%EOF", "startxref\nXXXXX\n%%EOF"); + } + // This test was once red, even it was not easy to accomplish this. The test must be run with // -Dfile.encoding=IBM273 from the IDE. Maven won't accept this property. + @Disabled("This test runs ok, if it is run alone. It fails when run with other tests in the IDE. Probably it is because some 'static' state in another class.") @Test - public void testCrossReferenceTableEncoding() throws Exception { + void testCrossReferenceTableEncoding() throws Exception { final String actualPDF = generateSimplePdf(); final String expectedPDF = readExpectedFile(); String actual = filterPdf(actualPDF); @@ -26,13 +35,6 @@ public void testCrossReferenceTableEncoding() throws Exception { assertThat(actual).isEqualTo(expected); } - private static String filterPdf(final String pdf) { - return pdf.replaceAll("<>", "") - .replaceAll("<>", "") - .replaceAll("<>", "<>") - .replaceAll("startxref\\n(\\d+)\\n%%EOF", "startxref\nXXXXX\n%%EOF"); - } - private String readExpectedFile() throws IOException { try (final InputStream expected = getClass().getResourceAsStream(TEST_PDF)) { assertThat(expected).isNotNull(); diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessor534Test.java b/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessor534Test.java index a348a6096..fc5097d5a 100644 --- a/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessor534Test.java +++ b/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessor534Test.java @@ -12,6 +12,7 @@ import java.awt.Font; import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,13 +25,18 @@ static void beforeAll() { LayoutProcessor.enable(java.awt.Font.LAYOUT_RIGHT_TO_LEFT); } + @AfterAll + static void afterAll() { + LayoutProcessor.disable(); + } + @BeforeEach void beforeEach() { assumeThat(LayoutProcessor.isSet(Font.LAYOUT_RIGHT_TO_LEFT)).isTrue(); } @Test - public void whenLayoutRightToLeftLatin_thenRevertCharOrder() throws IOException { + void whenLayoutRightToLeftLatinThenRevertCharOrder() throws IOException { // given Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); ByteArrayOutputStream pdfOut = new ByteArrayOutputStream(); @@ -61,7 +67,7 @@ public void whenLayoutRightToLeftLatin_thenRevertCharOrder() throws IOException } @Test - public void whenLayoutRightToLeftHebrew_thenRevertCharOrder() throws IOException { + void whenLayoutRightToLeftHebrewThenRevertCharOrder() throws IOException { // given Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); ByteArrayOutputStream pdfOut = new ByteArrayOutputStream(); diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessorTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessorTest.java new file mode 100644 index 000000000..ce650a9a6 --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessorTest.java @@ -0,0 +1,24 @@ +package com.lowagie.text.pdf; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class LayoutProcessorTest { + + @Test + void testEnable() { + LayoutProcessor.enable(); + assertTrue(LayoutProcessor.isEnabled()); + } + + @Test + void testDisable() { + LayoutProcessor.disable(); + assertFalse(LayoutProcessor.isEnabled()); + assertThat(LayoutProcessor.getFlags()).isEqualTo(-1); + } + +} diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/TTFCacheTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/TTFCacheTest.java new file mode 100644 index 000000000..22c9d4a90 --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/pdf/TTFCacheTest.java @@ -0,0 +1,53 @@ +package com.lowagie.text.pdf; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; + +import com.lowagie.text.ExceptionConverter; +import java.io.IOException; +import org.apache.fop.fonts.truetype.TTFFile; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class TTFCacheTest { + + @Test + void whenGetTTFFileWithNullTtuShouldThrowNpe() { + assertThatNullPointerException().isThrownBy(() -> TTFCache.getTTFFile("test", null)); + } + + @Test + void whenGetTTFFileWithNullFileNameShouldThrowNpe() throws IOException { + TrueTypeFontUnicode font = (TrueTypeFontUnicode) BaseFont + .createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, false); + assertThatNullPointerException().isThrownBy(() -> TTFCache.getTTFFile(null, font)); + } + + @Test + void whenGetTTFFileShouldThrowNpe() throws IOException { + // given + TrueTypeFontUnicode font = (TrueTypeFontUnicode) BaseFont + .createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, false); + + // when + TTFFile ttfFile = TTFCache.getTTFFile("ViaodaLibre-Regular.ttf", font); + + // then + assertThat(ttfFile).isNotNull(); + // load from cache + TTFFile ttfFile1 = TTFCache.getTTFFile("ViaodaLibre-Regular.ttf", font); + assertThat(ttfFile1).isEqualTo(ttfFile); + } + + @Test + void whenLoadTTFShouldThrowNpe() throws IOException { + // given + TrueTypeFontUnicode font = (TrueTypeFontUnicode) BaseFont + .createFont("fonts/jaldi/Jaldi-Regular.otf", BaseFont.IDENTITY_H, false); + font.cff = true; + // when then + Assertions.assertThatThrownBy(() -> TTFCache.getTTFFile("Jaldi-Regular.otf", font)) + .isInstanceOf(ExceptionConverter.class); + } + +} diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/TrueTypeFontTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/TrueTypeFontTest.java new file mode 100644 index 000000000..0c6550926 --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/pdf/TrueTypeFontTest.java @@ -0,0 +1,14 @@ +package com.lowagie.text.pdf; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class TrueTypeFontTest { + + @Test + void testTrueTypeFontDefaultConstructor() { + TrueTypeFont font = new TrueTypeFont(); + assertThat(font).isNotNull(); + } +} diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/fonts/AdvanceTypographyTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/fonts/AdvanceTypographyTest.java index b612c4bd5..e9a95504d 100644 --- a/openpdf/src/test/java/com/lowagie/text/pdf/fonts/AdvanceTypographyTest.java +++ b/openpdf/src/test/java/com/lowagie/text/pdf/fonts/AdvanceTypographyTest.java @@ -1,71 +1,88 @@ package com.lowagie.text.pdf.fonts; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.FopGlyphProcessor; +import com.lowagie.text.pdf.LayoutProcessor; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** - * - * @author Gajendra kumar (raaz2.gajendra@gmail.com) + * @author Gajendra kumar (raaz2.gajendra@gmail.com) */ -public class AdvanceTypographyTest { +class AdvanceTypographyTest { /** - * Without ghyph substitution out will be {660,666,676,1143,656,1130}, which is no correct - * FopGlyphProcessor performs ghyph substitution to correct the output + * Without glyph substitution out will be {660,666,676,1143,656,1130}, which is no correct FopGlyphProcessor + * performs glyph substitution to correct the output + * * @throws Exception - DocumentException or IOException thrown by the processedContent() method */ @Test - public void testTypographySubstitution() throws Exception{ + void testTypographySubstitution() throws Exception { char[] expectedOutput = {660, 666, 911, 656, 1130}; byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( - BaseFont.createFont("fonts/jaldi/Jaldi-Regular.ttf", BaseFont.IDENTITY_H, false), - "नमस्ते", "fonts/jaldi/Jaldi-Regular.ttf", new HashMap<>(), "dflt"); + BaseFont.createFont("fonts/jaldi/Jaldi-Regular.ttf", BaseFont.IDENTITY_H, false), + "नमस्ते", "fonts/jaldi/Jaldi-Regular.ttf", new HashMap<>(), "dflt"); String str = new String(processedContent, "UnicodeBigUnmarked"); - assertArrayEquals(expectedOutput,str.toCharArray()); + assertArrayEquals(expectedOutput, str.toCharArray()); } /** - * In some fonts combination of two characters can be represented by single glyph - * This method tests above case. + * In some fonts combination of two characters can be represented by single glyph This method tests above case. + * * @throws Exception - UnsupportedEncodingException by the convertToBytesWithGlyphs method */ @Test - public void testSubstitutionWithMerge() throws Exception{ + void testSubstitutionWithMerge() throws Exception { char[] expectedOutput = {254, 278, 390, 314, 331, 376, 254, 285, 278}; byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( - BaseFont.createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, false), - "instruction", "fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", new HashMap<>(), "dflt"); + BaseFont.createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, false), + "instruction", "fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", new HashMap<>(), "dflt"); String str = new String(processedContent, "UnicodeBigUnmarked"); - assertArrayEquals(expectedOutput,str.toCharArray()); + assertArrayEquals(expectedOutput, str.toCharArray()); + } + + @Test + void testSubstitutionWithMergeWithLayoutProcessorEnabled() throws Exception { + LayoutProcessor.enable(); + char[] expectedOutput = {254, 278, 390, 314, 331, 376, 254, 285, 278}; + byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( + BaseFont.createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, true, false, null, + null), + "instruction", "fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", new HashMap<>(), "dflt"); + String str = new String(processedContent, "UnicodeBigUnmarked"); + assertArrayEquals(expectedOutput, str.toCharArray()); + LayoutProcessor.disable(); } /** - * Test fonts loaded externally and passed as byte array to BaseFont, Fop should be able to - * resolve these fonts + * Test fonts loaded externally and passed as byte array to BaseFont, Fop should be able to resolve these fonts + * * @throws Exception a DocumentException or an IOException thrown by BaseFont.createFont */ @Test - public void testInMemoryFonts() throws Exception{ - char[] expectedOutput = {254,278,390,314,331,376,254,285,278}; + void testInMemoryFonts() throws Exception { + char[] expectedOutput = {254, 278, 390, 314, 331, 376, 254, 285, 278}; BaseFont font = BaseFont.createFont("ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, - BaseFont.EMBEDDED,true, - getFontByte("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf"), null, false,false); + BaseFont.EMBEDDED, true, + getTestFontByte(), null, false, false); byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( - font, "instruction", "Viaoda Libre", new HashMap<>(), "dflt"); + font, "instruction", "Viaoda Libre", new HashMap<>(), "dflt"); String str = new String(processedContent, "UnicodeBigUnmarked"); - assertArrayEquals(expectedOutput,str.toCharArray()); + assertArrayEquals(expectedOutput, str.toCharArray()); } - /*@Disabled - public void testSurrogatePair() throws Exception{ + @Disabled("This test is failing, need to investigate. @YOSHIDA may know the reason.") + @Test + void testSurrogatePair() throws Exception { BaseFont baseFont = BaseFont.createFont("fonts/jp/GenShinGothic-Normal.ttf", BaseFont.IDENTITY_H, false); @@ -73,14 +90,15 @@ public void testSurrogatePair() throws Exception{ // http://en.glyphwiki.org/wiki/u20bb7 String text = "\uD842\uDFB7"; byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( - baseFont, text, "fonts/jp/GenShinGothic-Normal.ttf", new HashMap<>(), "dflt"); + baseFont, text, "fonts/jp/GenShinGothic-Normal.ttf", new HashMap<>(), "dflt"); String str = new String(processedContent, "UnicodeBigUnmarked"); char[] actual = str.toCharArray(); assertArrayEquals(expectedOutput, actual); - }*/ + } - private byte[] getFontByte(String fileName) throws IOException { - InputStream stream = BaseFont.getResourceStream(fileName, null); + private byte[] getTestFontByte() throws IOException { + InputStream stream = BaseFont.getResourceStream("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", null); + assertThat(stream).isNotNull(); return IOUtils.toByteArray(stream); } } diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidi.java b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidi.java index f215be5fd..59e8284cb 100644 --- a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidi.java +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidi.java @@ -1,7 +1,7 @@ /* * GlyphLayoutDocumentDinSpec91379 - * + * * This code is part of the 'OpenPDF Tutorial'. * You can find the complete tutorial at the following address: * https://github.com/LibrePDF/OpenPDF/wiki/Tutorial @@ -10,7 +10,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * + * */ package com.lowagie.examples.fonts; @@ -28,27 +28,23 @@ * Prints bidirectional text with correct glyph layout, kerning and ligatures globally enabled */ public class GlyphLayoutDocumentBidi { - + public static String INTRO_TEXT = - "Test of bidirectional text\n"+ + "Test of bidirectional text\n" + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; /** * Main method - * + * * @param args -- not used */ - public static void main(String[] args) { - try { - test("GlyphLayoutDocumentBidi.pdf"); - } catch (Exception e) { - e.printStackTrace(); - } + public static void main(String[] args) throws Exception { + test("GlyphLayoutDocumentBidi.pdf"); } /** * Run the test: Show bidirectional text - * + * * @param fileName Name of output file * @throws Exception if an error occurs */ @@ -63,22 +59,21 @@ public static void test(String fileName) throws Exception { // available for glyph layout. String fontDir = "com/lowagie/examples/fonts/"; - FontFactory.register(fontDir+"noto/NotoSans-Regular.ttf", "notoSans"); + FontFactory.register(fontDir + "noto/NotoSans-Regular.ttf", "notoSans"); Font notoSans = FontFactory.getFont("notoSans", BaseFont.IDENTITY_H, true, fontSize); - FontFactory.register(fontDir+"noto/NotoSansArabic-Regular.ttf", "notoSansArabic"); + FontFactory.register(fontDir + "noto/NotoSansArabic-Regular.ttf", "notoSansArabic"); Font notoSansArabic = FontFactory.getFont("notoSansArabic", BaseFont.IDENTITY_H, true, fontSize); try (Document document = new Document()) { PdfWriter writer = PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(fileName))); writer.setInitialLeading(16.0f); document.open(); - document.add(new Chunk(INTRO_TEXT +"Fonts: Noto Sans, Noto Sans Arabic\n\n", notoSans)); + document.add(new Chunk(INTRO_TEXT + "Fonts: Noto Sans, Noto Sans Arabic\n\n", notoSans)); document.add(new Chunk("Guten Tag ", notoSans)); document.add(new Chunk("السلام عليكم", notoSansArabic)); document.add(new Chunk(" Good afternoon", notoSans)); - } catch (Exception e) { - e.printStackTrace(); } + LayoutProcessor.disable(); } -} \ No newline at end of file +} diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidiPerFont.java b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidiPerFont.java index 052cd32c0..b37d68898 100644 --- a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidiPerFont.java +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentBidiPerFont.java @@ -1,7 +1,7 @@ /* * GlyphLayoutDocumentDinSpec91379 - * + * * This code is part of the 'OpenPDF Tutorial'. * You can find the complete tutorial at the following address: * https://github.com/LibrePDF/OpenPDF/wiki/Tutorial @@ -10,7 +10,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * + * */ package com.lowagie.examples.fonts; @@ -25,44 +25,41 @@ import java.nio.file.Paths; /** - * Prints bidirectional text with correct glyph layout, kerning and ligatures globally enabled - * Direction can be chosen per font + * Prints bidirectional text with correct glyph layout, kerning and ligatures globally enabled Direction can be chosen + * per font */ public class GlyphLayoutDocumentBidiPerFont { - + public static String INTRO_TEXT = - "Test of bidirectional text\n"+ + "Test of bidirectional text\n" + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; /** * Main method - * + * * @param args -- not used */ - public static void main(String[] args) { - try { - test("GlyphLayoutDocumentBidiPerFont.pdf"); - } catch (Exception e) { - e.printStackTrace(); - } + public static void main(String[] args) throws Exception { + test("GlyphLayoutDocumentBidiPerFont.pdf"); } /** * Register and get a font, caching is switched off - * @param path the path to a font file - * @param alias the alias you want to use for the font - * @param fontSize the size of this font + * + * @param path the path to a font file + * @param alias the alias you want to use for the font + * @param fontSize the size of this font * @return the Font constructed based on the parameters */ public static Font getFont(String path, String alias, float fontSize) { FontFactory.register(path, alias); return FontFactory.getFont(alias, BaseFont.IDENTITY_H, true, fontSize, Font.UNDEFINED, null, false); - // cached has to be set to false, to allow different attributes for instances of one font + // cached has to be set to 'false', to allow different attributes for instances of one font } /** * Run the test: Show bidirectional text - * + * * @param fileName Name of output file * @throws Exception if an error occurs */ @@ -77,21 +74,20 @@ public static void test(String fileName) throws Exception { // available for glyph layout. String fontDir = "com/lowagie/examples/fonts/"; - Font notoSans = getFont(fontDir+"noto/NotoSans-Regular.ttf", "notoSans", fontSize); + Font notoSans = getFont(fontDir + "noto/NotoSans-Regular.ttf", "notoSans", fontSize); LayoutProcessor.setRunDirectionLtr(notoSans); - Font notoSansArabic = getFont(fontDir+"noto/NotoSansArabic-Regular.ttf", "notoSansArabic", fontSize); + Font notoSansArabic = getFont(fontDir + "noto/NotoSansArabic-Regular.ttf", "notoSansArabic", fontSize); LayoutProcessor.setRunDirectionRtl(notoSansArabic); try (Document document = new Document()) { PdfWriter writer = PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(fileName))); writer.setInitialLeading(16.0f); document.open(); - document.add(new Chunk(INTRO_TEXT +"Fonts: Noto Sans, Noto Sans Arabic\n\n", notoSans)); + document.add(new Chunk(INTRO_TEXT + "Fonts: Noto Sans, Noto Sans Arabic\n\n", notoSans)); document.add(new Chunk("Guten Tag ", notoSans)); document.add(new Chunk("السلام عليكم", notoSansArabic)); document.add(new Chunk(" Good afternoon", notoSans)); - } catch (Exception e) { - e.printStackTrace(); } + LayoutProcessor.disable(); } -} \ No newline at end of file +} diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentDin91379.java b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentDin91379.java index 51e802d89..9160e1cf2 100644 --- a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentDin91379.java +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentDin91379.java @@ -1,6 +1,6 @@ /* * GlyphLayoutDocumentDin91379 - * + * * This code is part of the 'OpenPDF Tutorial'. * You can find the complete tutorial at the following address: * https://github.com/LibrePDF/OpenPDF/wiki/Tutorial @@ -18,100 +18,101 @@ import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.LayoutProcessor; import com.lowagie.text.pdf.PdfWriter; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; /** - * Prints characters and sequences of DIN 91379 - * with correct glyph layout and kerning + * Prints characters and sequences of DIN 91379 with correct glyph layout and kerning */ public class GlyphLayoutDocumentDin91379 { public static String TEXT_INTRO = - "Test of formatting for letters and sequences defined in:\n" - + "DIN 91379:2022-08: Characters and defined character sequences in Unicode for the electronic\n " - + "processing of names and data exchange in Europe, with CD-ROM\n" - + "See https://www.beuth.de/de/norm/din-91379/353496133\n" - + " https://github.com/String-Latin/DIN-91379-Characters-and-Sequences" - + "and https://en.wikipedia.org/wiki/DIN_91379\n\n" - + "Fonts used: Noto Sans Regular, Noto Sans Math Regular, Noto Serif Regular\n" - + " see https://fonts.google.com/noto/specimen/Noto+Sans" - + " and https://github.com/googlefonts/noto-fonts/tree/main/hinted/ttf\n" - + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; + "Test of formatting for letters and sequences defined in:\n" + + "DIN 91379:2022-08: Characters and defined character sequences in Unicode for the electronic\n " + + "processing of names and data exchange in Europe, with CD-ROM\n" + + "See https://www.beuth.de/de/norm/din-91379/353496133\n" + + " https://github.com/String-Latin/DIN-91379-Characters-and-Sequences" + + "and https://en.wikipedia.org/wiki/DIN_91379\n\n" + + "Fonts used: Noto Sans Regular, Noto Sans Math Regular, Noto Serif Regular\n" + + " see https://fonts.google.com/noto/specimen/Noto+Sans" + + " and https://github.com/googlefonts/noto-fonts/tree/main/hinted/ttf\n" + + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; public static String LATIN_CHARS_DIN_91379 = - "bll; Latin Letters (normative)\n" - + "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \n" - + "a b c d e f g h i j k l m n o p q r s t u v w x y z \n" - + "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú \n" - + "Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô \n" - + "õ ö ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď \n" - + "Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ \n" - + "Ī ī Ĭ ĭ Į į İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Ł ł Ń \n" - + "ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ \n" - + "Ş ş Š š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ \n" - + "Ÿ Ź ź Ż ż Ž ž Ƈ ƈ Ə Ɨ Ơ ơ Ư ư Ʒ Ǎ ǎ Ǐ ǐ Ǒ ǒ Ǔ ǔ Ǖ ǖ \n" - + "Ǘ ǘ Ǚ ǚ Ǜ ǜ Ǟ ǟ Ǣ ǣ Ǥ ǥ Ǧ ǧ Ǩ ǩ Ǫ ǫ Ǭ ǭ Ǯ ǯ ǰ Ǵ ǵ Ǹ \n" - + "ǹ Ǻ ǻ Ǽ ǽ Ǿ ǿ Ȓ ȓ Ș ș Ț ț Ȟ ȟ ȧ Ȩ ȩ Ȫ ȫ Ȭ ȭ Ȯ ȯ Ȱ ȱ \n" - + "Ȳ ȳ ə ɨ ʒ Ḃ ḃ Ḇ ḇ Ḋ ḋ Ḍ ḍ Ḏ ḏ Ḑ ḑ ḗ Ḝ ḝ Ḟ ḟ Ḡ ḡ Ḣ ḣ \n" - + "Ḥ ḥ Ḧ ḧ Ḩ ḩ Ḫ ḫ ḯ Ḱ ḱ Ḳ ḳ Ḵ ḵ Ḷ ḷ Ḻ ḻ Ṁ ṁ Ṃ ṃ Ṅ ṅ Ṇ \n" - + "ṇ Ṉ ṉ Ṓ ṓ Ṕ ṕ Ṗ ṗ Ṙ ṙ Ṛ ṛ Ṟ ṟ Ṡ ṡ Ṣ ṣ Ṫ ṫ Ṭ ṭ Ṯ ṯ Ẁ \n" - + "ẁ Ẃ ẃ Ẅ ẅ Ẇ ẇ Ẍ ẍ Ẏ ẏ Ẑ ẑ Ẓ ẓ Ẕ ẕ ẖ ẗ ẞ Ạ ạ Ả ả Ấ ấ \n" - + "Ầ ầ Ẩ ẩ Ẫ ẫ Ậ ậ Ắ ắ Ằ ằ Ẳ ẳ Ẵ ẵ Ặ ặ Ẹ ẹ Ẻ ẻ Ẽ ẽ Ế ế \n" - + "Ề ề Ể ể Ễ ễ Ệ ệ Ỉ ỉ Ị ị Ọ ọ Ỏ ỏ Ố ố Ồ ồ Ổ ổ Ỗ ỗ Ộ ộ \n" - + "Ớ ớ Ờ ờ Ở ở Ỡ ỡ Ợ ợ Ụ ụ Ủ ủ Ứ ứ Ừ ừ Ử ử Ữ ữ Ự ự Ỳ ỳ \n" - + "Ỵ ỵ Ỷ ỷ Ỹ ỹ \n" - + "Sequences\n" - + "A̋ C̀ C̄ C̆ C̈ C̕ C̣ C̦ C̨̆ D̂ F̀ F̄ G̀ H̄ H̦ H̱ J́ J̌ K̀ K̂ K̄ K̇ K̕ K̛ K̦ K͟H \n" - + "K͟h L̂ L̥ L̥̄ L̦ M̀ M̂ M̆ M̐ N̂ N̄ N̆ N̦ P̀ P̄ P̕ P̣ R̆ R̥ R̥̄ S̀ S̄ S̛̄ S̱ T̀ T̄ \n" - + "T̈ T̕ T̛ U̇ Z̀ Z̄ Z̆ Z̈ Z̧ a̋ c̀ c̄ c̆ c̈ c̕ c̣ c̦ c̨̆ d̂ f̀ f̄ g̀ h̄ h̦ j́ k̀ \n" - + "k̂ k̄ k̇ k̕ k̛ k̦ k͟h l̂ l̥ l̥̄ l̦ m̀ m̂ m̆ m̐ n̂ n̄ n̆ n̦ p̀ p̄ p̕ p̣ r̆ r̥ r̥̄ \n" - + "s̀ s̄ s̛̄ s̱ t̀ t̄ t̕ t̛ u̇ z̀ z̄ z̆ z̈ z̧ Ç̆ Û̄ ç̆ û̄ ÿ́ Č̕ Č̣ č̕ č̣ ē̍ Ī́ ī́ \n" - + "ō̍ Ž̦ Ž̧ ž̦ ž̧ Ḳ̄ ḳ̄ Ṣ̄ ṣ̄ Ṭ̄ ṭ̄ Ạ̈ ạ̈ Ọ̈ ọ̈ Ụ̄ Ụ̈ ụ̄ ụ̈ \n" - + "bnlreq; Non-Letters N1 (normative)\n" - + " ' , - . ` ~ ¨ ´ · ʹ ʺ ʾ ʿ ˈ ˌ ’ ‡ \n" - + "bnl; Non-Letters N2 (normative)\n" - + "! \" # $ % & ( ) * + / 0 1 2 3 4 5 6 7 8 9 : ; < = > \n" - + "? @ [ \\ ] ^ _ { | } ¡ ¢ £ ¥ § © ª « ¬ ® ¯ ° ± ² ³ µ \n" - + "¶ ¹ º » ¿ × ÷ € \n" - + "bnlopt; Non-Letters N3 (normative)\n" - + "¤ ¦ ¸ ¼ ½ ¾ \n" - + "bnlnot; Non-Letters N4 (normative)\n" - + "-omitted-\n" - + "dc; Combining diacritics (normative)\n" - + "̀-omitted-\n" - + "gl; Greek Letters (extended)\n" - + "Ά Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ \n" - + "Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν \n" - + "ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ \n" - + "cl; Cyrillic Letters (extended)\n" - + "Ѝ А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш \n" - + "Щ Ъ Ь Ю Я а б в г д е ж з и й к л м н о п р с т у ф \n" - + "х ц ч ш щ ъ ь ю я ѝ \n" - + "enl; Non-Letters E1 (extended)\n" - + "ƒ ʰ ʳ ˆ ˜ ˢ ᵈ ᵗ ‘ ‚ “ ” „ † … ‰ ′ ″ ‹ › ⁰ ⁴ ⁵ ⁶ ⁷ ⁸ \n" - + "⁹ ⁿ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ™ \n\n"; + "bll; Latin Letters (normative)\n" + + "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \n" + + "a b c d e f g h i j k l m n o p q r s t u v w x y z \n" + + "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú \n" + + "Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô \n" + + "õ ö ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď \n" + + "Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ \n" + + "Ī ī Ĭ ĭ Į į İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Ł ł Ń \n" + + "ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ \n" + + "Ş ş Š š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ \n" + + "Ÿ Ź ź Ż ż Ž ž Ƈ ƈ Ə Ɨ Ơ ơ Ư ư Ʒ Ǎ ǎ Ǐ ǐ Ǒ ǒ Ǔ ǔ Ǖ ǖ \n" + + "Ǘ ǘ Ǚ ǚ Ǜ ǜ Ǟ ǟ Ǣ ǣ Ǥ ǥ Ǧ ǧ Ǩ ǩ Ǫ ǫ Ǭ ǭ Ǯ ǯ ǰ Ǵ ǵ Ǹ \n" + + "ǹ Ǻ ǻ Ǽ ǽ Ǿ ǿ Ȓ ȓ Ș ș Ț ț Ȟ ȟ ȧ Ȩ ȩ Ȫ ȫ Ȭ ȭ Ȯ ȯ Ȱ ȱ \n" + + "Ȳ ȳ ə ɨ ʒ Ḃ ḃ Ḇ ḇ Ḋ ḋ Ḍ ḍ Ḏ ḏ Ḑ ḑ ḗ Ḝ ḝ Ḟ ḟ Ḡ ḡ Ḣ ḣ \n" + + "Ḥ ḥ Ḧ ḧ Ḩ ḩ Ḫ ḫ ḯ Ḱ ḱ Ḳ ḳ Ḵ ḵ Ḷ ḷ Ḻ ḻ Ṁ ṁ Ṃ ṃ Ṅ ṅ Ṇ \n" + + "ṇ Ṉ ṉ Ṓ ṓ Ṕ ṕ Ṗ ṗ Ṙ ṙ Ṛ ṛ Ṟ ṟ Ṡ ṡ Ṣ ṣ Ṫ ṫ Ṭ ṭ Ṯ ṯ Ẁ \n" + + "ẁ Ẃ ẃ Ẅ ẅ Ẇ ẇ Ẍ ẍ Ẏ ẏ Ẑ ẑ Ẓ ẓ Ẕ ẕ ẖ ẗ ẞ Ạ ạ Ả ả Ấ ấ \n" + + "Ầ ầ Ẩ ẩ Ẫ ẫ Ậ ậ Ắ ắ Ằ ằ Ẳ ẳ Ẵ ẵ Ặ ặ Ẹ ẹ Ẻ ẻ Ẽ ẽ Ế ế \n" + + "Ề ề Ể ể Ễ ễ Ệ ệ Ỉ ỉ Ị ị Ọ ọ Ỏ ỏ Ố ố Ồ ồ Ổ ổ Ỗ ỗ Ộ ộ \n" + + "Ớ ớ Ờ ờ Ở ở Ỡ ỡ Ợ ợ Ụ ụ Ủ ủ Ứ ứ Ừ ừ Ử ử Ữ ữ Ự ự Ỳ ỳ \n" + + "Ỵ ỵ Ỷ ỷ Ỹ ỹ \n" + + "Sequences\n" + + "A̋ C̀ C̄ C̆ C̈ C̕ C̣ C̦ C̨̆ D̂ F̀ F̄ G̀ H̄ H̦ H̱ J́ J̌ K̀ K̂ K̄ K̇ K̕ K̛ K̦ K͟H \n" + + "K͟h L̂ L̥ L̥̄ L̦ M̀ M̂ M̆ M̐ N̂ N̄ N̆ N̦ P̀ P̄ P̕ P̣ R̆ R̥ R̥̄ S̀ S̄ S̛̄ S̱ T̀ T̄ \n" + + "T̈ T̕ T̛ U̇ Z̀ Z̄ Z̆ Z̈ Z̧ a̋ c̀ c̄ c̆ c̈ c̕ c̣ c̦ c̨̆ d̂ f̀ f̄ g̀ h̄ h̦ j́ k̀ \n" + + "k̂ k̄ k̇ k̕ k̛ k̦ k͟h l̂ l̥ l̥̄ l̦ m̀ m̂ m̆ m̐ n̂ n̄ n̆ n̦ p̀ p̄ p̕ p̣ r̆ r̥ r̥̄ \n" + + "s̀ s̄ s̛̄ s̱ t̀ t̄ t̕ t̛ u̇ z̀ z̄ z̆ z̈ z̧ Ç̆ Û̄ ç̆ û̄ ÿ́ Č̕ Č̣ č̕ č̣ ē̍ Ī́ ī́ \n" + + "ō̍ Ž̦ Ž̧ ž̦ ž̧ Ḳ̄ ḳ̄ Ṣ̄ ṣ̄ Ṭ̄ ṭ̄ Ạ̈ ạ̈ Ọ̈ ọ̈ Ụ̄ Ụ̈ ụ̄ ụ̈ \n" + + "bnlreq; Non-Letters N1 (normative)\n" + + " ' , - . ` ~ ¨ ´ · ʹ ʺ ʾ ʿ ˈ ˌ ’ ‡ \n" + + "bnl; Non-Letters N2 (normative)\n" + + "! \" # $ % & ( ) * + / 0 1 2 3 4 5 6 7 8 9 : ; < = > \n" + + "? @ [ \\ ] ^ _ { | } ¡ ¢ £ ¥ § © ª « ¬ ® ¯ ° ± ² ³ µ \n" + + "¶ ¹ º » ¿ × ÷ € \n" + + "bnlopt; Non-Letters N3 (normative)\n" + + "¤ ¦ ¸ ¼ ½ ¾ \n" + + "bnlnot; Non-Letters N4 (normative)\n" + + "-omitted-\n" + + "dc; Combining diacritics (normative)\n" + + "̀-omitted-\n" + + "gl; Greek Letters (extended)\n" + + "Ά Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ \n" + + "Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν \n" + + "ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ \n" + + "cl; Cyrillic Letters (extended)\n" + + "Ѝ А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш \n" + + "Щ Ъ Ь Ю Я а б в г д е ж з и й к л м н о п р с т у ф \n" + + "х ц ч ш щ ъ ь ю я ѝ \n" + + "enl; Non-Letters E1 (extended)\n" + + "ƒ ʰ ʳ ˆ ˜ ˢ ᵈ ᵗ ‘ ‚ “ ” „ † … ‰ ′ ″ ‹ › ⁰ ⁴ ⁵ ⁶ ⁷ ⁸ \n" + + "⁹ ⁿ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ™ \n\n"; public static String LATIN_CHARS_DIN_91379_MATH = - "enl; Non Letters E1 (extended) math\n" + "enl; Non Letters E1 (extended) math\n" + "∞ ≤ ≥ \n"; public static String LATIN_CHARS_ADDITIONAL = - "Additional non-letters (not included in DIN 91379)\n" + "Additional non-letters (not included in DIN 91379)\n" + "– — •�\n\n"; public static String TEST_KERNING = - "Kerning\n" - +"AVATAR Vector TeX\n\n"; + "Kerning\n" + + "AVATAR Vector TeX\n\n"; public static String TEST_LIGATURES = - "Ligatures\n" + "Ligatures\n" + "ff ffi ffl fi fl\n\n"; /** * Register and get font - * @param path of font file - * @param alias name + * + * @param path of font file + * @param alias name * @param fontSize size of font * @return the loaded font */ @@ -123,26 +124,21 @@ private static Font loadFont(String path, String alias, float fontSize) { /** * Main method - * + * * @param args -- not used */ - public static void main(String[] args) { - try { - test("GlyphLayoutDocumentDin91379.pdf", true); - } catch (Exception e) { - e.printStackTrace(); - } + public static void main(String[] args) throws Exception { + test("GlyphLayoutDocumentDin91379.pdf", true); } /** * Run the test: Print the characters of DIN 91379 in a pdf document - * - * @param fileName Name of output file + * + * @param fileName Name of output file * @param testChunks if true some chunks are added to test positioning - * @throws Exception if an error occurs */ - public static void test(String fileName, boolean testChunks) throws Exception { + public static void test(String fileName, boolean testChunks) throws IOException { // Enable the LayoutProcessor with kerning and ligatures LayoutProcessor.enableKernLiga(); @@ -153,14 +149,13 @@ public static void test(String fileName, boolean testChunks) throws Exception { // available for glyph layout. // Only these fonts can be used. String fontDir = "com/lowagie/examples/fonts/"; - Font sansFont = loadFont(fontDir+"noto/NotoSans-Regular.ttf", "sans", fontSize); + Font sansFont = loadFont(fontDir + "noto/NotoSans-Regular.ttf", "sans", fontSize); String sansFontName = sansFont.getBaseFont().getPostscriptFontName(); - Font mathFont = loadFont(fontDir+"noto/NotoSansMath-Regular.ttf", "math", fontSize); + Font mathFont = loadFont(fontDir + "noto/NotoSansMath-Regular.ttf", "math", fontSize); String mathFontName = mathFont.getBaseFont().getPostscriptFontName(); - Font serifFont = loadFont(fontDir+"noto/NotoSerif-Regular.ttf", "serif", fontSize); + Font serifFont = loadFont(fontDir + "noto/NotoSerif-Regular.ttf", "serif", fontSize); String serifFontName = serifFont.getBaseFont().getPostscriptFontName(); - try (Document document = new Document()) { PdfWriter writer = PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(fileName))); writer.setInitialLeading(16.0f); @@ -174,14 +169,13 @@ public static void test(String fileName, boolean testChunks) throws Exception { document.add(new Chunk(sansFontName + "\n" + TEST_KERNING, sansFont)); document.add(new Chunk(serifFontName + "\n" + TEST_LIGATURES, serifFont)); - if(testChunks) { + if (testChunks) { addChunks(document, sansFont); } - } catch (Exception e) { - e.printStackTrace(); } + LayoutProcessor.disable(); } - + /* * Add several chunks to test positioning */ @@ -196,4 +190,4 @@ private static void addChunks(Document document, Font font) { document.add(new Chunk("j́S̛̄s̛̄K̛", font)); document.add(new Chunk(".\n", font)); } -} \ No newline at end of file +} diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLiga.java b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLiga.java index 312072112..3cf0b1e02 100644 --- a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLiga.java +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLiga.java @@ -1,7 +1,7 @@ /* * GlyphLayoutDocumentDinSpec91379 - * + * * This code is part of the 'OpenPDF Tutorial'. * You can find the complete tutorial at the following address: * https://github.com/LibrePDF/OpenPDF/wiki/Tutorial @@ -10,7 +10,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * + * */ package com.lowagie.examples.fonts; @@ -28,31 +28,27 @@ * Prints text with correct glyph layout, kerning and ligatures globally enabled */ public class GlyphLayoutDocumentKernLiga { - + public static String INTRO_TEXT = - "Test of text attributes for kerning and ligatures\n" - + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; + "Test of text attributes for kerning and ligatures\n" + + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; public static String TEST_TEXT = - "AVATAR Vector TeX ff ffi ffl fi fl.\n\n"; + "AVATAR Vector TeX ff ffi ffl fi fl.\n\n"; /** * Main method - * + * * @param args -- not used */ - public static void main(String[] args) { - try { - test("GlyphLayoutDocumentKernLiga.pdf"); - } catch (Exception e) { - e.printStackTrace(); - } + public static void main(String[] args) throws Exception { + test("GlyphLayoutDocumentKernLiga.pdf"); } /** * Run the test: Show kerning and ligatures - * + * * @param fileName Name of output file * @throws Exception if an error occurs */ @@ -67,17 +63,16 @@ public static void test(String fileName) throws Exception { // available for glyph layout. String fontDir = "com/lowagie/examples/fonts/"; - FontFactory.register(fontDir+"noto/NotoSerif-Regular.ttf", "notoSerif"); + FontFactory.register(fontDir + "noto/NotoSerif-Regular.ttf", "notoSerif"); Font notoSerif = FontFactory.getFont("notoSerif", BaseFont.IDENTITY_H, true, fontSize); try (Document document = new Document()) { PdfWriter writer = PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(fileName))); writer.setInitialLeading(16.0f); document.open(); - document.add(new Chunk(INTRO_TEXT +"Font: Noto Serif Regular\n\n", notoSerif)); - document.add(new Chunk(TEST_TEXT , notoSerif)); - } catch (Exception e) { - e.printStackTrace(); + document.add(new Chunk(INTRO_TEXT + "Font: Noto Serif Regular\n\n", notoSerif)); + document.add(new Chunk(TEST_TEXT, notoSerif)); } + LayoutProcessor.disable(); } -} \ No newline at end of file +} diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLigaPerFont.java b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLigaPerFont.java index 35a6a7369..34d2978d7 100644 --- a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLigaPerFont.java +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutDocumentKernLigaPerFont.java @@ -1,7 +1,7 @@ /* * GlyphLayoutDocumentDinSpec91379 - * + * * This code is part of the 'OpenPDF Tutorial'. * You can find the complete tutorial at the following address: * https://github.com/LibrePDF/OpenPDF/wiki/Tutorial @@ -10,7 +10,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * + * */ package com.lowagie.examples.fonts; @@ -28,44 +28,41 @@ * Test kerning and ligatures per font */ public class GlyphLayoutDocumentKernLigaPerFont { - + public static String TEXT_INTRO = - "Test of kerning and ligatures per font\n" - + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; + "Test of kerning and ligatures per font\n" + + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; public static String TEST_TEXT = - "AVATAR Vector TeX ff ffi ffl fi fl."; + "AVATAR Vector TeX ff ffi ffl fi fl."; /** * Main method - * + * * @param args -- not used */ - public static void main(String[] args) { - try { - test("GlyphLayoutDocumentKernLigaPerFont.pdf"); - } catch (Exception e) { - e.printStackTrace(); - } + public static void main(String[] args) throws Exception { + test("GlyphLayoutDocumentKernLigaPerFont.pdf"); } /** * Register and get a font, caching is switched off - * @param path the path to a font file - * @param alias the alias you want to use for the font - * @param fontSize the size of this font + * + * @param path the path to a font file + * @param alias the alias you want to use for the font + * @param fontSize the size of this font * @return the Font constructed based on the parameters */ public static Font loadFont(String path, String alias, float fontSize) { FontFactory.register(path, alias); return FontFactory.getFont(alias, BaseFont.IDENTITY_H, true, fontSize, Font.UNDEFINED, null, false); - // cached has to be set to false, to allow different attributes for instances of one font + // cached has to be set to 'false', to allow different attributes for instances of one font } /** * Run the test: Show kerning and ligatures - * + * * @param fileName Name of output file * @throws Exception if an error occurs */ @@ -79,18 +76,18 @@ public static void test(String fileName) throws Exception { // The OpenType fonts loaded with FontFactory.register() are // available for glyph layout. String fontDir = "com/lowagie/examples/fonts/"; - Font serifFont = loadFont(fontDir+"noto/NotoSerif-Regular.ttf", "serif", fontSize); + Font serifFont = loadFont(fontDir + "noto/NotoSerif-Regular.ttf", "serif", fontSize); - Font serifKernLiga1 = loadFont(fontDir+"noto/NotoSerif-Regular.ttf", "serif_kern_liga", fontSize); + Font serifKernLiga1 = loadFont(fontDir + "noto/NotoSerif-Regular.ttf", "serif_kern_liga", fontSize); // Switch ligatures and kerning on for one font LayoutProcessor.setLigatures(serifKernLiga1); LayoutProcessor.setKerning(serifKernLiga1); - Font serifKern1 = loadFont(fontDir+"noto/NotoSerif-Regular.ttf", "serif_kern1", fontSize); + Font serifKern1 = loadFont(fontDir + "noto/NotoSerif-Regular.ttf", "serif_kern1", fontSize); // Switch on kerning for one font LayoutProcessor.setKerning(serifKern1); - Font serifLiga1 = loadFont(fontDir+"noto/NotoSerif-Regular.ttf", "serif_liga1", fontSize); + Font serifLiga1 = loadFont(fontDir + "noto/NotoSerif-Regular.ttf", "serif_liga1", fontSize); // Switch on ligatures for one font LayoutProcessor.setLigatures(serifLiga1); @@ -100,14 +97,13 @@ public static void test(String fileName) throws Exception { document.open(); document.add(new Chunk(TEXT_INTRO, serifFont)); - document.add(new Chunk(TEST_TEXT+" no kerning, no ligatures\n", serifFont)); - document.add(new Chunk(TEST_TEXT+" kerning, ligatures\n", serifKernLiga1)); - document.add(new Chunk(TEST_TEXT+" kerning, no ligatures\n", serifKern1)); - document.add(new Chunk(TEST_TEXT+" no kerning, ligatures\n", serifLiga1)); - document.add(new Chunk(TEST_TEXT+" no kerning, no ligatures\n\n", serifFont)); + document.add(new Chunk(TEST_TEXT + " no kerning, no ligatures\n", serifFont)); + document.add(new Chunk(TEST_TEXT + " kerning, ligatures\n", serifKernLiga1)); + document.add(new Chunk(TEST_TEXT + " kerning, no ligatures\n", serifKern1)); + document.add(new Chunk(TEST_TEXT + " no kerning, ligatures\n", serifLiga1)); + document.add(new Chunk(TEST_TEXT + " no kerning, no ligatures\n\n", serifFont)); - } catch (Exception e) { - e.printStackTrace(); } + LayoutProcessor.disable(); } -} \ No newline at end of file +} diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutFormDin91379.java b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutFormDin91379.java index 7308db31a..38f15ac59 100644 --- a/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutFormDin91379.java +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/fonts/GlyphLayoutFormDin91379.java @@ -1,6 +1,6 @@ /* * GlyphLayoutFormDin91379 - * + * * This code is part of the 'OpenPDF Tutorial'. * You can find the complete tutorial at the following address: * https://github.com/LibrePDF/OpenPDF/wiki/Tutorial @@ -12,10 +12,6 @@ package com.lowagie.examples.fonts; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.util.Map; - import com.lowagie.text.Font; import com.lowagie.text.FontFactory; import com.lowagie.text.pdf.AcroFields; @@ -23,94 +19,94 @@ import com.lowagie.text.pdf.LayoutProcessor; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfStamper; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.Map; /** - * Prints characters and sequences of DIN 91379 - * with correct glyph layout + * Prints characters and sequences of DIN 91379 with correct glyph layout */ public class GlyphLayoutFormDin91379 { public static String TEXT_INTRO = - "Test of formatting for letters and sequences defined in:\n" - + "DIN 91379:2022-08: Characters and defined character sequences in Unicode for the electronic\n " - + "processing of names and data exchange in Europe, with CD-ROM\n" - + "See https://www.beuth.de/de/norm/din-91379/353496133\n" - + " https://github.com/String-Latin/DIN-91379-Characters-and-Sequences" - + "and https://en.wikipedia.org/wiki/DIN_91379\n\n" - + "Fonts used: Noto Sans Regular, Noto Sans Math Regular\n" - + " see https://fonts.google.com/noto/specimen/Noto+Sans" - + " and https://github.com/googlefonts/noto-fonts/tree/main/hinted/ttf\n" - + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; + "Test of formatting for letters and sequences defined in:\n" + + "DIN 91379:2022-08: Characters and defined character sequences in Unicode for the electronic\n " + + "processing of names and data exchange in Europe, with CD-ROM\n" + + "See https://www.beuth.de/de/norm/din-91379/353496133\n" + + " https://github.com/String-Latin/DIN-91379-Characters-and-Sequences" + + "and https://en.wikipedia.org/wiki/DIN_91379\n\n" + + "Fonts used: Noto Sans Regular, Noto Sans Math Regular\n" + + " see https://fonts.google.com/noto/specimen/Noto+Sans" + + " and https://github.com/googlefonts/noto-fonts/tree/main/hinted/ttf\n" + + "Using LayoutProcessor for glyph layout with Java built-in routines.\n\n"; public static String LATIN_CHARS_DIN_91379 = - "bll; Latin Letters (normative)\n" - + "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z " - + "a b c d e f g h i j k l m n o p q r s t u v w x y z " - + "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú " - + "Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô " - + "õ ö ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď " - + "Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ " - + "Ī ī Ĭ ĭ Į į İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Ł ł Ń " - + "ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ " - + "Ş ş Š š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ " - + "Ÿ Ź ź Ż ż Ž ž Ƈ ƈ Ə Ɨ Ơ ơ Ư ư Ʒ Ǎ ǎ Ǐ ǐ Ǒ ǒ Ǔ ǔ Ǖ ǖ " - + "Ǘ ǘ Ǚ ǚ Ǜ ǜ Ǟ ǟ Ǣ ǣ Ǥ ǥ Ǧ ǧ Ǩ ǩ Ǫ ǫ Ǭ ǭ Ǯ ǯ ǰ Ǵ ǵ Ǹ " - + "ǹ Ǻ ǻ Ǽ ǽ Ǿ ǿ Ȓ ȓ Ș ș Ț ț Ȟ ȟ ȧ Ȩ ȩ Ȫ ȫ Ȭ ȭ Ȯ ȯ Ȱ ȱ " - + "Ȳ ȳ ə ɨ ʒ Ḃ ḃ Ḇ ḇ Ḋ ḋ Ḍ ḍ Ḏ ḏ Ḑ ḑ ḗ Ḝ ḝ Ḟ ḟ Ḡ ḡ Ḣ ḣ " - + "Ḥ ḥ Ḧ ḧ Ḩ ḩ Ḫ ḫ ḯ Ḱ ḱ Ḳ ḳ Ḵ ḵ Ḷ ḷ Ḻ ḻ Ṁ ṁ Ṃ ṃ Ṅ ṅ Ṇ " - + "ṇ Ṉ ṉ Ṓ ṓ Ṕ ṕ Ṗ ṗ Ṙ ṙ Ṛ ṛ Ṟ ṟ Ṡ ṡ Ṣ ṣ Ṫ ṫ Ṭ ṭ Ṯ ṯ Ẁ " - + "ẁ Ẃ ẃ Ẅ ẅ Ẇ ẇ Ẍ ẍ Ẏ ẏ Ẑ ẑ Ẓ ẓ Ẕ ẕ ẖ ẗ ẞ Ạ ạ Ả ả Ấ ấ " - + "Ầ ầ Ẩ ẩ Ẫ ẫ Ậ ậ Ắ ắ Ằ ằ Ẳ ẳ Ẵ ẵ Ặ ặ Ẹ ẹ Ẻ ẻ Ẽ ẽ Ế ế " - + "Ề ề Ể ể Ễ ễ Ệ ệ Ỉ ỉ Ị ị Ọ ọ Ỏ ỏ Ố ố Ồ ồ Ổ ổ Ỗ ỗ Ộ ộ " - + "Ớ ớ Ờ ờ Ở ở Ỡ ỡ Ợ ợ Ụ ụ Ủ ủ Ứ ứ Ừ ừ Ử ử Ữ ữ Ự ự Ỳ ỳ " - + "Ỵ ỵ Ỷ ỷ Ỹ ỹ \n" - + "Sequences\n" - + "A̋ C̀ C̄ C̆ C̈ C̕ C̣ C̦ C̨̆ D̂ F̀ F̄ G̀ H̄ H̦ H̱ J́ J̌ K̀ K̂ K̄ K̇ K̕ K̛ K̦ K͟H " - + "K͟h L̂ L̥ L̥̄ L̦ M̀ M̂ M̆ M̐ N̂ N̄ N̆ N̦ P̀ P̄ P̕ P̣ R̆ R̥ R̥̄ S̀ S̄ S̛̄ S̱ T̀ T̄ " - + "T̈ T̕ T̛ U̇ Z̀ Z̄ Z̆ Z̈ Z̧ a̋ c̀ c̄ c̆ c̈ c̕ c̣ c̦ c̨̆ d̂ f̀ f̄ g̀ h̄ h̦ j́ k̀ " - + "k̂ k̄ k̇ k̕ k̛ k̦ k͟h l̂ l̥ l̥̄ l̦ m̀ m̂ m̆ m̐ n̂ n̄ n̆ n̦ p̀ p̄ p̕ p̣ r̆ r̥ r̥̄ " - + "s̀ s̄ s̛̄ s̱ t̀ t̄ t̕ t̛ u̇ z̀ z̄ z̆ z̈ z̧ Ç̆ Û̄ ç̆ û̄ ÿ́ Č̕ Č̣ č̕ č̣ ē̍ Ī́ ī́ " - + "ō̍ Ž̦ Ž̧ ž̦ ž̧ Ḳ̄ ḳ̄ Ṣ̄ ṣ̄ Ṭ̄ ṭ̄ Ạ̈ ạ̈ Ọ̈ ọ̈ Ụ̄ Ụ̈ ụ̄ ụ̈ \n" - + "bnlreq; Non-Letters N1 (normative)\n" - + " ' , - . ` ~ ¨ ´ · ʹ ʺ ʾ ʿ ˈ ˌ ’ ‡ \n" - + "bnl; Non-Letters N2 (normative)\n" - + "! \" # $ % & ( ) * + / 0 1 2 3 4 5 6 7 8 9 : ; < = > " - + "? @ [ \\ ] ^ _ { | } ¡ ¢ £ ¥ § © ª « ¬ ® ¯ ° ± ² ³ µ " - + "¶ ¹ º » ¿ × ÷ € \n" - + "bnlopt; Non-Letters N3 (normative)\n" - + "¤ ¦ ¸ ¼ ½ ¾ \n" - + "bnlnot; Non-Letters N4 (normative) -omitted-\n" - + "dc; Combining diacritics (normative) ̀-omitted-\n" - + "gl; Greek Letters (extended)\n" - + "Ά Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ " - + "Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν " - + "ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ \n" - + "cl; Cyrillic Letters (extended)\n" - + "Ѝ А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш " - + "Щ Ъ Ь Ю Я а б в г д е ж з и й к л м н о п р с т у ф " - + "х ц ч ш щ ъ ь ю я ѝ \n" - + "enl; Non-Letters E1 (extended)\n" - + "ƒ ʰ ʳ ˆ ˜ ˢ ᵈ ᵗ ‘ ‚ “ ” „ † … ‰ ′ ″ ‹ › ⁰ ⁴ ⁵ ⁶ ⁷ ⁸ " - + "⁹ ⁿ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ™ ∞ ≤ ≥ \n\n"; + "bll; Latin Letters (normative)\n" + + "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z " + + "a b c d e f g h i j k l m n o p q r s t u v w x y z " + + "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú " + + "Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô " + + "õ ö ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď " + + "Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ " + + "Ī ī Ĭ ĭ Į į İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Ł ł Ń " + + "ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ " + + "Ş ş Š š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ " + + "Ÿ Ź ź Ż ż Ž ž Ƈ ƈ Ə Ɨ Ơ ơ Ư ư Ʒ Ǎ ǎ Ǐ ǐ Ǒ ǒ Ǔ ǔ Ǖ ǖ " + + "Ǘ ǘ Ǚ ǚ Ǜ ǜ Ǟ ǟ Ǣ ǣ Ǥ ǥ Ǧ ǧ Ǩ ǩ Ǫ ǫ Ǭ ǭ Ǯ ǯ ǰ Ǵ ǵ Ǹ " + + "ǹ Ǻ ǻ Ǽ ǽ Ǿ ǿ Ȓ ȓ Ș ș Ț ț Ȟ ȟ ȧ Ȩ ȩ Ȫ ȫ Ȭ ȭ Ȯ ȯ Ȱ ȱ " + + "Ȳ ȳ ə ɨ ʒ Ḃ ḃ Ḇ ḇ Ḋ ḋ Ḍ ḍ Ḏ ḏ Ḑ ḑ ḗ Ḝ ḝ Ḟ ḟ Ḡ ḡ Ḣ ḣ " + + "Ḥ ḥ Ḧ ḧ Ḩ ḩ Ḫ ḫ ḯ Ḱ ḱ Ḳ ḳ Ḵ ḵ Ḷ ḷ Ḻ ḻ Ṁ ṁ Ṃ ṃ Ṅ ṅ Ṇ " + + "ṇ Ṉ ṉ Ṓ ṓ Ṕ ṕ Ṗ ṗ Ṙ ṙ Ṛ ṛ Ṟ ṟ Ṡ ṡ Ṣ ṣ Ṫ ṫ Ṭ ṭ Ṯ ṯ Ẁ " + + "ẁ Ẃ ẃ Ẅ ẅ Ẇ ẇ Ẍ ẍ Ẏ ẏ Ẑ ẑ Ẓ ẓ Ẕ ẕ ẖ ẗ ẞ Ạ ạ Ả ả Ấ ấ " + + "Ầ ầ Ẩ ẩ Ẫ ẫ Ậ ậ Ắ ắ Ằ ằ Ẳ ẳ Ẵ ẵ Ặ ặ Ẹ ẹ Ẻ ẻ Ẽ ẽ Ế ế " + + "Ề ề Ể ể Ễ ễ Ệ ệ Ỉ ỉ Ị ị Ọ ọ Ỏ ỏ Ố ố Ồ ồ Ổ ổ Ỗ ỗ Ộ ộ " + + "Ớ ớ Ờ ờ Ở ở Ỡ ỡ Ợ ợ Ụ ụ Ủ ủ Ứ ứ Ừ ừ Ử ử Ữ ữ Ự ự Ỳ ỳ " + + "Ỵ ỵ Ỷ ỷ Ỹ ỹ \n" + + "Sequences\n" + + "A̋ C̀ C̄ C̆ C̈ C̕ C̣ C̦ C̨̆ D̂ F̀ F̄ G̀ H̄ H̦ H̱ J́ J̌ K̀ K̂ K̄ K̇ K̕ K̛ K̦ K͟H " + + "K͟h L̂ L̥ L̥̄ L̦ M̀ M̂ M̆ M̐ N̂ N̄ N̆ N̦ P̀ P̄ P̕ P̣ R̆ R̥ R̥̄ S̀ S̄ S̛̄ S̱ T̀ T̄ " + + "T̈ T̕ T̛ U̇ Z̀ Z̄ Z̆ Z̈ Z̧ a̋ c̀ c̄ c̆ c̈ c̕ c̣ c̦ c̨̆ d̂ f̀ f̄ g̀ h̄ h̦ j́ k̀ " + + "k̂ k̄ k̇ k̕ k̛ k̦ k͟h l̂ l̥ l̥̄ l̦ m̀ m̂ m̆ m̐ n̂ n̄ n̆ n̦ p̀ p̄ p̕ p̣ r̆ r̥ r̥̄ " + + "s̀ s̄ s̛̄ s̱ t̀ t̄ t̕ t̛ u̇ z̀ z̄ z̆ z̈ z̧ Ç̆ Û̄ ç̆ û̄ ÿ́ Č̕ Č̣ č̕ č̣ ē̍ Ī́ ī́ " + + "ō̍ Ž̦ Ž̧ ž̦ ž̧ Ḳ̄ ḳ̄ Ṣ̄ ṣ̄ Ṭ̄ ṭ̄ Ạ̈ ạ̈ Ọ̈ ọ̈ Ụ̄ Ụ̈ ụ̄ ụ̈ \n" + + "bnlreq; Non-Letters N1 (normative)\n" + + " ' , - . ` ~ ¨ ´ · ʹ ʺ ʾ ʿ ˈ ˌ ’ ‡ \n" + + "bnl; Non-Letters N2 (normative)\n" + + "! \" # $ % & ( ) * + / 0 1 2 3 4 5 6 7 8 9 : ; < = > " + + "? @ [ \\ ] ^ _ { | } ¡ ¢ £ ¥ § © ª « ¬ ® ¯ ° ± ² ³ µ " + + "¶ ¹ º » ¿ × ÷ € \n" + + "bnlopt; Non-Letters N3 (normative)\n" + + "¤ ¦ ¸ ¼ ½ ¾ \n" + + "bnlnot; Non-Letters N4 (normative) -omitted-\n" + + "dc; Combining diacritics (normative) ̀-omitted-\n" + + "gl; Greek Letters (extended)\n" + + "Ά Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ " + + "Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν " + + "ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ \n" + + "cl; Cyrillic Letters (extended)\n" + + "Ѝ А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш " + + "Щ Ъ Ь Ю Я а б в г д е ж з и й к л м н о п р с т у ф " + + "х ц ч ш щ ъ ь ю я ѝ \n" + + "enl; Non-Letters E1 (extended)\n" + + "ƒ ʰ ʳ ˆ ˜ ˢ ᵈ ᵗ ‘ ‚ “ ” „ † … ‰ ′ ″ ‹ › ⁰ ⁴ ⁵ ⁶ ⁷ ⁸ " + + "⁹ ⁿ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ™ ∞ ≤ ≥ \n\n"; /** * Main method + * * @param args -- not used */ - public static void main(String[] args) { - try { - test("GlyphLayoutFormDin91379.pdf", "com/lowagie/examples/fonts/form/PdfFormLayoutProcessor.pdf", - TEXT_INTRO + LATIN_CHARS_DIN_91379); - } catch (Exception e) { - e.printStackTrace(); - } + public static void main(String[] args) throws Exception { + test("GlyphLayoutFormDin91379.pdf", "com/lowagie/examples/fonts/form/PdfFormLayoutProcessor.pdf", + TEXT_INTRO + LATIN_CHARS_DIN_91379); } /** * Run the test: Print the characters of DIN 91379 in a pdf form - * @param fileName Name of output file + * + * @param fileName Name of output file * @param formPath Name of input pdf form - * @param text Text to show + * @param text Text to show * @throws Exception in case of error */ public static void test(String fileName, String formPath, String text) throws Exception { @@ -118,10 +114,11 @@ public static void test(String fileName, String formPath, String text) throws Ex // Enable the LayoutProcessor with kerning and ligatures LayoutProcessor.enableKernLiga(); - try ( InputStream acroFormInputStream = GlyphLayoutFormDin91379.class.getClassLoader().getResourceAsStream(formPath); - FileOutputStream outputStream = new FileOutputStream(fileName); - PdfReader reader = new PdfReader(acroFormInputStream) - ) { + try (InputStream acroFormInputStream = GlyphLayoutFormDin91379.class.getClassLoader() + .getResourceAsStream(formPath); + FileOutputStream outputStream = new FileOutputStream(fileName); + PdfReader reader = new PdfReader(acroFormInputStream) + ) { // The OpenType fonts loaded with FontFactory.register() are // available for glyph layout @@ -149,6 +146,7 @@ public static void test(String fileName, String formPath, String text) throws Ex stamper.setFormFlattening(true); stamper.setFullCompression(); stamper.close(); + LayoutProcessor.disable(); } } }