mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 20:07:57 +08:00
#8 tidy up truetype font internally. some more work on a potential document creation api
This commit is contained in:
@@ -4,15 +4,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Content;
|
||||
using Fonts.TrueType;
|
||||
using Fonts.TrueType.Parser;
|
||||
using Geometry;
|
||||
using IO;
|
||||
|
||||
internal class PdfDocumentBuilder
|
||||
{
|
||||
private static readonly TrueTypeFontParser Parser = new TrueTypeFontParser();
|
||||
|
||||
private readonly Dictionary<int, PdfPageBuilder> pages = new Dictionary<int, PdfPageBuilder>();
|
||||
private readonly Dictionary<Guid, TrueTypeFontProgram> fonts = new Dictionary<Guid, TrueTypeFontProgram>();
|
||||
|
||||
public IReadOnlyDictionary<int, PdfPageBuilder> Pages => pages;
|
||||
public IReadOnlyDictionary<Guid, TrueTypeFontProgram> Fonts => fonts;
|
||||
|
||||
public PdfPageBuilder AddPage(PageSize size, bool isPortrait)
|
||||
public AddedFont AddTrueTypeFont(IReadOnlyList<byte> fontFileBytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
var font = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
|
||||
var id = Guid.NewGuid();
|
||||
fonts[id] = font;
|
||||
|
||||
return new AddedFont(id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Writing only supports TrueType fonts, please provide a valid TrueType font.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public PdfPageBuilder AddPage(PageSize size, bool isPortrait = true)
|
||||
{
|
||||
if (!size.TryGetPdfRectangle(out var rectangle))
|
||||
{
|
||||
@@ -54,5 +77,16 @@
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class AddedFont
|
||||
{
|
||||
public Guid Id { get; }
|
||||
|
||||
internal AddedFont(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user