remove truetype files and remove obsolete ghostscript font analysis

This commit is contained in:
Jörg Prante 2023-12-07 14:28:52 +01:00
parent 7b624e8f30
commit 64bbee5cd3
39 changed files with 24 additions and 122 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib.graphics
name = graphics
version = 5.2.1
version = 5.3.0
org.gradle.warning.mode = ALL

View file

@ -1,50 +0,0 @@
package org.xbib.graphics.ghostscript;
public class FontAnalysisItem {
private String name;
private boolean embedded;
private boolean subSet;
public FontAnalysisItem() {
}
@Override
public String toString() {
String embeddedString = "NOT_EMBEDDED";
if (embedded) {
embeddedString = "EMBEDDED";
}
String setString = "FULL_SET";
if (subSet) {
setString = "SUB_SET";
}
return name + ": " + embeddedString + " " + setString;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEmbedded() {
return embedded;
}
public void setEmbedded(boolean embedded) {
this.embedded = embedded;
}
public boolean isSubSet() {
return subSet;
}
public void setSubSet(boolean subSet) {
this.subSet = subSet;
}
}

View file

@ -1,61 +0,0 @@
package org.xbib.graphics.ghostscript;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/**
* Font analyzer.
* Analyze fonts used in a document using {@code -fonta}.
* We use Pdfbox for font analysis, so this is not tested and not used.
*/
public class FontAnalyzer {
public FontAnalyzer() {
}
public synchronized List<FontAnalysisItem> analyze(Path path) throws IOException {
String[] gsArgs = new String[]{"-fonta",
"-dQUIET", "-dNOPAUSE", "-dBATCH", "-dNODISPLAY",
"-sFile=" + path.toAbsolutePath(),
"-sOutputFile=%stdout",
"-f", "-"};
try (Ghostscript gs = new Ghostscript();
InputStream is = this.getClass().getClassLoader().getResourceAsStream("script/AnalyzePDFFonts.ps");
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
gs.setStdIn(is);
gs.setStdOut(baos);
gs.run(gsArgs);
List<FontAnalysisItem> result = new ArrayList<>();
String s = baos.toString();
String[] lines = s.split("\n");
boolean inResults = false;
for (String line : lines) {
if (line.equals("---")) {
inResults = true;
} else if (inResults) {
String[] columns = line.split(" ");
if (columns.length == 2) {
FontAnalysisItem font = new FontAnalysisItem();
String name = columns[0];
String[] nameParts = name.split("\\+");
if (nameParts.length > 1) {
name = nameParts[1];
font.setSubSet(true);
}
font.setName(name);
font.setEmbedded(false);
if (columns[1].equals("EM") || columns[1].equals("SU")) {
font.setEmbedded(true);
}
result.add(font);
}
}
}
return result;
}
}
}

View file

@ -175,13 +175,21 @@ public class DocumentAnalyzer {
}
}
/*
* MediaBox: the largest box possible, for the carrier medium of the page, it contains all frames and all elements.
* CropBox: the size of the box for the printer and on-screen display. Includes printer marks.
* BleedBox: the "Anschnitt" which means the area of the page that is to be displayed, including cutmarks.
* BBox: PDFbox effective bounding box
* TrimBox: (optional) the "Endformat" of the page ready to be produced, without cutmarks.
* ArtBox: (optional) the smallest box possible, without header, footer, page numbering.
*/
private Map<String, Object> analyzePage(int i, PDPage page, Set<COSStream> seen) throws IOException {
Map<String, Object> m = new LinkedHashMap<>();
m.put("page", i);
m.put("bbox", Map.of("height", page.getBBox().getHeight(), "width", page.getBBox().getWidth()));
m.put("cropbox", Map.of("height", page.getCropBox().getHeight(), "width", page.getCropBox().getWidth()));
m.put("mediabox", Map.of("height", page.getMediaBox().getHeight(), "width", page.getMediaBox().getWidth()));
m.put("cropbox", Map.of("height", page.getCropBox().getHeight(), "width", page.getCropBox().getWidth()));
m.put("bleedbox", Map.of("height", page.getBleedBox().getHeight(), "width", page.getBleedBox().getWidth()));
m.put("bbox", Map.of("height", page.getBBox().getHeight(), "width", page.getBBox().getWidth()));
if (page.getTrimBox() != null) {
m.put("trimbox", Map.of("height", page.getTrimBox().getHeight(), "width", page.getTrimBox().getWidth()));
}

View file

@ -306,17 +306,22 @@ public class DefaultFontDrawer implements FontDrawer, Closeable {
if (windir == null) {
windir = javaFontDir;
}
File[] paths = new File[]{new File(new File(windir), "fonts"),
File[] paths = new File[] {
new File(new File(windir), "fonts"),
new File(System.getProperty("user.dir", ".")),
// Mac Fonts
new File("/Library/Fonts"), new File("/System/Library/Fonts/Supplemental/"),
new File("/Library/Fonts"),
new File("/System/Library/Fonts/Supplemental/"),
// Unix Fonts
new File("/usr/share/fonts/truetype"), new File("/usr/share/fonts/truetype/dejavu"),
new File("/usr/share/fonts/truetype"),
new File("/usr/share/fonts/truetype/dejavu"),
new File("/usr/share/fonts/truetype/liberation"),
new File("/usr/share/fonts/truetype/noto"), new File(javaFontDir)};
for (String fontFileName : new String[]{"LucidaSansRegular.ttf", "arial.ttf", "Arial.ttf",
new File("/usr/share/fonts/truetype/noto"),
new File(javaFontDir)
};
for (String fontFileName : List.of("LucidaSansRegular.ttf", "arial.ttf", "Arial.ttf",
"DejaVuSans.ttf", "LiberationMono-Regular.ttf", "NotoSerif-Regular.ttf",
"Arial Unicode.ttf", "Tahoma.ttf"}) {
"Arial Unicode.ttf", "Tahoma.ttf")) {
for (File path : paths) {
File arialFile = new File(path, fontFileName);
if (arialFile.exists()) {

View file

@ -19,7 +19,7 @@ public class BarcodeAnalyzerTest {
@Test
public void testBarcodeAnalysis() throws IOException {
Path tmp = Files.createTempDirectory("barcode-analyzer");
String sample = "test.pdf";
String sample = "mail_with_barcode.pdf";
Path path = tmp.resolve(sample);
try (InputStream inputStream = getClass().getResourceAsStream(sample);
OutputStream outputStream = Files.newOutputStream(path)) {

View file

@ -18,7 +18,7 @@ public class DocumentAnalyzerTest {
@Test
public void testDocument() throws IOException {
Path tmp = Files.createTempDirectory("document-analyzer");
String sample = "394_394-F3GIS2JO.pdf";
String sample = "antonio_sample.pdf";
Path path = tmp.resolve(sample);
try (InputStream inputStream = getClass().getResourceAsStream(sample);
OutputStream outputStream = Files.newOutputStream(path)) {