List of usage examples for com.lowagie.text Chunk getContent
public String getContent()
Chunk
. From source file:com.krawler.common.fontsettings.FontFamilySelector.java
License:Open Source License
public Phrase processElement(List<Chunk> chunks, FontContext context) { Phrase phrase = new Phrase(); try {//from w w w . j av a2 s . com for (Chunk chunk : chunks) { phrase.add(processChunk(chunk.getContent(), context)); } } catch (Exception e) { e.printStackTrace(); } return phrase; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") private void postProcessEmptyParagraph() { // add space if this paragraph is empty // otherwise its height will be zero boolean empty = true; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) { empty = false;/* w ww. j av a2 s . co m*/ break; } } if (empty) { super.add(new Chunk(ODFUtils.TAB_STR)); } }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") private Font getMostOftenUsedFont() { // determine font most often used in this paragraph // font with the highest count of non-whitespace characters // is considered to be most often used Map<String, Font> fontMap = new LinkedHashMap<String, Font>(); Map<String, Integer> countMap = new LinkedHashMap<String, Integer>(); Font mostUsedFont = null;/*from www . j a va 2 s . com*/ int mostUsedCount = -1; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { Font font = chunk.getFont(); int count = 0; String text = chunk.getContent(); if (text != null) { // count non-whitespace characters in a chunk for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (!Character.isWhitespace(ch)) { count++; } } } if (font != null) { // update font and its count String fontKey = font.getFamilyname() + "_" + (int) font.getSize(); Font fontTmp = fontMap.get(fontKey); if (fontTmp == null) { fontMap.put(fontKey, font); } Integer countTmp = countMap.get(fontKey); int totalCount = countTmp == null ? count : countTmp + count; countMap.put(fontKey, totalCount); // update most used font if (totalCount > mostUsedCount) { mostUsedCount = totalCount; mostUsedFont = font; } } } return mostUsedFont; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylablePhrase.java
License:Open Source License
@SuppressWarnings("unchecked") public Element getElement() { boolean empty = true; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) { empty = false;/*from w ww. ja va2 s . c om*/ break; } } if (empty) { super.add(new Chunk(ODFUtils.TAB_STR)); } return this; }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java
License:Open Source License
/** * Build the fields in a single paragraph. * @param listRecordFields the list of record fields * @param entry the entry/*from ww w. ja v a 2s . c om*/ * @param locale the locale * @param phraseEntry the phrase entry * @param paragraphEntry the paragraph entry * @param bExtractNotFilledField if true, extract empty fields, false * @throws DocumentException exception if there is an error */ private static void builFieldsInSinglePhrase(List<RecordField> listRecordFields, IEntry entry, Locale locale, Phrase phraseEntry, Paragraph paragraphEntry, Boolean bExtractNotFilledField) throws DocumentException { RecordField recordField = listRecordFields.get(0); Chunk chunkEntryValue = null; Font fontEntryValue = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_ENTRY_VALUE)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_ENTRY_VALUE))); if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeDownloadUrl) { if (StringUtils.isNotBlank(recordField.getFileName())) { chunkEntryValue = new Chunk(recordField.getFileName()); } else { chunkEntryValue = new Chunk(StringUtils.EMPTY); } } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeGeolocation) { for (RecordField recordFieldGeo : listRecordFields) { if ((recordFieldGeo.getField() != null) && EntryTypeGeolocation.CONSTANT_ADDRESS.equals(recordFieldGeo.getField().getTitle())) { chunkEntryValue = new Chunk( entry.convertRecordFieldValueToString(recordFieldGeo, locale, false, false), fontEntryValue); } } } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeCheckBox || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeSelect || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeRadioButton) { chunkEntryValue = new Chunk(entry.convertRecordFieldTitleToString(recordField, locale, false), fontEntryValue); } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeFile || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeImg) { String strFileName = StringUtils.EMPTY; if ((recordField.getFile() != null) && StringUtils.isNotBlank(recordField.getFile().getTitle())) { // The thumbnails and big thumbnails should not be displayed if (!((StringUtils.isNotBlank(recordField.getValue()) && recordField.getValue().startsWith(FIELD_THUMBNAIL)) || (StringUtils.isNotBlank(recordField.getValue()) && recordField.getValue().startsWith(FIELD_BIG_THUMBNAIL)))) { strFileName = recordField.getFile().getTitle(); } } chunkEntryValue = new Chunk(strFileName, fontEntryValue); } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeRichText) { String strValue = entry.convertRecordFieldValueToString(recordField, locale, false, false); strValue = StringUtils.defaultString(HtmlUtils.htmlUnescape(strValue)).replaceAll("<[^>]*>", ""); chunkEntryValue = new Chunk(strValue, fontEntryValue); } else { chunkEntryValue = new Chunk(entry.convertRecordFieldValueToString(recordField, locale, false, false), fontEntryValue); } if (chunkEntryValue != null) { if (bExtractNotFilledField || (!bExtractNotFilledField && StringUtils.isNotBlank(chunkEntryValue.getContent()))) { phraseEntry.add(chunkEntryValue); paragraphEntry.add(phraseEntry); } } }
From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") public Element getElement() { if (!elementPostProcessed) { elementPostProcessed = true;// www. j ava 2 s . c o m // add space if this paragraph is empty // otherwise it's height will be zero boolean empty = true; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) { empty = false; break; } } if (empty) { super.add(new Chunk("\u00A0")); // non breaking space } // adjust line height and baseline if (font != null && font.getBaseFont() != null) { // iText and open office computes proportional line height differently // [iText] line height = coefficient * font size // [open office] line height = coefficient * (font ascender + font descender + font extra margin) // we have to increase paragraph line height to generate pdf similar to open office document // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph float size = font.getSize(); float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size); float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size); float multiplier = (ascender + descender + margin) / size; if (multipliedLeading > 0.0f) { setMultipliedLeading(getMultipliedLeading() * multiplier); } // iText seems to output text with baseline lower than open office // we raise all paragraph text by some amount // again this may be inaccurate if fonts with different size are used in this paragraph float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier; chunks = getChunks(); for (Chunk chunk : chunks) { Font f = chunk.getFont(); if (f != null) { // have to raise underline and strikethru as well float s = f.getSize(); if (f.isUnderlined()) { f.setStyle(f.getStyle() & ~Font.UNDERLINE); chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise); } if (f.isStrikethru()) { f.setStyle(f.getStyle() & ~Font.STRIKETHRU); chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise); } } chunk.setTextRise(chunk.getTextRise() + textRise); } } // wrap this paragraph into a table if necessary if (wrapperCell != null) { // background color or borders were set wrapperCell.addElement(this); wrapperTable = createTable(wrapperCell); if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f || getSpacingAfter() > 0.0f) { // margins were set, have to wrap the cell again PdfPCell outerCell = createCell(); outerCell.setPaddingLeft(getIndentationLeft()); setIndentationLeft(0.0f); outerCell.setPaddingRight(getIndentationRight()); setIndentationRight(0.0f); outerCell.setPaddingTop(getSpacingBefore()); setSpacingBefore(0.0f); outerCell.setPaddingBottom(getSpacingAfter()); setSpacingAfter(0.0f); outerCell.addElement(wrapperTable); wrapperTable = createTable(outerCell); } } } return wrapperTable != null ? wrapperTable : this; }
From source file:org.pz.platypus.test.mocks.MockPdfOutfile.java
License:Open Source License
@Override public void startPlainBulletList(Chunk chunk) { addContent(chunk.getContent()); }