diff --git a/gradle.properties b/gradle.properties index 0bdba54..9c181cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = org.xbib.graphics name = graphics -version = 5.5.5 +version = 5.6.0 diff --git a/graphics-fonts-arabic/build.gradle b/graphics-fonts-arabic/build.gradle new file mode 100644 index 0000000..c9ce934 --- /dev/null +++ b/graphics-fonts-arabic/build.gradle @@ -0,0 +1,3 @@ +dependencies { + api project(':graphics-fonts') +} diff --git a/graphics-fonts-arabic/src/main/java/module-info.java b/graphics-fonts-arabic/src/main/java/module-info.java new file mode 100644 index 0000000..4b6ad3e --- /dev/null +++ b/graphics-fonts-arabic/src/main/java/module-info.java @@ -0,0 +1,8 @@ +import org.xbib.graphics.fonts.FontEmbedder; +import org.xbib.graphics.fonts.arabic.ArabicFontEmbedder; + +module org.xbib.graphics.fonts.arabic { + requires org.xbib.graphics.fonts; + exports org.xbib.graphics.fonts.arabic; + provides FontEmbedder with ArabicFontEmbedder; +} diff --git a/graphics-fonts-arabic/src/main/java/org/xbib/graphics/fonts/arabic/ArabicFontEmbedder.java b/graphics-fonts-arabic/src/main/java/org/xbib/graphics/fonts/arabic/ArabicFontEmbedder.java new file mode 100644 index 0000000..e47338f --- /dev/null +++ b/graphics-fonts-arabic/src/main/java/org/xbib/graphics/fonts/arabic/ArabicFontEmbedder.java @@ -0,0 +1,27 @@ +package org.xbib.graphics.fonts.arabic; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class ArabicFontEmbedder extends TrueTypeEmbedder { + + public ArabicFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "notosansarabic"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), + "NotoSansArabic-Regular.ttf", + "NotoSansArabic-Bold.ttf", + "NotoSansArabic-Regular.ttf", + "NotoSansArabic-Bold.ttf"); + } +} diff --git a/graphics-fonts-arabic/src/main/resources/org/xbib/graphics/fonts/arabic/NotoSansArabic-Bold.ttf b/graphics-fonts-arabic/src/main/resources/org/xbib/graphics/fonts/arabic/NotoSansArabic-Bold.ttf new file mode 100644 index 0000000..ab5b96f Binary files /dev/null and b/graphics-fonts-arabic/src/main/resources/org/xbib/graphics/fonts/arabic/NotoSansArabic-Bold.ttf differ diff --git a/graphics-fonts-arabic/src/main/resources/org/xbib/graphics/fonts/arabic/NotoSansArabic-Regular.ttf b/graphics-fonts-arabic/src/main/resources/org/xbib/graphics/fonts/arabic/NotoSansArabic-Regular.ttf new file mode 100644 index 0000000..08a5b52 Binary files /dev/null and b/graphics-fonts-arabic/src/main/resources/org/xbib/graphics/fonts/arabic/NotoSansArabic-Regular.ttf differ diff --git a/graphics-fonts-cjk/build.gradle b/graphics-fonts-cjk/build.gradle new file mode 100644 index 0000000..c9ce934 --- /dev/null +++ b/graphics-fonts-cjk/build.gradle @@ -0,0 +1,3 @@ +dependencies { + api project(':graphics-fonts') +} diff --git a/graphics-fonts-cjk/src/main/java/module-info.java b/graphics-fonts-cjk/src/main/java/module-info.java new file mode 100644 index 0000000..967b704 --- /dev/null +++ b/graphics-fonts-cjk/src/main/java/module-info.java @@ -0,0 +1,8 @@ +import org.xbib.graphics.fonts.FontEmbedder; +import org.xbib.graphics.fonts.cjk.CJKFontEmbedder; + +module org.xbib.graphics.fonts.cjk { + requires org.xbib.graphics.fonts; + exports org.xbib.graphics.fonts.cjk; + provides FontEmbedder with CJKFontEmbedder; +} diff --git a/graphics-fonts-cjk/src/main/java/org/xbib/graphics/fonts/cjk/CJKFontEmbedder.java b/graphics-fonts-cjk/src/main/java/org/xbib/graphics/fonts/cjk/CJKFontEmbedder.java new file mode 100644 index 0000000..072448b --- /dev/null +++ b/graphics-fonts-cjk/src/main/java/org/xbib/graphics/fonts/cjk/CJKFontEmbedder.java @@ -0,0 +1,27 @@ +package org.xbib.graphics.fonts.cjk; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class CJKFontEmbedder extends TrueTypeEmbedder { + + public CJKFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "notosanscjksc"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), + "NotoSansCJKsc-Regular.ttf", + "NotoSansCJKsc-Bold.ttf", + "NotoSansCJKsc-Italic.ttf", + "NotoSansCJKsc-BoldItalic.ttf"); + } +} diff --git a/graphics-fonts-cjk/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder b/graphics-fonts-cjk/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder new file mode 100644 index 0000000..200c6bd --- /dev/null +++ b/graphics-fonts-cjk/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder @@ -0,0 +1 @@ +org.xbib.graphics.fonts.cjk.CJKFontEmbedder \ No newline at end of file diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-Bold.ttf b/graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-Bold.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-Bold.ttf rename to graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-Bold.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-BoldItalic.ttf b/graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-BoldItalic.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-BoldItalic.ttf rename to graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-BoldItalic.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-Italic.ttf b/graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-Italic.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-Italic.ttf rename to graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-Italic.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-Regular.ttf b/graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-Regular.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansCJKsc-Regular.ttf rename to graphics-fonts-cjk/src/main/resources/org/xbib/graphics/fonts/cjk/NotoSansCJKsc-Regular.ttf diff --git a/graphics-fonts-cyrillic/build.gradle b/graphics-fonts-cyrillic/build.gradle new file mode 100644 index 0000000..c9ce934 --- /dev/null +++ b/graphics-fonts-cyrillic/build.gradle @@ -0,0 +1,3 @@ +dependencies { + api project(':graphics-fonts') +} diff --git a/graphics-fonts-cyrillic/src/main/java/module-info.java b/graphics-fonts-cyrillic/src/main/java/module-info.java new file mode 100644 index 0000000..0d69a72 --- /dev/null +++ b/graphics-fonts-cyrillic/src/main/java/module-info.java @@ -0,0 +1,7 @@ +import org.xbib.graphics.fonts.FontEmbedder; +import org.xbib.graphics.fonts.cyrillic.CyrillicFontEmbedder; + +module org.xbib.graphics.fonts.cyrillic { + requires org.xbib.graphics.fonts; + provides FontEmbedder with CyrillicFontEmbedder; +} diff --git a/graphics-fonts-cyrillic/src/main/java/org/xbib/graphics/fonts/cyrillic/CyrillicFontEmbedder.java b/graphics-fonts-cyrillic/src/main/java/org/xbib/graphics/fonts/cyrillic/CyrillicFontEmbedder.java new file mode 100644 index 0000000..a0e9c3d --- /dev/null +++ b/graphics-fonts-cyrillic/src/main/java/org/xbib/graphics/fonts/cyrillic/CyrillicFontEmbedder.java @@ -0,0 +1,27 @@ +package org.xbib.graphics.fonts.cyrillic; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class CyrillicFontEmbedder extends TrueTypeEmbedder { + + public CyrillicFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "notosanscyrillic"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), + "NotoSans-Regular.ttf", + "NotoSans-Bold.ttf", + "NotoSans-Italic.ttf", + "NotoSans-BoldItalic.ttf"); + } +} diff --git a/graphics-fonts-cyrillic/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder b/graphics-fonts-cyrillic/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder new file mode 100644 index 0000000..1c982f9 --- /dev/null +++ b/graphics-fonts-cyrillic/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder @@ -0,0 +1 @@ +org.xbib.graphics.fonts.cyrillic.CyrillicFontEmbedder \ No newline at end of file diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-Bold.ttf b/graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-Bold.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-Bold.ttf rename to graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-Bold.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-BoldItalic.ttf b/graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-BoldItalic.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-BoldItalic.ttf rename to graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-BoldItalic.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-Italic.ttf b/graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-Italic.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-Italic.ttf rename to graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-Italic.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-Regular.ttf b/graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-Regular.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSans-Regular.ttf rename to graphics-fonts-cyrillic/src/main/resources/org/xbib/graphics/fonts/cyrillic/NotoSans-Regular.ttf diff --git a/graphics-fonts-hebrew/build.gradle b/graphics-fonts-hebrew/build.gradle new file mode 100644 index 0000000..c9ce934 --- /dev/null +++ b/graphics-fonts-hebrew/build.gradle @@ -0,0 +1,3 @@ +dependencies { + api project(':graphics-fonts') +} diff --git a/graphics-fonts-hebrew/src/main/java/module-info.java b/graphics-fonts-hebrew/src/main/java/module-info.java new file mode 100644 index 0000000..2597614 --- /dev/null +++ b/graphics-fonts-hebrew/src/main/java/module-info.java @@ -0,0 +1,7 @@ +import org.xbib.graphics.fonts.FontEmbedder; +import org.xbib.graphics.fonts.hebrew.HebrewFontEmbedder; + +module org.xbib.graphics.fonts.hebrew { + requires org.xbib.graphics.fonts; + provides FontEmbedder with HebrewFontEmbedder; +} diff --git a/graphics-fonts-hebrew/src/main/java/org/xbib/graphics/fonts/hebrew/HebrewFontEmbedder.java b/graphics-fonts-hebrew/src/main/java/org/xbib/graphics/fonts/hebrew/HebrewFontEmbedder.java new file mode 100644 index 0000000..1c38172 --- /dev/null +++ b/graphics-fonts-hebrew/src/main/java/org/xbib/graphics/fonts/hebrew/HebrewFontEmbedder.java @@ -0,0 +1,27 @@ +package org.xbib.graphics.fonts.hebrew; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class HebrewFontEmbedder extends TrueTypeEmbedder { + + public HebrewFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "notosanshebrew"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), + "NotoSansHebrew-Regular.ttf", + "NotoSansHebrew-Bold.ttf", + "NotoSansHebrew-Regular.ttf", + "NotoSansHebrew-Bold.ttf"); + } +} diff --git a/graphics-fonts-hebrew/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder b/graphics-fonts-hebrew/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder new file mode 100644 index 0000000..736a87c --- /dev/null +++ b/graphics-fonts-hebrew/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder @@ -0,0 +1 @@ +org.xbib.graphics.fonts.hebrew.HebrewFontEmbedder \ No newline at end of file diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansHebrew-Bold.ttf b/graphics-fonts-hebrew/src/main/resources/org/xbib/graphics/fonts/hebrew/NotoSansHebrew-Bold.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansHebrew-Bold.ttf rename to graphics-fonts-hebrew/src/main/resources/org/xbib/graphics/fonts/hebrew/NotoSansHebrew-Bold.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansHebrew-Regular.ttf b/graphics-fonts-hebrew/src/main/resources/org/xbib/graphics/fonts/hebrew/NotoSansHebrew-Regular.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/NotoSansHebrew-Regular.ttf rename to graphics-fonts-hebrew/src/main/resources/org/xbib/graphics/fonts/hebrew/NotoSansHebrew-Regular.ttf diff --git a/graphics-fonts-latin/build.gradle b/graphics-fonts-latin/build.gradle new file mode 100644 index 0000000..c9ce934 --- /dev/null +++ b/graphics-fonts-latin/build.gradle @@ -0,0 +1,3 @@ +dependencies { + api project(':graphics-fonts') +} diff --git a/graphics-fonts-latin/src/main/java/module-info.java b/graphics-fonts-latin/src/main/java/module-info.java new file mode 100644 index 0000000..5b62c25 --- /dev/null +++ b/graphics-fonts-latin/src/main/java/module-info.java @@ -0,0 +1,11 @@ +import org.xbib.graphics.fonts.FontEmbedder; +import org.xbib.graphics.fonts.latin.NotoSansFontEmbedder; +import org.xbib.graphics.fonts.latin.OpenSansFontEmbedder; +import org.xbib.graphics.fonts.latin.SourceSansFontEmbedder; + +module org.xbib.graphics.fonts.latin { + requires org.xbib.graphics.fonts; + provides FontEmbedder with NotoSansFontEmbedder, + OpenSansFontEmbedder, + SourceSansFontEmbedder; +} diff --git a/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/NotoSansFontEmbedder.java b/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/NotoSansFontEmbedder.java new file mode 100644 index 0000000..2a7162b --- /dev/null +++ b/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/NotoSansFontEmbedder.java @@ -0,0 +1,27 @@ +package org.xbib.graphics.fonts.latin; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class NotoSansFontEmbedder extends TrueTypeEmbedder { + + public NotoSansFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "notosans"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), + "NotoSans-Regular.ttf", + "NotoSans-Bold.ttf", + "NotoSans-Italic.ttf", + "NotoSans-BoldItalic.ttf"); + } +} diff --git a/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/OpenSansFontEmbedder.java b/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/OpenSansFontEmbedder.java new file mode 100644 index 0000000..dbe3cdf --- /dev/null +++ b/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/OpenSansFontEmbedder.java @@ -0,0 +1,27 @@ +package org.xbib.graphics.fonts.latin; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class OpenSansFontEmbedder extends TrueTypeEmbedder { + + public OpenSansFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "opensans"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), + "OpenSans-Regular.ttf", + "OpenSans-Bold.ttf", + "OpenSans-Italic.ttf", + "OpenSans-BoldItalic.ttf"); + } +} diff --git a/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/SourceSansFontEmbedder.java b/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/SourceSansFontEmbedder.java new file mode 100644 index 0000000..4874b6c --- /dev/null +++ b/graphics-fonts-latin/src/main/java/org/xbib/graphics/fonts/latin/SourceSansFontEmbedder.java @@ -0,0 +1,26 @@ +package org.xbib.graphics.fonts.latin; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.xbib.graphics.fonts.TrueTypeEmbedder; + +import java.io.IOException; + +public class SourceSansFontEmbedder extends TrueTypeEmbedder { + + public SourceSansFontEmbedder() { + super(); + } + + @Override + public String getAlias() { + return "sourcesans"; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + embed(pdDocument, getAlias(), "SourceSans3-Regular.ttf", + "SourceSans3-Bold.ttf", + "SourceSans3-It.ttf", + "SourceSans3-BoldIt.ttf"); + } +} diff --git a/graphics-fonts-latin/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder b/graphics-fonts-latin/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder new file mode 100644 index 0000000..e19f882 --- /dev/null +++ b/graphics-fonts-latin/src/main/resources/META-INF/services/org.xbib.graphics.fonts.FontEmbedder @@ -0,0 +1,3 @@ +org.xbib.graphics.fonts.latin.NotoSansFontEmbedder +org.xbib.graphics.fonts.latin.OpenSansFontEmbedder +org.xbib.graphics.fonts.latin.SourceSansFontEmbedder diff --git a/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Bold.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Bold.ttf new file mode 100644 index 0000000..ab4cdee Binary files /dev/null and b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Bold.ttf differ diff --git a/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-BoldItalic.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-BoldItalic.ttf new file mode 100644 index 0000000..c10e146 Binary files /dev/null and b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-BoldItalic.ttf differ diff --git a/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Italic.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Italic.ttf new file mode 100644 index 0000000..1aa2a52 Binary files /dev/null and b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Italic.ttf differ diff --git a/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Regular.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Regular.ttf new file mode 100644 index 0000000..ebd7703 Binary files /dev/null and b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/NotoSans-Regular.ttf differ diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-Bold.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-Bold.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-Bold.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-Bold.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-BoldItalic.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-BoldItalic.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-BoldItalic.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-BoldItalic.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-Italic.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-Italic.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-Italic.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-Italic.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-Regular.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-Regular.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/OpenSans-Regular.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/OpenSans-Regular.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-Bold.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-Bold.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-Bold.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-Bold.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-BoldIt.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-BoldIt.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-BoldIt.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-BoldIt.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-It.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-It.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-It.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-It.ttf diff --git a/graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-Regular.ttf b/graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-Regular.ttf similarity index 100% rename from graphics-pdfbox-layout/src/main/resources/org/xbib/graphics/pdfbox/layout/font/SourceSans3-Regular.ttf rename to graphics-fonts-latin/src/main/resources/org/xbib/graphics/fonts/latin/SourceSans3-Regular.ttf diff --git a/graphics-fonts-latin/src/test/java/org/xbib/graphics/fonts/latin/test/LatinEmbedderTest.java b/graphics-fonts-latin/src/test/java/org/xbib/graphics/fonts/latin/test/LatinEmbedderTest.java new file mode 100644 index 0000000..40719d3 --- /dev/null +++ b/graphics-fonts-latin/src/test/java/org/xbib/graphics/fonts/latin/test/LatinEmbedderTest.java @@ -0,0 +1,28 @@ +package org.xbib.graphics.fonts.latin.test; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.junit.jupiter.api.Test; +import org.xbib.graphics.fonts.latin.NotoSansFontEmbedder; +import org.xbib.graphics.fonts.latin.OpenSansFontEmbedder; +import org.xbib.graphics.fonts.latin.SourceSansFontEmbedder; + +import java.io.IOException; + +public class LatinEmbedderTest { + + @Test + public void testLatin() throws IOException { + NotoSansFontEmbedder embedder = new NotoSansFontEmbedder(); + try (PDDocument document = new PDDocument()) { + embedder.embed(document); + } + OpenSansFontEmbedder openSansFontEmbedder = new OpenSansFontEmbedder(); + try (PDDocument document = new PDDocument()) { + openSansFontEmbedder.embed(document); + } + SourceSansFontEmbedder sourceSansFontEmbedder = new SourceSansFontEmbedder(); + try (PDDocument document = new PDDocument()) { + sourceSansFontEmbedder.embed(document); + } + } +} diff --git a/graphics-fonts/build.gradle b/graphics-fonts/build.gradle new file mode 100644 index 0000000..5a172bb --- /dev/null +++ b/graphics-fonts/build.gradle @@ -0,0 +1,3 @@ +dependencies { + api libs.pdfbox +} diff --git a/graphics-fonts/src/main/java/module-info.java b/graphics-fonts/src/main/java/module-info.java new file mode 100644 index 0000000..26e1696 --- /dev/null +++ b/graphics-fonts/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module org.xbib.graphics.fonts { + requires java.logging; + requires transitive java.desktop; + requires transitive org.apache.fontbox; + requires transitive org.apache.pdfbox; + requires org.apache.pdfbox.io; + exports org.xbib.graphics.fonts; +} diff --git a/graphics-fonts/src/main/java/org/xbib/graphics/fonts/BaseFont.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/BaseFont.java new file mode 100644 index 0000000..364e462 --- /dev/null +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/BaseFont.java @@ -0,0 +1,91 @@ +package org.xbib.graphics.fonts; + +import org.apache.pdfbox.pdmodel.font.PDFont; +import org.apache.pdfbox.pdmodel.font.PDType1Font; +import org.apache.pdfbox.pdmodel.font.Standard14Fonts; + +import java.io.IOException; + +/** + * In order to easy handling with fonts, this enum bundles the + * plain/italic/bold/bold-italic variants of the three standard font types + * Times, Courier, Helvetica. + */ +public enum BaseFont implements Font { + + TIMES("times", new PDType1Font(Standard14Fonts.FontName.TIMES_ROMAN), new PDType1Font(Standard14Fonts.FontName.TIMES_BOLD), + new PDType1Font(Standard14Fonts.FontName.TIMES_ITALIC), new PDType1Font(Standard14Fonts.FontName.TIMES_BOLD_ITALIC)), + + COURIER("courier", new PDType1Font(Standard14Fonts.FontName.COURIER), new PDType1Font(Standard14Fonts.FontName.COURIER_BOLD), + new PDType1Font(Standard14Fonts.FontName.COURIER_OBLIQUE), new PDType1Font(Standard14Fonts.FontName.COURIER_BOLD_OBLIQUE)), + + HELVETICA("helvetica", new PDType1Font(Standard14Fonts.FontName.HELVETICA), new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD), + new PDType1Font(Standard14Fonts.FontName.HELVETICA_OBLIQUE), new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD_OBLIQUE)); + + private final String alias; + + private final PDType1Font regularFont; + + private final PDType1Font boldFont; + + private final PDType1Font italicFont; + + private final PDType1Font boldItalicFont; + + BaseFont(String alias, PDType1Font regularFont, PDType1Font boldFont, PDType1Font italicFont, PDType1Font boldItalicFont) { + this.alias = alias; + this.regularFont = regularFont; + this.boldFont = boldFont; + this.italicFont = italicFont; + this.boldItalicFont = boldItalicFont; + } + + public String getAlias() { + return alias; + } + + @Override + public PDFont getRegularFont() { + return regularFont; + } + + @Override + public PDFont getBoldFont() { + return boldFont; + } + + @Override + public PDFont getItalicFont() { + return italicFont; + } + + @Override + public PDFont getBoldItalicFont() { + return boldItalicFont; + } + + @Override + public boolean hasGlyph(int code) { + try { + return regularFont.hasGlyph(code); + } catch (IOException e) { + return false; + } + } + + @Override + public boolean canRender(String string) { + if (string == null) { + return false; + } + String printable = string.replaceAll("\\P{Print}|\\p{Cntrl}|\\p{Space}", ""); + if (printable.isEmpty()) { + return true; + } + try { + return regularFont.getStringWidth(printable) > 0; + } catch (IllegalArgumentException | IOException e) { + return false; + } + } +} diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/CoreFontDrawer.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/CoreFontDrawer.java similarity index 95% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/CoreFontDrawer.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/CoreFontDrawer.java index 8513d37..167a94e 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/CoreFontDrawer.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/CoreFontDrawer.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import org.apache.pdfbox.pdmodel.font.PDFont; diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/DefaultFontDrawer.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/DefaultFontDrawer.java similarity index 98% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/DefaultFontDrawer.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/DefaultFontDrawer.java index 5e9c92a..6dc15f0 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/DefaultFontDrawer.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/DefaultFontDrawer.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import org.apache.fontbox.ttf.TrueTypeCollection; import org.apache.pdfbox.pdmodel.PDPageContentStream; @@ -6,7 +6,6 @@ import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.font.PDType0Font; import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.apache.pdfbox.util.Matrix; -import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import java.awt.Font; import java.awt.FontFormatException; @@ -44,8 +43,7 @@ import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.ZAPF_DINGB /** * Default implementation to draw fonts. You can reuse instances of this class - * within a PDDocument for more then one {@link PdfBoxGraphics2D}. - * Just ensure that you call close after you closed the PDDocument to free any + * within a PDDocument. Just ensure that you call close after you closed the PDDocument to free any * temporary files. */ public class DefaultFontDrawer implements FontDrawer, Closeable { diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/DefaultFontMetrics.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/DefaultFontMetrics.java similarity index 99% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/DefaultFontMetrics.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/DefaultFontMetrics.java index c340075..5fa3f19 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/DefaultFontMetrics.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/DefaultFontMetrics.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import org.apache.pdfbox.pdmodel.font.PDFont; import java.awt.Font; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/Font.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/Font.java similarity index 67% rename from graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/Font.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/Font.java index 0a4f122..62ba063 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/Font.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/Font.java @@ -1,11 +1,11 @@ -package org.xbib.graphics.pdfbox.layout.font; +package org.xbib.graphics.fonts; import org.apache.pdfbox.pdmodel.font.PDFont; -import java.io.IOException; - public interface Font { + String getAlias(); + PDFont getRegularFont(); PDFont getBoldFont(); @@ -16,5 +16,5 @@ public interface Font { boolean hasGlyph(int code); - boolean canWrite(String string); + boolean canRender(String string); } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/FontDescriptor.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDescriptor.java similarity index 85% rename from graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/FontDescriptor.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDescriptor.java index 242a6fd..bec872d 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/FontDescriptor.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDescriptor.java @@ -1,8 +1,8 @@ -package org.xbib.graphics.pdfbox.layout.font; +package org.xbib.graphics.fonts; import org.apache.pdfbox.pdmodel.font.PDFont; -import java.util.List; +import java.util.Collection; import java.util.Objects; /** @@ -10,7 +10,7 @@ import java.util.Objects; */ public class FontDescriptor { - private final List fonts; + private final Collection fonts; private float size; @@ -20,11 +20,11 @@ public class FontDescriptor { private boolean italic; - public FontDescriptor(List fonts, float size) { + public FontDescriptor(Collection fonts, float size) { this(fonts, size, false, false); } - public FontDescriptor(List fonts, float size, boolean bold, boolean italic) { + public FontDescriptor(Collection fonts, float size, boolean bold, boolean italic) { this.fonts = fonts; // we do not accept null fonts for (Font font : fonts) { @@ -36,7 +36,7 @@ public class FontDescriptor { this.regular = !bold && !italic; } - public List getFonts() { + public Collection getFonts() { return fonts; } @@ -60,7 +60,7 @@ public class FontDescriptor { public PDFont getSelectedFont(String text) { for (Font font : fonts) { - if (font.canWrite(text)) { + if (font.canRender(text)) { if (regular) { return font.getRegularFont(); } diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontDrawer.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDrawer.java similarity index 97% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontDrawer.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDrawer.java index 1718d07..586059e 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontDrawer.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDrawer.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import java.awt.Font; import java.awt.FontFormatException; diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontDrawerEnvironment.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDrawerEnvironment.java similarity index 93% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontDrawerEnvironment.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDrawerEnvironment.java index 821a36b..89c187a 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontDrawerEnvironment.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontDrawerEnvironment.java @@ -1,10 +1,9 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; -import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import java.awt.Font; import java.awt.Graphics2D; @@ -59,7 +58,7 @@ public interface FontDrawerEnvironment { FontRenderContext getFontRenderContext(); /** - * @return the bbox of the {@link PdfBoxGraphics2D} + * @return the bbox */ PDRectangle getGraphicsBBox(); diff --git a/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontEmbedder.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontEmbedder.java new file mode 100644 index 0000000..575b795 --- /dev/null +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontEmbedder.java @@ -0,0 +1,12 @@ +package org.xbib.graphics.fonts; + +import org.apache.pdfbox.pdmodel.PDDocument; + +import java.io.IOException; + +public interface FontEmbedder { + + String getAlias(); + + void embed(PDDocument pdDocument) throws IOException; +} diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontEntry.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontEntry.java similarity index 69% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontEntry.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontEntry.java index 28dab23..f53e252 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/FontEntry.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/FontEntry.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import java.io.File; diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/ForcedFontDrawer.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/ForcedFontDrawer.java similarity index 89% rename from graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/ForcedFontDrawer.java rename to graphics-fonts/src/main/java/org/xbib/graphics/fonts/ForcedFontDrawer.java index 60b0540..442ab34 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/font/ForcedFontDrawer.java +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/ForcedFontDrawer.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.pdfbox.font; +package org.xbib.graphics.fonts; import java.text.AttributedCharacterIterator; diff --git a/graphics-fonts/src/main/java/org/xbib/graphics/fonts/TrueTypeEmbedder.java b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/TrueTypeEmbedder.java new file mode 100644 index 0000000..5d03ea0 --- /dev/null +++ b/graphics-fonts/src/main/java/org/xbib/graphics/fonts/TrueTypeEmbedder.java @@ -0,0 +1,128 @@ +package org.xbib.graphics.fonts; + +import org.apache.fontbox.ttf.TTFParser; +import org.apache.fontbox.ttf.TrueTypeFont; +import org.apache.pdfbox.io.RandomAccessRead; +import org.apache.pdfbox.io.RandomAccessReadBuffer; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.font.PDFont; +import org.apache.pdfbox.pdmodel.font.PDType0Font; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +public class TrueTypeEmbedder implements FontEmbedder { + + private static final Map fonts = new LinkedHashMap<>(); + + public TrueTypeEmbedder() { + } + + public static void clearFonts() { + fonts.clear(); + } + + @Override + public String getAlias() { + // dummy + return ""; + } + + @Override + public void embed(PDDocument pdDocument) throws IOException { + // nothing to embed er default + } + + public void embed(PDDocument pdDocument, + final String name, + final String regularFontResource, + final String boldFontResource, + final String italicsFontResource, + final String boldItalicsFontResource) throws IOException { + if (fonts.containsKey(name)) { + return; + } + final PDType0Font regularFont = embedTrueTypeFont(pdDocument, regularFontResource); + final PDType0Font boldFont = embedTrueTypeFont(pdDocument, boldFontResource); + final PDType0Font italicsFont = embedTrueTypeFont(pdDocument, italicsFontResource); + final PDType0Font boldItalicsFont = embedTrueTypeFont(pdDocument, boldItalicsFontResource); + fonts.putIfAbsent(name, new Font() { + + @Override + public String getAlias() { + return name; + } + + @Override + public PDFont getRegularFont() { + return regularFont; + } + + @Override + public PDFont getBoldFont() { + return boldFont; + } + + @Override + public PDFont getItalicFont() { + return italicsFont; + } + + @Override + public PDFont getBoldItalicFont() { + return boldItalicsFont; + } + + @Override + public boolean hasGlyph(int code) { + try { + return regularFont.hasGlyph(code); + } catch (IOException e) { + return false; + } + } + + @Override + public boolean canRender(String string) { + try { + return regularFont.getStringWidth(string) > 0; + } catch (IOException | IllegalArgumentException e) { + return false; + } + } + + @Override + public String toString() { + return name; + } + }); + } + + public void register(Font font) { + fonts.putIfAbsent(font.getAlias(), font); + } + + public Font getFont(String alias) { + return fonts.get(alias); + } + + public Set getFontAliases() { + return fonts.keySet(); + } + + public Collection getFonts() { + return fonts.values(); + } + + private PDType0Font embedTrueTypeFont(PDDocument pdDocument, String resourceName) throws IOException { + InputStream inputStream = getClass().getResourceAsStream(resourceName); + TTFParser ttfParser = new TTFParser(); + RandomAccessRead randomAccessRead = new RandomAccessReadBuffer(inputStream); + TrueTypeFont trueTypeFont = ttfParser.parse(randomAccessRead); + return PDType0Font.load(pdDocument, trueTypeFont, true); + } +} diff --git a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontDrawerTest.java b/graphics-fonts/src/test/java/org/xbib/graphics/fonts/test/FontDrawerTest.java similarity index 97% rename from graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontDrawerTest.java rename to graphics-fonts/src/test/java/org/xbib/graphics/fonts/test/FontDrawerTest.java index 94a024e..a9de0c7 100644 --- a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontDrawerTest.java +++ b/graphics-fonts/src/test/java/org/xbib/graphics/fonts/test/FontDrawerTest.java @@ -1,10 +1,9 @@ -package org.xbib.graphics.pdfbox.test; +package org.xbib.graphics.fonts.test; import java.util.Objects; import org.apache.pdfbox.pdmodel.font.PDType1Font; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.xbib.graphics.pdfbox.font.CoreFontDrawer; +import org.xbib.graphics.fonts.CoreFontDrawer; import java.awt.Font; diff --git a/graphics-pdfbox-layout/build.gradle b/graphics-pdfbox-layout/build.gradle index fe93c59..7ec6c74 100644 --- a/graphics-pdfbox-layout/build.gradle +++ b/graphics-pdfbox-layout/build.gradle @@ -2,7 +2,11 @@ dependencies { api project(':graphics-pdfbox') api project(':graphics-barcode') api project(':graphics-chart') + api project(':graphics-fonts') api libs.datastructures.settings runtimeOnly libs.datastructures.settings.json runtimeOnly libs.datastructures.settings.yaml + testRuntimeOnly project(':graphics-fonts-latin') + testRuntimeOnly project(':graphics-fonts-hebrew') + testRuntimeOnly project(':graphics-fonts-cjk') } diff --git a/graphics-pdfbox-layout/src/main/java/module-info.java b/graphics-pdfbox-layout/src/main/java/module-info.java index 2b24fcd..473c840 100644 --- a/graphics-pdfbox-layout/src/main/java/module-info.java +++ b/graphics-pdfbox-layout/src/main/java/module-info.java @@ -1,9 +1,9 @@ module org.xbib.graphics.layout.pdfbox { + uses org.xbib.graphics.fonts.FontEmbedder; exports org.xbib.graphics.pdfbox.layout.boxable; exports org.xbib.graphics.pdfbox.layout.color; exports org.xbib.graphics.pdfbox.layout.element; exports org.xbib.graphics.pdfbox.layout.element.render; - exports org.xbib.graphics.pdfbox.layout.font; exports org.xbib.graphics.pdfbox.layout.element.scripting; exports org.xbib.graphics.pdfbox.layout.element.scripting.command; exports org.xbib.graphics.pdfbox.layout.shape; @@ -17,7 +17,6 @@ module org.xbib.graphics.layout.pdfbox { requires transitive org.xbib.graphics.pdfbox; requires transitive org.xbib.settings.api; requires org.xbib.settings.datastructures; - requires transitive java.desktop; - requires java.logging; requires org.xbib.graphics.chart; + requires org.xbib.graphics.fonts; } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java index 257b685..daf9fb9 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java @@ -1,13 +1,11 @@ package org.xbib.graphics.pdfbox.layout.element; -import org.apache.fontbox.ttf.TTFParser; -import org.apache.fontbox.ttf.TrueTypeFont; -import org.apache.pdfbox.io.RandomAccessRead; -import org.apache.pdfbox.io.RandomAccessReadBuffer; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentInformation; -import org.apache.pdfbox.pdmodel.font.PDFont; -import org.apache.pdfbox.pdmodel.font.PDType0Font; +import org.xbib.graphics.fonts.BaseFont; +import org.xbib.graphics.fonts.Font; +import org.xbib.graphics.fonts.FontEmbedder; +import org.xbib.graphics.fonts.TrueTypeEmbedder; import org.xbib.graphics.pdfbox.layout.element.render.Layout; import org.xbib.graphics.pdfbox.layout.element.render.LayoutHint; import org.xbib.graphics.pdfbox.layout.element.render.RenderContext; @@ -15,33 +13,33 @@ import org.xbib.graphics.pdfbox.layout.element.render.RenderListener; import org.xbib.graphics.pdfbox.layout.element.render.Renderer; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayout; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; -import org.xbib.graphics.pdfbox.layout.font.Font; import java.io.Closeable; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.GregorianCalendar; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.ServiceLoader; +import java.util.logging.Level; +import java.util.logging.Logger; /** * The central class for creating a document. */ public class Document implements Element, Closeable, RenderListener { - private final List> elements; + private static final Logger logger = Logger.getLogger(Document.class.getName()); - private final Map fonts; + private final List> elements; private final List customRenderer; @@ -53,6 +51,8 @@ public class Document implements Element, Closeable, RenderListener { private final PDDocumentInformation pdDocumentInformation; + private final TrueTypeEmbedder trueTypeFonts; + /** * Creates a Document. */ @@ -85,22 +85,69 @@ public class Document implements Element, Closeable, RenderListener { public Document(PageFormat pageFormat) { this.pdDocument = new PDDocument(); this.pdDocumentInformation = new PDDocumentInformation(); + this.trueTypeFonts = new TrueTypeEmbedder(); this.elements = new ArrayList<>(); - this.fonts = new LinkedHashMap<>(); this.customRenderer = new ArrayList<>(); this.renderListener = new ArrayList<>(); setPageFormat(pageFormat); - registerFont("helvetica", BaseFont.HELVETICA); - } - - public void setPageFormat(PageFormat pageFormat) { - this.pageFormat = pageFormat; } public PDDocument getPdDocument() { return pdDocument; } + public void registerCoreFonts() { + trueTypeFonts.register(BaseFont.HELVETICA); + trueTypeFonts.register(BaseFont.TIMES); + trueTypeFonts.register(BaseFont.COURIER); + } + + public void embedAllFonts() { + embedAllFonts(getClass().getClassLoader()); + } + + public void embedAllFonts(ClassLoader classLoader) { + for (FontEmbedder fontEmbedder : ServiceLoader.load(FontEmbedder.class, classLoader)) { + try { + fontEmbedder.embed(this.pdDocument); + } catch (IOException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + logger.log(Level.FINER, "fonts: " + trueTypeFonts.getFontAliases()); + } + + public void embedFonts(Collection aliases) { + embedFonts(aliases, getClass().getClassLoader()); + } + + public void embedFonts(Collection aliases, ClassLoader classLoader) { + for (String alias : aliases) { + for (FontEmbedder fontEmbedder : ServiceLoader.load(FontEmbedder.class, classLoader)) { + try { + if (fontEmbedder.getAlias().equals(alias)) { + fontEmbedder.embed(this.pdDocument); + } + } catch (IOException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + } + logger.log(Level.FINER, "fonts: " + trueTypeFonts.getFontAliases()); + } + + public Font getFont(String alias) { + return trueTypeFonts.getFont(alias); + } + + public Collection getFonts() { + return trueTypeFonts.getFonts(); + } + + public void setPageFormat(PageFormat pageFormat) { + this.pageFormat = pageFormat; + } + public void setAuthor(String author) { pdDocumentInformation.setAuthor(author); } @@ -145,116 +192,6 @@ public class Document implements Element, Closeable, RenderListener { pdDocumentInformation.setCustomMetadataValue(key, value); } - public void registerFont(String name, Font font) { - fonts.put(name, font); - } - - public void registerNotoSansFont() throws IOException { - registerFont("notosans", - "NotoSans-Regular.ttf", - "NotoSans-Bold.ttf", - "NotoSans-Italic.ttf", - "NotoSans-BoldItalic.ttf"); - } - - public void registerNotoSansHebrewFont() throws IOException { - registerFont("notosanshebrew", - "NotoSansHebrew-Regular.ttf", - "NotoSansHebrew-Bold.ttf", - "NotoSansHebrew-Regular.ttf", - "NotoSansHebrew-Bold.ttf"); - } - - public void registerNotoSansCJKSCFont() throws IOException { - registerFont("notosanscjksc", - "NotoSansCJKsc-Regular.ttf", - "NotoSansCJKsc-Bold.ttf", - "NotoSansCJKsc-Italic.ttf", - "NotoSansCJKsc-BoldItalic.ttf"); - } - - public void registerOpenSansFont() throws IOException { - registerFont("opensans", - "OpenSans-Regular.ttf", - "OpenSans-Bold.ttf", - "OpenSans-Italic.ttf", - "OpenSans-BoldItalic.ttf"); - } - - public void registerSourceSansFont() throws IOException { - registerFont("sourcesans", - "SourceSans3-Regular.ttf", - "SourceSans3-Bold.ttf", - "SourceSans3-It.ttf", - "SourceSans3-BoldIt.ttf"); - } - - public void registerFont(String name, - String regularFontResource, - String boldFontResource, - String italicsFontResource, - String boldItalicsFontResource) throws IOException { - final PDType0Font regularFont = loadTrueTypeFont(regularFontResource); - final PDType0Font boldFont = loadTrueTypeFont(boldFontResource); - final PDType0Font italicsFont = loadTrueTypeFont(italicsFontResource); - final PDType0Font boldItalicsFont = loadTrueTypeFont(boldItalicsFontResource); - fonts.put(name, new Font() { - @Override - public PDFont getRegularFont() { - return regularFont; - } - - @Override - public PDFont getBoldFont() { - return boldFont; - } - - @Override - public PDFont getItalicFont() { - return italicsFont; - } - - @Override - public PDFont getBoldItalicFont() { - return boldItalicsFont; - } - - @Override - public boolean hasGlyph(int code) { - try { - return regularFont.hasGlyph(code); - } catch (IOException e) { - return false; - } - } - - @Override - public boolean canWrite(String string) { - try { - return regularFont.getStringWidth(string) > 0; - } catch (IOException | IllegalArgumentException e) { - return false; - } - } - - public String toString() { - return name; - } - }); - } - - private PDType0Font loadTrueTypeFont(String resourceName) throws IOException { - InputStream inputStream = Font.class.getResourceAsStream(resourceName); - TTFParser ttfParser = new TTFParser(); - RandomAccessRead randomAccessRead = new RandomAccessReadBuffer(inputStream); - TrueTypeFont openTypeFont = ttfParser.parse(randomAccessRead); - return PDType0Font.load(pdDocument, openTypeFont, true); - } - - public Font getFont(String name) { - return fonts.get(name); - } - /** * Adds an element to the document using a {@link VerticalLayoutHint}. * diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/SVGElement.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/SVGElement.java index 80845cf..a89a749 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/SVGElement.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/SVGElement.java @@ -7,8 +7,8 @@ import org.apache.pdfbox.util.Matrix; import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import org.xbib.graphics.pdfbox.color.DefaultColorMapper; import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper; -import org.xbib.graphics.pdfbox.font.DefaultFontDrawer; -import org.xbib.graphics.pdfbox.font.FontDrawer; +import org.xbib.graphics.fonts.DefaultFontDrawer; +import org.xbib.graphics.fonts.FontDrawer; import org.xbib.graphics.pdfbox.layout.element.render.Transform; import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.position.Position; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/TextElement.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/TextElement.java index a2e1b80..db846a8 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/TextElement.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/TextElement.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.element; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import java.util.ArrayList; import java.util.List; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/CellCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/CellCommand.java index 92e9f41..6ab025a 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/CellCommand.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/CellCommand.java @@ -3,10 +3,10 @@ package org.xbib.graphics.pdfbox.layout.element.scripting.command; import org.xbib.graphics.pdfbox.layout.color.ColorFactory; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import org.xbib.graphics.pdfbox.layout.element.scripting.Engine; import org.xbib.graphics.pdfbox.layout.element.scripting.State; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.table.BorderStyle; import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface; import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java index 4b99de3..122bb9c 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java @@ -4,11 +4,12 @@ import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.PageFormat; import org.xbib.graphics.pdfbox.layout.element.scripting.Engine; import org.xbib.graphics.pdfbox.layout.element.scripting.State; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.settings.Settings; import java.io.IOException; import java.time.Instant; +import java.util.List; import java.util.Locale; import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt; @@ -73,16 +74,7 @@ public class DocumentCommand implements Command { } String[] fonts = settings.getAsArray("font"); for (String font : fonts) { - switch (font) { - case "helvetica" -> document.registerFont("helvetica", BaseFont.HELVETICA); - case "times" -> document.registerFont("times", BaseFont.TIMES); - case "courier" -> document.registerFont("courier", BaseFont.COURIER); - case "notosans" -> document.registerNotoSansFont(); - case "notosanshebrew" -> document.registerNotoSansHebrewFont(); - case "notosanscjksc" -> document.registerNotoSansCJKSCFont(); - case "opensans" -> document.registerOpenSansFont(); - case "sourcesans" -> document.registerSourceSansFont(); - } + document.embedFonts(List.of(font)); } state.getElements().push(document); engine.executeElements(settings); diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/RowCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/RowCommand.java index c963bdf..1b33256 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/RowCommand.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/RowCommand.java @@ -3,8 +3,8 @@ package org.xbib.graphics.pdfbox.layout.element.scripting.command; import org.xbib.graphics.pdfbox.layout.color.ColorFactory; import org.xbib.graphics.pdfbox.layout.element.scripting.Engine; import org.xbib.graphics.pdfbox.layout.element.scripting.State; -import org.xbib.graphics.pdfbox.layout.font.Font; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.Font; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.table.BorderStyle; import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface; import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/BaseFont.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/BaseFont.java deleted file mode 100644 index 30fb4b1..0000000 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/font/BaseFont.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.xbib.graphics.pdfbox.layout.font; - -import org.apache.pdfbox.pdmodel.font.PDFont; -import org.apache.pdfbox.pdmodel.font.PDType1Font; -import org.apache.pdfbox.pdmodel.font.Standard14Fonts; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.COURIER_BOLD; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.COURIER_BOLD_OBLIQUE; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.COURIER_OBLIQUE; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.HELVETICA_BOLD; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.HELVETICA_BOLD_OBLIQUE; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.HELVETICA_OBLIQUE; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.TIMES_BOLD; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.TIMES_BOLD_ITALIC; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.TIMES_ITALIC; -import static org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.TIMES_ROMAN; - -/** - * In order to easy handling with fonts, this enum bundles the - * plain/italic/bold/bold-italic variants of the three standard font types - * Times, Courier, Helveticy. - */ -public enum BaseFont implements Font { - - TIMES(new PDType1Font(TIMES_ROMAN), new PDType1Font(TIMES_BOLD), - new PDType1Font(TIMES_ITALIC), new PDType1Font(TIMES_BOLD_ITALIC)), - - COURIER(new PDType1Font(Standard14Fonts.FontName.COURIER), new PDType1Font(COURIER_BOLD), - new PDType1Font(COURIER_OBLIQUE), new PDType1Font(COURIER_BOLD_OBLIQUE)), - - HELVETICA(new PDType1Font(Standard14Fonts.FontName.HELVETICA), new PDType1Font(HELVETICA_BOLD), - new PDType1Font(HELVETICA_OBLIQUE), new PDType1Font(HELVETICA_BOLD_OBLIQUE)); - - private final PDType1Font regularFont; - - private final PDType1Font boldFont; - - private final PDType1Font italicFont; - - private final PDType1Font boldItalicFont; - - BaseFont(PDType1Font regularFont, PDType1Font boldFont, PDType1Font italicFont, PDType1Font boldItalicFont) { - this.regularFont = regularFont; - this.boldFont = boldFont; - this.italicFont = italicFont; - this.boldItalicFont = boldItalicFont; - } - - @Override - public PDFont getRegularFont() { - return regularFont; - } - - @Override - public PDFont getBoldFont() { - return boldFont; - } - - @Override - public PDFont getItalicFont() { - return italicFont; - } - - @Override - public PDFont getBoldItalicFont() { - return boldItalicFont; - } - - @Override - public boolean hasGlyph(int code) { - try { - return regularFont.hasGlyph(code); - } catch (IOException e) { - return false; - } - } - - @Override - public boolean canWrite(String string) { - if (string == null) { - return false; - } - String printable = string.replaceAll("\\P{Print}|\\p{Cntrl}|\\p{Space}", ""); - if (printable.isEmpty()) { - return true; - } - try { - return regularFont.getStringWidth(printable) > 0; - } catch (IllegalArgumentException | IOException e) { - return false; - } - } -} diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java index abf8796..fc381b9 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.table; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Hyperlink.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Hyperlink.java index ec743ae..3b49b0e 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Hyperlink.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Hyperlink.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotatedStyledText; import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Markup.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Markup.java index 6f89cb7..ca8539a 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Markup.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Markup.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; public class Markup implements ParagraphProcessor { diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/NewLine.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/NewLine.java index 3f5495c..bdd347d 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/NewLine.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/NewLine.java @@ -1,8 +1,8 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.Font; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.Font; +import org.xbib.graphics.fonts.FontDescriptor; import java.util.List; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Parameters.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Parameters.java index 985deb9..1e2d2d1 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Parameters.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Parameters.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.table; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.BaseFont; +import org.xbib.graphics.fonts.FontDescriptor; import java.awt.Color; import java.util.List; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Row.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Row.java index 86c287e..9459d1d 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Row.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Row.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.element.Drawable; import org.xbib.graphics.pdfbox.layout.element.Element; import org.xbib.graphics.pdfbox.layout.element.HorizontalRuler; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import java.awt.Color; import java.util.ArrayList; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java index 59908d7..d742531 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/StyledText.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.table; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Table.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Table.java index 3831b22..ad5a13b 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Table.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/Table.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.table; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.BaseFont; +import org.xbib.graphics.fonts.FontDescriptor; import java.awt.Color; import java.awt.Point; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/TextCell.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/TextCell.java index d63a26a..b02357b 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/TextCell.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/TextCell.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.table; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.table.render.Renderer; import org.xbib.graphics.pdfbox.layout.table.render.TextCellRenderer; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/PositionedStyledText.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/PositionedStyledText.java index 95f3acf..b96c878 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/PositionedStyledText.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/PositionedStyledText.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.table.render; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java index ddb6960..a9b6c71 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/TextCellRenderer.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.table.render; import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.CENTER; import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.JUSTIFY; import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.RIGHT; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.table.AbstractTextCell; import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import org.xbib.graphics.pdfbox.layout.util.RenderUtil; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java index b9dfa58..0d28a98 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/render/VerticalTextCellRenderer.java @@ -2,8 +2,8 @@ package org.xbib.graphics.pdfbox.layout.table.render; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.util.Matrix; -import org.xbib.graphics.pdfbox.layout.font.Font; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.Font; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.util.PdfUtil; import org.xbib.graphics.pdfbox.layout.table.VerticalTextCell; @@ -62,7 +62,7 @@ public class VerticalTextCellRenderer extends AbstractCellRenderer fonts) { + public void addText(String text, float fontSize, Collection fonts) { add(TextFlowUtil.createTextFlow(text, new FontDescriptor(fonts, fontSize), lineSpacing, rotation)); } @@ -84,15 +85,15 @@ public class TextFlow implements TextSequence, WidthRespecting { add(TextFlowUtil.createTextFlowFromMarkup(markup, fontDescriptor, lineSpacing, rotation)); } - public void addMarkup(String markup, float fontSize, List fonts) { + public void addMarkup(String markup, float fontSize, Collection fonts) { add(TextFlowUtil.createTextFlowFromMarkup(markup, new FontDescriptor(fonts, fontSize), lineSpacing, rotation)); } - public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, List fonts) { + public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, Collection fonts) { add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(fonts, fontsize))); } - public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, List fonts, Alignment alignment) { + public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, Collection fonts, Alignment alignment) { add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(fonts, fontsize), alignment)); } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFlowUtil.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFlowUtil.java index a102c11..2e76f3c 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFlowUtil.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFlowUtil.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.text; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotatedStyledText; import org.xbib.graphics.pdfbox.layout.text.annotations.Annotation; import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationCharacters; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFragment.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFragment.java index 007496f..8f4bc92 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFragment.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextFragment.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.text; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import java.awt.Color; /** diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextLine.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextLine.java index 1890971..8c752e4 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextLine.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextLine.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.text; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.util.Matrix; import org.xbib.graphics.pdfbox.layout.element.render.Transform; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.position.Position; import java.awt.Color; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextSequenceUtil.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextSequenceUtil.java index e3613bb..c49e2bf 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextSequenceUtil.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/TextSequenceUtil.java @@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.xbib.graphics.pdfbox.layout.element.Dividable.Divided; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.Transform; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.util.Pair; import org.xbib.graphics.pdfbox.layout.util.WordBreakerFactory; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/WrappingNewLine.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/WrappingNewLine.java index 97d6607..199bedd 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/WrappingNewLine.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/WrappingNewLine.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.text; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; /** * A NewLine introduced by wrapping. This interface is useful for detecting diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/annotations/AnnotatedStyledText.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/annotations/AnnotatedStyledText.java index 8cf9e52..a042016 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/annotations/AnnotatedStyledText.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/text/annotations/AnnotatedStyledText.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.text.annotations; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.text.StyledText; import java.awt.Color; import java.util.ArrayList; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java index 9cdf8b6..6ca07e3 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/PdfUtil.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.util; -import org.xbib.graphics.pdfbox.layout.font.Font; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.Font; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.table.CouldNotDetermineStringWidthException; import java.io.IOException; @@ -53,7 +53,7 @@ public final class PdfUtil { for (String codepoint : codePointsAsString) { boolean found = false; for (Font font : fontDescriptor.getFonts()) { - if (font.canWrite(codepoint)) { + if (font.canRender(codepoint)) { try { widths.add(font.getRegularFont().getStringWidth(codepoint) * fontDescriptor.getSize() / 1000F); } catch (IllegalArgumentException | IOException e) { diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/RenderUtil.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/RenderUtil.java index 388c9cf..e4d6520 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/RenderUtil.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/RenderUtil.java @@ -2,7 +2,7 @@ package org.xbib.graphics.pdfbox.layout.util; import static org.xbib.graphics.pdfbox.layout.table.BorderStyle.SOLID; import org.apache.pdfbox.pdmodel.PDPageContentStream; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import org.xbib.graphics.pdfbox.layout.table.render.PositionedLine; import org.xbib.graphics.pdfbox.layout.table.render.PositionedRectangle; import org.xbib.graphics.pdfbox.layout.table.render.PositionedStyledText; @@ -23,7 +23,7 @@ public class RenderUtil { public static void drawText(PDPageContentStream contentStream, PositionedStyledText styledText) { for (Font font : styledText.getFontDescriptor().getFonts()) { boolean isBeginText = false; - if (font.canWrite(styledText.getText())) { + if (font.canRender(styledText.getText())) { try { contentStream.beginText(); isBeginText = true; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreaker.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreaker.java index ff4baad..a749418 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreaker.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreaker.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.util; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import java.io.IOException; /** diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreakers.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreakers.java index ded0c60..aff8f5f 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreakers.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/util/WordBreakers.java @@ -1,6 +1,6 @@ package org.xbib.graphics.pdfbox.layout.util; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil; import java.util.regex.Matcher; diff --git a/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader b/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader index d7b543a..d3ebb87 100644 --- a/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader +++ b/graphics-pdfbox-layout/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader @@ -1,2 +1 @@ org.xbib.settings.datastructures.PropertiesSettingsLoader -org.xbib.settings.datastructures.json.JsonSettingsLoader diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/AlignedTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/AlignedTest.java index bd6eef9..27783da 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/AlignedTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/AlignedTest.java @@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.util.WordBreakerFactory; import java.io.FileOutputStream; import java.io.OutputStream; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ColumnsTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ColumnsTest.java index 3a69fda..c6f0cb7 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ColumnsTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ColumnsTest.java @@ -6,7 +6,7 @@ import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer; import org.xbib.graphics.pdfbox.layout.element.render.ColumnLayout; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomAnnotationTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomAnnotationTest.java index 7db743a..d2dc9ad 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomAnnotationTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomAnnotationTest.java @@ -11,8 +11,8 @@ import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.PageFormat; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.BaseFont; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.text.DrawContext; import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.text.annotations.Annotated; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomRendererTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomRendererTest.java index 68f6326..da56d30 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomRendererTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/CustomRendererTest.java @@ -10,11 +10,11 @@ import org.xbib.graphics.pdfbox.layout.element.render.RenderContext; import org.xbib.graphics.pdfbox.layout.element.render.RenderListener; import org.xbib.graphics.pdfbox.layout.element.render.Renderer; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.shape.Stroke.CapStyle; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.text.TextFlow; import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/FramesTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/FramesTest.java index a618f77..594bb56 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/FramesTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/FramesTest.java @@ -11,7 +11,7 @@ import org.xbib.graphics.pdfbox.layout.shape.Rect; import org.xbib.graphics.pdfbox.layout.shape.RoundRect; import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.awt.Color; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloBarcodeTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloBarcodeTest.java index 64f089c..c6afa8e 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloBarcodeTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloBarcodeTest.java @@ -10,7 +10,7 @@ import org.xbib.graphics.pdfbox.layout.element.PageFormats; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.text.SpaceUnit; import java.io.FileOutputStream; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloCatTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloCatTest.java index ccbd051..b702240 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloCatTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloCatTest.java @@ -6,7 +6,7 @@ import org.xbib.graphics.pdfbox.layout.element.ImageElement; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; import javax.imageio.ImageIO; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloDocTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloDocTest.java index bba9e31..f57cafc 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloDocTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloDocTest.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.test; import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansCJKFontTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansCJKFontTest.java index 1d2a898..7122872 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansCJKFontTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansCJKFontTest.java @@ -4,11 +4,12 @@ import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.PageFormats; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.text.SpaceUnit; import java.io.FileOutputStream; +import java.util.Collection; import java.util.List; public class HelloNotoSansCJKFontTest { @@ -16,9 +17,8 @@ public class HelloNotoSansCJKFontTest { @Test public void testDocumentOne() throws Exception { Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerNotoSansFont(); - document.registerNotoSansCJKSCFont(); - List font = List.of(document.getFont("notosans"), document.getFont("notosanscjksc")); + document.embedFonts(List.of("notosans", "notosanscjksc"), getClass().getClassLoader()); + Collection font = document.getFonts(); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); paragraph.addMarkup("Hello Noto Sans CJK Regular\n", 12, font); @@ -37,7 +37,7 @@ public class HelloNotoSansCJKFontTest { @Test public void testDocumentTwo() throws Exception { Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerNotoSansCJKSCFont(); + document.embedFonts(List.of("notosans", "notosanscjksc"), getClass().getClassLoader()); List font = List.of(document.getFont("notosanscjksc")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); @@ -53,5 +53,4 @@ public class HelloNotoSansCJKFontTest { document.add(anotherParagraph); document.render().save(new FileOutputStream("build/hellonotofontcjk2.pdf")).close(); } - } diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansFontTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansFontTest.java index a9c8956..da89415 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansFontTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloNotoSansFontTest.java @@ -1,10 +1,11 @@ package org.xbib.graphics.pdfbox.layout.test; import org.junit.jupiter.api.Test; +import org.xbib.graphics.fonts.TrueTypeEmbedder; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.PageFormats; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.text.SpaceUnit; import java.io.FileOutputStream; @@ -14,8 +15,9 @@ public class HelloNotoSansFontTest { @Test public void testDocumentOne() throws Exception { + TrueTypeEmbedder.clearFonts(); Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerNotoSansFont(); + document.embedAllFonts(); List font = List.of(document.getFont("notosans")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); @@ -35,8 +37,9 @@ public class HelloNotoSansFontTest { @Test public void testDocumentTwo() throws Exception { + TrueTypeEmbedder.clearFonts(); Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerNotoSansFont(); + document.embedFonts(List.of("notosans")); List font = List.of(document.getFont("notosans")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloOpenSansFontTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloOpenSansFontTest.java index 9357840..e5bf80e 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloOpenSansFontTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloOpenSansFontTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.PageFormats; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.text.SpaceUnit; @@ -16,7 +16,7 @@ public class HelloOpenSansFontTest { @Test public void testDocumentOne() throws Exception { Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerOpenSansFont(); + document.embedAllFonts(); List font = List.of(document.getFont("opensans")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); @@ -38,7 +38,7 @@ public class HelloOpenSansFontTest { @Test public void testDocumentTwo() throws Exception { Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerOpenSansFont(); + document.embedAllFonts(); List font = List.of(document.getFont("opensans")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloSourceSansFontTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloSourceSansFontTest.java index 3d73259..a91a4e5 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloSourceSansFontTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/HelloSourceSansFontTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.PageFormats; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.Font; +import org.xbib.graphics.fonts.Font; import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.text.SpaceUnit; @@ -16,7 +16,7 @@ public class HelloSourceSansFontTest { @Test public void testDocumentOne() throws Exception { Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerSourceSansFont(); + document.embedAllFonts(); List font = List.of(document.getFont("sourcesans")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); @@ -38,7 +38,7 @@ public class HelloSourceSansFontTest { @Test public void testDocumentTwo() throws Exception { Document document = new Document(PageFormats.A4_PORTRAIT); - document.registerSourceSansFont(); + document.embedAllFonts(); List font = List.of(document.getFont("sourcesans")); Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(32, SpaceUnit.pt)); @@ -56,5 +56,4 @@ public class HelloSourceSansFontTest { document.add(anotherParagraph); document.render().save(new FileOutputStream("build/hellosourcesansfont2.pdf")).close(); } - } diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/IndentationTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/IndentationTest.java index 43545f8..323e4ec 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/IndentationTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/IndentationTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.text.SpaceUnit; import org.xbib.graphics.pdfbox.layout.util.Enumerators.AlphabeticEnumerator; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LandscapeTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LandscapeTest.java index 45e845d..54ae7d9 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LandscapeTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LandscapeTest.java @@ -9,7 +9,7 @@ import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer; import org.xbib.graphics.pdfbox.layout.element.render.ColumnLayout; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayout; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LetterTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LetterTest.java index 36d4242..3b1773b 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LetterTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LetterTest.java @@ -7,7 +7,7 @@ import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.position.Position; import java.awt.image.BufferedImage; import java.io.File; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java index 5995235..e6c35de 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LineSpacingTest.java @@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.ControlElement; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.ColumnLayout; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LinksTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LinksTest.java index 54f8643..f53f1d5 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LinksTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LinksTest.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.test; import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ListenerTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ListenerTest.java index 0abba7e..2e57a9d 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ListenerTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/ListenerTest.java @@ -5,9 +5,9 @@ import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.RenderContext; import org.xbib.graphics.pdfbox.layout.element.render.RenderListener; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.text.TextFlow; import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LowLevelText.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LowLevelText.java index 7f6a650..17121d7 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LowLevelText.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/LowLevelText.java @@ -7,12 +7,12 @@ import org.apache.pdfbox.util.Matrix; import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.PageFormat; import org.xbib.graphics.pdfbox.layout.element.render.Transform; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.shape.RoundRect; import org.xbib.graphics.pdfbox.layout.shape.Shape; import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import org.xbib.graphics.pdfbox.layout.text.DrawContext; import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.text.TextFlow; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarginTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarginTest.java index 800c023..9929467 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarginTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarginTest.java @@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarkupTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarkupTest.java index b83e3f8..060c23f 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarkupTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MarkupTest.java @@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; import org.xbib.graphics.pdfbox.layout.text.Alignment; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MultiplePagesTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MultiplePagesTest.java index 09bf996..4705fca 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MultiplePagesTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/MultiplePagesTest.java @@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.test; import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/PageFormatRotationTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/PageFormatRotationTest.java index f8db9aa..f946339 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/PageFormatRotationTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/PageFormatRotationTest.java @@ -9,7 +9,7 @@ import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer; import org.xbib.graphics.pdfbox.layout.element.render.ColumnLayout; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayout; import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.io.FileOutputStream; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/Section.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/Section.java index 173490a..f80b257 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/Section.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/Section.java @@ -1,7 +1,7 @@ package org.xbib.graphics.pdfbox.layout.test; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; import java.util.List; diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/TextRotationTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/TextRotationTest.java index cc34a44..6aa45ed 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/TextRotationTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/TextRotationTest.java @@ -6,7 +6,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Paragraph; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; +import org.xbib.graphics.fonts.BaseFont; public class TextRotationTest { diff --git a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java index 102c342..a75c8ef 100644 --- a/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java +++ b/graphics-pdfbox-layout/src/test/java/org/xbib/graphics/pdfbox/layout/test/table/TableTest.java @@ -13,8 +13,8 @@ import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.xbib.graphics.pdfbox.layout.font.BaseFont; -import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; +import org.xbib.graphics.fonts.BaseFont; +import org.xbib.graphics.fonts.FontDescriptor; import org.xbib.graphics.pdfbox.layout.table.AbstractCell; import org.xbib.graphics.pdfbox.layout.table.BorderStyle; import org.xbib.graphics.pdfbox.layout.table.Column; diff --git a/graphics-pdfbox/build.gradle b/graphics-pdfbox/build.gradle index db7b71a..d39260b 100644 --- a/graphics-pdfbox/build.gradle +++ b/graphics-pdfbox/build.gradle @@ -1,5 +1,6 @@ dependencies { api libs.pdfbox + api project(':graphics-fonts') api project(':graphics-zxing') runtimeOnly libs.pdfbox.jbig2 runtimeOnly libs.jai.jpeg2000 diff --git a/graphics-pdfbox/src/main/java/module-info.java b/graphics-pdfbox/src/main/java/module-info.java index e3ebe18..7a61e17 100644 --- a/graphics-pdfbox/src/main/java/module-info.java +++ b/graphics-pdfbox/src/main/java/module-info.java @@ -3,12 +3,11 @@ module org.xbib.graphics.pdfbox { exports org.xbib.graphics.pdfbox.analyze; exports org.xbib.graphics.pdfbox.color; exports org.xbib.graphics.pdfbox.draw; - exports org.xbib.graphics.pdfbox.font; exports org.xbib.graphics.pdfbox.image; exports org.xbib.graphics.pdfbox.paint; + requires org.xbib.graphics.fonts; requires org.xbib.graphics.zxing; requires transitive org.apache.pdfbox; - requires transitive org.apache.fontbox; requires transitive org.apache.pdfbox.io; requires transitive java.desktop; requires java.logging; diff --git a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/PdfBoxGraphics2D.java b/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/PdfBoxGraphics2D.java index b985089..6b7f1d7 100644 --- a/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/PdfBoxGraphics2D.java +++ b/graphics-pdfbox/src/main/java/org/xbib/graphics/pdfbox/PdfBoxGraphics2D.java @@ -5,9 +5,9 @@ import org.xbib.graphics.pdfbox.draw.DrawControl; import org.xbib.graphics.pdfbox.draw.DrawControl.DrawControlEnvironment; import org.xbib.graphics.pdfbox.color.ColorMapper; import org.xbib.graphics.pdfbox.color.DefaultColorMapper; -import org.xbib.graphics.pdfbox.font.DefaultFontDrawer; -import org.xbib.graphics.pdfbox.font.FontDrawer; -import org.xbib.graphics.pdfbox.font.FontDrawerEnvironment; +import org.xbib.graphics.fonts.DefaultFontDrawer; +import org.xbib.graphics.fonts.FontDrawer; +import org.xbib.graphics.fonts.FontDrawerEnvironment; import org.xbib.graphics.pdfbox.image.ImageEncoder; import org.xbib.graphics.pdfbox.image.LosslessImageEncoder; import org.xbib.graphics.pdfbox.paint.DefaultPaintApplier; diff --git a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontTest.java b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontTest.java index 1f3fe34..a4e8d44 100644 --- a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontTest.java +++ b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontTest.java @@ -6,18 +6,20 @@ import java.awt.Color; import java.awt.Font; import java.awt.FontFormatException; import java.io.IOException; +import java.io.InputStream; public class FontTest extends PdfBoxGraphics2DTestBase { @Test public void testAntonioFont() throws IOException, FontFormatException { - final Font antonioRegular = Font.createFont(Font.TRUETYPE_FONT, - PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf")) - .deriveFont(15f); - exportGraphic("fonts", "antonio", gfx -> { - gfx.setColor(Color.BLACK); - gfx.setFont(antonioRegular); - gfx.drawString("Für älter österlich, Umlauts are not always fun.", 10, 50); - }); + InputStream inputStream = PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf"); + if (inputStream != null) { + final Font antonioRegular = Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(15f); + exportGraphic("fonts", "antonio", gfx -> { + gfx.setColor(Color.BLACK); + gfx.setFont(antonioRegular); + gfx.drawString("Für älter österlich, Umlauts are not always fun.", 10, 50); + }); + } } } diff --git a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontWidthDiscrepancyTest.java b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontWidthDiscrepancyTest.java index 19deab7..26ce2bc 100644 --- a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontWidthDiscrepancyTest.java +++ b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/FontWidthDiscrepancyTest.java @@ -12,6 +12,7 @@ import java.awt.FontFormatException; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.io.IOException; +import java.io.InputStream; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -19,46 +20,32 @@ public class FontWidthDiscrepancyTest extends PdfBoxGraphics2DTestBase { @Test public void testAntonioFontWidth() throws IOException, FontFormatException { - final String testString = "MMMMMMMMMMMMMMMMMMMMMM"; final float fontSize = 20f; - final Font antonioRegular = Font.createFont(Font.TRUETYPE_FONT, - PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf")) - .deriveFont(fontSize); - + InputStream inputStream = PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf"); + final Font antonioRegular = Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(fontSize); + InputStream pdFontInputStream = PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf"); final PDDocument doc = new PDDocument(); - final PDFont pdFont = PDType0Font.load(doc, - PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf")); - + final PDFont pdFont = PDType0Font.load(doc, pdFontInputStream); final Graphics2D gfx = new PdfBoxGraphics2D(doc, 400, 400); - final float pdfWidth = pdFont.getStringWidth(testString) / 1000 * fontSize; final int gfxWidth = gfx.getFontMetrics(antonioRegular).stringWidth(testString); gfx.dispose(); doc.close(); - - exportGraphic("fontWidthDiscrepancy", "antonio-m", new GraphicsExporter() { - @Override - public void draw(Graphics2D gfx) throws IOException, FontFormatException { - gfx.setFont(antonioRegular); - gfx.setColor(Color.GREEN); - gfx.drawString(testString, 10, 10); - gfx.setColor(Color.RED); - gfx.drawLine(10, 1, (int) (10 + pdfWidth), 1); - gfx.setColor(Color.BLUE); - gfx.drawLine(10, 15, 10 + gfxWidth, 15); - - gfx.setColor(Color.magenta); - FontMetrics fontMetrics = gfx.getFontMetrics(); - int currentMeasurement = fontMetrics.stringWidth(testString); - gfx.drawLine(10, 25, 10 + currentMeasurement, 25); - - gfx.drawLine(10, 5, 10 + fontMetrics.charWidth('M'), 5); - - assertNotNull(fontMetrics.getWidths()); - } + exportGraphic("fontWidthDiscrepancy", "antonio-m", gfx1 -> { + gfx1.setFont(antonioRegular); + gfx1.setColor(Color.GREEN); + gfx1.drawString(testString, 10, 10); + gfx1.setColor(Color.RED); + gfx1.drawLine(10, 1, (int) (10 + pdfWidth), 1); + gfx1.setColor(Color.BLUE); + gfx1.drawLine(10, 15, 10 + gfxWidth, 15); + gfx1.setColor(Color.magenta); + FontMetrics fontMetrics = gfx1.getFontMetrics(); + int currentMeasurement = fontMetrics.stringWidth(testString); + gfx1.drawLine(10, 25, 10 + currentMeasurement, 25); + gfx1.drawLine(10, 5, 10 + fontMetrics.charWidth('M'), 5); + assertNotNull(fontMetrics.getWidths()); }); - } - } diff --git a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/PdfBoxGraphics2DTestBase.java b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/PdfBoxGraphics2DTestBase.java index 932f340..ae17e4e 100644 --- a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/PdfBoxGraphics2DTestBase.java +++ b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/PdfBoxGraphics2DTestBase.java @@ -10,9 +10,9 @@ import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; import org.apache.pdfbox.util.Matrix; import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; -import org.xbib.graphics.pdfbox.font.CoreFontDrawer; -import org.xbib.graphics.pdfbox.font.DefaultFontDrawer; -import org.xbib.graphics.pdfbox.font.ForcedFontDrawer; +import org.xbib.graphics.fonts.CoreFontDrawer; +import org.xbib.graphics.fonts.DefaultFontDrawer; +import org.xbib.graphics.fonts.ForcedFontDrawer; import java.awt.FontFormatException; import java.awt.Graphics2D; diff --git a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java index 03fadd9..46d9265 100644 --- a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java +++ b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java @@ -1,39 +1,13 @@ package org.xbib.graphics.pdfbox.test; -/* -import io.sf.carte.echosvg.anim.dom.SAXSVGDocumentFactory; -import io.sf.carte.echosvg.bridge.BridgeContext; -import io.sf.carte.echosvg.bridge.DocumentLoader; -import io.sf.carte.echosvg.bridge.GVTBuilder; -import io.sf.carte.echosvg.bridge.UserAgent; -import io.sf.carte.echosvg.bridge.UserAgentAdapter; -import io.sf.carte.echosvg.gvt.GraphicsNode; -*/ - -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDPageContentStream; -import org.apache.pdfbox.pdmodel.common.PDRectangle; -import org.apache.pdfbox.pdmodel.font.PDType1Font; -import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; -import org.apache.pdfbox.util.Matrix; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.w3c.dom.Document; -import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; -import org.xbib.graphics.pdfbox.color.DefaultColorMapper; -import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper; -import org.xbib.graphics.pdfbox.font.DefaultFontDrawer; -import org.xbib.graphics.pdfbox.font.FontDrawer; import org.xbib.graphics.svg.SVGDiagram; import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.SVGUniverse; -import java.awt.color.ICC_Profile; -import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URL; -import java.util.logging.Logger; public class RenderSVGsTest extends PdfBoxGraphics2DTestBase { @@ -64,13 +38,14 @@ public class RenderSVGsTest extends PdfBoxGraphics2DTestBase { renderSVG("horizontal-gradient.svg", 0.55); } + @Disabled @Test public void testSVGinCMYKColorspace() throws IOException { - renderSVGCMYK("atmospheric-composiition.svg", 0.7); + //renderSVGCMYK("atmospheric-composiition.svg", 0.7); } private void renderSVG(String name, final double scale) { - /*URL url = getClass().getResource(name); + URL url = getClass().getResource(name); SVGUniverse svgUniverse = new SVGUniverse(); SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(url)); exportGraphic("xbibsvg", name.replace(".svg", ""), gfx -> { @@ -80,64 +55,6 @@ public class RenderSVGsTest extends PdfBoxGraphics2DTestBase { } catch (SVGException e) { throw new IllegalArgumentException(e); } - });*/ - - /*String uri = RenderSVGsTest.class.getResource(name).toString(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(); - Document document = f.createDocument(uri, RenderSVGsTest.class.getResourceAsStream(name)); - UserAgent userAgent = new UserAgentAdapter(); - DocumentLoader loader = new DocumentLoader(userAgent); - BridgeContext bctx = new BridgeContext(userAgent, loader); - bctx.setDynamicState(BridgeContext.STATIC); - GVTBuilder builder = new GVTBuilder(); - final GraphicsNode gvtRoot = builder.build(bctx, document); - this.exportGraphic("svg", name.replace(".svg", ""), gfx -> { - gfx.scale(scale, scale); - gvtRoot.paint(gfx); - });*/ - } - - private void renderSVGCMYK(String name, double scale) throws IOException { - /*String uri = RenderSVGsTest.class.getResource(name).toString(); - SAXSVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(); - Document document = documentFactory.createDocument(uri, RenderSVGsTest.class.getResourceAsStream(name)); - UserAgent userAgent = new UserAgentAdapter(); - DocumentLoader documentLoader = new DocumentLoader(userAgent); - BridgeContext bridgeContext = new BridgeContext(userAgent, documentLoader); - bridgeContext.setDynamicState(BridgeContext.STATIC); - GVTBuilder gvtBuilder = new GVTBuilder(); - GraphicsNode graphicsNode = gvtBuilder.build(bridgeContext, document); - PDDocument pdfDocument = new PDDocument(); - ICC_Profile icc_profile = ICC_Profile.getInstance(PDDocument.class.getResourceAsStream( - "/org/apache/pdfbox/resources/icc/ISOcoated_v2_300_bas.icc")); - DefaultColorMapper colorMapper = new RGBtoCMYKColorMapper(icc_profile, pdfDocument); - File parentDir = new File("build/test/svg"); - parentDir.mkdirs(); - PDPage page = new PDPage(PDRectangle.A4); - pdfDocument.addPage(page); - PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page); - PdfBoxGraphics2D pdfBoxGraphics2D = new PdfBoxGraphics2D(pdfDocument, 400, 400); - pdfBoxGraphics2D.setColorMapper(colorMapper); - contentStream.beginText(); - contentStream.setStrokingColor(0.0f, 0.0f, 0.0f, 1.0f); - contentStream.setNonStrokingColor(0.0f, 0.0f, 0.0f, 1.0f); - contentStream.setFont(PDType1Font.HELVETICA_BOLD, 15); - contentStream.setTextMatrix(Matrix.getTranslateInstance(10, 800)); - contentStream.showText("Mode: CMYK colorspace"); - contentStream.endText(); - FontDrawer fontDrawer = new DefaultFontDrawer(); - pdfBoxGraphics2D.setFontTextDrawer(fontDrawer); - pdfBoxGraphics2D.scale(scale, scale); - graphicsNode.paint(pdfBoxGraphics2D); - pdfBoxGraphics2D.dispose(); - PDFormXObject xFormObject = pdfBoxGraphics2D.getXFormObject(); - Matrix matrix = new Matrix(); - matrix.translate(0, 300); - contentStream.transform(matrix); - contentStream.drawForm(xFormObject); - contentStream.close(); - String baseName = name.substring(0, name.lastIndexOf('.')); - pdfDocument.save(new File(parentDir, baseName + ".pdf")); - pdfDocument.close();*/ + }); } } diff --git a/settings.gradle b/settings.gradle index e8539b8..35d145f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -74,6 +74,12 @@ include 'graphics-vector-pdf' include 'graphics-vector-svg' include 'graphics-chart' include 'graphics-barcode' +include 'graphics-fonts' +include 'graphics-fonts-arabic' +include 'graphics-fonts-cjk' +include 'graphics-fonts-cyrillic' +include 'graphics-fonts-hebrew' +include 'graphics-fonts-latin' include 'graphics-ghostscript' include 'graphics-pdfbox' include 'graphics-pdfbox-layout'