mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
complete move of truetype, afm and standard14 fonts
the 3 font types mentioned are moved to the new fonts project, any referenced types are moved to the core project. most truetype classes are made public #8.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Parser.Parts;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content;
|
||||
using Core;
|
||||
using Geometry;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Graphics.Colors;
|
||||
using Parser.Parts;
|
||||
using PdfFonts;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using Util;
|
||||
using PdfPig.Core;
|
||||
|
||||
internal static class OperationWriteHelper
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
||||
{
|
||||
using System.IO;
|
||||
using Geometry;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
||||
{
|
||||
using System.IO;
|
||||
using Geometry;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
@@ -10,7 +10,6 @@
|
||||
/// </summary>
|
||||
public class AppendEndControlPointBezierCurve : IGraphicsStateOperation
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The symbol for this operation in a stream.
|
||||
/// </summary>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
||||
{
|
||||
using System.IO;
|
||||
using Geometry;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
||||
{
|
||||
using System.IO;
|
||||
using Geometry;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
||||
{
|
||||
using System.IO;
|
||||
using Geometry;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
||||
{
|
||||
using System.IO;
|
||||
using Geometry;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
|
@@ -1,8 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Graphics.Operations.TextShowing
|
||||
{
|
||||
using System.IO;
|
||||
using IO;
|
||||
using Util;
|
||||
using PdfPig.Core;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@@ -4,7 +4,6 @@ namespace UglyToad.PdfPig.Graphics
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Exceptions;
|
||||
using Operations;
|
||||
using Operations.ClippingPaths;
|
||||
using Operations.Compatibility;
|
||||
@@ -17,6 +16,7 @@ namespace UglyToad.PdfPig.Graphics
|
||||
using Operations.TextPositioning;
|
||||
using Operations.TextShowing;
|
||||
using Operations.TextState;
|
||||
using PdfPig.Core;
|
||||
using Tokens;
|
||||
|
||||
internal class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
|
||||
|
@@ -2,10 +2,10 @@
|
||||
{
|
||||
using Content;
|
||||
using Destinations;
|
||||
using Exceptions;
|
||||
using Logging;
|
||||
using Parser.Parts;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using Util;
|
||||
|
@@ -3,11 +3,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Parts;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using Util;
|
||||
|
||||
internal static class CatalogFactory
|
||||
{
|
||||
|
@@ -3,7 +3,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CrossReference;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Parts.CrossReference;
|
||||
using Tokenization;
|
||||
using Tokenization.Scanner;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using Content;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Logging;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
@@ -4,11 +4,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Annotations;
|
||||
using Content;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Filters;
|
||||
using Geometry;
|
||||
using Graphics;
|
||||
using IO;
|
||||
using Logging;
|
||||
using Parts;
|
||||
using Tokenization.Scanner;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Parser.Parts.CrossReference
|
||||
{
|
||||
using System;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Tokens;
|
||||
using Util;
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Parser.Parts.CrossReference
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Filters;
|
||||
using PdfPig.CrossReference;
|
||||
using Tokens;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.Parser.Parts
|
||||
{
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
||||
|
@@ -9,9 +9,9 @@
|
||||
using Core;
|
||||
using CrossReference;
|
||||
using Encryption;
|
||||
using Exceptions;
|
||||
using FileStructure;
|
||||
using Filters;
|
||||
using Fonts.SystemFonts;
|
||||
using Graphics;
|
||||
using Logging;
|
||||
using Outline;
|
||||
@@ -23,7 +23,6 @@
|
||||
using PdfFonts.Parser;
|
||||
using PdfFonts.Parser.Handlers;
|
||||
using PdfFonts.Parser.Parts;
|
||||
using PdfFonts.SystemFonts;
|
||||
using PdfFonts.Type1.Parser;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
@@ -115,7 +114,6 @@
|
||||
|
||||
crossReferenceTable = crossReferenceParser.Parse(inputBytes, isLenientParsing, crossReferenceOffset, pdfScanner, scanner);
|
||||
|
||||
var trueTypeFontParser = new TrueTypeFontParser();
|
||||
var fontDescriptorFactory = new FontDescriptorFactory();
|
||||
var compactFontFormatParser = new CompactFontFormatParser(new CompactFontFormatIndividualFontParser(new CompactFontFormatTopLevelDictionaryReader(),
|
||||
new CompactFontFormatPrivateDictionaryReader()));
|
||||
@@ -130,12 +128,12 @@
|
||||
|
||||
pdfScanner.UpdateEncryptionHandler(encryptionHandler);
|
||||
|
||||
var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, trueTypeFontParser, compactFontFormatParser, filterProvider);
|
||||
var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, compactFontFormatParser, filterProvider);
|
||||
var encodingReader = new EncodingReader(pdfScanner);
|
||||
|
||||
var fontFactory = new FontFactory(log, new Type0FontHandler(cidFontFactory,
|
||||
filterProvider, pdfScanner),
|
||||
new TrueTypeFontHandler(log, pdfScanner, filterProvider, fontDescriptorFactory, trueTypeFontParser, encodingReader, new SystemFontFinder(new TrueTypeFontParser())),
|
||||
new TrueTypeFontHandler(log, pdfScanner, filterProvider, fontDescriptorFactory, encodingReader, new SystemFontFinder()),
|
||||
new Type1FontHandler(pdfScanner, filterProvider, fontDescriptorFactory, encodingReader,
|
||||
new Type1FontParser(new Type1EncryptedPortionParser()), compactFontFormatParser),
|
||||
new Type3FontHandler(pdfScanner, filterProvider, encodingReader));
|
||||
|
17
src/UglyToad.PdfPig/PdfFonts/CharacterBoundingBox.cs
Normal file
17
src/UglyToad.PdfPig/PdfFonts/CharacterBoundingBox.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts
|
||||
{
|
||||
using Core;
|
||||
|
||||
internal class CharacterBoundingBox
|
||||
{
|
||||
public PdfRectangle GlyphBounds { get; }
|
||||
|
||||
public double Width { get; }
|
||||
|
||||
public CharacterBoundingBox(PdfRectangle bounds, double width)
|
||||
{
|
||||
GlyphBounds = bounds;
|
||||
Width = width;
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Util;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// A mutable class used when parsing and generating a <see cref="CMap"/>.
|
||||
|
@@ -1,12 +1,13 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Encodings
|
||||
{
|
||||
using System;
|
||||
using Fonts.AdobeFontMetrics;
|
||||
|
||||
internal class AdobeFontMetricsEncoding : Encoding
|
||||
{
|
||||
public override string EncodingName { get; } = "AFM";
|
||||
|
||||
public AdobeFontMetricsEncoding(FontMetrics metrics)
|
||||
public AdobeFontMetricsEncoding(AdobeFontMetrics metrics)
|
||||
{
|
||||
if (metrics == null)
|
||||
{
|
||||
|
@@ -3,20 +3,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SystemFonts;
|
||||
using Cmap;
|
||||
using Core;
|
||||
using Encodings;
|
||||
using Exceptions;
|
||||
using Filters;
|
||||
using IO;
|
||||
using Fonts;
|
||||
using Fonts.Standard14Fonts;
|
||||
using Fonts.SystemFonts;
|
||||
using Fonts.TrueType;
|
||||
using Fonts.TrueType.Parser;
|
||||
using Logging;
|
||||
using Parts;
|
||||
using PdfPig.Parser.Parts;
|
||||
using Simple;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using TrueType;
|
||||
using TrueType.Parser;
|
||||
using Util;
|
||||
|
||||
internal class TrueTypeFontHandler : IFontHandler
|
||||
@@ -25,20 +26,17 @@
|
||||
private readonly IPdfTokenScanner pdfScanner;
|
||||
private readonly IFilterProvider filterProvider;
|
||||
private readonly FontDescriptorFactory fontDescriptorFactory;
|
||||
private readonly TrueTypeFontParser trueTypeFontParser;
|
||||
private readonly IEncodingReader encodingReader;
|
||||
private readonly ISystemFontFinder systemFontFinder;
|
||||
|
||||
public TrueTypeFontHandler(ILog log, IPdfTokenScanner pdfScanner, IFilterProvider filterProvider,
|
||||
FontDescriptorFactory fontDescriptorFactory,
|
||||
TrueTypeFontParser trueTypeFontParser,
|
||||
IEncodingReader encodingReader,
|
||||
ISystemFontFinder systemFontFinder)
|
||||
{
|
||||
this.log = log;
|
||||
this.filterProvider = filterProvider;
|
||||
this.fontDescriptorFactory = fontDescriptorFactory;
|
||||
this.trueTypeFontParser = trueTypeFontParser;
|
||||
this.encodingReader = encodingReader;
|
||||
this.systemFontFinder = systemFontFinder;
|
||||
this.pdfScanner = pdfScanner;
|
||||
@@ -127,7 +125,7 @@
|
||||
if (font.TableRegister.CMapTable.TryGetGlyphIndex(i, out var index))
|
||||
{
|
||||
string glyphName;
|
||||
if (index >= 0 && index < postscript.GlyphNames.Length)
|
||||
if (index >= 0 && index < postscript.GlyphNames.Count)
|
||||
{
|
||||
glyphName = postscript.GlyphNames[index];
|
||||
}
|
||||
@@ -146,13 +144,14 @@
|
||||
return new TrueTypeSimpleFont(name, descriptor, toUnicodeCMap, encoding, font, firstCharacter, widths);
|
||||
}
|
||||
|
||||
private TrueTypeFontProgram ParseTrueTypeFont(FontDescriptor descriptor)
|
||||
private TrueTypeFont ParseTrueTypeFont(FontDescriptor descriptor)
|
||||
{
|
||||
if (descriptor.FontFile == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return systemFontFinder.GetTrueTypeFont(descriptor.FontName.Data);
|
||||
var ttf = systemFontFinder.GetTrueTypeFont(descriptor.FontName.Data);
|
||||
return ttf;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -175,7 +174,7 @@
|
||||
|
||||
var fontFile = fontFileStream.Decode(filterProvider);
|
||||
|
||||
var font = trueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)));
|
||||
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)));
|
||||
|
||||
return font;
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@
|
||||
using CidFonts;
|
||||
using Cmap;
|
||||
using Composite;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Filters;
|
||||
using IO;
|
||||
using Fonts;
|
||||
using Parts;
|
||||
using PdfPig.Parser.Parts;
|
||||
using Tokenization.Scanner;
|
||||
|
@@ -7,6 +7,7 @@
|
||||
using Encodings;
|
||||
using Filters;
|
||||
using Fonts;
|
||||
using Fonts.Standard14Fonts;
|
||||
using Parts;
|
||||
using PdfPig.Parser.Parts;
|
||||
using Simple;
|
||||
@@ -14,7 +15,6 @@
|
||||
using Tokens;
|
||||
using Type1;
|
||||
using Type1.Parser;
|
||||
using Fonts;
|
||||
|
||||
internal class Type1FontHandler : IFontHandler
|
||||
{
|
||||
|
@@ -3,10 +3,8 @@
|
||||
using Cmap;
|
||||
using Core;
|
||||
using Encodings;
|
||||
using Exceptions;
|
||||
using Filters;
|
||||
using Geometry;
|
||||
using IO;
|
||||
using Fonts;
|
||||
using PdfPig.Parser.Parts;
|
||||
using Simple;
|
||||
using Tokenization.Scanner;
|
||||
|
@@ -5,32 +5,30 @@
|
||||
using CidFonts;
|
||||
using CompactFontFormat;
|
||||
using Core;
|
||||
using Exceptions;
|
||||
using Filters;
|
||||
using Fonts;
|
||||
using Fonts.TrueType;
|
||||
using Fonts.TrueType.Parser;
|
||||
using Geometry;
|
||||
using PdfPig.Parser.Parts;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using TrueType;
|
||||
using Util;
|
||||
|
||||
internal class CidFontFactory
|
||||
{
|
||||
private readonly FontDescriptorFactory descriptorFactory;
|
||||
private readonly TrueTypeFontParser trueTypeFontParser;
|
||||
private readonly CompactFontFormatParser compactFontFormatParser;
|
||||
private readonly IFilterProvider filterProvider;
|
||||
private readonly IPdfTokenScanner pdfScanner;
|
||||
|
||||
public CidFontFactory(IPdfTokenScanner pdfScanner, FontDescriptorFactory descriptorFactory,
|
||||
TrueTypeFontParser trueTypeFontParser,
|
||||
public CidFontFactory(IPdfTokenScanner pdfScanner, FontDescriptorFactory descriptorFactory,
|
||||
CompactFontFormatParser compactFontFormatParser,
|
||||
IFilterProvider filterProvider)
|
||||
{
|
||||
this.pdfScanner = pdfScanner;
|
||||
this.descriptorFactory = descriptorFactory;
|
||||
this.trueTypeFontParser = trueTypeFontParser;
|
||||
this.compactFontFormatParser = compactFontFormatParser;
|
||||
this.filterProvider = filterProvider;
|
||||
}
|
||||
@@ -117,7 +115,8 @@
|
||||
{
|
||||
case DescriptorFontFile.FontFileType.TrueType:
|
||||
var input = new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile));
|
||||
return trueTypeFontParser.Parse(input);
|
||||
var ttf = TrueTypeFontParser.Parse(input);
|
||||
return new PdfCidTrueTypeFont(ttf);
|
||||
case DescriptorFontFile.FontFileType.FromSubtype:
|
||||
{
|
||||
if (!DirectObjectFinder.TryGet(descriptor.FontFile.ObjectKey, pdfScanner, out StreamToken str))
|
||||
|
@@ -6,10 +6,8 @@
|
||||
using Composite;
|
||||
using Core;
|
||||
using Encodings;
|
||||
using Geometry;
|
||||
using IO;
|
||||
using Fonts.TrueType;
|
||||
using Tokens;
|
||||
using TrueType;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
internal class TrueTypeSimpleFont : IFont
|
||||
@@ -26,7 +24,7 @@
|
||||
|
||||
[CanBeNull] private readonly Encoding encoding;
|
||||
|
||||
[CanBeNull] private readonly TrueTypeFontProgram fontProgram;
|
||||
[CanBeNull] private readonly TrueTypeFont font;
|
||||
|
||||
private readonly int firstCharacter;
|
||||
|
||||
@@ -43,13 +41,13 @@
|
||||
FontDescriptor descriptor,
|
||||
[CanBeNull] CMap toUnicodeCMap,
|
||||
[CanBeNull] Encoding encoding,
|
||||
[CanBeNull] TrueTypeFontProgram fontProgram,
|
||||
[CanBeNull] TrueTypeFont font,
|
||||
int firstCharacter,
|
||||
double[] widths)
|
||||
{
|
||||
this.descriptor = descriptor;
|
||||
this.encoding = encoding;
|
||||
this.fontProgram = fontProgram;
|
||||
this.font = font;
|
||||
this.firstCharacter = firstCharacter;
|
||||
this.widths = widths;
|
||||
|
||||
@@ -142,9 +140,9 @@
|
||||
fromFont = false;
|
||||
width = widths[index];
|
||||
}
|
||||
else if (fontProgram != null)
|
||||
else if (font != null)
|
||||
{
|
||||
if (!fontProgram.TryGetBoundingAdvancedWidth(characterCode, out width))
|
||||
if (!font.TryGetAdvanceWidth(characterCode, out width))
|
||||
{
|
||||
width = boundingBoxPreTransform;
|
||||
}
|
||||
@@ -156,11 +154,11 @@
|
||||
|
||||
if (fromFont)
|
||||
{
|
||||
width = fontMatrix.Transform(new PdfVector(width, 0)).X;
|
||||
width = fontMatrix.Transform(new PdfPoint(width, 0)).X;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = DefaultTransformation.Transform(new PdfVector(width, 0)).X;
|
||||
width = DefaultTransformation.Transform(new PdfPoint(width, 0)).X;
|
||||
}
|
||||
|
||||
var result = new CharacterBoundingBox(boundingBox, width);
|
||||
@@ -174,9 +172,9 @@
|
||||
{
|
||||
var scale = 1000.0;
|
||||
|
||||
if (fontProgram?.TableRegister.HeaderTable != null)
|
||||
if (font?.TableRegister.HeaderTable != null)
|
||||
{
|
||||
scale = fontProgram.GetFontMatrixMultiplier();
|
||||
scale = font.GetUnitsPerEm();
|
||||
}
|
||||
|
||||
return TransformationMatrix.FromValues(1 / scale, 0, 0, 1 / scale, 0, 0);
|
||||
@@ -186,17 +184,17 @@
|
||||
{
|
||||
fromFont = true;
|
||||
|
||||
if (fontProgram == null)
|
||||
if (font == null)
|
||||
{
|
||||
return descriptor.BoundingBox;
|
||||
}
|
||||
|
||||
if (fontProgram.TryGetBoundingBox(characterCode, CharacterCodeToGlyphId, out var bounds))
|
||||
if (font.TryGetBoundingBox(characterCode, CharacterCodeToGlyphId, out var bounds))
|
||||
{
|
||||
return bounds;
|
||||
}
|
||||
|
||||
if (fontProgram.TryGetBoundingAdvancedWidth(characterCode, out var width))
|
||||
if (font.TryGetAdvanceWidth(characterCode, out var width))
|
||||
{
|
||||
return new PdfRectangle(0, 0, width, 0);
|
||||
}
|
||||
@@ -214,7 +212,7 @@
|
||||
}
|
||||
|
||||
if (descriptor == null || !unicodeValuesCache.TryGetValue(characterCode, out var unicode)
|
||||
|| fontProgram.TableRegister.CMapTable == null
|
||||
|| font.TableRegister.CMapTable == null
|
||||
|| encoding == null
|
||||
|| !encoding.CodeToNameMap.TryGetValue(characterCode, out var name)
|
||||
|| name == null)
|
||||
@@ -229,63 +227,63 @@
|
||||
|
||||
var glyphId = 0;
|
||||
|
||||
if (HasFlag(descriptor.Flags, FontDescriptorFlags.Symbolic) && fontProgram.WindowsSymbolCMap != null)
|
||||
if (HasFlag(descriptor.Flags, FontDescriptorFlags.Symbolic) && font.WindowsSymbolCMap != null)
|
||||
{
|
||||
const int startRangeF000 = 0xF000;
|
||||
const int startRangeF100 = 0xF100;
|
||||
const int startRangeF200 = 0xF200;
|
||||
|
||||
// (3, 0) - (Windows, Symbol)
|
||||
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode);
|
||||
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode);
|
||||
|
||||
if (glyphId == 0 && characterCode >= 0 && characterCode <= 0xFF)
|
||||
{
|
||||
// CMap may use one of the following code ranges, so that we have to add the high byte to get the mapped value.
|
||||
|
||||
// F000 - F0FF
|
||||
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF000);
|
||||
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF000);
|
||||
|
||||
if (glyphId == 0)
|
||||
{
|
||||
// F100 - F1FF
|
||||
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF100);
|
||||
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF100);
|
||||
}
|
||||
|
||||
if (glyphId == 0)
|
||||
{
|
||||
// F200 - F2FF
|
||||
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF200);
|
||||
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF200);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle fonts incorrectly set to symbolic.
|
||||
if (glyphId == 0 && fontProgram.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
|
||||
if (glyphId == 0 && font.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
|
||||
{
|
||||
glyphId = fontProgram.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
|
||||
glyphId = font.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// (3, 1) - (Windows, Unicode)
|
||||
if (fontProgram.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
|
||||
if (font.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
|
||||
{
|
||||
glyphId = fontProgram.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
|
||||
glyphId = font.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
|
||||
}
|
||||
|
||||
if (glyphId == 0
|
||||
&& fontProgram.MacRomanCMap != null
|
||||
&& font.MacRomanCMap != null
|
||||
&& MacOsRomanEncoding.Instance.NameToCodeMap.TryGetValue(name, out var macCode))
|
||||
{
|
||||
// (1, 0) - (Macintosh, Roman)
|
||||
|
||||
glyphId = fontProgram.MacRomanCMap.CharacterCodeToGlyphIndex(macCode);
|
||||
glyphId = font.MacRomanCMap.CharacterCodeToGlyphIndex(macCode);
|
||||
}
|
||||
|
||||
if (glyphId == 0 && fontProgram.TableRegister.PostScriptTable != null)
|
||||
if (glyphId == 0 && font.TableRegister.PostScriptTable != null)
|
||||
{
|
||||
for (var i = 0; i < fontProgram.TableRegister.PostScriptTable.GlyphNames.Length; i++)
|
||||
for (var i = 0; i < font.TableRegister.PostScriptTable.GlyphNames.Count; i++)
|
||||
{
|
||||
var glyphName = fontProgram.TableRegister.PostScriptTable.GlyphNames[i];
|
||||
var glyphName = font.TableRegister.PostScriptTable.GlyphNames[i];
|
||||
|
||||
if (string.Equals(glyphName, name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
@@ -4,9 +4,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Encodings;
|
||||
using IO;
|
||||
using Fonts.AdobeFontMetrics;
|
||||
using Fonts.TrueType;
|
||||
using Tokens;
|
||||
using TrueType;
|
||||
|
||||
/// <summary>
|
||||
/// Some TrueType fonts use both the Standard 14 descriptor and the TrueType font from disk.
|
||||
@@ -16,16 +16,16 @@
|
||||
private static readonly TransformationMatrix DefaultTransformation =
|
||||
TransformationMatrix.FromValues(1 / 1000.0, 0, 0, 1 / 1000.0, 0, 0);
|
||||
|
||||
private readonly FontMetrics fontMetrics;
|
||||
private readonly AdobeFontMetrics fontMetrics;
|
||||
private readonly Encoding encoding;
|
||||
private readonly TrueTypeFontProgram font;
|
||||
private readonly TrueTypeFont font;
|
||||
private readonly MetricOverrides overrides;
|
||||
|
||||
public NameToken Name { get; }
|
||||
|
||||
public bool IsVertical { get; } = false;
|
||||
|
||||
public TrueTypeStandard14FallbackSimpleFont(NameToken name, FontMetrics fontMetrics, Encoding encoding, TrueTypeFontProgram font,
|
||||
public TrueTypeStandard14FallbackSimpleFont(NameToken name, AdobeFontMetrics fontMetrics, Encoding encoding, TrueTypeFont font,
|
||||
MetricOverrides overrides)
|
||||
{
|
||||
this.fontMetrics = fontMetrics;
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
if (overrides?.TryGetWidth(characterCode, out width) != true)
|
||||
{
|
||||
width = fontMatrix.TransformX(metrics.WidthX);
|
||||
width = fontMatrix.TransformX(metrics.Width.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,7 +106,7 @@
|
||||
{
|
||||
if (font?.TableRegister.HeaderTable != null)
|
||||
{
|
||||
var scale = (double)font.GetFontMatrixMultiplier();
|
||||
var scale = (double)font.GetUnitsPerEm();
|
||||
|
||||
return TransformationMatrix.FromValues(1 / scale, 0, 0, 1 / scale, 0, 0);
|
||||
}
|
||||
|
@@ -4,8 +4,7 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
|
||||
using System;
|
||||
using Core;
|
||||
using Encodings;
|
||||
using Geometry;
|
||||
using IO;
|
||||
using Fonts.AdobeFontMetrics;
|
||||
using Tokens;
|
||||
|
||||
/// <summary>
|
||||
@@ -13,7 +12,7 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
|
||||
/// </summary>
|
||||
internal class Type1Standard14Font: IFont
|
||||
{
|
||||
private readonly FontMetrics standardFontMetrics;
|
||||
private readonly AdobeFontMetrics standardFontMetrics;
|
||||
private readonly Encoding encoding;
|
||||
|
||||
public NameToken Name { get; }
|
||||
@@ -21,7 +20,7 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
|
||||
|
||||
private readonly TransformationMatrix fontMatrix = TransformationMatrix.FromValues(0.001, 0, 0, 0.001, 0, 0);
|
||||
|
||||
public Type1Standard14Font(FontMetrics standardFontMetrics, Encoding overrideEncoding = null)
|
||||
public Type1Standard14Font(AdobeFontMetrics standardFontMetrics, Encoding overrideEncoding = null)
|
||||
{
|
||||
this.standardFontMetrics = standardFontMetrics ?? throw new ArgumentNullException(nameof(standardFontMetrics));
|
||||
encoding = overrideEncoding ?? new AdobeFontMetricsEncoding(standardFontMetrics);
|
||||
@@ -65,18 +64,21 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
|
||||
{
|
||||
return new PdfRectangle(0, 0, 250, 0);
|
||||
}
|
||||
|
||||
var x = metrics.Width.X;
|
||||
var y = metrics.Width.Y;
|
||||
|
||||
if (metrics.WidthX == 0 && metrics.BoundingBox.Width > 0)
|
||||
if (metrics.Width.X == 0 && metrics.BoundingBox.Width > 0)
|
||||
{
|
||||
metrics.WidthX = metrics.BoundingBox.Width;
|
||||
x = metrics.BoundingBox.Width;
|
||||
}
|
||||
|
||||
if (metrics.WidthY == 0 && metrics.BoundingBox.Height > 0)
|
||||
if (metrics.Width.Y == 0 && metrics.BoundingBox.Height > 0)
|
||||
{
|
||||
metrics.WidthY = metrics.BoundingBox.Height;
|
||||
y = metrics.BoundingBox.Height;
|
||||
}
|
||||
|
||||
return new PdfRectangle(0, 0, metrics.WidthX, metrics.WidthY);
|
||||
return new PdfRectangle(0, 0, x, y);
|
||||
}
|
||||
|
||||
public TransformationMatrix GetFontMatrix()
|
||||
|
@@ -4,9 +4,7 @@
|
||||
using Composite;
|
||||
using Core;
|
||||
using Encodings;
|
||||
using Exceptions;
|
||||
using Geometry;
|
||||
using IO;
|
||||
using Fonts;
|
||||
using Tokens;
|
||||
|
||||
internal class Type3Font : IFont
|
||||
@@ -69,7 +67,7 @@
|
||||
|
||||
characterBoundingBox = fontMatrix.Transform(characterBoundingBox);
|
||||
|
||||
var width = fontMatrix.Transform(new PdfVector(widths[characterCode - firstChar], 0)).X;
|
||||
var width = fontMatrix.Transform(new PdfPoint(widths[characterCode - firstChar], 0)).X;
|
||||
|
||||
return new CharacterBoundingBox(characterBoundingBox, width);
|
||||
}
|
||||
|
@@ -5,11 +5,11 @@
|
||||
using Core;
|
||||
using Fonts.TrueType;
|
||||
|
||||
internal class TrueTypeFontProgram : ICidFontProgram
|
||||
internal class PdfCidTrueTypeFont : ICidFontProgram
|
||||
{
|
||||
private readonly TrueTypeFont font;
|
||||
|
||||
public TrueTypeFontProgram(TrueTypeFont font)
|
||||
public PdfCidTrueTypeFont(TrueTypeFont font)
|
||||
{
|
||||
this.font = font ?? throw new ArgumentNullException(nameof(font));
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.Arithmetic
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current point to (x, y) in absolute character space coordinates without performing a charstring moveto command.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal line-to command.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Relative move to for horizontal dimension only.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal vertical curve to command. Draws a Bézier curve when the first Bézier tangent is horizontal and the second Bézier tangent is vertical.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Relative line-to command. Creates a line moving a distance relative to the current point.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Relative move to command. starts a new subpath of the current path in the same manner as moveto.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Relative rcurveto. Whereas the arguments to the rcurveto operator in the PostScript language are all relative to the current
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical-line to command.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical move to. Moves relative to the current point.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical-horizontal curveto.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.StartFinishOutline
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// The name hsbw stands for horizontal sidebearing and width;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.StartFinishOutline
|
||||
{
|
||||
using Geometry;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Sets left sidebearing and the character width vector.
|
||||
|
@@ -2,10 +2,8 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CharStrings;
|
||||
using IO;
|
||||
using PdfPig.Parser.Parts;
|
||||
using Core;
|
||||
using Tokens;
|
||||
|
||||
internal class Type1EncryptedPortionParser
|
||||
|
@@ -3,7 +3,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Parser.Parts;
|
||||
using Tokenization.Scanner;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
@@ -30,13 +30,11 @@
|
||||
var filterProvider = new MemoryFilterProvider(new DecodeParameterResolver(logger), new PngPredictor(), logger);
|
||||
|
||||
var cmapParser = new CMapParser();
|
||||
var afmParser = new AdobeFontMetricsParser();
|
||||
|
||||
var container = new Container();
|
||||
container.Register(trailerParser);
|
||||
container.Register(filterProvider);
|
||||
container.Register(cmapParser);
|
||||
container.Register(afmParser);
|
||||
container.Register(logger);
|
||||
|
||||
return container;
|
||||
|
@@ -4,19 +4,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Core;
|
||||
using PdfFonts;
|
||||
using PdfFonts.Encodings;
|
||||
using PdfPig.Fonts.AdobeFontMetrics;
|
||||
using Tokens;
|
||||
|
||||
internal class Standard14WritingFont : IWritingFont
|
||||
{
|
||||
private readonly FontMetrics metrics;
|
||||
private readonly AdobeFontMetrics metrics;
|
||||
|
||||
public bool HasWidths { get; } = false;
|
||||
|
||||
public string Name => metrics.FontName;
|
||||
|
||||
public Standard14WritingFont(FontMetrics metrics)
|
||||
public Standard14WritingFont(AdobeFontMetrics metrics)
|
||||
{
|
||||
this.metrics = metrics;
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
|
||||
boundingBox = new PdfRectangle(characterMetric.BoundingBox.Left, characterMetric.BoundingBox.Bottom,
|
||||
characterMetric.BoundingBox.Left + characterMetric.WidthX, characterMetric.BoundingBox.Top);
|
||||
characterMetric.BoundingBox.Left + characterMetric.Width.X, characterMetric.BoundingBox.Top);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@
|
||||
using Tokens;
|
||||
using PdfPig.Fonts;
|
||||
using PdfPig.Fonts.TrueType;
|
||||
using PdfPig.Fonts.TrueType.Subsetting;
|
||||
using PdfPig.Fonts.TrueType.Tables;
|
||||
|
||||
internal class TrueTypeWritingFont : IWritingFont
|
||||
{
|
||||
@@ -69,7 +71,7 @@
|
||||
// TODO: get flags TrueTypeEmbedder.java
|
||||
{ NameToken.Flags, new NumericToken((int)FontDescriptorFlags.Symbolic) },
|
||||
{ NameToken.FontBbox, GetBoundingBox(bbox, scaling) },
|
||||
{ NameToken.ItalicAngle, new NumericToken(postscript.ItalicAngle) },
|
||||
{ NameToken.ItalicAngle, new NumericToken((decimal)postscript.ItalicAngle) },
|
||||
{ NameToken.Ascent, new NumericToken(Math.Round(hhead.Ascent * scaling, 2)) },
|
||||
{ NameToken.Descent, new NumericToken(Math.Round(hhead.Descent * scaling, 2)) },
|
||||
{ NameToken.CapHeight, new NumericToken(90) },
|
||||
|
@@ -9,7 +9,8 @@
|
||||
using Fonts;
|
||||
using PdfPig.Fonts.TrueType;
|
||||
using Graphics.Operations;
|
||||
using PdfFonts;
|
||||
using PdfPig.Fonts.Standard14Fonts;
|
||||
using PdfPig.Fonts.TrueType.Parser;
|
||||
using Tokens;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
@@ -18,8 +19,6 @@
|
||||
/// </summary>
|
||||
public class PdfDocumentBuilder
|
||||
{
|
||||
private static readonly TrueTypeFontParser Parser = new TrueTypeFontParser();
|
||||
|
||||
private readonly Dictionary<int, PdfPageBuilder> pages = new Dictionary<int, PdfPageBuilder>();
|
||||
private readonly Dictionary<Guid, FontStored> fonts = new Dictionary<Guid, FontStored>();
|
||||
|
||||
@@ -67,7 +66,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
var font = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
|
||||
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
|
||||
|
||||
if (font.TableRegister.CMapTable == null)
|
||||
{
|
||||
@@ -105,7 +104,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var font = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
|
||||
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
|
||||
var id = Guid.NewGuid();
|
||||
var i = fonts.Count;
|
||||
var added = new AddedFont(id, NameToken.Create($"F{i}"));
|
||||
|
@@ -4,15 +4,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content;
|
||||
using Exceptions;
|
||||
using Core;
|
||||
using Filters;
|
||||
using Geometry;
|
||||
using Graphics;
|
||||
using Graphics.Colors;
|
||||
using Graphics.Core;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using Util;
|
||||
|
||||
internal static class XObjectFactory
|
||||
{
|
||||
|
Reference in New Issue
Block a user