⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtfparagraphstyle.java

📁 有关对pdf操作的代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: RtfParagraphStyle.java 3124 2008-02-07 20:03:47Z hallm $ * $Name$ * * Copyright 2001, 2002, 2003, 2004 by Mark Hall * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the * provisions of LGPL are applicable instead of those above.  If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */package com.lowagie.text.rtf.style;import java.awt.Color;import java.io.IOException;import java.io.OutputStream;import com.lowagie.text.Element;import com.lowagie.text.Font;import com.lowagie.text.rtf.RtfBasicElement;import com.lowagie.text.rtf.document.RtfDocument;import com.lowagie.text.rtf.text.RtfParagraph;/** * The RtfParagraphStyle stores all style/formatting attributes of a RtfParagraph. * Additionally it also supports the style name system available in RTF. The RtfParagraphStyle * is a Font and can thus be used as such. To use the stylesheet functionality * it needs to be set as the font of a Paragraph. Otherwise it will work like a * RtfFont. It also supports inheritance of styles. *  * @version $Id: RtfParagraphStyle.java 3124 2008-02-07 20:03:47Z hallm $ * @author Mark Hall (mhall@edu.uni-klu.ac.at) * @author Thomas Bickel (tmb99@inode.at) */public class RtfParagraphStyle extends RtfFont {    /**     * Constant for left alignment     */    public static final byte[] ALIGN_LEFT = "\\ql".getBytes();    /**     * Constant for right alignment     */    public static final byte[] ALIGN_RIGHT = "\\qr".getBytes();    /**     * Constant for center alignment     */    public static final byte[] ALIGN_CENTER = "\\qc".getBytes();    /**     * Constant for justified alignment     */    public static final byte[] ALIGN_JUSTIFY = "\\qj".getBytes();    /**     * Constant for the first line indentation     */    public static final byte[] FIRST_LINE_INDENT = "\\fi".getBytes();    /**     * Constant for left indentation     */    public static final byte[] INDENT_LEFT = "\\li".getBytes();    /**     * Constant for right indentation     */    public static final byte[] INDENT_RIGHT = "\\ri".getBytes();    /**     * Constant for keeping the paragraph together on one page     */    public static final byte[] KEEP_TOGETHER = "\\keep".getBytes();    /**     * Constant for keeping the paragraph together with the next one on one page     */    public static final byte[] KEEP_TOGETHER_WITH_NEXT = "\\keepn".getBytes();    /**     * Constant for the space after the paragraph.     */    public static final byte[] SPACING_AFTER = "\\sa".getBytes();    /**     * Constant for the space before the paragraph.     */    public static final byte[] SPACING_BEFORE = "\\sb".getBytes();    /**     * The NORMAL/STANDARD style.     */    public static final RtfParagraphStyle STYLE_NORMAL = new RtfParagraphStyle("Normal", "Arial", 12, Font.NORMAL, Color.black);    /**     * The style for level 1 headings.     */    public static final RtfParagraphStyle STYLE_HEADING_1 = new RtfParagraphStyle("heading 1", "Normal");    /**     * The style for level 2 headings.     */    public static final RtfParagraphStyle STYLE_HEADING_2 = new RtfParagraphStyle("heading 2", "Normal");    /**     * The style for level 3 headings.     */    public static final RtfParagraphStyle STYLE_HEADING_3 = new RtfParagraphStyle("heading 3", "Normal");    /**     * Initializes the properties of the styles.     */    static {        STYLE_HEADING_1.setSize(16);        STYLE_HEADING_1.setStyle(Font.BOLD);        STYLE_HEADING_2.setSize(14);        STYLE_HEADING_2.setStyle(Font.BOLDITALIC);        STYLE_HEADING_3.setSize(13);        STYLE_HEADING_3.setStyle(Font.BOLD);    }        /**     * No modification has taken place when compared to the RtfParagraphStyle this RtfParagraphStyle     * is based on. These modification markers are used to determine what needs to be     * inherited and what not from the parent RtfParagraphStyle.     */    private static final int MODIFIED_NONE = 0;    /**     * The alignment has been modified.     */    private static final int MODIFIED_ALIGNMENT = 1;    /**     * The left indentation has been modified.     */    private static final int MODIFIED_INDENT_LEFT = 2;    /**     * The right indentation has been modified.     */    private static final int MODIFIED_INDENT_RIGHT = 4;    /**     * The spacing before a paragraph has been modified.     */    private static final int MODIFIED_SPACING_BEFORE = 8;    /**     * The spacing after a paragraph has been modified.     */    private static final int MODIFIED_SPACING_AFTER = 16;    /**     * The font name has been modified.     */    private static final int MODIFIED_FONT_NAME = 32;    /**     * The font style has been modified.     */    private static final int MODIFIED_FONT_SIZE = 64;    /**     * The font size has been modified.     */    private static final int MODIFIED_FONT_STYLE = 128;    /**     * The font color has been modified.     */    private static final int MODIFIED_FONT_COLOR = 256;    /**     * The line leading has been modified.      */    private static final int MODIFIED_LINE_LEADING = 512;    /**     * The paragraph keep together setting has been modified.     */    private static final int MODIFIED_KEEP_TOGETHER = 1024;    /**     * The paragraph keep together with next setting has been modified.     */    private static final int MODIFIED_KEEP_TOGETHER_WITH_NEXT = 2048;        /**     * The alignment of the paragraph.     */    private int alignment = Element.ALIGN_LEFT;    /**     * The indentation for the first line     */    private int firstLineIndent = 0;    /**     * The left indentation of the paragraph.     */    private int indentLeft = 0;    /**     * The right indentation of the paragraph.     */    private int indentRight = 0;    /**     * The spacing before a paragraph.     */    private int spacingBefore = 0;    /**     * The spacing after a paragraph.     */    private int spacingAfter = 0;    /**     * The line leading of the paragraph.     */    private int lineLeading = 0;    /**     * Whether this RtfParagraph must stay on one page.     */    private boolean keepTogether = false;    /**     * Whether this RtfParagraph must stay on the same page as the next paragraph.     */    private boolean keepTogetherWithNext = false;    /**     * The name of this RtfParagraphStyle.     */    private String styleName = "";    /**     * The name of the RtfParagraphStyle this RtfParagraphStyle is based on.     */    private String basedOnName = null;    /**     * The RtfParagraphStyle this RtfParagraphStyle is based on.     */    private RtfParagraphStyle baseStyle = null;    /**     * Which properties have been modified when compared to the base style.     */    private int modified = MODIFIED_NONE;    /**     * The number of this RtfParagraphStyle in the stylesheet list.     */    private int styleNumber = -1;        /**     * Constructs a new RtfParagraphStyle with the given attributes.     *      * @param styleName The name of this RtfParagraphStyle.     * @param fontName The name of the font to use for this RtfParagraphStyle.     * @param fontSize The size of the font to use for this RtfParagraphStyle.     * @param fontStyle The style of the font to use for this RtfParagraphStyle.     * @param fontColor The color of the font to use for this RtfParagraphStyle.     */    public RtfParagraphStyle(String styleName, String fontName, int fontSize, int fontStyle, Color fontColor) {        super(null, new RtfFont(fontName, fontSize, fontStyle, fontColor));        this.styleName = styleName;    }        /**     * Constructs a new RtfParagraphStyle that is based on an existing RtfParagraphStyle.     *      * @param styleName The name of this RtfParagraphStyle.     * @param basedOnName The name of the RtfParagraphStyle this RtfParagraphStyle is based on.     */    public RtfParagraphStyle(String styleName, String basedOnName) {        super(null, new Font());        this.styleName = styleName;        this.basedOnName = basedOnName;    }        /**     * Constructs a RtfParagraphStyle from another RtfParagraphStyle.     *      * INTERNAL USE ONLY     *      * @param doc The RtfDocument this RtfParagraphStyle belongs to.     * @param style The RtfParagraphStyle to copy settings from.     */    public RtfParagraphStyle(RtfDocument doc, RtfParagraphStyle style) {        super(doc, style);        this.document = doc;        this.styleName = style.getStyleName();        this.alignment = style.getAlignment();        this.firstLineIndent = (int)(style.getFirstLineIndent() * RtfBasicElement.TWIPS_FACTOR);        this.indentLeft = (int) (style.getIndentLeft() * RtfBasicElement.TWIPS_FACTOR);        this.indentRight = (int) (style.getIndentRight() * RtfBasicElement.TWIPS_FACTOR);        this.spacingBefore = (int) (style.getSpacingBefore() * RtfBasicElement.TWIPS_FACTOR);        this.spacingAfter = (int) (style.getSpacingAfter() * RtfBasicElement.TWIPS_FACTOR);        this.lineLeading = (int) (style.getLineLeading() * RtfBasicElement.TWIPS_FACTOR);        this.keepTogether = style.getKeepTogether();        this.keepTogetherWithNext = style.getKeepTogetherWithNext();        this.basedOnName = style.basedOnName;        this.modified = style.modified;        this.styleNumber = style.getStyleNumber();        if(this.document != null) {            setRtfDocument(this.document);        }    }    /**     * Gets the name of this RtfParagraphStyle.     *      * @return The name of this RtfParagraphStyle.     */    public String getStyleName() {        return this.styleName;    }        /**     * Gets the name of the RtfParagraphStyle this RtfParagraphStyle is based on.     *      * @return The name of the base RtfParagraphStyle.     */    public String getBasedOnName() {        return this.basedOnName;    }        /**     * Gets the alignment of this RtfParagraphStyle.     *      * @return The alignment of this RtfParagraphStyle.     */    public int getAlignment() {        return this.alignment;    }    /**     * Sets the alignment of this RtfParagraphStyle.     *      * @param alignment The alignment to use.     */    public void setAlignment(int alignment) {        this.modified = this.modified | MODIFIED_ALIGNMENT;        this.alignment = alignment;    }        /**     * Gets the first line indentation of this RtfParagraphStyle.     *      * @return The first line indentation of this RtfParagraphStyle.     */    public int getFirstLineIndent() {        return this.firstLineIndent;    }        /**     * Sets the first line indentation of this RtfParagraphStyle. It     * is relative to the left indentation.     *      * @param firstLineIndent The first line indentation to use.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -