aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/pdf/PDFGoTo.java
blob: 0a9042b91971b595780768ce4d0d290cbc2e0505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * $Id$
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.pdf;

/**
 * class representing a /GoTo object.
 *
 */
public class PDFGoTo extends PDFAction {

    /**
     * the pageReference
     */
    protected String pageReference;
    protected String destination = null;
    protected float xPosition = 0, yPosition = 0;

    /**
     * create a /GoTo object.
     *
     * @param number the object's number
     * @param pageReference the pageReference represented by this object
     */
    public PDFGoTo(int number, String pageReference) {

        /* generic creation of object */
        super(number);

        this.pageReference = pageReference;
    }


    /**
     * Sets page reference after object has been created
     *
     * @param pageReference
     * the new page reference to use
     */
    public void setPageReference(String pageReference) {
        this.pageReference = pageReference;
    }



    /**
     * Sets the Y position to jump to
     *
     * @param yPosition y position
     */
    public void setYPosition(float yPosition) {
        this.yPosition = yPosition;
    }

    public void setDestination(String dest) {
        destination = dest;
    }

    /**
     * Sets the x Position to jump to
     *
     * @param xPosition x position
     */
    public void setXPosition(int xPosition) {
        this.xPosition = (xPosition / 1000f);
    }

    public String getAction() {
        return referencePDF();
    }


    /**
     * represent the object in PDF
     *
     * @return the PDF string
     */
    public byte[] toPDF() {
        if(destination == null) {
            destination = "/D ["
                              + this.pageReference + " /XYZ " + xPosition
                              + " " + yPosition + " null]\n";
        } else {
            destination = "/D ["
                              + this.pageReference + " " + destination + "]\n";
        }
        String p = new String(this.number + " " + this.generation
                              + " obj\n<<\n/S /GoTo\n" + destination
                              + ">>\nendobj\n");
        return p.getBytes();
    }

    /*
     * example
     * 29 0 obj
     * <<
     * /S /GoTo
     * /D [23 0 R /FitH 600]
     * >>
     * endobj
     */
}