Skip to content

Commit

Permalink
Implement IsHidden property
Browse files Browse the repository at this point in the history
  • Loading branch information
y0ung3r committed Apr 26, 2024
1 parent 7442028 commit 6815565
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Implementation Dashboard
- [ ] Borders
- [ ] Background Color
- [ ] Shading
- [ ] Outline
- [ ] Styles
- [x] Keep lines
- [x] Keep next
Expand All @@ -76,7 +75,7 @@ Implementation Dashboard
- [x] Bold
- [ ] Outline
- [x] Strikethrough
- [ ] Hidden
- [x] Hidden
- [ ] Background color
- [ ] Text color
- [ ] Borders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text;
public sealed class RunFormat : IVisitable
{
public static RunFormat Default
=> new()
{
IsItalic = false,
IsBold = false,
StrikethroughType = StrikethroughType.None
};
=> new();

public bool IsItalic { get; set; }

public bool IsBold { get; set; }

public bool IsHidden { get; set; }

public StrikethroughType StrikethroughType { get; set; }
= StrikethroughType.None;

/// <inheritdoc />
public void Accept(IWordVisitor visitor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ public void Should_read_bold_properly()
.BeTrue();
}

[Fact]
public void Should_read_hidden_properly()
{
// Arrange
var xml = new XElement(OpenXmlNamespaces.Word + "rPr",
new XElement(OpenXmlNamespaces.Word + "vanish"));

var runFormat = new RunFormat();
var sut = new OpenXmlElementReader(xml);

// Act
sut.Visit(runFormat);

// Assert
runFormat
.IsHidden
.Should()
.BeTrue();
}

[Theory]
[InlineData("strike", StrikethroughType.Single)]
[InlineData("dstrike", StrikethroughType.Double)]
Expand Down Expand Up @@ -92,6 +112,11 @@ public void Should_read_empty_run_format_properly()
.IsBold
.Should()
.Be(RunFormat.Default.IsBold);

runFormat
.IsHidden
.Should()
.BeFalse();

runFormat
.StrikethroughType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,53 @@ public void Default_value_of_bold_should_not_be_written()
.Should()
.Be(expectedXml);
}

[Fact]
public void Should_write_hidden_properly()
{
// Assert
var expectedXml = new XElement(OpenXmlNamespaces.Word + "rPr",
new XElement(OpenXmlNamespaces.Word + "vanish"));

var sut = new OpenXmlElementWriter(
new XElement(OpenXmlNamespaces.Word + "rPr"));

var runFormat = new RunFormat
{
IsHidden = true
};

// Act
sut.Visit(runFormat);

// Assert
sut.Xml
.Should()
.Be(expectedXml);
}

[Fact]
public void Default_value_of_hidden_should_not_be_written()
{
// Assert
var expectedXml = new XElement(OpenXmlNamespaces.Word + "rPr");

var sut = new OpenXmlElementWriter(
new XElement(OpenXmlNamespaces.Word + "rPr"));

var runFormat = new RunFormat
{
IsHidden = false
};

// Act
sut.Visit(runFormat);

// Assert
sut.Xml
.Should()
.Be(expectedXml);
}

[Theory]
[InlineData("strike", StrikethroughType.Single)]
Expand Down
4 changes: 4 additions & 0 deletions src/Word/OfficeFlow.Word.OpenXml/OpenXmlElementReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ public void Visit(RunFormat runFormat)
runFormat.IsBold = true;
break;

case "vanish":
runFormat.IsHidden = true;
break;

case "u":
// TODO: Add underline support
break;
Expand Down
7 changes: 7 additions & 0 deletions src/Word/OfficeFlow.Word.OpenXml/OpenXmlElementWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ public void Visit(RunFormat runFormat)
Xml.Add(boldXml);
}

if (runFormat.IsHidden)
{
var vanishXml = new XElement(OpenXmlNamespaces.Word + "vanish");

Xml.Add(vanishXml);
}

if (runFormat.StrikethroughType != StrikethroughType.None)
{
var strikethroughName = runFormat.StrikethroughType switch
Expand Down

0 comments on commit 6815565

Please sign in to comment.