Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FOPRtfAttributes.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.rtf;
  19. import java.awt.Color;
  20. import org.apache.fop.datatypes.Length;
  21. import org.apache.fop.render.DummyPercentBaseContext;
  22. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
  23. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
  24. /**
  25. * A RtfAttributes subclass that adds some helper set methods.
  26. */
  27. public class FOPRtfAttributes extends RtfAttributes {
  28. /**
  29. * Set an attribute that has a Length value (internal units in twips)
  30. * @param name name of attribute
  31. * @param value value of attribute
  32. * @return this (which now contains the new entry)
  33. */
  34. public RtfAttributes setTwips(String name, Length value) {
  35. set(name, value.getValue() / (1000 / 20)); //Convert millipoints to twips
  36. return this;
  37. }
  38. /**
  39. * Set an attribute using a value in millipoints (internal units in twips)
  40. * @param name name of attribute
  41. * @param value value of attribute (in millipoints)
  42. * @return this (which now contains the new entry)
  43. */
  44. public RtfAttributes setTwips(String name, int value) {
  45. set(name, value / (1000 / 20)); //Convert millipoints to twips
  46. return this;
  47. }
  48. /**
  49. * Set an attribute that has a Length value (internal units in half-points)
  50. * @param name name of attribute
  51. * @param value value of attribute
  52. * @return this (which now contains the new entry)
  53. */
  54. public RtfAttributes setHalfPoints(String name, Length value) {
  55. //Convert millipoints to half-points
  56. set(name, value.getValue(DummyPercentBaseContext.getInstance()) / (1000 / 2));
  57. return this;
  58. }
  59. /**
  60. * Set an attribute that has a Color value.
  61. * @param name name of attribute
  62. * @param color value of attribute
  63. * @return this (which now contains the new entry)
  64. */
  65. public RtfAttributes set(String name, Color color) {
  66. // TODO: This code is duplicated in TextAttributesConverter
  67. int redComponent = color.getRed();
  68. int greenComponent = color.getGreen();
  69. int blueComponent = color.getBlue();
  70. set(name, RtfColorTable.getInstance().getColorNumber(
  71. redComponent, greenComponent, blueComponent));
  72. return this;
  73. }
  74. }