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 2.9KB

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