fix font embedder and cloass loader issues, add arabic/hebrew fonts

This commit is contained in:
Jörg Prante 2025-01-22 17:52:05 +01:00
parent 09086f9b5b
commit 2d6961e848
17 changed files with 336 additions and 68 deletions

View file

@ -0,0 +1 @@
org.xbib.graphics.fonts.arabic.ArabicFontEmbedder

View 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.

View 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.

View 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.

View 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.

View 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.

View file

@ -3,10 +3,13 @@ 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;
}

View file

@ -13,30 +13,14 @@ 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 {
public abstract class TrueTypeEmbedder implements FontEmbedder {
private static final Map<String, Font> fonts = new LinkedHashMap<>();
private 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,
@ -102,18 +86,7 @@ public class TrueTypeEmbedder implements FontEmbedder {
});
}
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();
}
@Override
public Collection<Font> getFonts() {
return fonts.values();
}

View file

@ -6,6 +6,7 @@ dependencies {
api libs.datastructures.settings
runtimeOnly libs.datastructures.settings.json
runtimeOnly libs.datastructures.settings.yaml
testRuntimeOnly project(':graphics-fonts-arabic')
testRuntimeOnly project(':graphics-fonts-latin')
testRuntimeOnly project(':graphics-fonts-hebrew')
testRuntimeOnly project(':graphics-fonts-cjk')

View file

@ -5,7 +5,6 @@ import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.xbib.graphics.fonts.BaseFont;
import org.xbib.graphics.fonts.Font;
import org.xbib.graphics.fonts.FontEmbedder;
import org.xbib.graphics.fonts.TrueTypeEmbedder;
import org.xbib.graphics.pdfbox.layout.element.render.Layout;
import org.xbib.graphics.pdfbox.layout.element.render.LayoutHint;
import org.xbib.graphics.pdfbox.layout.element.render.RenderContext;
@ -31,6 +30,7 @@ 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.
@ -51,7 +51,7 @@ public class Document implements Element, Closeable, RenderListener {
private final PDDocumentInformation pdDocumentInformation;
private final TrueTypeEmbedder trueTypeFonts;
private final Collection<Font> fonts;
/**
* Creates a Document.
@ -85,7 +85,7 @@ public class Document implements Element, Closeable, RenderListener {
public Document(PageFormat pageFormat) {
this.pdDocument = new PDDocument();
this.pdDocumentInformation = new PDDocumentInformation();
this.trueTypeFonts = new TrueTypeEmbedder();
this.fonts = new ArrayList<>();
this.elements = new ArrayList<>();
this.customRenderer = new ArrayList<>();
this.renderListener = new ArrayList<>();
@ -97,51 +97,57 @@ public class Document implements Element, Closeable, RenderListener {
}
public void registerCoreFonts() {
trueTypeFonts.register(BaseFont.HELVETICA);
trueTypeFonts.register(BaseFont.TIMES);
trueTypeFonts.register(BaseFont.COURIER);
fonts.add(BaseFont.HELVETICA);
fonts.add(BaseFont.TIMES);
fonts.add(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());
embedFonts(List.of(""));
}
public void embedFonts(Collection<String> aliases) {
embedFonts(aliases, getClass().getClassLoader());
embedFonts(aliases, List.of(getClass().getClassLoader(),
ClassLoader.getSystemClassLoader(),
Thread.currentThread().getContextClassLoader()));
}
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);
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) {
boolean found = false;
for (FontEmbedder fontEmbedder : fontEmbedders) {
try {
if (alias == null || alias.isEmpty() || fontEmbedder.getAlias().equals(alias)) {
fontEmbedder.embed(this.pdDocument);
found = true;
serviceLoaded = true;
fonts.addAll(fontEmbedder.getFonts());
}
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
} 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: " + trueTypeFonts.getFontAliases());
logger.log(Level.FINER, "fonts: " + fonts);
}
public Font getFont(String alias) {
return trueTypeFonts.getFont(alias);
return fonts.stream().filter(f -> f.getAlias().equals(alias)).findFirst().orElse(null);
}
public Collection<Font> getFonts() {
return trueTypeFonts.getFonts();
return fonts;
}
public void setPageFormat(PageFormat pageFormat) {

View file

@ -0,0 +1,52 @@
package org.xbib.graphics.pdfbox.layout.test;
import org.junit.jupiter.api.Test;
import org.xbib.graphics.fonts.Font;
import org.xbib.graphics.pdfbox.layout.element.Document;
import org.xbib.graphics.pdfbox.layout.element.PageFormats;
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
import org.xbib.graphics.pdfbox.layout.text.Indent;
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.List;
public class HelloNotoSansArabicFontTest {
@Test
public void testDocumentOne() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosans", "notosansarabic"));
Collection<Font> font = document.getFonts();
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Noto Sans Arabic Regular\n", 12, font);
paragraph.addMarkup("*Hello Noto Sans Arabic Bold*\n", 12, font);
paragraph.addText("Hello Unicode Arabic Text: فهرس\n", 12, font);
document.add(paragraph);
Paragraph anotherParagraph = new Paragraph();
anotherParagraph.add(new Indent(32, SpaceUnit.pt));
anotherParagraph.addMarkup("Hello Noto Sans Arabic Regular\n", 12, font);
document.add(anotherParagraph);
document.render().save(new FileOutputStream("build/hellonotofontarabic.pdf")).close();
}
@Test
public void testDocumentTwo() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosansarabic"));
List<Font> font = List.of(document.getFont("notosansarabic"));
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Noto Sans Arabic Regular 2\n", 12, font);
paragraph.addMarkup("*Hello Noto Sans Arabic Bold*\n", 12, font);
paragraph.addText("Hello Unicode Arabic Text: فهرس\n", 12, font);
document.add(paragraph);
Paragraph anotherParagraph = new Paragraph();
anotherParagraph.add(new Indent(32, SpaceUnit.pt));
anotherParagraph.addMarkup("Hello Noto Sans Arabic Regular 2\n", 12, font);
document.add(anotherParagraph);
document.render().save(new FileOutputStream("build/hellonotofontarabic2.pdf")).close();
}
}

View file

@ -17,7 +17,7 @@ public class HelloNotoSansCJKFontTest {
@Test
public void testDocumentOne() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosans", "notosanscjksc"), getClass().getClassLoader());
document.embedFonts(List.of("notosans", "notosanscjksc"));
Collection<Font> font = document.getFonts();
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
@ -37,7 +37,7 @@ public class HelloNotoSansCJKFontTest {
@Test
public void testDocumentTwo() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosans", "notosanscjksc"), getClass().getClassLoader());
document.embedFonts(List.of("notosanscjksc"));
List<Font> font = List.of(document.getFont("notosanscjksc"));
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));

View file

@ -15,7 +15,6 @@ public class HelloNotoSansFontTest {
@Test
public void testDocumentOne() throws Exception {
TrueTypeEmbedder.clearFonts();
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedAllFonts();
List<Font> font = List.of(document.getFont("notosans"));
@ -37,7 +36,6 @@ public class HelloNotoSansFontTest {
@Test
public void testDocumentTwo() throws Exception {
TrueTypeEmbedder.clearFonts();
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosans"));
List<Font> font = List.of(document.getFont("notosans"));

View file

@ -0,0 +1,52 @@
package org.xbib.graphics.pdfbox.layout.test;
import org.junit.jupiter.api.Test;
import org.xbib.graphics.fonts.Font;
import org.xbib.graphics.pdfbox.layout.element.Document;
import org.xbib.graphics.pdfbox.layout.element.PageFormats;
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
import org.xbib.graphics.pdfbox.layout.text.Indent;
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.List;
public class HelloNotoSansHebrewFontTest {
@Test
public void testDocumentOne() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosans", "notosanshebrew"));
Collection<Font> font = document.getFonts();
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Noto Sans Hebrew Regular\n", 12, font);
paragraph.addMarkup("*Hello Noto Sans Hebrew Bold*\n", 12, font);
paragraph.addText("Hello Unicode Hebrew Text: יְרוּשָׁלַיִם\n", 12, font);
document.add(paragraph);
Paragraph anotherParagraph = new Paragraph();
anotherParagraph.add(new Indent(32, SpaceUnit.pt));
anotherParagraph.addMarkup("Hello Noto Sans Hebrew Regular\n", 12, font);
document.add(anotherParagraph);
document.render().save(new FileOutputStream("build/hellonotofonthebrew.pdf")).close();
}
@Test
public void testDocumentTwo() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedFonts(List.of("notosanshebrew"));
List<Font> font = List.of(document.getFont("notosanshebrew"));
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Noto Sans Hebrew Regular 2\n", 12, font);
paragraph.addMarkup("*Hello Noto Sans Hebrew Bold*\n", 12, font);
paragraph.addText("Hello Unicode Hebrew Text: יְרוּשָׁלַיִם \n", 12, font);
document.add(paragraph);
Paragraph anotherParagraph = new Paragraph();
anotherParagraph.add(new Indent(32, SpaceUnit.pt));
anotherParagraph.addMarkup("Hello Noto Sans Hebrew Regular 2\n", 12, font);
document.add(anotherParagraph);
document.render().save(new FileOutputStream("build/hellonotofonthebrew2.pdf")).close();
}
}

View file

@ -17,7 +17,7 @@ public class HelloOpenSansFontTest {
public void testDocumentOne() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedAllFonts();
List<Font> font = List.of(document.getFont("opensans"));
List<Font> font = List.of(document.getFont("opensans"), document.getFont("notosanscjksc"));
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Open Sans Regular\n", 12, font);
@ -26,7 +26,7 @@ public class HelloOpenSansFontTest {
paragraph.addMarkup("*_Hello Open Sans Bold Italic_*\n", 12, font);
paragraph.addText("Hello Unicode Text: Zwrotki dla Dorotki : arcyksiążę fiołków\n", 12, font);
paragraph.addMarkup("Hello Unicode Markup: _Zwrotki dla Dorotki : arcyksiążę fiołków_\n", 12, font);
//paragraph.addText("Hello CJK Text: 北京是中国古都,是拥有三千余年建城历史、八百六十余年建都史的历史文化名城\n", 12, font);
paragraph.addText("Hello CJK Text: 北京是中国古都,是拥有三千余年建城历史、八百六十余年建都史的历史文化名城\n", 12, font);
document.add(paragraph);
Paragraph anotherParagraph = new Paragraph();
anotherParagraph.add(new Indent(32, SpaceUnit.pt));
@ -39,7 +39,7 @@ public class HelloOpenSansFontTest {
public void testDocumentTwo() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT);
document.embedAllFonts();
List<Font> font = List.of(document.getFont("opensans"));
List<Font> font = List.of(document.getFont("opensans"), document.getFont("notosanscjksc"));
Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Open Sans Regular 2\n", 12, font);
@ -48,7 +48,7 @@ public class HelloOpenSansFontTest {
paragraph.addMarkup("*_Hello Open Sans Bold Italic_*\n", 12, font);
paragraph.addText("Hello Unicode Text: Zwrotki dla Dorotki : arcyksiążę fiołków\n", 12, font);
paragraph.addMarkup("Hello Unicode Markup: _Zwrotki dla Dorotki : arcyksiążę fiołków_\n", 12, font);
//paragraph.addText("Hello CJK Text: 北京是中国古都,是拥有三千余年建城历史、八百六十余年建都史的历史文化名城\n", 12, font);
paragraph.addText("Hello CJK Text: 北京是中国古都,是拥有三千余年建城历史、八百六十余年建都史的历史文化名城\n", 12, font);
document.add(paragraph);
Paragraph anotherParagraph = new Paragraph();
anotherParagraph.add(new Indent(32, SpaceUnit.pt));