~ubuntu-branches/ubuntu/raring/libitext-java/raring-proposed

« back to all changes in this revision

Viewing changes to com/lowagie/text/rtf/text/RtfTab.java

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2008-11-23 12:26:51 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081123122651-ab7juwjz41q1123k
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: RtfTab.java,v 1.1 2006/06/17 09:51:30 hallm Exp $
3
 
 * $Name:  $
4
 
 *
5
 
 * Copyright 2001, 2002, 2003, 2004 by Mark Hall
6
 
 *
7
 
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 
 * (the "License"); you may not use this file except in compliance with the License.
9
 
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10
 
 *
11
 
 * Software distributed under the License is distributed on an "AS IS" basis,
12
 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 
 * for the specific language governing rights and limitations under the License.
14
 
 *
15
 
 * The Original Code is 'iText, a free JAVA-PDF library'.
16
 
 *
17
 
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18
 
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19
 
 * All Rights Reserved.
20
 
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21
 
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22
 
 * Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
23
 
 * Copyright (C) 2006 by Mark Hall. All Rights Reserved
24
 
 *
25
 
 * Contributor(s): all the names of the contributors are added in the source code
26
 
 * where applicable.
27
 
 *
28
 
 * Alternatively, the contents of this file may be used under the terms of the
29
 
 * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
30
 
 * provisions of LGPL are applicable instead of those above.  If you wish to
31
 
 * allow use of your version of this file only under the terms of the LGPL
32
 
 * License and not to allow others to use your version of this file under
33
 
 * the MPL, indicate your decision by deleting the provisions above and
34
 
 * replace them with the notice and other provisions required by the LGPL.
35
 
 * If you do not delete the provisions above, a recipient may use your version
36
 
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
37
 
 *
38
 
 * This library is free software; you can redistribute it and/or modify it
39
 
 * under the terms of the MPL as stated above or under the terms of the GNU
40
 
 * Library General Public License as published by the Free Software Foundation;
41
 
 * either version 2 of the License, or any later version.
42
 
 *
43
 
 * This library is distributed in the hope that it will be useful, but WITHOUT
44
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
45
 
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
46
 
 * details.
47
 
 *
48
 
 * If you didn't download this code from the following link, you should check if
49
 
 * you aren't using an obsolete version:
50
 
 * http://www.lowagie.com/iText/
51
 
 */
52
 
 
53
 
package com.lowagie.text.rtf.text;
54
 
 
55
 
import java.io.ByteArrayOutputStream;
56
 
import java.io.IOException;
57
 
 
58
 
import com.lowagie.text.rtf.RtfAddableElement;
59
 
 
60
 
/**
61
 
 * The RtfTab encapsulates a tab position and tab type in a paragraph.
62
 
 * To add tabs to a paragraph construct new RtfTab objects with the desired
63
 
 * tab position and alignment and then add them to the paragraph. In the actual
64
 
 * text the tabs are then defined as standard \t characters.<br /><br />
65
 
 * 
66
 
 * <code>RtfTab tab = new RtfTab(300, RtfTab.TAB_LEFT_ALIGN);<br />
67
 
 * Paragraph para = new Paragraph();<br />
68
 
 * para.add(tab);<br />
69
 
 * para.add("This paragraph has a\ttab defined.");</code>
70
 
 * 
71
 
 * @version $Revision: 1.1 $
72
 
 * @author Mark Hall (mhall@edu.uni-klu.ac.at)
73
 
 */
74
 
public class RtfTab extends RtfAddableElement {
75
 
 
76
 
        /**
77
 
         * A tab where the text is left aligned.
78
 
         */
79
 
        public static final int TAB_LEFT_ALIGN = 0;
80
 
        /**
81
 
         * A tab where the text is centre aligned.
82
 
         */
83
 
        public static final int TAB_CENTER_ALIGN = 1;
84
 
        /**
85
 
         * A tab where the text is right aligned.
86
 
         */
87
 
        public static final int TAB_RIGHT_ALIGN = 2;
88
 
        /**
89
 
         * A tab where the text is aligned on the decimal character. Which
90
 
         * character that is depends on the language settings of the viewer.
91
 
         */
92
 
        public static final int TAB_DECIMAL_ALIGN = 3;
93
 
        
94
 
        /**
95
 
         * The tab position in twips.
96
 
         */
97
 
        private int position = 0;
98
 
        /**
99
 
         * The tab alignment.
100
 
         */
101
 
        private int type = TAB_LEFT_ALIGN;
102
 
        
103
 
        /**
104
 
         * Constructs a new RtfTab with the given position and type. The position
105
 
         * is in standard iText points. The type is one of the tab alignment
106
 
         * constants defined in the RtfTab.
107
 
         * 
108
 
         * @param position The position of the tab in points.
109
 
         * @param type The tab type constant.
110
 
         */
111
 
        public RtfTab(float position, int type) {
112
 
                this.position = (int) Math.round(position * TWIPS_FACTOR);
113
 
                switch(type) {
114
 
                case TAB_LEFT_ALIGN: this.type = TAB_LEFT_ALIGN; break;
115
 
                case TAB_CENTER_ALIGN: this.type = TAB_CENTER_ALIGN; break;
116
 
                case TAB_RIGHT_ALIGN: this.type = TAB_RIGHT_ALIGN; break;
117
 
                case TAB_DECIMAL_ALIGN: this.type = TAB_DECIMAL_ALIGN; break;
118
 
                default: this.type = TAB_LEFT_ALIGN; break;
119
 
                }
120
 
        }
121
 
        
122
 
        /**
123
 
         * Writes the tab settings.
124
 
         */
125
 
        public byte[] write() {
126
 
        ByteArrayOutputStream result = new ByteArrayOutputStream();
127
 
        try {
128
 
                switch(this.type) {
129
 
                case TAB_CENTER_ALIGN: result.write("\\tqc".getBytes()); break;
130
 
                case TAB_RIGHT_ALIGN: result.write("\\tqr".getBytes()); break;
131
 
                case TAB_DECIMAL_ALIGN: result.write("\\tqdec".getBytes()); break;
132
 
                }
133
 
                result.write("\\tx".getBytes());
134
 
                result.write(intToByteArray(this.position));
135
 
        } catch(IOException ioe) {
136
 
            ioe.printStackTrace();
137
 
        }
138
 
        return result.toByteArray();
139
 
        }
140
 
}