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

📄 chunk.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 *            the value of the attribute	 * @return this <CODE>Chunk</CODE>	 */	private Chunk setAttribute(String name, Object obj) {		if (attributes == null)			attributes = new HashMap();		attributes.put(name, obj);		return this;	}	// the attributes are ordered as they appear in the book 'iText in Action'	/** Key for text horizontal scaling. */	public static final String HSCALE = "HSCALE";	/**	 * Sets the text horizontal scaling. A value of 1 is normal and a value of	 * 0.5f shrinks the text to half it's width.	 * 	 * @param scale	 *            the horizontal scaling factor	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setHorizontalScaling(float scale) {		return setAttribute(HSCALE, new Float(scale));	}	/**	 * Gets the horizontal scaling.	 * 	 * @return a percentage in float	 */	public float getHorizontalScaling() {		if (attributes == null)			return 1f;		Float f = (Float) attributes.get(HSCALE);		if (f == null)			return 1f;		return f.floatValue();	}	/** Key for underline. */	public static final String UNDERLINE = "UNDERLINE";	/**	 * Sets an horizontal line that can be an underline or a strikethrough.	 * Actually, the line can be anywhere vertically and has always the <CODE>	 * Chunk</CODE> width. Multiple call to this method will produce multiple	 * lines.	 * 	 * @param thickness	 *            the absolute thickness of the line	 * @param yPosition	 *            the absolute y position relative to the baseline	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setUnderline(float thickness, float yPosition) {		return setUnderline(null, thickness, 0f, yPosition, 0f,				PdfContentByte.LINE_CAP_BUTT);	}	/**	 * Sets an horizontal line that can be an underline or a strikethrough.	 * Actually, the line can be anywhere vertically and has always the <CODE>	 * Chunk</CODE> width. Multiple call to this method will produce multiple	 * lines.	 * 	 * @param color	 *            the color of the line or <CODE>null</CODE> to follow the	 *            text color	 * @param thickness	 *            the absolute thickness of the line	 * @param thicknessMul	 *            the thickness multiplication factor with the font size	 * @param yPosition	 *            the absolute y position relative to the baseline	 * @param yPositionMul	 *            the position multiplication factor with the font size	 * @param cap	 *            the end line cap. Allowed values are	 *            PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND	 *            and PdfContentByte.LINE_CAP_PROJECTING_SQUARE	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setUnderline(Color color, float thickness, float thicknessMul,			float yPosition, float yPositionMul, int cap) {		if (attributes == null)			attributes = new HashMap();		Object obj[] = {				color,				new float[] { thickness, thicknessMul, yPosition, yPositionMul, cap } };		Object unders[][] = Utilities.addToArray((Object[][]) attributes.get(UNDERLINE),				obj);		return setAttribute(UNDERLINE, unders);	}		/** Key for sub/superscript. */	public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT";		/**	 * Sets the text displacement relative to the baseline. Positive values rise	 * the text, negative values lower the text.	 * <P>	 * It can be used to implement sub/superscript.	 * 	 * @param rise	 *            the displacement in points	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setTextRise(float rise) {		return setAttribute(SUBSUPSCRIPT, new Float(rise));	}	/**	 * Gets the text displacement relative to the baseline.	 * 	 * @return a displacement in points	 */	public float getTextRise() {		if (attributes != null && attributes.containsKey(SUBSUPSCRIPT)) {			Float f = (Float) attributes.get(SUBSUPSCRIPT);			return f.floatValue();		}		return 0.0f;	}	/** Key for text skewing. */	public static final String SKEW = "SKEW";	/**	 * Skews the text to simulate italic and other effects. Try <CODE>alpha=0	 * </CODE> and <CODE>beta=12</CODE>.	 * 	 * @param alpha	 *            the first angle in degrees	 * @param beta	 *            the second angle in degrees	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setSkew(float alpha, float beta) {		alpha = (float) Math.tan(alpha * Math.PI / 180);		beta = (float) Math.tan(beta * Math.PI / 180);		return setAttribute(SKEW, new float[] { alpha, beta });	}	/** Key for background. */	public static final String BACKGROUND = "BACKGROUND";	/**	 * Sets the color of the background <CODE>Chunk</CODE>.	 * 	 * @param color	 *            the color of the background	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setBackground(Color color) {		return setBackground(color, 0, 0, 0, 0);	}	/**	 * Sets the color and the size of the background <CODE>Chunk</CODE>.	 * 	 * @param color	 *            the color of the background	 * @param extraLeft	 *            increase the size of the rectangle in the left	 * @param extraBottom	 *            increase the size of the rectangle in the bottom	 * @param extraRight	 *            increase the size of the rectangle in the right	 * @param extraTop	 *            increase the size of the rectangle in the top	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setBackground(Color color, float extraLeft, float extraBottom,			float extraRight, float extraTop) {		return setAttribute(BACKGROUND, new Object[] { color,				new float[] { extraLeft, extraBottom, extraRight, extraTop } });	}	/** Key for text rendering mode. */	public static final String TEXTRENDERMODE = "TEXTRENDERMODE";	/**	 * Sets the text rendering mode. It can outline text, simulate bold and make	 * text invisible.	 * 	 * @param mode	 *            the text rendering mode. It can be <CODE>	 *            PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,<CODE>	 *            PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE>,<CODE>	 *            PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE> and <CODE>	 *            PdfContentByte.TEXT_RENDER_MODE_INVISIBLE</CODE>.	 * @param strokeWidth	 *            the stroke line width for the modes <CODE>	 *            PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE> and <CODE>	 *            PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE>.	 * @param strokeColor	 *            the stroke color or <CODE>null</CODE> to follow the text	 *            color	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setTextRenderMode(int mode, float strokeWidth,			Color strokeColor) {		return setAttribute(TEXTRENDERMODE, new Object[] { new Integer(mode),				new Float(strokeWidth), strokeColor });	}	/** Key for split character. */	public static final String SPLITCHARACTER = "SPLITCHARACTER";	/**	 * Sets the split characters.	 * 	 * @param splitCharacter	 *            the <CODE>SplitCharacter</CODE> interface	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setSplitCharacter(SplitCharacter splitCharacter) {		return setAttribute(SPLITCHARACTER, splitCharacter);	}	/** Key for hyphenation. */	public static final String HYPHENATION = "HYPHENATION";		/**	 * sets the hyphenation engine to this <CODE>Chunk</CODE>.	 * 	 * @param hyphenation	 *            the hyphenation engine	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setHyphenation(HyphenationEvent hyphenation) {		return setAttribute(HYPHENATION, hyphenation);	}	/** Key for remote goto. */	public static final String REMOTEGOTO = "REMOTEGOTO";	/**	 * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.	 * 	 * @param filename	 *            the file name of the destination document	 * @param name	 *            the name of the destination to go to	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setRemoteGoto(String filename, String name) {		return setAttribute(REMOTEGOTO, new Object[] { filename, name });	}	/**	 * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.	 * 	 * @param filename	 *            the file name of the destination document	 * @param page	 *            the page of the destination to go to. First page is 1	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setRemoteGoto(String filename, int page) {		return setAttribute(REMOTEGOTO, new Object[] { filename,				new Integer(page) });	}	/** Key for local goto. */	public static final String LOCALGOTO = "LOCALGOTO";		/**	 * Sets a local goto for this <CODE>Chunk</CODE>.	 * <P>	 * There must be a local destination matching the name.	 * 	 * @param name	 *            the name of the destination to go to	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setLocalGoto(String name) {		return setAttribute(LOCALGOTO, name);	}	/** Key for local destination. */	public static final String LOCALDESTINATION = "LOCALDESTINATION";	/**	 * Sets a local destination for this <CODE>Chunk</CODE>.	 * 	 * @param name	 *            the name for this destination	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setLocalDestination(String name) {		return setAttribute(LOCALDESTINATION, name);	}	/** Key for generic tag. */	public static final String GENERICTAG = "GENERICTAG";	/**	 * Sets the generic tag <CODE>Chunk</CODE>.	 * <P>	 * The text for this tag can be retrieved with <CODE>PdfPageEvent</CODE>.	 * 	 * @param text	 *            the text for the tag	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setGenericTag(String text) {		return setAttribute(GENERICTAG, text);	}		/** Key for image. */	public static final String IMAGE = "IMAGE";	/**	 * Returns the image.	 * 	 * @return the image	 */	public Image getImage() {		if (attributes == null)			return null;		Object obj[] = (Object[]) attributes.get(Chunk.IMAGE);		if (obj == null)			return null;		else {			return (Image) obj[0];		}	}		/** Key for Action. */	public static final String ACTION = "ACTION";	/**	 * Sets an action for this <CODE>Chunk</CODE>.	 * 	 * @param action	 *            the action	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setAction(PdfAction action) {		return setAttribute(ACTION, action);	}	/**	 * Sets an anchor for this <CODE>Chunk</CODE>.	 * 	 * @param url	 *            the <CODE>URL</CODE> to link to	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setAnchor(URL url) {		return setAttribute(ACTION, new PdfAction(url.toExternalForm()));	}	/**	 * Sets an anchor for this <CODE>Chunk</CODE>.	 * 	 * @param url	 *            the url to link to	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setAnchor(String url) {		return setAttribute(ACTION, new PdfAction(url));	}		/** Key for newpage. */	public static final String NEWPAGE = "NEWPAGE";	/**	 * Sets a new page tag..	 * 	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setNewPage() {		return setAttribute(NEWPAGE, null);	}	/** Key for annotation. */	public static final String PDFANNOTATION = "PDFANNOTATION";	/**	 * Sets a generic annotation to this <CODE>Chunk</CODE>.	 * 	 * @param annotation	 *            the annotation	 * @return this <CODE>Chunk</CODE>	 */	public Chunk setAnnotation(PdfAnnotation annotation) {		return setAttribute(PDFANNOTATION, annotation);	}		/**	 * @see com.lowagie.text.Element#isContent()	 * @since	iText 2.0.8	 */	public boolean isContent() {		return true;	}	/**	 * @see com.lowagie.text.Element#isNestable()	 * @since	iText 2.0.8	 */	public boolean isNestable() {		return true;	}	/**     * Returns the hyphenation (if present).     * @since	2.1.2	 */    public HyphenationEvent getHyphenation() {        if (attributes == null) return null;        return (HyphenationEvent) attributes.get(Chunk.HYPHENATION);	}		// keys used in PdfChunk		/** Key for color. */	public static final String COLOR = "COLOR";	/** Key for encoding. */	public static final String ENCODING = "ENCODING";}

⌨️ 快捷键说明

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