Exemple #1
0
            // Draw this glyph part. gaps is used only for Circle parts, and is a set of gaps in the circle in degrees.
            public void Draw(GraphicsTarget g, float[] gaps, RenderOptions renderOpts)
            {
                float radius;

                switch (kind) {
                case GlyphPartKind.Line:
                    if (lineWidth > 0 && path.Length > 0) {
                        if (pen == null) {
                            pen = GraphicsUtil.CreateSolidPen(color.ColorValue, lineWidth, lineStyle);
                        }
                        path.Draw(g, pen);
                    }
                    break;

                case GlyphPartKind.Area:
                    areaPath.Fill(g, color.Brush);
                    break;

                case GlyphPartKind.Circle:
                    if (lineWidth > 0 && circleDiam > lineWidth) {
                        if (pen == null) {
                            pen = GraphicsUtil.CreateSolidPen(color.ColorValue, lineWidth, LineStyle.Mitered);
                        }

                        radius = (circleDiam - lineWidth) / 2;
                        if (gaps == null || gaps.Length == 0) {
                            g.DrawEllipse(pen, point, radius, radius);
                        }
                        else {
                            // There are gaps in the circle. The arcs to draw are from end of one gap to start of the next.
                            RectangleF rect = new RectangleF(point.X - radius, point.Y - radius, radius * 2, radius * 2);
                            for (int i = 1; i < gaps.Length; i += 2) {
                                float startArc = gaps[i];
                                float endArc = (i == gaps.Length - 1) ? gaps[0] : gaps[i + 1];
                #if false
                                Point ptStart = new Point(Math.Cos(startArc * Math.PI / 180.0) * radius, Math.Sin(startArc * Math.PI / 180.0) * radius);
                                Point ptEnd = new Point(Math.Cos(endArc * Math.PI / 180.0) * radius, Math.Sin(endArc * Math.PI / 180.0) * radius);
                                ArcSegment segment = new ArcSegment(ptEnd, new Size(radius, radius), 0, ((endArc - startArc + 360.0) % 360.0) > 180.0, SweepDirection.Clockwise, true);
                                PathFigure figure = new PathFigure(ptStart, new PathSegment[] { segment }, false);
                                PathGeometry geometry = new PathGeometry(new PathFigure[] { figure });
                                g.DrawingContext.DrawGeometry(null, pen, geometry);
                #else
                                g.Graphics.DrawArc(pen, rect, startArc, (float) ((endArc - startArc + 360.0) % 360.0));
                #endif
                            }
                        }
                    }
                    break;

                case GlyphPartKind.FilledCircle:
                    if (circleDiam > 0) {
                        radius = circleDiam / 2;
                        g.FillEllipse(color.Brush, point, radius, radius);
                    }
                    break;
                }
            }
Exemple #2
0
        void DrawSimple(GraphicsTarget g, PointF pt, RenderOptions renderOpts)
        {
            Debug.Assert(parts.Length == 1);
            Debug.Assert(parts[0].kind == GlyphPartKind.Circle || parts[0].kind == GlyphPartKind.FilledCircle);
            Debug.Assert(parts[0].point.X == 0.0F && parts[0].point.Y == 0.0F);

            if (parts[0].kind == GlyphPartKind.Circle) {
                if (parts[0].lineWidth > 0 && parts[0].circleDiam > 0) {
                    if (parts[0].pen == null)
                        parts[0].pen = GraphicsUtil.CreateSolidPen(parts[0].color.ColorValue, parts[0].lineWidth, LineStyle.Mitered);
                    float radius = (parts[0].circleDiam - parts[0].lineWidth) / 2;
                    g.DrawEllipse(parts[0].pen, pt, radius, radius);
                }
            }
            else {
             	// filled circle
                if (parts[0].circleDiam > 0) {
                    float radius = parts[0].circleDiam / 2;
                    g.FillEllipse(parts[0].color.Brush, pt, radius, radius);
                }
            }
        }