📄 pdfline.java
字号:
return left + (width / 2f); default: return left; } } } /** * Checks if this line has to be justified. * * @return <CODE>true</CODE> if the alignment equals <VAR>ALIGN_JUSTIFIED</VAR> and there is some width left. */ public boolean hasToBeJustified() { return ((alignment == Element.ALIGN_JUSTIFIED || alignment == Element.ALIGN_JUSTIFIED_ALL) && width != 0); } /** * Resets the alignment of this line. * <P> * The alignment of the last line of for instance a <CODE>Paragraph</CODE> * that has to be justified, has to be reset to <VAR>ALIGN_LEFT</VAR>. */ public void resetAlignment() { if (alignment == Element.ALIGN_JUSTIFIED) { alignment = Element.ALIGN_LEFT; } } /** Adds extra indentation to the left (for Paragraph.setFirstLineIndent). */ void setExtraIndent(float extra) { left += extra; width -= extra; } /** * Returns the width that is left, after a maximum of characters is added to the line. * * @return a value */ float widthLeft() { return width; } /** * Returns the number of space-characters in this line. * * @return a value */ int numberOfSpaces() { String string = toString(); int length = string.length(); int numberOfSpaces = 0; for (int i = 0; i < length; i++) { if (string.charAt(i) == ' ') { numberOfSpaces++; } } return numberOfSpaces; } /** * Sets the listsymbol of this line. * <P> * This is only necessary for the first line of a <CODE>ListItem</CODE>. * * @param listItem the list symbol */ public void setListItem(ListItem listItem) { this.listSymbol = listItem.getListSymbol(); this.symbolIndent = listItem.getIndentationLeft(); } /** * Returns the listsymbol of this line. * * @return a <CODE>PdfChunk</CODE> if the line has a listsymbol; <CODE>null</CODE> otherwise */ public Chunk listSymbol() { return listSymbol; } /** * Return the indentation needed to show the listsymbol. * * @return a value */ public float listIndent() { return symbolIndent; } /** * Get the string representation of what is in this line. * * @return a <CODE>String</CODE> */ public String toString() { StringBuffer tmp = new StringBuffer(); for (Iterator i = line.iterator(); i.hasNext(); ) { tmp.append(((PdfChunk) i.next()).toString()); } return tmp.toString(); } /** * Returns the length of a line in UTF32 characters * @return the length in UTF32 characters * @since 2.1.2 */ public int GetLineLengthUtf32() { int total = 0; for (Iterator i = line.iterator(); i.hasNext();) { total += ((PdfChunk)i.next()).lengthUtf32(); } return total; } /** * Checks if a newline caused the line split. * @return <CODE>true</CODE> if a newline caused the line split */ public boolean isNewlineSplit() { return newlineSplit && (alignment != Element.ALIGN_JUSTIFIED_ALL); } /** * Gets the index of the last <CODE>PdfChunk</CODE> with metric attributes * @return the last <CODE>PdfChunk</CODE> with metric attributes */ public int getLastStrokeChunk() { int lastIdx = line.size() - 1; for (; lastIdx >= 0; --lastIdx) { PdfChunk chunk = (PdfChunk)line.get(lastIdx); if (chunk.isStroked()) break; } return lastIdx; } /** * Gets a <CODE>PdfChunk</CODE> by index. * @param idx the index * @return the <CODE>PdfChunk</CODE> or null if beyond the array */ public PdfChunk getChunk(int idx) { if (idx < 0 || idx >= line.size()) return null; return (PdfChunk)line.get(idx); } /** * Gets the original width of the line. * @return the original width of the line */ public float getOriginalWidth() { return originalWidth; } /** * Gets the maximum size of all the fonts used in this line * including images. * @return maximum size of all the fonts used in this line */ float getMaxSizeSimple() { float maxSize = 0; for (int k = 0; k < line.size(); ++k) { PdfChunk chunk = (PdfChunk)line.get(k); if (!chunk.isImage()) { maxSize = Math.max(chunk.font().size(), maxSize); } else { maxSize = Math.max(chunk.getImage().getScaledHeight() + chunk.getImageOffsetY() , maxSize); } } return maxSize; } boolean isRTL() { return isRTL; } /** * Gets the number of separators in the line. * @return the number of separators in the line * @since 2.1.2 */ int getSeparatorCount() { int s = 0; PdfChunk ck; for (Iterator i = line.iterator(); i.hasNext(); ) { ck = (PdfChunk)i.next(); if (ck.isTab()) { return 0; } if (ck.isHorizontalSeparator()) { s++; } } return s; } /** * Gets a width corrected with a charSpacing and wordSpacing. * @param charSpacing * @param wordSpacing * @return a corrected width */ public float getWidthCorrected(float charSpacing, float wordSpacing) { float total = 0; for (int k = 0; k < line.size(); ++k) { PdfChunk ck = (PdfChunk)line.get(k); total += ck.getWidthCorrected(charSpacing, wordSpacing); } return total; } /** * Gets the maximum size of the ascender for all the fonts used * in this line. * @return maximum size of all the ascenders used in this line */ public float getAscender() { float ascender = 0; for (int k = 0; k < line.size(); ++k) { PdfChunk ck = (PdfChunk)line.get(k); if (ck.isImage()) ascender = Math.max(ascender, ck.getImage().getScaledHeight() + ck.getImageOffsetY()); else { PdfFont font = ck.font(); ascender = Math.max(ascender, font.getFont().getFontDescriptor(BaseFont.ASCENT, font.size())); } } return ascender; }/** * Gets the biggest descender for all the fonts used * in this line. Note that this is a negative number. * @return maximum size of all the ascenders used in this line */ public float getDescender() { float descender = 0; for (int k = 0; k < line.size(); ++k) { PdfChunk ck = (PdfChunk)line.get(k); if (ck.isImage()) descender = Math.min(descender, ck.getImageOffsetY()); else { PdfFont font = ck.font(); descender = Math.min(descender, font.getFont().getFontDescriptor(BaseFont.DESCENT, font.size())); } } return descender; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -