Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
a70b7e62cf | |||
a323076ca3 | |||
b13aa5f3ef | |||
2d6961e848 | |||
09086f9b5b | |||
2dedbc154f | |||
0564b2e934 | |||
aa08fa45f0 |
164 changed files with 1255 additions and 687 deletions
gradle.properties
graphics-barcode/src
graphics-chart/src/main/java
graphics-fonts-arabic
Google-Noto-LICENSE.txtbuild.gradle
src/main
java
resources
META-INF/services
org/xbib/graphics/fonts/arabic
graphics-fonts-cjk
Google-Noto-LICENSE.txtbuild.gradle
src/main
java
resources
META-INF/services
org/xbib/graphics/fonts/cjk
graphics-fonts-cyrillic
Google-Noto-LICENSE.txtNOTICE.txtbuild.gradle
src/main
java
resources
META-INF/services
org/xbib/graphics/fonts/cyrillic
graphics-fonts-hebrew
Google-Noto-LICENSE.txtbuild.gradle
src/main
java
resources
META-INF/services
org/xbib/graphics/fonts/hebrew
graphics-fonts-latin
Adobe-Source-LICENSE.txtGoogle-Noto-LICENSE.txtbuild.gradle
src
main
java
module-info.java
org/xbib/graphics/fonts/latin
resources
META-INF/services
org/xbib/graphics/fonts/latin
test/java/org/xbib/graphics/fonts/latin/test
graphics-fonts
build.gradle
src
graphics-ghostscript/src/main/java
graphics-pdfbox-layout
build.gradle
src/main/java
module-info.java
org/xbib/graphics/pdfbox/layout
element
font
table
AbstractTextCell.javaHyperlink.javaMarkup.javaNewLine.javaParameters.javaRow.javaStyledText.javaTable.javaTextCell.java
render
text
|
@ -1,3 +1,3 @@
|
|||
group = org.xbib.graphics
|
||||
name = graphics
|
||||
version = 5.5.3
|
||||
version = 5.7.0
|
||||
|
|
|
@ -46,8 +46,8 @@ module org.xbib.graphics.barcode {
|
|||
exports org.xbib.graphics.barcode;
|
||||
exports org.xbib.graphics.barcode.util;
|
||||
exports org.xbib.graphics.barcode.render;
|
||||
requires transitive java.desktop;
|
||||
requires transitive org.xbib.graphics.zxing;
|
||||
requires java.desktop;
|
||||
requires org.xbib.graphics.zxing;
|
||||
provides SymbolProvider with
|
||||
AustraliaPost.Provider,
|
||||
AztecCode.Provider,
|
||||
|
|
|
@ -17,14 +17,11 @@ import java.nio.file.Paths;
|
|||
|
||||
public class QRCodeTest {
|
||||
|
||||
/**
|
||||
* The hard way by using Okapi Barcode.
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void createQRCode() throws IOException {
|
||||
//String content = "IFLA-15: Kostenlimit überschritten, erneute Bestellung, wenn Kosten akzeptiert werden";
|
||||
String content = "IFLA-16:";
|
||||
//String content = "IFLA-16:";
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 128;
|
||||
|
@ -34,7 +31,7 @@ public class QRCodeTest {
|
|||
code.setQuietZoneHorizontal(1);
|
||||
code.setQuietZoneVertical(1);
|
||||
code.setEccMode(QrCode.EccMode.L);
|
||||
code.setContent(content);
|
||||
//code.setContent(content);
|
||||
double scalingFactor = 5.0d;
|
||||
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
|
||||
BarcodeGraphicsRenderer renderer = createRenderer(bufferedImage, x, y, scalingFactor, scalingFactor);
|
||||
|
@ -56,14 +53,12 @@ public class QRCodeTest {
|
|||
/**
|
||||
* Easy way by using zxing.
|
||||
* @throws IOException
|
||||
* @throws NotFoundException
|
||||
* @throws WriterException
|
||||
*/
|
||||
@Test
|
||||
public void testQrCode() throws IOException, NotFoundException, WriterException {
|
||||
public void testQrCode() throws IOException {
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
try (OutputStream outputStream = Files.newOutputStream(Paths.get("build/ifla-20.png"))) {
|
||||
qrCodeWriter.write("IFLA-20: Art der gewünschten Lieferung nicht möglich",
|
||||
try (OutputStream outputStream = Files.newOutputStream(Paths.get("build/de-361-ifla-20.png"))) {
|
||||
qrCodeWriter.write("DE-361: IFLA-20: Art der gewünschten Lieferung nicht möglich",
|
||||
outputStream, "png", 200, 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,5 +17,5 @@ module org.xbib.graphics.chart {
|
|||
requires org.xbib.graphics.io.vector.eps;
|
||||
requires org.xbib.graphics.io.vector.pdf;
|
||||
requires org.xbib.graphics.io.vector.svg;
|
||||
requires transitive java.desktop;
|
||||
requires java.desktop;
|
||||
}
|
||||
|
|
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')
|
||||
}
|
9
graphics-fonts-arabic/src/main/java/module-info.java
Normal file
9
graphics-fonts-arabic/src/main/java/module-info.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
import org.xbib.graphics.fonts.FontEmbedder;
|
||||
import org.xbib.graphics.fonts.arabic.ArabicFontEmbedder;
|
||||
|
||||
module org.xbib.graphics.fonts.arabic {
|
||||
requires org.xbib.graphics.fonts;
|
||||
requires org.apache.pdfbox;
|
||||
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");
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.xbib.graphics.fonts.arabic.ArabicFontEmbedder
|
Binary file not shown.
Binary file not shown.
45
graphics-fonts-cjk/Google-Noto-LICENSE.txt
Normal file
45
graphics-fonts-cjk/Google-Noto-LICENSE.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
SIL Open Font License
|
||||
|
||||
Copyright 2012 Google Inc. All Rights Reserved.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
—————————————————————————————-
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
—————————————————————————————-
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
|
||||
|
||||
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
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')
|
||||
}
|
9
graphics-fonts-cjk/src/main/java/module-info.java
Normal file
9
graphics-fonts-cjk/src/main/java/module-info.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
import org.xbib.graphics.fonts.FontEmbedder;
|
||||
import org.xbib.graphics.fonts.cjk.CJKFontEmbedder;
|
||||
|
||||
module org.xbib.graphics.fonts.cjk {
|
||||
requires org.xbib.graphics.fonts;
|
||||
requires org.apache.pdfbox;
|
||||
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
|
45
graphics-fonts-cyrillic/Google-Noto-LICENSE.txt
Normal file
45
graphics-fonts-cyrillic/Google-Noto-LICENSE.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
SIL Open Font License
|
||||
|
||||
Copyright 2012 Google Inc. All Rights Reserved.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
—————————————————————————————-
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
—————————————————————————————-
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
|
||||
|
||||
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
2
graphics-fonts-cyrillic/NOTICE.txt
Normal file
2
graphics-fonts-cyrillic/NOTICE.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Identical to Noto Latin fonts. There is no need to add cyrillic Noto fonst if the latin Noto fonts are already added.
|
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')
|
||||
}
|
8
graphics-fonts-cyrillic/src/main/java/module-info.java
Normal file
8
graphics-fonts-cyrillic/src/main/java/module-info.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
import org.xbib.graphics.fonts.FontEmbedder;
|
||||
import org.xbib.graphics.fonts.cyrillic.CyrillicFontEmbedder;
|
||||
|
||||
module org.xbib.graphics.fonts.cyrillic {
|
||||
requires org.xbib.graphics.fonts;
|
||||
requires org.apache.pdfbox;
|
||||
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
|
45
graphics-fonts-hebrew/Google-Noto-LICENSE.txt
Normal file
45
graphics-fonts-hebrew/Google-Noto-LICENSE.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
SIL Open Font License
|
||||
|
||||
Copyright 2012 Google Inc. All Rights Reserved.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
—————————————————————————————-
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
—————————————————————————————-
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
|
||||
|
||||
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
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')
|
||||
}
|
8
graphics-fonts-hebrew/src/main/java/module-info.java
Normal file
8
graphics-fonts-hebrew/src/main/java/module-info.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
import org.xbib.graphics.fonts.FontEmbedder;
|
||||
import org.xbib.graphics.fonts.hebrew.HebrewFontEmbedder;
|
||||
|
||||
module org.xbib.graphics.fonts.hebrew {
|
||||
requires org.xbib.graphics.fonts;
|
||||
requires org.apache.pdfbox;
|
||||
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
|
45
graphics-fonts-latin/Google-Noto-LICENSE.txt
Normal file
45
graphics-fonts-latin/Google-Noto-LICENSE.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
SIL Open Font License
|
||||
|
||||
Copyright 2012 Google Inc. All Rights Reserved.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
—————————————————————————————-
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
—————————————————————————————-
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
|
||||
|
||||
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
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')
|
||||
}
|
12
graphics-fonts-latin/src/main/java/module-info.java
Normal file
12
graphics-fonts-latin/src/main/java/module-info.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
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;
|
||||
requires org.apache.pdfbox;
|
||||
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 java.desktop;
|
||||
requires org.apache.fontbox;
|
||||
requires 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;
|
||||
|
|
@ -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 {
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
|
@ -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<Font> fonts;
|
||||
private final Collection<Font> fonts;
|
||||
|
||||
private float size;
|
||||
|
||||
|
@ -20,11 +20,11 @@ public class FontDescriptor {
|
|||
|
||||
private boolean italic;
|
||||
|
||||
public FontDescriptor(List<Font> fonts, float size) {
|
||||
public FontDescriptor(Collection<Font> fonts, float size) {
|
||||
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;
|
||||
// we do not accept null fonts
|
||||
for (Font font : fonts) {
|
||||
|
@ -36,7 +36,7 @@ public class FontDescriptor {
|
|||
this.regular = !bold && !italic;
|
||||
}
|
||||
|
||||
public List<Font> getFonts() {
|
||||
public Collection<Font> 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();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.graphics.pdfbox.font;
|
||||
package org.xbib.graphics.fonts;
|
||||
|
||||
import java.awt.Font;
|
||||
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.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();
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.xbib.graphics.fonts;
|
||||
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface FontEmbedder {
|
||||
|
||||
String getAlias();
|
||||
|
||||
Collection<Font> getFonts();
|
||||
|
||||
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;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.graphics.pdfbox.font;
|
||||
package org.xbib.graphics.fonts;
|
||||
|
||||
import java.text.AttributedCharacterIterator;
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
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;
|
||||
|
||||
public abstract class TrueTypeEmbedder implements FontEmbedder {
|
||||
|
||||
private final Map<String, Font> fonts = new LinkedHashMap<>();
|
||||
|
||||
public TrueTypeEmbedder() {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
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 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;
|
||||
|
|
@ -2,7 +2,7 @@ module org.xbib.graphics.ghostscript {
|
|||
exports org.xbib.graphics.ghostscript;
|
||||
requires com.sun.jna;
|
||||
requires java.logging;
|
||||
requires transitive java.desktop;
|
||||
requires transitive org.apache.pdfbox;
|
||||
requires transitive org.apache.pdfbox.io;
|
||||
requires java.desktop;
|
||||
requires org.apache.pdfbox;
|
||||
requires org.apache.pdfbox.io;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@ dependencies {
|
|||
api project(':graphics-pdfbox')
|
||||
api project(':graphics-barcode')
|
||||
api project(':graphics-chart')
|
||||
api libs.datastructures.settings
|
||||
runtimeOnly libs.datastructures.settings.json
|
||||
runtimeOnly libs.datastructures.settings.yaml
|
||||
api project(':graphics-fonts')
|
||||
api libs.settings.api
|
||||
testImplementation testLibs.settings.json
|
||||
testRuntimeOnly project(':graphics-fonts-arabic')
|
||||
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 {
|
||||
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;
|
||||
|
@ -13,11 +13,12 @@ module org.xbib.graphics.layout.pdfbox {
|
|||
exports org.xbib.graphics.pdfbox.layout.text.annotations;
|
||||
exports org.xbib.graphics.pdfbox.layout.util;
|
||||
exports org.xbib.graphics.pdfbox.layout.position;
|
||||
requires transitive org.xbib.graphics.barcode;
|
||||
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.barcode;
|
||||
requires org.xbib.graphics.pdfbox;
|
||||
requires org.xbib.settings.api;
|
||||
requires org.xbib.graphics.chart;
|
||||
requires org.xbib.graphics.fonts;
|
||||
requires org.apache.pdfbox;
|
||||
requires java.desktop;
|
||||
requires java.logging;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
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.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 +12,35 @@ 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.LinkedHashSet;
|
||||
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;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* The central class for creating a document.
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@ -53,6 +52,8 @@ public class Document implements Element, Closeable, RenderListener {
|
|||
|
||||
private final PDDocumentInformation pdDocumentInformation;
|
||||
|
||||
private final Collection<Font> fonts;
|
||||
|
||||
/**
|
||||
* Creates a Document.
|
||||
*/
|
||||
|
@ -85,22 +86,83 @@ public class Document implements Element, Closeable, RenderListener {
|
|||
public Document(PageFormat pageFormat) {
|
||||
this.pdDocument = new PDDocument();
|
||||
this.pdDocumentInformation = new PDDocumentInformation();
|
||||
this.fonts = new LinkedHashSet<>();
|
||||
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() {
|
||||
fonts.add(BaseFont.HELVETICA);
|
||||
fonts.add(BaseFont.TIMES);
|
||||
fonts.add(BaseFont.COURIER);
|
||||
}
|
||||
|
||||
public void embedAllFonts() {
|
||||
embedFonts(List.of(""));
|
||||
}
|
||||
|
||||
public void embedFonts(Collection<String> aliases) {
|
||||
embedFonts(aliases, List.of(getClass().getClassLoader(),
|
||||
ClassLoader.getSystemClassLoader(),
|
||||
Thread.currentThread().getContextClassLoader()));
|
||||
}
|
||||
|
||||
private void embedFonts(Collection<String> aliases, Collection<ClassLoader> classLoaders) {
|
||||
for (ClassLoader classLoader : classLoaders) {
|
||||
Iterable<FontEmbedder> fontEmbedders = ServiceLoader.load(FontEmbedder.class, classLoader);
|
||||
boolean serviceLoaded = false;
|
||||
for (String alias : aliases) {
|
||||
// fonts times, helvetica, courier are standard fonts without embedding
|
||||
switch (alias) {
|
||||
case "times" -> fonts.add(BaseFont.TIMES);
|
||||
case "helvetica" -> fonts.add(BaseFont.HELVETICA);
|
||||
case "courier" -> fonts.add(BaseFont.COURIER);
|
||||
case null, default -> {
|
||||
boolean found = false;
|
||||
for (FontEmbedder fontEmbedder : fontEmbedders) {
|
||||
try {
|
||||
if (alias == null || alias.isEmpty() || fontEmbedder.getAlias().equals(alias)) {
|
||||
fontEmbedder.embed(this.pdDocument);
|
||||
fonts.addAll(fontEmbedder.getFonts());
|
||||
found = true;
|
||||
serviceLoaded = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
logger.log(Level.WARNING, "font " + alias + " not found using embedders " +
|
||||
StreamSupport.stream(fontEmbedders.spliterator(), false).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (serviceLoaded) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
logger.log(Level.FINER, "fonts: " + fonts);
|
||||
}
|
||||
|
||||
public Font getFont(String alias) {
|
||||
return fonts.stream().filter(f -> f.getAlias().equals(alias)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public Collection<Font> getFonts() {
|
||||
return fonts;
|
||||
}
|
||||
|
||||
public void setPageFormat(PageFormat pageFormat) {
|
||||
this.pageFormat = pageFormat;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
pdDocumentInformation.setAuthor(author);
|
||||
}
|
||||
|
@ -145,116 +207,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}.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -4,11 +4,13 @@ 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.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
|
||||
|
@ -72,18 +74,7 @@ public class DocumentCommand implements Command {
|
|||
document.setModificationDate(instant);
|
||||
}
|
||||
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(Arrays.asList(fonts));
|
||||
state.getElements().push(document);
|
||||
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.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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<VerticalTextC
|
|||
PDPageContentStream contentStream) {
|
||||
try {
|
||||
for (Font font : fontDescriptor.getFonts()) {
|
||||
if (font.canWrite(text)) {
|
||||
if (font.canRender(text)) {
|
||||
// Rotate by 90 degrees counter clockwise
|
||||
AffineTransform transform = AffineTransform.getTranslateInstance(x, y);
|
||||
transform.concatenate(AffineTransform.getRotateInstance(Math.PI * 0.5));
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.xbib.graphics.pdfbox.layout.text;
|
||||
|
||||
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.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
|
|
@ -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.util.Enumerator;
|
||||
import org.xbib.graphics.pdfbox.layout.util.EnumeratorFactory;
|
||||
import java.awt.Color;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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.
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue