Skip to content

Commit

Permalink
(#11) Implement SpacingBetweenLines property
Browse files Browse the repository at this point in the history
  • Loading branch information
y0ung3r committed May 6, 2024
1 parent 046b4b5 commit 48fad92
Show file tree
Hide file tree
Showing 32 changed files with 392 additions and 74 deletions.
1 change: 1 addition & 0 deletions src/Word/OfficeFlow.Word.Core.Tests/ParagraphTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using FluentAssertions;
using OfficeFlow.Word.Core.Elements.Paragraphs;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Enums;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Enums;

public enum HorizontalAlignment
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Enums;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Enums;

public enum TextAlignment
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using OfficeFlow.MeasureUnits.Absolute;
using OfficeFlow.Word.Core.Elements.Paragraphs.Enums;
using OfficeFlow.Word.Core.Elements.Paragraphs.Spacing;
using OfficeFlow.Word.Core.Elements.Paragraphs.Spacing.Interfaces;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Enums;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;
using OfficeFlow.Word.Core.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting;

public sealed class ParagraphFormat : IVisitable
{
Expand All @@ -23,6 +23,9 @@ public static ParagraphFormat Default
public IParagraphSpacing SpacingAfter { get; set; }
= ParagraphSpacing.Exactly(8.0, AbsoluteUnits.Points);

public ILineSpacing SpacingBetweenLines { get; set; }
= LineSpacing.Multiple(factor: 1.08);

public bool KeepLines { get; set; }

public bool KeepNext { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using OfficeFlow.MeasureUnits.Absolute;
using OfficeFlow.Word.Core.Elements.Paragraphs.Spacing.Interfaces;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Spacing;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;

public sealed class AtLeastSpacing : ILineSpacing, IEquatable<AtLeastSpacing>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;

public sealed class AutoSpacing : IParagraphSpacing
{
internal AutoSpacing()
{ }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using OfficeFlow.MeasureUnits.Absolute;
using OfficeFlow.Word.Core.Elements.Paragraphs.Spacing.Interfaces;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Spacing;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;

public sealed class ExactSpacing : IParagraphSpacing, ILineSpacing, IEquatable<ExactSpacing>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

public interface ILineSpacing;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

public interface IParagraphSpacing;
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using OfficeFlow.MeasureUnits.Absolute;
using OfficeFlow.Word.Core.Elements.Paragraphs.Spacing.Interfaces;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Spacing;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;

public static class LineSpacing
{
public static readonly ILineSpacing Single
= Multiple(factor: 1.0);

public static readonly ILineSpacing OneAndHalf
= Multiple(factor: 1.5);

public static readonly ILineSpacing Double
= Multiple(factor: 2.0);

public static ILineSpacing Exactly<TUnits>(AbsoluteValue<TUnits> value)
where TUnits : AbsoluteUnits, new()
=> new ExactSpacing(
Expand All @@ -25,6 +34,7 @@ public static ILineSpacing AtLeast<TUnits>(double value, TUnits units)
=> AtLeast(
AbsoluteValue.From(value, units));

public static readonly ILineSpacing Auto
= new AutoSpacing();
// TODO[#11]: Design relative measurement units
public static ILineSpacing Multiple(double factor)
=> new MultipleSpacing(factor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;

public sealed class MultipleSpacing : ILineSpacing, IEquatable<MultipleSpacing>
{
private const double MinValue = 0.0;
private const double MaxValue = 132.0;

// TODO[#11]: Design relative measurement units
public double Factor { get; }

internal MultipleSpacing(double factor)
{
if (factor is < MinValue or > MaxValue)
throw new ArgumentException(
$"The factor of multiple spacing must be between {MinValue} and {MaxValue}",
nameof(factor));

Factor = factor;
}

public bool Equals(MultipleSpacing? other)
=> other is not null && Factor.Equals(other.Factor);

/// <inheritdoc />
public override bool Equals(object? other)
=> other is MultipleSpacing spacing && Equals(spacing);

/// <inheritdoc />
public override int GetHashCode()
=> Factor.GetHashCode();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OfficeFlow.MeasureUnits.Absolute;
using OfficeFlow.Word.Core.Elements.Paragraphs.Spacing.Interfaces;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Spacing;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Formatting.Spacing;

public static class ParagraphSpacing
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Text;
using OfficeFlow.DocumentObjectModel;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text;
using OfficeFlow.Word.Core.Interfaces;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting.Enums;

public enum LineBreakType
{
Column,
Page,
TextWrapping
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting.Enums;

public enum StrikethroughType
{
None,
Single,
Double
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Enums;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting.Enums;
using OfficeFlow.Word.Core.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text;
namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting;

public sealed class RunFormat : IVisitable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OfficeFlow.DocumentObjectModel;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Enums;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting.Enums;
using OfficeFlow.Word.Core.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using OfficeFlow.DocumentObjectModel;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Enums;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting.Enums;
using OfficeFlow.Word.Core.Interfaces;

namespace OfficeFlow.Word.Core.Elements.Paragraphs.Text;
Expand Down
2 changes: 2 additions & 0 deletions src/Word/OfficeFlow.Word.Core/Interfaces/IWordVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using OfficeFlow.Word.Core.Elements;
using OfficeFlow.Word.Core.Elements.Paragraphs;
using OfficeFlow.Word.Core.Elements.Paragraphs.Formatting;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting;

namespace OfficeFlow.Word.Core.Interfaces;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Xml.Linq;
using FluentAssertions;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Enums;
using OfficeFlow.Word.Core.Elements.Paragraphs.Text.Formatting.Enums;
using Xunit;

namespace OfficeFlow.Word.OpenXml.Tests.OpenXmlElementReaderTests;
Expand Down
Loading

0 comments on commit 48fad92

Please sign in to comment.