aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2011-02-15 17:24:23 +0000
committerpdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2011-02-15 17:24:23 +0000
commit5b2afac565a29266ef60c4e3039b8258712210f9 (patch)
tree87b274f0c5ec2504dd51c2999b0651bd55d7d7b9 /src
parentcce6fc95852a1c2d8dae1b00704be7e0d5389b38 (diff)
downloadpdf-as-3-5b2afac565a29266ef60c4e3039b8258712210f9.tar.gz
pdf-as-3-5b2afac565a29266ef60c4e3039b8258712210f9.tar.bz2
pdf-as-3-5b2afac565a29266ef60c4e3039b8258712210f9.zip
improved link overlay positioning
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@758 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java
index 220f9b7..a754b8e 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java
@@ -1,6 +1,8 @@
package at.knowcenter.wag.egov.egiz.pdf;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.log4j.Logger;
@@ -23,6 +25,7 @@ import com.lowagie.text.pdf.PdfString;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdfas.StructContentWriter;
import com.lowagie.text.pdfas.StructContentWriterHolder;
+import com.lowagie.text.pdfas.UrlInTextFinder;
/**
* Helper class for writing the structure hierarchy of the signature elements.
@@ -408,7 +411,17 @@ public class StructContentHelper implements StructContentWriter {
*/
public void storeCurrentPosAsLink() {
this.verifyLinkPos = new Rectangle(this.tempMarkedPos);
- }
+ }
+
+ private Map tmpMap = new HashMap();
+ public void putVal(String key, Object val) {
+ tmpMap.put(key, val);
+ }
+
+ private Map linkPosMap;
+ public void storeVals() {
+ linkPosMap = new HashMap(tmpMap);
+ }
/**
* set explicit annotation tab order if missing
@@ -450,7 +463,7 @@ public class StructContentHelper implements StructContentWriter {
// iText "converts" 0.0f to an integer, therefore we cannot use 0, not nice...
//linkAnnot.put(PdfName.RECT, new PdfArray(new float[] {0.01f, 0.01f, 0.01f, 0.01f}));
// take cell pos as link pos
- linkAnnot.put(PdfName.RECT, new PdfArray(createAbsPos(atp, this.verifyLinkPos)));
+ linkAnnot.put(PdfName.RECT, new PdfArray(calcLinkPos(atp, this.verifyLinkPos)));
linkAnnot.put(PdfName.STRUCTPARENT, structParentNr);
linkAnnot.put(PdfName.SUBTYPE, PdfName.LINK);
@@ -459,15 +472,31 @@ public class StructContentHelper implements StructContentWriter {
}
- private static PdfArray createAbsPos(ActualTablePos atp, Rectangle pos) {
+ private PdfArray calcLinkPos(ActualTablePos atp, Rectangle pos) {
PdfArray res = new PdfArray();
- float y = atp.y - atp.height + pos.getTop();
- res.add(new PdfNumber(atp.x + pos.getLeft()));
- res.add(new PdfNumber(y));
- res.add(new PdfNumber(atp.x + pos.getLeft() + pos.getWidth()));
- res.add(new PdfNumber(y - pos.getHeight()));
+ float downY = atp.y - atp.height + pos.getTop() - pos.getHeight();
+
+ float startX = atp.x + pos.getLeft();
+ float yLine = getPosMapVal("yLine");
+ float lineHigh = getPosMapVal("maxSize");;
+ float lineWidth = getPosMapVal("lineWidth");
+ UrlInTextFinder finder = (UrlInTextFinder) this.linkPosMap.get("urlFinder");
+
+ // maybe one could calc the link pos even more exactly with char with counting
+ // but this should be close enough (see BidiLine.processLine and chung.getcharwith)
+ float lineCorr = -2;
+ float xCorr = 2;
+ res.add(new PdfNumber(xCorr +startX + finder.calcLinkPosXStart(lineWidth)));
+ res.add(new PdfNumber(downY + yLine + lineHigh + lineCorr));
+ res.add(new PdfNumber(xCorr + startX + finder.calcLinkPosXEnd(lineWidth)));
+ res.add(new PdfNumber(downY + yLine + lineCorr));
+
return res;
}
+
+ private float getPosMapVal(String key) {
+ return ((Float) this.linkPosMap.get(key)).floatValue();
+ }
protected static PdfArray createPdfArrayFromTablePos(ActualTablePos pos) {
return new PdfArray( new float[] {pos.x, pos.y, pos.x + pos.width, pos.y - pos.height});
@@ -645,6 +674,4 @@ public class StructContentHelper implements StructContentWriter {
return AdobeSignatureHelper.getDefaultableConfigProperty(sigProfile, ALT_TEXT_CONF_KEY, ALT_TEXT_DEFAULT);
}
-
-
}