KickJava   Java API By Example, From Geeks To Geeks.

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


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: BorderAttributesConverter.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 import org.apache.fop.fo.Constants;
30 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
31 import org.apache.fop.render.rtf.rtflib.rtfdoc.IBorderAttributes;
32 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
33 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
34
35 /** Constants for RTF border attribute names, and a static method for converting
36  * fo attribute strings. */

37
38 public final class BorderAttributesConverter {
39
40     /**
41      * Constructor is private, because it's just a utility class.
42      */

43     private BorderAttributesConverter() {
44     }
45     
46     /**
47      * Create a border control word in attributes, with border properties
48      * as specified in color, style and width.
49      * @param border The CommonBorderPaddingBackground object.
50      * @param side The START, END, BEFORE, AFTER enum from CommonBorderPaddingBackground.
51      * @param attributes The attributes list to set the border control word.
52      * @param controlWord The border control word.
53      */

54     public static void makeBorder(CommonBorderPaddingBackground border, int side,
55             RtfAttributes attributes, String JavaDoc controlWord) {
56         int styleEnum = border.getBorderStyle(side);
57         if (styleEnum != Constants.EN_NONE) {
58             FOPRtfAttributes attrs = new FOPRtfAttributes();
59             attrs.set(IBorderAttributes.BORDER_COLOR, border.getBorderColor(side));
60             attrs.set(convertAttributetoRtf(styleEnum));
61             //division by 50 to convert millipoints to twips
62
attrs.set(IBorderAttributes.BORDER_WIDTH, border.getBorderWidth(side, false) / 50);
63             attributes.set(controlWord, attrs);
64             //Don't set BORDER_SPACE, because it makes the table look quite broken:
65
//vertical and horizontal borders don't meet at corners.
66
//attrs.setTwips(IBorderAttributes.BORDER_SPACE, border.getPadding(side, false, null));
67
//attributes.set(controlWord, attrs);
68
} else {
69             // Here padding specified, but corresponding border is not available
70

71             // Padding in millipoints
72
double paddingPt = border.getPadding(side, false, null) / 1000.0;
73             // Padding in twips
74
int padding = (int) Math.round(paddingPt * FoUnitsConverter.POINT_TO_TWIPS);
75             
76             // Add padding to corresponding space (space-before or space-after)
77
// if side == START or END, do nothing
78
if (side == CommonBorderPaddingBackground.BEFORE) {
79                 attributes.addIntegerValue(padding, RtfText.SPACE_BEFORE);
80             } else if (side == CommonBorderPaddingBackground.AFTER) {
81                 attributes.addIntegerValue(padding, RtfText.SPACE_AFTER);
82             }
83         }
84     }
85
86     /**
87     *
88     * @param iBorderStyle the border style to be converted
89     * @return String with the converted border style
90     */

91    public static String JavaDoc convertAttributetoRtf(int iBorderStyle) {
92        // Added by Normand Masse
93
// "solid" is interpreted like "thin"
94
if (iBorderStyle == Constants.EN_NONE) {
95            return IBorderAttributes.BORDER_NIL;
96        } else if (iBorderStyle == Constants.EN_SOLID) {
97            return IBorderAttributes.BORDER_SINGLE_THICKNESS;
98 /* } else if (iBorderStyle==Constants.EN_THIN) {
99                        return IBorderAttributes.BORDER_SINGLE_THICKNESS;
100        } else if (iBorderStyle==Constants.EN_THICK) {
101            return IBorderAttributes.BORDER_DOUBLE_THICKNESS;
102        } else if (iBorderStyle==Constants.EN_ value.equals("shadowed")) {
103            return IBorderAttributes.BORDER_SHADOWED;*/

104        } else if (iBorderStyle == Constants.EN_DOUBLE) {
105            return IBorderAttributes.BORDER_DOUBLE;
106        } else if (iBorderStyle == Constants.EN_DOTTED) {
107            return IBorderAttributes.BORDER_DOTTED;
108        } else if (iBorderStyle == Constants.EN_DASHED) {
109            return IBorderAttributes.BORDER_DASH;
110        } else if (iBorderStyle == Constants.EN_GROOVE) {
111            return IBorderAttributes.BORDER_ENGRAVE;
112        } else if (iBorderStyle == Constants.EN_RIDGE) {
113            return IBorderAttributes.BORDER_EMBOSS;
114        } else if (iBorderStyle == Constants.EN_INSET) {
115            return IBorderAttributes.BORDER_ENGRAVE;
116        } else if (iBorderStyle == Constants.EN_OUTSET) {
117            return IBorderAttributes.BORDER_EMBOSS;
118 /* } else if (iBorderStyle==Constants value.equals("hairline")) {
119            return IBorderAttributes.BORDER_HAIRLINE;*/

120 /* } else if (iBorderStyle==Constant value.equals("dot-dash")) {
121            return IBorderAttributes.BORDER_DOT_DASH;
122        } else if (iBorderStyle==Constant value.equals("dot-dot-dash")) {
123            return IBorderAttributes.BORDER_DOT_DOT_DASH;
124        } else if (iBorderStyle==Constant value.equals("triple")) {
125            return IBorderAttributes.BORDER_TRIPLE;
126        } else if (iBorderStyle==Constant value.equals("wavy")) {
127            return IBorderAttributes.BORDER_WAVY;
128        } else if (iBorderStyle==Constant value.equals("wavy-double")) {
129            return IBorderAttributes.BORDER_WAVY_DOUBLE;
130        } else if (iBorderStyle==Constant value.equals("striped")) {
131            return IBorderAttributes.BORDER_STRIPED;
132        } else if (iBorderStyle==Constant value.equals("emboss")) {
133            return IBorderAttributes.BORDER_EMBOSS;
134        } else if (iBorderStyle==Constant value.equals("engrave")) {
135            return IBorderAttributes.BORDER_ENGRAVE;*/

136        } else {
137            return IBorderAttributes.BORDER_SINGLE_THICKNESS;
138        }
139
140    }
141 }
Popular Tags