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 @@ -16,6 +16,7 @@
*/
package org.apache.pdfbox.pdmodel.interactive;

import org.apache.pdfbox.pdmodel.GlyphLayoutProcessorInterface;
import org.apache.pdfbox.pdmodel.font.PDFont;

/**
Expand All @@ -38,7 +39,12 @@ public class AppearanceStyle
* Defaulting to 1.2*fontSize to match Acrobats default.
*/
private float leading = 14.4f;


/**
* Glyph layout processor
*/
private GlyphLayoutProcessorInterface glyphLayoutProcessor;

/**
* Get the font used for text formatting.
*
Expand Down Expand Up @@ -99,4 +105,22 @@ public void setLeading(float leading)
{
this.leading = leading;
}

/**
*
* @param glyphLayoutProcessor
*/
public void setGlyphLayoutProcessor(GlyphLayoutProcessorInterface glyphLayoutProcessor)
{
this.glyphLayoutProcessor = glyphLayoutProcessor;
}

/**
*
* @return
*/
public GlyphLayoutProcessorInterface getGlyphLayoutProcessor()
{
return glyphLayoutProcessor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.io.IOException;
import java.util.List;

import org.apache.pdfbox.pdmodel.GlyphLayoutProcessorInterface;
import org.apache.pdfbox.pdmodel.PDAppearanceContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.interactive.PlainText.Line;
import org.apache.pdfbox.pdmodel.interactive.PlainText.Paragraph;
import org.apache.pdfbox.pdmodel.interactive.PlainText.TextAttribute;
Expand Down Expand Up @@ -246,7 +249,15 @@ private void processLines(List<Line> lines, boolean isFirstParagraph) throws IOE
for (Word word : words)
{
contents.showText(word.getText());
wordWidth = (Float) word.getAttributes().getIterator().getAttribute(TextAttribute.WIDTH);
GlyphLayoutProcessorInterface glyphLayoutProcessor = appearanceStyle.getGlyphLayoutProcessor();
PDFont font = appearanceStyle.getFont();
if (glyphLayoutProcessor == null || !glyphLayoutProcessor.supportsFont(font))
{
wordWidth = (Float) word.getAttributes().getIterator().getAttribute(TextAttribute.WIDTH);
} else {
wordWidth = glyphLayoutProcessor.getStringWidth(
(PDType0Font) font, appearanceStyle.getFontSize(), word.getText());
}
if (wordIndex != words.size() -1)
{
contents.newLineAtOffset(wordWidth + interWordSpacing, 0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,10 @@ else if (field instanceof PDListBox)
AppearanceStyle appearanceStyle = new AppearanceStyle();
appearanceStyle.setFont(font);
appearanceStyle.setFontSize(fontSize);

if (glyphLayoutProcessor != null) {
appearanceStyle.setGlyphLayoutProcessor(glyphLayoutProcessor);
}

// Adobe Acrobat uses the font's bounding box for the leading between the lines
appearanceStyle.setLeading(font.getBoundingBox().getHeight() * fontScaleY);

Expand Down