You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFGoToRemote.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.pdf;
  19. /**
  20. * Class representing a /GoToR object.
  21. */
  22. public class PDFGoToRemote extends PDFAction {
  23. /**
  24. * the file specification
  25. */
  26. private PDFReference pdfFileSpec;
  27. private int pageReference;
  28. private String destination;
  29. private boolean newWindow;
  30. /**
  31. * Create an GoToR object.
  32. *
  33. * @param pdfFileSpec the fileSpec associated with the action
  34. * @param newWindow boolean indicating whether the target should be
  35. * displayed in a new window
  36. */
  37. public PDFGoToRemote(PDFFileSpec pdfFileSpec, boolean newWindow) {
  38. /* generic creation of object */
  39. super();
  40. this.pdfFileSpec = pdfFileSpec.makeReference();
  41. this.newWindow = newWindow;
  42. }
  43. /**
  44. * Create an GoToR object.
  45. *
  46. * @param pdfFileSpec the fileSpec associated with the action
  47. * @param page a page reference within the remote document
  48. * @param newWindow boolean indicating whether the target should be
  49. * displayed in a new window
  50. */
  51. public PDFGoToRemote(PDFFileSpec pdfFileSpec, int page, boolean newWindow) {
  52. this(pdfFileSpec.makeReference(), page, newWindow);
  53. }
  54. /**
  55. * Create an GoToR object.
  56. *
  57. * @param pdfFileSpec the fileSpec associated with the action
  58. * @param page a page reference within the remote document
  59. * @param newWindow boolean indicating whether the target should be
  60. * displayed in a new window
  61. */
  62. public PDFGoToRemote(PDFReference pdfFileSpec, int page, boolean newWindow) {
  63. super();
  64. this.pdfFileSpec = pdfFileSpec;
  65. this.pageReference = page;
  66. this.newWindow = newWindow;
  67. }
  68. /**
  69. * create an GoToR object.
  70. *
  71. * @param pdfFileSpec the fileSpec associated with the action
  72. * @param dest a named destination within the remote document
  73. * @param newWindow boolean indicating whether the target should be
  74. * displayed in a new window
  75. */
  76. public PDFGoToRemote(PDFFileSpec pdfFileSpec, String dest, boolean newWindow) {
  77. /* generic creation of object */
  78. super();
  79. this.pdfFileSpec = pdfFileSpec.makeReference();
  80. this.destination = dest;
  81. this.newWindow = newWindow;
  82. }
  83. /**
  84. * return the action string which will reference this object
  85. *
  86. * @return the action String
  87. */
  88. public String getAction() {
  89. return this.referencePDF();
  90. }
  91. /**
  92. * {@inheritDoc}
  93. */
  94. public String toPDFString() {
  95. StringBuffer sb = new StringBuffer(64);
  96. sb.append("<<\n/S /GoToR\n/F ");
  97. sb.append(pdfFileSpec.toString());
  98. sb.append("\n");
  99. if (destination != null) {
  100. sb.append("/D (").append(this.destination).append(")");
  101. } else {
  102. sb.append("/D [ ").append(this.pageReference).append(" /XYZ null null null ]");
  103. }
  104. if (newWindow) {
  105. sb.append("/NewWindow true");
  106. }
  107. sb.append("\n>>");
  108. return sb.toString();
  109. }
  110. /*
  111. * example
  112. * 28 0 obj
  113. * <<
  114. * /S /GoToR
  115. * /F 29 0 R
  116. * /D [ 0 /XYZ -6 797 null ]
  117. * >>
  118. * endobj
  119. */
  120. /** {@inheritDoc} */
  121. protected boolean contentEquals(PDFObject obj) {
  122. if (this == obj) {
  123. return true;
  124. }
  125. if (obj == null || !(obj instanceof PDFGoToRemote)) {
  126. return false;
  127. }
  128. PDFGoToRemote remote = (PDFGoToRemote)obj;
  129. if (!remote.pdfFileSpec.toString().equals(pdfFileSpec.toString())) {
  130. return false;
  131. }
  132. if (destination != null) {
  133. if (!destination.equals(remote.destination)) {
  134. return false;
  135. }
  136. } else {
  137. if (pageReference != remote.pageReference) {
  138. return false;
  139. }
  140. }
  141. return (this.newWindow == remote.newWindow);
  142. }
  143. }