/// <summary>
        /// Draws a filled rectangle on the resource at a specific position with a determined color.
        /// </summary>
        /// <param name="image">The surface.</param>
        /// <param name="x1">X1.</param>
        /// <param name="y1">Y1.</param>
        /// <param name="x2">X2.</param>
        /// <param name="y2">Y2.</param>
        /// <param name="color">The color.</param>
        protected override void DrawFilledRectangle(BCGSurface image, int x1, int y1, int x2, int y2, int color)
        {
            int scaleX = this.scale * this.scaleX;
            int scaleY = this.scale * this.scaleY;

            if (x1 > x2) // Swap
            {
                // XOR Swap not available in C#
                int t = x1;
                x1 = x2;
                x2 = t;
            }

            if (y1 > y2) // Swap
            {
                // XOR Swap not available in C#
                int t = y1;
                y1 = y2;
                y2 = t;
            }


            image.FillRectangle(
                (x1 + this.offsetX) * scaleX + this.pushLabel[0],
                (y1 + this.offsetY) * scaleY + this.pushLabel[1],
                (x2 + this.offsetX) * scaleX + scaleX - 1 + this.pushLabel[0],
                (y2 + this.offsetY) * scaleY + scaleY - 1 + this.pushLabel[1],
                this.GetColor(image, color)
                );
        }
        /**
         * Draws the text.
         * The coordinate passed are the positions of the barcode.
         * $x1 and $y1 represent the top left corner.
         * $x2 and $y2 represent the bottom right corner.
         *
         * @param resource $im
         * @param int $x1
         * @param int $y1
         * @param int $x2
         * @param int $y2
         */
        public /*internal*/ void Draw(BCGSurface image, int x1, int y1, int x2, int y2)
        {
            var x = 0;
            var y = 0;

            var fontDimension = this.font.GetDimension();

            if (this.position == Position.Top || this.position == Position.Bottom)
            {
                if (this.position == Position.Top)
                {
                    y = y1 - this.spacing - fontDimension[1];
                }
                else if (this.position == Position.Bottom)
                {
                    y = y2 + this.spacing;
                }

                if (this.alignment == Alignment.Center)
                {
                    x = (x2 - x1) / 2 + x1 - fontDimension[0] / 2 + this.offset;
                }
                else if (this.alignment == Alignment.Left)
                {
                    x = x1 + this.offset;
                }
                else
                {
                    x = x2 + this.offset - fontDimension[0];
                }
            }
            else
            {
                if (this.position == Position.Left)
                {
                    x = x1 - this.spacing - fontDimension[0];
                }
                else if (this.position == Position.Right)
                {
                    x = x2 + this.spacing;
                }

                if (this.alignment == Alignment.Center)
                {
                    y = (y2 - y1) / 2 + y1 - fontDimension[1] / 2 + this.offset;
                }
                else if (this.alignment == Alignment.Top)
                {
                    y = y1 + this.offset;
                }
                else
                {
                    y = y2 + this.offset - fontDimension[1];
                }
            }

            this.font.SetText(this.text);
            this.font.Draw(image, x, y);
        }
 /// <summary>
 /// Allocates the color based on the integer.
 /// </summary>
 /// <param name="image">The surface.</param>
 /// <param name="color">The color.</param>
 /// <returns>Implementation details of the color.</returns>
 protected SKColor GetColor(BCGSurface image, int color)
 {
     if (color == BCGBarcode.COLOR_BG)
     {
         return(this.colorBg.Allocate(image));
     }
     else
     {
         return(this.colorFg.Allocate(image));
     }
 }
 /// <summary>
 /// Draws the text.
 /// The coordinate passed are the positions of the barcode.
 /// <paramref name="x1"/> and <paramref name="y1"/> represent the top left corner.
 /// <paramref name="x2"/> and <paramref name="y2"/> represent the bottom right corner.
 /// </summary>
 /// <param name="image">The surface.</param>
 /// <param name="x1">The top left corner X coordinate.</param>
 /// <param name="y1">The top left corner Y coordinate.</param>
 /// <param name="x2">The bottom right corner X coordinate.</param>
 /// <param name="y2">The bottom right corner Y coordinate.</param>
 protected virtual void DrawText(BCGSurface image, int x1, int y1, int x2, int y2)
 {
     foreach (var label in labels)
     {
         label.Draw(image,
                    (x1 + this.offsetX) * this.scale + this.pushLabel[0],
                    (y1 + this.offsetY) * this.scale + this.pushLabel[1],
                    (x2 + this.offsetX) * this.scale + this.pushLabel[0],
                    (y2 + this.offsetY) * this.scale + this.pushLabel[1]);
     }
 }
        /// <summary>
        /// Draws 1 pixel on the resource at a specific position with a determined color.
        /// </summary>
        /// <param name="image">The surface.</param>
        /// <param name="x">The X coordinate.</param>
        /// <param name="y">The Y coordinate.</param>
        /// <param name="color">The color.</param>
        protected virtual void DrawPixel(BCGSurface image, int x, int y, int color)
        {
            var xR = (x + this.offsetX) * this.scale + this.pushLabel[0];
            var yR = (y + this.offsetY) * this.scale + this.pushLabel[1];

            // We always draw a rectangle
            image.FillRectangle(
                xR,
                yR,
                xR + this.scale - 1,
                yR + this.scale - 1,
                this.GetColor(image, color)
                );
        }
        /// <summary>
        /// Draws 1 pixel on the resource at a specific position with a determined color.
        /// </summary>
        /// <param name="image">The surface.</param>
        /// <param name="x">X.</param>
        /// <param name="y">Y.</param>
        /// <param name="color">The color.</param>
        protected override void DrawPixel(BCGSurface image, int x, int y, int color)
        {
            int scaleX = this.scale * this.scaleX;
            int scaleY = this.scale * this.scaleY;

            int xR = (x + this.offsetX) * scaleX + this.pushLabel[0];
            int yR = (y + this.offsetY) * scaleY + this.pushLabel[1];

            image.FillRectangle(
                xR,
                yR,
                xR + scaleX - 1,
                yR + scaleY - 1,
                this.GetColor(image, color)
                );
        }
        /// <summary>
        /// Draws a filled rectangle on the resource at a specific position with a determined color.
        /// </summary>
        /// <param name="image">The surface.</param>
        /// <param name="x1">The top left corner X coordinate.</param>
        /// <param name="y1">The top left corner Y coordinate.</param>
        /// <param name="x2">The bottom right corner X coordinate.</param>
        /// <param name="y2">The bottom right corner Y coordinate.</param>
        /// <param name="color">The color.</param>
        protected virtual void DrawFilledRectangle(BCGSurface image, int x1, int y1, int x2, int y2, int color)
        {
            if (x1 > x2)
            { // Swap
                x1 ^= x2 ^= x1 ^= x2;
            }

            if (y1 > y2)
            { // Swap
                y1 ^= y2 ^= y1 ^= y2;
            }

            image.FillRectangle(
                (x1 + this.offsetX) * this.scale + this.pushLabel[0],
                (y1 + this.offsetY) * this.scale + this.pushLabel[1],
                (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1,
                (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1,
                this.GetColor(image, color)
                );
        }
 /// <summary>
 /// Draws an empty rectangle on the resource at a specific position with a determined color.
 /// </summary>
 /// <param name="image">The surface.</param>
 /// <param name="x1">The top left corner X coordinate.</param>
 /// <param name="y1">The top left corner Y coordinate.</param>
 /// <param name="x2">The bottom right corner X coordinate.</param>
 /// <param name="y2">The bottom right corner Y coordinate.</param>
 /// <param name="color">The color.</param>
 protected virtual void DrawRectangle(BCGSurface image, int x1, int y1, int x2, int y2, int color)
 {
     if (this.scale == 1)
     {
         image.FillRectangle(
             (x1 + this.offsetX) + this.pushLabel[0],
             (y1 + this.offsetY) + this.pushLabel[1],
             (x2 + this.offsetX) + this.pushLabel[0],
             (y2 + this.offsetY) + this.pushLabel[1],
             this.GetColor(image, color)
             );
     }
     else
     {
         image.FillRectangle((x1 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y1 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.GetColor(image, color));
         image.FillRectangle((x1 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x1 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.GetColor(image, color));
         image.FillRectangle((x2 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.GetColor(image, color));
         image.FillRectangle((x1 + this.offsetX) * this.scale + this.pushLabel[0], (y2 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.GetColor(image, color));
     }
 }
        /// <summary>
        /// Draws an empty rectangle on the resource at a specific position with a determined color.
        /// </summary>
        /// <param name="image">The surface.</param>
        /// <param name="x1">X1.</param>
        /// <param name="y1">Y1.</param>
        /// <param name="x2">X2.</param>
        /// <param name="y2">Y2.</param>
        /// <param name="color">The color.</param>
        protected override void DrawRectangle(BCGSurface image, int x1, int y1, int x2, int y2, int color)
        {
            int scaleX = this.scale * this.scaleX;
            int scaleY = this.scale * this.scaleY;

            if (this.scale == 1)
            {
                image.FillRectangle(
                    (x1 + this.offsetX) * scaleX + this.pushLabel[0],
                    (y1 + this.offsetY) * scaleY + this.pushLabel[1],
                    (x2 + this.offsetX) * scaleX + this.pushLabel[0],
                    (y2 + this.offsetY) * scaleY + this.pushLabel[1],
                    this.GetColor(image, color)
                    );
            }
            else
            {
                image.FillRectangle((x1 + this.offsetX) * scaleX + this.pushLabel[0], (y1 + this.offsetY) * scaleY + this.pushLabel[1], (x2 + this.offsetX) * scaleX + scaleX - 1 + this.pushLabel[0], (y1 + this.offsetY) * scaleY + scaleY - 1 + this.pushLabel[1], this.GetColor(image, color));
                image.FillRectangle((x1 + this.offsetX) * scaleX + this.pushLabel[0], (y1 + this.offsetY) * scaleY + this.pushLabel[1], (x1 + this.offsetX) * scaleX + scaleX - 1 + this.pushLabel[0], (y2 + this.offsetY) * scaleY + scaleY - 1 + this.pushLabel[1], this.GetColor(image, color));
                image.FillRectangle((x2 + this.offsetX) * scaleX + this.pushLabel[0], (y1 + this.offsetY) * scaleY + this.pushLabel[1], (x2 + this.offsetX) * scaleX + scaleX - 1 + this.pushLabel[0], (y2 + this.offsetY) * scaleY + scaleY - 1 + this.pushLabel[1], this.GetColor(image, color));
                image.FillRectangle((x1 + this.offsetX) * scaleX + this.pushLabel[0], (y2 + this.offsetY) * scaleY + this.pushLabel[1], (x2 + this.offsetX) * scaleX + scaleX - 1 + this.pushLabel[0], (y2 + this.offsetY) * scaleY + scaleY - 1 + this.pushLabel[1], this.GetColor(image, color));
            }
        }
Ejemplo n.º 10
0
        /**
         * Draws the text on the image at a specific position.
         * $x and $y represent the left bottom corner.
         *
         * @param resource $im
         * @param int $x
         * @param int $y
         */
        public void Draw(BCGSurface image, int x, int y)
        {
            var width         = GetWidth();
            var height        = GetHeight();
            var top           = GetFontInfo().Top;
            var rotationAngle = GetRotationAngle();

            font !.Color = this.foregroundColor.Allocate(image);

            var canvas = image.SKSurface.Canvas;

            canvas.Save();
            switch (rotationAngle)
            {
            case 0:
                canvas.Translate(x, y - top);
                break;

            case 90:
                canvas.Translate(height + x + top, y);
                break;

            case 180:
                canvas.Translate(width + x, height + y + top);
                break;

            case 270:
                canvas.Translate(x - top, width + y);
                break;
            }

            canvas.RotateDegrees(rotationAngle);


            image.SKSurface.Canvas.DrawText(text, 0, 0, font);
            canvas.Restore();
        }
 /// <summary>
 /// Creates a color to be used on the surface.
 /// </summary>
 /// <param name="image">The surface.</param>
 /// <returns>The color.</returns>
 public SKColor Allocate(BCGSurface image)
 {
     return(new SKColor((byte)this.vR, (byte)this.vG, (byte)this.vB));
 }
 /// <summary>
 /// Draws a filled rectangle on the resource at a specific position with the foreground color.
 /// </summary>
 /// <param name="image">The surface.</param>
 /// <param name="x1">The top left corner X coordinate.</param>
 /// <param name="y1">The top left corner Y coordinate.</param>
 /// <param name="x2">The bottom right corner X coordinate.</param>
 /// <param name="y2">The bottom right corner Y coordinate.</param>
 protected virtual void DrawFilledRectangle(BCGSurface image, int x1, int y1, int x2, int y2)
 {
     this.DrawFilledRectangle(image, x1, y1, x2, y2, BCGBarcode.COLOR_FG);
 }
 /// <summary>
 /// Draws 1 pixel on the resource at a specific position with the foreground color.
 /// </summary>
 /// <param name="image">The surface.</param>
 /// <param name="x">The X coordinate.</param>
 /// <param name="y">The Y coordinate.</param>
 protected virtual void DrawPixel(BCGSurface image, int x, int y)
 {
     DrawPixel(image, x, y, BCGBarcode.COLOR_FG);
 }
 /// <summary>
 /// Abstract method that draws the barcode on the surface.
 /// </summary>
 /// <param name="image">The surface.</param>
 public abstract void Draw(BCGSurface image);
Ejemplo n.º 15
0
 /// <summary>
 /// Sets the image resource.
 /// </summary>
 /// <param name="image">The surface.</param>
 public void SetImage(ref BCGSurface image)
 {
     this.im = image;
 }