// Draw this line symbol in the graphics along the path provided, with // the given color only. internal void Draw(GraphicsTarget g, SymPath path, SymColor color, RenderOptions renderOpts) { Debug.Assert(map != null); if (path.Length == 0) return; // Don't draw anything for a zero-length path. if (!pensCreated) CreatePens(); SymPath mainPath = path; // the path for the main part of the line (might be shortened). if (shortenInfo.shortenBeginning > 0.0F || shortenInfo.shortenEnd > 0.0F) { mainPath = path.ShortenBizzarro(shortenInfo.shortenBeginning, shortenInfo.shortenEnd); // NOTE: mainPath can be NULL below here!!! } if (color == lineColor && thickness > 0.0F && mainPath != null) { if (!isDashed) { // simple drawing. mainPath.Draw(g, mainPen); } else { // Draw the dashed line. DrawDashed(g, mainPath, mainPen, dashInfo, renderOpts); } } // Draw the pointy ends of the line. If mainPath is null, this is all the line! if (color == lineColor && shortenInfo.pointyEnds && thickness > 0.0F && (shortenInfo.shortenBeginning > 0.0F || shortenInfo.shortenEnd > 0.0F)) DrawPointyEnds(g, path, shortenInfo.shortenBeginning, shortenInfo.shortenEnd, thickness); if (color == secondLineColor && secondThickness > 0.0F && path != null) { // note that shortened path not used for secondary line, the full length path is. path.Draw(g, secondPen); } // Double lines don't use the shortened path, but the full-length path. if (isDoubleLine) { if (doubleLines.doubleFillColor == color) { if (doubleLines.doubleFillDashed) DrawDashed(g, path, doubleFillPen, doubleLines.doubleDashes, renderOpts); else path.Draw(g, doubleFillPen); } if (doubleLines.doubleLeftColor == color && doubleLines.doubleLeftWidth > 0.0F) { foreach (SymPath subpath in path.GetSubpaths(SymPath.DOUBLE_LEFT_STARTSTOPFLAG)) { float offsetRight = -(doubleLines.doubleThick + doubleLines.doubleLeftWidth) / 2F; if (doubleLines.doubleLeftDashed) { DrawDashedWithOffset(g, subpath, doubleLeftPen, doubleLines.doubleDashes, offsetRight, GraphicsUtil.MITER_LIMIT, renderOpts); } else { SymPath leftPath = subpath.OffsetRight(offsetRight, GraphicsUtil.MITER_LIMIT); leftPath.Draw(g, doubleLeftPen); } } } if (doubleLines.doubleRightColor == color && doubleLines.doubleRightWidth > 0.0F) { foreach (SymPath subpath in path.GetSubpaths(SymPath.DOUBLE_RIGHT_STARTSTOPFLAG)) { float offsetRight = (doubleLines.doubleThick + doubleLines.doubleRightWidth) / 2F; if (doubleLines.doubleRightDashed) { DrawDashedWithOffset(g, subpath, doubleRightPen, doubleLines.doubleDashes, offsetRight, GraphicsUtil.MITER_LIMIT, renderOpts); } else { SymPath rightPath = subpath.OffsetRight(offsetRight, GraphicsUtil.MITER_LIMIT); rightPath.Draw(g, doubleRightPen); } } } } if (glyphs != null && mainPath != null) { foreach (GlyphInfo glyphInfo in glyphs) { if (glyphInfo.glyph.HasColor(color)) DrawGlyphs(g, glyphInfo, mainPath, path, color, renderOpts); } } }
private static void DrawDashedWithOffset(GraphicsTarget g, SymPath path, Pen pen, DashInfo dashes, float offsetRight, float miterLimit, RenderOptions renderOpts) { float[] distances; distances = ComputeDashDistances(path, LocationKind.DashAndGapLengths, dashes.dashLength, dashes.firstDashLength, dashes.lastDashLength, dashes.gapLength, dashes.minGaps, 0, dashes.secondaryEndGaps, dashes.secondaryEndLength, dashes.secondaryMiddleGaps, dashes.secondaryMiddleLength, 1.0F, false); if (distances.Length == 0 || (dashes.gapLength < renderOpts.minResolution && (dashes.secondaryMiddleGaps == 0 || dashes.secondaryMiddleLength < renderOpts.minResolution) && (dashes.secondaryEndGaps == 0 || dashes.secondaryEndLength < renderOpts.minResolution))) { // No dashes, or the dashes are too small to be visible. Draw solid. if (offsetRight != 0) { SymPath offsetPath = path.OffsetRight(offsetRight, miterLimit); offsetPath.Draw(g, pen); } else path.Draw(g, pen); } else { path.DrawDashedOffsetBizzarro(g, pen, distances, 0, offsetRight, miterLimit); } }