Exemplo n.º 1
0
        private static ICanvas CreateCanvas(BillFormat format)
        {
            double drawingWidth;
            double drawingHeight;

            // define page size
            switch (format.OutputSize)
            {
            case OutputSize.QrBillOnly:
                drawingWidth  = QrBillWidth;
                drawingHeight = QrBillHeight;
                break;

            case OutputSize.QrBillExtraSpace:
                drawingWidth  = QrBillWithHoriLineWidth;
                drawingHeight = QrBillWithHoriLineHeight;
                break;

            case OutputSize.QrCodeOnly:
                drawingWidth  = QrCodeWidth;
                drawingHeight = QrCodeHeight;
                break;

            default:
                drawingWidth  = A4PortraitWidth;
                drawingHeight = A4PortraitHeight;
                break;
            }

            var canvas = CanvasCreator.Create(format, drawingWidth, drawingHeight);

            if (canvas != null)
            {
                return(canvas);
            }

            if (format.GraphicsFormat == GraphicsFormat.PNG)
            {
                // The PNG canvas factory is provided by a separate assembly / NuGet package.
                // Try to load the factory dynamically, and if it still fails, print a message with specific hint.
                CanvasCreator.RegisterPixelCanvasFactory();
                canvas = CanvasCreator.Create(format, drawingWidth, drawingHeight);
                if (canvas == null)
                {
                    throw new QRBillGenerationException("Graphics format PNG not available (are you missing the NuGet package Codecrete.SwissQRBill.Generator?)");
                }
            }
            else
            {
                throw new QRBillGenerationException("Invalid graphics format specified");
            }

            return(canvas);
        }
Exemplo n.º 2
0
        private static ICanvas CreateCanvas(BillFormat format)
        {
            double drawingWidth;
            double drawingHeight;

            // define page size
            switch (format.OutputSize)
            {
            case OutputSize.QrBillOnly:
                drawingWidth  = QrBillWidth;
                drawingHeight = QrBillHeight;
                break;

            case OutputSize.QrBillExtraSpace:
#pragma warning disable CS0618 // Type or member is obsolete
            case OutputSize.QrBillWithHorizontalLine:
#pragma warning restore CS0618 // Type or member is obsolete
                drawingWidth  = QrBillWithHoriLineWidth;
                drawingHeight = QrBillWithHoriLineHeight;
                break;

            case OutputSize.QrCodeOnly:
                drawingWidth  = QrCodeWidth;
                drawingHeight = QrCodeHeight;
                break;

            default:
                drawingWidth  = A4PortraitWidth;
                drawingHeight = A4PortraitHeight;
                break;
            }

            ICanvas canvas;
            switch (format.GraphicsFormat)
            {
            case GraphicsFormat.SVG:
                canvas = new SVGCanvas(drawingWidth, drawingHeight, format.FontFamily);
                break;

            case GraphicsFormat.PNG:
                canvas = new PNGCanvas(drawingWidth, drawingHeight, format.Resolution, format.FontFamily);
                break;

            case GraphicsFormat.PDF:
                canvas = new PDFCanvas(drawingWidth, drawingHeight);
                break;

            default:
                throw new QRBillGenerationException("Invalid graphics format specified");
            }
            return(canvas);
        }
Exemplo n.º 3
0
        private static ICanvas CreateCanvas(BillFormat format)
        {
            double drawingWidth;
            double drawingHeight;

            // define page size
            switch (format.OutputSize)
            {
            case OutputSize.QrBillOnly:
                drawingWidth  = QrBillWidth;
                drawingHeight = QrBillHeight;
                break;

            case OutputSize.QrBillWithHorizontalLine:
                drawingWidth  = QrBillWithHoriLineWidth;
                drawingHeight = QrBillWithHoriLineHeight;
                break;

            case OutputSize.QrCodeOnly:
                drawingWidth  = QrCodeWidth;
                drawingHeight = QrCodeHeight;
                break;

            default:
                drawingWidth  = A4PortraitWidth;
                drawingHeight = A4PortraitHeight;
                break;
            }

            ICanvas canvas;

            switch (format.GraphicsFormat)
            {
            case GraphicsFormat.SVG:
                canvas = new SVGCanvas(drawingWidth, drawingHeight, format.FontFamily);
                break;

            case GraphicsFormat.PDF:
                canvas = new PDFCanvas(drawingWidth, drawingHeight);
                break;

            default:
                throw new QRBillGenerationException("Invalid graphics format specified");
            }
            return(canvas);
        }