001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: PDFLink.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.pdf;
021:
022: // Java
023: import java.awt.geom.Rectangle2D;
024:
025: /**
026: * class representing an /Annot object of /Subtype /Link
027: */
028: public class PDFLink extends PDFObject {
029: /**
030: * Used to represent an external link.
031: */
032: public static final int EXTERNAL = 0;
033:
034: /**
035: * Used to represent an internal link.
036: */
037: public static final int INTERNAL = 1;
038:
039: private float ulx;
040: private float uly;
041: private float brx;
042: private float bry;
043: private String color;
044: private PDFAction action;
045:
046: /**
047: * create objects associated with a link annotation (GoToR)
048: *
049: * @param r the rectangle of the link hotspot in absolute coordinates
050: */
051: public PDFLink(Rectangle2D r) {
052: /* generic creation of PDF object */
053: super ();
054:
055: this .ulx = (float) r.getX();
056: this .uly = (float) r.getY();
057: this .brx = (float) (r.getX() + r.getWidth());
058: this .bry = (float) (r.getY() + r.getHeight());
059: this .color = "0 0 0"; // just for now
060:
061: }
062:
063: /**
064: * Set the pdf action for this link.
065: * @param action the pdf action that is activated for this link
066: */
067: public void setAction(PDFAction action) {
068: this .action = action;
069: }
070:
071: /**
072: * @see org.apache.fop.pdf.PDFObject#toPDFString()
073: */
074: public String toPDFString() {
075: getDocumentSafely().getProfile().verifyAnnotAllowed();
076: String fFlag = "";
077: if (getDocumentSafely().getProfile().getPDFAMode()
078: .isPDFA1LevelB()) {
079: int f = 0;
080: f |= 1 << (3 - 1); //Print, bit 3
081: f |= 1 << (4 - 1); //NoZoom, bit 4
082: f |= 1 << (5 - 1); //NoRotate, bit 5
083: fFlag = "/F " + f;
084: }
085: String s = getObjectID() + "<< /Type /Annot\n"
086: + "/Subtype /Link\n" + "/Rect [ " + (ulx) + " " + (uly)
087: + " " + (brx) + " " + (bry) + " ]\n" + "/C [ "
088: + this .color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A "
089: + this .action.getAction() + "\n" + "/H /I\n" + fFlag
090: + "\n>>\nendobj\n";
091: return s;
092: }
093:
094: /*
095: * example
096: * 19 0 obj
097: * <<
098: * /Type /Annot
099: * /Subtype /Link
100: * /Rect [ 176.032 678.48412 228.73579 692.356 ]
101: * /C [ 0.86491 0.03421 0.02591 ]
102: * /Border [ 0 0 1 ]
103: * /A 28 0 R
104: * /H /I
105: * >>
106: * endobj
107: */
108:
109: /**
110: * Check if this equals another object.
111: *
112: * @param obj the object to compare
113: * @return true if this equals other object
114: */
115: public boolean equals(Object obj) {
116: if (this == obj) {
117: return true;
118: }
119:
120: if (obj == null || !(obj instanceof PDFLink)) {
121: return false;
122: }
123:
124: PDFLink link = (PDFLink) obj;
125:
126: if (!((link.ulx == ulx) && (link.uly == uly)
127: && (link.brx == brx) && (link.bry == bry))) {
128: return false;
129: }
130:
131: if (!(link.color.equals(color) && link.action.getAction()
132: .equals(action.getAction()))) {
133: return false;
134: }
135:
136: return true;
137: }
138: }
|