Exemplo n.º 1
0
        public void BasicProps()
        {
            AssembledStyles astyles       = new AssembledStyles();
            var             changedStyles = new HashSet <AssembledStyles>();

            changedStyles.Add(astyles);
            TestDeriverEffect(astyles, "<default font>", "Times New Roman", "Arial", (styles) => styles.FaceName,
                              (styles, val) => styles.WithFaceName(val), "font face", changedStyles);
            TestDeriverEffect(astyles, (int)VwFontWeight.kvfwNormal, 700, 200, (styles) => styles.FontWeight,
                              (styles, val) => styles.WithFontWeight(val), "weight", changedStyles);
            TestDeriverEffect(astyles, 0, 1, 2, (styles) => styles.Ws, (styles, val) => styles.WithWs(val), "Ws", changedStyles);
            TestDeriverEffect(astyles, 10000, 12000, 24000, (styles) => styles.FontSize,
                              (styles, val) => styles.WithFontSize(val), "Font Height", changedStyles);
            TestDeriverEffect(astyles, 0, 10000, 2000, (styles) => styles.BaselineOffset,
                              (styles, val) => styles.WithBaselineOffset(val), "Baseline Offset", changedStyles);
            TestDeriverEffect(astyles, 0, 10000, 20000, (styles) => styles.LineHeight,
                              (styles, val) => styles.WithLineHeight(val), "Line Spacing", changedStyles);
            TestDeriverEffect(astyles, FwUnderlineType.kuntNone, FwUnderlineType.kuntSingle, FwUnderlineType.kuntSquiggle,
                              (styles) => styles.Underline,
                              (styles, val) => styles.WithUnderline(val), "Underline", changedStyles);
            TestDeriverEffect(astyles, Color.Black.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(),
                              (styles => styles.ForeColor.ToArgb()),
                              (styles, val) => styles.WithForeColor(Color.FromArgb(val)), "foreground color", changedStyles);
            TestDeriverEffect(astyles, Color.Transparent.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(),
                              (styles => styles.BackColor.ToArgb()),
                              (styles, val) => styles.WithBackColor(Color.FromArgb(val)), "background color", changedStyles);
            TestDeriverEffect(astyles, Color.Black.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(),
                              (styles => styles.UnderlineColor.ToArgb()),
                              (styles, val) => styles.WithUnderlineColor(Color.FromArgb(val)), "underline color", changedStyles);
            TestDeriverEffect(astyles, Color.Black.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(),
                              (styles => styles.BorderColor.ToArgb()),
                              (styles, val) => styles.WithBorderColor(Color.FromArgb(val)), "border color", changedStyles);
            TestDeriverEffect(astyles, Thickness.Default, new Thickness(1.0), new Thickness(2.0),
                              styles => styles.Margins, (styles, val) => styles.WithMargins(val), "margins", changedStyles);
            TestDeriverEffect(astyles, Thickness.Default, new Thickness(1.0), new Thickness(2.0),
                              styles => styles.Pads, (styles, val) => styles.WithPads(val), "pads", changedStyles);
            TestDeriverEffect(astyles, Thickness.Default, new Thickness(1.0), new Thickness(2.0),
                              styles => styles.Borders, (styles, val) => styles.WithBorders(val), "borders", changedStyles);
            TestDeriverEffect(astyles, false, true, false,
                              styles => styles.RightToLeft, (styles, val) => styles.WithRightToLeft(val), "right to left", changedStyles);
            // Todo: many other properties, including using Thickness to implement Border, Margin, and Padding.

            // Italic is special because of handling invert, also because only two values are possible for the result.
            Assert.That(astyles.FontItalic, Is.False, "default italics");
            var derived = astyles.WithFontItalic(FwTextToggleVal.kttvForceOn);

            Assert.That(derived.FontItalic, Is.True);
            var derived2 = astyles.WithFontItalic(FwTextToggleVal.kttvInvert);

            Assert.That(derived2.FontItalic, Is.True);
            var derived3 = derived.WithFontItalic(FwTextToggleVal.kttvInvert);

            Assert.That(derived3.FontItalic, Is.False);
            Assert.That(ReferenceEquals(derived, derived2), Is.True);
            Assert.That(ReferenceEquals(astyles, derived3), Is.True);
            int oldCount = changedStyles.Count;

            changedStyles.Add(derived2);
            Assert.That(changedStyles.Count, Is.EqualTo(oldCount + 1), "italic styles not equal to any other");

            // Check the conversion of colors.
            var colored = astyles.WithForeColor(Color.Red).WithBackColor(Color.Yellow).WithUnderlineColor(Color.Green);
            var chrp    = colored.Chrp;

            Assert.That(chrp.clrFore, Is.EqualTo(ColorUtil.ConvertColorToBGR(Color.Red)));
            Assert.That(chrp.clrBack, Is.EqualTo(ColorUtil.ConvertColorToBGR(Color.Yellow)));
            Assert.That(chrp.clrUnder, Is.EqualTo(ColorUtil.ConvertColorToBGR(Color.Green)));

            // Check the special deriver for FontBold
            var bold = astyles.WithFontBold(FwTextToggleVal.kttvForceOn);

            Assert.That(bold.Chrp.ttvBold, Is.EqualTo((int)FwTextToggleVal.kttvForceOn));
            Assert.That(bold.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold));
            var normal = bold.WithFontBold(FwTextToggleVal.kttvInvert);

            Assert.That(normal.Chrp.ttvBold, Is.EqualTo((int)FwTextToggleVal.kttvOff));
            Assert.That(normal.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwNormal));
            Assert.That(normal, Is.EqualTo(astyles));
            Assert.That(astyles.WithFontBold(FwTextToggleVal.kttvInvert), Is.EqualTo(bold));
        }