Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,30 @@
public class GlyphLayoutProcessorAwt extends AbstractGlyphLayoutProcessor implements GlyphLayoutProcessorInterface
{

private final GlyphLayoutFontLoaderAwt glyphLayoutFontLoaderAwt;
private final GlyphLayoutFontLoaderAwt glyphLayoutFontLoaderAwt = new GlyphLayoutFontLoaderAwt();


/**
* Constructs a GlyphLayoutProcessorFop with options
*
*/
public GlyphLayoutProcessorAwt(AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions options)
{
super(options);
}

/**
* Constructs a GlyphLayoutProcessorAwt
*
*/
public GlyphLayoutProcessorAwt()
{
this.glyphLayoutFontLoaderAwt = new GlyphLayoutFontLoaderAwt();
super();
}

/**


/**
* Checks if glyphs needed for text are missing in awtFont
*
* @param text text to be checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

import org.apache.pdfbox.Loader;

import org.apache.pdfbox.pdmodel.AbstractGlyphLayoutProcessor;
import org.junit.jupiter.api.Test;

import org.apache.pdfbox.pdmodel.PDDocument;
Expand Down Expand Up @@ -90,14 +93,47 @@ class GlyphLayoutDin91379Test extends TestBase
+ "⁹ ⁿ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ™ ∞ ≤ ≥\n"
+ "Additional non-letters (not included in DIN 91379): – — •�";

/**
* Test, no ActualText
* @throws IOException
* @throws FontFormatException
* @throws URISyntaxException
*/
@Test
void testGlyphLayoutDin91379NoActualText() throws IOException, FontFormatException, URISyntaxException {
testGlyphLayoutDin91379(false, "");
}

/**
* Test with ActualText
* @throws IOException
* @throws FontFormatException
* @throws URISyntaxException
*/
@Test
void testGlyphLayoutDin91379() throws IOException, FontFormatException, URISyntaxException
void testGlyphLayoutDin91379UseActualText() throws IOException, FontFormatException, URISyntaxException {
testGlyphLayoutDin91379(true, "_ActualText");
}

/**
* Test GlyphLayoutProcessorAwt with letters and sequences from DIN 91379
* @param useActualText
* @throws IOException
* @throws FontFormatException
* @throws URISyntaxException
*/
void testGlyphLayoutDin91379(boolean useActualText, String sActualText) throws IOException, FontFormatException, URISyntaxException
{
GlyphLayoutProcessorAwt glyphLayoutProcessor = new GlyphLayoutProcessorAwt();
AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions options = new AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions();
if (useActualText) {
options.useActualText();
}
GlyphLayoutProcessorAwt glyphLayoutProcessor = new GlyphLayoutProcessorAwt(options);

String outputBaseName = String.format("GlyphLayoutDIN91379%s", sActualText);
String outputPDFFilename = "target/" + outputBaseName + ".pdf";
String outputTextFilename = "target/" + outputBaseName + ".txt";

String outputName = "GlyphLayoutDIN91379.pdf";
String outputPDFFilename = "target/" + outputName;
String outputTextFilename = "target/GlyphLayoutDIN91379.txt";
float fontSize = 12.0f;

try (PDDocument doc = new PDDocument())
Expand All @@ -119,8 +155,9 @@ void testGlyphLayoutDin91379() throws IOException, FontFormatException, URISynta
}
doc.save(outputPDFFilename);
}
checkRenderIdent(outputName);

checkRenderIdent(outputBaseName + ".pdf");

// Extract text
try (PDDocument doc = Loader.loadPDF(new File(outputPDFFilename)))
{
assertEquals(1, doc.getNumberOfPages());
Expand All @@ -133,7 +170,7 @@ void testGlyphLayoutDin91379() throws IOException, FontFormatException, URISynta
os.write (0xBB);
os.write (0xBF);

try (Writer writer = new BufferedWriter(new OutputStreamWriter(os, "utf-8")))
try (Writer writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)))
{
//TODO compare this output with the input, like in TextStripper test
// Not yet correct as of 4.7.2026
Expand All @@ -158,7 +195,7 @@ private void showComposites(PDPageContentStream cs, PDType0Font font, float font
if (!line.isEmpty())
{
showCompositesLine(cs, font, fontSize, x, y, line);
y -= fontSize * 1.5;
y -= fontSize * 1.5f;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
package org.apache.pdfbox.glyphlayout.awt;

import java.awt.FontFormatException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.AbstractGlyphLayoutProcessor;
import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.jupiter.api.Test;

import org.apache.pdfbox.pdmodel.PDDocument;
Expand Down Expand Up @@ -82,13 +94,49 @@ void testMissingGlyph() throws IOException, FontFormatException
}
}

/**
* Test, no ActualText
* @throws IOException
* @throws FontFormatException
* @throws URISyntaxException
*/
@Test
void testLigaturesAndKerning() throws IOException, FontFormatException, URISyntaxException
void testLigaturesAndKerningNoActualText() throws IOException, FontFormatException, URISyntaxException {
testLigaturesAndKerning(false, "");
}

/**
* Test with ActualText
* @throws IOException
* @throws FontFormatException
* @throws URISyntaxException
*/
@Test
void testLigaturesAndKerningUseActualText() throws IOException, FontFormatException, URISyntaxException {
testLigaturesAndKerning(true, "_ActualText");
}

/**
* Test ligatures and kerning
* @param useActualText
* @throws IOException
* @throws FontFormatException
* @throws URISyntaxException
*/
void testLigaturesAndKerning(boolean useActualText, String sActualText) throws IOException, FontFormatException, URISyntaxException
{
GlyphLayoutProcessorAwt glyphLayoutProcessor = new GlyphLayoutProcessorAwt();
AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions options = new AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions();
if (useActualText) {
options.useActualText();
}
GlyphLayoutProcessorAwt glyphLayoutProcessor = new GlyphLayoutProcessorAwt(options);


String outputBaseName = String.format("GlyphLayoutLigaturesAndKerning%s", sActualText);
String outputPDFFilename = "target/" + outputBaseName + ".pdf";
String outputTextFilename = String.format("target/" + outputBaseName + ".txt");


String outputName = "GlyphLayoutLigaturesAndKerning.pdf";
String outputFilename = "target/" + outputName;
String firaPath = "/ttf/FiraCode-Regular.ttf";
String dejavuPath = "/ttf/DejaVuSans.ttf"; // ligatures not in Liberation nor in Arimo
String thaiPath = "/ttf/NotoSansThai-Regular.ttf";
Expand Down Expand Up @@ -166,9 +214,33 @@ void testLigaturesAndKerning() throws IOException, FontFormatException, URISynta
cs.lineTo(x + f4, 676);
cs.stroke();
}
doc.save(outputFilename);
doc.save(outputPDFFilename);
}

checkRenderIdent(outputBaseName + ".pdf");

// Extract text
try (PDDocument doc = Loader.loadPDF(new File(outputPDFFilename)))
{
assertEquals(1, doc.getNumberOfPages());

PDFTextStripper stripper = new PDFTextStripper();
String s = stripper.getText(doc);
try (OutputStream os = new FileOutputStream(outputTextFilename))
{
os.write (0xEF);
os.write (0xBB);
os.write (0xBF);

try (Writer writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)))
{
//TODO compare this output with the input, like in TextStripper test
// Not yet correct as of 4.7.2026
writer.write(s);
}
}
}
checkRenderIdent(outputName);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
Expand All @@ -46,7 +49,10 @@ void checkRenderIdent(String outputName) throws IOException, URISyntaxException
PDFRenderer r = new PDFRenderer(doc);
expectedImage = r.renderImage(0);
}
try (PDDocument doc = Loader.loadPDF(new File(TestBase.class.getResource("/pdf/" + outputName).toURI())))
URL url = TestBase.class.getResource("/pdf/" + outputName);
Objects.requireNonNull(url, "Resource not found: " + outputName);

try (PDDocument doc = Loader.loadPDF(new File(url.toURI())))
{
PDFRenderer r = new PDFRenderer(doc);
actualImage = r.renderImage(0);
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class GlyphLayoutProcessorFop extends AbstractGlyphLayoutProcessor implements GlyphLayoutProcessorInterface
{

private final GlyphLayoutFontLoaderFop glyphLayoutFontLoaderFop;
private final GlyphLayoutFontLoaderFop glyphLayoutFontLoaderFop = new GlyphLayoutFontLoaderFop();

/*
Before you call GlyphMapping.doGlyphMapping to position the glyphs,
Expand All @@ -54,13 +54,22 @@ public class GlyphLayoutProcessorFop extends AbstractGlyphLayoutProcessor implem
*/
private static final float FOP_FONTSIZE_FACTOR = 1000f;

/**
* Constructs a GlyphLayoutProcessorFop with options
*
*/
public GlyphLayoutProcessorFop(AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions options)
{
super(options);
}

/**
* Constructs a GlyphLayoutProcessorFop
*
*/
public GlyphLayoutProcessorFop()
{
this.glyphLayoutFontLoaderFop = new GlyphLayoutFontLoaderFop();
super();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.pdfbox.pdmodel.AbstractGlyphLayoutProcessor;
import org.junit.jupiter.api.Test;

import org.apache.pdfbox.Loader;
Expand Down Expand Up @@ -90,14 +92,44 @@ class GlyphLayoutDin91379Test extends TestBase
+ "⁹ ⁿ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ™ ∞ ≤ ≥\n"
+ "Additional non-letters (not included in DIN 91379): – — •�";

/**
* Test, no ActualText
* @throws IOException
* @throws URISyntaxException
*/
@Test
void testGlyphLayoutDin91379NoActualText() throws IOException, URISyntaxException {
testGlyphLayoutDin91379(false, "");
}

/**
* Test with ActualText
* @throws IOException
* @throws URISyntaxException
*/
@Test
void testGlyphLayoutDin91379() throws IOException, URISyntaxException
void testGlyphLayoutDin91379UseActualText() throws IOException, URISyntaxException {
testGlyphLayoutDin91379(true, "_ActualText");
}

/**
* Test GlyphLayoutProcessorAwt with letters and sequences from DIN 91379
* @param useActualText
* @throws IOException
* @throws URISyntaxException
*/
void testGlyphLayoutDin91379(boolean useActualText, String sActualText) throws IOException, URISyntaxException
{
GlyphLayoutProcessorFop glyphLayoutProcessor = new GlyphLayoutProcessorFop();
AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions options = new AbstractGlyphLayoutProcessor.GlyphLayoutProcessorOptions();
if (useActualText) {
options.useActualText();
}
GlyphLayoutProcessorFop glyphLayoutProcessor = new GlyphLayoutProcessorFop(options);

String outputName = "GlyphLayoutDIN91379.pdf";
String outputName = String.format("GlyphLayoutDIN91379%s.pdf", sActualText);
String outputPDFFilename = "target/" + outputName;
String outputTextFilename = "target/GlyphLayoutDIN91379.txt";
String outputTextFilename = String.format("target/GlyphLayoutDIN91379%s.txt", sActualText);

float fontSize = 12.0f;

try (PDDocument doc = new PDDocument())
Expand Down Expand Up @@ -132,7 +164,7 @@ void testGlyphLayoutDin91379() throws IOException, URISyntaxException
os.write (0xBB);
os.write (0xBF);

try (Writer writer = new BufferedWriter(new OutputStreamWriter(os, "utf-8")))
try (Writer writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)))
{
//TODO compare this output with the input, like in TextStripper test
// Not yet correct as of 4.7.2026
Expand All @@ -157,7 +189,7 @@ private void showComposites(PDPageContentStream cs, PDType0Font font, float font
if (!line.isEmpty())
{
showCompositesLine(cs, font, fontSize, x, y, line);
y -= fontSize * 1.5;
y -= fontSize * 1.5f;
}
}
}
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ public final class COSName extends COSBase implements Comparable<COSName>
public static final COSName SORT = getPDFName("Sort");
public static final COSName SOUND = getPDFName("Sound");
public static final COSName SPLIT = getPDFName("Split");
public static final COSName SPAN = getPDFName("Span");
public static final COSName SS = getPDFName("SS");
public static final COSName ST = getPDFName("St");
public static final COSName STANDARD_ENCODING = getPDFName("StandardEncoding");
Expand Down
Loading