use of org.apache.fontbox.cff.CFFFont in project veraPDF-pdfbox-validation by veraPDF.
the class PBoxPDType1Font method getcharSetListsAllGlyphs.
@Override
public Boolean getcharSetListsAllGlyphs() {
try {
PDFontDescriptor fontDescriptor = pdFontLike.getFontDescriptor();
if (fontDescriptor != null) {
String charSet = fontDescriptor.getCharSet();
if (charSet != null) {
String[] splittedCharSet = fontDescriptor.getCharSet().split("/");
// TODO : Log warning if charset doesn't start with '/'
FontBoxFont font = ((org.apache.pdfbox.pdmodel.font.PDSimpleFont) pdFontLike).getFontBoxFont();
for (int i = 1; i < splittedCharSet.length; i++) {
if (!font.hasGlyph(splittedCharSet[i])) {
return Boolean.FALSE;
}
}
if (font instanceof Type1Font) {
if (((Type1Font) font).getCharStringsDict().size() != splittedCharSet.length) {
return Boolean.FALSE;
}
} else if (font instanceof CFFFont) {
if (((CFFFont) font).getNumCharStrings() != splittedCharSet.length) {
return Boolean.FALSE;
}
}
// }
return Boolean.TRUE;
}
}
} catch (IOException e) {
LOGGER.debug("Error while parsing embedded font program. " + e.getMessage(), e);
}
return Boolean.FALSE;
}
use of org.apache.fontbox.cff.CFFFont in project xmlgraphics-fop by apache.
the class CFFToType1Font method convertOTFToType1.
private List<InputStream> convertOTFToType1(InputStream in) throws IOException {
CFFFont f = new CFFParser().parse(IOUtils.toByteArray(in)).get(0);
List<InputStream> fonts = new ArrayList<InputStream>();
Map<Integer, Integer> glyphs = cidSet.getGlyphs();
int i = 0;
for (Map<Integer, Integer> x : splitGlyphs(glyphs)) {
String iStr = "." + i;
fonts.add(convertOTFToType1(x, f, iStr));
i++;
}
return fonts;
}
use of org.apache.fontbox.cff.CFFFont in project xmlgraphics-fop by apache.
the class OTFSubSetFileTestCase method validateCharStrings.
/**
* Validates the subset font CharString data by comparing it with the original.
* @param subsetCFF The subset CFFDataReader containing the CharString data
* @param origCFF The original CFFDataReader containing the CharString data
* @throws IOException
*/
private void validateCharStrings(CFFDataReader subsetCFF, CFFDataReader origCFF) throws IOException {
CFFFont sourceSansOriginal = sourceSansProBold.fileFont;
CFFIndexData charStrings = subsetCFF.getCharStringIndex();
List<byte[]> origCharStringData = sourceSansOriginal.getCharStringBytes();
for (int i = 0; i < charStrings.getNumObjects(); i++) {
byte[] origCharData = origCharStringData.get(i);
byte[] charData = charStrings.getValue(i);
List<BytesNumber> origOperands = getFullCharString(new Context(), origCharData, origCFF);
List<BytesNumber> subsetOperands = getFullCharString(new Context(), charData, subsetCFF);
for (int j = 0; j < origOperands.size(); j++) {
assertTrue(origOperands.get(j).equals(subsetOperands.get(j)));
}
}
}
use of org.apache.fontbox.cff.CFFFont in project sambox by torakiki.
the class FileSystemFontProvider method addTrueTypeFontImpl.
/**
* Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached.
*/
private void addTrueTypeFontImpl(TrueTypeFont ttf, File file) throws IOException {
try {
// read PostScript name, if any
if (ttf.getName() != null) {
// ignore bitmap fonts
if (ttf.getHeader() == null) {
fontInfoList.add(new FSIgnored(file, FontFormat.TTF, ttf.getName()));
return;
}
int macStyle = ttf.getHeader().getMacStyle();
int sFamilyClass = -1;
int usWeightClass = -1;
int ulCodePageRange1 = 0;
int ulCodePageRange2 = 0;
byte[] panose = null;
OS2WindowsMetricsTable os2WindowsMetricsTable = ttf.getOS2Windows();
// Apple's AAT fonts don't have an OS/2 table
if (nonNull(os2WindowsMetricsTable)) {
sFamilyClass = os2WindowsMetricsTable.getFamilyClass();
usWeightClass = os2WindowsMetricsTable.getWeightClass();
ulCodePageRange1 = (int) os2WindowsMetricsTable.getCodePageRange1();
ulCodePageRange2 = (int) os2WindowsMetricsTable.getCodePageRange2();
panose = os2WindowsMetricsTable.getPanose();
}
String format;
if (ttf instanceof OpenTypeFont && ((OpenTypeFont) ttf).isPostScript()) {
format = "OTF";
CFFFont cff = ((OpenTypeFont) ttf).getCFF().getFont();
CIDSystemInfo ros = null;
if (cff instanceof CFFCIDFont) {
CFFCIDFont cidFont = (CFFCIDFont) cff;
String registry = cidFont.getRegistry();
String ordering = cidFont.getOrdering();
int supplement = cidFont.getSupplement();
ros = new CIDSystemInfo(registry, ordering, supplement);
}
fontInfoList.add(new FSFontInfo(file, FontFormat.OTF, ttf.getName(), ros, usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2, macStyle, panose, this));
} else {
CIDSystemInfo ros = null;
if (ttf.getTableMap().containsKey("gcid")) {
// Apple's AAT fonts have a "gcid" table with CID info
byte[] bytes = ttf.getTableBytes(ttf.getTableMap().get("gcid"));
String reg = new String(bytes, 10, 64, StandardCharsets.US_ASCII);
String registryName = reg.substring(0, reg.indexOf('\0'));
String ord = new String(bytes, 76, 64, StandardCharsets.US_ASCII);
String orderName = ord.substring(0, ord.indexOf('\0'));
int supplementVersion = bytes[140] << 8 & (bytes[141] & 0xFF);
ros = new CIDSystemInfo(registryName, orderName, supplementVersion);
}
format = "TTF";
fontInfoList.add(new FSFontInfo(file, FontFormat.TTF, ttf.getName(), ros, usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2, macStyle, panose, this));
}
if (LOG.isTraceEnabled()) {
NamingTable name = ttf.getNaming();
if (name != null) {
LOG.trace(format + ": '" + name.getPostScriptName() + "' / '" + name.getFontFamily() + "' / '" + name.getFontSubFamily() + "'");
}
}
} else {
fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipnoname*"));
LOG.warn("Missing 'name' entry for PostScript name in font " + file);
}
} catch (IOException e) {
fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipexception*"));
LOG.warn("Could not load font file: " + file, e);
} finally {
IOUtils.close(ttf);
}
}
use of org.apache.fontbox.cff.CFFFont in project docx4j by plutext.
the class CFFToType1Font method convertOTFToType1.
private List<InputStream> convertOTFToType1(InputStream in) throws IOException {
CFFFont f = new CFFParser().parse(IOUtils.toByteArray(in)).get(0);
List<InputStream> fonts = new ArrayList<InputStream>();
Map<Integer, Integer> glyphs = cidSet.getGlyphs();
int i = 0;
for (Map<Integer, Integer> x : splitGlyphs(glyphs)) {
String iStr = "." + i;
fonts.add(convertOTFToType1(x, f, iStr));
i++;
}
return fonts;
}
Aggregations