示例#1
0
 public DAuthorProperties()
 {
     fill = DColor.White;
     stroke = DColor.Black;
     strokeWidth = 1;
     strokeStyle = DStrokeStyle.Solid;
     startMarker = DMarker.None;
     endMarker = DMarker.None;
     alpha = 1;
     fontName = "Arial";
     fontSize = 14;
     bold = false;
     italics = false;
     underline = false;
     strikethrough = false;
 }
示例#2
0
 public static DBitmap FormatToBmp(IList<Figure> figures, bool antiAlias, DColor backgroundColor)
 {
     if (figures.Count > 0)
     {
         DRect r = GetBounds(figures);
         DBitmap bmp = GraphicsHelper.MakeBitmap(r.Width, r.Height);
         DGraphics dg = GraphicsHelper.MakeGraphics(bmp);
         dg.AntiAlias = antiAlias;
         dg.FillRect(-1, -1, r.Width + 2, r.Height + 2, backgroundColor, 1);
         dg.Translate(-r.Left, -r.Top);
         foreach (Figure f in figures)
             f.Paint(dg);
         return bmp;
     }
     else
         return null;
 }
示例#3
0
 public override void DrawLine(DPoint pt1, DPoint pt2, DColor color, double alpha, DStrokeStyle strokeStyle, double strokeWidth, DStrokeCap strokeCap)
 {
     cr.SetSource(MakeColor(color, alpha));
     cr.LineWidth = strokeWidth;
     CairoStrokeStyle(cr, strokeStyle, strokeWidth);
     cr.LineCap = MakeLineCap(strokeCap);
     cr.MoveTo(pt1.X, pt1.Y);
     cr.LineTo(pt2.X, pt2.Y);
     cr.Stroke();
 }
示例#4
0
文件: DColor.cs 项目: djpnewton/ddraw
 public static string FormatToString(DColor color)
 {
     return string.Format("{0},{1},{2},{3}", color.R, color.G, color.B, color.A);
 }
示例#5
0
 public void SetProperties(DAuthorProperties dap)
 {
     this.fill = dap.Fill;
     this.stroke = dap.Stroke;
     this.strokeWidth = dap.StrokeWidth;
     this.strokeStyle = dap.StrokeStyle;
     this.startMarker = dap.StartMarker;
     this.endMarker = dap.EndMarker;
     this.alpha = dap.Alpha;
     this.fontName = dap.FontName;
     this.fontSize = dap.FontSize;
     this.bold = dap.Bold;
     this.italics = dap.Italics;
     this.underline = dap.Underline;
     this.strikethrough = dap.Strikethrough;
     DoPropertyChanged();
 }
示例#6
0
 Color MakeColor(DColor color, double alpha)
 {
     return new Color(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f * alpha);
 }
示例#7
0
 void CairoSetPattern(Context cr, DColor color, double alpha, DFillStyle fillStyle)
 {
     switch (fillStyle)
     {
         case DFillStyle.ForwardDiagonalHatch:
             Surface patSurf = cr.Target.CreateSimilar(Content.ColorAlpha, 7, 7);
             Context patCr = new Context(patSurf);
             patCr.SetSource(MakeColor(color, alpha));
             patCr.LineWidth = 1;
             patCr.MoveTo(0, 0);
             patCr.LineTo(7, 7);
             patCr.Stroke();
             SurfacePattern pat = new SurfacePattern(patSurf);
             pat.Extend = Extend.Repeat;
             cr.SetSource(pat);
             ((IDisposable)patCr).Dispose();
             ((IDisposable)patSurf).Dispose();
             break;
         default:
             cr.SetSource(MakeColor(color, alpha));
             break;
     }
 }
示例#8
0
 // Drawing Functions //
 public override void FillRect(double x, double y, double width, double height, DColor color, double alpha)
 {
     FillRect(x, y, width, height, color, alpha, DFillStyle.Solid);
 }
示例#9
0
 public override void DrawRect(DRect rect, DColor color, double alpha)
 {
     DrawRect(rect.X, rect.Y, rect.Width, rect.Height, color, alpha, 1);
 }
示例#10
0
 public override void DrawRect(DRect rect, DColor color)
 {
     DrawRect(rect.X, rect.Y, rect.Width, rect.Height, color, 1, 1);
 }
示例#11
0
 public override void DrawRect(double x, double y, double width, double height, DColor color, double alpha, double strokeWidth)
 {
     DrawRect(x, y, width, height, color, alpha, strokeWidth, DStrokeStyle.Solid, DStrokeJoin.Mitre);
 }
示例#12
0
 public override void DrawRect(double x, double y, double width, double height, DColor color)
 {
     DrawRect(x, y, width, height, color, 1, 1);
 }
示例#13
0
 public override void DrawRect(double x, double y, double width, double height, DColor color, double alpha, double strokeWidth, DStrokeStyle strokeStyle, DStrokeJoin strokeJoin)
 {
     cr.SetSource(MakeColor(color, alpha));
     cr.LineWidth = strokeWidth;
     CairoStrokeStyle(cr, strokeStyle, strokeWidth);
     cr.LineJoin = MakeLineJoin(strokeJoin);
     cr.Rectangle(x, y, width, height);
     cr.Stroke();
 }
示例#14
0
 public override void DrawPolyline(DPoints pts, DColor color, double alpha, double strokeWidth, DStrokeStyle strokeStyle, DStrokeJoin strokeJoin, DStrokeCap strokeCap)
 {
     if (pts.Count > 1)
     {
         cr.SetSource(MakeColor(color, alpha));
         CairoStrokeStyle(cr, strokeStyle, strokeWidth);
         cr.LineWidth = strokeWidth;
         cr.LineJoin = MakeLineJoin(strokeJoin);
         cr.LineCap = MakeLineCap(strokeCap);
         cr.MoveTo(pts[0].X, pts[0].Y);
         for (int i = 1; i < pts.Count; i++)
             cr.LineTo(pts[i].X, pts[i].Y);
         cr.Stroke();
     }
 }
示例#15
0
 public override void DrawPolyline(DPoints pts, DColor color)
 {
     DrawPolyline(pts, color, 1, 1, DStrokeStyle.Solid, DStrokeJoin.Round, DStrokeCap.Round);
 }
示例#16
0
 public override void FillPolygon(DPoints pts, DColor color, double alpha)
 {
     FillPolygon(pts, color, alpha, DFillRule.EvenOdd);
 }
示例#17
0
 public override void FillPolygon(DPoints pts, DColor color, double alpha, DFillRule fillRule)
 {
     if (pts.Count > 1)
     {
         cr.SetSource(MakeColor(color, alpha));
         cr.FillRule = MakeFillRule(fillRule);
         cr.MoveTo(pts[0].X, pts[0].Y);
         for (int i = 1; i < pts.Count; i++)
             cr.LineTo(pts[i].X, pts[i].Y);
         cr.Fill();
     }
 }
示例#18
0
 public override void DrawRect(DRect rect, DColor color, double alpha, DStrokeStyle strokeStyle)
 {
     cr.SetSource(MakeColor(color, alpha));
     cr.LineWidth = 1;
     CairoStrokeStyle(cr, strokeStyle, 1);
     cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
     cr.Stroke();
 }
示例#19
0
 public override void FillRect(double x, double y, double width, double height, DColor color, double alpha, DFillStyle fillStyle)
 {
     CairoSetPattern(cr, color, alpha, fillStyle);
     cr.Rectangle(x, y, width, height);
     cr.Fill();
 }
示例#20
0
 public override void DrawText(string text, string fontName, double fontSize, DPoint pt, DColor color, double alpha)
 {
     DrawText(text, fontName, fontSize, false, false, false, false, pt, color, alpha);
 }
示例#21
0
 // Helper Functions //
 Color MakeColor(DColor color)
 {
     return new Color(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
 }
示例#22
0
 public override void DrawText(string text, string fontName, double fontSize, bool bold, bool italics, bool underline, bool strikethrough, DPoint pt, DColor color, double alpha)
 {
     // set context properties (font, color etc)
     FontWeight fw = FontWeight.Normal;
     if (bold) fw = FontWeight.Bold;
     FontSlant fs = FontSlant.Normal;
     if (italics) fs = FontSlant.Italic;
     cr.SelectFontFace(fontName, fs, fw);
     cr.SetFontSize(fontSize);
     cr.SetSource(MakeColor(color, alpha));
     // split text at new lines
     string[] lines = text.Split('\n');
     // draw each line of text
     FontExtents fe = cr.FontExtents;
     foreach (string line in lines)
     {
         if (line.Length > 0) // cairo doesnt like measuring or drawing empty lines
         {
             TextExtents te = cr.TextExtents(line);
             double line_x = pt.X - te.XBearing;
             double line_y = pt.Y - te.YBearing;
             cr.MoveTo(line_x, line_y);
             cr.ShowText(line);
             if (underline)
             {
                 cr.MoveTo(line_x, line_y + fe.Descent - 2);
                 cr.LineTo(line_x + te.XAdvance, line_y + fe.Descent - 2);
                 cr.Stroke();
             }
             if (strikethrough)
             {
                 cr.MoveTo(line_x, line_y - fe.Descent);
                 cr.LineTo(line_x + te.XAdvance, line_y - fe.Descent);
                 cr.Stroke();
             }
         }
         // increment pt.Y
         pt.Y += fe.Height;
     }
 }
示例#23
0
 public void SetProperties(DColor fill, DColor stroke, double strokeWidth, DStrokeStyle strokeStyle, 
     DMarker startMarker, DMarker endMarker, double alpha, string fontName, double fontSize, bool bold,
     bool italics, bool underline, bool strikethrough)
 {
     this.fill = fill;
     this.stroke = stroke;
     this.strokeWidth = strokeWidth;
     this.strokeStyle = strokeStyle;
     this.startMarker = startMarker;
     this.endMarker = endMarker;
     this.alpha = alpha;
     this.fontName = fontName;
     this.fontSize = fontSize;
     this.bold = bold;
     this.italics = italics;
     this.underline = underline;
     this.strikethrough = strikethrough;
     DoPropertyChanged();
 }
示例#24
0
 public override void FillEllipse(double x, double y, double width, double height, DColor color)
 {
     FillEllipse(x, y, width, height, color, 1);
 }
示例#25
0
 public void SetProperties(Type figureClass, DAuthorProperties dap)
 {
     if (typeof(IFillable).IsAssignableFrom(figureClass))
         this.fill = dap.Fill;
     if (typeof(IStrokeable).IsAssignableFrom(figureClass))
     {
         this.stroke = dap.Stroke;
         this.strokeWidth = dap.StrokeWidth;
         this.strokeStyle = dap.StrokeStyle;
     }
     if (typeof(IMarkable).IsAssignableFrom(figureClass))
     {
         this.startMarker = dap.StartMarker;
         this.endMarker = dap.EndMarker;
     }
     if (typeof(IAlphaBlendable).IsAssignableFrom(figureClass))
         this.alpha = dap.Alpha;
     if (typeof(ITextable).IsAssignableFrom(figureClass))
     {
         this.fontName = dap.FontName;
         this.fontSize = dap.FontSize;
         this.bold = dap.Bold;
         this.italics = dap.Italics;
         this.underline = dap.Underline;
         this.strikethrough = dap.Strikethrough;
     }
     DoPropertyChanged();
 }
示例#26
0
 public override void FillEllipse(double x, double y, double width, double height, DColor color, double alpha)
 {
     cr.SetSource(MakeColor(color, alpha));
     cr.LineWidth = 1;
     CairoStrokeStyle(cr, DStrokeStyle.Solid, 1);
     CairoEllipse(cr, x, y, width, height);
     cr.Fill();
 }
示例#27
0
 public string Copy(List<Figure> figs, out DBitmap bmp, bool bmpAntiAlias, DColor bmpBackgroundColor)
 {
     bmp = FigureSerialize.FormatToBmp(figs, bmpAntiAlias, bmpBackgroundColor);
     return FigureSerialize.FormatToXml(figs, null);
 }
示例#28
0
 public override void FillEllipse(DRect rect, DColor color)
 {
     FillEllipse(rect.X, rect.Y, rect.Width, rect.Height, color, 1);
 }
示例#29
0
文件: DColor.cs 项目: djpnewton/ddraw
 public bool Equals(DColor color)
 {
     return R == color.R && G == color.G && B == color.B && A == color.A;
 }
示例#30
0
 public override void FillEllipse(DRect rect, DColor color, double alpha)
 {
     FillEllipse(rect.X, rect.Y, rect.Width, rect.Height, color, alpha);
 }