コード例 #1
0
        public void Clip(Rectangle rectangle, DeviceDescription description)
        {
            const float epsilon = 0.10f; // A sub-pixel is close enough.
            if (Math.Abs(rectangle.Width - _mapper.Width) < epsilon && Math.Abs(rectangle.Height - _mapper.Height) < epsilon) return;

            _mapper.SetClipRegion(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
        }
コード例 #2
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 void IGraphicsDevice.DrawLine(Point source, Point destination, GraphicsContext context, DeviceDescription description)
 {
     var color = ConvertColor(context.Foreground);
     var p0 = ConvertPointF(source);
     var p1 = ConvertPointF(destination);
     using (var g = CreateGraphics())
     using (var pen = new Pen(color))
     {
         g.DrawLine(pen, p0, p1);
     }
 }
コード例 #3
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 void IGraphicsDevice.DrawCircle(Point center, double radius, GraphicsContext context, DeviceDescription description)
 {
     var diameter = (float)(2 * radius);
     var point = ConvertPointF(center);
     var color = ConvertColor(context.Foreground);
     using (var g = CreateGraphics())
     using (var pen = new Pen(color))
     {
         g.DrawEllipse(pen, (float)(point.X - radius), (float)(point.Y - radius), diameter, diameter);
     }
 }
コード例 #4
0
 public void DrawCircle(Point center, double radius, GraphicsContext context, DeviceDescription description)
 {
     var svgContext = _mapper.MapGraphicsContextToSvg(center, context);
     AddChild(new SvgCircle
     {
         CenterX = svgContext.Coordinate.X,
         CenterY = svgContext.Coordinate.Y,
         Fill = svgContext.Fill,
         FillOpacity = svgContext.Opacity,
         Radius = new SvgUnit(svgContext.UnitType, (float)(radius)),
         Stroke = svgContext.Pen.Stroke,
         StrokeDashArray = svgContext.Pen.StrokeDashArray,
         StrokeLineCap = svgContext.Pen.StrokeLineCap,
         StrokeLineJoin = svgContext.Pen.StrokeLineJoin,
         StrokeWidth = svgContext.Pen.StrokeWidth
     });
 }
コード例 #5
0
 public void DrawLine(Point source, Point destination, GraphicsContext context, DeviceDescription description)
 {
     var svgContext = _mapper.MapGraphicsContextToSvg(source, context);
     var end = _mapper.MapPoint(destination, 0d);
     AddChild(new SvgLine
     {
         EndX = end.X,
         EndY = end.Y,
         Fill = svgContext.Fill,
         FillOpacity = svgContext.Opacity,
         StartX = svgContext.Coordinate.X,
         StartY = svgContext.Coordinate.Y,
         Stroke = svgContext.Pen.Stroke,
         StrokeDashArray = svgContext.Pen.StrokeDashArray,
         StrokeLineCap = svgContext.Pen.StrokeLineCap,
         StrokeLineJoin = svgContext.Pen.StrokeLineJoin,
         StrokeWidth = svgContext.Pen.StrokeWidth
     });
 }
コード例 #6
0
 public void OnDeactivated(DeviceDescription description)
 { }
コード例 #7
0
 public void DrawText(string s, Point location, double rotation, double adjustment, GraphicsContext context, DeviceDescription description)
 {
     var svgContext = _mapper.MapGraphicsContextToSvg(location, rotation, context);
     AddChild(new SvgText
     {
         Fill = svgContext.Pen.Stroke,
         FontFamily = svgContext.Font.Family,
         FontSize = svgContext.Font.Size,
         FontWeight = svgContext.Font.Weight,
         Text = s,
         TextAnchor = svgContext.TextAnchor,
         Transforms = new SvgTransformCollection { svgContext.Coordinate.Rotation },
         X = createUnitCollection(svgContext.Coordinate.X),
         Y = createUnitCollection(svgContext.Coordinate.Y)
     });
 }
コード例 #8
0
 public Raster Capture(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
        public void DrawPath(IEnumerable<IEnumerable<Point>> points, bool winding, GraphicsContext context,
            DeviceDescription description)
        {
            var svgContext = _mapper.MapGraphicsContextToSvg(context);
            foreach (var point in points)
            {
                var vertices = point.ToList();
                var list = new SvgPathSegmentList();
                var first = vertices.First();
                list.Add(new SvgMoveToSegment(new PointF((float)first.X, (float)first.Y)));

                foreach (var vertex in vertices.Skip(1))
                {
                    list.Add(new SvgLineSegment(new PointF((float)first.X, (float)first.Y),
                                                  new PointF((float)vertex.X, (float)vertex.Y)));
                    first = vertex;
                }

                list.Add(new SvgClosePathSegment());
                AddChild(new SvgPath
                {
                    Fill = svgContext.Fill,
                    FillOpacity = svgContext.Opacity,
                    PathData = list,
                    Stroke = svgContext.Pen.Stroke,
                    StrokeDashArray = svgContext.Pen.StrokeDashArray,
                    StrokeLineCap = svgContext.Pen.StrokeLineCap,
                    StrokeLineJoin = svgContext.Pen.StrokeLineJoin,
                    StrokeWidth = svgContext.Pen.StrokeWidth
                });
            }
        }
コード例 #10
0
        public void DrawPolyline(IEnumerable<Point> points, GraphicsContext context, DeviceDescription description)
        {
            var svgContext = _mapper.MapGraphicsContextToSvg(context);
            var collection = new SvgPointCollection();

            collection.AddRange(points.Select(p => _mapper.MapPoint(p, SvgUnitType.User))
                                      .Select(p => new[] { p.X, p.Y })
                                      .SelectMany(p => p));

            AddChild(new SvgPolyline
            {
                Fill = svgContext.Fill,
                FillOpacity = svgContext.Opacity,
                Points = collection,
                Stroke = svgContext.Pen.Stroke,
                StrokeDashArray = svgContext.Pen.StrokeDashArray,
                StrokeLineCap = svgContext.Pen.StrokeLineCap,
                StrokeLineJoin = svgContext.Pen.StrokeLineJoin,
                StrokeWidth = svgContext.Pen.StrokeWidth
            });
        }
コード例 #11
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 public void OnNewPageRequested(GraphicsContext context, DeviceDescription description)
 {
     var color = ConvertColor(description.StartBackground);
     using (var g = CreateGraphics())
     {
         g.Clear(color);
     }
 }
コード例 #12
0
 public bool ConfirmNewFrame(DeviceDescription description)
 {
     return true;
 }
コード例 #13
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 public MetricsInfo GetMetricInfo(int character, GraphicsContext context, DeviceDescription description)
 {
     return GetTextMetrics(character.ToString(CultureInfo.InvariantCulture), context, description);
 }
コード例 #14
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 private MetricsInfo GetTextMetrics(string s, GraphicsContext context, DeviceDescription description)
 {
     var style = GetStyle(context.FontFace);
     var family = Font.FontFamily;
     var conversion = Font.SizeInPoints / family.GetEmHeight(style);
     using (var g = CreateGraphics())
     {
         return new MetricsInfo {
             Ascent = family.GetCellAscent(style) * conversion,
             Descent = family.GetCellDescent(style) * conversion,
             Width = g.MeasureString(s, Font).Width
         };
     }
 }
コード例 #15
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 public void OnActivated(DeviceDescription description)
 {
     var bounds = Bounds;
     var rectangle = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
     description.Bounds = rectangle;
     description.ClipBounds = rectangle;
 }
コード例 #16
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 Point? IGraphicsDevice.GetLocation(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 void IGraphicsDevice.Clip(Rectangle rectangle, DeviceDescription description)
 { }
コード例 #18
0
 public Rectangle OnResized(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 void IGraphicsDevice.Clip(Rectangle rectangle, DeviceDescription description)
 {
 }
コード例 #20
0
 public void OnClosed(DeviceDescription description)
 { }
コード例 #21
0
        void IGraphicsDevice.DrawLine(Point source, Point destination, GraphicsContext context, DeviceDescription description)
        {
            var color = ConvertColor(context.Foreground);
            var p0    = ConvertPointF(source);
            var p1    = ConvertPointF(destination);

            using (var g = CreateGraphics())
                using (var pen = new Pen(color))
                {
                    g.DrawLine(pen, p0, p1);
                }
        }
コード例 #22
0
        void IGraphicsDevice.DrawPolyline(IEnumerable <Point> points, GraphicsContext context, DeviceDescription description)
        {
            var color = ConvertColor(context.Foreground);

            using (var g = CreateGraphics())
                using (var pen = new Pen(color))
                {
                    g.DrawLines(pen, points.Select(ConvertPointF).ToArray());
                }
        }
コード例 #23
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 bool IGraphicsDevice.ConfirmNewFrame(DeviceDescription description)
 {
     return true;
 }
コード例 #24
0
ファイル: GraphPanel.cs プロジェクト: tjaskula/rdotnet
 void IGraphicsDevice.DrawText(string s, Point location, double rotation, double adjustment, GraphicsContext context, DeviceDescription description)
 {
     var color = ConvertColor(context.Foreground);
     using (var g = CreateGraphics())
     using (var brush = new SolidBrush(color))
     {
         g.DrawString(s, Font, brush, ConvertPointF(location));
     }
 }
コード例 #25
0
        void IGraphicsDevice.DrawRectangle(Rectangle rectangle, GraphicsContext context, DeviceDescription description)
        {
            var color = ConvertColor(context.Foreground);
            var rect  = ConvertRectangle(rectangle);

            using (var g = CreateGraphics())
                using (var pen = new Pen(color))
                {
                    g.DrawRectangle(pen, rect);
                }
        }
コード例 #26
0
 Point?IGraphicsDevice.GetLocation(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #27
0
        void IGraphicsDevice.DrawPath(IEnumerable <IEnumerable <Point> > points, bool winding, GraphicsContext context, DeviceDescription description)
        {
            var path = new GraphicsPath();

            foreach (var vertices in points)
            {
                path.StartFigure();
                path.AddLines(vertices.Select(ConvertPointF).ToArray());
            }
            var color = ConvertColor(context.Foreground);

            using (var g = CreateGraphics())
                using (var pen = new Pen(color))
                {
                    g.DrawPath(pen, path);
                }
        }
コード例 #28
0
 public MetricsInfo GetMetricInfo(int character, GraphicsContext context, DeviceDescription description)
 {
     return(GetTextMetrics(character.ToString(CultureInfo.InvariantCulture), context, description));
 }
コード例 #29
0
 void IGraphicsDevice.DrawRaster(Raster raster, Rectangle destination, double rotation, bool interpolated, GraphicsContext context, DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #30
0
 public void DrawRectangle(Rectangle rectangle, GraphicsContext context, DeviceDescription description)
 {
     var svgContext = _mapper.MapGraphicsContextToSvg(new Point(rectangle.Left, rectangle.Top), context);
     AddChild(new SvgRectangle
     {
         Fill = svgContext.Fill,
         FillOpacity = svgContext.Opacity,
         Height = (float)rectangle.Height,
         Stroke = svgContext.Pen.Stroke,
         StrokeDashArray = svgContext.Pen.StrokeDashArray,
         StrokeLineCap = svgContext.Pen.StrokeLineCap,
         StrokeLineJoin = svgContext.Pen.StrokeLineJoin,
         StrokeWidth = svgContext.Pen.StrokeWidth,
         Width = (float)rectangle.Width,
         X = svgContext.Coordinate.X,
         Y = svgContext.Coordinate.Y,
     });
 }
コード例 #31
0
 Raster IGraphicsDevice.Capture(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #32
0
 public void DrawRaster(Raster raster, Rectangle destination, double rotation, bool interpolated, GraphicsContext context,
     DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #33
0
        double IGraphicsDevice.MeasureWidth(string s, GraphicsContext context, DeviceDescription description)
        {
            var metrics = GetTextMetrics(s, context, description);

            return(metrics.Width);
        }
コード例 #34
0
 public double MeasureWidth(string s, GraphicsContext context, DeviceDescription description)
 {
     var svgContext = _mapper.MapGraphicsContextToSvg(context);
     var text = new SvgText
     {
         FontFamily = svgContext.Font.Family,
         FontSize = svgContext.Font.Size,
         FontWeight = svgContext.Font.Weight,
         Text = s,
         TextAnchor = svgContext.TextAnchor,
         X = createUnitCollection(0f),
         Y = createUnitCollection(0f),
     };
     return text.Bounds.Width;
 }
コード例 #35
0
        void IGraphicsDevice.DrawText(string s, Point location, double rotation, double adjustment, GraphicsContext context, DeviceDescription description)
        {
            var color = ConvertColor(context.Foreground);

            using (var g = CreateGraphics())
                using (var brush = new SolidBrush(color))
                {
                    g.DrawString(s, Font, brush, ConvertPointF(location));
                }
        }
コード例 #36
0
 public void OnActivated(DeviceDescription description)
 {
     var rectangle = new Rectangle(0, 0, _mapper.Height, _mapper.Width);
     description.Bounds = rectangle;
     description.ClipBounds = rectangle;
 }
コード例 #37
0
 public void OnDeactivated(DeviceDescription description)
 {
 }
コード例 #38
0
        public void OnNewPageRequested(GraphicsContext context, DeviceDescription description)
        {
            _currentImage = new SvgDocument
            {
                Width = new SvgUnit(SvgUnitType.Pixel, _mapper.Height),
                Height = new SvgUnit(SvgUnitType.Pixel, _mapper.Width)
            };

            _images.Add(_currentImage);
        }
コード例 #39
0
 public Rectangle OnResized(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #40
0
 public Rectangle GetSize(GraphicsContext context, DeviceDescription description)
 {
     return description.ClipBounds;
 }
コード例 #41
0
 public void OnClosed(DeviceDescription description)
 {
 }
コード例 #42
0
 public void OnDrawStopped(DeviceDescription description)
 { }
コード例 #43
0
 public void OnDrawStopped(DeviceDescription description)
 {
 }
コード例 #44
0
 Rectangle IGraphicsDevice.GetSize(GraphicsContext context, DeviceDescription description)
 {
     return(description.ClipBounds);
 }
コード例 #45
0
 bool IGraphicsDevice.ConfirmNewFrame(DeviceDescription description)
 {
     return(true);
 }
コード例 #46
0
 public Point? GetLocation(DeviceDescription description)
 {
     throw new NotImplementedException();
 }
コード例 #47
0
        void IGraphicsDevice.DrawCircle(Point center, double radius, GraphicsContext context, DeviceDescription description)
        {
            var diameter = (float)(2 * radius);
            var point    = ConvertPointF(center);
            var color    = ConvertColor(context.Foreground);

            using (var g = CreateGraphics())
                using (var pen = new Pen(color))
                {
                    g.DrawEllipse(pen, (float)(point.X - radius), (float)(point.Y - radius), diameter, diameter);
                }
        }
コード例 #48
0
        public MetricsInfo GetMetricInfo(int character, GraphicsContext context, DeviceDescription description)
        {
            var svgContext = _mapper.MapGraphicsContextToSvg(new Point(), 0, context);
            var s = new string(new[] { (char)character });
            var family = new FontFamily(svgContext.Font.Family);
            var style = GetStyle(context.FontFace);

            return new MetricsInfo
            {
                Ascent = family.GetCellAscent(style),
                Descent = family.GetCellDescent(style),
                Width = MeasureWidth(s, context, description),
            };
        }
コード例 #49
0
 public GraphicsDeviceEventArgs(DeviceDescription description, GraphicsContext context = null)
 {
     this.description = description;
     this.context     = context;
 }