Esempio n. 1
0
File: SymDef.cs Progetto: jonc/carto
        // Draw the pattern using the texture brush.
        void DrawPatternWithTexBrush(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
        {
            Brush brush = (Brush) patternBrushes[color];
            Debug.Assert(brush != null);

            if (angle != 0.0F) {
                object graphicsState = g.Save();

                try {
                    // Set the clipping region to draw only inside the area.
                    g.SetClip(path);

                    // use a transform to rotate.
                    Matrix matrix = GraphicsUtil.RotationMatrix(angle, new PointF(0, 0));
                    g.Transform(matrix);

                    // Get the correct bounding rect.
                    RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -angle);

                    g.FillRectangle(brush, bounding);
                }
                finally {
                    // restore the clip region and the transform
                    g.Restore(graphicsState);
                }
            }
            else {
                path.Fill(g, brush);
            }
        }
Esempio n. 2
0
File: SymDef.cs Progetto: jonc/carto
        // Draw this area symbol in the graphics inside/around the path provided, with
        // the given color only.
        internal void Draw(GraphicsTarget g, SymPathWithHoles path, SymColor color, float angle, RenderOptions renderOpts)
        {
            if (!pensAndBrushesCreated)
                CreatePensAndBrushes();

            if (color == fillColor) {
                path.Fill(g, color.Brush);
            }

            if (hatchMode != 0 && hatchColor == color) {
                DrawHatching(g, path, angle, renderOpts);
            }

            if (drawPattern && patternGlyph.HasColor(color)) {
                // Faster to draw the pattern with a texture brush that has a bitmap
                // of the pattern in it. Better quality to do it all with glyph drawing.
                // Choose based on the renderOptions.
            #if false
                DrawPatternWithTexBrush(g, path, angle, color, renderOpts);
            #else
                if (renderOpts.usePatternBitmaps) {
                    CreatePatternBrush(renderOpts.minResolution);
                    DrawPatternWithTexBrush(g, path, angle, color, renderOpts);
                }
                else
                    DrawPattern(g, path, angle, color, renderOpts);
            #endif
            }

            // Draw the border. Take into account the subpaths defined by start/stop flags along the paths.
            if (borderSymdef != null && borderSymdef.HasColor(color)) {
                // Draw main part of border.
                foreach (SymPath subpath in path.MainPath.GetSubpaths(SymPath.AREA_BOUNDARY_STARTSTOPFLAG))
                    borderSymdef.Draw(g, subpath, color, renderOpts);

                // Draw the holes.
                if (path.Holes != null)
                    foreach (SymPath hole in path.Holes)
                        foreach (SymPath subpath in hole.GetSubpaths(SymPath.AREA_BOUNDARY_STARTSTOPFLAG))
                            borderSymdef.Draw(g, subpath, color, renderOpts);
            }
        }