01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: /* $Id: FOPRtfAttributes.java 495371 2007-01-11 21:03:07Z adelmelle $ */
19:
20: package org.apache.fop.render.rtf;
21:
22: import java.awt.Color;
23: import org.apache.fop.datatypes.Length;
24: import org.apache.fop.datatypes.PercentBaseContext;
25: import org.apache.fop.fo.FObj;
26: import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
27: import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
28:
29: /**
30: * A RtfAttributes subclass that adds some helper set methods.
31: */
32: public class FOPRtfAttributes extends RtfAttributes {
33:
34: /**
35: * Set an attribute that has a Length value (internal units in twips)
36: * @param name name of attribute
37: * @param value value of attribute
38: * @return this (which now contains the new entry)
39: */
40: public RtfAttributes setTwips(String name, Length value) {
41: set(name, value.getValue() / (1000 / 20)); //Convert millipoints to twips
42: return this ;
43: }
44:
45: /**
46: * Set an attribute using a value in millipoints (internal units in twips)
47: * @param name name of attribute
48: * @param value value of attribute (in millipoints)
49: * @return this (which now contains the new entry)
50: */
51: public RtfAttributes setTwips(String name, int value) {
52: set(name, value / (1000 / 20)); //Convert millipoints to twips
53: return this ;
54: }
55:
56: /**
57: * Set an attribute that has a Length value (internal units in half-points)
58: * @param name name of attribute
59: * @param value value of attribute
60: * @return this (which now contains the new entry)
61: */
62: public RtfAttributes setHalfPoints(String name, Length value) {
63: //Convert millipoints to half-points
64: set(name, value.getValue(DummyPercentBaseContext.singleton)
65: / (1000 / 2));
66: return this ;
67: }
68:
69: /**
70: * Set an attribute that has a Color value.
71: * @param name name of attribute
72: * @param color value of attribute
73: * @return this (which now contains the new entry)
74: */
75: public RtfAttributes set(String name, Color color) {
76: // TODO: This code is duplicated in TextAttributesConverter
77: int redComponent = color.getRed();
78: int greenComponent = color.getGreen();
79: int blueComponent = color.getBlue();
80: set(name, RtfColorTable.getInstance().getColorNumber(
81: redComponent, greenComponent, blueComponent).intValue());
82: return this ;
83: }
84:
85: private static class DummyPercentBaseContext implements
86: PercentBaseContext {
87:
88: static DummyPercentBaseContext singleton = new DummyPercentBaseContext();
89:
90: private DummyPercentBaseContext() {
91: // noop
92: }
93:
94: public int getBaseLength(int lengthBase, FObj fo) {
95: return 0;
96: }
97: }
98:
99: }
|