Beispiel #1
0
        /// <summary>
        /// Adds one of the Standard 14 fonts which are included by default in PDF programs so that pages in this document can use it. These Standard 14 fonts are old and possibly obsolete.
        /// </summary>
        /// <param name="type">The type of the Standard 14 font to use.</param>
        /// <returns>An identifier which can be passed to <see cref="PdfPageBuilder.AddText"/>.</returns>
        public AddedFont AddStandard14Font(Standard14Font type)
        {
            var id    = Guid.NewGuid();
            var name  = NameToken.Create($"F{fonts.Count}");
            var added = new AddedFont(id, name);

            fonts[id] = new FontStored(added, new Standard14WritingFont(Standard14.GetAdobeFontMetrics(type)));

            return(added);
        }
Beispiel #2
0
        /// <summary>
        /// Adds one of the Standard 14 fonts which are included by default in PDF programs so that pages in this document can use it. These Standard 14 fonts are old and possibly obsolete.
        /// </summary>
        /// <param name="type">The type of the Standard 14 font to use.</param>
        /// <returns>An identifier which can be passed to <see cref="PdfPageBuilder.AddText"/>.</returns>
        public AddedFont AddStandard14Font(Standard14Font type)
        {
            if (ArchiveStandard != PdfAStandard.None)
            {
                throw new NotSupportedException($"PDF/A {ArchiveStandard} requires the font to be embedded in the file, only {nameof(AddTrueTypeFont)} is supported.");
            }

            var id    = Guid.NewGuid();
            var name  = NameToken.Create($"F{fontId++}");
            var added = new AddedFont(id, context.ReserveObjectNumber());

            fonts[id] = new FontStored(added, new Standard14WritingFont(Standard14.GetAdobeFontMetrics(type)));
            return(added);
        }
Beispiel #3
0
 /// <summary>
 /// Adds a TrueType font to the builder so that pages in this document can use it.
 /// </summary>
 /// <param name="fontFileBytes">The bytes of a TrueType font.</param>
 /// <returns>An identifier which can be passed to <see cref="PdfPageBuilder.AddText"/>.</returns>
 public AddedFont AddTrueTypeFont(IReadOnlyList <byte> fontFileBytes)
 {
     try
     {
         var font  = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
         var id    = Guid.NewGuid();
         var added = new AddedFont(id, context.ReserveObjectNumber());
         fonts[id] = new FontStored(added, new TrueTypeWritingFont(font, fontFileBytes));
         return(added);
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException("Writing only supports TrueType fonts, please provide a valid TrueType font.", ex);
     }
 }
Beispiel #4
0
        public AddedFont AddTrueTypeFont(IReadOnlyList <byte> fontFileBytes)
        {
            try
            {
                var font  = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
                var id    = Guid.NewGuid();
                var i     = fonts.Count;
                var added = new AddedFont(id, NameToken.Create($"F{i}"));
                fonts[id] = new FontStored(added, font);

                return(added);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Writing only supports TrueType fonts, please provide a valid TrueType font.", ex);
            }
        }
Beispiel #5
0
 public FontStored(AddedFont fontKey, IWritingFont fontProgram)
 {
     FontKey     = fontKey ?? throw new ArgumentNullException(nameof(fontKey));
     FontProgram = fontProgram ?? throw new ArgumentNullException(nameof(fontProgram));
 }
Beispiel #6
0
 public FontStored(AddedFont fontKey, TrueTypeFontProgram fontProgram)
 {
     FontKey     = fontKey;
     FontProgram = fontProgram;
 }