Skip to content

Commit

Permalink
PDFBOX-1529: refactor to prepare for lineHeight
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922737 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 29, 2024
1 parent 5568978 commit c83380b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ public void createPDFFromText( PDDocument doc, Reader text ) throws IOException
font = new PDType1Font(standardFont);
}
final int margin = 40;
float height = font.getBoundingBox().getHeight() / FONTSCALE;
float fontHeight = font.getBoundingBox().getHeight() / FONTSCALE;
PDRectangle actualMediaBox =
landscape ? new PDRectangle(mediaBox.getHeight(), mediaBox.getWidth()) : mediaBox;

//calculate font height and increase by a factor.
height = height * fontSize * LINE_HEIGHT_FACTOR;
// calculate line height and increase by a factor.
float lineHeight = fontHeight * fontSize * LINE_HEIGHT_FACTOR;
BufferedReader data = new BufferedReader(text);
String nextLine;
PDPage page = new PDPage(actualMediaBox);
Expand Down Expand Up @@ -344,16 +344,16 @@ public void createPDFFromText( PDDocument doc, Reader text ) throws IOException
contentStream = new PDPageContentStream(doc, page);
contentStream.setFont(font, fontSize);
contentStream.beginText();
y = page.getMediaBox().getHeight() - margin + height;
y = page.getMediaBox().getHeight() - margin + lineHeight;
contentStream.newLineAtOffset(margin, y);
}

if (contentStream == null)
{
throw new IOException("Error:Expected non-null content stream.");
}
contentStream.newLineAtOffset(0, -height);
y -= height;
contentStream.newLineAtOffset(0, -lineHeight);
y -= lineHeight;
contentStream.showText(nextLineToDraw.toString());
if (ff)
{
Expand All @@ -364,7 +364,7 @@ public void createPDFFromText( PDDocument doc, Reader text ) throws IOException
contentStream = new PDPageContentStream(doc, page);
contentStream.setFont(font, fontSize);
contentStream.beginText();
y = page.getMediaBox().getHeight() - margin + height;
y = page.getMediaBox().getHeight() - margin + lineHeight;
contentStream.newLineAtOffset(margin, y);
}
}
Expand Down

0 comments on commit c83380b

Please sign in to comment.