Exemplo n.º 1
0
    /// <summary>
    /// Gets the FontDescriptor identified by the specified FontSelector. Returns null if no
    /// such objects exists.
    /// </summary>
    public FontDescriptor FindDescriptor(FontSelector selector)
    {
      if (selector == null)
        return null;

      FontDescriptor descriptor = this.table[selector] as FontDescriptor;
      return descriptor;
    }
Exemplo n.º 2
0
    ///// <summary>
    ///// Gets the FontDescriptor identified by the specified FontSelector. If no such objects 
    ///// exists, a new FontDescriptor is created and added to the stock.
    ///// </summary>
    //public FontDescriptor CreateDescriptor(FontSelector selector)
    //{
    //  if (selector == null)
    //    throw new ArgumentNullException("selector");

    //  FontDescriptor descriptor = this.table[selector] as FontDescriptor;
    //  if (descriptor == null)
    //  {
    //    descriptor = new TrueTypeDescriptor(selector);
    //    this.table.Add(selector, descriptor);
    //  }
    //  return descriptor;
    //}

    /// <summary>
    /// Gets the FontDescriptor identified by the specified FontSelector. If no such objects 
    /// exists, a new FontDescriptor is created and added to the stock.
    /// </summary>
    public FontDescriptor CreateDescriptor(XFont font)
    {
      if (font == null)
        throw new ArgumentNullException("font");

      FontSelector selector = new FontSelector(font);
      FontDescriptor descriptor = this.table[selector] as FontDescriptor;
      if (descriptor == null)
      {
        lock (typeof(FontDescriptorStock))
        {
          // may be created by other thread meanwhile
          descriptor = this.table[selector] as FontDescriptor;
          if (descriptor == null)
          {
            descriptor = new TrueTypeDescriptor(font, font.privateFontCollection);
            this.table.Add(selector, descriptor);
          }
        }
      }
      return descriptor;
    }
Exemplo n.º 3
0
 public FontDescriptor CreateDescriptor(string idName, byte[] fontData)
 {
   FontSelector selector = new FontSelector(idName);
   FontDescriptor descriptor = this.table[selector] as FontDescriptor;
   if (descriptor == null)
   {
     lock (typeof(FontDescriptorStock))
     {
       // may be created by other thread meanwhile
       descriptor = this.table[selector] as FontDescriptor;
       if (descriptor == null)
       {
         descriptor = new TrueTypeDescriptor(idName, fontData);
         this.table.Add(selector, descriptor);
       }
     }
   }
   return descriptor;
 }
Exemplo n.º 4
0
    /// <summary>
    /// Gets the FontDescriptor identified by the specified FontSelector. If no such objects 
    /// exists, a new FontDescriptor is created and added to the stock.
    /// </summary>
    public FontDescriptor CreateDescriptor(XFontFamily family, XFontStyle style)
    {
      if (family == null)
        throw new ArgumentNullException("family");

      FontSelector selector = new FontSelector(family, style);
      FontDescriptor descriptor = this.table[selector] as FontDescriptor;
      if (descriptor == null)
      {
        lock (typeof(FontDescriptorStock))
        {
          // may be created by other thread meanwhile
          descriptor = this.table[selector] as FontDescriptor;
          if (descriptor == null)
          {
            XFont font = new XFont(family.Name, 10, style);
            descriptor = new TrueTypeDescriptor(font, font.privateFontCollection);
            if (this.table.ContainsKey(selector))
              GetType();
            else
              this.table.Add(selector, descriptor);
          }
        }
      }
      return descriptor;
    }
Exemplo n.º 5
0
    /// <summary>
    /// Gets a PdfFont from an XFont. If no PdfFont already exists, a new one is created.
    /// </summary>
    public PdfFont GetFont(XFont font)
    {
      string fontName = font.Name;

      PdfFontTable.FontSelector selector = font.selector;
      if (selector == null)
      {
        selector = new FontSelector(font);
        font.selector = selector;
      }
      PdfFont pdfFont = this.fonts[selector] as PdfFont;
      if (pdfFont == null)
      {
        if (font.Unicode)
          pdfFont = new PdfType0Font(this.owner, font);
        else
          pdfFont = new PdfTrueTypeFont(this.owner, font);
        //pdfFont.Document = this.document;
        Debug.Assert(pdfFont.Owner == this.owner);
        this.fonts[selector] = pdfFont;
        //if (this.owner.EarlyWrite)
        //{
        //  //pdfFont.Close(); delete 
        //  //pdfFont.AssignObjID(ref this.document.ObjectID); // BUG: just test code!!!!
        //  //pdfFont.WriteObject(null);
        //}
      }
      return pdfFont;

#if false
      goto TrueTypeFont;
      switch (font.Name)
      {
        case "Times":
        case "Times New Roman":
          std = 0;
          break;

        case "Helvetica":
          std = 1;
          break;

        case "Courier":
          std = 2;
          break;

        case "Symbol":
          std = 3;
          break;

        case "ZapfDingbats":
          std = 4;
          break;
      }
      if (std != -1)
      {
        int idx = (int)font.Style & 0x3;
        string name = pdfStandardFonts[std][idx];
        PdfFont pdfFont = GetFont(name);
        if (pdfFont == null)
        {
          pdfFont = new PdfFont();
          pdfFont.SubType = "/Type1";
          pdfFont.BaseFont = name;
          pdfFont.DefaultName = string.Format("F{0}", PdfFontTable.fontNumber++);
        }
        return pdfFont;
      }
      else
      {
      TrueTypeFont:
        // TrueType font
        PdfFont pdfFont = new PdfFont();
        pdfFont.SubType = "/TrueType";
        pdfFont.FirstChar = 0;
        pdfFont.LastChar = 255;
        pdfFont.BaseFont = font.Name;
        pdfFont.DefaultName = string.Format("F{0}", PdfFontTable.fontNumber++);
      } 
#endif
      // TrueType font
      //      PdfFont pdfFont = new PdfFont();
      //      pdfFont.descriptor = new PdfFontDescriptor((TrueTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(font));
      //      pdfFont.SubType = "/TrueType";
      //      pdfFont.FirstChar = 0;
      //      pdfFont.LastChar = 255;
      //      pdfFont.BaseFont = font.Name;
      //      pdfFont.BaseFont = pdfFont.BaseFont.Replace(" ", "");
      //      switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic))
      //      {
      //        case XFontStyle.Bold:
      //          pdfFont.BaseFont += ",Bold";
      //          break;
      //
      //        case XFontStyle.Italic:
      //          pdfFont.BaseFont += ",Italic";
      //          break;
      //        
      //        case XFontStyle.Bold | XFontStyle.Italic:
      //          pdfFont.BaseFont += ",BoldItalic";
      //          break;
      //      }
      //      pdfFont.descriptor.FontName = pdfFont.BaseFont;
      //      pdfFont.DefaultName = string.Format("F{0}", PdfFontTable.fontNumber++);
    }
Exemplo n.º 6
0
 /// <summary>
 /// Tries to gets a PdfFont from the font dictionary.
 /// Returns null if no such PdfFont exists.
 /// </summary>
 public PdfFont TryGetFont(string idName)
 {
   PdfFontTable.FontSelector selector = new FontSelector(idName);
   PdfFont pdfFont = this.fonts[selector] as PdfFont;
   return pdfFont;
 }
Exemplo n.º 7
0
    //string[][] pdfStandardFonts =
    //{
    //  new string[]{"Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic"},
    //  new string[]{"Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique"},
    //  new string[]{"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"},
    //  new string[]{"Symbol", "Symbol", "Symbol", "Symbol"},
    //  new string[]{"ZapfDingbats", "ZapfDingbats", "ZapfDingbats", "ZapfDingbats"},
    //};

#if true
    /// <summary>
    /// Gets a PdfFont from a font program. If no PdfFont already exists, a new one is created.
    /// </summary>
    public PdfFont GetFont(string idName, byte[] fontData)
    {
      PdfFontTable.FontSelector selector = new FontSelector(idName);
      PdfFont pdfFont = this.fonts[selector] as PdfFont;
      if (pdfFont == null)
      {
        //if (font.Unicode)
        pdfFont = new PdfType0Font(this.owner, idName, fontData);
        //else
        //  pdfFont = new PdfTrueTypeFont(this.owner, font);
        //pdfFont.Document = this.document;
        Debug.Assert(pdfFont.Owner == this.owner);
        this.fonts[selector] = pdfFont;
      }
      return pdfFont;
    }
    ///// <summary>
    ///// Gets the FontDescriptor identified by the specified FontSelector. If no such objects 
    ///// exists, a new FontDescriptor is created and added to the stock.
    ///// </summary>
    //public FontDescriptor CreateDescriptor(FontSelector selector)
    //{
    //  if (selector == null)
    //    throw new ArgumentNullException("selector");

    //  FontDescriptor descriptor = this.table[selector] as FontDescriptor;
    //  if (descriptor == null)
    //  {
    //    descriptor = new TrueTypeDescriptor(selector);
    //    this.table.Add(selector, descriptor);
    //  }
    //  return descriptor;
    //}

    /// <summary>
    /// Gets the FontDescriptor identified by the specified FontSelector. If no such objects 
    /// exists, a new FontDescriptor is created and added to the stock.
    /// </summary>
    public FontDescriptor CreateDescriptor(XFont font)
    {
      if (font == null)
        throw new ArgumentNullException("font");

      FontSelector selector = new FontSelector(font);
      FontDescriptor descriptor = this.table[selector] as FontDescriptor;
      if (descriptor == null)
      {
        descriptor = new TrueTypeDescriptor(font);
        this.table.Add(selector, descriptor);
      }
      return descriptor;
    }