/// <summary> /// Adds the specified font to this resource dictionary and returns its local resource name. /// </summary> public string AddFont(PdfFont font) { string name = (string)this.resources[font]; if (name == null) { name = NextFontName; this.resources[font] = name; if (font.Reference == null) this.Owner.irefTable.Add(font); Fonts.Elements[name] = font.Reference; } return name; }
/// <summary> /// Adds the specified font to this resource dictionary and returns its local resource name. /// </summary> public string AddFont(PdfFont font) { string name; if (!this.resources.TryGetValue(font, out name)) { name = NextFontName; this.resources[font] = name; if (font.Reference == null) Owner.irefTable.Add(font); Fonts.Elements[name] = font.Reference; } return name; }
/// <summary> /// Gets the resource name of the specified font data within this form. /// </summary> internal string GetFontName(string idName, byte[] fontData, out PdfFont pdfFont) { Debug.Assert(IsTemplate, "This function is for form templates only."); pdfFont = this.document.FontTable.GetFont(idName, fontData); //pdfFont = new PdfType0Font(Owner, idName, fontData); //pdfFont.Document = this.document; Debug.Assert(pdfFont != null); string name = Resources.AddFont(pdfFont); return name; }
/// <summary> /// Tries to get the resource name of the specified font data within this form. /// Returns null if no such font exists. /// </summary> internal string TryGetFontName(string idName, out PdfFont pdfFont) { Debug.Assert(IsTemplate, "This function is for form templates only."); pdfFont = this.document.FontTable.TryGetFont(idName); string name = null; if (pdfFont != null) name = Resources.AddFont(pdfFont); return name; }
/// <summary> /// Gets the resource name of the specified font within this form. /// </summary> internal string GetFontName(XFont font, out PdfFont pdfFont) { Debug.Assert(IsTemplate, "This function is for form templates only."); pdfFont = this.document.FontTable.GetFont(font); Debug.Assert(pdfFont != null); string name = Resources.AddFont(pdfFont); return name; }
// string realizedFontName = String.Empty; // double realizedFontSize = 0; public void RealizeFont(Glyphs glyphs) { // So far rendering mode 0 only //RealizeBrush(brush, this.renderer.colorMode); // this.renderer.page.document.Options.ColorMode); try { // Get fixed payload which contains the font manager FixedPage fpage = glyphs.GetParent<FixedPage>(); if (fpage == null) { GetType(); this.realizedFont = new PdfFont(null); } FixedPayload payload = fpage.Document.Payload; // Get the font object. // Important: font.PdfFont is not yet defined here on the first call string uriString = glyphs.FontUri; Font font = payload.GetFont(uriString); // Get the page local resource name and define font.PdfFont if it is not yet defined string fontName = writer.GetFontName(font); 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", fontName, -glyphs.FontRenderingEmSize); //this.realizedFontName = fontName; //this.realizedFontSize = font.Size; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Gets the resource name of the specified font data within this page. /// </summary> internal string GetFontName(string idName, byte[] fontData, out PdfFont pdfFont) { pdfFont = _document.FontTable.GetFont(idName, fontData); //pdfFont = new PdfType0Font(Owner, idName, fontData); //pdfFont.Document = _document; Debug.Assert(pdfFont != null); string name = Resources.AddFont(pdfFont); return name; }
string IContentStream.GetFontName(XFont font, out PdfFont pdfFont) { return GetFontName(font, out pdfFont); }
/// <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; if (!this.fonts.TryGetValue(selector, out pdfFont)) { if (font.Unicode) pdfFont = new PdfType0Font(this.owner, font, font.IsVertical); 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++); }
string IContentStream.GetFontName(string idName, byte[] fontData, out PdfFont pdfFont) { return(GetFontName(idName, fontData, out pdfFont)); }
/// <summary> /// Gets the resource name of the specified font within this page or form. /// </summary> internal string GetFontName(XFont font, out PdfFont pdfFont) { if (_page != null) return _page.GetFontName(font, out pdfFont); return _form.GetFontName(font, out pdfFont); }
string IContentStream.GetFontName(XFont font, out PdfFont pdfFont) { return(GetFontName(font, out pdfFont)); }
/// <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; if (!this.fonts.TryGetValue(selector, out pdfFont)) { if (font.Unicode) { pdfFont = new PdfType0Font(this.owner, font, font.IsVertical); } 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++); }
double _realizedCharSpace; // Reference: TABLE 5.2 Text state operators / Page 398 public void RealizeFont(XFont font, XBrush brush, int renderingMode) { const string format = Config.SignificantFigures3; // So far rendering mode 0 (fill text) and 2 (fill, then stroke text) only. RealizeBrush(brush, _renderer._colorMode, renderingMode, font.Size); // _renderer.page.document.Options.ColorMode); // Realize rendering mode. if (_realizedRenderingMode != renderingMode) { _renderer.AppendFormatInt("{0} Tr\n", renderingMode); _realizedRenderingMode = renderingMode; } // Realize character spacing. if (_realizedRenderingMode == 0) { if (_realizedCharSpace != 0) { _renderer.Append("0 Tc\n"); _realizedCharSpace = 0; } } else // _realizedRenderingMode is 2. { double charSpace = font.Size * Const.BoldEmphasis; if (_realizedCharSpace != charSpace) { _renderer.AppendFormatDouble("{0:" + format + "} Tc\n", charSpace); _realizedCharSpace = charSpace; } } _realizedFont = null; string fontName = _renderer.GetFontName(font, out _realizedFont); if (fontName != _realizedFontName || _realizedFontSize != font.Size) { if (_renderer.Gfx.PageDirection == XPageDirection.Downwards) _renderer.AppendFormatFont("{0} {1:" + format + "} Tf\n", fontName, font.Size); else _renderer.AppendFormatFont("{0} {1:" + format + "} Tf\n", fontName, font.Size); _realizedFontName = fontName; _realizedFontSize = font.Size; } }
public void RealizeFont(XFont font, XBrush brush, int renderMode) { // So far rendering mode 0 only RealizeBrush(brush, this.renderer.colorMode); // this.renderer.page.document.Options.ColorMode); this.realizedFont = null; string fontName = this.renderer.GetFontName(font, out this.realizedFont); if (fontName != this.realizedFontName || this.realizedFontSize != font.Size) { if (this.renderer.Gfx.PageDirection == XPageDirection.Downwards) this.renderer.AppendFormat("{0} {1:0.###} Tf\n", fontName, -font.Size); else this.renderer.AppendFormat("{0} {1:0.###} Tf\n", fontName, font.Size); this.realizedFontName = fontName; this.realizedFontSize = font.Size; } }
/// <summary> /// Gets the resource name of the specified font within this page or form. /// </summary> internal string GetFontName(XFont font, out PdfFont pdfFont) { if (this.page != null) return this.page.GetFontName(font, out pdfFont); else return this.form.GetFontName(font, out pdfFont); }
/// <summary> /// Gets the resource name of the specified font within this page. /// </summary> internal string GetFontName(XFont font, out PdfFont pdfFont) { pdfFont = _document.FontTable.GetFont(font); Debug.Assert(pdfFont != null); string name = Resources.AddFont(pdfFont); return name; }
/// <summary> /// Gets the resource name of the specified font data within this form XObject. /// </summary> internal string GetFontName(string idName, byte[] fontData, out PdfFont pdfFont) { pdfFont = this.document.FontTable.GetFont(idName, fontData); Debug.Assert(pdfFont != null); string name = Resources.AddFont(pdfFont); return name; }
/// <summary> /// Tries to get the resource name of the specified font data within this page. /// Returns null if no such font exists. /// </summary> internal string TryGetFontName(string idName, out PdfFont pdfFont) { pdfFont = _document.FontTable.TryGetFont(idName); string name = null; if (pdfFont != null) name = Resources.AddFont(pdfFont); return name; }
/// <summary> /// Gets the resource name of the specified font within this page or form. /// </summary> internal string GetFontName(string idName, byte[] fontData, out PdfFont pdfFont) { if (this.page != null) return this.page.GetFontName(idName, fontData, out pdfFont); else if (this.form != null) return this.form.GetFontName(idName, fontData, out pdfFont); else if (this.contentDictionary != null) { throw new NotImplementedException("GetFontName"); } Debug.Assert(false, "Undefined conent target."); pdfFont = null; return null; }
string IContentStream.GetFontName(string idName, byte[] fontData, out PdfFont pdfFont) { return GetFontName(idName, fontData, out pdfFont); }
/// <summary> /// Initializes a new instance of PdfTrueTypeFont from an XFont. /// </summary> public PdfTrueTypeFont(PdfDocument document, XFont font) : base(document) { Elements.SetName(Keys.Type, "/Font"); Elements.SetName(Keys.Subtype, "/TrueType"); // TrueType with WinAnsiEncoding only OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(font); this.fontDescriptor = new PdfFontDescriptor(document, ttDescriptor); this.fontOptions = font.PdfOptions; Debug.Assert(this.fontOptions != null); //this.cmapInfo = new CMapInfo(null/*ttDescriptor*/); this.cmapInfo = new CMapInfo(ttDescriptor); BaseFont = font.Name.Replace(" ", ""); switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic)) { case XFontStyle.Bold: BaseFont += ",Bold"; break; case XFontStyle.Italic: BaseFont += ",Italic"; break; case XFontStyle.Bold | XFontStyle.Italic: BaseFont += ",BoldItalic"; break; } if (this.fontOptions.FontEmbedding == PdfFontEmbedding.Always) { BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont); } this.fontDescriptor.FontName = BaseFont; Debug.Assert(this.fontOptions.FontEncoding == PdfFontEncoding.WinAnsi); if (!IsSymbolFont) { Encoding = "/WinAnsiEncoding"; } // { //#if true // throw new NotImplementedException("Specifying a font file is not yet supported."); //#else // // Testcode // FileStream stream = new FileStream("WAL____I.AFM", FileAccess.Read); // int length = stream.Length; // byte[] fontProgram = new byte[length]; // PdfDictionary fontStream = new PdfDictionary(this.Document); // this.Document.xrefTable.Add(fontStream); // this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile] = fontStream.XRef; // fontStream.Elements["/Length1"] = new PdfInteger(fontProgram.Length); // if (!this.Document.Options.NoCompression) // { // fontProgram = Filtering.FlateDecode.Encode(fontProgram); // fontStream.Elements["/Filter"] = new PdfName("/FlateDecode"); // } // fontStream.Elements["/Length"] = new PdfInteger(fontProgram.Length); // fontStream.CreateStream(fontProgram); //#endif // } Owner.irefTable.Add(this.fontDescriptor); Elements[Keys.FontDescriptor] = this.fontDescriptor.Reference; FontEncoding = font.PdfOptions.FontEncoding; FontEmbedding = font.PdfOptions.FontEmbedding; }