Exemplo n.º 1
0
        /// <summary>
        /// Converts an DOM Font to an XFont.
        /// </summary>
        internal static XFont FontToXFont(Font font, XPrivateFontCollection pfc,
                                          PdfFontEncoding encoding)
        {
            XFont xFont = null;

#if GDI____  // done in PDFsharp
#if CACHE_FONTS
            string signature = BuildSignature(font, unicode, fontEmbedding);
            xFont = fontCache[signature] as XFont;
            if (xFont == null)
            {
                XPdfFontOptions options = null;
                options = new XPdfFontOptions(fontEmbedding, unicode);
                XFontStyle style = GetXStyle(font);
                xFont = new XFont(font.Name, font.Size, style, options);
                fontCache[signature] = xFont;
            }
#else
            XPdfFontOptions options = null;
            options = new XPdfFontOptions(encoding, fontEmbedding);
            XFontStyle style = GetXStyle(font);
            if (pfc != null && pfc.PrivateFontCollection != null)
            {
                // Is it a private font?
                try
                {
                    foreach (System.Drawing.FontFamily ff in pfc.PrivateFontCollection.Families)
                    {
                        if (String.Compare(ff.Name, font.Name, true) == 0)
                        {
                            xFont = new XFont(ff, font.Size, style, options, pfc);
                            break;
                        }
                    }
                }
                catch
                {
#if DEBUG
                    pfc.GetType();
#endif
                }
            }
#endif
#endif

#if WPF___
            XPdfFontOptions options = null;
            options = new XPdfFontOptions(encoding, fontEmbedding);
            XFontStyle style = GetXStyle(font);
            //if (pfc != null &&
            //  pfc.PrivateFontCollection != null)
            //{
            //  // Is it a private font?
            //  try
            //  {
            //    foreach (System.Drawing.FontFamily ff in pfc.PrivateFontCollection.Families)
            //    {
            //      if (String.Compare(ff.Name, font.Name, true) == 0)
            //      {
            //        xFont = new XFont(ff, font.Size, style, options, pfc);
            //        break;
            //      }
            //    }
            //  }
            //  catch
            //  {
            //  }
            //}
#endif

            // #PFC
            XPdfFontOptions options = null;
            options = new XPdfFontOptions(encoding);
            XFontStyle style = GetXStyle(font);

            if (xFont == null)
            {
                xFont = new XFont(font.Name, font.Size, style, options);
            }
#if DEBUG
            CreateFontCounter++;
#endif
            return(xFont);
        }