"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PlainText.java" between
pdfbox-2.0.23-src.zip and pdfbox-2.0.24-src.zip

About: Apache PDFBox is a Java PDF library tool that allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents.

PlainText.java  (pdfbox-2.0.23-src):PlainText.java  (pdfbox-2.0.24-src)
skipping to change at line 24 skipping to change at line 24
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.pdfbox.pdmodel.interactive.form; package org.apache.pdfbox.pdmodel.interactive.form;
import java.io.IOException; import java.io.IOException;
import java.text.AttributedString; import java.text.AttributedString;
import java.text.BreakIterator; import java.text.BreakIterator;
import java.text.AttributedCharacterIterator.Attribute; import java.text.AttributedCharacterIterator.Attribute;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.font.PDFont;
/** /**
* A block of text. * A block of text.
* <p> * <p>
* A block of text can contain multiple paragraphs which will * A block of text can contain multiple paragraphs which will
* be treated individually within the block placement. * be treated individually within the block placement.
* </p> * </p>
skipping to change at line 54 skipping to change at line 53
* Construct the text block from a single value. * Construct the text block from a single value.
* *
* Constructs the text block from a single value splitting * Constructs the text block from a single value splitting
* into individual {@link Paragraph} when a new line character is * into individual {@link Paragraph} when a new line character is
* encountered. * encountered.
* *
* @param textValue the text block string. * @param textValue the text block string.
*/ */
PlainText(String textValue) PlainText(String textValue)
{ {
paragraphs = new ArrayList<Paragraph>(); if (textValue.isEmpty())
if (textValue.isEmpty()) { {
paragraphs = new ArrayList<Paragraph>(1);
paragraphs.add(new Paragraph("")); paragraphs.add(new Paragraph(""));
} }
else else
{ {
List<String> parts = Arrays.asList(textValue.replaceAll("\t", " ").s String[] parts = textValue.replace('\t', ' ').split("\\r\\n|\\n|\\r|
plit("\\r\\n|\\n|\\r|\\u2028|\\u2029")); \\u2028|\\u2029");
paragraphs = new ArrayList<Paragraph>(parts.length);
for (String part : parts) for (String part : parts)
{ {
// Acrobat prints a space for an empty paragraph // Acrobat prints a space for an empty paragraph
if (part.length() == 0) if (part.length() == 0)
{ {
part = " "; part = " ";
} }
paragraphs.add(new Paragraph(part)); paragraphs.add(new Paragraph(part));
} }
} }
skipping to change at line 264 skipping to change at line 265
void setWidth(float width) void setWidth(float width)
{ {
lineWidth = width; lineWidth = width;
} }
float calculateWidth(PDFont font, float fontSize) throws IOException float calculateWidth(PDFont font, float fontSize) throws IOException
{ {
final float scale = fontSize/FONTSCALE; final float scale = fontSize/FONTSCALE;
float calculatedWidth = 0f; float calculatedWidth = 0f;
int indexOfWord = 0;
for (Word word : words) for (Word word : words)
{ {
calculatedWidth = calculatedWidth + calculatedWidth = calculatedWidth +
(Float) word.getAttributes().getIterator().getAttribute( TextAttribute.WIDTH); (Float) word.getAttributes().getIterator().getAttribute( TextAttribute.WIDTH);
String text = word.getText(); String text = word.getText();
if (words.indexOf(word) == words.size() -1 && Character.isWhites pace(text.charAt(text.length()-1))) if (indexOfWord == words.size() -1 && Character.isWhitespace(tex t.charAt(text.length()-1)))
{ {
float whitespaceWidth = font.getStringWidth(text.substring(t ext.length()-1)) * scale; float whitespaceWidth = font.getStringWidth(text.substring(t ext.length()-1)) * scale;
calculatedWidth = calculatedWidth - whitespaceWidth; calculatedWidth = calculatedWidth - whitespaceWidth;
} }
++indexOfWord;
} }
return calculatedWidth; return calculatedWidth;
} }
List<Word> getWords() List<Word> getWords()
{ {
return words; return words;
} }
float getInterWordSpacing(float width) float getInterWordSpacing(float width)
 End of changes. 6 change blocks. 
6 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)