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


Java BaseFont.getWidthPoint方法代碼示例

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


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

示例1: addTextVertical

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception  {
	if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
       Font font = PdfFont.getFont(bold);
	BaseFont bf = font.getBaseFont();
	float width = bf.getWidthPoint(text, font.getSize());
	PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
	template.beginText();
	template.setColorFill(Color.BLACK);
	template.setFontAndSize(bf, font.getSize());
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(font.getSize() + 2);
	//make an Image object from the template
	Image img = Image.getInstance(template);
	img.setRotationDegrees(270);
	//embed the image in a Chunk
	Chunk ck = new Chunk(img, 0, 0);
	
	if (cell.getPhrase()==null) {
		cell.setPhrase(new Paragraph(ck));
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	} else {
		cell.getPhrase().add(ck);
	}
}
 
開發者ID:UniTime,項目名稱:unitime,代碼行數:31,代碼來源:PdfTimetableGridTable.java

示例2: outputText

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
public void outputText(int x, int y, int flag, int x1, int y1, int x2, int y2, String text) {
    MetaFont font = state.getCurrentFont();
    float refX = state.transformX(x);
    float refY = state.transformY(y);
    float angle = state.transformAngle(font.getAngle());
    float sin = (float)Math.sin(angle);
    float cos = (float)Math.cos(angle);
    float fontSize = font.getFontSize(state);
    BaseFont bf = font.getFont();
    int align = state.getTextAlign();
    float textWidth = bf.getWidthPoint(text, fontSize);
    float tx = 0;
    float ty = 0;
    float descender = bf.getFontDescriptor(BaseFont.DESCENT, fontSize);
    float ury = bf.getFontDescriptor(BaseFont.BBOXURY, fontSize);
    cb.saveState();
    cb.concatCTM(cos, sin, -sin, cos, refX, refY);
    if ((align & MetaState.TA_CENTER) == MetaState.TA_CENTER)
        tx = -textWidth / 2;
    else if ((align & MetaState.TA_RIGHT) == MetaState.TA_RIGHT)
        tx = -textWidth;
    if ((align & MetaState.TA_BASELINE) == MetaState.TA_BASELINE)
        ty = 0;
    else if ((align & MetaState.TA_BOTTOM) == MetaState.TA_BOTTOM)
        ty = -descender;
    else
        ty = -ury;
    Color textColor;
    if (state.getBackgroundMode() == MetaState.OPAQUE) {
        textColor = state.getCurrentBackgroundColor();
        cb.setColorFill(textColor);
        cb.rectangle(tx, ty + descender, textWidth, ury - descender);
        cb.fill();
    }
    textColor = state.getCurrentTextColor();
    cb.setColorFill(textColor);
    cb.beginText();
    cb.setFontAndSize(bf, fontSize);
    cb.setTextMatrix(tx, ty);
    cb.showText(text);
    cb.endText();
    if (font.isUnderline()) {
        cb.rectangle(tx, ty - fontSize / 4, textWidth, fontSize / 15);
        cb.fill();
    }
    if (font.isStrikeout()) {
        cb.rectangle(tx, ty + fontSize / 3, textWidth, fontSize / 15);
        cb.fill();
    }
    cb.restoreState();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:52,代碼來源:MetaDo.java

示例3: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
    * PdfTemplates can be wrapped in an Image.
    */
@Test
   public  void main() throws Exception {
       
           
       // step 1: creation of a document-object
       Rectangle rect = new Rectangle(PageSize.A4);
       rect.setBackgroundColor(new Color(238, 221, 88));
       Document document = new Document(rect, 50, 50, 50, 50);
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
	// step 3: we open the document
	document.open();
	// step 4:
	PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
	BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
			BaseFont.NOT_EMBEDDED);
	String text = "Vertical";
	float size = 16;
	float width = bf.getWidthPoint(text, size);
	template.beginText();
	template.setRGBColorFillF(1, 1, 1);
	template.setFontAndSize(bf, size);
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(size + 2);
	template.sanityCheck();
	Image img = Image.getInstance(template);
	img.setRotationDegrees(90);
	Chunk ck = new Chunk(img, 0, 0);
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	PdfPCell cell = new PdfPCell(img);
	cell.setPadding(4);
	cell.setBackgroundColor(new Color(0, 0, 255));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	table.addCell(cell);
	table.addCell("I see a template everywhere");
	table.addCell(cell);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");

	Paragraph p1 = new Paragraph("This is a template ");
	p1.add(ck);
	p1.add(" just here.");
	p1.setLeading(img.getScaledHeight() * 1.1f);
	document.add(p1);
	document.add(table);
	Paragraph p2 = new Paragraph("More templates ");
	p2.setLeading(img.getScaledHeight() * 1.1f);
	p2.setAlignment(Element.ALIGN_JUSTIFIED);
	img.scalePercent(70);
	for (int k = 0; k < 20; ++k)
		p2.add(ck);
	document.add(p2);
	// step 5: we close the document
	document.close();

   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:70,代碼來源:TemplateImagesTest.java

示例4: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
 * Example with vertical text in Cells.
 */
@Test
public void main() throws Exception {

	// step1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("VerticalText.pdf"));
	// step3
	document.open();
	// step4

	// make a PdfTemplate with the vertical text
	PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
	BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
	String text = "Vertical";
	float size = 16;
	float width = bf.getWidthPoint(text, size);
	template.beginText();
	template.setRGBColorFillF(1, 1, 1);
	template.setFontAndSize(bf, size);
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(size + 2);
	// make an Image object from the template
	Image img = Image.getInstance(template);
	img.setRotationDegrees(90);
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	PdfPCell cell = new PdfPCell(img);
	cell.setPadding(4);
	cell.setBackgroundColor(new Color(0, 0, 255));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	table.addCell(cell);
	table.addCell("I see a template everywhere");
	table.addCell(cell);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	document.add(table);

	// step5
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:54,代碼來源:VerticalTextInCellsTest.java

示例5: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
 * PdfTemplates can be wrapped in an Image.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {

	System.out.println("PdfTemplate wrapped in an Image");

	// step 1: creation of a document-object
	Rectangle rect = new Rectangle(PageSize.A4);
	rect.setBackgroundColor(new Color(238, 221, 88));
	Document document = new Document(rect, 50, 50, 50, 50);
	try {
		// step 2: we create a writer that listens to the document
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "templateImages.pdf"));
		// step 3: we open the document
		document.open();
		// step 4:
		PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
		String text = "Vertical";
		float size = 16;
		float width = bf.getWidthPoint(text, size);
		template.beginText();
		template.setRGBColorFillF(1, 1, 1);
		template.setFontAndSize(bf, size);
		template.setTextMatrix(0, 2);
		template.showText(text);
		template.endText();
		template.setWidth(width);
		template.setHeight(size + 2);
		template.sanityCheck();
		Image img = Image.getInstance(template);
		img.setRotationDegrees(90);
		Chunk ck = new Chunk(img, 0, 0);
		PdfPTable table = new PdfPTable(3);
		table.setWidthPercentage(100);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
		table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
		PdfPCell cell = new PdfPCell(img);
		cell.setPadding(4);
		cell.setBackgroundColor(new Color(0, 0, 255));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell("I see a template on my right");
		table.addCell(cell);
		table.addCell("I see a template on my left");
		table.addCell(cell);
		table.addCell("I see a template everywhere");
		table.addCell(cell);
		table.addCell("I see a template on my right");
		table.addCell(cell);
		table.addCell("I see a template on my left");

		Paragraph p1 = new Paragraph("This is a template ");
		p1.add(ck);
		p1.add(" just here.");
		p1.setLeading(img.getScaledHeight() * 1.1f);
		document.add(p1);
		document.add(table);
		Paragraph p2 = new Paragraph("More templates ");
		p2.setLeading(img.getScaledHeight() * 1.1f);
		p2.setAlignment(Element.ALIGN_JUSTIFIED);
		img.scalePercent(70);
		for (int k = 0; k < 20; ++k)
			p2.add(ck);
		document.add(p2);
		// step 5: we close the document
		document.close();
	} catch (Exception de) {
		System.err.println(de.getMessage());
	}
}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:75,代碼來源:TemplateImages.java

示例6: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
 * Example with vertical text in Cells.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {

	System.out.println("Vertical text in cells");
	// step1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	try {
		// step2
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "VerticalText.pdf"));
		// step3
		document.open();
		// step4

		// make a PdfTemplate with the vertical text
		PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
		BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
		String text = "Vertical";
		float size = 16;
		float width = bf.getWidthPoint(text, size);
		template.beginText();
		template.setRGBColorFillF(1, 1, 1);
		template.setFontAndSize(bf, size);
		template.setTextMatrix(0, 2);
		template.showText(text);
		template.endText();
		template.setWidth(width);
		template.setHeight(size + 2);
		// make an Image object from the template
		Image img = Image.getInstance(template);
		img.setRotationDegrees(90);
		PdfPTable table = new PdfPTable(3);
		table.setWidthPercentage(100);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
		table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
		PdfPCell cell = new PdfPCell(img);
		cell.setPadding(4);
		cell.setBackgroundColor(new Color(0, 0, 255));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell("I see a template on my right");
		table.addCell(cell);
		table.addCell("I see a template on my left");
		table.addCell(cell);
		table.addCell("I see a template everywhere");
		table.addCell(cell);
		table.addCell("I see a template on my right");
		table.addCell(cell);
		table.addCell("I see a template on my left");
		document.add(table);
	} catch (Exception de) {
		de.printStackTrace();
	}
	// step5
	document.close();
}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:60,代碼來源:VerticalTextInCells.java


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