Skip to content

Commit

Permalink
PDFBOX-5869: replace tabs
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1919959 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Aug 17, 2024
1 parent bb9d6f2 commit dcac369
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public static void main(String[] args) throws IOException, TransformerException
//
if (!font.isEmbedded())
{
throw new IllegalStateException("PDF/A compliance requires that all fonts used for"
+ " text rendering in rendering modes other than rendering mode 3 are embedded.");
throw new IllegalStateException("PDF/A compliance requires that all fonts used for"
+ " text rendering in rendering modes other than rendering mode 3 are embedded.");
}

// create a page with the message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EncodingTest
@Test
void testStandardEncoding()
{
StandardEncoding standardEncoding = StandardEncoding.INSTANCE;
StandardEncoding standardEncoding = StandardEncoding.INSTANCE;
// check some randomly chosen mappings
assertEquals(".notdef", standardEncoding.getName(0));
assertEquals("space", standardEncoding.getName(32));
Expand All @@ -38,7 +38,7 @@ void testStandardEncoding()
@Test
void testMacRomanEncoding()
{
MacRomanEncoding macRomanEncoding = MacRomanEncoding.INSTANCE;
MacRomanEncoding macRomanEncoding = MacRomanEncoding.INSTANCE;
// check some randomly chosen mappings
assertEquals(".notdef", macRomanEncoding.getName(0));
assertEquals("space", macRomanEncoding.getName(32));
Expand Down
2 changes: 1 addition & 1 deletion pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public final void setToNull()
@Override
public String toString()
{
return "COSObject{" + getKey() + "}";
return "COSObject{" + getKey() + "}";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,11 @@ private boolean validateStreamLength(long streamLength) throws IOException

protected BruteForceParser getBruteForceParser() throws IOException
{
if (bruteForceParser == null)
{
if (bruteForceParser == null)
{
bruteForceParser = new BruteForceParser(document, this);
}
return bruteForceParser;
return bruteForceParser;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,16 +967,16 @@ private String richContentsToString(Node node, boolean root)
}
else if (child instanceof CDATASection)
{
sb.append("<![CDATA[").append(((CDATASection) child).getData()).append("]]>");
sb.append("<![CDATA[").append(((CDATASection) child).getData()).append("]]>");
}
else if (child instanceof Text)
{
String cdata = ((Text) child).getData();
if (cdata!=null)
{
cdata = cdata.replace("&", "&amp;").replace("<", "&lt;");
}
sb.append(cdata);
String cdata = ((Text) child).getData();
if (cdata!=null)
{
cdata = cdata.replace("&", "&amp;").replace("<", "&lt;");
}
sb.append(cdata);
}
}
if (root)
Expand All @@ -992,7 +992,7 @@ else if (child instanceof Text)
String attributeNodeValue = attribute.getNodeValue();
if (attributeNodeValue!=null)
{
attributeNodeValue = attributeNodeValue.replace("\"", "&quot;");
attributeNodeValue = attributeNodeValue.replace("\"", "&quot;");
}
builder.append(String.format(" %s=\"%s\"", attribute.getNodeName(),
attributeNodeValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ private static Map<COSName, BlendMode> createBlendModeMap()
*/
private BlendMode(COSName name, BlendChannelFunction blendChannel, BlendFunction blend)
{
this.name = name;
this.blendChannel = blendChannel;
this.name = name;
this.blendChannel = blendChannel;
this.blend = blend;
isSeparable = blendChannel != null;
}
Expand All @@ -213,7 +213,7 @@ private BlendMode(COSName name, BlendChannelFunction blendChannel, BlendFunction
*/
public COSName getCOSName()
{
return name;
return name;
}

/**
Expand Down Expand Up @@ -264,15 +264,15 @@ else if (cosBlendMode instanceof COSArray)
COSArray cosBlendModeArray = (COSArray) cosBlendMode;
for (int i = 0; i < cosBlendModeArray.size(); i++)
{
COSBase cosBase = cosBlendModeArray.getObject(i);
if (cosBase instanceof COSName)
{
COSBase cosBase = cosBlendModeArray.getObject(i);
if (cosBase instanceof COSName)
{
result = BLEND_MODES.get(cosBase);
if (result != null)
{
break;
}
}
}
}
}
return result != null ? result : BlendMode.NORMAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static ICC_Profile ensureDisplayProfile(ICC_Profile profile)
if (profileData[ICC_Profile.icHdrRenderingIntent] == ICC_Profile.icPerceptual)
{
LOG.warn("ICC profile is Perceptual, ignoring, treating as Display class");
intToBigEndian(ICC_Profile.icSigDisplayClass, profileData, ICC_Profile.icHdrDeviceClass);
intToBigEndian(ICC_Profile.icSigDisplayClass, profileData, ICC_Profile.icHdrDeviceClass);
return ICC_Profile.getInstance(profileData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Paint toPaint(Matrix matrix)
List<ShadedTriangle> collectTriangles(AffineTransform xform, Matrix matrix)
throws IOException
{
int bitsPerFlag = getBitsPerFlag();
int bitsPerFlag = getBitsPerFlag();
COSDictionary dict = getCOSObject();
if (!(dict instanceof COSStream))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,14 @@ private boolean overlaps(Point2D p0, Point2D p1)
{
return Math.abs(p0.getX() - p1.getX()) < 0.001 && Math.abs(p0.getY() - p1.getY()) < 0.001;
}

static Point2D[] clonedPoint2DArray(Point2D[] input)
{
Point2D[] cloned = new Point2D[input.length];
for (int i = 0; i < input.length; ++i)
{
cloned[i] = (Point2D) input[i].clone();
}
return cloned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void format() throws IOException
if (textContent != null && !textContent.getParagraphs().isEmpty())
{
boolean isFirstParagraph = true;
for (Paragraph paragraph : textContent.getParagraphs())
for (Paragraph paragraph : textContent.getParagraphs())
{
if (wrapLines)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void characterNUL() throws IOException
void characterTAB() throws IOException
{
PDField field = acroForm.getField("pdfbox-tab");
field.setValue("TAB\tTAB");
field.setValue("TAB\tTAB");

List<String> pdfboxValues = getStringsFromStream(field);
pdfboxValues.forEach(token -> assertEquals("TAB", token));
Expand Down Expand Up @@ -131,12 +131,12 @@ public void tearDown() throws IOException

private List<String> getStringsFromStream(PDField field) throws IOException
{
PDAnnotationWidget widget = field.getWidgets().get(0);
PDAnnotationWidget widget = field.getWidgets().get(0);
PDFStreamParser parser = new PDFStreamParser(
widget.getNormalAppearanceStream());
List<Object> tokens = parser.parse();
// TODO: improve the string output to better match
// trimming as Acrobat adds spaces to strings
// where we don't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ void testMultilineBreak() throws IOException

private float getFontSizeFromAppearanceStream(PDField field) throws IOException
{
PDAnnotationWidget widget = field.getWidgets().get(0);
PDAnnotationWidget widget = field.getWidgets().get(0);
PDFStreamParser parser = new PDFStreamParser(widget.getNormalAppearanceStream());
Object token = parser.parseNextToken();
while (token != null)
{
Object token = parser.parseNextToken();
while (token != null)
{
if (token instanceof COSName && ((COSName) token).getName().equals("Helv"))
{
{
token = parser.parseNextToken();
if (token instanceof COSNumber)
{
Expand All @@ -184,17 +184,17 @@ private float getFontSizeFromAppearanceStream(PDField field) throws IOException

private List<String> getTextLinesFromAppearanceStream(PDField field) throws IOException
{
PDAnnotationWidget widget = field.getWidgets().get(0);
PDAnnotationWidget widget = field.getWidgets().get(0);
PDFStreamParser parser = new PDFStreamParser(widget.getNormalAppearanceStream());
Object token = parser.parseNextToken();

List<String> lines = new ArrayList<>();
while (token != null)
{
while (token != null)
{
if (token instanceof COSString)
{
{
lines.add(((COSString) token).getString());
}
token = parser.parseNextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ class PlainTextTest
@Test
void characterCR()
{
PlainText text = new PlainText("CR\rCR");
assertEquals(2,text.getParagraphs().size());
PlainText text = new PlainText("CR\rCR");
assertEquals(2,text.getParagraphs().size());
}

@Test
void characterLF()
{
PlainText text = new PlainText("LF\nLF");
assertEquals(2,text.getParagraphs().size());
PlainText text = new PlainText("LF\nLF");
assertEquals(2,text.getParagraphs().size());
}

@Test
void characterCRLF()
{
PlainText text = new PlainText("CRLF\r\nCRLF");
assertEquals(2,text.getParagraphs().size());
PlainText text = new PlainText("CRLF\r\nCRLF");
assertEquals(2,text.getParagraphs().size());
}

@Test
void characterLFCR()
{
PlainText text = new PlainText("LFCR\n\rLFCR");
assertEquals(3,text.getParagraphs().size());
PlainText text = new PlainText("LFCR\n\rLFCR");
assertEquals(3,text.getParagraphs().size());
}

@Test
void characterUnicodeLinebreak()
{
PlainText text = new PlainText("linebreak\u2028linebreak");
assertEquals(2,text.getParagraphs().size());
PlainText text = new PlainText("linebreak\u2028linebreak");
assertEquals(2,text.getParagraphs().size());
}

@Test
void characterUnicodeParagraphbreak()
{
PlainText text = new PlainText("paragraphbreak\u2029paragraphbreak");
assertEquals(2,text.getParagraphs().size());
PlainText text = new PlainText("paragraphbreak\u2029paragraphbreak");
assertEquals(2,text.getParagraphs().size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
/*
* to be used at runtime
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
18 changes: 9 additions & 9 deletions xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,11 @@ else if ((ln != null) && !(ln.equals(element.getLocalName())))
*/
private void removeComments(Node root)
{
// will hold the nodes which are to be deleted
List<Node> forDeletion = new ArrayList<>();
NodeList nl = root.getChildNodes();
// will hold the nodes which are to be deleted
List<Node> forDeletion = new ArrayList<>();
NodeList nl = root.getChildNodes();
if (nl.getLength()<=1)
{
// There is only one node so we do not remove it
Expand All @@ -864,15 +864,15 @@ private void removeComments(Node root)
if (node instanceof Comment)
{
// comments to be deleted
forDeletion.add(node);
forDeletion.add(node);
}
else if (node instanceof Text)
{
if (node.getTextContent().trim().isEmpty())
{
// TODO: verify why this is necessary
// empty text nodes to be deleted
forDeletion.add(node);
// TODO: verify why this is necessary
// empty text nodes to be deleted
forDeletion.add(node);
}
}
else if (node instanceof Element)
Expand Down

0 comments on commit dcac369

Please sign in to comment.