Esempio n. 1
0
 private Metafile CreateMetafile()
 {
     // ouput size for QR bill only: 210 x 110mm
     bill.Format.OutputSize      = OutputSize.QrBillExtraSpace;
     using MetafileCanvas canvas = new MetafileCanvas(210, 110, "Arial");
     QRBill.Draw(bill, canvas);
     return(canvas.ToMetafile());
 }
Esempio n. 2
0
        public void ToMetafile_CorrectFrame()
        {
            Bill bill = SampleData.CreateExample6();

            bill.Format.OutputSize      = OutputSize.A4PortraitSheet;
            using MetafileCanvas canvas = new MetafileCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);
            using Metafile metafile = canvas.ToMetafile();
            var graphicsUnit = GraphicsUnit.Millimeter;
            // GetBounds() returns the metafile frame in pixels
            var bounds = metafile.GetBounds(ref graphicsUnit);

            Assert.Equal(GraphicsUnit.Pixel, graphicsUnit);

            // Since we've just created the metafile, pixel units will use the current dpi
            float dpi           = GetScreenDpi();
            float expectedWidth = (float)QRBill.A4PortraitWidth / 25.4f * dpi;

            Assert.InRange(bounds.Width, expectedWidth - 2, expectedWidth + 2);
            float expectedHeight = (float)QRBill.A4PortraitHeight / 25.4f * dpi;

            Assert.InRange(bounds.Height, expectedHeight - 2, expectedHeight + 2);
        }