OpenType is a format for scalable computer fonts. It was built on its predecessor TrueType, retaining TrueType’s basic structure and adding many intricate data structures for prescribing typographic behavior.
Note
Please find more information on the OpenType format here: https://en.wikipedia.org/wiki/OpenType.
Reading OpenType metadata
The GroupDocs.Metadata API supports extracting format-specific information from OpenType font files.
The following are the steps to read the header of an OpenType file.
try(Metadatametadata=newMetadata(Constants.InputTtf)){OpenTypeRootPackageroot=metadata.getRootPackageGeneric();// Read the OpenType font metadatafor(OpenTypeFontmetadataEntry:root.getOpenTypePackage().getFonts()){// Display the values of some metadata propertiesSystem.out.println(metadataEntry.getCreated());System.out.println(metadataEntry.getDirectionHint());System.out.println(metadataEntry.getEmbeddingLicensingRights());System.out.println(metadataEntry.getFlags());System.out.println(metadataEntry.getFontFamilyName());System.out.println(metadataEntry.getFontRevision());System.out.println(metadataEntry.getFontSubfamilyName());System.out.println(metadataEntry.getFullFontName());System.out.println(metadataEntry.getGlyphBounds());System.out.println(metadataEntry.getMajorVersion());System.out.println(metadataEntry.getMinorVersion());System.out.println(metadataEntry.getModified());System.out.println(metadataEntry.getSfntVersion());System.out.println(metadataEntry.getStyle());System.out.println(metadataEntry.getTypographicFamily());System.out.println(metadataEntry.getTypographicSubfamily());System.out.println(metadataEntry.getWeight());System.out.println(metadataEntry.getWidth());for(OpenTypeBaseNameRecordnameRecord:metadataEntry.getNames()){System.out.println(nameRecord.getNameID());System.out.println(nameRecord.getPlatform());System.out.println(nameRecord.getValue());if(nameRecordinstanceofOpenTypeMacintoshNameRecord){OpenTypeMacintoshNameRecordmacintoshNameRecord=(OpenTypeMacintoshNameRecord)nameRecord;System.out.println(macintoshNameRecord.getEncoding());System.out.println(macintoshNameRecord.getLanguage());}else{if(nameRecordinstanceofOpenTypeUnicodeNameRecord){OpenTypeUnicodeNameRecordunicodeNameRecord=(OpenTypeUnicodeNameRecord)nameRecord;System.out.println(unicodeNameRecord.getEncoding());}else{if(nameRecordinstanceofOpenTypeWindowsNameRecord){OpenTypeWindowsNameRecordwindowsNameRecord=(OpenTypeWindowsNameRecord)nameRecord;System.out.println(windowsNameRecord.getEncoding());System.out.println(windowsNameRecord.getLanguage());}}}}}}
Reading digital signatures
The code snippet bellow demonstrates how to extract information about digital signatures associated with an OpenType font.
publicstaticvoidrun(){try(Metadatametadata=newMetadata(Constants.InputTtf)){OpenTypeRootPackageroot=metadata.getRootPackageGeneric();if(root.getDigitalSignaturePackage()!=null){System.out.println(root.getDigitalSignaturePackage().getFlags());for(Cmssignature:root.getDigitalSignaturePackage().getSignatures()){System.out.println(signature.getSignTime());if(signature.getDigestAlgorithms()!=null){for(OidsignatureDigestAlgorithm:signature.getDigestAlgorithms()){printOid(signatureDigestAlgorithm);}}if(signature.getEncapsulatedContent()!=null){printOid(signature.getEncapsulatedContent().getContentType());System.out.println(signature.getEncapsulatedContent().getContentRawData().length);}if(signature.getCertificates()!=null){for(CmsCertificatecertificate:signature.getCertificates()){System.out.println(certificate.getNotAfter());System.out.println(certificate.getNotBefore());System.out.println(certificate.getRawData().length);}}if(signature.getSigners()!=null){for(CmsSignersignerInfoEntry:signature.getSigners()){System.out.println(signerInfoEntry.getSignatureValue());printOid(signerInfoEntry.getDigestAlgorithm());printOid(signerInfoEntry.getSignatureAlgorithm());System.out.println(signerInfoEntry.getSigningTime());printAttributes(signerInfoEntry.getSignedAttributes());printAttributes(signerInfoEntry.getUnsignedAttributes());}}}}}}privatestaticvoidprintOid(Oidoid){// Display the property name and value of OIDif(oid!=null){System.out.println(oid.getFriendlyName());System.out.println(oid.getValue());}}privatestaticvoidprintAttributes(CmsAttribute[]attributes){//Display the CmsAttributes of an OIDif(attributes!=null){for(CmsAttributeattribute:attributes){printOid(attribute.getOid());System.out.println(attribute.getValue());}}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: