예제 #1
0
        public void PrintNodes_LineAbsolute_LinePrinted()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><line absFromX=\"10\" absFromY=\"20\" absToX=\"30\" absToY=\"40\" /></root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();
            sut.CursorX = 12;
            sut.CursorY = 14;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            using (new AssertionScope())
            {
                graphics.Received(1).DrawLine(
                    Arg.Any <Pen>(),
                    39,   // 10*(100/25.4)
                    79,   // 20*(100/25.4)
                    118,  // 30*(100/25.4)
                    157); // 40*(100/25.4)
            }

            sut.CleanupGraphics();
        }
예제 #2
0
        public void PrintAB(DataTable dt, string printerConnection)
        {
            string destinationDevice     = printerConnection;
            string templateFilename      = "D:\\AB0801-04.prn";
            string defaultQuantityString = "1";
            bool   verbose = true;

            try
            {
                foreach (DataRow row in dt.Rows)
                {
                    using (MemoryStream outputDataStream = new MemoryStream())
                    {
                        string serialNumber = row["serialNumber"].ToString();
                        string week         = row["week"].ToString();
                        string customerPart = row["customerPart"].ToString();
                        string direction    = row["direction"].ToString();
                        string qrCode       = row["qrCode"].ToString();

                        using (Stream sourceStream = XmlData(customerPart, qrCode, serialNumber, week, direction))
                        {
                            XmlPrinter.Print(destinationDevice, sourceStream, templateFilename, defaultQuantityString, outputDataStream, verbose);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        public void TransformDocument_TableStartAtBottom_NewPageBeforeTable()
        {
            var sut = new XmlPrinter {
                DocumentHeight = 20
            };

            sut.LoadXml(
                "<root>"
                + "<move relY=\"15\" />"
                + "<table><columns>"
                + "<column width=\"10\">C1</column>"
                + "</columns><data>"
                + "<tr><td>1</td></tr>"
                + "<tr><td>2</td></tr>"
                + "</data></table>"
                + "</root>");

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            XDocument.Parse(sut.Document.OuterXml).Should().BeEquivalentTo(
                XDocument.Parse(
                    "<root>"
                    + "<move relY=\"15\" />"
                    + "<newPage />"
                    + "<text relX=\"0\">C1</text>"
                    + "<move relY=\"4\" />"
                    + "<text relX=\"0\">1</text>"
                    + "<move relY=\"4\" />"
                    + "<text relX=\"0\">2</text>"
                    + "<move relY=\"4\" />"
                    + "</root>"));
        }
예제 #4
0
        public void PrintNodes_LineRelative_LinePrinted()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><line relFromX=\"10\" relFromY=\"20\" relToX=\"30\" relToY=\"40\" /></root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();
            sut.CursorX = 12;
            sut.CursorY = 14;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            using (new AssertionScope())
            {
                graphics.Received(1).DrawLine(
                    Arg.Any <Pen>(),
                    87,   // 22*(100/25.4)
                    134,  // 34*(100/25.4)
                    165,  // 52*(100/25.4)
                    213); // 74*(100/25.4)
            }

            sut.CleanupGraphics();
        }
예제 #5
0
        public void TransformDocument_TableTopLine_ConvertedToTexts()
        {
            var sut = new XmlPrinter {
                DocumentHeight = 100
            };

            sut.LoadXml(
                "<root>"
                + "<table><columns>"
                + "<column width=\"10\" topLine=\"true\">C1</column>"
                + "<column width=\"20\">C2</column>"
                + "</columns><data>"
                + "<tr><td>1</td><td>2</td></tr>"
                + "</data></table>"
                + "</root>");

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            XDocument.Parse(sut.Document.OuterXml).Should().BeEquivalentTo(
                XDocument.Parse(
                    "<root>"
                    + "<line relToX=\"10\" />"
                    + "<text relX=\"0\">C1</text>"
                    + "<text relX=\"10\">C2</text>"
                    + "<move relY=\"4\" />"
                    + "<line relToX=\"10\" />"
                    + "<text relX=\"0\">1</text>"
                    + "<text relX=\"10\">2</text>"
                    + "<move relY=\"4\" />"
                    + "</root>"));
        }
예제 #6
0
        public void PrintNodes_TextRelative_TextPrinted()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><text relX=\"10\" relY=\"20\" align=\"center\">The text.</text></root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            graphics.Received(1).DrawString(
                "The text.",
                Arg.Any <Font>(),
                Arg.Any <Brush>(),
                59,  // 15*(100/25.4)
                110, // 28*(100/25.4)
                StringAlignment.Center);

            sut.CleanupGraphics();
        }
예제 #7
0
        public void PrintNodes_TextRight_TextPrintedAtCursor()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><text align=\"right\">The text.</text></root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            graphics.Received(1).DrawString(
                "The text.",
                Arg.Any <Font>(),
                Arg.Any <Brush>(),
                20, // 5*(100/25.4)
                31, // 8*(100/25.4)
                StringAlignment.Far);

            sut.CleanupGraphics();
        }
예제 #8
0
        public void PrintNodes_TextAbsolute_TextPrintedCursorUnchanged()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><text absX=\"10\" absY=\"20\">The text.</text></root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            using (new AssertionScope())
            {
                graphics.Received(1).DrawString(
                    "The text.",
                    Arg.Any <Font>(),
                    Arg.Any <Brush>(),
                    39, // 10*(100/25.4)
                    79, // 20*(100/25.4)
                    StringAlignment.Near);
                sut.CursorX.Should().Be(5);
                sut.CursorY.Should().Be(8);
            }

            sut.CleanupGraphics();
        }
예제 #9
0
        public void LoadDocument_UnknownReport_Throws()
        {
            var sut = new XmlPrinter();

            sut.Invoking(x => x.LoadDocument("XXX")).Should().Throw <ArgumentException>()
            .WithMessage("*XXX*");
        }
예제 #10
0
        public void PrintAH1501_05(DataTable dt, string printerConnection)
        {
            string destinationDevice     = printerConnection;
            string templateFilename      = "D:\\AH1501-05.prn";
            string defaultQuantityString = "1";
            bool   verbose = true;

            try
            {
                foreach (DataRow row in dt.Rows)
                {
                    using (MemoryStream outputDataStream = new MemoryStream())
                    {
                        using (Stream sourceStream = XmlData(dt))
                        {
                            XmlPrinter.Print(destinationDevice, sourceStream, templateFilename, defaultQuantityString, outputDataStream, verbose);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #11
0
        public void ParseToXml(TextWriter output)
        {
            var parser = parserSource();

            using (var printer = new XmlPrinter(output))
            {
                parser.AddParseListener(printer);
                parser.chunk();
            }
        }
예제 #12
0
        public void SetupDocument_Custom_DocumentInitialized()
        {
            var sut      = new XmlPrinter();
            var document = new PrintDocument();

            sut.LoadXml("<root paperSize=\"custom\" width=\"10\" height=\"20\" />");

            sut.SetupDocument(document, PaperSizes);

            using (new AssertionScope())
            {
                sut.DocumentWidth.Should().Be(10);
                sut.DocumentHeight.Should().Be(20);
            }
        }
예제 #13
0
        public void SetupDocument_A4Landscape_DocumentInitialized()
        {
            var sut      = new XmlPrinter();
            var document = new PrintDocument();

            sut.LoadXml("<root paperSize=\"A4\" landscape=\"true\" />");

            sut.SetupDocument(document, PaperSizes);

            using (new AssertionScope())
            {
                sut.DocumentWidth.Should().Be(297);
                sut.DocumentHeight.Should().Be(210);
            }
        }
예제 #14
0
        public void SetupDocument_Margins_DocumentInitialized()
        {
            var sut      = new XmlPrinter();
            var document = new PrintDocument();

            sut.LoadXml("<root left=\"1\" top=\"2\" bottom=\"3\" />");

            sut.SetupDocument(document, PaperSizes);

            using (new AssertionScope())
            {
                sut.DocumentLeftMargin.Should().Be(1);
                sut.DocumentTopMargin.Should().Be(2);
                sut.DocumentBottomMargin.Should().Be(3);
            }
        }
예제 #15
0
        public void PrintNodes_NewPage_MorePagesRequested()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><move absX=\"10\" absY=\"20\" /><newPage /></root>");
            sut.SetupGraphics();
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            graphics.HasMorePages.Should().BeTrue();

            sut.CleanupGraphics();
        }
예제 #16
0
        public void TransformDocument_MoveRelativeOnly_CursorUpdated()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><move relX=\"10\" relY=\"20\" /></root>");
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            using (new AssertionScope())
            {
                sut.CursorX.Should().Be(15);
                sut.CursorY.Should().Be(28);
            }
        }
예제 #17
0
        public void TransformDocument_MoveAbsolute_CursorUpdated()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><move absX=\"10\" absY=\"20\" /></root>");
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            using (new AssertionScope())
            {
                sut.CursorX.Should().Be(10);
                sut.CursorY.Should().Be(20);
            }
        }
예제 #18
0
        public void TransformDocument_Rectangle_ConvertedToLines()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><rectangle relFromX=\"10\" relFromY=\"20\" relToX=\"30\" relToY=\"40\" /></root>");

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            XDocument.Parse(sut.Document.OuterXml).Should().BeEquivalentTo(
                XDocument.Parse(
                    "<root>"
                    + "<line relFromX=\"10\" relFromY=\"20\" relToX=\"30\" relToY=\"20\" />"
                    + "<line relFromX=\"30\" relFromY=\"20\" relToX=\"30\" relToY=\"40\" />"
                    + "<line relFromX=\"30\" relFromY=\"40\" relToX=\"10\" relToY=\"40\" />"
                    + "<line relFromX=\"10\" relFromY=\"40\" relToX=\"10\" relToY=\"20\" />"
                    + "</root>"));
        }
예제 #19
0
        public void TransformDocument_NewPage_CursorReset()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><move absX=\"10\" absY=\"20\" relX=\"3\" relY=\"4\" /><newPage/></root>");

            // initialize cursor with irrelevant values
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            using (new AssertionScope())
            {
                sut.CursorX.Should().Be(0);
                sut.CursorY.Should().Be(0);
            }
        }
예제 #20
0
        private static void Printing(Stream xmlData, string templatePath)
        {
            string destinationDevice     = GetUSBConnection();
            string templateFilename      = templatePath;
            string defaultQuantityString = "1";
            bool   verbose = true;

            try
            {
                using (MemoryStream outputDataStream = new MemoryStream())
                {
                    using (Stream sourceStream = xmlData)
                    {
                        XmlPrinter.Print(destinationDevice, sourceStream, templateFilename, defaultQuantityString, outputDataStream, verbose);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #21
0
        public void PrintNodes_Move_CursorUpdated()
        {
            var sut = new XmlPrinter();

            sut.LoadXml("<root><move absX=\"10\" absY=\"20\" /></root>");
            sut.SetupGraphics();
            sut.CursorX = 5;
            sut.CursorY = 8;

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            using (new AssertionScope())
            {
                graphics.HasMorePages.Should().BeFalse();
                sut.CursorX.Should().Be(10);
                sut.CursorY.Should().Be(20);
            }

            sut.CleanupGraphics();
        }
예제 #22
0
        public void PrintNodes_TextWithFontChange_TextPrintedWithFont()
        {
            var sut = new XmlPrinter();

            sut.LoadXml(
                "<root>" +
                "<text>text1</text>" +
                "<font size=\"20\" />" +
                "<text>text2</text>" +
                "</root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            graphics.Received(1).DrawString(
                "text1",
                Arg.Is <Font>(x => Math.Abs(x.SizeInPoints - 10) < 0.1),
                Arg.Any <Brush>(),
                Arg.Any <float>(),
                Arg.Any <float>(),
                Arg.Any <StringAlignment>());
            graphics.Received(1).DrawString(
                "text2",
                Arg.Is <Font>(x => Math.Abs(x.SizeInPoints - 20) < 0.1),
                Arg.Any <Brush>(),
                Arg.Any <float>(),
                Arg.Any <float>(),
                Arg.Any <StringAlignment>());

            sut.CleanupGraphics();
        }
예제 #23
0
        public static void Main(string[] args)
        {
            var data = "Hello World !";
            AbstractMediator abstractMediator = new Mediator.Mediator();

            AbstractPrinter textPrinter = new TextPrinter(abstractMediator);
            AbstractPrinter xmlPrinter  = new XmlPrinter(abstractMediator);
            AbstractPrinter htmlPrinter = new HtmlPrinter(abstractMediator);

            abstractMediator.Register(textPrinter);
            abstractMediator.Register(xmlPrinter);
            abstractMediator.Register(htmlPrinter);

            Console.WriteLine("Text Printer talking ......\n");
            textPrinter.Print(data, textPrinter.PrinterType);
            textPrinter.PrintToOtherFormat(data, xmlPrinter.PrinterType, textPrinter.PrinterType);

            Console.WriteLine("\nText Printer talking ......\n");
            xmlPrinter.Print(data, xmlPrinter.PrinterType);
            xmlPrinter.PrintToOtherFormat(data, textPrinter.PrinterType, xmlPrinter.PrinterType);

            Console.WriteLine("\nText Printer talking ......\n");
            htmlPrinter.PrintToOtherFormat(data, xmlPrinter.PrinterType, htmlPrinter.PrinterType);
        }
예제 #24
0
        public void PrintNodes_TextWithFontStack_TextPrintedWithFont()
        {
            var sut = new XmlPrinter();

            sut.LoadXml(
                "<root>" +
                "<text>text1</text>" +
                "<font bold=\"1\"><text>text2</text></font>" +
                "</root>");
            // TODO SetupDocument is required for print factor only
            var document = new PrintDocument();

            sut.SetupDocument(document, PaperSizes);
            sut.SetupGraphics();

            var graphics = Substitute.For <IGraphics>();

            sut.PrintNodes(graphics);

            graphics.Received(1).DrawString(
                "text1",
                Arg.Is <Font>(x => x.Style == FontStyle.Regular),
                Arg.Any <Brush>(),
                Arg.Any <float>(),
                Arg.Any <float>(),
                Arg.Any <StringAlignment>());
            graphics.Received(1).DrawString(
                "text2",
                Arg.Is <Font>(x => x.Style == FontStyle.Bold),
                Arg.Any <Brush>(),
                Arg.Any <float>(),
                Arg.Any <float>(),
                Arg.Any <StringAlignment>());

            sut.CleanupGraphics();
        }
예제 #25
0
        public void TransformDocument_PageTexts_ConvertedToLines()
        {
            var sut = new XmlPrinter {
                DocumentHeight = 10
            };

            sut.LoadXml(
                "<root>"
                + "<pageTexts><font><text>page {pageNumber}</text></font></pageTexts>"
                + "<table><columns>"
                + "<column width=\"10\">C1</column>"
                + "</columns><data>"
                + "<tr><td>1</td></tr>"
                + "<tr><td>2</td></tr>"
                + "</data></table>"
                + "</root>");

            var graphics = Substitute.For <IGraphics>();

            sut.TransformDocument(graphics);

            XDocument.Parse(sut.Document.OuterXml).Should().BeEquivalentTo(
                XDocument.Parse(
                    "<root>"
                    + "<font><text>page 1</text></font>"
                    + "<text relX=\"0\">C1</text>"
                    + "<move relY=\"4\" />"
                    + "<text relX=\"0\">1</text>"
                    + "<newPage />"
                    + "<font><text>page 2</text></font>"
                    + "<text relX=\"0\">C1</text>"
                    + "<move relY=\"4\" />"
                    + "<text relX=\"0\">2</text>"
                    + "<move relY=\"4\" />"
                    + "</root>"));
        }
예제 #26
0
        public void LoadDocument_AccountJournalReport_Loaded()
        {
            var sut = new XmlPrinter();

            sut.Invoking(x => x.LoadDocument(AccountJournalReport.ResourceName)).Should().NotThrow();
        }
예제 #27
0
        public void LoadDocument_TotalsAndBalancesReport_Loaded()
        {
            var sut = new XmlPrinter();

            sut.Invoking(x => x.LoadDocument(TotalsAndBalancesReport.ResourceName)).Should().NotThrow();
        }