public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); _isTextPath = false; _isGroupAdded = false; _textWidth = 0; _isMeasuring = false; WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint == SvgRenderingHint.Clipping) { return; } // We do not directly render the contents of the clip-path, unless specifically requested... if (string.Equals(_svgElement.ParentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } _context = renderer.Context; SetQuality(context); SetTransform(context); SetClip(_context); SetMask(_context); _drawGroup = new DrawingGroup(); string sVisibility = _textElement.GetPropertyValue("visibility"); string sDisplay = _textElement.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { _drawGroup.Opacity = 0; } string elementId = this.GetElementName(); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { SvgObject.SetName(_drawGroup, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(_drawGroup, elementId); } } string elementClass = this.GetElementClass(); if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime) { SvgObject.SetClass(_drawGroup, elementClass); } Transform textTransform = this.Transform; if (textTransform != null && !textTransform.Value.IsIdentity) { _drawGroup.Transform = textTransform; } else { textTransform = null; // render any identity transform useless... } Geometry textClip = this.ClipGeometry; if (textClip != null && !textClip.IsEmpty()) { _drawGroup.ClipGeometry = textClip; } else { textClip = null; // render any empty geometry useless... } Brush textMask = this.Masking; if (textMask != null) { _drawGroup.OpacityMask = textMask; } if (textTransform != null || textClip != null || textMask != null) { DrawingGroup curGroup = _context.Peek(); Debug.Assert(curGroup != null); if (curGroup != null) { curGroup.Children.Add(_drawGroup); context.Push(_drawGroup); _isGroupAdded = true; } } _drawContext = _drawGroup.Open(); _horzRenderer.Initialize(_drawContext, _context); _vertRenderer.Initialize(_drawContext, _context); _pathRenderer.Initialize(_drawContext, _context); }
public override void Render(GdiGraphicsRenderer renderer) { _graphics = renderer.GraphicsWrapper; SvgRenderingHint hint = element.RenderingHint; if (hint == SvgRenderingHint.Clipping) { return; } if (element.ParentNode is SvgClipPathElement) { return; } SvgTextElement textElement = element as SvgTextElement; if (textElement == null) { return; } string sVisibility = textElement.GetPropertyValue("visibility"); string sDisplay = textElement.GetPropertyValue("display"); if (String.Equals(sVisibility, "hidden") || String.Equals(sDisplay, "none")) { return; } Clip(_graphics); PointF ctp = new PointF(0, 0); // current text position ctp = GetCurrentTextPosition(textElement, ctp); string sBaselineShift = textElement.GetPropertyValue("baseline-shift").Trim(); double shiftBy = 0; if (sBaselineShift.Length > 0) { float textFontSize = GetComputedFontSize(textElement); if (sBaselineShift.EndsWith("%")) { shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0, sBaselineShift.Length - 1)) / 100 * textFontSize; } else if (sBaselineShift == "sub") { shiftBy = -0.6F * textFontSize; } else if (sBaselineShift == "super") { shiftBy = 0.6F * textFontSize; } else if (sBaselineShift == "baseline") { shiftBy = 0; } else { shiftBy = SvgNumber.ParseNumber(sBaselineShift); } } XmlNodeType nodeType = XmlNodeType.None; foreach (XmlNode child in element.ChildNodes) { nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { ctp.Y -= (float)shiftBy; AddGraphicsPath(textElement, ref ctp, GetText(textElement, child)); ctp.Y += (float)shiftBy; } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (String.Equals(nodeName, "tref")) { AddTRefElementPath((SvgTRefElement)child, ref ctp); } else if (String.Equals(nodeName, "tspan")) { AddTSpanElementPath((SvgTSpanElement)child, ref ctp); } } } PaintMarkers(renderer, textElement, _graphics); _graphics = null; }
protected WpfTextStringFormat GetTextStringFormat(SvgTextContentElement element) { WpfTextStringFormat sf = WpfTextStringFormat.Default; bool doAlign = true; if (element is SvgTSpanElement || element is SvgTRefElement) { SvgTextPositioningElement posElement = (SvgTextPositioningElement)element; if (posElement.X.AnimVal.NumberOfItems == 0) { doAlign = false; } } var comparer = StringComparison.OrdinalIgnoreCase; string dir = element.GetPropertyValue("direction"); bool isRightToLeft = string.Equals(dir, "rtl", comparer); sf.Direction = isRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; if (doAlign) { string anchor = element.GetPropertyValue("text-anchor"); if (isRightToLeft) { if (string.Equals(anchor, "middle", comparer)) { sf.Anchor = WpfTextAnchor.Middle; } else if (string.Equals(anchor, "end", comparer)) { sf.Anchor = WpfTextAnchor.Start; } else { sf.Anchor = WpfTextAnchor.End; } } else { if (string.Equals(anchor, "middle", comparer)) { sf.Anchor = WpfTextAnchor.Middle; } else if (string.Equals(anchor, "end", comparer)) { sf.Anchor = WpfTextAnchor.End; } } } else { SvgTextElement textElement = element.ParentNode as SvgTextElement; if (textElement != null) { string anchor = textElement.GetPropertyValue("text-anchor"); if (isRightToLeft) { if (string.Equals(anchor, "middle", comparer)) { sf.Anchor = WpfTextAnchor.Middle; } else if (string.Equals(anchor, "end", comparer)) { sf.Anchor = WpfTextAnchor.Start; } else { sf.Anchor = WpfTextAnchor.End; } } else { if (string.Equals(anchor, "middle", comparer)) { sf.Anchor = WpfTextAnchor.Middle; } else if (string.Equals(anchor, "end", comparer)) { sf.Anchor = WpfTextAnchor.End; } } } } //if (isRightToLeft) //{ // if (sf.Alignment == TextAlignment.Right) // sf.Alignment = TextAlignment.Left; // else if (sf.Alignment == TextAlignment.Left) // sf.Alignment = TextAlignment.Right; // //sf.FormatFlags = StringFormatFlags.DirectionRightToLeft; //} //dir = element.GetPropertyValue("writing-mode"); //if (dir == "tb") //{ // sf.FormatFlags = sf.FormatFlags | StringFormatFlags.DirectionVertical; //} //sf.FormatFlags = sf.FormatFlags | StringFormatFlags.MeasureTrailingSpaces; return(sf); }
public override void Render(GdiGraphicsRenderer renderer) { _graphics = renderer.GdiGraphics; //SvgRenderingHint hint = _svgElement.RenderingHint; //if (hint == SvgRenderingHint.Clipping) //{ // return; //} //if (_svgElement.ParentNode is SvgClipPathElement) //{ // return; //} SvgTextElement textElement = _svgElement as SvgTextElement; if (textElement == null) { return; } string sVisibility = textElement.GetPropertyValue("visibility"); string sDisplay = textElement.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { return; } if (_textMode != GdiTextMode.Outlining) { SetClip(_graphics); } PointF ctp = new PointF(0, 0); // current text position ctp = GetCurrentTextPosition(textElement, ctp); string sBaselineShift = textElement.GetPropertyValue("baseline-shift").Trim(); double shiftBy = 0; if (sBaselineShift.Length > 0) { float textFontSize = GetComputedFontSize(textElement); if (sBaselineShift.EndsWith("%", StringComparison.OrdinalIgnoreCase)) { shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0, sBaselineShift.Length - 1)) / 100 * textFontSize; } else if (sBaselineShift == "sub") { shiftBy = -0.6F * textFontSize; } else if (sBaselineShift == "super") { shiftBy = 0.6F * textFontSize; } else if (sBaselineShift == "baseline") { shiftBy = 0; } else { shiftBy = SvgNumber.ParseNumber(sBaselineShift); } } // For for fonts loading in the background... var svgDoc = _svgElement.OwnerDocument; if (svgDoc.IsFontsLoaded == false) { //TODO: Use of SpinUntil is known to CPU heavy, but will work for now... SpinWait.SpinUntil(() => svgDoc.IsFontsLoaded == true); } XmlNodeType nodeType = XmlNodeType.None; foreach (XmlNode child in _svgElement.ChildNodes) { SvgStyleableElement stylable = child as SvgStyleableElement; if (stylable != null) { sVisibility = stylable.GetPropertyValue("visibility"); sDisplay = stylable.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { continue; } } nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { ctp.Y -= (float)shiftBy; AddGraphicsPath(textElement, ref ctp, GetText(textElement, child)); ctp.Y += (float)shiftBy; } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (string.Equals(nodeName, "tref")) { AddTRefElementPath((SvgTRefElement)child, ref ctp); } else if (string.Equals(nodeName, "tspan")) { AddTSpanElementPath((SvgTSpanElement)child, ref ctp); } } } PaintMarkers(renderer, textElement, _graphics); _graphics = null; }