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); }
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); } }
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); } }
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 }); }
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 }); }
public void OnDeactivated(DeviceDescription description) { }
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) }); }
public Raster Capture(DeviceDescription description) { throw new NotImplementedException(); }
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 }); } }
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 }); }
public void OnNewPageRequested(GraphicsContext context, DeviceDescription description) { var color = ConvertColor(description.StartBackground); using (var g = CreateGraphics()) { g.Clear(color); } }
public bool ConfirmNewFrame(DeviceDescription description) { return true; }
public MetricsInfo GetMetricInfo(int character, GraphicsContext context, DeviceDescription description) { return GetTextMetrics(character.ToString(CultureInfo.InvariantCulture), context, description); }
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 }; } }
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; }
Point? IGraphicsDevice.GetLocation(DeviceDescription description) { throw new NotImplementedException(); }
void IGraphicsDevice.Clip(Rectangle rectangle, DeviceDescription description) { }
public Rectangle OnResized(DeviceDescription description) { throw new NotImplementedException(); }
public void OnClosed(DeviceDescription description) { }
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()); } }
bool IGraphicsDevice.ConfirmNewFrame(DeviceDescription description) { return true; }
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)); } }
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); } }
Point?IGraphicsDevice.GetLocation(DeviceDescription description) { throw new NotImplementedException(); }
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); } }
public MetricsInfo GetMetricInfo(int character, GraphicsContext context, DeviceDescription description) { return(GetTextMetrics(character.ToString(CultureInfo.InvariantCulture), context, description)); }
void IGraphicsDevice.DrawRaster(Raster raster, Rectangle destination, double rotation, bool interpolated, GraphicsContext context, DeviceDescription description) { throw new NotImplementedException(); }
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, }); }
Raster IGraphicsDevice.Capture(DeviceDescription description) { throw new NotImplementedException(); }
public void DrawRaster(Raster raster, Rectangle destination, double rotation, bool interpolated, GraphicsContext context, DeviceDescription description) { throw new NotImplementedException(); }
double IGraphicsDevice.MeasureWidth(string s, GraphicsContext context, DeviceDescription description) { var metrics = GetTextMetrics(s, context, description); return(metrics.Width); }
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; }
public void OnActivated(DeviceDescription description) { var rectangle = new Rectangle(0, 0, _mapper.Height, _mapper.Width); description.Bounds = rectangle; description.ClipBounds = rectangle; }
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); }
public Rectangle GetSize(GraphicsContext context, DeviceDescription description) { return description.ClipBounds; }
public void OnDrawStopped(DeviceDescription description) { }
Rectangle IGraphicsDevice.GetSize(GraphicsContext context, DeviceDescription description) { return(description.ClipBounds); }
bool IGraphicsDevice.ConfirmNewFrame(DeviceDescription description) { return(true); }
public Point? GetLocation(DeviceDescription description) { throw new NotImplementedException(); }
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), }; }
public GraphicsDeviceEventArgs(DeviceDescription description, GraphicsContext context = null) { this.description = description; this.context = context; }