Beispiel #1
0
 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));
 }
        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)));
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
 {
 }
Beispiel #6
0
        public Size MeasureText(string text, Font font)
        {
            if (string.IsNullOrEmpty(text))
                return Size.Zero;
            if (font == null)
                throw new ArgumentNullException("font");

            string fontName = font.Name;
            Array availableFonts =
                #if __IOS__
                UIKit.UIFont.FontNamesForFamilyName(fontName);
                #else
                AppKit.NSFontManager.SharedFontManager.AvailableMembersOfFontFamily (fontName).ToArray ();
                #endif

            #if __IOS__
            UIKit.UIFont nsFont;
            if (availableFonts != null && availableFonts.Length > 0)
                nsFont = UIKit.UIFont.FromName(font.Name, (nfloat)font.Size);
            else
                nsFont = UIKit.UIFont.FromName("Georgia", (nfloat)font.Size);
            #else
            AppKit.NSFont nsFont;
            if (availableFonts != null && availableFonts.Length > 0)
            nsFont = AppKit.NSFont.FromFontName(font.Name, (nfloat)font.Size);
            else
            nsFont = AppKit.NSFont.FromFontName("Georgia", (nfloat)font.Size);
            #endif

            using (var s = new NSAttributedString(text, font: nsFont))
            using (nsFont)
            {
                #if __IOS__
                var result = s.GetBoundingRect(new CGSize(float.MaxValue, float.MaxValue), NSStringDrawingOptions.UsesDeviceMetrics, null);
                #else
                var result = s.BoundingRectWithSize(new CGSize(float.MaxValue, float.MaxValue), NSStringDrawingOptions.UsesDeviceMetrics);
                #endif
                return new Size(result.Width, result.Height);
            }
        }
Beispiel #7
0
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
        {
            if (string.IsNullOrEmpty (text))
                return;
            if (font == null)
                throw new ArgumentNullException ("font");

            SetBrush (brush);

            string fontName = font.Name;
            Array availableFonts =
                #if __IOS__
                UIKit.UIFont.FontNamesForFamilyName(fontName);
                #else
                AppKit.NSFontManager.SharedFontManager.AvailableMembersOfFontFamily (fontName).ToArray ();
                #endif
            if (availableFonts != null && availableFonts.Length > 0)
                context.SelectFont (font.Name, (nfloat)font.Size, CGTextEncoding.MacRoman);
            else
                context.SelectFont ("Georgia", (nfloat)font.Size, CGTextEncoding.MacRoman);

            context.ShowTextAtPoint ((nfloat)frame.X, (nfloat)frame.Y, text);

            //			using (var atext = new NSMutableAttributedString (text)) {
            //
            //				atext.AddAttributes (new CTStringAttributes {
            //					ForegroundColor = new CGColor (1, 0, 0, 1),
            //				}, new NSRange (0, text.Length));
            //
            //				using (var ct = new CTFramesetter (atext))
            //				using (var path = CGPath.FromRect (Conversions.GetCGRect (frame)))
            //				using (var tframe = ct.GetFrame (new NSRange (0, atext.Length), path, null))
            //					tframe.Draw (context);
            //			}
        }
Beispiel #8
0
        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.Id = ReadString(e.Attribute("id"));
              }

              if (element != null)
              {
            element.Transform = ReadTransform(ReadString(e.Attribute("transform")));
            list.Add(element);
              }
        }
Beispiel #9
0
 private DW.TextFormat GetTextFormat(Font font)
 {
     return new DW.TextFormat (factories.DWFactory, font.Family, (float)font.Size);
 }
Beispiel #10
0
 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));
 }
Beispiel #11
0
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
 {
     throw new NotImplementedException();
 }
Beispiel #12
0
 private DW.TextFormat GetTextFormat(Font font)
 {
     return(new DW.TextFormat(factories.DWFactory, font.Family, (float)font.Size));
 }