/** * Removes all the <VAR>' '</VAR> and <VAR>'-'</VAR>-characters on the right of a <CODE>String</CODE>. * <P> * @param string the <CODE>String<CODE> that has to be trimmed. * @return the trimmed <CODE>String</CODE> */ String trim(String string) { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { while (string.endsWith("\u0001")) { string = string.substring(0, string.length() - 1); } } else { while (string.endsWith(" ") || string.endsWith("\t")) { string = string.substring(0, string.length() - 1); } } return string; }
/** * Removes all the <VAR>' '</VAR> and <VAR>'-'</VAR>-characters on the right of a <CODE>String</CODE>. * <P> * @param string the <CODE>String<CODE> that has to be trimmed. * @return the trimmed <CODE>String</CODE> */ String trim(String string) { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { while (string.endsWith("\u0001")) { string = string.substring(0, string.length() - 1); } } else { while (string.endsWith(" ") || string.endsWith("\t")) { string = string.substring(0, string.length() - 1); } } return string; }
/** * Removes all the <VAR>' '</VAR> and <VAR>'-'</VAR>-characters on the right of a <CODE>String</CODE>. * <P> * @param string the <CODE>String<CODE> that has to be trimmed. * @return the trimmed <CODE>String</CODE> */ String trim(String string) { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { while (string.endsWith("\u0001")) { string = string.substring(0, string.length() - 1); } } else { while (string.endsWith(" ") || string.endsWith("\t")) { string = string.substring(0, string.length() - 1); } } return string; }
public float trimFirstSpace() { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { if (value.length() > 1 && value.startsWith("\u0001")) { value = value.substring(1); return font.width('\u0001'); } } else { if (value.length() > 1 && value.startsWith(" ")) { value = value.substring(1); return font.width(' '); } } return 0; }
public float trimFirstSpace() { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { if (value.length() > 1 && value.startsWith("\u0001")) { value = value.substring(1); return font.width('\u0001'); } } else { if (value.length() > 1 && value.startsWith(" ")) { value = value.substring(1); return font.width(' '); } } return 0; }
public float trimFirstSpace() { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { if (value.length() > 1 && value.startsWith("\u0001")) { value = value.substring(1); return font.width('\u0001'); } } else { if (value.length() > 1 && value.startsWith(" ")) { value = value.substring(1); return font.width(' '); } } return 0; }
/** * Trims the last space. * @return the width of the space trimmed, otherwise 0 */ public float trimLastSpace() { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { if (value.length() > 1 && value.endsWith("\u0001")) { value = value.substring(0, value.length() - 1); return font.width('\u0001'); } } else { if (value.length() > 1 && value.endsWith(" ")) { value = value.substring(0, value.length() - 1); return font.width(' '); } } return 0; } public float trimFirstSpace()
/** * Trims the last space. * @return the width of the space trimmed, otherwise 0 */ public float trimLastSpace() { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { if (value.length() > 1 && value.endsWith("\u0001")) { value = value.substring(0, value.length() - 1); return font.width('\u0001'); } } else { if (value.length() > 1 && value.endsWith(" ")) { value = value.substring(0, value.length() - 1); return font.width(' '); } } return 0; } public float trimFirstSpace()
/** * Trims the last space. * @return the width of the space trimmed, otherwise 0 */ public float trimLastSpace() { BaseFont ft = font.getFont(); if (ft.getFontType() == BaseFont.FONT_TYPE_CJK && ft.getUnicodeEquivalent(' ') != ' ') { if (value.length() > 1 && value.endsWith("\u0001")) { value = value.substring(0, value.length() - 1); return font.width('\u0001'); } } else { if (value.length() > 1 && value.endsWith(" ")) { value = value.substring(0, value.length() - 1); return font.width(' '); } } return 0; } public float trimFirstSpace()
/** * Each font used in a document has an instance of this class. * This class stores the characters used in the document and other * specifics unique to the current working document. * @param fontName the font name * @param indirectReference the indirect reference to the font * @param baseFont the <CODE>BaseFont</CODE> */ FontDetails(PdfName fontName, PdfIndirectReference indirectReference, BaseFont baseFont) { this.fontName = fontName; this.indirectReference = indirectReference; this.baseFont = baseFont; fontType = baseFont.getFontType(); switch (fontType) { case BaseFont.FONT_TYPE_T1: case BaseFont.FONT_TYPE_TT: shortTag = new byte[256]; break; case BaseFont.FONT_TYPE_CJK: cjkTag = new IntHashtable(); cjkFont = (CJKFont)baseFont; break; case BaseFont.FONT_TYPE_TTUNI: longTag = new HashMap(); ttu = (TrueTypeFontUnicode)baseFont; symbolic = baseFont.isFontSpecific(); break; } }
/** * Each font used in a document has an instance of this class. * This class stores the characters used in the document and other * specifics unique to the current working document. * @param fontName the font name * @param indirectReference the indirect reference to the font * @param baseFont the <CODE>BaseFont</CODE> */ FontDetails(PdfName fontName, PdfIndirectReference indirectReference, BaseFont baseFont) { this.fontName = fontName; this.indirectReference = indirectReference; this.baseFont = baseFont; fontType = baseFont.getFontType(); switch (fontType) { case BaseFont.FONT_TYPE_T1: case BaseFont.FONT_TYPE_TT: shortTag = new byte[256]; break; case BaseFont.FONT_TYPE_CJK: cjkTag = new IntHashtable(); cjkFont = (CJKFont)baseFont; break; case BaseFont.FONT_TYPE_TTUNI: longTag = new HashMap(); ttu = (TrueTypeFontUnicode)baseFont; symbolic = baseFont.isFontSpecific(); break; } }
/** * Each font used in a document has an instance of this class. * This class stores the characters used in the document and other * specifics unique to the current working document. * @param fontName the font name * @param indirectReference the indirect reference to the font * @param baseFont the <CODE>BaseFont</CODE> */ FontDetails(PdfName fontName, PdfIndirectReference indirectReference, BaseFont baseFont) { this.fontName = fontName; this.indirectReference = indirectReference; this.baseFont = baseFont; fontType = baseFont.getFontType(); switch (fontType) { case BaseFont.FONT_TYPE_T1: case BaseFont.FONT_TYPE_TT: shortTag = new byte[256]; break; case BaseFont.FONT_TYPE_CJK: cjkTag = new IntHashtable(); cjkFont = (CJKFont)baseFont; break; case BaseFont.FONT_TYPE_TTUNI: longTag = new HashMap(); ttu = (TrueTypeFontUnicode)baseFont; symbolic = baseFont.isFontSpecific(); break; } }
int ft = bf.getFontType(); if (state.wordSpace != 0.0f && (ft == BaseFont.FONT_TYPE_T1 || ft == BaseFont.FONT_TYPE_TT || ft == BaseFont.FONT_TYPE_T3)) { for (int i = 0; i < (text.length() -1); i++) {
public BaseFontFontMetrics( final FontNativeContext record, final BaseFont baseFont, final float size ) { if ( baseFont == null ) { throw new NullPointerException( "BaseFont is invalid." ); } this.record = record; this.baseFont = baseFont; this.size = size; this.cpBuffer = new char[ 4 ]; this.cachedWidths = new long[ 256 - 32 ]; Arrays.fill( cachedWidths, -1 ); sizeScaled = FontStrictGeomUtility.toInternalValue( size ); this.ascent = (long) baseFont.getFontDescriptor( BaseFont.AWT_ASCENT, sizeScaled ); this.descent = (long) -baseFont.getFontDescriptor( BaseFont.AWT_DESCENT, sizeScaled ); this.leading = (long) baseFont.getFontDescriptor( BaseFont.AWT_LEADING, sizeScaled ); italicsAngle = FontStrictGeomUtility.toInternalValue( baseFont.getFontDescriptor( BaseFont.ITALICANGLE, size ) ); maxAscent = (long) baseFont.getFontDescriptor( BaseFont.BBOXURY, sizeScaled ); maxDescent = (long) -baseFont.getFontDescriptor( BaseFont.BBOXLLY, sizeScaled ); maxCharAdvance = (long) baseFont.getFontDescriptor( BaseFont.AWT_MAXADVANCE, sizeScaled ); final int[] charBBox = this.baseFont.getCharBBox( 'x' ); if ( charBBox != null ) { this.xHeight = (long) ( charBBox[ 3 ] * size ); } if ( this.xHeight == 0 ) { this.xHeight = getAscent() / 2; } this.trueTypeFont = baseFont.getFontType() == BaseFont.FONT_TYPE_TT || baseFont.getFontType() == BaseFont.FONT_TYPE_TTUNI; }
/** * Adds a <CODE>BaseFont</CODE> to the document but not to the page resources. * It is used for templates. * @param bf the <CODE>BaseFont</CODE> to add * @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE> * and position 1 is an <CODE>PdfIndirectReference</CODE> */ FontDetails addSimple(BaseFont bf) { if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf); } FontDetails ret = (FontDetails)documentFonts.get(bf); if (ret == null) { PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf); ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf); documentFonts.put(bf, ret); } return ret; }
/** * Adds a <CODE>BaseFont</CODE> to the document but not to the page resources. * It is used for templates. * @param bf the <CODE>BaseFont</CODE> to add * @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE> * and position 1 is an <CODE>PdfIndirectReference</CODE> */ FontDetails addSimple(BaseFont bf) { if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf); } FontDetails ret = (FontDetails)documentFonts.get(bf); if (ret == null) { PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf); ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf); documentFonts.put(bf, ret); } return ret; }
/** * Adds a <CODE>BaseFont</CODE> to the document but not to the page resources. * It is used for templates. * @param bf the <CODE>BaseFont</CODE> to add * @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE> * and position 1 is an <CODE>PdfIndirectReference</CODE> */ FontDetails addSimple(BaseFont bf) { if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf); } FontDetails ret = documentFonts.get(bf); if (ret == null) { PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf); ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf); documentFonts.put(bf, ret); } return ret; }
/** * Set the font and the size for the subsequent text writing. * * @param bf the font * @param size the font size in points */ public void setFontAndSize(BaseFont bf, float size) { checkWriter(); state.size = size; if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { state.fontDetails = new FontDetails(null, ((DocumentFont)bf).getIndirectReference(), bf); } else state.fontDetails = writer.addSimple(bf); PdfName psn = stdFieldFontNames.get(bf.getPostscriptFontName()); if (psn == null) { if (bf.isSubset() && bf.getFontType() == BaseFont.FONT_TYPE_TTUNI) psn = state.fontDetails.getFontName(); else { psn = new PdfName(bf.getPostscriptFontName()); state.fontDetails.setSubset(false); } } PageResources prs = getPageResources(); // PdfName name = state.fontDetails.getFontName(); prs.addFont(psn, state.fontDetails.getIndirectReference()); content.append(psn.getBytes()).append(' ').append(size).append(" Tf").append_i(separator); }
/** * Set the font and the size for the subsequent text writing. * * @param bf the font * @param size the font size in points */ public void setFontAndSize(BaseFont bf, float size) { checkWriter(); state.size = size; if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { state.fontDetails = new FontDetails(null, ((DocumentFont)bf).getIndirectReference(), bf); } else state.fontDetails = writer.addSimple(bf); PdfName psn = (PdfName)stdFieldFontNames.get(bf.getPostscriptFontName()); if (psn == null) { if (bf.isSubset() && bf.getFontType() == BaseFont.FONT_TYPE_TTUNI) psn = state.fontDetails.getFontName(); else { psn = new PdfName(bf.getPostscriptFontName()); state.fontDetails.setSubset(false); } } PageResources prs = getPageResources(); // PdfName name = state.fontDetails.getFontName(); prs.addFont(psn, state.fontDetails.getIndirectReference()); content.append(psn.getBytes()).append(' ').append(size).append(" Tf").append_i(separator); }
/** * Set the font and the size for the subsequent text writing. * * @param bf the font * @param size the font size in points */ public void setFontAndSize(BaseFont bf, float size) { checkWriter(); state.size = size; if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { state.fontDetails = new FontDetails(null, ((DocumentFont)bf).getIndirectReference(), bf); } else state.fontDetails = writer.addSimple(bf); PdfName psn = (PdfName)stdFieldFontNames.get(bf.getPostscriptFontName()); if (psn == null) { if (bf.isSubset() && bf.getFontType() == BaseFont.FONT_TYPE_TTUNI) psn = state.fontDetails.getFontName(); else { psn = new PdfName(bf.getPostscriptFontName()); state.fontDetails.setSubset(false); } } PageResources prs = getPageResources(); // PdfName name = state.fontDetails.getFontName(); prs.addFont(psn, state.fontDetails.getIndirectReference()); content.append(psn.getBytes()).append(' ').append(size).append(" Tf").append_i(separator); }