move fonts to subprojects
This commit is contained in:
parent
2dedbc154f
commit
09086f9b5b
136 changed files with 761 additions and 498 deletions
|
@ -1,3 +1,3 @@
|
||||||
group = org.xbib.graphics
|
group = org.xbib.graphics
|
||||||
name = graphics
|
name = graphics
|
||||||
version = 5.5.5
|
version = 5.6.0
|
||||||
|
|
3
graphics-fonts-arabic/build.gradle
Normal file
3
graphics-fonts-arabic/build.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies {
|
||||||
|
api project(':graphics-fonts')
|
||||||
|
}
|
8
graphics-fonts-arabic/src/main/java/module-info.java
Normal file
8
graphics-fonts-arabic/src/main/java/module-info.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
3
graphics-fonts-cjk/build.gradle
Normal file
3
graphics-fonts-cjk/build.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies {
|
||||||
|
api project(':graphics-fonts')
|
||||||
|
}
|
8
graphics-fonts-cjk/src/main/java/module-info.java
Normal file
8
graphics-fonts-cjk/src/main/java/module-info.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.xbib.graphics.fonts.cjk.CJKFontEmbedder
|
3
graphics-fonts-cyrillic/build.gradle
Normal file
3
graphics-fonts-cyrillic/build.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies {
|
||||||
|
api project(':graphics-fonts')
|
||||||
|
}
|
7
graphics-fonts-cyrillic/src/main/java/module-info.java
Normal file
7
graphics-fonts-cyrillic/src/main/java/module-info.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.xbib.graphics.fonts.cyrillic.CyrillicFontEmbedder
|
3
graphics-fonts-hebrew/build.gradle
Normal file
3
graphics-fonts-hebrew/build.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies {
|
||||||
|
api project(':graphics-fonts')
|
||||||
|
}
|
7
graphics-fonts-hebrew/src/main/java/module-info.java
Normal file
7
graphics-fonts-hebrew/src/main/java/module-info.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.xbib.graphics.fonts.hebrew.HebrewFontEmbedder
|
3
graphics-fonts-latin/build.gradle
Normal file
3
graphics-fonts-latin/build.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies {
|
||||||
|
api project(':graphics-fonts')
|
||||||
|
}
|
11
graphics-fonts-latin/src/main/java/module-info.java
Normal file
11
graphics-fonts-latin/src/main/java/module-info.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
org.xbib.graphics.fonts.latin.NotoSansFontEmbedder
|
||||||
|
org.xbib.graphics.fonts.latin.OpenSansFontEmbedder
|
||||||
|
org.xbib.graphics.fonts.latin.SourceSansFontEmbedder
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
graphics-fonts/build.gradle
Normal file
3
graphics-fonts/build.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies {
|
||||||
|
api libs.pdfbox
|
||||||
|
}
|
8
graphics-fonts/src/main/java/module-info.java
Normal file
8
graphics-fonts/src/main/java/module-info.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.xbib.graphics.pdfbox.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.xbib.graphics.pdfbox.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import org.apache.fontbox.ttf.TrueTypeCollection;
|
import org.apache.fontbox.ttf.TrueTypeCollection;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
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.PDType0Font;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
import org.apache.pdfbox.util.Matrix;
|
import org.apache.pdfbox.util.Matrix;
|
||||||
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
|
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.FontFormatException;
|
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
|
* Default implementation to draw fonts. You can reuse instances of this class
|
||||||
* within a PDDocument for more then one {@link PdfBoxGraphics2D}.
|
* within a PDDocument. Just ensure that you call close after you closed the PDDocument to free any
|
||||||
* Just ensure that you call close after you closed the PDDocument to free any
|
|
||||||
* temporary files.
|
* temporary files.
|
||||||
*/
|
*/
|
||||||
public class DefaultFontDrawer implements FontDrawer, Closeable {
|
public class DefaultFontDrawer implements FontDrawer, Closeable {
|
|
@ -1,4 +1,4 @@
|
||||||
package org.xbib.graphics.pdfbox.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
|
@ -1,11 +1,11 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public interface Font {
|
public interface Font {
|
||||||
|
|
||||||
|
String getAlias();
|
||||||
|
|
||||||
PDFont getRegularFont();
|
PDFont getRegularFont();
|
||||||
|
|
||||||
PDFont getBoldFont();
|
PDFont getBoldFont();
|
||||||
|
@ -16,5 +16,5 @@ public interface Font {
|
||||||
|
|
||||||
boolean hasGlyph(int code);
|
boolean hasGlyph(int code);
|
||||||
|
|
||||||
boolean canWrite(String string);
|
boolean canRender(String string);
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,7 +10,7 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
public class FontDescriptor {
|
public class FontDescriptor {
|
||||||
|
|
||||||
private final List<Font> fonts;
|
private final Collection<Font> fonts;
|
||||||
|
|
||||||
private float size;
|
private float size;
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ public class FontDescriptor {
|
||||||
|
|
||||||
private boolean italic;
|
private boolean italic;
|
||||||
|
|
||||||
public FontDescriptor(List<Font> fonts, float size) {
|
public FontDescriptor(Collection<Font> fonts, float size) {
|
||||||
this(fonts, size, false, false);
|
this(fonts, size, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FontDescriptor(List<Font> fonts, float size, boolean bold, boolean italic) {
|
public FontDescriptor(Collection<Font> fonts, float size, boolean bold, boolean italic) {
|
||||||
this.fonts = fonts;
|
this.fonts = fonts;
|
||||||
// we do not accept null fonts
|
// we do not accept null fonts
|
||||||
for (Font font : fonts) {
|
for (Font font : fonts) {
|
||||||
|
@ -36,7 +36,7 @@ public class FontDescriptor {
|
||||||
this.regular = !bold && !italic;
|
this.regular = !bold && !italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Font> getFonts() {
|
public Collection<Font> getFonts() {
|
||||||
return fonts;
|
return fonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class FontDescriptor {
|
||||||
|
|
||||||
public PDFont getSelectedFont(String text) {
|
public PDFont getSelectedFont(String text) {
|
||||||
for (Font font : fonts) {
|
for (Font font : fonts) {
|
||||||
if (font.canWrite(text)) {
|
if (font.canRender(text)) {
|
||||||
if (regular) {
|
if (regular) {
|
||||||
return font.getRegularFont();
|
return font.getRegularFont();
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.xbib.graphics.pdfbox.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.FontFormatException;
|
import java.awt.FontFormatException;
|
|
@ -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.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import org.apache.pdfbox.pdmodel.PDResources;
|
import org.apache.pdfbox.pdmodel.PDResources;
|
||||||
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
||||||
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
|
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
@ -59,7 +58,7 @@ public interface FontDrawerEnvironment {
|
||||||
FontRenderContext getFontRenderContext();
|
FontRenderContext getFontRenderContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the bbox of the {@link PdfBoxGraphics2D}
|
* @return the bbox
|
||||||
*/
|
*/
|
||||||
PDRectangle getGraphicsBBox();
|
PDRectangle getGraphicsBBox();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.xbib.graphics.pdfbox.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.xbib.graphics.pdfbox.font;
|
package org.xbib.graphics.fonts;
|
||||||
|
|
||||||
import java.text.AttributedCharacterIterator;
|
import java.text.AttributedCharacterIterator;
|
||||||
|
|
|
@ -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<String, Font> 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<String> getFontAliases() {
|
||||||
|
return fonts.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Font> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,9 @@
|
||||||
package org.xbib.graphics.pdfbox.test;
|
package org.xbib.graphics.fonts.test;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.xbib.graphics.pdfbox.font.CoreFontDrawer;
|
import org.xbib.graphics.fonts.CoreFontDrawer;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
|
@ -2,7 +2,11 @@ dependencies {
|
||||||
api project(':graphics-pdfbox')
|
api project(':graphics-pdfbox')
|
||||||
api project(':graphics-barcode')
|
api project(':graphics-barcode')
|
||||||
api project(':graphics-chart')
|
api project(':graphics-chart')
|
||||||
|
api project(':graphics-fonts')
|
||||||
api libs.datastructures.settings
|
api libs.datastructures.settings
|
||||||
runtimeOnly libs.datastructures.settings.json
|
runtimeOnly libs.datastructures.settings.json
|
||||||
runtimeOnly libs.datastructures.settings.yaml
|
runtimeOnly libs.datastructures.settings.yaml
|
||||||
|
testRuntimeOnly project(':graphics-fonts-latin')
|
||||||
|
testRuntimeOnly project(':graphics-fonts-hebrew')
|
||||||
|
testRuntimeOnly project(':graphics-fonts-cjk')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
module org.xbib.graphics.layout.pdfbox {
|
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.boxable;
|
||||||
exports org.xbib.graphics.pdfbox.layout.color;
|
exports org.xbib.graphics.pdfbox.layout.color;
|
||||||
exports org.xbib.graphics.pdfbox.layout.element;
|
exports org.xbib.graphics.pdfbox.layout.element;
|
||||||
exports org.xbib.graphics.pdfbox.layout.element.render;
|
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;
|
||||||
exports org.xbib.graphics.pdfbox.layout.element.scripting.command;
|
exports org.xbib.graphics.pdfbox.layout.element.scripting.command;
|
||||||
exports org.xbib.graphics.pdfbox.layout.shape;
|
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.graphics.pdfbox;
|
||||||
requires transitive org.xbib.settings.api;
|
requires transitive org.xbib.settings.api;
|
||||||
requires org.xbib.settings.datastructures;
|
requires org.xbib.settings.datastructures;
|
||||||
requires transitive java.desktop;
|
|
||||||
requires java.logging;
|
|
||||||
requires org.xbib.graphics.chart;
|
requires org.xbib.graphics.chart;
|
||||||
|
requires org.xbib.graphics.fonts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.element;
|
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.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
|
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.xbib.graphics.fonts.BaseFont;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDType0Font;
|
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.Layout;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.LayoutHint;
|
import org.xbib.graphics.pdfbox.layout.element.render.LayoutHint;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.RenderContext;
|
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.Renderer;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayout;
|
import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayout;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint;
|
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.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
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.
|
* The central class for creating a document.
|
||||||
*/
|
*/
|
||||||
public class Document implements Element, Closeable, RenderListener {
|
public class Document implements Element, Closeable, RenderListener {
|
||||||
|
|
||||||
private final List<Entry<Element, LayoutHint>> elements;
|
private static final Logger logger = Logger.getLogger(Document.class.getName());
|
||||||
|
|
||||||
private final Map<String, Font> fonts;
|
private final List<Entry<Element, LayoutHint>> elements;
|
||||||
|
|
||||||
private final List<Renderer> customRenderer;
|
private final List<Renderer> customRenderer;
|
||||||
|
|
||||||
|
@ -53,6 +51,8 @@ public class Document implements Element, Closeable, RenderListener {
|
||||||
|
|
||||||
private final PDDocumentInformation pdDocumentInformation;
|
private final PDDocumentInformation pdDocumentInformation;
|
||||||
|
|
||||||
|
private final TrueTypeEmbedder trueTypeFonts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Document.
|
* Creates a Document.
|
||||||
*/
|
*/
|
||||||
|
@ -85,22 +85,69 @@ public class Document implements Element, Closeable, RenderListener {
|
||||||
public Document(PageFormat pageFormat) {
|
public Document(PageFormat pageFormat) {
|
||||||
this.pdDocument = new PDDocument();
|
this.pdDocument = new PDDocument();
|
||||||
this.pdDocumentInformation = new PDDocumentInformation();
|
this.pdDocumentInformation = new PDDocumentInformation();
|
||||||
|
this.trueTypeFonts = new TrueTypeEmbedder();
|
||||||
this.elements = new ArrayList<>();
|
this.elements = new ArrayList<>();
|
||||||
this.fonts = new LinkedHashMap<>();
|
|
||||||
this.customRenderer = new ArrayList<>();
|
this.customRenderer = new ArrayList<>();
|
||||||
this.renderListener = new ArrayList<>();
|
this.renderListener = new ArrayList<>();
|
||||||
setPageFormat(pageFormat);
|
setPageFormat(pageFormat);
|
||||||
registerFont("helvetica", BaseFont.HELVETICA);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPageFormat(PageFormat pageFormat) {
|
|
||||||
this.pageFormat = pageFormat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDDocument getPdDocument() {
|
public PDDocument getPdDocument() {
|
||||||
return pdDocument;
|
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<String> aliases) {
|
||||||
|
embedFonts(aliases, getClass().getClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void embedFonts(Collection<String> 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<Font> getFonts() {
|
||||||
|
return trueTypeFonts.getFonts();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageFormat(PageFormat pageFormat) {
|
||||||
|
this.pageFormat = pageFormat;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAuthor(String author) {
|
public void setAuthor(String author) {
|
||||||
pdDocumentInformation.setAuthor(author);
|
pdDocumentInformation.setAuthor(author);
|
||||||
}
|
}
|
||||||
|
@ -145,116 +192,6 @@ public class Document implements Element, Closeable, RenderListener {
|
||||||
pdDocumentInformation.setCustomMetadataValue(key, value);
|
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}.
|
* Adds an element to the document using a {@link VerticalLayoutHint}.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,8 +7,8 @@ import org.apache.pdfbox.util.Matrix;
|
||||||
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
|
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
|
||||||
import org.xbib.graphics.pdfbox.color.DefaultColorMapper;
|
import org.xbib.graphics.pdfbox.color.DefaultColorMapper;
|
||||||
import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper;
|
import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper;
|
||||||
import org.xbib.graphics.pdfbox.font.DefaultFontDrawer;
|
import org.xbib.graphics.fonts.DefaultFontDrawer;
|
||||||
import org.xbib.graphics.pdfbox.font.FontDrawer;
|
import org.xbib.graphics.fonts.FontDrawer;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
|
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
|
||||||
import org.xbib.graphics.pdfbox.layout.position.Position;
|
import org.xbib.graphics.pdfbox.layout.position.Position;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.element;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -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.color.ColorFactory;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Document;
|
import org.xbib.graphics.pdfbox.layout.element.Document;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
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.Engine;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
|
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.BorderStyle;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface;
|
import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment;
|
import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment;
|
||||||
|
|
|
@ -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.PageFormat;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
|
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
|
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 org.xbib.settings.Settings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
|
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
|
||||||
|
@ -73,16 +74,7 @@ public class DocumentCommand implements Command {
|
||||||
}
|
}
|
||||||
String[] fonts = settings.getAsArray("font");
|
String[] fonts = settings.getAsArray("font");
|
||||||
for (String font : fonts) {
|
for (String font : fonts) {
|
||||||
switch (font) {
|
document.embedFonts(List.of(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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
state.getElements().push(document);
|
state.getElements().push(document);
|
||||||
engine.executeElements(settings);
|
engine.executeElements(settings);
|
||||||
|
|
|
@ -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.color.ColorFactory;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
|
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
|
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.Font;
|
import org.xbib.graphics.fonts.Font;
|
||||||
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.BorderStyle;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface;
|
import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment;
|
import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
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 org.xbib.graphics.pdfbox.layout.util.PdfUtil;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
package org.xbib.graphics.pdfbox.layout.table;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
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.AnnotatedStyledText;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations;
|
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
package org.xbib.graphics.pdfbox.layout.table;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
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 {
|
public class Markup implements ParagraphProcessor {
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
package org.xbib.graphics.pdfbox.layout.table;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
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.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
package org.xbib.graphics.pdfbox.layout.table;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.fonts.BaseFont;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -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.Drawable;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Element;
|
import org.xbib.graphics.pdfbox.layout.element.Element;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.HorizontalRuler;
|
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.awt.Color;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
package org.xbib.graphics.pdfbox.layout.table;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
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 org.xbib.graphics.pdfbox.layout.util.PdfUtil;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
package org.xbib.graphics.pdfbox.layout.table;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.fonts.BaseFont;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table;
|
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.Renderer;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.render.TextCellRenderer;
|
import org.xbib.graphics.pdfbox.layout.table.render.TextCellRenderer;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.table.render;
|
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;
|
import java.awt.Color;
|
||||||
|
|
||||||
|
|
|
@ -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.CENTER;
|
||||||
import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.JUSTIFY;
|
import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.JUSTIFY;
|
||||||
import static org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment.RIGHT;
|
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.table.AbstractTextCell;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.PdfUtil;
|
import org.xbib.graphics.pdfbox.layout.util.PdfUtil;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.RenderUtil;
|
import org.xbib.graphics.pdfbox.layout.util.RenderUtil;
|
||||||
|
|
|
@ -2,8 +2,8 @@ package org.xbib.graphics.pdfbox.layout.table.render;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import org.apache.pdfbox.util.Matrix;
|
import org.apache.pdfbox.util.Matrix;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.Font;
|
import org.xbib.graphics.fonts.Font;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.PdfUtil;
|
import org.xbib.graphics.pdfbox.layout.util.PdfUtil;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.VerticalTextCell;
|
import org.xbib.graphics.pdfbox.layout.table.VerticalTextCell;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class VerticalTextCellRenderer extends AbstractCellRenderer<VerticalTextC
|
||||||
PDPageContentStream contentStream) {
|
PDPageContentStream contentStream) {
|
||||||
try {
|
try {
|
||||||
for (Font font : fontDescriptor.getFonts()) {
|
for (Font font : fontDescriptor.getFonts()) {
|
||||||
if (font.canWrite(text)) {
|
if (font.canRender(text)) {
|
||||||
// Rotate by 90 degrees counter clockwise
|
// Rotate by 90 degrees counter clockwise
|
||||||
AffineTransform transform = AffineTransform.getTranslateInstance(x, y);
|
AffineTransform transform = AffineTransform.getTranslateInstance(x, y);
|
||||||
transform.concatenate(AffineTransform.getRotateInstance(Math.PI * 0.5));
|
transform.concatenate(AffineTransform.getRotateInstance(Math.PI * 0.5));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
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;
|
import java.awt.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.fonts.BaseFont;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
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.util.Enumerator;
|
import org.xbib.graphics.pdfbox.layout.util.Enumerator;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.EnumeratorFactory;
|
import org.xbib.graphics.pdfbox.layout.util.EnumeratorFactory;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Control fragment that represents a new line in text. It has a (font and)
|
* Control fragment that represents a new line in text. It has a (font and)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acts as a replacement for whitespace that has been removed by word wrapping.
|
* Acts as a replacement for whitespace that has been removed by word wrapping.
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit to specify space, currently only em and pt.
|
* Unit to specify space, currently only em and pt.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
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;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
|
@ -2,11 +2,12 @@ package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.Font;
|
import org.xbib.graphics.fonts.Font;
|
||||||
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.position.Position;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -76,7 +77,7 @@ public class TextFlow implements TextSequence, WidthRespecting {
|
||||||
return (T) cache.get(key);
|
return (T) cache.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addText(String text, float fontSize, List<Font> fonts) {
|
public void addText(String text, float fontSize, Collection<Font> fonts) {
|
||||||
add(TextFlowUtil.createTextFlow(text, new FontDescriptor(fonts, fontSize), lineSpacing, rotation));
|
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));
|
add(TextFlowUtil.createTextFlowFromMarkup(markup, fontDescriptor, lineSpacing, rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMarkup(String markup, float fontSize, List<Font> fonts) {
|
public void addMarkup(String markup, float fontSize, Collection<Font> fonts) {
|
||||||
add(TextFlowUtil.createTextFlowFromMarkup(markup, new FontDescriptor(fonts, fontSize), lineSpacing, rotation));
|
add(TextFlowUtil.createTextFlowFromMarkup(markup, new FontDescriptor(fonts, fontSize), lineSpacing, rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, List<Font> fonts) {
|
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, Collection<Font> fonts) {
|
||||||
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(fonts, fontsize)));
|
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(fonts, fontsize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, List<Font> fonts, Alignment alignment) {
|
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, Collection<Font> fonts, Alignment alignment) {
|
||||||
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(fonts, fontsize), alignment));
|
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(fonts, fontsize), alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
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.AnnotatedStyledText;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotation;
|
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotation;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationCharacters;
|
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationCharacters;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
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;
|
import java.awt.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.text;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import org.apache.pdfbox.util.Matrix;
|
import org.apache.pdfbox.util.Matrix;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
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.position.Position;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
|
@ -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.Dividable.Divided;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
||||||
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
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.position.Position;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.Pair;
|
import org.xbib.graphics.pdfbox.layout.util.Pair;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.WordBreakerFactory;
|
import org.xbib.graphics.pdfbox.layout.util.WordBreakerFactory;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
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
|
* A NewLine introduced by wrapping. This interface is useful for detecting
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text.annotations;
|
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 org.xbib.graphics.pdfbox.layout.text.StyledText;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.util;
|
package org.xbib.graphics.pdfbox.layout.util;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.Font;
|
import org.xbib.graphics.fonts.Font;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.fonts.FontDescriptor;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.CouldNotDetermineStringWidthException;
|
import org.xbib.graphics.pdfbox.layout.table.CouldNotDetermineStringWidthException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -53,7 +53,7 @@ public final class PdfUtil {
|
||||||
for (String codepoint : codePointsAsString) {
|
for (String codepoint : codePointsAsString) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Font font : fontDescriptor.getFonts()) {
|
for (Font font : fontDescriptor.getFonts()) {
|
||||||
if (font.canWrite(codepoint)) {
|
if (font.canRender(codepoint)) {
|
||||||
try {
|
try {
|
||||||
widths.add(font.getRegularFont().getStringWidth(codepoint) * fontDescriptor.getSize() / 1000F);
|
widths.add(font.getRegularFont().getStringWidth(codepoint) * fontDescriptor.getSize() / 1000F);
|
||||||
} catch (IllegalArgumentException | IOException e) {
|
} catch (IllegalArgumentException | IOException e) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.xbib.graphics.pdfbox.layout.util;
|
||||||
|
|
||||||
import static org.xbib.graphics.pdfbox.layout.table.BorderStyle.SOLID;
|
import static org.xbib.graphics.pdfbox.layout.table.BorderStyle.SOLID;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
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.PositionedLine;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.render.PositionedRectangle;
|
import org.xbib.graphics.pdfbox.layout.table.render.PositionedRectangle;
|
||||||
import org.xbib.graphics.pdfbox.layout.table.render.PositionedStyledText;
|
import org.xbib.graphics.pdfbox.layout.table.render.PositionedStyledText;
|
||||||
|
@ -23,7 +23,7 @@ public class RenderUtil {
|
||||||
public static void drawText(PDPageContentStream contentStream, PositionedStyledText styledText) {
|
public static void drawText(PDPageContentStream contentStream, PositionedStyledText styledText) {
|
||||||
for (Font font : styledText.getFontDescriptor().getFonts()) {
|
for (Font font : styledText.getFontDescriptor().getFonts()) {
|
||||||
boolean isBeginText = false;
|
boolean isBeginText = false;
|
||||||
if (font.canWrite(styledText.getText())) {
|
if (font.canRender(styledText.getText())) {
|
||||||
try {
|
try {
|
||||||
contentStream.beginText();
|
contentStream.beginText();
|
||||||
isBeginText = true;
|
isBeginText = true;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.util;
|
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;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue