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.

HwmfColorRef.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hwmf.record;
  16. import java.awt.Color;
  17. import java.io.IOException;
  18. import java.util.Locale;
  19. import org.apache.poi.util.LittleEndianConsts;
  20. import org.apache.poi.util.LittleEndianInputStream;
  21. /**
  22. * A 32-bit ColorRef Object that defines the color value.
  23. * Red (1 byte): An 8-bit unsigned integer that defines the relative intensity of red.
  24. * Green (1 byte): An 8-bit unsigned integer that defines the relative intensity of green.
  25. * Blue (1 byte): An 8-bit unsigned integer that defines the relative intensity of blue.
  26. * Reserved (1 byte): An 8-bit unsigned integer that MUST be 0x00.
  27. */
  28. public class HwmfColorRef implements Cloneable {
  29. private Color colorRef = Color.BLACK;
  30. public HwmfColorRef() {}
  31. public HwmfColorRef(Color colorRef) {
  32. this.colorRef = colorRef;
  33. }
  34. public int init(LittleEndianInputStream leis) throws IOException {
  35. int red = leis.readUByte();
  36. int green = leis.readUByte();
  37. int blue = leis.readUByte();
  38. /*int reserved =*/ leis.readUByte();
  39. colorRef = new Color(red, green, blue);
  40. return 4*LittleEndianConsts.BYTE_SIZE;
  41. }
  42. public Color getColor() {
  43. return colorRef;
  44. }
  45. public void setColor(Color color) {
  46. colorRef = color;
  47. }
  48. /**
  49. * Creates a new object of the same class and with the
  50. * same contents as this object.
  51. * @return a clone of this instance.
  52. * @exception OutOfMemoryError if there is not enough memory.
  53. * @see java.lang.Cloneable
  54. */
  55. @Override
  56. public HwmfColorRef clone() {
  57. try {
  58. return (HwmfColorRef)super.clone();
  59. } catch (CloneNotSupportedException e) {
  60. // this shouldn't happen, since we are Cloneable
  61. throw new InternalError();
  62. }
  63. }
  64. @Override
  65. public String toString() {
  66. return String.format(Locale.ROOT, "%#08X", colorRef.getRGB()&0xFFFFFF);
  67. }
  68. }