private int GetBarWidth(string ACode) { int vResult = 0; FModules[0] = (byte)FModul; FModules[1] = (byte)(FModul * 2); // 2为宽条宽度 FModules[2] = (byte)(FModules[1] * 3 / 2); FModules[3] = (byte)(FModules[1] * 2); int vW = 0; HCCodeLineType vLineType = HCCodeLineType.White; for (int i = 0; i < FCode.Length; i++) { OneBarProps(FCode[i], ref vW, ref vLineType); vResult += vW; } return(vResult); }
public void PaintTo(HCCanvas canvas, RECT rect) { int vX = 0, vHeight = this.Height, vW = 0; HCCodeLineType vLineType = HCCodeLineType.White; if (this.FTextVisible) { vHeight -= 12; } RECT vRect = new RECT(); for (int i = 0, vLen = this.FCode.Length; i < vLen; i++) { vLineType = HCCodeLineType.White; this.OneBarProps(this.FCode[i], ref vW, ref vLineType); if (vLineType != HCCodeLineType.White) { canvas.Brush.Color = Color.Black; } else { canvas.Brush.Color = Color.White; } vRect.Left = vX; vRect.Top = 0; vRect.Right = vX + vW * this.FZoom; vRect.Bottom = vHeight; vX = vRect.Right; vRect.Offset(rect.Left, rect.Top); canvas.FillRect(vRect); } if (this.FCode == "") { canvas.Pen.BeginUpdate(); try { canvas.Pen.Width = 1; canvas.Pen.Color = Color.Black; } finally { canvas.Pen.EndUpdate(); } canvas.Rectangle(rect); } if (this.FTextVisible) { canvas.Font.BeginUpdate(); try { canvas.Font.Size = 8; canvas.Font.FontStyles.Value = 0; canvas.Font.Family = "Arial"; canvas.Font.Color = Color.Black; } finally { canvas.Font.EndUpdate(); } canvas.Brush.Style = HCBrushStyle.bsClear; if (this.FCode != "") { canvas.TextOut(rect.Left + (rect.Width - canvas.TextWidth(this.FText)) / 2, rect.Top + vHeight + 2, this.FText); } else { SIZE vSize = canvas.TextExtent("无效条码" + this.FText); canvas.TextOut(rect.Left + (rect.Width - vSize.cx) / 2, rect.Top + (rect.Height - vSize.cy) / 2, "无效条码" + this.FText); } } }
private void OneBarProps(Char code, ref int width, ref HCCodeLineType lineType) { switch (code) { case '0': width = this.FModules[0]; lineType = HCCodeLineType.White; break; case '1': width = this.FModules[1]; lineType = HCCodeLineType.White; break; case '2': width = this.FModules[2]; lineType = HCCodeLineType.White; break; case '3': width = this.FModules[3]; lineType = HCCodeLineType.White; break; case '5': width = this.FModules[0]; lineType = HCCodeLineType.Black; break; case '6': width = this.FModules[1]; lineType = HCCodeLineType.Black; break; case '7': width = this.FModules[2]; lineType = HCCodeLineType.Black; break; case '8': width = this.FModules[3]; lineType = HCCodeLineType.Black; break; case 'A': width = this.FModules[0]; lineType = HCCodeLineType.BlackHalf; break; case 'B': width = this.FModules[1]; lineType = HCCodeLineType.BlackHalf; break; case 'C': width = this.FModules[2]; lineType = HCCodeLineType.BlackHalf; break; case 'D': width = this.FModules[3]; lineType = HCCodeLineType.BlackHalf; break; case 'F': width = this.FModules[0]; lineType = HCCodeLineType.BlackTrack; break; case 'G': width = this.FModules[0]; lineType = HCCodeLineType.BlackAscend; break; case 'H': width = this.FModules[0]; lineType = HCCodeLineType.BlackDescend; break; default: throw new Exception("HCCode128计算宽度出错!"); } }