📄 chunk.java
字号:
* 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,
(float) 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 relatiev 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);
}
// keys used in PdfChunk
/** Key for color. */
public static final String COLOR = "COLOR";
/** Key for encoding. */
public static final String ENCODING = "ENCODING";
// deprecated
/**
* Returns a <CODE>Chunk</CODE> that has been constructed taking in
* account the value of some <VAR>attributes </VAR>.
*
* @param attributes
* Some attributes
* @deprecated use ElementFactory.getChunk()
*/
public Chunk(java.util.Properties attributes) {
this(com.lowagie.text.factories.ElementFactory.getChunk(attributes));
}
/**
* Returns the content of this <CODE>Chunk</CODE>.
*
* @return a <CODE>String</CODE>
* @deprecated Use {@link #getContent()} instead
*/
public String content() {
return getContent();
}
/**
* Gets the font of this <CODE>Chunk</CODE>.
*
* @return a <CODE>Font</CODE>
* @deprecated Use {@link #getFont()} instead
*/
public Font font() {
return getFont();
}
/**
* Gets the keys of a Hashtable
*
* @param table
* a Hashtable
* @return the keyset of a Hashtable (or an empty set if table is null)
* @deprecated Use {@link Utilities#getKeySet(Hashtable)} instead
*/
public static Set getKeySet(Hashtable table) {
return Utilities.getKeySet(table);
}
/**
* Utility method to extend an array.
*
* @param original
* the original array or <CODE>null</CODE>
* @param item
* the item to be added to the array
* @return a new array with the item appended
* @deprecated Use {@link Utilities#addToArray(Object[][],Object[])} instead
*/
public static Object[][] addToArray(Object original[][], Object item[]) {
return Utilities.addToArray(original, item);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -