Example #1
0
        public org.pdfclown.documents.contents.objects.ContentObject ToInlineObject(org.pdfclown.documents.contents.composition.PrimitiveComposer composer)
        {
            var barcodeObject = composer.BeginLocalState();

            RectangleF  innerRect = new RectangleF(MargemHorizontal, MargemVertical, Size.Width - 2 * MargemHorizontal, Size.Height - 2 * MargemVertical);
            List <byte> codeBytes = new List <byte>();

            codeBytes.Add(105);

            for (int i = 0; i < this.Code.Length; i += 2)
            {
                byte b = byte.Parse(this.Code.Substring(i, 2));
                codeBytes.Add(b);
            }

            // Calcular dígito verificador
            int cd = 105;

            for (int i = 1; i < codeBytes.Count; i++)
            {
                cd += i * codeBytes[i];
                cd %= 103;
            }

            codeBytes.Add((byte)cd);
            codeBytes.Add(106);

            float n = codeBytes.Count * 11 + 2;
            float w = innerRect.Width / n;

            float x = 0;

            for (int i = 0; i < codeBytes.Count; i++)
            {
                byte[] pt = Barcode128C.Dic[codeBytes[i]];

                for (int i2 = 0; i2 < pt.Length; i2++)
                {
                    if (i2 % 2 == 0)
                    {
                        composer.SafeDrawRectangle(new RectangleF(innerRect.X + x, innerRect.Y, w * pt[i2], innerRect.Height));
                    }

                    x += w * pt[i2];
                }
            }

            composer.Fill();
            composer.End();
            return(barcodeObject);
        }