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.

GraphicsSetProcessColor.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.afp.goca;
  19. import java.awt.Color;
  20. import java.awt.color.ColorSpace;
  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. /**
  24. * Sets the current processing color for the following GOCA structured fields
  25. */
  26. public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder {
  27. private final Color color;
  28. private final float[] colorComponents;
  29. /**
  30. * Main constructor
  31. *
  32. * @param color the color to set
  33. */
  34. public GraphicsSetProcessColor(Color color) {
  35. this.color = color;
  36. this.colorComponents = color.getColorComponents(null);
  37. }
  38. /** {@inheritDoc} */
  39. public int getDataLength() {
  40. return 12 + colorComponents.length;
  41. }
  42. /** {@inheritDoc} */
  43. byte getOrderCode() {
  44. return (byte)0xB2;
  45. }
  46. /** {@inheritDoc} */
  47. public void writeToStream(OutputStream os) throws IOException {
  48. // COLSPCE
  49. byte colspace;
  50. int colSpaceType = color.getColorSpace().getType();
  51. if (colSpaceType == ColorSpace.TYPE_CMYK) {
  52. colspace = 0x04;
  53. } else if (colSpaceType == ColorSpace.TYPE_RGB) {
  54. colspace = 0x01;
  55. } else {
  56. log.error("unsupported colorspace " + colSpaceType);
  57. colspace = 0x01;
  58. }
  59. // COLSIZE(S)
  60. byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00};
  61. for (int i = 0; i < colorComponents.length; i++) {
  62. colsizes[i] = (byte)8;
  63. }
  64. int len = getDataLength();
  65. byte[] data = new byte[len];
  66. data[0] = getOrderCode(); // GSPCOL order code
  67. data[1] = (byte)(len - 2); // LEN
  68. data[2] = 0x00; // reserved; must be zero
  69. data[3] = colspace; // COLSPCE
  70. data[4] = 0x00; // reserved; must be zero
  71. data[5] = 0x00; // reserved; must be zero
  72. data[6] = 0x00; // reserved; must be zero
  73. data[7] = 0x00; // reserved; must be zero
  74. data[8] = colsizes[0]; // COLSIZE(S)
  75. data[9] = colsizes[1];
  76. data[10] = colsizes[2];
  77. data[11] = colsizes[3];
  78. // COLVALUE(S)
  79. for (int i = 0; i < colorComponents.length; i++) {
  80. data[i + 12] = (byte)(colorComponents[i] * 255);
  81. }
  82. os.write(data);
  83. }
  84. /** {@inheritDoc} */
  85. public String toString() {
  86. return "GraphicsSetProcessColor(col=" + color + ")";
  87. }
  88. }