~ubuntu-branches/ubuntu/karmic/libitext-java/karmic

« back to all changes in this revision

Viewing changes to com/lowagie/text/rtf/style/RtfParagraphStyle.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
Tags: 2.1.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: RtfParagraphStyle.java,v 1.5 2006/08/07 10:42:35 blowagie 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
 
 *
23
 
 * Contributor(s): all the names of the contributors are added in the source code
24
 
 * where applicable.
25
 
 *
26
 
 * Alternatively, the contents of this file may be used under the terms of the
27
 
 * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
28
 
 * provisions of LGPL are applicable instead of those above.  If you wish to
29
 
 * allow use of your version of this file only under the terms of the LGPL
30
 
 * License and not to allow others to use your version of this file under
31
 
 * the MPL, indicate your decision by deleting the provisions above and
32
 
 * replace them with the notice and other provisions required by the LGPL.
33
 
 * If you do not delete the provisions above, a recipient may use your version
34
 
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35
 
 *
36
 
 * This library is free software; you can redistribute it and/or modify it
37
 
 * under the terms of the MPL as stated above or under the terms of the GNU
38
 
 * Library General Public License as published by the Free Software Foundation;
39
 
 * either version 2 of the License, or any later version.
40
 
 *
41
 
 * This library is distributed in the hope that it will be useful, but WITHOUT
42
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43
 
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44
 
 * details.
45
 
 *
46
 
 * If you didn't download this code from the following link, you should check if
47
 
 * you aren't using an obsolete version:
48
 
 * http://www.lowagie.com/iText/
49
 
 */
50
 
package com.lowagie.text.rtf.style;
51
 
 
52
 
import java.awt.Color;
53
 
import java.io.ByteArrayOutputStream;
54
 
import java.io.IOException;
55
 
 
56
 
import com.lowagie.text.Element;
57
 
import com.lowagie.text.Font;
58
 
import com.lowagie.text.rtf.RtfBasicElement;
59
 
import com.lowagie.text.rtf.document.RtfDocument;
60
 
import com.lowagie.text.rtf.text.RtfParagraph;
61
 
 
62
 
/**
63
 
 * The RtfParagraphStyle stores all style/formatting attributes of a RtfParagraph.
64
 
 * Additionally it also supports the style name system available in RTF. The RtfParagraphStyle
65
 
 * is a Font and can thus be used as such. To use the stylesheet functionality
66
 
 * it needs to be set as the font of a Paragraph. Otherwise it will work like a
67
 
 * RtfFont. It also supports inheritance of styles.
68
 
 * 
69
 
 * @version $Revision: 1.5 $
70
 
 * @author Mark Hall (mhall@edu.uni-klu.ac.at)
71
 
 */
72
 
public class RtfParagraphStyle extends RtfFont {
73
 
 
74
 
    /**
75
 
     * Constant for left alignment
76
 
     */
77
 
    public static final byte[] ALIGN_LEFT = "\\ql".getBytes();
78
 
    /**
79
 
     * Constant for right alignment
80
 
     */
81
 
    public static final byte[] ALIGN_RIGHT = "\\qr".getBytes();
82
 
    /**
83
 
     * Constant for center alignment
84
 
     */
85
 
    public static final byte[] ALIGN_CENTER = "\\qc".getBytes();
86
 
    /**
87
 
     * Constant for justified alignment
88
 
     */
89
 
    public static final byte[] ALIGN_JUSTIFY = "\\qj".getBytes();
90
 
    /**
91
 
     * Constant for left indentation
92
 
     */
93
 
    public static final byte[] INDENT_LEFT = "\\li".getBytes();
94
 
    /**
95
 
     * Constant for right indentation
96
 
     */
97
 
    public static final byte[] INDENT_RIGHT = "\\ri".getBytes();
98
 
    /**
99
 
     * Constant for keeping the paragraph together on one page
100
 
     */
101
 
    public static final byte[] KEEP_TOGETHER = "\\keep".getBytes();
102
 
    /**
103
 
     * Constant for keeping the paragraph toghether with the next one on one page
104
 
     */
105
 
    public static final byte[] KEEP_TOGETHER_WITH_NEXT = "\\keepn".getBytes();
106
 
    /**
107
 
     * Constant for the space after the paragraph.
108
 
     */
109
 
    public static final byte[] SPACING_AFTER = "\\sa".getBytes();
110
 
    /**
111
 
     * Constant for the space before the paragraph.
112
 
     */
113
 
    public static final byte[] SPACING_BEFORE = "\\sb".getBytes();
114
 
 
115
 
    /**
116
 
     * The NORMAL/STANDARD style.
117
 
     */
118
 
    public static final RtfParagraphStyle STYLE_NORMAL = new RtfParagraphStyle("Normal", "Arial", 12, Font.NORMAL, Color.black);
119
 
    /**
120
 
     * The style for level 1 headings.
121
 
     */
122
 
    public static final RtfParagraphStyle STYLE_HEADING_1 = new RtfParagraphStyle("heading 1", "Normal");
123
 
    /**
124
 
     * The style for level 2 headings.
125
 
     */
126
 
    public static final RtfParagraphStyle STYLE_HEADING_2 = new RtfParagraphStyle("heading 2", "Normal");
127
 
    /**
128
 
     * The style for level 3 headings.
129
 
     */
130
 
    public static final RtfParagraphStyle STYLE_HEADING_3 = new RtfParagraphStyle("heading 3", "Normal");
131
 
 
132
 
    /**
133
 
     * Initialises the properties of the styles.
134
 
     */
135
 
    static {
136
 
        STYLE_HEADING_1.setSize(16);
137
 
        STYLE_HEADING_1.setStyle(Font.BOLD);
138
 
        STYLE_HEADING_2.setSize(14);
139
 
        STYLE_HEADING_2.setStyle(Font.BOLDITALIC);
140
 
        STYLE_HEADING_3.setSize(13);
141
 
        STYLE_HEADING_3.setStyle(Font.BOLD);
142
 
    }
143
 
    
144
 
    /**
145
 
     * No modification has taken place when compared to the RtfParagraphStyle this RtfParagraphStyle
146
 
     * is based on. These modification markers are used to determine what needs to be
147
 
     * inherited and what not from the parent RtfParagraphStyle.
148
 
     */
149
 
    private static final int MODIFIED_NONE = 0;
150
 
    /**
151
 
     * The alignment has been modified.
152
 
     */
153
 
    private static final int MODIFIED_ALIGNMENT = 1;
154
 
    /**
155
 
     * The left indentation has been modified.
156
 
     */
157
 
    private static final int MODIFIED_INDENT_LEFT = 2;
158
 
    /**
159
 
     * The right indentation has been modified.
160
 
     */
161
 
    private static final int MODIFIED_INDENT_RIGHT = 4;
162
 
    /**
163
 
     * The spacing before a paragraph has been modified.
164
 
     */
165
 
    private static final int MODIFIED_SPACING_BEFORE = 8;
166
 
    /**
167
 
     * The spacing after a paragraph has been modified.
168
 
     */
169
 
    private static final int MODIFIED_SPACING_AFTER = 16;
170
 
    /**
171
 
     * The font name has been modified.
172
 
     */
173
 
    private static final int MODIFIED_FONT_NAME = 32;
174
 
    /**
175
 
     * The font style has been modified.
176
 
     */
177
 
    private static final int MODIFIED_FONT_SIZE = 64;
178
 
    /**
179
 
     * The font size has been modified.
180
 
     */
181
 
    private static final int MODIFIED_FONT_STYLE = 128;
182
 
    /**
183
 
     * The font colour has been modified.
184
 
     */
185
 
    private static final int MODIFIED_FONT_COLOR = 256;
186
 
    /**
187
 
     * The line leading has been modified. 
188
 
     */
189
 
    private static final int MODIFIED_LINE_LEADING = 512;
190
 
    /**
191
 
     * The paragraph keep together setting has been modified.
192
 
     */
193
 
    private static final int MODIFIED_KEEP_TOGETHER = 1024;
194
 
    /**
195
 
     * The paragraph keep together with next setting has been modified.
196
 
     */
197
 
    private static final int MODIFIED_KEEP_TOGETHER_WITH_NEXT = 2048;
198
 
    
199
 
    /**
200
 
     * The alignment of the paragraph.
201
 
     */
202
 
    private int alignment = Element.ALIGN_LEFT;
203
 
    /**
204
 
     * The left indentation of the paragraph.
205
 
     */
206
 
    private int indentLeft = 0;
207
 
    /**
208
 
     * The right indentation of the paragraph.
209
 
     */
210
 
    private int indentRight = 0;
211
 
    /**
212
 
     * The spacing before a paragraph.
213
 
     */
214
 
    private int spacingBefore = 0;
215
 
    /**
216
 
     * The spacing after a paragraph.
217
 
     */
218
 
    private int spacingAfter = 0;
219
 
    /**
220
 
     * The line leading of the paragraph.
221
 
     */
222
 
    private int lineLeading = 0;
223
 
    /**
224
 
     * Whether this RtfParagraph must stay on one page.
225
 
     */
226
 
    private boolean keepTogether = false;
227
 
    /**
228
 
     * Whether this RtfParagraph must stay on the same page as the next paragraph.
229
 
     */
230
 
    private boolean keepTogetherWithNext = false;
231
 
    /**
232
 
     * The name of this RtfParagraphStyle.
233
 
     */
234
 
    private String styleName = "";
235
 
    /**
236
 
     * The name of the RtfParagraphStyle this RtfParagraphStyle is based on.
237
 
     */
238
 
    private String basedOnName = null;
239
 
    /**
240
 
     * The RtfParagraphStyle this RtfParagraphStyle is based on.
241
 
     */
242
 
    private RtfParagraphStyle baseStyle = null;
243
 
    /**
244
 
     * Which properties have been modified when compared to the base style.
245
 
     */
246
 
    private int modified = MODIFIED_NONE;
247
 
    /**
248
 
     * The number of this RtfParagraphStyle in the stylesheet list.
249
 
     */
250
 
    private int styleNumber = -1;
251
 
    
252
 
    /**
253
 
     * Constructs a new RtfParagraphStyle with the given attributes.
254
 
     * 
255
 
     * @param styleName The name of this RtfParagraphStyle.
256
 
     * @param fontName The name of the font to use for this RtfParagraphStyle.
257
 
     * @param fontSize The size of the font to use for this RtfParagraphStyle.
258
 
     * @param fontStyle The style of the font to use for this RtfParagraphStyle.
259
 
     * @param fontColor The colour of the font to use for this RtfParagraphStyle.
260
 
     */
261
 
    public RtfParagraphStyle(String styleName, String fontName, int fontSize, int fontStyle, Color fontColor) {
262
 
        super(null, new RtfFont(fontName, fontSize, fontStyle, fontColor));
263
 
        this.styleName = styleName;
264
 
    }
265
 
    
266
 
    /**
267
 
     * Constructs a new RtfParagraphStyle that is based on an existing RtfParagraphStyle.
268
 
     * 
269
 
     * @param styleName The name of this RtfParagraphStyle.
270
 
     * @param basedOnName The name of the RtfParagraphStyle this RtfParagraphStyle is based on.
271
 
     */
272
 
    public RtfParagraphStyle(String styleName, String basedOnName) {
273
 
        super(null, new Font());
274
 
        this.styleName = styleName;
275
 
        this.basedOnName = basedOnName;
276
 
    }
277
 
    
278
 
    /**
279
 
     * Constructs a RtfParagraphStyle from another RtfParagraphStyle.
280
 
     * 
281
 
     * INTERNAL USE ONLY
282
 
     * 
283
 
     * @param doc The RtfDocument this RtfParagraphStyle belongs to.
284
 
     * @param style The RtfParagraphStyle to copy settings from.
285
 
     */
286
 
    public RtfParagraphStyle(RtfDocument doc, RtfParagraphStyle style) {
287
 
        super(doc, style);
288
 
        this.document = doc;
289
 
        this.styleName = style.getStyleName();
290
 
        this.alignment = style.getAlignment();
291
 
        this.indentLeft = (int) (style.getIndentLeft() * RtfBasicElement.TWIPS_FACTOR);
292
 
        this.indentRight = (int) (style.getIndentRight() * RtfBasicElement.TWIPS_FACTOR);
293
 
        this.spacingBefore = (int) (style.getSpacingBefore() * RtfBasicElement.TWIPS_FACTOR);
294
 
        this.spacingAfter = (int) (style.getSpacingAfter() * RtfBasicElement.TWIPS_FACTOR);
295
 
        this.lineLeading = (int) (style.getLineLeading() * RtfBasicElement.TWIPS_FACTOR);
296
 
        this.keepTogether = style.getKeepTogether();
297
 
        this.keepTogetherWithNext = style.getKeepTogetherWithNext();
298
 
        this.basedOnName = style.basedOnName;
299
 
        this.modified = style.modified;
300
 
        this.styleNumber = style.getStyleNumber();
301
 
 
302
 
        if(this.document != null) {
303
 
            setRtfDocument(this.document);
304
 
        }
305
 
    }
306
 
 
307
 
    /**
308
 
     * Gets the name of this RtfParagraphStyle.
309
 
     * 
310
 
     * @return The name of this RtfParagraphStyle.
311
 
     */
312
 
    public String getStyleName() {
313
 
        return this.styleName;
314
 
    }
315
 
    
316
 
    /**
317
 
     * Gets the name of the RtfParagraphStyle this RtfParagraphStyle is based on.
318
 
     * 
319
 
     * @return The name of the base RtfParagraphStyle.
320
 
     */
321
 
    public String getBasedOnName() {
322
 
        return this.basedOnName;
323
 
    }
324
 
    
325
 
    /**
326
 
     * Gets the alignment of this RtfParagraphStyle.
327
 
     * 
328
 
     * @return The alignment of this RtfParagraphStyle.
329
 
     */
330
 
    public int getAlignment() {
331
 
        return this.alignment;
332
 
    }
333
 
 
334
 
    /**
335
 
     * Sets the alignment of this RtfParagraphStyle.
336
 
     * 
337
 
     * @param alignment The alignment to use.
338
 
     */
339
 
    public void setAlignment(int alignment) {
340
 
        this.modified = this.modified | MODIFIED_ALIGNMENT;
341
 
        this.alignment = alignment;
342
 
    }
343
 
    
344
 
    /**
345
 
     * Gets the left indentation of this RtfParagraphStyle.
346
 
     * 
347
 
     * @return The left indentation of this RtfParagraphStyle.
348
 
     */
349
 
    public int getIndentLeft() {
350
 
        return this.indentLeft;
351
 
    }
352
 
 
353
 
    /**
354
 
     * Sets the left indentation of this RtfParagraphStyle.
355
 
     * 
356
 
     * @param indentLeft The left indentation to use.
357
 
     */
358
 
    public void setIndentLeft(int indentLeft) {
359
 
        this.modified = this.modified | MODIFIED_INDENT_LEFT;
360
 
        this.indentLeft = indentLeft;
361
 
    }
362
 
    
363
 
    /**
364
 
     * Gets the right indentation of this RtfParagraphStyle.
365
 
     * 
366
 
     * @return The right indentation of this RtfParagraphStyle.
367
 
     */
368
 
    public int getIndentRight() {
369
 
        return this.indentRight;
370
 
    }
371
 
 
372
 
    /**
373
 
     * Sets the right indentation of this RtfParagraphStyle.
374
 
     * 
375
 
     * @param indentRight The right indentation to use.
376
 
     */
377
 
    public void setIndentRight(int indentRight) {
378
 
        this.modified = this.modified | MODIFIED_INDENT_RIGHT;
379
 
        this.indentRight = indentRight;
380
 
    }
381
 
    
382
 
    /**
383
 
     * Gets the space before the paragraph of this RtfParagraphStyle..
384
 
     * 
385
 
     * @return The space before the paragraph.
386
 
     */
387
 
    public int getSpacingBefore() {
388
 
        return this.spacingBefore;
389
 
    }
390
 
 
391
 
    /**
392
 
     * Sets the space before the paragraph of this RtfParagraphStyle.
393
 
     * 
394
 
     * @param spacingBefore The space before to use.
395
 
     */
396
 
    public void setSpacingBefore(int spacingBefore) {
397
 
        this.modified = this.modified | MODIFIED_SPACING_BEFORE;
398
 
        this.spacingBefore = spacingBefore;
399
 
    }
400
 
    
401
 
    /**
402
 
     * Gets the space after the paragraph of this RtfParagraphStyle.
403
 
     * 
404
 
     * @return The space after the paragraph.
405
 
     */
406
 
    public int getSpacingAfter() {
407
 
        return this.spacingAfter;
408
 
    }
409
 
    
410
 
    /**
411
 
     * Sets the space after the paragraph of this RtfParagraphStyle.
412
 
     * 
413
 
     * @param spacingAfter The space after to use.
414
 
     */
415
 
    public void setSpacingAfter(int spacingAfter) {
416
 
        this.modified = this.modified | MODIFIED_SPACING_AFTER;
417
 
        this.spacingAfter = spacingAfter;
418
 
    }
419
 
    
420
 
    /**
421
 
     * Sets the font name of this RtfParagraphStyle.
422
 
     * 
423
 
     * @param fontName The font name to use 
424
 
     */
425
 
    public void setFontName(String fontName) {
426
 
        this.modified = this.modified | MODIFIED_FONT_NAME;
427
 
        super.setFontName(fontName);
428
 
    }
429
 
    
430
 
    /**
431
 
     * Sets the font size of this RtfParagraphStyle.
432
 
     * 
433
 
     * @param fontSize The font size to use.
434
 
     */
435
 
    public void setSize(float fontSize) {
436
 
        this.modified = this.modified | MODIFIED_FONT_SIZE;
437
 
        super.setSize(fontSize);
438
 
    }
439
 
    
440
 
    /**
441
 
     * Sets the font style of this RtfParagraphStyle.
442
 
     * 
443
 
     * @param fontStyle The font style to use.
444
 
     */
445
 
    public void setStyle(int fontStyle) {
446
 
        this.modified = this.modified | MODIFIED_FONT_STYLE;
447
 
        super.setStyle(fontStyle);
448
 
    }
449
 
    
450
 
    /**
451
 
     * Sets the colour of this RtfParagraphStyle.
452
 
     * 
453
 
     * @param color The Color to use.
454
 
     */
455
 
    public void setColor(Color color) {
456
 
        this.modified = this.modified | MODIFIED_FONT_COLOR;
457
 
        super.setColor(color);
458
 
    }
459
 
    
460
 
    /**
461
 
     * Gets the line leading of this RtfParagraphStyle.
462
 
     * 
463
 
     * @return The line leading of this RtfParagraphStyle.
464
 
     */
465
 
    public int getLineLeading() {
466
 
        return this.lineLeading;
467
 
    }
468
 
    
469
 
    /**
470
 
     * Sets the line leading of this RtfParagraphStyle.
471
 
     * 
472
 
     * @param lineLeading The line leading to use.
473
 
     */
474
 
    public void setLineLeading(int lineLeading) {
475
 
        this.lineLeading = lineLeading;
476
 
        this.modified = this.modified | MODIFIED_LINE_LEADING;
477
 
    }
478
 
    
479
 
    /**
480
 
     * Gets whether the lines in the paragraph should be kept together in
481
 
     * this RtfParagraphStyle.
482
 
     * 
483
 
     * @return Whether the lines in the paragraph should be kept together.
484
 
     */
485
 
    public boolean getKeepTogether() {
486
 
        return this.keepTogether;
487
 
    }
488
 
    
489
 
    /**
490
 
     * Sets whether the lines in the paragraph should be kept together in
491
 
     * this RtfParagraphStyle.
492
 
     * 
493
 
     * @param keepTogether Whether the lines in the paragraph should be kept together.
494
 
     */
495
 
    public void setKeepTogether(boolean keepTogether) {
496
 
        this.keepTogether = keepTogether;
497
 
        this.modified = this.modified | MODIFIED_KEEP_TOGETHER;
498
 
    }
499
 
    
500
 
    /**
501
 
     * Gets whether the paragraph should be kept toggether with the next in
502
 
     * this RtfParagraphStyle.
503
 
     * 
504
 
     * @return Whether the paragraph should be kept together with the next.
505
 
     */
506
 
    public boolean getKeepTogetherWithNext() {
507
 
        return this.keepTogetherWithNext;
508
 
    }
509
 
    
510
 
    /**
511
 
     * Sets whether the paragraph should be kept together with the next in
512
 
     * this RtfParagraphStyle.
513
 
     * 
514
 
     * @param keepTogetherWithNext Whether the paragraph should be kept together with the next.
515
 
     */
516
 
    public void setKeepTogetherWithNext(boolean keepTogetherWithNext) {
517
 
        this.keepTogetherWithNext = keepTogetherWithNext;
518
 
        this.modified = this.modified | MODIFIED_KEEP_TOGETHER_WITH_NEXT;
519
 
    }
520
 
    
521
 
    /**
522
 
     * Handles the inheritance of paragraph style settings. All settings that
523
 
     * have not been modified will be inherited from the base RtfParagraphStyle.
524
 
     * If this RtfParagraphStyle is not based on another one, then nothing happens.
525
 
     */
526
 
    public void handleInheritance() {
527
 
        if(this.basedOnName != null && this.document.getDocumentHeader().getRtfParagraphStyle(this.basedOnName) != null) {
528
 
            this.baseStyle = this.document.getDocumentHeader().getRtfParagraphStyle(this.basedOnName);
529
 
            this.baseStyle.handleInheritance();
530
 
            if(!((this.modified & MODIFIED_ALIGNMENT) == MODIFIED_ALIGNMENT)) {
531
 
                this.alignment = this.baseStyle.getAlignment();
532
 
            }
533
 
            if(!((this.modified & MODIFIED_INDENT_LEFT) == MODIFIED_INDENT_LEFT)) {
534
 
                this.indentLeft = this.baseStyle.getIndentLeft();
535
 
            }
536
 
            if(!((this.modified & MODIFIED_INDENT_RIGHT) == MODIFIED_INDENT_RIGHT)) {
537
 
                this.indentRight = this.baseStyle.getIndentRight();
538
 
            }
539
 
            if(!((this.modified & MODIFIED_SPACING_BEFORE) == MODIFIED_SPACING_BEFORE)) {
540
 
                this.spacingBefore = this.baseStyle.getSpacingBefore();
541
 
            }
542
 
            if(!((this.modified & MODIFIED_SPACING_AFTER) == MODIFIED_SPACING_AFTER)) {
543
 
                this.spacingAfter = this.baseStyle.getSpacingAfter();
544
 
            }
545
 
            if(!((this.modified & MODIFIED_FONT_NAME) == MODIFIED_FONT_NAME)) {
546
 
                setFontName(this.baseStyle.getFontName());
547
 
            }
548
 
            if(!((this.modified & MODIFIED_FONT_SIZE) == MODIFIED_FONT_SIZE)) {
549
 
                setSize(this.baseStyle.getFontSize());
550
 
            }
551
 
            if(!((this.modified & MODIFIED_FONT_STYLE) == MODIFIED_FONT_STYLE)) {
552
 
                setStyle(this.baseStyle.getFontStyle());
553
 
            }
554
 
            if(!((this.modified & MODIFIED_FONT_COLOR) == MODIFIED_FONT_COLOR)) {
555
 
                setColor(this.baseStyle.color());
556
 
            }
557
 
            if(!((this.modified & MODIFIED_LINE_LEADING) == MODIFIED_LINE_LEADING)) {
558
 
                setLineLeading(this.baseStyle.getLineLeading());
559
 
            }
560
 
            if(!((this.modified & MODIFIED_KEEP_TOGETHER) == MODIFIED_KEEP_TOGETHER)) {
561
 
                setKeepTogether(this.baseStyle.getKeepTogether());
562
 
            }
563
 
            if(!((this.modified & MODIFIED_KEEP_TOGETHER_WITH_NEXT) == MODIFIED_KEEP_TOGETHER_WITH_NEXT)) {
564
 
                setKeepTogetherWithNext(this.baseStyle.getKeepTogetherWithNext());
565
 
            }
566
 
        }
567
 
    }
568
 
    
569
 
    /**
570
 
     * Writes the settings of this RtfParagraphStyle.
571
 
     * 
572
 
     * @return A byte array with the settings of this RtfParagraphStyle.
573
 
     */
574
 
    private byte[] writeParagraphSettings() {
575
 
        ByteArrayOutputStream result = new ByteArrayOutputStream();
576
 
        try {
577
 
            if(this.keepTogether) {
578
 
                result.write(RtfParagraphStyle.KEEP_TOGETHER);
579
 
            }
580
 
            if(this.keepTogetherWithNext) {
581
 
                result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
582
 
            }
583
 
            switch (alignment) {
584
 
                case Element.ALIGN_LEFT:
585
 
                    result.write(RtfParagraphStyle.ALIGN_LEFT);
586
 
                    break;
587
 
                case Element.ALIGN_RIGHT:
588
 
                    result.write(RtfParagraphStyle.ALIGN_RIGHT);
589
 
                    break;
590
 
                case Element.ALIGN_CENTER:
591
 
                    result.write(RtfParagraphStyle.ALIGN_CENTER);
592
 
                    break;
593
 
                case Element.ALIGN_JUSTIFIED:
594
 
                case Element.ALIGN_JUSTIFIED_ALL:
595
 
                    result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
596
 
                    break;
597
 
            }
598
 
            result.write(RtfParagraphStyle.INDENT_LEFT);
599
 
            result.write(intToByteArray(indentLeft));
600
 
            result.write(RtfParagraphStyle.INDENT_RIGHT);
601
 
            result.write(intToByteArray(indentRight));
602
 
            if(this.spacingBefore > 0) {
603
 
                result.write(RtfParagraphStyle.SPACING_BEFORE);
604
 
                result.write(intToByteArray(this.spacingBefore));
605
 
            }
606
 
            if(this.spacingAfter > 0) {
607
 
                result.write(RtfParagraphStyle.SPACING_AFTER);
608
 
                result.write(intToByteArray(this.spacingAfter));
609
 
            }
610
 
            if(this.lineLeading > 0) {
611
 
                result.write(RtfParagraph.LINE_SPACING);
612
 
                result.write(intToByteArray(this.lineLeading));
613
 
            }            
614
 
        } catch(IOException ioe) {
615
 
            ioe.printStackTrace();
616
 
        }
617
 
        return result.toByteArray();
618
 
    }
619
 
    
620
 
    /**
621
 
     * Writes the definition of this RtfParagraphStyle for the stylesheet list.
622
 
     */
623
 
    public byte[] writeDefinition() {
624
 
        ByteArrayOutputStream result = new ByteArrayOutputStream();
625
 
        try {
626
 
            result.write("{".getBytes());
627
 
            result.write("\\style".getBytes());
628
 
            result.write("\\s".getBytes());
629
 
            result.write(intToByteArray(this.styleNumber));
630
 
            result.write(RtfBasicElement.DELIMITER);
631
 
            result.write(writeParagraphSettings());
632
 
            result.write(super.writeBegin());
633
 
            result.write(RtfBasicElement.DELIMITER);
634
 
            result.write(this.styleName.getBytes());
635
 
            result.write(";".getBytes());
636
 
            result.write("}".getBytes());
637
 
            if(this.document.getDocumentSettings().isOutputDebugLineBreaks()) {
638
 
                result.write('\n');
639
 
            }
640
 
        } catch(IOException ioe) {
641
 
            ioe.printStackTrace();
642
 
        }
643
 
        return result.toByteArray();
644
 
    }
645
 
    
646
 
    /**
647
 
     * Writes the start information of this RtfParagraphStyle.
648
 
     */
649
 
    public byte[] writeBegin() {
650
 
        ByteArrayOutputStream result = new ByteArrayOutputStream();
651
 
        try {
652
 
            result.write("\\s".getBytes());
653
 
            result.write(intToByteArray(this.styleNumber));
654
 
            result.write(writeParagraphSettings());
655
 
        } catch(IOException ioe) {
656
 
            ioe.printStackTrace();
657
 
        }
658
 
        return result.toByteArray();
659
 
    }
660
 
    
661
 
    /**
662
 
     * Unused
663
 
     * @return An empty byte array.
664
 
     */
665
 
    public byte[] writeEnd() {
666
 
        return new byte[0];
667
 
    }
668
 
    
669
 
    /**
670
 
     * Unused
671
 
     * @return An empty byte array.
672
 
     */
673
 
    public byte[] write() {
674
 
        return new byte[0];
675
 
    }
676
 
    
677
 
    /**
678
 
     * Tests whether two RtfParagraphStyles are equal. Equality
679
 
     * is determined via the name.
680
 
     */
681
 
    public boolean equals(Object o) {
682
 
        if(o == null || !(o instanceof RtfParagraphStyle)) {
683
 
            return false;
684
 
        }
685
 
        RtfParagraphStyle paragraphStyle = (RtfParagraphStyle) o;
686
 
        boolean result = this.getStyleName().equals(paragraphStyle.getStyleName());
687
 
        return result;
688
 
    }
689
 
    
690
 
    /**
691
 
     * Gets the hash code of this RtfParagraphStyle.
692
 
     */
693
 
    public int hashCode() {
694
 
        return this.styleName.hashCode();
695
 
    }
696
 
    
697
 
    /**
698
 
     * Gets the number of this RtfParagraphStyle in the stylesheet list.
699
 
     * 
700
 
     * @return The number of this RtfParagraphStyle in the stylesheet list.
701
 
     */
702
 
    private int getStyleNumber() {
703
 
        return this.styleNumber;
704
 
    }
705
 
    
706
 
    /**
707
 
     * Sets the number of this RtfParagraphStyle in the stylesheet list.
708
 
     * 
709
 
     * @param styleNumber The number to use.
710
 
     */
711
 
    protected void setStyleNumber(int styleNumber) {
712
 
        this.styleNumber = styleNumber;
713
 
    }
714
 
}