use of org.apache.fontbox.afm.AFMParser in project tika by apache.
the class AdobeFontMetricParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
FontMetrics fontMetrics;
AFMParser parser = new AFMParser(stream);
// Have FontBox process the file
fontMetrics = parser.parse();
// Get the comments in the file to display in xhtml
List<String> unModifiableComments = fontMetrics.getComments();
//have to copy because we modify list in extractCreationDate
List<String> comments = new ArrayList<>();
for (String comment : unModifiableComments) {
comments.add(comment);
}
// Get the creation date
extractCreationDate(metadata, comments);
metadata.set(Metadata.CONTENT_TYPE, AFM_TYPE.toString());
metadata.set(TikaCoreProperties.TITLE, fontMetrics.getFullName());
// Add metadata associated with the font type
addMetadataByString(metadata, MET_AVG_CHAR_WIDTH, Float.toString(fontMetrics.getAverageCharacterWidth()));
addMetadataByString(metadata, MET_DOC_VERSION, Float.toString(fontMetrics.getAFMVersion()));
addMetadataByString(metadata, MET_FONT_NAME, fontMetrics.getFontName());
addMetadataByString(metadata, MET_FONT_FULL_NAME, fontMetrics.getFullName());
addMetadataByString(metadata, MET_FONT_FAMILY_NAME, fontMetrics.getFamilyName());
addMetadataByString(metadata, MET_FONT_VERSION, fontMetrics.getFontVersion());
addMetadataByString(metadata, MET_FONT_WEIGHT, fontMetrics.getWeight());
addMetadataByString(metadata, MET_FONT_NOTICE, fontMetrics.getNotice());
addMetadataByString(metadata, MET_FONT_UNDERLINE_THICKNESS, Float.toString(fontMetrics.getUnderlineThickness()));
// Output the remaining comments as text
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
// Display the comments
if (comments.size() > 0) {
xhtml.element("h1", "Comments");
xhtml.startElement("div", "class", "comments");
for (String comment : comments) {
xhtml.element("p", comment);
}
xhtml.endElement("div");
}
xhtml.endDocument();
}
Aggregations