#8 tidy up truetype font internally. some more work on a potential document creation api

This commit is contained in:
Eliot Jones
2018-11-25 13:56:27 +00:00
parent 9f783ddef0
commit d5a50f2236
17 changed files with 278 additions and 76 deletions

View File

@@ -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;
}
}
}
}