예제 #1
0
        /**
         * <summary>Loads the font data.</summary>
         */
        private void Load(OpenFontParser parser)
        {
            glyphIndexes  = parser.GlyphIndexes;
            glyphKernings = parser.GlyphKernings;
            glyphWidths   = parser.GlyphWidths;

            PdfDictionary baseDataObject = BaseDataObject;

            // BaseFont.
            baseDataObject[PdfName.BaseFont] = new PdfName(parser.FontName);

            // Subtype.
            baseDataObject[PdfName.Subtype] = PdfName.Type0;

            // Encoding.
            baseDataObject[PdfName.Encoding] = PdfName.IdentityH; //TODO: this is a simplification (to refine later).

            // Descendant font.
            PdfDictionary cidFontDictionary = new PdfDictionary(
                new PdfName[] { PdfName.Type },
                new PdfDirectObject[] { PdfName.Font }
                ); // CIDFont dictionary [PDF:1.6:5.6.3].

            {
                // Subtype.
                // FIXME: verify proper Type 0 detection.
                cidFontDictionary[PdfName.Subtype] = PdfName.CIDFontType2;

                // BaseFont.
                cidFontDictionary[PdfName.BaseFont] = new PdfName(parser.FontName);

                // CIDSystemInfo.
                cidFontDictionary[PdfName.CIDSystemInfo] = new PdfDictionary(
                    new PdfName[]
                {
                    PdfName.Registry,
                    PdfName.Ordering,
                    PdfName.Supplement
                },
                    new PdfDirectObject[]
                {
                    new PdfTextString("Adobe"),
                    new PdfTextString("Identity"),
                    PdfInteger.Get(0)
                }
                    ); // Generic predefined CMap (Identity-H/V (Adobe-Identity-0)) [PDF:1.6:5.6.4].

                // FontDescriptor.
                cidFontDictionary[PdfName.FontDescriptor] = Load_CreateFontDescriptor(parser);

                // Encoding.
                Load_CreateEncoding(baseDataObject, cidFontDictionary);
            }
            baseDataObject[PdfName.DescendantFonts] = new PdfArray(new PdfDirectObject[] { File.Register(cidFontDictionary) });

            Load();
        }
예제 #2
0
 /**
  * <summary>Creates the representation of a font.</summary>
  */
 public static Font Get(Document context, IInputStream fontData)
 {
     if (OpenFontParser.IsOpenFont(fontData))
     {
         return(CompositeFont.Get(context, fontData));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
예제 #3
0
        new public static CompositeFont Get(Document context, bytes::IInputStream fontData)
        {
            OpenFontParser parser = new OpenFontParser(fontData);

            switch (parser.OutlineFormat)
            {
            case OpenFontParser.OutlineFormatEnum.PostScript:
                return(new Type0Font(context, parser));

            case OpenFontParser.OutlineFormatEnum.TrueType:
                return(new Type2Font(context, parser));
            }
            throw new NotSupportedException("Unknown composite font format.");
        }
예제 #4
0
 internal Type2Font(Document context, OpenFontParser parser) : base(context, parser)
 {
 }
예제 #5
0
 internal CompositeFont(Document context, OpenFontParser parser)
     : base(context)
 {
     Load(parser);
 }
예제 #6
0
        /**
         * <summary>Creates the font descriptor.</summary>
         */
        private PdfReference Load_CreateFontDescriptor(OpenFontParser parser)
        {
            PdfDictionary fontDescriptor = new PdfDictionary();

            {
                OpenFontParser.FontMetrics metrics = parser.Metrics;

                // Type.
                fontDescriptor[PdfName.Type] = PdfName.FontDescriptor;

                // FontName.
                fontDescriptor[PdfName.FontName] = BaseDataObject[PdfName.BaseFont];

                // Flags [PDF:1.6:5.7.1].
                FlagsEnum flags = 0;
                if (metrics.IsFixedPitch)
                {
                    flags |= FlagsEnum.FixedPitch;
                }
                if (metrics.IsCustomEncoding)
                {
                    flags |= FlagsEnum.Symbolic;
                }
                else
                {
                    flags |= FlagsEnum.Nonsymbolic;
                }
                fontDescriptor[PdfName.Flags] = PdfInteger.Get(Convert.ToInt32(flags));

                // FontBBox.
                fontDescriptor[PdfName.FontBBox] = new Rectangle(
                    new SKPoint(metrics.XMin * metrics.UnitNorm, metrics.YMin * metrics.UnitNorm),
                    new SKPoint(metrics.XMax * metrics.UnitNorm, metrics.YMax * metrics.UnitNorm)
                    ).BaseDataObject;

                // ItalicAngle.
                fontDescriptor[PdfName.ItalicAngle] = PdfReal.Get(metrics.ItalicAngle);

                // Ascent.
                fontDescriptor[PdfName.Ascent] = PdfReal.Get(
                    metrics.STypoAscender == 0
                    ? metrics.Ascender * metrics.UnitNorm
                    : (metrics.STypoLineGap == 0 ? metrics.SCapHeight : metrics.STypoAscender) * metrics.UnitNorm
                    );

                // Descent.
                fontDescriptor[PdfName.Descent] = PdfReal.Get(
                    metrics.STypoDescender == 0
                    ? metrics.Descender * metrics.UnitNorm
                    : metrics.STypoDescender * metrics.UnitNorm
                    );

                // CapHeight.
                fontDescriptor[PdfName.CapHeight] = PdfReal.Get(metrics.SCapHeight * metrics.UnitNorm);

                // StemV.

                /*
                 * NOTE: '100' is just a rule-of-thumb value, 'cause I've still to solve the
                 * 'cvt' table puzzle (such a harsh headache!) for TrueType fonts...
                 * TODO:IMPL TrueType and CFF stemv real value to extract!!!
                 */
                fontDescriptor[PdfName.StemV] = PdfInteger.Get(100);

                // FontFile.
                fontDescriptor[PdfName.FontFile2] = File.Register(new PdfStream(new bytes::Buffer(parser.FontData.ToByteArray())));
            }
            return(File.Register(fontDescriptor));
        }