PdfSharp.Xps.Rendering.PdfContentWriter.GetFontName C# (CSharp) Méthode

GetFontName() private méthode

Gets the resource name of the specified font within this page or form.
private GetFontName ( PdfSharp.Xps.XpsModel.Font font ) : string
font PdfSharp.Xps.XpsModel.Font
Résultat string
    internal string GetFontName(Font font)
    {
      PdfFont pdfFont;
      string name = null;
      if (this.page != null)
        name = this.page.GetFontName(font.Name, font.FontData, out pdfFont);
      else if (this.form != null)
        name = this.form.GetFontName(font.Name, font.FontData, out pdfFont);
      else if (this.contentDictionary != null)
      {
        Debug.Assert(this.contentStreamDictionary != null);
        name = this.contentStreamDictionary.GetFontName(font.Name, font.FontData, out pdfFont);
      }
      else
      {
        Debug.Assert(false, "Undefined conent target.");
        pdfFont = null;  // supress compiler warning
      }

      Debug.Assert(font.PdfFont == null || Object.ReferenceEquals(font.PdfFont, pdfFont));
      if (font.PdfFont == null)
        font.PdfFont = pdfFont;
      return name;
    }

Same methods

PdfContentWriter::GetFontName ( PdfSharp.Drawing.XFont font, PdfSharp.Pdf.Advanced.PdfFont &pdfFont ) : string
PdfContentWriter::GetFontName ( string idName, byte fontData, PdfSharp.Pdf.Advanced.PdfFont &pdfFont ) : string

Usage Example

        public void RealizeFont(Glyphs glyphs)
        {
            var absURI = glyphs.FontUri;

            if (!glyphs.FontUri.IsAbsoluteUri)
            {
                var uriCtx = glyphs as System.Windows.Markup.IUriContext;

                var host = uriCtx.BaseUri.Host;
                absURI = new Uri("pack://" + host + glyphs.FontUri.OriginalString, UriKind.Absolute);
            }

            var nameInPdf = "";
            KeyValuePair <string, PdfFont> exist;

            if (_fonts.TryGetValue(absURI.OriginalString, out exist))
            {
                this.realizedFont = exist.Value;
                nameInPdf         = exist.Key;
            }
            else
            {
                GlyphTypeface typeFace =
                    new GlyphTypeface(absURI);

                string name = String.Format("XPS-Font-{0:00}", ++fontCount);
                name = PdfFont.CreateEmbeddedFontSubsetName(name);

                var fontStream = typeFace.GetFontStream();
                var memStream  = new System.IO.MemoryStream();
                var buff       = new byte[512];
                int len        = 0;
                while ((len = fontStream.Read(buff, 0, buff.Length)) > 0)
                {
                    memStream.Write(buff, 0, len);
                }
                var  fontData = memStream.ToArray();
                Font font     = new Font(name, fontData);

                nameInPdf = writer.GetFontName(font);
                _fonts.Add(absURI.OriginalString, new KeyValuePair <string, PdfFont>(
                               nameInPdf, font.PdfFont));
                this.realizedFont = font.PdfFont;
            }
            //if (fontName != this.realizedFontName || this.realizedFontSize != font.Size)
            {
                //this.writer.WriteLiteral("{0} {1:0.###} Tf\n", fontName, -glyphs.FontRenderingEmSize);
                this.writer.WriteLiteral("{0} {1:0.###} Tf\n", nameInPdf, -glyphs.FontRenderingEmSize);

                //this.realizedFontName = fontName;
                //this.realizedFontSize = font.Size;
            }
        }
All Usage Examples Of PdfSharp.Xps.Rendering.PdfContentWriter::GetFontName