public void RealizeBrush(XBrush brush, PdfColorMode colorMode, XGraphicsPdfRendererOptions options, double fontEmSize) { // Rendering mode 2 is used for bold simulation. // Reference: TABLE 5.3 Text rendering modes / Page 402 XSolidBrush solidBrush = brush as XSolidBrush; if (solidBrush != null) { XColor color = solidBrush.Color; bool overPrint = solidBrush.Overprint; if (options.RenderMode == XGraphicsPdfRenderMode.Text_Render_Mode_Fill) { RealizeFillColor(color, overPrint, colorMode); } else if (options.RenderMode == XGraphicsPdfRenderMode.Text_Render_Mode_Fill_Stroke) { // Come here in case of bold simulation. RealizeFillColor(color, false, colorMode); //color = XColors.Green; RealizePen(new XPen(color, fontEmSize * Const.BoldEmphasis), colorMode); } else { throw new InvalidOperationException("Only rendering modes 0 and 2 are currently supported."); } } else { if (options.RenderMode != 0) { throw new InvalidOperationException("Rendering modes other than 0 can only be used with solid color brushes."); } XLinearGradientBrush gradientBrush = brush as XLinearGradientBrush; if (gradientBrush != null) { Debug.Assert(UnrealizedCtm.IsIdentity, "Must realize ctm first."); XMatrix matrix = _renderer.DefaultViewMatrix; matrix.Prepend(EffectiveCtm); PdfShadingPattern pattern = new PdfShadingPattern(_renderer.Owner); pattern.SetupFromBrush(gradientBrush, matrix, _renderer); string name = _renderer.Resources.AddPattern(pattern); _renderer.AppendFormatString("/Pattern cs\n", name); _renderer.AppendFormatString("{0} scn\n", name); // Invalidate fill color. _realizedFillColor = XColor.Empty; } } }
double _realizedCharSpace; // Reference: TABLE 5.2 Text state operators / Page 398 public void RealizeFont(XFont font, XBrush brush, XGraphicsPdfRendererOptions options = null) { const string format = Config.SignificantFigures3; // So far rendering mode 0 (fill text) and 2 (fill, then stroke text) only. RealizeBrush(brush, _renderer._colorMode, options, font.Size); // _renderer.page.document.Options.ColorMode); // Realize rendering mode. if (_realizedRenderingMode != options.RenderMode || options.IncludeRenderModeForObject) { _renderer.AppendFormatInt("{0} Tr\n", Convert.ToInt32(options.RenderMode)); _realizedRenderingMode = options.RenderMode; } // Realize character spacing. if (_realizedRenderingMode == XGraphicsPdfRenderMode.Text_Render_Mode_Fill) { 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; } }