protected boolean fontFileNotEmbedded(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 == null && ff2 == null && ff3 == null); }
PDRectangle bbox = desc.getFontBoundingBox(); float retval = 0; if (bbox != null) retval = desc.getCapHeight(); retval = desc.getAscent(); retval = desc.getXHeight(); if (retval > 0) retval -= desc.getDescent();
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff3 = fontDescriptor.getFontFile3(); fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); return null; fontDescriptor.getFontName() + ": The FontFile is invalid")); return null;
@Override Object[][] getFlagBits() { PDFontDescriptor fontDesc = new PDFontDescriptor(fontDescriptor); return new Object[][]{ new Object[]{1, "FixedPitch", fontDesc.isFixedPitch()}, new Object[]{2, "Serif", fontDesc.isSerif()}, new Object[]{3, "Symbolic", fontDesc.isSymbolic()}, new Object[]{4, "Script", fontDesc.isScript()}, new Object[]{6, "NonSymbolic", fontDesc.isNonSymbolic()}, new Object[]{7, "Italic", fontDesc.isItalic()}, new Object[]{17, "AllCap", fontDesc.isAllCap()}, new Object[]{18, "SmallCap", fontDesc.isSmallCap()}, new Object[]{19, "ForceBold", fontDesc.isForceBold()} }; } }
private boolean isBold(PDFontDescriptor descriptor) { if (descriptor.isForceBold()) { return true; } return descriptor.getFontName().contains("Bold"); }
PDFontDescriptor fd = new PDFontDescriptor(); fd.setFontName(ttf.getName()); fd.setFixedPitch(post.getIsFixedPitch() > 0 || ttf.getHorizontalHeader().getNumberOfHMetrics() == 1); fd.setItalic(((fsSelection & (ITALIC | OBLIQUE)) != 0)); case OS2WindowsMetricsTable.FAMILY_CLASS_OLDSTYLE_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_SLAB_SERIFS: fd.setSerif(true); break; case OS2WindowsMetricsTable.FAMILY_CLASS_SCRIPTS: fd.setScript(true); break; default: fd.setFontWeight(os2.getWeightClass()); fd.setSymbolic(true); fd.setNonSymbolic(false); fd.setItalicAngle(post.getItalicAngle()); rect.setUpperRightX(header.getXMax() * scaling); rect.setUpperRightY(header.getYMax() * scaling); fd.setFontBoundingBox(rect); fd.setAscent(hHeader.getAscender() * scaling);
/** * If the embedded font is a subset, the CIDSet entry is mandatory and must be a Stream. If the CIDSet entry doesn't * respects conditions, the FontContainer is updated. * * @param pfDescriptor */ protected void checkCIDSet(PDFontDescriptor pfDescriptor) { if (isSubSet(pfDescriptor.getFontName())) { COSDocument cosDocument = context.getDocument().getDocument(); COSBase cidset = pfDescriptor.getCOSObject().getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CIDSET)); if (cidset == null || !COSUtils.isStream(cidset, cosDocument)) { this.fContainer.push(new ValidationResult.ValidationError(ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET, pfDescriptor.getFontName() + ": The CIDSet entry is missing for the Composite Subset")); } } }
String name = fontDescriptor.getFontName(); if (name != null) String lower = fontDescriptor.getFontName().toLowerCase(); isBold = lower.contains("bold") || lower.contains("black") || if (fontDescriptor.isFixedPitch()) if (isBold && fontDescriptor.isItalic()) else if (fontDescriptor.isItalic()) else if (fontDescriptor.isSerif()) if (isBold && fontDescriptor.isItalic()) else if (fontDescriptor.isItalic()) if (isBold && fontDescriptor.isItalic()) else if (fontDescriptor.isItalic())
if (fd != null) stream = fd.getFontFile2(); if (stream == null) stream = fd.getFontFile3(); stream = fd.getFontFile(); LOG.warn("Found CFF/OTF but expected embedded TTF font " + fd.getFontName());
if (fd.isNonSymbolic()) fd.getFontName() + ": The Encoding is invalid for the NonSymbolic TTF")); if (fd.isSymbolic() && fontDictionary.getItem(COSName.ENCODING) != null) fd.getFontName() + ": The Encoding should be missing for the Symbolic TTF"));
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream fontFile = fontDescriptor.getFontFile2(); COSStream stream = (fontFile == null ? null : fontFile.getCOSObject()); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile2 is missing")); this.fContainer.notEmbedded(); return null; } if (stream.getInt(COSName.LENGTH1) <= 0) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile entry /Length1 is invalid")); return null; } return fontFile; }
private static List<List<String>> getReAlignedTextBasedOnPageHeight(List<String> originalLines, PDFont font, float workablePageHeight) { final float newLineHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * FONT_SIZE + LINE_GAP; List<List<String>> realignedTexts = new ArrayList<>(); float consumedHeight = 0; List<String> linesInAPage = new ArrayList<>(); for (String line : originalLines) { if (newLineHeight + consumedHeight < workablePageHeight) { consumedHeight += newLineHeight; } else { consumedHeight = newLineHeight; realignedTexts.add(linesInAPage); linesInAPage = new ArrayList<>(); } linesInAPage.add(line); } realignedTexts.add(linesInAPage); return realignedTexts; }
float height = (font.getFontDescriptor().getCapHeight() + -font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0)
public static PdfBoxRawPDFontMetrics fromPdfBox(PDFont font, PDFontDescriptor descriptor) throws IOException { return new PdfBoxRawPDFontMetrics( font.getBoundingBox().getUpperRightY(), // Ascent -font.getBoundingBox().getLowerLeftY(), // Descent -descriptor.getFontBoundingBox().getUpperRightY() / 3f, // Strikethrough offset 100f, // FIXME: Strikethrough thickness -descriptor.getDescent(), // Underline position 50f); // FIXME: Underline thickness }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream ff3 = fontDescriptor.getFontFile3(); if (ff3 != null) { // Stream validation should be done by the StreamValidateHelper. Process font specific check COSStream stream = ff3.getCOSObject(); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); } else { // Length1/2/3 aren't mandatory for this type of font // But the Subtype is a mandatory field with specific values String st = stream.getNameAsString(COSName.SUBTYPE); if (!(FONT_DICTIONARY_VALUE_TYPE0C.equals(st) || FONT_DICTIONARY_VALUE_TYPE1C.equals(st))) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": invalid /Subtype /" + st + " in /FontFile3 stream")); } checkCIDSet(fontDescriptor); } } return ff3; }
public static float findMaxFontHeigth(PDFont font, int fontSize) { return (font.getFontDescriptor().getAscent() / 1000 * fontSize) - (font.getFontDescriptor().getDescent() / 1000 * fontSize); }
float ascentAtFontSize = font.getFontDescriptor().getAscent() / FONTSCALE * fontSize; float baselineOffset = paddingEdge.getLowerLeftY() + (appearanceStream.getBBox().getHeight() - ascentAtFontSize)/2;
/** * <p> * Create basic {@link FontMetrics} for current font. * <p> * * @param font * The font from which calculation will be applied <<<<<<< HEAD * @throws IOException * If reading the font file fails ======= >>>>>>> using FreeSans * as default font and added new free fonts */ private static void createFontMetrics(final PDFont font) { final float base = font.getFontDescriptor().getXHeight() / 1000; final float ascent = font.getFontDescriptor().getAscent() / 1000 - base; final float descent = font.getFontDescriptor().getDescent() / 1000; fontMetrics.put(font.getName(), new FontMetrics(base + ascent - descent, ascent, descent)); }
private boolean isItalic(PDFontDescriptor descriptor) { if (descriptor.isItalic()) { return true; } return descriptor.getFontName().contains("Italic"); } }
@Override public byte[] getBytes() throws IOException { PDStream ff3Stream = getFontDescriptor().getFontFile3(); return IOUtils.toByteArray(ff3Stream.createInputStream()); } }