Exemplo n.º 1
0
        public void RenderTest()
        {
            LtrParent.Styles.TextAlign = TextAlignment.Left;
            RtlParent.Styles.TextAlign = TextAlignment.Right;
            LtrParent.Size             = _resetSize;
            RtlParent.Size             = _resetSize;
            var ltrLine     = LtrParent.AddLine(new Line(_ltrStartPoint));
            var rtlLine     = RtlParent.AddLine(new Line(_rtlStartPoint));
            var lineCounter = 1;

            Assert.AreEqual(ltrLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(rtlLine.CurrentParagraph.Lines.Count, lineCounter);

            for (var i = 0; i < LtrWords.Count - 1; i++)
            {
                var ltrWord = LtrWords[i];
                var rtlWord = RtlWords[i];
                Debug.WriteLine($"Word {i}");

                ltrWord.SetFormattedText(_arial, _fontSize, 1, _lineHeight);
                rtlWord.SetFormattedText(_arial, _fontSize, 1, _lineHeight);
                ltrLine.AddWord(ltrWord);
                rtlLine.AddWord(rtlWord);
            }

            ltrLine.Build(false); // test after line rendering
            rtlLine.Build(false); // test after line rendering
            Assert.AreEqual(ltrLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(rtlLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.IsTrue(ltrLine.RemainWidth < 0);
            Assert.IsTrue(rtlLine.RemainWidth < 0);

            for (var i = 0; i < LtrWords.Count - 1; i++)
            {
                var ltrWord = LtrWords[i];
                var rtlWord = RtlWords[i];
                Debug.WriteLine($"Word {i}");

                Assert.IsTrue(ltrWord.DrawPoint.X > 0);
                Assert.IsTrue(rtlWord.DrawPoint.X < W);
                Assert.IsTrue(ltrWord.DrawPoint.Y > 0);
                Assert.IsTrue(rtlWord.DrawPoint.Y > 0);
                Assert.AreEqual(ltrWord.Area.Width, ltrWord.Width);
                Assert.AreEqual(rtlWord.Area.Width, rtlWord.Width);
            }

            while (rtlLine.RemainWidth < 1)
            {
                rtlLine.CurrentParagraph.Size = new Size(rtlLine.CurrentParagraph.Size.Width + 100, rtlLine.CurrentParagraph.Size.Height);
            }
            while (ltrLine.RemainWidth < 1)
            {
                ltrLine.CurrentParagraph.Size = new Size(ltrLine.CurrentParagraph.Size.Width + 100, ltrLine.CurrentParagraph.Size.Height);
            }

            // Test justify text-align
            ltrLine.Build(true);
            Assert.AreEqual(ltrLine.CurrentParagraph.Lines.Count, lineCounter);
            for (var i = 0; i < ltrLine.Words.Count - 1; i++)
            {
                var w = ltrLine.Words[i];
                Debug.WriteLine($"Justify LTR Word {i}");

                if (w is SpaceWord wSpace)
                {
                    Assert.IsTrue(wSpace.ExtraWidth > 0);
                }
            }
            rtlLine.Build(true);
            Assert.AreEqual(rtlLine.CurrentParagraph.Lines.Count, lineCounter);
            for (var i = 0; i < rtlLine.Words.Count - 1; i++)
            {
                var w = rtlLine.Words[i];
                Debug.WriteLine($"Justify RTL Word {i}");

                if (w is SpaceWord wSpace)
                {
                    Assert.IsTrue(wSpace.ExtraWidth > 0);
                }
            }
            //
            // Test center text-align
            LtrParent.Styles.TextAlign = TextAlignment.Center;
            RtlParent.Styles.TextAlign = TextAlignment.Center;
            ltrLine.Build(false);
            rtlLine.Build(false);
            Assert.AreEqual(ltrLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(rtlLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(ltrLine.Words.First().Area.Location.X, ltrLine.RemainWidth / 2 + _ltrStartPoint.X);
            Assert.AreEqual(rtlLine.Words.First().DrawPoint.X, _rtlStartPoint.X - rtlLine.RemainWidth / 2);
            //
            // Test left text-align
            LtrParent.Styles.TextAlign = TextAlignment.Left;
            RtlParent.Styles.TextAlign = TextAlignment.Left;
            ltrLine.Build(false);
            rtlLine.Build(false);
            Assert.AreEqual(ltrLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(rtlLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(ltrLine.Words.First().Area.Location.X, ltrLine.Location.X);
            // Assert.IsTrue(IsClose(Math.Abs(rtlLine.Words.Last().Area.Left), Math.Abs(rtlLine.RemainWidth - rtlLine.ActualWidth - rtlLine.Width + rtlLine.Location.X)));
            //
            // Test right text-align
            LtrParent.Styles.TextAlign = TextAlignment.Right;
            RtlParent.Styles.TextAlign = TextAlignment.Right;
            ltrLine.Build(false);
            rtlLine.Build(false);
            Assert.AreEqual(ltrLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(rtlLine.CurrentParagraph.Lines.Count, lineCounter);
            Assert.AreEqual(ltrLine.Words.First().Area.Location.X, ltrLine.RemainWidth + _ltrStartPoint.X);
            Assert.AreEqual(rtlLine.Words.First().DrawPoint.X, rtlLine.Location.X);
        }
Exemplo n.º 2
0
        public void AddWordTest()
        {
            LtrParent.Styles.TextAlign = TextAlignment.Left;
            RtlParent.Styles.TextAlign = TextAlignment.Right;
            LtrParent.Size             = _resetSize;
            RtlParent.Size             = _resetSize;
            var ltrLine = LtrParent.AddLine(new Line(_ltrStartPoint));
            var rtlLine = RtlParent.AddLine(new Line(_rtlStartPoint));

            Assert.AreEqual(ltrLine.Height, 0);
            Assert.AreEqual(rtlLine.Height, 0);
            Assert.AreEqual(ltrLine.RemainWidth, W);
            Assert.AreEqual(rtlLine.RemainWidth, W);

            for (var i = 0; i < LtrWords.Count; i++)
            {
                var ltrWord = LtrWords[i];
                var rtlWord = RtlWords[i];
                Debug.WriteLine($"Word {i}");

                ltrWord.SetFormattedText(_arial, _fontSize, 1, _lineHeight);
                rtlWord.SetFormattedText(_arial, _fontSize, 1, _lineHeight);
                if (ltrWord.IsImage || ltrWord.Type == WordType.Space)
                {
                    Assert.IsNull(ltrWord.Format);
                }
                else
                {
                    Assert.IsNotNull(ltrWord.Format);
                }


                if (rtlWord.IsImage || rtlWord.Type == WordType.Space)
                {
                    Assert.IsNull(rtlWord.Format);
                }
                else
                {
                    Assert.IsNotNull(rtlWord.Format);
                }
                Assert.IsTrue(ltrWord.Width > 0);
                Assert.IsTrue(rtlWord.Width > 0);
                ltrLine.AddWord(ltrWord);
                rtlLine.AddWord(rtlWord);
                //W -= ltrWord.Width;
                Assert.IsTrue(ltrLine.Height >= ltrWord.Height);                      // check change line height
                Assert.IsTrue(rtlLine.Height >= rtlWord.Height);                      // check change line height

                Assert.IsTrue(IsClose(ltrLine.RemainWidth, W - ltrLine.ActualWidth)); // check remain width
                Assert.IsTrue(ltrLine.Words.Contains(ltrWord));
                Assert.IsTrue(rtlLine.Words.Contains(rtlWord));

                if (LtrParent.Styles.IsRtl != ltrWord.Styles.IsRtl)
                {
                    Assert.AreEqual(ltrWord.DrawPoint.X, 0);
                    Assert.AreEqual(ltrWord.DrawPoint.Y, 0);
                }
                else
                {
                    Assert.IsTrue(ltrWord.DrawPoint.X > 0); // ltr
                    Assert.IsTrue(ltrWord.DrawPoint.Y > 0);

                    if (i > 0)
                    {
                        Assert.IsTrue(CompareTo(ltrWord.DrawPoint, LtrWords[i - 1].DrawPoint) > 0); // ltr
                    }
                }

                if (RtlParent.Styles.IsRtl != rtlWord.Styles.IsRtl)
                {
                    Assert.AreEqual(rtlWord.DrawPoint.X, 0);
                    Assert.AreEqual(rtlWord.DrawPoint.Y, 0);
                }
                else
                {
                    Assert.IsTrue(rtlWord.DrawPoint.X < W); // rtl
                    Assert.IsTrue(rtlWord.DrawPoint.Y > 0);

                    if (i > 0)
                    {
                        Assert.IsTrue(CompareTo(rtlWord.DrawPoint, RtlWords[i - 1].DrawPoint) <= 0); // rtl
                    }
                }

                if (i > 0)
                {
                    Assert.IsTrue(ltrWord.CompareTo(LtrWords[i - 1]) > 0);
                    Assert.IsTrue(rtlWord.CompareTo(RtlWords[i - 1]) > 0);
                }
            }

            Assert.AreEqual(ltrLine.Count, LtrWords.Count);
            Assert.AreEqual(rtlLine.Count, RtlWords.Count);
        }