Exemple #1
0
        /// <summary>
        /// Prepares the object to get saved.
        /// </summary>
        internal override void PrepareForSave()
        {
            base.PrepareForSave();

#if DEBUG_
            if (FontDescriptor._descriptor.FontFace.loca == null)
            {
                GetType();
            }
#endif
            // CID fonts must be always embedded. PDFsharp embeds automatically a subset.
            OpenTypeFontface subSet = null;
            if (FontDescriptor._descriptor.FontFace.loca == null)
            {
                subSet = FontDescriptor._descriptor.FontFace;
            }
            else
            {
                subSet = FontDescriptor._descriptor.FontFace.CreateFontSubSet(_cmapInfo.GlyphIndices, true);
            }
            byte[]        fontData   = subSet.FontSource.Bytes;
            PdfDictionary fontStream = new PdfDictionary(Owner);
            Owner.Internals.AddObject(fontStream);
            FontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;

            fontStream.Elements["/Length1"] = new PdfInteger(fontData.Length);
            if (!Owner.Options.NoCompression)
            {
                fontData = Filtering.FlateDecode.Encode(fontData, _document.Options.FlateEncodeMode);
                fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
            }
            fontStream.Elements["/Length"] = new PdfInteger(fontData.Length);
            fontStream.CreateStream(fontData);
        }
Exemple #2
0
        /// <summary>
        /// Prepares the object to get saved.
        /// </summary>
        internal override void PrepareForSave()
        {
            base.PrepareForSave();

            // Fonts are always embedded.
            OpenTypeFontface subSet = FontDescriptor._descriptor.FontFace.CreateFontSubSet(_cmapInfo.GlyphIndices, false);

            byte[] fontData = subSet.FontSource.Bytes;

            PdfDictionary fontStream = new PdfDictionary(Owner);

            Owner.Internals.AddObject(fontStream);
            FontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;

            fontStream.Elements["/Length1"] = new PdfInteger(fontData.Length);
            if (!Owner.Options.NoCompression)
            {
                fontData = Filtering.FlateDecode.Encode(fontData, _document.Options.FlateEncodeMode);
                fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
            }
            fontStream.Elements["/Length"] = new PdfInteger(fontData.Length);
            fontStream.CreateStream(fontData);

            FirstChar = 0;
            LastChar  = 255;
            PdfArray width = Widths;

            //width.Elements.Clear();
            for (int idx = 0; idx < 256; idx++)
            {
                width.Elements.Add(new PdfInteger(FontDescriptor._descriptor.Widths[idx]));
            }
        }
        const string KeyPrefix = "tk:";  // "typeface key"

        XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations)
        {
            _key        = key;
            _fontFamily = fontFamily;
            _fontSource = fontSource;

            _fontface = OpenTypeFontface.CetOrCreateFrom(fontSource);
            Debug.Assert(ReferenceEquals(_fontSource.Fontface, _fontface));

            _styleSimulations = styleSimulations;
            Initialize();
        }
Exemple #4
0
        /// <summary>
        /// Caches a font source under its face name and its key.
        /// </summary>
        public static XFontSource CacheFontSource(XFontSource fontSource)
        {
            try
            {
                Lock.EnterFontFactory();
                // Check whether an identical font source with a different face name already exists.
                XFontSource existingFontSource;
                if (FontSourcesByKey.TryGetValue(fontSource.Key, out existingFontSource))
                {
#if DEBUG
                    // Fonts have same length and check sum. Now check byte by byte identity.
                    int length = fontSource.Bytes.Length;
                    for (int idx = 0; idx < length; idx++)
                    {
                        if (existingFontSource.Bytes[idx] != fontSource.Bytes[idx])
                        {
                            //Debug.Assert(false,"Two fonts with identical checksum found.");
                            break;
                            //goto FontsAreNotIdentical;
                        }
                    }
                    Debug.Assert(existingFontSource.Fontface != null);
#endif
                    return(existingFontSource);

                    //FontsAreNotIdentical:
                    //// Incredible rare case: Two different fonts have the same size and check sum.
                    //// Give the new one a new key until it do not clash with an existing one.
                    //while (FontSourcesByKey.ContainsKey(fontSource.Key))
                    //    fontSource.IncrementKey();
                }

                OpenTypeFontface fontface = fontSource.Fontface;
                if (fontface == null)
                {
                    // Create OpenType fontface for this font source.
                    fontSource.Fontface = new OpenTypeFontface(fontSource);
                }
                FontSourcesByKey.Add(fontSource.Key, fontSource);
                if (FontSourcesByName.ContainsKey(fontSource.FontName))
                {
                    // TODO: merge font faces?..
                }
                else
                {
                    FontSourcesByName.Add(fontSource.FontName, fontSource);
                }

                return(fontSource);
            }
            finally { Lock.ExitFontFactory(); }
        }
Exemple #5
0
        const string KeyPrefix = "tk:";  // "typeface key"

#if CORE || GDI
        XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations, GdiFont gdiFont)
        {
            Key        = key;
            FontFamily = fontFamily;
            FontSource = fontSource;

            Fontface = OpenTypeFontface.CetOrCreateFrom(fontSource);
            Debug.Assert(ReferenceEquals(FontSource.Fontface, Fontface));

            GdiFont = gdiFont;

            StyleSimulations = styleSimulations;
            Initialize();
        }
        /// <summary>
        /// Caches a font source under its face name and its key.
        /// </summary>
        public static XFontSource CacheNewFontSource(string typefaceKey, XFontSource fontSource)
        {
            // Debug.Assert(!FontSourcesByFaceName.ContainsKey(fontSource.FaceName));

            // Check whether an identical font source with a different face name already exists.
            XFontSource existingFontSource;

            if (FontSourcesByKey.TryGetValue(fontSource.Key, out existingFontSource))
            {
                //// Fonts have same length and check sum. Now check byte by byte identity.
                //int length = fontSource.Bytes.Length;
                //for (int idx = 0; idx < length; idx++)
                //{
                //    if (existingFontSource.Bytes[idx] != fontSource.Bytes[idx])
                //    {
                //        goto FontsAreNotIdentical;
                //    }
                //}
                return(existingFontSource);

                ////// The bytes are really identical. Register font source again with the new face name
                ////// but return the existing one to save memory.
                ////FontSourcesByFaceName.Add(fontSource.FaceName, existingFontSource);
                ////return existingFontSource;

                //FontsAreNotIdentical:
                //// Incredible rare case: Two different fonts have the same size and check sum.
                //// Give the new one a new key until it do not clash with an existing one.
                //while (FontSourcesByKey.ContainsKey(fontSource.Key))
                //    fontSource.IncrementKey();
            }

            OpenTypeFontface fontface = fontSource.Fontface;

            if (fontface == null)
            {
                fontface            = new OpenTypeFontface(fontSource);
                fontSource.Fontface = fontface;  // Also sets the font name in fontSource
            }

            FontSourcesByName.Add(typefaceKey, fontSource);
            FontSourcesByName.Add(fontSource.FontName, fontSource);
            FontSourcesByKey.Add(fontSource.Key, fontSource);

            return(fontSource);
        }
Exemple #7
0
        const string KeyPrefix = "tk:";  // "typeface key"

#if CORE || GDI
        XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations
#if !WITHOUT_DRAWING
                       , GdiFont gdiFont
#endif
                       )
        {
            _key        = key;
            _fontFamily = fontFamily;
            _fontSource = fontSource;

            _fontface = OpenTypeFontface.CetOrCreateFrom(fontSource);
            Debug.Assert(ReferenceEquals(_fontSource.Fontface, _fontface));

#if !WITHOUT_DRAWING
            _gdiFont = gdiFont;
#endif

            _styleSimulations = styleSimulations;
            Initialize();
        }
Exemple #8
0
 public GenericFontTable(OpenTypeFontface fontData, string tag)
     : base(fontData, tag)
 {
     _fontData = fontData;
 }
Exemple #9
0
 public GenericFontTable(OpenTypeFontface fontData, string tag)
   : base(fontData, tag)
 {
     _fontData = fontData;
 }