re-use truetype parser for opentype cid fonts

This commit is contained in:
Eliot Jones 2020-06-20 12:46:41 +01:00
parent 79dea8d314
commit 982c331935

View File

@ -114,9 +114,11 @@
switch (descriptor.FontFile.FileType) switch (descriptor.FontFile.FileType)
{ {
case DescriptorFontFile.FontFileType.TrueType: case DescriptorFontFile.FontFileType.TrueType:
{
var input = new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)); var input = new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile));
var ttf = TrueTypeFontParser.Parse(input); var ttf = TrueTypeFontParser.Parse(input);
return new PdfCidTrueTypeFont(ttf); return new PdfCidTrueTypeFont(ttf);
}
case DescriptorFontFile.FontFileType.FromSubtype: case DescriptorFontFile.FontFileType.FromSubtype:
{ {
if (!DirectObjectFinder.TryGet(descriptor.FontFile.ObjectKey, pdfScanner, out StreamToken str)) if (!DirectObjectFinder.TryGet(descriptor.FontFile.ObjectKey, pdfScanner, out StreamToken str))
@ -139,15 +141,13 @@
if (subtypeName == NameToken.OpenType) if (subtypeName == NameToken.OpenType)
{ {
var bytes = str.Decode(filterProvider);
var ttf = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(bytes)));
return new PdfCidTrueTypeFont(ttf);
} }
else
{
throw new PdfDocumentFormatException($"Unexpected subtype for CID font: {subtypeName}."); throw new PdfDocumentFormatException($"Unexpected subtype for CID font: {subtypeName}.");
} }
throw new NotSupportedException($"Cannot read CID font from subtype: {subtypeName}.");
}
default: default:
throw new NotSupportedException("Currently only TrueType fonts are supported."); throw new NotSupportedException("Currently only TrueType fonts are supported.");
} }