當前位置: 首頁>>代碼示例>>Java>>正文


Java PDFont.getStringWidth方法代碼示例

本文整理匯總了Java中org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java PDFont.getStringWidth方法的具體用法?Java PDFont.getStringWidth怎麽用?Java PDFont.getStringWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.pdfbox.pdmodel.font.PDFont的用法示例。


在下文中一共展示了PDFont.getStringWidth方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addHeaderPJ

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
/**
 * @param textHeader
 * @param font
 * @param PAGE_SIZE_A4
 * @param contentStream
 * @return ajoute un header a la piece
 * @throws IOException
 */
private Float addHeaderPJ(final String textHeader, final PDFont font, final PDRectangle PAGE_SIZE_A4,
		final PDPageContentStream contentStream) throws IOException {
	Float marginTop = 0f;
	// si font Ok, on ajoute le text
	if (font != null && ConstanteUtils.DOSSIER_ADD_HEADER_IMG) {

		// calcul de la largeur et hauteur du txt
		Float titleWidth = font.getStringWidth(textHeader) / 1000 * ConstanteUtils.DOSSIER_FONT_SIZE;
		Float titleHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000
				* ConstanteUtils.DOSSIER_FONT_SIZE;

		// calcul de la marge du haut : hauteur du text + marge
		marginTop = titleHeight + ConstanteUtils.DOSSIER_MARGIN;

		// calcul de la position du text
		Float xText = (PAGE_SIZE_A4.getWidth() - 2 * ConstanteUtils.DOSSIER_MARGIN - titleWidth) / 2;
		Float yText = PAGE_SIZE_A4.getHeight() - marginTop;

		// ecriture du text
		contentStream.beginText();
		contentStream.setFont(PDType1Font.HELVETICA_BOLD, ConstanteUtils.DOSSIER_FONT_SIZE);
		contentStream.newLineAtOffset(xText, yText);
		contentStream.showText(textHeader);
		contentStream.endText();
	}
	return marginTop;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:36,代碼來源:CandidatureController.java

示例2: showTextOnStream

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
private void showTextOnStream(IFontTextDrawerEnv env, PDPageContentStream contentStream, Font attributeFont,
		PDFont font, boolean isStrikeThrough, boolean isUnderline, boolean isLigatures, String text)
		throws IOException {
	if (isStrikeThrough || isUnderline) {
		// noinspection unused
		float stringWidth = font.getStringWidth(text);
		// noinspection unused
		LineMetrics lineMetrics = attributeFont.getLineMetrics(text, env.getFontRenderContext());
		/*
		 * TODO: We can not draw that yet, we must do that later. While in textmode its
		 * not possible to draw lines...
		 */
	}
	// noinspection StatementWithEmptyBody
	if (isLigatures) {
		/*
		 * No idea how to map this ...
		 */
	}
	contentStream.showText(text);
}
 
開發者ID:rototor,項目名稱:pdfbox-graphics2d,代碼行數:22,代碼來源:PdfBoxGraphics2DFontTextDrawer.java

示例3: getLines

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
/**
 * Method to separate lines of the PDF.
 * @param text
 * @param fontSize
 * @param pdfFont
 * @param width
 * @return
 * @throws IOException
 */
private static List<String> getLines(String text, float fontSize, PDFont pdfFont, float width)
        throws IOException {
    width = width - 150 ;
    java.util.List<String> lines = new ArrayList<String>();
    int lastSpace = -1;
    while (text.length() > 0) {
        int spaceIndex = text.indexOf(' ', lastSpace + 1);
        if (spaceIndex < 0)
            spaceIndex = text.length();
        String subString = text.substring(0, spaceIndex);
        float size = fontSize * pdfFont.getStringWidth(subString) / 1000;
        if (size > width) {
            float requiredSize = (width * 1000)/fontSize;
            int characterSize = getCharacterCount(requiredSize, subString, pdfFont);
            //if (lastSpace < 0)
            lastSpace = characterSize;
            subString = text.substring(0, lastSpace);
            lines.add(subString);
            text = text.substring(lastSpace).trim();
            lastSpace = -1;
        } else if (spaceIndex == text.length()) {
            lines.add(text);
            text = "";
        } else {
            lastSpace = spaceIndex;
        }
    }
    return lines;
}
 
開發者ID:wso2-incubator,項目名稱:scim2-compliance-test-suite,代碼行數:39,代碼來源:PDFGenerator.java

示例4: getCharacterCount

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
/**
 * This return the character count of a given text.
 * @param requiredSize
 * @param subString
 * @param pdfFont
 * @return
 * @throws IOException
 */
private static int getCharacterCount(float requiredSize, String subString, PDFont pdfFont) throws IOException {
    double factor = 0.95;
    String string  = subString;
    while (pdfFont.getStringWidth(string) > requiredSize) {
        string = string.substring(0, (int) Math.round(string.length()*factor));
    }
    return string.length();
}
 
開發者ID:wso2-incubator,項目名稱:scim2-compliance-test-suite,代碼行數:17,代碼來源:PDFGenerator.java

示例5: getStringWidth

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
private float getStringWidth(String text, PDFont font, int fontSize) throws IOException {
    return font.getStringWidth(text) * fontSize / 1000F;
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:4,代碼來源:BillPdfGenerator.java

示例6: getTextWidth

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
/**
 * Returns the width of a particular string rendered in a give font and size
 * 
 * @param text
 *            The string
 * @param font
 *            The font used to render the string
 * @param fontSize
 *            The font size used to render the string
 * @return The width of the rendered string, without padding or borders
 * @throws IOException
 *             If accessing information needed to calculate text size fails
 */
private float getTextWidth(final String text, final PDFont font, final float fontSize) throws IOException {
	return font.getStringWidth(text) / 1000 * fontSize;
}
 
開發者ID:errt,項目名稱:BoxTable,代碼行數:17,代碼來源:TextCell.java

示例7: getWidth

import org.apache.pdfbox.pdmodel.font.PDFont; //導入方法依賴的package包/類
/**
 * Returns the width this text will occupy
 * 
 * @param font
 *            The font the text should be rendered in if it inherits its font
 * @param fontSize
 *            The font sise the text should be rendered in if it inherits its font size
 * @return The width of this text when rendered
 * @throws IOException
 *             If accessing information needed to calculate text size fails
 */
public float getWidth(final PDFont font, final float fontSize) throws IOException {
	final PDFont usedFont = this.font != null ? this.font : font;
	final float usedFontSize = this.fontSize > 0 ? this.fontSize : fontSize;
	return usedFont.getStringWidth(text) / 1000 * usedFontSize;
}
 
開發者ID:errt,項目名稱:BoxTable,代碼行數:17,代碼來源:Text.java


注:本文中的org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。