예제 #1
0
        public void InkPen_CreateSections_AllGood()
        {
            var normalFont = new Font(FontFamily.GenericSansSerif, (Single)72.0, FontStyle.Regular);
            var boldFont   = new Font(FontFamily.GenericSansSerif, (Single)72.0, FontStyle.Bold);

            // Arrange
            var stbd = new SectionToBeDrawn();

            stbd.SectionParts.Add(new TextToBeDrawn()
            {
                Font = boldFont, LeftEdge = 0, TopEdge = 0, Text = "Some Title"
            });
            stbd.SectionParts.Add(new TextToBeDrawn()
            {
                Font = normalFont, LeftEdge = 0, TopEdge = 0, Text = "Some Text"
            });

            var pen = new InkPen();

            Image image          = new Bitmap(100, 100);
            var   drawingSurface = Graphics.FromImage(image);
            Brush brush          = new SolidBrush(Color.White);

            // Act
            pen.DrawSection(drawingSurface, brush, stbd);

            // Assert

            // Cleanup
            brush.Dispose();
            drawingSurface.Dispose();
        }
예제 #2
0
        public void TapeMeasure_DefineTextToBeDrawn_ShortTextWithPilcrow()
        {
            // Arrange
            var pageSize         = new SizeF(500, 2000);
            var startingLocation = new SizeF(0, 0);
            var shortText        = "Short Text";
            var pilcrow          = "¶";
            var text             = shortText + pilcrow;
            var font             = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold);

            var mockGraphics = new Mock <IGraphics>();
            var measure      = new TapeMeasure(mockGraphics.Object);

            mockGraphics.Setup(mock => mock.MeasureString(It.IsAny <String>(), It.IsAny <Font>())).Returns(new SizeF(100, 12));

            // Act
            SectionToBeDrawn section = measure.DefineTextToBeDrawn(pageSize, startingLocation, text, font);

            // Assert
            Assert.That(section.SectionParts.Count, Is.EqualTo(1), "Only one text block.");
            Assert.That(section.SectionParts[0].Text, Is.EqualTo(shortText), "Text should be short text.");
            Assert.That(section.SectionParts[0].Font, Is.EqualTo(font), "Font must be the same.");
            Assert.That(section.SectionParts[0].LeftEdge, Is.EqualTo(0), "Block should start at the left side of the page.");
            Assert.That(section.SectionParts[0].TopEdge, Is.EqualTo(0), "Block should start at the top of the page.");
            Assert.That(section.SectionParts[0].Width, Is.EqualTo(500), "Block should reach the end of page.");
            Assert.That(section.SectionParts[0].Height, Is.EqualTo(12), "Block should be one line high.");
        }
예제 #3
0
        public void TapeMeasure_DefineTextToBeDrawn_Pilcrow()
        {
            // We want a Pilcrow to represent a new-line/carriage-return
            // by taking up the remainder of the line (and not printing the pilcrow)

            // Arrange
            var pageSize         = new SizeF(500, 2000);
            var startingLocation = new SizeF(0, 0);
            var text             = "¶";
            var font             = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold);

            var mockGraphics = new Mock <IGraphics>();
            var measure      = new TapeMeasure(mockGraphics.Object);

            mockGraphics.Setup(mock => mock.MeasureString(It.IsAny <String>(), It.IsAny <Font>())).Returns(new SizeF(10, 12));

            // Act
            SectionToBeDrawn section = measure.DefineTextToBeDrawn(pageSize, startingLocation, text, font);

            // Assert
            Assert.That(section.SectionParts.Count, Is.EqualTo(1), "Only one text block.");
            Assert.That(section.SectionParts[0].Text, Is.EqualTo(""), "Text should be empty.");
            Assert.That(section.SectionParts[0].Font, Is.EqualTo(font), "Font must be the same.");
            Assert.That(section.SectionParts[0].LeftEdge, Is.EqualTo(0), "Block should start at the left side of the page.");
            Assert.That(section.SectionParts[0].TopEdge, Is.EqualTo(0), "Block should start at the top of the page.");
            Assert.That(section.SectionParts[0].Width, Is.EqualTo(500), "Block should reach the end of page.");
            Assert.That(section.SectionParts[0].Height, Is.EqualTo(12), "Block should be one line high.");
        }
예제 #4
0
        public void TapeMeasure_DefineTextToBeDrawn_LongText()
        {
            // Arrange
            var pageSize         = new SizeF(500, 2000);
            var startingLocation = new SizeF(0, 0);
            var text             = "Hello Elemental Purposeful Octopodes. Your activity is graceless but your results are without equal.";
            var font             = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold);

            var mockGraphics = new Mock <IGraphics>();
            var measure      = new TapeMeasure(mockGraphics.Object);

            mockGraphics.SetupSequence(mock => mock.MeasureString(It.IsAny <String>(), It.IsAny <Font>()))
            .Returns(new SizeF(50, 12))
            .Returns(new SizeF(160, 12))
            .Returns(new SizeF(260, 12))
            .Returns(new SizeF(370, 12))
            .Returns(new SizeF(420, 12))
            .Returns(new SizeF(510, 12))
            .Returns(new SizeF(420, 12))
            .Returns(new SizeF(80, 12))
            .Returns(new SizeF(110, 12))
            .Returns(new SizeF(210, 12))
            .Returns(new SizeF(250, 12))
            .Returns(new SizeF(300, 12))
            .Returns(new SizeF(380, 12))
            .Returns(new SizeF(420, 12))
            .Returns(new SizeF(500, 12))
            .Returns(new SizeF(570, 12))
            .Returns(new SizeF(500, 12))
            .Returns(new SizeF(60, 12));

            // Act
            SectionToBeDrawn section = measure.DefineTextToBeDrawn(pageSize, startingLocation, text, font);

            // Assert
            Assert.That(section.SectionParts.Count, Is.EqualTo(3), "There should be three text blocks.");
            Assert.That(section.SectionParts[0].Text, Is.EqualTo("Hello Elemental Purposeful Octopodes. Your"), "Text should be 'Hello Elemental Purposeful Octopodes. Your'.");
            Assert.That(section.SectionParts[0].Font, Is.EqualTo(font), "Font must be the same.");
            Assert.That(section.SectionParts[0].LeftEdge, Is.EqualTo(0), "Block should start at the left side of the page.");
            Assert.That(section.SectionParts[0].TopEdge, Is.EqualTo(0), "Block should start at the top of the page.");
            Assert.That(section.SectionParts[0].Width, Is.EqualTo(420), "Block should be width 420.");
            Assert.That(section.SectionParts[0].Height, Is.EqualTo(12), "Block should be one line high.");
            Assert.That(section.SectionParts[1].Text, Is.EqualTo("activity is graceless but your results are without"), "Text should be 'activity is graceless but your results are without'.");
            Assert.That(section.SectionParts[1].Font, Is.EqualTo(font), "Font must be the same.");
            Assert.That(section.SectionParts[1].LeftEdge, Is.EqualTo(0), "Block should start at the left side of the page.");
            Assert.That(section.SectionParts[1].TopEdge, Is.EqualTo(12), "Block should start one line down .");
            Assert.That(section.SectionParts[1].Width, Is.EqualTo(500), "Block should be 500 wide.");
            Assert.That(section.SectionParts[1].Height, Is.EqualTo(12), "Block should be one line high.");
            Assert.That(section.SectionParts[2].Text, Is.EqualTo("equal."), "Text should be 'equal'.");
            Assert.That(section.SectionParts[2].Font, Is.EqualTo(font), "Font must be the same.");
            Assert.That(section.SectionParts[2].LeftEdge, Is.EqualTo(0), "Block should start at the left side of the page.");
            Assert.That(section.SectionParts[2].TopEdge, Is.EqualTo(24), "Block should start two lines down.");
            Assert.That(section.SectionParts[2].Width, Is.EqualTo(60), "Block should be width 60.");
            Assert.That(section.SectionParts[2].Height, Is.EqualTo(12), "Block should be one line high.");
        }
예제 #5
0
        public void SectionToBeDrawn_Constructor_Empty()
        {
            // Arrange

            // Act
            var stbd = new SectionToBeDrawn();

            // Assert
            Assert.That(stbd, Is.Not.Null, "Empty constructor should still construct");
            Assert.That(stbd.SectionParts.Count, Is.EqualTo(0), "Empty constructor should still construct");
        }
예제 #6
0
        public void TapeMeasure_DefineTextToBeDrawn_EmptyText()
        {
            // We want an empty string to be effectively ignored

            // Arrange
            var pageSize         = new SizeF(500, 2000);
            var startingLocation = new SizeF(0, 0);
            var text             = "";
            var font             = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold);

            var mockGraphics = new Mock <IGraphics>();
            var measure      = new TapeMeasure(mockGraphics.Object);

            // Act
            SectionToBeDrawn section = measure.DefineTextToBeDrawn(pageSize, startingLocation, text, font);

            // Assert
            Assert.That(section.SectionParts.Count, Is.EqualTo(0), "No text blocks.");
        }