public void FontVariantsShouldCorrectlySaveToRtf(FontVariantInfo info) { if (Platform.Instance.IsGtk) { Assert.Inconclusive("Gtk does not support RTF format"); } if (!info.IsFound) { Assert.Inconclusive("Font cannot be found on this system"); } var text = "This is some Font Variant text."; var richText = new RichTextArea(); richText.Text = text; Assert.AreEqual(text, richText.Text.TrimEnd(), "#1"); richText.Selection = GetRange(text, "Font Variant"); Assert.AreEqual("Font Variant", richText.SelectedText, "#2"); if (info.BaseTypeface != null) { // test base typeface (non-bold/italic) richText.SelectionTypeface = info.BaseTypeface; Assert.AreEqual(info.BaseTypeface.Name, richText.SelectionTypeface.Name, "#3.1"); Assert.AreEqual(info.BaseTypeface.Name, richText.SelectionFont.Typeface.Name, "#3.2"); } else { richText.SelectionTypeface = info.Typeface; } Assert.AreEqual(info.Family.Name, richText.SelectionFamily.Name, "#3.3"); Assert.AreEqual(info.Family.Name, richText.SelectionFont.FamilyName, "#3.4"); // setting these should not affect font name in RTF as it uses \b and \i to specify that if (info.WithBold) { richText.SelectionBold = true; } if (info.WithItalic) { richText.SelectionItalic = true; } // test it is using the right typeface Assert.AreEqual(info.Typeface.Name, richText.SelectionTypeface.Name, "#4.1"); Assert.AreEqual(info.Typeface.Name, richText.SelectionFont.Typeface.Name, "#4.2"); // ensure the generated RTF contains the correct font variant name var rtf = richText.Rtf; Console.WriteLine($"Generated RTF:"); Console.WriteLine(rtf); var reg = $@"(?<={{\\fonttbl.*)\\f\d+[^}};]* ({info.RegexFontName});"; Assert.IsTrue(Regex.IsMatch(rtf, reg), $"#5 - Variant '{info}' does not exist in RTF:\n{rtf}"); }
public void FontVariantsShouldCorrectlyLoadFromRtf(FontVariantInfo info) { if (Platform.Instance.IsGtk) { Assert.Inconclusive("Gtk does not support RTF format"); } if (!info.IsFound) { Assert.Inconclusive("Font cannot be found on this system"); } var text = "This is some Font Variant text."; var rtf = @"{\rtf1\ansi {\fonttbl\f0\fswiss\fcharset0 Arial;\f1\fswiss\fcharset0 " + info.RtfFontName + @";} {\f0\fs24 \cf0 This is some \f1" + info.RtfFlags + @" Font Variant \f0\b0 text.}}"; Console.WriteLine("Loading rtf"); Console.WriteLine(rtf); var richText = new RichTextArea(); richText.Rtf = rtf; Assert.AreEqual(text, richText.Text.TrimEnd(), "#1"); // select Font Variant text and ensure it is correctly set richText.Selection = GetRange(text, "Font Variant"); Assert.AreEqual("Font Variant", richText.SelectedText, "#2"); Assert.AreEqual(info.Family.Name, richText.SelectionFamily.Name, "#3.1"); Assert.AreEqual(info.Family.Name, richText.SelectionFont.FamilyName, "#3.2"); Assert.AreEqual(info.Typeface.Name, richText.SelectionTypeface.Name, "#3.3"); Assert.AreEqual(info.Typeface.Name, richText.SelectionFont.Typeface.Name, "#3.4"); }