-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store rich text as an immutable rich text through a new type XLImmuta…
…bleRichText. The XLRichText transparently updates immutable rich text, whenever it changes (run, pohonetic runs or phonetic properties). This is required for shared string table, because items stored in a reverse dictionary must be immutable.
- Loading branch information
Showing
20 changed files
with
834 additions
and
188 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
ClosedXML.Tests/Excel/RichText/XLImmutableRichTextTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Linq; | ||
using ClosedXML.Excel; | ||
using NUnit.Framework; | ||
|
||
namespace ClosedXML.Tests.Excel.RichText | ||
{ | ||
[TestFixture] | ||
public class XLImmutableRichTextTests | ||
{ | ||
[Test] | ||
public void Equals_compares_text_runs_phonetic_runs_and_properties() | ||
{ | ||
using var wb = new XLWorkbook(); | ||
var ws = wb.AddWorksheet(); | ||
var richText = (XLRichText)ws.Cell("A1").CreateRichText(); | ||
richText | ||
.AddText("こんにち").SetBold(true) // Hello in hiragana | ||
.AddText("は,").SetBold(false) // object marker | ||
.AddText("世界").SetFontSize(15); // world in kanji | ||
richText.Phonetics | ||
.SetAlignment(XLPhoneticAlignment.Distributed) | ||
.Add(@"konnichi wa", 0, 6); // world in hiragana | ||
|
||
// Assert equal | ||
var immutableRichText = new XLImmutableRichText(richText); | ||
var equalImmutableRichText = new XLImmutableRichText(richText); | ||
Assert.AreEqual(immutableRichText, equalImmutableRichText); | ||
|
||
// Different font of a first run | ||
richText.ElementAt(0).SetBold(false); | ||
var withDifferentTextRunFont = new XLImmutableRichText(richText); | ||
Assert.AreNotEqual(immutableRichText, withDifferentTextRunFont); | ||
richText.ElementAt(0).SetBold(true); | ||
|
||
// Different phonetic properties | ||
richText.Phonetics.SetAlignment(XLPhoneticAlignment.Left); | ||
var withDifferentPhoneticsProps = new XLImmutableRichText(richText); | ||
Assert.AreNotEqual(immutableRichText, withDifferentPhoneticsProps); | ||
richText.Phonetics.SetAlignment(XLPhoneticAlignment.Distributed); | ||
|
||
// Different phonetic runs | ||
richText.Phonetics.Add("せかい", 6, 8); | ||
var withDifferentTextPhonetics = new XLImmutableRichText(richText); | ||
Assert.AreNotEqual(immutableRichText, withDifferentTextPhonetics); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
#nullable disable | ||
|
||
using System; | ||
|
||
namespace ClosedXML.Excel | ||
{ | ||
public interface IXLPhonetic: IEquatable<IXLPhonetic> | ||
{ | ||
String Text { get; set; } | ||
Int32 Start { get; set; } | ||
Int32 End { get; set; } | ||
String Text { get; } | ||
Int32 Start { get; } | ||
Int32 End { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#nullable disable | ||
|
||
namespace ClosedXML.Excel | ||
{ | ||
public interface IXLRichText : IXLFormattedText<IXLRichText> | ||
|
Oops, something went wrong.