List of usage examples for com.itextpdf.text Font getBaseFont
public BaseFont getBaseFont()
BaseFont
inside this object. From source file:com.vectorprint.report.itext.style.parameters.binding.ReportBindingHelper.java
License:Open Source License
@Override public <T> T convert(String value, Class<T> clazz) { if (BaseFontWrapper.class.equals(clazz)) { Font f = FontFactory.getFont(value); if (f.getBaseFont() == null) { throw new VectorPrintRuntimeException("No basefont for: " + value); }/*from w w w. j a v a 2 s .co m*/ return (T) new BaseFontWrapper(f.getBaseFont()); } else { return super.convert(value, clazz); } }
From source file:com.vectorprint.report.itext.style.stylers.Shadow.java
License:Open Source License
@Override public void draw(Rectangle rect, String genericTag) throws VectorPrintException { if (genericTag == null) { if (log.isLoggable(Level.FINE)) { log.fine("not drawing shadow because genericTag is null (no data for shadow)"); }/*from ww w .j a v a 2s .c o m*/ return; } DelayedData delayed = getDelayed(genericTag); PdfContentByte canvas = getPreparedCanvas(); try { com.itextpdf.text.Font f = delayed.getChunk().getFont(); if (f.getBaseFont() == null) { throw new VectorPrintRuntimeException( "font " + f.getFamilyname() + " does not have a basefont, check your fontloading"); } /* * print as much of the text as fits in the width of the rectangle */ String toPrint = delayed.getStringData(); int i = toPrint.length() + 1; do { toPrint = toPrint.substring(0, --i); } while (ItextHelper.getTextWidth(toPrint, f.getBaseFont(), f.getSize()) > rect.getWidth() + 1); if (i < delayed.getStringData().length()) { String nextPart = delayed.getStringData().substring(i).replaceFirst(" *", ""); if (log.isLoggable(Level.FINE)) { log.fine(String.format("event %s, printed shadow %s of %s, left %s for next event", genericTag, toPrint, delayed.getData(), nextPart)); } delayed.setData(nextPart); } canvas.setFontAndSize(f.getBaseFont(), f.getSize()); canvas.setColorFill((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor())); canvas.setColorStroke((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor())); canvas.beginText(); HashMap<String, Object> attributes = delayed.getChunk().getAttributes(); if (attributes != null && attributes.containsKey(Chunk.SKEW)) { float[] skew = (float[]) attributes.get(Chunk.SKEW); canvas.setTextMatrix(1, skew[0], skew[1], 1, rect.getLeft() + calculateShift(getShiftx(), f), rect.getBottom() - calculateShift(getShifty(), f)); } else { canvas.setTextMatrix(1, 0, 0, 1, rect.getLeft() + calculateShift(getShiftx(), f), rect.getBottom() - calculateShift(getShifty(), f)); } canvas.setTextRise(delayed.getChunk().getTextRise()); canvas.showText(toPrint); canvas.endText(); } catch (Exception ex) { resetCanvas(canvas); throw new VectorPrintException(ex); } resetCanvas(canvas); }
From source file:de.knurt.heinzelmann.util.itext.TextBlock.java
License:Creative Commons License
public TextBlock(Font font, String content) { this(font.getSize(), font.getBaseFont(), font, content); }
From source file:Model.MyFontSelector.java
License:Open Source License
/** * Inits the BaseFonts of External Fonts and gets of the internals * Faz a inicializao das BaseFonts das fontes externas e recupera das * fontes internas.//from w w w . java2 s. c o m */ private void initBaseFonts() { try { ArrayList<BaseFont> baseFontList = new ArrayList<>(); ArrayList<Font> fontList = new ArrayList<>(); /** * Gets Internals BaseFonts * Recupera as BaseFonts das fontes internas */ fontList.add(FontFactory.getFont(BaseFont.TIMES_ROMAN)); fontList.add(FontFactory.getFont(BaseFont.COURIER)); fontList.add(FontFactory.getFont(BaseFont.SYMBOL)); for (Font f : fontList) { baseFontList.add(f.getBaseFont()); } /** * Gets external chinese traditional BaseFonts * Recupera as BaseFonts da fonte externa do Chins tradicional */ baseFontList.add(BaseFont.createFont("MHei-Medium", "UniCNS-UCS2-H", BaseFont.EMBEDDED)); baseFontList.add(BaseFont.createFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.EMBEDDED)); /** * Gets external chinese simplified BaseFonts * Recupera o BaseFont da fonte externa do Chins simplificado */ baseFontList.add(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED)); initFonts(baseFontList); } catch (DocumentException | IOException ex) { System.out.println("Error - BaseFont generation"); } }
From source file:org.javad.pdf.fonts.FontRegistry.java
License:Apache License
/** * This method will attempt to find the named font with the specified size and style * using a naming roll-off technique based on some of the naming conventions observed. * <ul><li>// ww w . j a va 2 s . com * If the style is bold and italic, a font with the name <code>"[name]-bolditalic"</code> * will attempted. </li> * <li>If the style is both a name like <code>"[name] bold"</code> will be * attempted.</li> * <li>If the font is italic, the names <code>"[name] italic"</code> and then * <code>"[name]-italic"</code> will be tried.</li> * <li> Finally if none of these styled fonts can be located, the <code>"[name]"</code> will be tried.</li> * </ul> * * @param name * @param bean * @return */ Font findFont(String name, PdfFontBean bean) { String form = (bean.isI18N()) ? BaseFont.IDENTITY_H : BaseFont.CP1252; Font f = null; if (bean.isBold() && bean.isItalic()) { f = FontFactory.getFont(name + "-bolditalic", form, bean.getSize(), bean.getStyle()); } if (isFontInvalid(f) && bean.isBold()) { f = FontFactory.getFont(name + " bold", form, bean.getSize(), bean.getStyle()); } if (isFontInvalid(f) && bean.isItalic()) { f = FontFactory.getFont(name + " italic", form, bean.getSize(), bean.getStyle()); if (isFontInvalid(f)) { f = FontFactory.getFont(name + "-italic", form, bean.getSize(), bean.getStyle()); } } if (isFontInvalid(f)) { f = FontFactory.getFont(name, form, bean.getSize(), bean.getStyle()); } if (logger.isLoggable(Level.FINER)) { @SuppressWarnings("null") BaseFont bf = f.getBaseFont(); if (bf != null) { String[][] fullName = bf.getFullFontName(); if (fullName != null && fullName.length >= 1 && fullName[0].length >= 4) { logger.log(Level.FINER, "The calculated font name is \"{0}\"", fullName[0][3]); } else { logger.finer("The base font full name was not parseable."); } } else { logger.log(Level.FINER, "The base font was null for \"{0}\" with style {1}", new Object[] { name, bean.getStyle() }); } } return f; }
From source file:org.javad.pdf.fonts.FontRegistry.java
License:Apache License
@SuppressWarnings("null") private boolean isFontInvalid(Font f) { return (f == null || (f != null && f.getBaseFont() == null)); }
From source file:org.javad.pdf.PageTitle.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { int maxWidth = 0; content.setColorStroke(BaseColor.BLACK); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.Title); content.setFontAndSize(f.getBaseFont(), f.getSize()); float top = getY(); content.setHorizontalScaling(110.0f); if (getTitle() != null && !getTitle().isEmpty()) { maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize()); PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, (int) (maxWidth * 1.1)); }/*from ww w. j av a2 s . c om*/ if (getSubTitle() != null && !getSubTitle().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Subtitle); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(getSubTitle().toUpperCase(), subFont.getSize())); PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, (int) (maxWidth * 1.10)); } content.setHorizontalScaling(100.0f); if (getClassifier() != null && !getClassifier().isEmpty()) { Font classFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Classifier); content.setFontAndSize(classFont.getBaseFont(), classFont.getSize()); top -= classFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); float width = classFont.getBaseFont().getWidthPoint(getClassifier(), classFont.getCalculatedSize()) + 4; maxWidth = Math.max(maxWidth, (int) width + (2 * DASH_LENGTH)); content.setLineWidth(0.8f); float lineTop = top + ((int) classFont.getSize() / 2 - 1); content.moveTo(getX() - (width / 2) - DASH_LENGTH, lineTop); content.lineTo(getX() - (width / 2), lineTop); content.moveTo(getX() + (width / 2), lineTop); content.lineTo(getX() + (width / 2) + DASH_LENGTH, lineTop); content.stroke(); PdfUtil.renderConstrainedText(content, getClassifier(), classFont, getX(), top, (int) (maxWidth * 1.10)); } OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top); return rect; }
From source file:org.javad.pdf.TitlePageContent.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { if (isSkipped()) { return new OutputBounds(getX(), getY(), 0, 0); }/*from w w w . j av a 2 s .co m*/ int maxWidth = 0; float top = getY() - PdfUtil.convertFromMillimeters( (configuration.getHeight() - configuration.getMarginBottom() - configuration.getMarginTop()) / 2); if (getImage() != null) { try { com.itextpdf.text.Image img = determineScaledImage(getImage()); if (img != null) { content.addImage(img); top = img.getAbsoluteY() - PdfUtil.convertFromMillimeters(25.0f); } } catch (Exception e) { logger.log(Level.FINER, "An error occured scaling the image. ", e); } } content.setColorStroke(BaseColor.BLACK); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumTitle); content.setFontAndSize(f.getBaseFont(), f.getSize()); content.setHorizontalScaling(110.0f); if (getTitle() != null && !getTitle().isEmpty()) { maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize()); PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, maxWidth); } if (getSubTitle() != null && !getSubTitle().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumSubtitle); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); maxWidth = Math.max(maxWidth, (int) content.getEffectiveStringWidth(getSubTitle().toUpperCase(), false)); PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, maxWidth); } if (getDescription() != null && !getDescription().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumDescription); top -= PdfUtil.convertFromMillimeters(15.0f); float width = PdfUtil.convertFromMillimeters( (configuration.getWidth() - configuration.getMarginLeft() - configuration.getMarginRight()) / 2); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); top += PdfUtil.renderConstrainedText(content, getDescription(), subFont, width + PdfUtil.convertFromMillimeters(configuration.getMarginLeft()), top, (int) (width * 0.7f)); } if (!getItems().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumContents); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(6.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); for (String s : getItems()) { maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(s, subFont.getSize())); PdfUtil.renderConstrainedText(content, s, subFont, getX(), top, maxWidth); top -= PdfUtil.convertFromMillimeters(3.0f); } } content.setHorizontalScaling(100.0f); OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top); return rect; }
From source file:org.javad.pdf.util.PdfUtil.java
License:Apache License
public static boolean isTextTooWide(String text, Font f, float width) { return f.getBaseFont().getWidthPoint(text, f.getSize()) > width; }
From source file:org.javad.stamp.pdf.ColumnSet.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { if (isSkipped()) { return new OutputBounds(getX(), getY(), 0, 0); }//from w w w . j a v a 2 s . c om float totalWidth = 0.0f; float maxHeight = 0.0f; float cur_x = getX(); float top = getY(); if (getIssue() != null && !getIssue().isEmpty()) { top -= PdfUtil.convertFromMillimeters(5.0f); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.SetIssue); content.setFontAndSize(f.getBaseFont(), f.getSize()); String is = getIssue().replace("\\n", "\n"); StringTokenizer tokenizer = new StringTokenizer(is, "\n", true); float x = PdfUtil .convertFromMillimeters(configuration.getUsableWidth() / 2 + configuration.getMarginLeft()); while (tokenizer.hasMoreTokens()) { is = tokenizer.nextToken(); if (is.equals("\n")) { top -= f.getCalculatedSize() + 2; } else { PdfUtil.renderConstrainedText(content, is, f, x, top, (int) PdfUtil.convertFromMillimeters(configuration.getUsableWidth())); if (tokenizer.hasMoreTokens()) { top -= f.getCalculatedSize() + 2; } } } top -= PdfUtil.convertFromMillimeters(3.0f); } float spacing = PdfUtil.convertFromMillimeters(getSpacingMode().getSpacing(box_spacing)); int count = 0; for (int i = 0; i < columns.size(); i++) { StampSet set = columns.get(i); if (set.isSkipped()) { continue; } float s_w = PdfUtil.findMaximumWidth(set, content); set.setX(cur_x + s_w / 2); set.setY(top); OutputBounds rect = set.generate(content); totalWidth += rect.width + ((count > 0) ? spacing : 0.0f); cur_x += rect.width + spacing; maxHeight = Math.max(maxHeight, rect.height); count++; } return new OutputBounds(getX() - (totalWidth / 2.0f), getY(), totalWidth, maxHeight + (getY() - top)); }