mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
add support for standardencoding in type 1 fonts #78
This commit is contained in:
@@ -97,13 +97,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Encoding fromFont = null;
|
Encoding fromFont = font?.Match(x => x.Encoding != null ? new BuiltInEncoding(x.Encoding) : default(Encoding), x =>
|
||||||
font?.Match(x => fromFont = x.Encoding != null ? new BuiltInEncoding(x.Encoding) : default(Encoding), x =>
|
|
||||||
{
|
{
|
||||||
if (x.Fonts != null && x.Fonts.Count > 0)
|
if (x.Fonts != null && x.Fonts.Count > 0)
|
||||||
{
|
{
|
||||||
fromFont = x.Fonts.First().Value.Encoding;
|
return x.Fonts.First().Value.Encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return default(Encoding);
|
||||||
});
|
});
|
||||||
|
|
||||||
Encoding encoding = encodingReader.Read(dictionary, isLenientParsing, descriptor, fromFont);
|
Encoding encoding = encodingReader.Read(dictionary, isLenientParsing, descriptor, fromFont);
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
namespace UglyToad.PdfPig.Fonts.Simple
|
namespace UglyToad.PdfPig.Fonts.Simple
|
||||||
{
|
{
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Cmap;
|
using Cmap;
|
||||||
using CompactFontFormat;
|
using CompactFontFormat;
|
||||||
@@ -165,11 +164,10 @@
|
|||||||
return new PdfRectangle(0, 0, widths[characterCode - firstChar], 0);
|
return new PdfRectangle(0, 0, widths[characterCode - firstChar], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rect = default(PdfRectangle?);
|
var rect = fontProgram.Match(x =>
|
||||||
fontProgram.Match(x =>
|
|
||||||
{
|
{
|
||||||
var name = encoding.GetName(characterCode);
|
var name = encoding.GetName(characterCode);
|
||||||
rect = x.GetCharacterBoundingBox(name);
|
return x.GetCharacterBoundingBox(name);
|
||||||
},
|
},
|
||||||
x =>
|
x =>
|
||||||
{
|
{
|
||||||
@@ -182,7 +180,8 @@
|
|||||||
{
|
{
|
||||||
characterName = x.GetCharacterName(characterCode);
|
characterName = x.GetCharacterName(characterCode);
|
||||||
}
|
}
|
||||||
rect = x.GetCharacterBoundingBox(characterName);
|
|
||||||
|
return x.GetCharacterBoundingBox(characterName);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!rect.HasValue)
|
if (!rect.HasValue)
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Encodings;
|
||||||
using Exceptions;
|
using Exceptions;
|
||||||
using Geometry;
|
using Geometry;
|
||||||
using IO;
|
using IO;
|
||||||
@@ -254,7 +255,8 @@
|
|||||||
|
|
||||||
if (key.Data.Equals(NameToken.Encoding))
|
if (key.Data.Equals(NameToken.Encoding))
|
||||||
{
|
{
|
||||||
dictionary[key] = ReadEncoding(scanner);
|
var encoding = ReadEncoding(scanner);
|
||||||
|
dictionary[key] = (IToken)encoding.encoding ?? encoding.name;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,19 +298,25 @@
|
|||||||
return new DictionaryToken(dictionary);
|
return new DictionaryToken(dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayToken ReadEncoding(ISeekableTokenScanner scanner)
|
private static (ArrayToken encoding, NameToken name) ReadEncoding(ISeekableTokenScanner scanner)
|
||||||
{
|
{
|
||||||
var result = new List<IToken>();
|
var result = new List<IToken>();
|
||||||
|
|
||||||
// Treat encoding differently, it's what we came here for!
|
// Treat encoding differently, it's what we came here for!
|
||||||
if (!scanner.TryReadToken(out NumericToken _))
|
if (!scanner.TryReadToken(out NumericToken _))
|
||||||
{
|
{
|
||||||
return new ArrayToken(result);
|
// The tokens following /Encoding may be StandardEncoding def.
|
||||||
|
if (scanner.CurrentToken is OperatorToken encodingName
|
||||||
|
&& encodingName.Data.Equals(NameToken.StandardEncoding))
|
||||||
|
{
|
||||||
|
return (null, NameToken.StandardEncoding);
|
||||||
|
}
|
||||||
|
return (new ArrayToken(result), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scanner.TryReadToken(out OperatorToken arrayOperatorToken) || arrayOperatorToken.Data != "array")
|
if (!scanner.TryReadToken(out OperatorToken arrayOperatorToken) || arrayOperatorToken.Data != "array")
|
||||||
{
|
{
|
||||||
return new ArrayToken(result);
|
return (new ArrayToken(result), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (scanner.MoveNext() && (!(scanner.CurrentToken is OperatorToken forOperator) || forOperator.Data != "for"))
|
while (scanner.MoveNext() && (!(scanner.CurrentToken is OperatorToken forOperator) || forOperator.Data != "for"))
|
||||||
@@ -318,7 +326,7 @@
|
|||||||
|
|
||||||
if (scanner.CurrentToken != OperatorToken.For)
|
if (scanner.CurrentToken != OperatorToken.For)
|
||||||
{
|
{
|
||||||
return new ArrayToken(result);
|
return (new ArrayToken(result), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (scanner.MoveNext() && scanner.CurrentToken != OperatorToken.Def && scanner.CurrentToken != OperatorToken.Readonly)
|
while (scanner.MoveNext() && scanner.CurrentToken != OperatorToken.Def && scanner.CurrentToken != OperatorToken.Readonly)
|
||||||
@@ -347,26 +355,34 @@
|
|||||||
// skip
|
// skip
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayToken(result);
|
return (new ArrayToken(result), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<int, string> GetEncoding(IReadOnlyList<DictionaryToken> dictionaries)
|
private static IReadOnlyDictionary<int, string> GetEncoding(IReadOnlyList<DictionaryToken> dictionaries)
|
||||||
{
|
{
|
||||||
var result = new Dictionary<int, string>();
|
var result = new Dictionary<int, string>();
|
||||||
|
|
||||||
foreach (var dictionary in dictionaries)
|
foreach (var dictionary in dictionaries)
|
||||||
{
|
{
|
||||||
if (dictionary.TryGet(NameToken.Encoding, out var token) && token is ArrayToken encodingArray)
|
if (dictionary.TryGet(NameToken.Encoding, out var token))
|
||||||
{
|
{
|
||||||
for (var i = 0; i < encodingArray.Data.Count; i += 2)
|
if (token is ArrayToken encodingArray)
|
||||||
{
|
{
|
||||||
var code = (NumericToken)encodingArray.Data[i];
|
for (var i = 0; i < encodingArray.Data.Count; i += 2)
|
||||||
var name = (NameToken)encodingArray.Data[i + 1];
|
{
|
||||||
|
var code = (NumericToken) encodingArray.Data[i];
|
||||||
|
var name = (NameToken) encodingArray.Data[i + 1];
|
||||||
|
|
||||||
result[code.Int] = name.Data;
|
result[code.Int] = name.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
if (token is NameToken encodingName && encodingName.Equals(NameToken.StandardEncoding))
|
||||||
|
{
|
||||||
|
return StandardEncoding.Instance.CodeToNameMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
<PackageTags>PDF;Reader;Document;Adobe;PDFBox;PdfPig;pdf-extract</PackageTags>
|
<PackageTags>PDF;Reader;Document;Adobe;PDFBox;PdfPig;pdf-extract</PackageTags>
|
||||||
<RepositoryUrl>https://github.com/UglyToad/PdfPig</RepositoryUrl>
|
<RepositoryUrl>https://github.com/UglyToad/PdfPig</RepositoryUrl>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<Version>0.0.9</Version>
|
<Version>0.0.9.91</Version>
|
||||||
<AssemblyVersion>0.0.9.0</AssemblyVersion>
|
<AssemblyVersion>0.0.9.0</AssemblyVersion>
|
||||||
<FileVersion>0.0.9.0</FileVersion>
|
<FileVersion>0.0.9.0</FileVersion>
|
||||||
<PackageIconUrl>https://raw.githubusercontent.com/UglyToad/PdfPig/master/documentation/pdfpig.png</PackageIconUrl>
|
<PackageIconUrl>https://raw.githubusercontent.com/UglyToad/PdfPig/master/documentation/pdfpig.png</PackageIconUrl>
|
||||||
|
Reference in New Issue
Block a user