📄 layoutbox.java
字号:
* @since 1.2.10 */ public float addTab(float[] stops) { return box.addTab(stops); } /** * Return true if the LayoutBox is empty, false if it's not */ public boolean isEmpty() { return box.isEmpty(); } /** * Return the height of the positioned items in the LayoutBox, in points * @return the height of the LayoutBox */ public float getHeight() { return box.getHeight(); } /** * Return true if the LayoutBox has been flushed - ie. if there are any items * of text that are still to be positioned. A LayoutBox should be flushed before * the {@link #getBoxes} or the {@link PDFPage#drawLayoutBox PDFPage.drawLayoutBox} methods are called. * @see #flush */ public boolean isFlushed() { return box.isFlushed(); } /** * Flush the flowbox. Flushing causes any items which have not yet been positioned * (specifically any text on the last incomplete line of the LayoutBox) to be positioned. * @see #isFlushed */ public void flush() { box.flush(); } /** * Return the list of boxes which make up the LayoutBox. Unless the LayoutBox has * been {@link #flush flushed}, some of these items may not have a position * specified. * @return a list of {@link LayoutBox.Box} objects which make up the visible contents * of the LayoutBox. * @see #isFlushed * @see #flush */ public Box[] getBoxes() { org.faceless.pdf2.LayoutBox.Box[] newboxes = box.getBoxes(); Box[] oldboxes = new Box[newboxes.length]; for (int i=0;i<newboxes.length;i++) { oldboxes[i]=(Box)PeeredObject.getPeer(newboxes[i]); } return oldboxes; } /** * Return the style of the LayoutBox, as set by {@link #setStyle} */ public PDFStyle getStyle() { return (PDFStyle)PeeredObject.getPeer(box.getStyle()); } //------------------------------------------------------------------------- /** * Split a LayoutBox into two boxes at the specified height. The current box * is shortened and a new box returned containing all the content below the * requested row. * @return a new LayoutBox containing all the data below the requested row. * @since 1.2.1 */ public LayoutBox splitAt(float splitpos) { return (LayoutBox)PeeredObject.getPeer(box.splitAt(splitpos)); } /** * Return the number of lines in the LayoutBox. Blank lines are not * included in the total. The LayoutBox should be flushed before * calling this method to ensure the correct result. * @since 1.2.1 */ public int getNumberOfLines() { return box.getNumberOfLines(); } /** * <p> * A class representing a Box, several of which make up the visible * content of a LayoutBox. Boxs on their own represent nothing but a * space in the LayoutBox layout - if the rectangle is to be filled with * some content (an image, for example), that has to be done separately. * </p><p> * The {@link LayoutBox.Text} class is a subclass of Box which is used to * specifically display a phrase of text. * </p> * @see #getBoxes * @since 1.2 */ public static class Box extends PeeredObject { final org.faceless.pdf2.LayoutBox.Box box; Box(org.faceless.pdf2.LayoutBox.Box box) { this.box=box; } Object getPeer() { return box; } /** * Return which line number this text belongs to. The first line of text in the * LayoutBox has line number 0, the next 1 and so on. Blank lines (created by * one or more calls to {@link #addLineBreak} do not count as lines. * Left or right floating boxes will have the same line number as the text next * to the top of the box. If the LayoutBox has not been flushed then this method * may return -1, indicating the line number hasn't been set yet. * @since 1.2.1 */ public final int getLineNumber() { return box.getLineNumber(); } /** * Return the left edge of this Box relative to the parent LayoutBox, in points */ public final float getLeft() { return box.getLeft(); } /** * Return the right edge of this Box relative to the parent LayoutBox, in points */ public final float getRight() { return box.getRight(); } /** * Return the top edge of this Box relative to the parent LayoutBox, in points. * Note that in standard PDF geometry, (0,0) is at the bottom left of the page, so * this value will usually be negative, indicating the top is below the top of the * LayoutBox on the page. * @see #getBottom * @see #getLineTop */ public final float getTop() { return box.getTop(); } /** * Return the bottom edge of this Box relative to the parent LayoutBox, in points. * @see #getTop * @see #getLineBottom */ public final float getBottom() { return box.getBottom(); } /** * Return the top edge of the line this Box sits on, relative to the parent * LayoutBox, in points. Note that in standard PDF geometry, (0,0) is at the bottom * left of the page, so this value will usually be negative, indicating the top is * below the top of the LayoutBox on the page. The LayoutBox should be flushed * before this method is called to ensure the correct result * @since 1.2.1 * @see #getLineBottom * @see #getTop */ public final float getLineTop() { return box.getLineTop(); } /** * Return the bottom edge of the line this Box sits on, relative to the parent * LayoutBox, in points. Note that in standard PDF geometry, (0,0) is at the bottom * left of the page, so this value will usually be negative, indicating the top is * below the top of the LayoutBox on the page. The LayoutBox should be flushed * before this method is called to ensure the correct result * @since 1.2.1 * @see #getLineTop * @see #getTop */ public final float getLineBottom() { return box.getLineBottom(); } public String toString() { return "{l="+getLeft()+" r="+getRight()+" t="+getTop()+" b="+getBottom()+" lt="+getLineTop()+" lb="+getLineBottom()+" #"+getLineNumber()+"}"; } /** * Set an optional image which goes with this Box. The image will be automatically * drawn when the LayoutBox is drawn to a page. */ public void setImage(PDFImage image) { box.setImage(image.image); } /** * Return the optional image set by the {@link #setImage setImage} method, * or <code>null</code> if no image was defined. */ public PDFImage getImage() { return (PDFImage)PeeredObject.getPeer(box.getImage()); } } /** * The <tt>Text</tt> class is a subclass of {@link LayoutBox.Box} which * is specifically for displaying Text. * @since 1.2 */ public static class Text extends Box { Text(org.faceless.pdf2.LayoutBox.Text text) { super(text); } /** * Return the style of this Text item */ public PDFStyle getStyle() { return (PDFStyle)PeeredObject.getPeer(((org.faceless.pdf2.LayoutBox.Text)this.box).getStyle()); } /** * Return the content of this Text item as a String. */ public String getText() { return ((org.faceless.pdf2.LayoutBox.Text)this.box).getText(); } /** * Return the next "twin" of this Text item, or <code>null</code> if none * exist. A "twin" is a second (or third, fourth etc.) <code>Text</code> object * which was created when a phrase of text was split at the end of the line. */ public Text getNextTwin() { return (Text)PeeredObject.getPeer(((org.faceless.pdf2.LayoutBox.Text)this.box).getNextTwin()); } /** * Replace the contents of this Text box with a different line of text. * This method does <b>not</b> reflow the text, so you need to ensure * that the contents of the box are the same length by sticking to digits * or using a fixed-width font. This method is not recommended for normal * use. * @since 1.2.1 */ public void setText(String s) { ((org.faceless.pdf2.LayoutBox.Text)this.box).setText(s); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -