/// <summary> /// Renders the bar code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); InitRendering(info); info.CurrPosInString = 0; //info.CurrPos = Center - Size / 2; info.CurrPos = position - CalcDistance(AnchorType.TopLeft, Anchor, Size); if (TurboBit) { RenderTurboBit(info, true); } RenderStart(info); while (info.CurrPosInString < Text.Length) { RenderNextChar(info); RenderGap(info, false); } RenderStop(info); if (TurboBit) { RenderTurboBit(info, false); } if (TextLocation != TextLocation.None) { RenderText(info); } gfx.Restore(state); }
internal override void InitRendering(BarCodeRenderInfo info) { base.InitRendering(info); CalcThinBarWidth(info); info.BarHeight = Size.Height; // HACK in ThickThinBarCode if (TextLocation != TextLocation.None) { info.BarHeight *= 4.0 / 5; } #if DEBUG_ XColor back = XColors.LightSalmon; back.A = 0.3; XSolidBrush brush = new XSolidBrush(back); info.Gfx.DrawRectangle(brush, new XRect(info.Center - size / 2, size)); #endif switch (Direction) { case CodeDirection.RightToLeft: info.Gfx.RotateAtTransform(180, info.Position); break; case CodeDirection.TopToBottom: info.Gfx.RotateAtTransform(90, info.Position); break; case CodeDirection.BottomToTop: info.Gfx.RotateAtTransform(-90, info.Position); break; } }
private void RenderChar(BarCodeRenderInfo info, char ch) { bool[] thickThinLines = ThickThinLines(ch); int idx = 0; while (idx < 9) { RenderBar(info, thickThinLines[idx]); if (idx < 8) { RenderGap(info, thickThinLines[idx + 1]); } idx += 2; } }
/// <summary> /// Calculates the thick and thin line widths, /// taking into account the required rendering size. /// </summary> internal override void CalcThinBarWidth(BarCodeRenderInfo info) { /* * The total width is the sum of the following parts: * Starting lines = 3 * thick + 7 * thin * + * Code Representation = (3 * thick + 7 * thin) * code.Length * + * Stopping lines = 3 * thick + 6 * thin * * with r = relation ( = thick / thin), this results in * * Total width = (13 + 6 * r + (3 * r + 7) * code.Length) * thin */ double thinLineAmount = 13 + 6 * WideNarrowRatio + (3 * WideNarrowRatio + 7) * Text.Length; info.ThinBarWidth = Size.Width / thinLineAmount; }
private void RenderStop(BarCodeRenderInfo info) => RenderChar(info, '*');
private void RenderStart(BarCodeRenderInfo info) { RenderChar(info, '*'); RenderGap(info, false); }
private void RenderNextChar(BarCodeRenderInfo info) { RenderChar(info, Text[info.CurrPosInString]); ++info.CurrPosInString; }