public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) { var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height); var h = layout.Metrics.Height; //todo : : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. //renderTarget.DrawTextLayout ((frame.TopLeft - h*Point.OneY.Y).ToVector2 (), layout, GetBrush (frame, brush)); }
private DW.TextFormat GetTextFormat(Font font) { return new DW.TextFormat (factories.DWFactory, font.Family, (float)font.Size); }
private TextPaint GetFontPaint(Font font, TextAlignment alignment) { var paint = new TextPaint(PaintFlags.AntiAlias); paint.TextAlign = Paint.Align.Left; if (alignment == TextAlignment.Center) paint.TextAlign = Paint.Align.Left; else if (alignment == TextAlignment.Right) paint.TextAlign = Paint.Align.Right; paint.TextSize = (float) font.Size; var typeface = Typeface.Create(font.Family, TypefaceStyle.Normal); paint.SetTypeface(typeface); return paint; }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) { if (brush == null) return; var paint = GetFontPaint(font, alignment); var w = paint.MeasureText(text); var fm = paint.GetFontMetrics(); var h = fm.Ascent + fm.Descent; var point = frame.Position; var fr = new Rect(point, new Size(w, h)); AddBrushPaint(paint, brush, fr); graphics.DrawText(text, (float) point.X, (float) point.Y, paint); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush baseBrush = null) { if (baseBrush == null) return; var sdfont = new System.Drawing.Font(font.Family, (float) font.Size, FontStyle.Regular, GraphicsUnit.Pixel); var sz = graphics.MeasureString(text, sdfont); var point = frame.Position; var fr = new Rect(point, new Size(sz.Width, sz.Height)); graphics.DrawString(text, sdfont, baseBrush.GetBrush(fr), Conversions.GetPointF(point - new Point(0, sdfont.Height))); }
private void AddElement(IList<IDrawable> list, XElement e, Pen inheritPen, BaseBrush inheritBaseBrush) { Element element = null; var styleAttributedDictionary = e.Attributes().ToDictionary(k => k.Name.LocalName, v => v.Value); var pen = _stylesParser.GetPen(styleAttributedDictionary); var baseBrush = _stylesParser.GetBrush(styleAttributedDictionary,defs, pen); var style = ReadString(e.Attribute("style")); if (!string.IsNullOrWhiteSpace(style)) { ApplyStyle(style, ref pen, ref baseBrush); } pen = pen ?? inheritPen; baseBrush = baseBrush ?? inheritBaseBrush; //var id = ReadString (e.Attribute ("id")); // // Elements // switch (e.Name.LocalName) { case "text": { var x = _valuesParser.ReadNumber(e.Attribute("x")); var y = _valuesParser.ReadNumber(e.Attribute("y")); var text = e.Value.Trim(); var font = new Font(); element = new Text(text, new Rect(new Point(x, y), new Size(double.MaxValue, double.MaxValue)), font, TextAlignment.Left, pen, baseBrush); } break; case "rect": { var x = _valuesParser.ReadNumber(e.Attribute("x")); var y = _valuesParser.ReadNumber(e.Attribute("y")); var width = _valuesParser.ReadNumber(e.Attribute("width")); var height = _valuesParser.ReadNumber(e.Attribute("height")); element = new Rectangle(new Point(x, y), new Size(width, height), pen, baseBrush); } break; case "ellipse": { var cx = _valuesParser.ReadNumber(e.Attribute("cx")); var cy = _valuesParser.ReadNumber(e.Attribute("cy")); var rx = _valuesParser.ReadNumber(e.Attribute("rx")); var ry = _valuesParser.ReadNumber(e.Attribute("ry")); element = new Ellipse(new Point(cx - rx, cy - ry), new Size(2*rx, 2*ry), pen, baseBrush); } break; case "circle": { var cx = _valuesParser.ReadNumber(e.Attribute("cx")); var cy = _valuesParser.ReadNumber(e.Attribute("cy")); var rr = _valuesParser.ReadNumber(e.Attribute("r")); element = new Ellipse(new Point(cx - rr, cy - rr), new Size(2*rr, 2*rr), pen, baseBrush); } break; case "path": { var dA = e.Attribute("d"); if (dA != null && !string.IsNullOrWhiteSpace(dA.Value)) { var p = new Path(pen, baseBrush); SvgPathParser.Parse(p, dA.Value); element = p; } } break; case "g": { var g = new Group(); AddElements(g.Children, e.Elements(), pen, baseBrush); element = g; } break; case "use": { var href = ReadString(e.Attributes().FirstOrDefault(x => x.Name.LocalName == "href")); if (!string.IsNullOrWhiteSpace(href)) { XElement useE; if (defs.TryGetValue(href.Trim().Replace("#", ""), out useE)) { var useList = new List<IDrawable>(); AddElement(useList, useE, pen, baseBrush); element = useList.OfType<Element>().FirstOrDefault(); } } } break; case "title": Graphic.Title = ReadString(e); break; case "description": Graphic.Description = ReadString(e); break; case "defs": // Already read in earlier pass break; case "namedview": case "metadata": case "SVGTestCase": case "switch": break; default: throw new NotSupportedException("SVG element \"" + e.Name.LocalName + "\" is not supported"); } if (element != null) { element.Transform = ReadTransform(ReadString(e.Attribute("transform"))); list.Add(element); } }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) { }