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.

PDFLink.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.pdf;
  8. // Java
  9. import java.awt.geom.Rectangle2D;
  10. /**
  11. * class representing an /Annot object of /Subtype /Link
  12. */
  13. public class PDFLink extends PDFObject {
  14. public static final int EXTERNAL = 0;
  15. public static final int INTERNAL = 1;
  16. float ulx;
  17. float uly;
  18. float brx;
  19. float bry;
  20. String color;
  21. PDFAction action;
  22. /**
  23. * create objects associated with a link annotation (GoToR)
  24. *
  25. * @param number the object's number
  26. * @param producer the application producing the PDF
  27. */
  28. public PDFLink(int number, Rectangle2D r) {
  29. /* generic creation of PDF object */
  30. super(number);
  31. this.ulx = (float)r.getX();
  32. this.uly = (float)r.getY();
  33. this.brx = (float)(r.getX() + r.getWidth());
  34. this.bry = (float)(r.getY() - r.getHeight());
  35. this.color = "0 0 0"; // just for now
  36. }
  37. public void setAction(PDFAction action) {
  38. this.action = action;
  39. }
  40. /**
  41. * produce the PDF representation of the object
  42. *
  43. * @return the PDF
  44. */
  45. public byte[] toPDF() {
  46. String p = this.number + " " + this.generation + " obj\n"
  47. + "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ "
  48. + (ulx) + " " + (uly) + " "
  49. + (brx) + " " + (bry) + " ]\n" + "/C [ "
  50. + this.color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A "
  51. + this.action.getAction() + "\n" + "/H /I\n>>\nendobj\n";
  52. return p.getBytes();
  53. }
  54. /*
  55. * example
  56. * 19 0 obj
  57. * <<
  58. * /Type /Annot
  59. * /Subtype /Link
  60. * /Rect [ 176.032 678.48412 228.73579 692.356 ]
  61. * /C [ 0.86491 0.03421 0.02591 ]
  62. * /Border [ 0 0 1 ]
  63. * /A 28 0 R
  64. * /H /I
  65. * >>
  66. * endobj
  67. */
  68. }