View | Details | Raw Unified | Return to bug 46980
Collapse All | Expand All

(-)src/java/org/apache/fop/pdf/PDFFactory.java (-16 / +29 lines)
Lines 1082-1097 Link Here
1082
        } else if (targetLo.endsWith(".pdf")) {
1082
        } else if (targetLo.endsWith(".pdf")) {
1083
            // Bare PDF file name?
1083
            // Bare PDF file name?
1084
            return getGoToPDFAction(target, null, -1, newWindow);
1084
            return getGoToPDFAction(target, null, -1, newWindow);
1085
        } else if ((index = targetLo.indexOf(".pdf#page=")) > 0) { // CSOK: InnerAssignment
1085
        } else if ((index = targetLo.indexOf(".pdf#")) > 0) { // CSOK: InnerAssignment
1086
            // PDF file + page?
1087
            String filename = target.substring(0, index + 4);
1086
            String filename = target.substring(0, index + 4);
1088
            int page = Integer.parseInt(target.substring(index + 10));
1087
            String tmp = targetLo.substring(index + 5, index + 10);
1089
            return getGoToPDFAction(filename, null, page, newWindow);
1088
            int page = -1;
1090
        } else if ((index = targetLo.indexOf(".pdf#dest=")) > 0) { // CSOK: InnerAssignment
1089
            String dest = null;
1091
            // PDF file + destination?
1090
            if ("page=".equals(tmp)) {
1092
            String filename = target.substring(0, index + 4);
1091
                // PDF file + page?
1093
            String dest = target.substring(index + 10);
1092
                page = Integer.parseInt(target.substring(index + 10));
1094
            return getGoToPDFAction(filename, dest, -1, newWindow);
1093
            } else {
1094
                // PDF file + named destination?
1095
                dest = target.substring(index + ("dest=".equals(tmp) ? 10 : 5));
1096
            }
1097
            return getGoToPDFAction(filename, dest, page, newWindow);
1098
        } else if (target.startsWith("#")) {
1099
            //actually an _internal_ named destination
1100
            return getPDFGoTo(target.substring(1), true, null);
1095
        } else {
1101
        } else {
1096
            // None of the above? Default to URI:
1102
            // None of the above? Default to URI:
1097
            return new PDFUri(target);
1103
            return new PDFUri(target);
Lines 1159-1183 Link Here
1159
     * @return the GoTo's object reference
1165
     * @return the GoTo's object reference
1160
     */
1166
     */
1161
    public String getGoToReference(String pdfPageRef, float yoffset) {
1167
    public String getGoToReference(String pdfPageRef, float yoffset) {
1162
        return getPDFGoTo(pdfPageRef, new Point2D.Float(0.0f, yoffset)).referencePDF();
1168
        return getPDFGoTo(pdfPageRef, false, new Point2D.Float(0.0f, yoffset)).referencePDF();
1163
    }
1169
    }
1164
1170
1165
    /**
1171
    /**
1166
     * Finds and returns a PDFGoTo to the given page and position.
1172
     * Finds and returns a PDFGoTo to the given page and position.
1167
     * Creates the PDFGoTo if not found.
1173
     * Creates the PDFGoTo if not found.
1168
     *
1174
     *
1169
     * @param pdfPageRef the PDF page reference
1175
     * @param pdfDestinationRef    the PDF destination reference
1170
     * @param position the (X,Y) position in points
1176
     * @param isNamedDestination   indicates whether the destination reference is a
1177
     *                             named destination (if {@code true}, the position
1178
     *                             parameter is ignored)
1179
     * @param position             the (X,Y) position in points
1171
     *
1180
     *
1172
     * @return the new or existing PDFGoTo object
1181
     * @return the new or existing PDFGoTo object
1173
     */
1182
     */
1174
    public PDFGoTo getPDFGoTo(String pdfPageRef, Point2D position) {
1183
    public PDFGoTo getPDFGoTo(String pdfDestinationRef, boolean isNamedDestination, Point2D position) {
1175
        getDocument().getProfile().verifyActionAllowed();
1184
        getDocument().getProfile().verifyActionAllowed();
1176
        PDFGoTo gt = new PDFGoTo(pdfPageRef, position);
1185
        PDFGoTo gt;
1186
        if (isNamedDestination) {
1187
            gt = new PDFGoTo(pdfDestinationRef, isNamedDestination);
1188
        } else {
1189
            gt = new PDFGoTo(pdfDestinationRef, position);
1190
        }
1177
        PDFGoTo oldgt = getDocument().findGoTo(gt);
1191
        PDFGoTo oldgt = getDocument().findGoTo(gt);
1178
        if (oldgt == null) {
1192
        if (oldgt == null) {
1179
            getDocument().assignObjectNumber(gt);
1193
            getDocument().registerObject(gt);
1180
            getDocument().addTrailerObject(gt);
1181
        } else {
1194
        } else {
1182
            gt = oldgt;
1195
            gt = oldgt;
1183
        }
1196
        }
(-)src/java/org/apache/fop/pdf/PDFGoTo.java (-31 / +45 lines)
Lines 32-40 Link Here
32
     * the pageReference
32
     * the pageReference
33
     */
33
     */
34
    private String pageReference;
34
    private String pageReference;
35
    private String destination = null;
35
    private String positionDestination = null;
36
    private float xPosition = 0;
36
    private float xPosition = 0;
37
    private float yPosition = 0;
37
    private float yPosition = 0;
38
    private final String namedDestination;
38
39
39
    /**
40
    /**
40
     * create a /GoTo object.
41
     * create a /GoTo object.
Lines 44-52 Link Here
44
    public PDFGoTo(String pageReference) {
45
    public PDFGoTo(String pageReference) {
45
        super();
46
        super();
46
        setPageReference(pageReference);
47
        setPageReference(pageReference);
48
        this.namedDestination = null;
47
    }
49
    }
48
50
49
    /**
51
    /**
52
     * create a /GoTo object
53
     *
54
     * @param destinationRef        the destination reference represented by this object
55
     * @param isNamedDestination    indicates whether the destinationRef is a named destination
56
     *                              if {@code false}, the destinationRef is interpreted to
57
     *                              be a page reference
58
     */
59
    public PDFGoTo(String destinationRef, boolean isNamedDestination) {
60
        super();
61
        if (!isNamedDestination) {
62
            setPageReference(destinationRef);
63
            this.namedDestination = null;
64
        } else {
65
            this.namedDestination = destinationRef;
66
        }
67
    }
68
69
    /**
50
     * create a /GoTo object.
70
     * create a /GoTo object.
51
     *
71
     *
52
     * @param pageReference the PDF reference to the target page
72
     * @param pageReference the PDF reference to the target page
Lines 96-107 Link Here
96
    }
116
    }
97
117
98
    /**
118
    /**
99
     * Set the destination string for this Goto.
119
     * Set the positionDestination string for this Goto.
120
     * (Only has effect if it does not point to a named positionDestination)
100
     *
121
     *
101
     * @param dest the PDF destination string
122
     * @param dest the PDF positionDestination string
102
     */
123
     */
103
    public void setDestination(String dest) {
124
    public void setDestination(String dest) {
104
        destination = dest;
125
        this.positionDestination = dest;
105
    }
126
    }
106
127
107
    /**
128
    /**
Lines 113-128 Link Here
113
        return referencePDF();
134
        return referencePDF();
114
    }
135
    }
115
136
116
    /**
137
    /** {@inheritDoc} */
117
     * {@inheritDoc}
118
     */
119
    public String toPDFString() {
138
    public String toPDFString() {
120
        String dest;
139
        String dest = "/D ";
121
        if (destination == null) {
140
        if (this.namedDestination != null) {
122
            dest = "/D [" + this.pageReference + " /XYZ " + xPosition
141
            dest += "(" + this.namedDestination + ")";
123
                          + " " + yPosition + " null]\n";
142
        } else if (this.positionDestination != null) {
143
            dest += "[" + this.pageReference + " " + this.positionDestination + "]";
124
        } else {
144
        } else {
125
            dest = "/D [" + this.pageReference + " " + destination + "]\n";
145
            dest += "[" + this.pageReference + " /XYZ "
146
                    + this.xPosition + " " + this.yPosition + " null]";
126
        }
147
        }
127
        return getObjectID()
148
        return getObjectID()
128
                    + "<< /Type /Action\n/S /GoTo\n" + dest
149
                    + "<< /Type /Action\n/S /GoTo\n" + dest
Lines 151-178 Link Here
151
172
152
        PDFGoTo gt = (PDFGoTo)obj;
173
        PDFGoTo gt = (PDFGoTo)obj;
153
174
154
        if (gt.pageReference == null) {
175
        if (this.pageReference == null) {
155
            if (pageReference != null) {
176
            return (gt.pageReference == null
156
                return false;
177
                && gt.namedDestination != null
178
                && gt.namedDestination.equals(this.namedDestination));
179
        } else if (this.pageReference.equals(gt.pageReference)) {
180
            if (this.positionDestination == null) {
181
                return (gt.positionDestination == null
182
                        && gt.xPosition == this.xPosition
183
                        && gt.yPosition == this.yPosition);
184
            } else {
185
                return (this.positionDestination.equals(gt.positionDestination));
157
            }
186
            }
158
        } else {
159
            if (!gt.pageReference.equals(pageReference)) {
160
                return false;
161
            }
162
        }
187
        }
163
188
164
        if (destination == null) {
189
        return false;
165
            if (!(gt.destination == null && gt.xPosition == xPosition
166
                && gt.yPosition == yPosition)) {
167
                return false;
168
            }
169
        } else {
170
            if (!destination.equals(gt.destination)) {
171
                return false;
172
            }
173
        }
174
175
        return true;
176
    }
190
    }
177
}
191
}
178
192

Return to bug 46980