KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > FOPRtfAttributes


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
18 /* $Id: FOPRtfAttributes.java 454369 2006-10-09 13:07:13Z spepping $ */
19
20 package org.apache.fop.render.rtf;
21
22 import java.awt.Color JavaDoc;
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 /**
31  * A RtfAttributes subclass that adds some helper set methods.
32  */

33 public class FOPRtfAttributes extends RtfAttributes {
34
35     /**
36      * Set an attribute that has a Length value (internal units in twips)
37      * @param name name of attribute
38      * @param value value of attribute
39      * @return this (which now contains the new entry)
40      */

41     public RtfAttributes setTwips(String JavaDoc name, Length value) {
42         set(name, value.getValue() / (1000 / 20)); //Convert millipoints to twips
43
return this;
44     }
45
46     /**
47      * Set an attribute using a value in millipoints (internal units in twips)
48      * @param name name of attribute
49      * @param value value of attribute (in millipoints)
50      * @return this (which now contains the new entry)
51      */

52     public RtfAttributes setTwips(String JavaDoc name, int value) {
53         set(name, value / (1000 / 20)); //Convert millipoints to twips
54
return this;
55     }
56
57     /**
58      * Set an attribute that has a Length value (internal units in half-points)
59      * @param name name of attribute
60      * @param value value of attribute
61      * @return this (which now contains the new entry)
62      */

63     public RtfAttributes setHalfPoints(String JavaDoc name, Length value) {
64         //Convert millipoints to half-points
65
set(name, value.getValue(DummyPercentBaseContext.singleton) / (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 JavaDoc name, Color JavaDoc 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 PercentBaseContext {
86         
87         static DummyPercentBaseContext singleton = new DummyPercentBaseContext();
88         
89         private DummyPercentBaseContext() {
90             // noop
91
}
92         
93         public int getBaseLength(int lengthBase, FObj fobj) {
94             return 0;
95         }
96     }
97         
98 }
99
Popular Tags