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.

PDFRectangle.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. import java.io.IOException;
  20. import java.io.OutputStream;
  21. /**
  22. * class representing a rectangle
  23. *
  24. * Rectangles are specified on page 183 of the PDF 1.3 spec.
  25. */
  26. public class PDFRectangle implements PDFWritable {
  27. /**
  28. * lower left x coordinate
  29. */
  30. protected int llx;
  31. /**
  32. * lower left y coordinate
  33. */
  34. protected int lly;
  35. /**
  36. * upper right x coordinate
  37. */
  38. protected int urx;
  39. /**
  40. * upper right y coordinate
  41. */
  42. protected int ury;
  43. /**
  44. * create a rectangle giving the four separate values
  45. *
  46. * @param llx lower left x coordinate
  47. * @param lly lower left y coordinate
  48. * @param urx upper right x coordinate
  49. * @param ury upper right y coordinate
  50. */
  51. public PDFRectangle(int llx, int lly, int urx, int ury) {
  52. this.llx = llx;
  53. this.lly = lly;
  54. this.urx = urx;
  55. this.ury = ury;
  56. }
  57. /**
  58. * create a rectangle giving an array of four values
  59. *
  60. * @param array values in the order llx, lly, urx, ury
  61. */
  62. public PDFRectangle(int[] array) {
  63. this.llx = array[0];
  64. this.lly = array[1];
  65. this.urx = array[2];
  66. this.ury = array[3];
  67. }
  68. private String format() {
  69. StringBuilder textBuffer = new StringBuilder(32);
  70. format(textBuffer);
  71. return textBuffer.toString();
  72. }
  73. private void format(StringBuilder textBuffer) {
  74. textBuffer.append('[').append(llx)
  75. .append(' ').append(lly)
  76. .append(' ').append(urx)
  77. .append(' ').append(ury).append(']');
  78. }
  79. /** {@inheritDoc} */
  80. @Override
  81. public String toString() {
  82. return "PDFRectangle" + format();
  83. }
  84. /** {@inheritDoc} */
  85. public void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException {
  86. format(textBuffer);
  87. }
  88. }