You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2015/12/04 20:04:53 UTC
svn commit: r1718008 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainTextFormatter.java
Author: msahyoun
Date: Fri Dec 4 19:04:53 2015
New Revision: 1718008
URL: http://svn.apache.org/viewvc?rev=1718008&view=rev
Log:
PDFBOX-3148: correct appearance generation for multiple paragraphs
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainTextFormatter.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainTextFormatter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainTextFormatter.java?rev=1718008&r1=1718007&r2=1718008&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainTextFormatter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainTextFormatter.java Fri Dec 4 19:04:53 2015
@@ -174,7 +174,8 @@ class PlainTextFormatter
{
if (textContent != null && !textContent.getParagraphs().isEmpty())
{
- for (Paragraph paragraph : textContent.getParagraphs())
+ boolean isFirstParagraph = true;
+ for (Paragraph paragraph : textContent.getParagraphs())
{
if (wrapLines)
{
@@ -183,7 +184,8 @@ class PlainTextFormatter
appearanceStyle.getFontSize(),
width
);
- processLines(lines);
+ processLines(lines, isFirstParagraph);
+ isFirstParagraph = false;
}
else
{
@@ -225,14 +227,14 @@ class PlainTextFormatter
* @param lines the lines to process.
* @throws IOException if there is an error writing to the stream.
*/
- private void processLines(List<Line> lines) throws IOException
+ private void processLines(List<Line> lines, boolean isFirstParagraph) throws IOException
{
float wordWidth = 0f;
float lastPos = 0f;
float startOffset = 0f;
float interWordSpacing = 0f;
-
+
for (Line line : lines)
{
switch (textAlignment)
@@ -255,19 +257,19 @@ class PlainTextFormatter
float offset = -lastPos + startOffset + horizontalOffset;
- if (lines.indexOf(line) == 0)
+ if (lines.indexOf(line) == 0 && isFirstParagraph)
{
contents.newLineAtOffset(offset, verticalOffset);
- // reset the initial verticalOffset
- verticalOffset = 0f;
+ // reset the initial horizontalOffset
horizontalOffset = 0f;
}
else
{
// keep the last position
verticalOffset = verticalOffset - appearanceStyle.getLeading();
- contents.newLineAtOffset(offset, -appearanceStyle.getLeading());
+ contents.newLineAtOffset(offset, - appearanceStyle.getLeading());
}
+
lastPos = startOffset;
List<Word> words = line.getWords();