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

📄 chunk.java

📁 iText可以制作中文PDF文件的JAVA源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: Chunk.java,v 1.70 2002/11/19 08:33:32 blowagie Exp $ * $Name:  $ * * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie. * * 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;import java.awt.Color;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Hashtable;import java.util.Properties;import java.util.Set;import java.net.URL;import com.lowagie.text.pdf.PdfAction;import com.lowagie.text.pdf.PdfAnnotation;import com.lowagie.text.pdf.HyphenationEvent;import com.lowagie.text.markup.MarkupTags;import com.lowagie.text.markup.MarkupParser;/** * This is the smallest significant part of text that can be added to a document. * <P> * Most elements can be divided in one or more <CODE>Chunk</CODE>s. * A chunk is a <CODE>String</CODE> with a certain <CODE>Font</CODE>. * all other layoutparameters should be defined in the object to which * this chunk of text is added. * <P> * Example: * <BLOCKQUOTE><PRE> * <STRONG>Chunk chunk = new Chunk("Hello world", FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0, 0)));</STRONG> * document.add(chunk); * </PRE></BLOCKQUOTE> */public class Chunk implements Element, MarkupAttributes {// public static membervariables        public static final String OBJECT_REPLACEMENT_CHARACTER = "\ufffc";/** This is a Chunk containing a newline. */    public static final Chunk NEWLINE = new Chunk("\n");/** Key for sub/superscript. */    public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT";/** Key for underline. */    public static final String UNDERLINE = "UNDERLINE";/** Key for strikethru. */    public static final String STRIKETHRU = "STRIKETHRU";/** Key for color. */    public static final String COLOR = "COLOR";/** Key for encoding. */    public static final String ENCODING = "ENCODING";/** Key for remote goto. */    public static final String REMOTEGOTO = "REMOTEGOTO";/** Key for local goto. */    public static final String LOCALGOTO = "LOCALGOTO";/** Key for local destination. */    public static final String LOCALDESTINATION = "LOCALDESTINATION";/** Key for image. */    public static final String IMAGE = "IMAGE";/** Key for generic tag. */    public static final String GENERICTAG = "GENERICTAG";/** Key for newpage. */    public static final String NEWPAGE = "NEWPAGE";/** Key for split character. */    public static final String SPLITCHARACTER = "SPLITCHARACTER";/** Key for Action. */    public static final String ACTION = "ACTION";/** Key for background. */    public static final String BACKGROUND = "BACKGROUND";/** Key for annotation. */    public static final String PDFANNOTATION = "PDFANNOTATION";/** Key for hyphenation. */    public static final String HYPHENATION = "HYPHENATION";// member variables/** This is the content of this chunk of text. */    protected StringBuffer content = null;/** This is the <CODE>Font</CODE> of this chunk of text. */    protected Font font = null;/** Contains some of the attributes for this Chunk. */    protected HashMap attributes = null;/** Contains extra markupAttributes */    protected Properties markupAttributes = null;// constructors/** * Empty constructor. */    protected Chunk() {    }/** * Constructs a chunk of text with a certain content and a certain <CODE>Font</CODE>. * * @param	content		the content * @param	font		the font */    public Chunk(String content, Font font) {        this.content = new StringBuffer(content);        this.font = font;    }/** * Constructs a chunk of text with a certain content, without specifying a <CODE>Font</CODE>. * * @param	content		the content */    public Chunk(String content) {        this(content, new Font());    }/** * Constructs a chunk containing an <CODE>Image</CODE>. * * @param image the image * @param offsetX the image offset in the x direction * @param offsetY the image offset in the y direction */    public Chunk(Image image, float offsetX, float offsetY) {        this(OBJECT_REPLACEMENT_CHARACTER, new Font());        Image copyImage = Image.getInstance(image);        copyImage.setAbsolutePosition(Float.NaN, Float.NaN);        setAttribute(IMAGE, new Object[]{copyImage, new Float(offsetX), new Float(offsetY), new Boolean(false)});    }/** * Constructs a chunk containing an <CODE>Image</CODE>. * * @param image         the image * @param offsetX       the image offset in the x direction * @param offsetY       the image offset in the y direction * @param changeLeading true if the leading has to be adapted to the image */    public Chunk(Image image, float offsetX, float offsetY, boolean changeLeading) {        this(OBJECT_REPLACEMENT_CHARACTER, new Font());        setAttribute(IMAGE, new Object[]{image, new Float(offsetX), new Float(offsetY), new Boolean(changeLeading)});    }/** * Returns a <CODE>Chunk</CODE> that has been constructed taking in account * the value of some <VAR>attributes</VAR>. * * @param	attributes		Some attributes */    public Chunk(Properties attributes) {        this("", FontFactory.getFont(attributes));        String value;        if ((value = (String)attributes.remove(ElementTags.ITEXT)) != null) {            append(value);        }        if ((value = (String)attributes.remove(ElementTags.LOCALGOTO)) != null) {            setLocalGoto(value);        }        if ((value = (String)attributes.remove(ElementTags.REMOTEGOTO)) != null) {            String destination = (String) attributes.remove(ElementTags.DESTINATION);            String page = (String) attributes.remove(ElementTags.PAGE);            if (page != null) {                setRemoteGoto(value, Integer.valueOf(page).intValue());            }            else if (destination != null) {                setRemoteGoto(value, destination);            }        }        if ((value = (String)attributes.remove(ElementTags.LOCALDESTINATION)) != null) {            setLocalDestination(value);        }        if ((value = (String)attributes.remove(ElementTags.SUBSUPSCRIPT)) != null) {            setTextRise(Float.valueOf(value + "f").floatValue());        }        if ((value = (String)attributes.remove(MarkupTags.CSS_VERTICALALIGN)) != null && value.endsWith("%")) {            float p = Float.valueOf(value.substring(0, value.length() - 1) + "f").floatValue() / 100f;            setTextRise(p * font.size());        }        if ((value = (String)attributes.remove(ElementTags.GENERICTAG)) != null) {            setGenericTag(value);        }        if ((value = (String)attributes.remove(ElementTags.BACKGROUNDCOLOR)) != null) {            setBackground(MarkupParser.decodeColor(value));        }        if (attributes.size() > 0) setMarkupAttributes(attributes);    }    // implementation of the Element-methods/** * Processes the element by adding it (or the different parts) to an * <CODE>ElementListener</CODE>. * * @param	listener	an <CODE>ElementListener</CODE> * @return	<CODE>true</CODE> if the element was processed successfully */    public boolean process(ElementListener listener) {        try {            return listener.add(this);        }        catch(DocumentException de) {            return false;        }    }/** * Gets the type of the text element. * * @return	a type */    public int type() {        return Element.CHUNK;    }/** * Gets all the chunks in this element. * * @return	an <CODE>ArrayList</CODE> */    public ArrayList getChunks() {        ArrayList tmp = new ArrayList();        tmp.add(this);        return tmp;    }    // methods/** * appends some text to this <CODE>Chunk</CODE>. * * @param	string <CODE>String</CODE>

⌨️ 快捷键说明

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