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.

PDFGState.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 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. import java.util.HashMap;
  9. import java.util.Iterator;
  10. /**
  11. * class representing a /ExtGState object.
  12. *
  13. */
  14. public class PDFGState extends PDFObject {
  15. public static final String LW = "lw";
  16. public static final String LC = "lc";
  17. public static final String LJ = "lj";
  18. public static final String ML = "ml";
  19. public static final String D = "d";
  20. public static final String RI = "ri";
  21. public static final String OP = "OP";
  22. public static final String op = "op";
  23. public static final String OPM = "opm";
  24. public static final String Font = "font";
  25. public static final String BG = "bg";
  26. public static final String BG2 = "bg2";
  27. public static final String UCR = "ucr";
  28. public static final String UCR2 = "ucr2";
  29. public static final String TR = "tr";
  30. public static final String TR2 = "tr2";
  31. public static final String HT = "ht";
  32. public static final String FL = "fl";
  33. public static final String SM = "sm";
  34. public static final String SA = "sa";
  35. public static final String BM = "bm";
  36. public static final String SMask = "smask";
  37. public static final String CA = "CA";
  38. public static final String ca = "ca";
  39. public static final String AIS = "ais";
  40. public static final String TK = "tk";
  41. public static final PDFGState DEFAULT;
  42. static {
  43. DEFAULT = new PDFGState(0);
  44. HashMap vals = DEFAULT.values;
  45. /*vals.put(LW, new Float(1.0));
  46. vals.put(LC, new Integer(0));
  47. vals.put(LJ, new Integer(0));
  48. vals.put(ML, new Float(10.0));
  49. vals.put(D, "0 []");
  50. vals.put(RI, "RelativeColorimetric");
  51. vals.put(OP, Boolean.FALSE);
  52. vals.put(op, Boolean.FALSE);
  53. vals.put(OPM, new Integer(1));
  54. vals.put(Font, "");*/
  55. vals.put(CA, new Float(1.0));
  56. vals.put(ca, new Float(1.0));
  57. }
  58. HashMap values = new HashMap();
  59. /**
  60. * create a /ExtGState object.
  61. *
  62. * @param number the object's number
  63. * @param pageReference the pageReference represented by this object
  64. */
  65. public PDFGState(int number) {
  66. /* generic creation of object */
  67. super(number);
  68. }
  69. public String getName() {
  70. return "GS" + this.number;
  71. }
  72. public void setAlpha(float val, boolean fill) {
  73. if (fill) {
  74. values.put(ca, new Float(val));
  75. } else {
  76. values.put(CA, new Float(val));
  77. }
  78. }
  79. public void addValues(PDFGState state) {
  80. values.putAll(state.values);
  81. }
  82. public void addValues(HashMap vals) {
  83. values.putAll(vals);
  84. }
  85. /**
  86. * represent the object in PDF
  87. *
  88. * @return the PDF string
  89. */
  90. public byte[] toPDF() {
  91. StringBuffer sb = new StringBuffer(this.number + " " + this.generation
  92. + " obj\n<<\n/Type /ExtGState\n");
  93. appendVal(sb, ca);
  94. appendVal(sb, CA);
  95. sb.append(">>\nendobj\n");
  96. return sb.toString().getBytes();
  97. }
  98. private void appendVal(StringBuffer sb, String name) {
  99. Object val = values.get(name);
  100. if (val != null) {
  101. sb.append("/" + name + " " + val + "\n");
  102. }
  103. }
  104. /*
  105. * example
  106. * 29 0 obj
  107. * <<
  108. * /Type /ExtGState
  109. * /ca 0.5
  110. * >>
  111. * endobj
  112. */
  113. public boolean equals(Object obj) {
  114. if (obj == this) {
  115. return true;
  116. }
  117. if (!(obj instanceof PDFGState)) {
  118. return false;
  119. }
  120. HashMap vals1 = values;
  121. HashMap vals2 = ((PDFGState)obj).values;
  122. if (vals1.size() != vals2.size()) {
  123. return false;
  124. }
  125. for(Iterator iter = vals1.keySet().iterator(); iter.hasNext();) {
  126. Object str = iter.next();
  127. Object obj1 = vals1.get(str);
  128. if (!obj1.equals(vals2.get(str))) {
  129. return false;
  130. }
  131. }
  132. return true;
  133. }
  134. }