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 2014/11/03 11:23:12 UTC
svn commit: r1636305 - in /pdfbox/branches/1.8/pdfbox: ./
src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java
Author: msahyoun
Date: Mon Nov 3 10:23:12 2014
New Revision: 1636305
URL: http://svn.apache.org/r1636305
Log:
PDFBOX-1036 Always regenerate text in appearance stream.
Modified:
pdfbox/branches/1.8/pdfbox/ (props changed)
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java
Propchange: pdfbox/branches/1.8/pdfbox/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Nov 3 10:23:12 2014
@@ -5,3 +5,7 @@ tools
external
bin
+
+pdfbox-eclipse-formatter.xml
+
+pdfbox-checkstyle-5.xml
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java?rev=1636305&r1=1636304&r2=1636305&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java Mon Nov 3 10:23:12 2014
@@ -356,80 +356,31 @@ public class PDAppearance
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
ContentStreamWriter writer = new ContentStreamWriter(output);
- float fontSize = calculateFontSize(pdFont, appearanceStream.getBoundingBox(), tokens, null);
+ float fontSize = calculateFontSize(pdFont, appearanceStream.getBoundingBox(), tokens, daTokens);
boolean foundString = false;
int indexOfString = -1;
- // Don't replace the string content of the
- // current appearance stream value for a choice list PDFBOX-2249
- // and if the comb flag is set PDFBOX-91
- // TODO: Shall be addressed properly in a future release
- if (parent instanceof PDChoiceField || parent.shouldComb())
+ int setFontIndex = tokens.indexOf(PDFOperator.getOperator("Tf"));
+ tokens.set(setFontIndex - 1, new COSFloat(fontSize));
+
+ int bmcIndex = tokens.indexOf(PDFOperator.getOperator("BMC"));
+ int emcIndex = tokens.indexOf(PDFOperator.getOperator("EMC"));
+
+ if (bmcIndex != -1)
{
- // Nothing to do here
- // enforces
+ writer.writeTokens(tokens, 0, bmcIndex + 1);
}
else
{
- // This part works only in certain circumstances
- // retained for the moment for compatibility
- // TODO: handle properly in a future release
- //
- for (int i = 0; i < tokens.size(); i++)
- {
- Object token = tokens.get(i);
- if (token instanceof COSString)
- {
- foundString = true;
- indexOfString = tokens.indexOf(token);
- COSString drawnString = ((COSString) token);
- drawnString.reset();
- drawnString.append(apValue.getBytes("ISO-8859-1"));
- // replace the first string only if the appearance stream
- // consists of more than one text
- break;
- }
- }
+ writer.writeTokens(tokens);
}
-
- int setFontIndex = tokens.indexOf(PDFOperator.getOperator("Tf"));
- tokens.set(setFontIndex - 1, new COSFloat(fontSize));
- if (foundString)
+ output.write("\n".getBytes("ISO-8859-1"));
+ insertGeneratedAppearance(widget, output, pdFont, tokens, appearanceStream);
+ if (emcIndex != -1)
{
- int indexOfET = tokens.indexOf(PDFOperator.getOperator("ET"));
- // the existing appearance stream may contain more than one text
- // so that we shall replace the first with the new value
- // and skip the remaining parts
- if (indexOfString+2 != indexOfET)
- {
- writer.writeTokens(tokens, 0, indexOfString+2);
- writer.writeTokens(tokens, indexOfET, tokens.size());
- }
- else
- {
- writer.writeTokens(tokens);
- }
+ writer.writeTokens(tokens, emcIndex, tokens.size());
}
- else
- {
- int bmcIndex = tokens.indexOf(PDFOperator.getOperator("BMC"));
- int emcIndex = tokens.indexOf(PDFOperator.getOperator("EMC"));
- if (bmcIndex != -1)
- {
- writer.writeTokens(tokens, 0, bmcIndex + 1);
- }
- else
- {
- writer.writeTokens(tokens);
- }
- output.write("\n".getBytes("ISO-8859-1"));
- insertGeneratedAppearance(widget, output, pdFont, tokens, appearanceStream);
- if (emcIndex != -1)
- {
- writer.writeTokens(tokens, emcIndex, tokens.size());
- }
- }
writeToStream(output.toByteArray(), appearanceStream);
}
else
@@ -578,7 +529,7 @@ public class PDAppearance
if (parent.shouldComb()) {
insertGeneratedPaddingEdge(printWriter, appearanceStream);
}
-
+
printWriter.println("BT");
if (defaultAppearance != null)
@@ -680,7 +631,8 @@ public class PDAppearance
float combWidth = appearanceStream.getBoundingBox().getWidth() / maxLen;
float ascentAtFontSize = pdFont.getFontDescriptor().getAscent() / 1000 * fontSize;
- float baselineOffset = paddingEdge.getLowerLeftY() + (appearanceStream.getBoundingBox().getHeight() - ascentAtFontSize)/2;
+ float baselineOffset = paddingEdge.getLowerLeftY() +
+ (appearanceStream.getBoundingBox().getHeight() - ascentAtFontSize)/2;
float prevCharWidth = 0f;
float currCharWidth = 0f;
@@ -952,16 +904,7 @@ public class PDAppearance
throws IOException
{
float fontSize = 0;
- if (tokens != null)
- {
- // reuse the fontsize of an existing apperance stream
- int fontIndex = tokens.indexOf(PDFOperator.getOperator("Tf"));
- if (fontIndex != -1)
- {
- fontSize = ((COSNumber) tokens.get(fontIndex - 1)).floatValue();
- }
- }
- else if (daTokens != null)
+ if (daTokens != null)
{
// daString looks like "BMC /Helv 3.4 Tf EMC"
// use the fontsize of the default existing apperance stream
@@ -971,7 +914,9 @@ public class PDAppearance
fontSize = ((COSNumber) daTokens.get(fontIndex - 1)).floatValue();
}
}
-
+
+ System.out.println(fontSize + " " + daTokens);
+
float widthBasedFontSize = Float.MAX_VALUE;
if (parent.doNotScroll())
@@ -988,7 +933,7 @@ public class PDAppearance
float height = 0;
if (pdFont instanceof PDSimpleFont)
{
- height = ((PDSimpleFont) pdFont).getFontDescriptor().getFontBoundingBox().getHeight();
+ height = ((PDSimpleFont) pdFont).getFontBoundingBox().getHeight();
}
else
{