mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 03:17:57 +08:00
remove more unused classes
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
namespace UglyToad.Pdf.Fonts
|
namespace UglyToad.Pdf.Fonts
|
||||||
{
|
{
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Cmap;
|
|
||||||
using Cos;
|
using Cos;
|
||||||
using Geometry;
|
using Geometry;
|
||||||
using IO;
|
using IO;
|
||||||
@@ -19,63 +16,4 @@
|
|||||||
|
|
||||||
PdfVector GetDisplacement(int characterCode);
|
PdfVector GetDisplacement(int characterCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CompositeFont : IFont
|
|
||||||
{
|
|
||||||
private readonly Dictionary<int, decimal> codeToWidthMap = new Dictionary<int, decimal>();
|
|
||||||
|
|
||||||
public CosName Name { get; set; }
|
|
||||||
|
|
||||||
public CosName SubType { get; set; }
|
|
||||||
|
|
||||||
public string BaseFontType { get; set; }
|
|
||||||
|
|
||||||
public bool IsVertical => ToUnicode?.WMode == 1;
|
|
||||||
|
|
||||||
public CMap ToUnicode { get; set; }
|
|
||||||
|
|
||||||
public CosName BaseFont { get; set; }
|
|
||||||
|
|
||||||
public int ReadCharacterCode(IInputBytes bytes, out int codeLength)
|
|
||||||
{
|
|
||||||
var current = bytes.CurrentOffset;
|
|
||||||
|
|
||||||
var code = ToUnicode.ReadCode(bytes);
|
|
||||||
|
|
||||||
codeLength = bytes.CurrentOffset - current;
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetUnicode(int characterCode, out string value)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetUnicode(int characterCode)
|
|
||||||
{
|
|
||||||
if (ToUnicode != null)
|
|
||||||
{
|
|
||||||
if (ToUnicode.TryConvertToUnicode(characterCode, out string s)) return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotImplementedException($"Could not locate the unicode for the character code {characterCode} in font {Name}.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public PdfVector GetDisplacement(int characterCode)
|
|
||||||
{
|
|
||||||
var width = GetCharacterWidth(characterCode);
|
|
||||||
return new PdfVector(width / 1000, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private decimal GetCharacterWidth(int characterCode)
|
|
||||||
{
|
|
||||||
if (codeToWidthMap.TryGetValue(characterCode, out var width))
|
|
||||||
{
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 12000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,68 +0,0 @@
|
|||||||
namespace UglyToad.Pdf.Parser.PageTree
|
|
||||||
{
|
|
||||||
using System;
|
|
||||||
using ContentStream;
|
|
||||||
using ContentStream.TypedAccessors;
|
|
||||||
using Cos;
|
|
||||||
using Filters;
|
|
||||||
using Fonts;
|
|
||||||
|
|
||||||
internal class CompositeFontParser
|
|
||||||
{
|
|
||||||
public CompositeFont Parse(PdfDictionary dictionary, ParsingArguments arguments)
|
|
||||||
{
|
|
||||||
var descendants = dictionary.GetItemOrDefault(CosName.DESCENDANT_FONTS) as COSArray;
|
|
||||||
|
|
||||||
if (descendants == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("DescendantFonts is required for a Type0 composite font. It was not found: " + dictionary);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descendants.Count < 1)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Descendant fonts should be a single element array. There were no elements: " + dictionary);
|
|
||||||
}
|
|
||||||
|
|
||||||
var descendantKey = descendants.get(0) as CosObject;
|
|
||||||
|
|
||||||
var descendant = arguments.Container.Get<DynamicParser>()
|
|
||||||
.Parse(arguments, descendantKey, false);
|
|
||||||
|
|
||||||
var toUnicode = dictionary.GetObjectKey(CosName.TO_UNICODE);
|
|
||||||
|
|
||||||
if (toUnicode != null)
|
|
||||||
{
|
|
||||||
var toUnicodeValue = arguments.Container.Get<DynamicParser>()
|
|
||||||
.Parse(arguments, toUnicode, false);
|
|
||||||
|
|
||||||
if (toUnicodeValue is RawCosStream stream)
|
|
||||||
{
|
|
||||||
var decoded = stream.Decode(arguments.Container.Get<IFilterProvider>());
|
|
||||||
|
|
||||||
// This is described on page 472 of the spec.
|
|
||||||
var str = UglyToad.Pdf.Util.OtherEncodings.BytesAsLatin1String(decoded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CompositeFont();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class SimpleFontParser
|
|
||||||
{
|
|
||||||
public SimpleFont Parse(PdfDictionary dictionary, ParsingArguments arguments)
|
|
||||||
{
|
|
||||||
return new SimpleFont();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SimpleFont
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Font
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
namespace UglyToad.Pdf.Parser.PageTree
|
|
||||||
{
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Content;
|
|
||||||
using Cos;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents the resources specified for a <see cref="Page"/> or <see cref="Pages"/> object.
|
|
||||||
/// </summary>
|
|
||||||
public class ResourceDictionary
|
|
||||||
{
|
|
||||||
private readonly Dictionary<CosName, CosObjectKey> fonts = new Dictionary<CosName, CosObjectKey>();
|
|
||||||
private readonly Dictionary<CosName, Font> fontObjects
|
|
||||||
= new Dictionary<CosName, Font>();
|
|
||||||
|
|
||||||
public void Merge(ResourceDictionary parent)
|
|
||||||
{
|
|
||||||
foreach (var font in parent.fonts)
|
|
||||||
{
|
|
||||||
if (!fonts.ContainsKey(font.Key))
|
|
||||||
{
|
|
||||||
fonts[font.Key] = font.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFonts(IReadOnlyDictionary<CosName, CosObjectKey> resourceFonts)
|
|
||||||
{
|
|
||||||
foreach (var font in resourceFonts)
|
|
||||||
{
|
|
||||||
fonts[font.Key] = font.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ContainsFont(CosName name)
|
|
||||||
{
|
|
||||||
return fonts.ContainsKey(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
namespace UglyToad.Pdf.Parser.PageTree
|
|
||||||
{
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using ContentStream;
|
|
||||||
using ContentStream.TypedAccessors;
|
|
||||||
using Cos;
|
|
||||||
|
|
||||||
internal class ResourceDictionaryParser
|
|
||||||
{
|
|
||||||
public ResourceDictionary Parse(PdfDictionary dictionary, ParsingArguments arguments)
|
|
||||||
{
|
|
||||||
var fontDictionary = dictionary.GetDictionaryOrDefault(CosName.FONT);
|
|
||||||
|
|
||||||
var fontMap = new Dictionary<CosName, CosObjectKey>();
|
|
||||||
|
|
||||||
if (fontDictionary != null)
|
|
||||||
{
|
|
||||||
foreach (var entry in fontDictionary)
|
|
||||||
{
|
|
||||||
fontMap[entry.Key] = new CosObjectKey(entry.Value as CosObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new ResourceDictionary();
|
|
||||||
|
|
||||||
result.SetFonts(fontMap);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -4,7 +4,6 @@
|
|||||||
using Fonts.Parser;
|
using Fonts.Parser;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Parser;
|
using Parser;
|
||||||
using Parser.PageTree;
|
|
||||||
using Parser.Parts;
|
using Parser.Parts;
|
||||||
using Parser.Parts.CrossReference;
|
using Parser.Parts.CrossReference;
|
||||||
|
|
||||||
@@ -42,11 +41,7 @@
|
|||||||
|
|
||||||
var crossReferenceTableParser = new FileCrossReferenceTableParser(logger, dictionaryParser, baseParser, streamParser, crossReferenceParser,
|
var crossReferenceTableParser = new FileCrossReferenceTableParser(logger, dictionaryParser, baseParser, streamParser, crossReferenceParser,
|
||||||
new CrossReferenceTableParser(logger, dictionaryParser, baseParser));
|
new CrossReferenceTableParser(logger, dictionaryParser, baseParser));
|
||||||
|
|
||||||
var resourceDictionaryParser = new ResourceDictionaryParser();
|
|
||||||
var simpleFontParser = new SimpleFontParser();
|
|
||||||
var compositeFontParser = new CompositeFontParser();
|
|
||||||
|
|
||||||
var cmapParser = new CMapParser();
|
var cmapParser = new CMapParser();
|
||||||
var afmParser = new AdobeFontMetricsParser();
|
var afmParser = new AdobeFontMetricsParser();
|
||||||
|
|
||||||
@@ -62,9 +57,6 @@
|
|||||||
container.Register(dynamicParser);
|
container.Register(dynamicParser);
|
||||||
container.Register(objectStreamParser);
|
container.Register(objectStreamParser);
|
||||||
container.Register(filterProvider);
|
container.Register(filterProvider);
|
||||||
container.Register(resourceDictionaryParser);
|
|
||||||
container.Register(simpleFontParser);
|
|
||||||
container.Register(compositeFontParser);
|
|
||||||
container.Register(cmapParser);
|
container.Register(cmapParser);
|
||||||
container.Register(afmParser);
|
container.Register(afmParser);
|
||||||
container.Register(logger);
|
container.Register(logger);
|
||||||
|
Reference in New Issue
Block a user