public DrawableCodeSymbol(ICodeSymbol codeSymbol, SymbolColors symbolColors) { this.CodeSymbol = codeSymbol; this.SymbolColoring = symbolColors; this.DrawSymbol = false; this.DrawSymbolValue = false; this.DrawBitIndices = false; }
public void DrawCodeSymbol(ICodeSymbol symbol, Graphics g, SymbolColors symbolColors, bool drawBitIndices, bool drawSymbolValue) { // Draw symbol edges float penWidth = 2; var p = new Pen(symbolColors.Outline, penWidth); var smallFont = new Font(this.fontFamily, 0.5F * CodeElHeight, FontStyle.Regular, GraphicsUnit.Pixel); var largeFont = new Font(this.fontFamily, CodeElHeight, FontStyle.Regular, GraphicsUnit.Pixel); var solidbrush = new SolidBrush(symbolColors.BitIndex); foreach (var edge in symbol.GetContour()) { var edgeStartX = edge.Start.X * this.CodeElWidth; var edgeStartY = edge.Start.Y * this.CodeElHeight; var edgeEndX = edge.End.X * this.CodeElWidth; var edgeEndY = edge.End.Y * this.CodeElHeight; switch (edge.GetDirection()) // Inside is on the right looking in edge direction. { case PolygonEdge.Direction.Down: edgeStartX -= penWidth / 2; // shift left edgeEndX -= penWidth / 2; // shift left edgeStartY += penWidth / 2; // push down edgeEndY -= penWidth / 2; // pull up break; case PolygonEdge.Direction.Up: edgeStartX += penWidth / 2; // shift right edgeEndX += penWidth / 2; // shift right edgeStartY -= penWidth / 2; // push up edgeEndY += penWidth / 2; // pull down break; case PolygonEdge.Direction.Left: edgeStartX -= penWidth / 2; // shift left edgeEndX += penWidth / 2; // shift right edgeStartY -= penWidth / 2; // pull up edgeEndY -= penWidth / 2; // pull up break; case PolygonEdge.Direction.Right: edgeStartX += penWidth / 2; // shift right edgeEndX -= penWidth / 2; // shift left edgeStartY += penWidth / 2; // push down edgeEndY += penWidth / 2; // push down break; default: throw new NotImplementedException("Drawing Direction type " + edge.GetDirection().ToString() + " is not implemented."); } g.DrawLine(p, edgeStartX, edgeStartY, edgeEndX, edgeEndY); } // Draw bit index if (drawBitIndices) { for (uint i = 0; i < symbol.CurrentSymbolLength; i++) { var pixCoord = symbol.GetBitCoordinate(i); g.DrawString(i.ToString(), smallFont, solidbrush, new Point((int)((pixCoord.X + 0.4F) * CodeElWidth), (int)((pixCoord.Y + 0.4F) * CodeElHeight))); } } if (drawSymbolValue && (symbol.CurrentSymbolLength > 0)) { var drawLocation = symbol.GetBitCoordinate(Math.Min(4, symbol.CurrentSymbolLength - 1)); var solidBrush = new SolidBrush(symbolColors.SymbolValue); g.DrawString(symbol.ToString(), largeFont, solidBrush, new Point((int)(drawLocation.X * CodeElWidth), (int)(drawLocation.Y * CodeElHeight))); } }
public CodeSymbolCodeDrawingProperties(SymbolColors symbolColoring, Color symbolIndexColor, string displayName) { this.SymbolColoring = symbolColoring; this.SymbolIndexColor = symbolIndexColor; this.DisplayName = displayName; }