Skip to content

Commit

Permalink
Merge pull request #38 from bookfx/zh/fixes
Browse files Browse the repository at this point in the history
api improvements
  • Loading branch information
zhenyagusev committed Feb 10, 2022
2 parents a222385 + a5dc151 commit 734d0f1
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README-ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ Make.Sheet("New Sheet Name", protoBook, "Prototype Sheet Name");
- `BoxStyle.Top` - выровнять по верхнему краю
- `BoxStyle.Middle` - выровнять вертикально по середине
- `BoxStyle.Bottom` - выровнять по нижнему краю
- `BoxStyle.Rotate` - повернуть текст
- `BoxStyle.RotateCounterclockwise` - повернуть текст против часовой стрелки
- `BoxStyle.RotateClockwise` - повернуть текст по часовой стрелке
- `BoxStyle.Indent` - задать отступ
- `BoxStyle.Format` - задать произвольный формат
- `BoxStyle.DefaultFormat` - задать формат `General` (Общий)
Expand Down Expand Up @@ -400,7 +401,7 @@ Make.Sheet("New Sheet Name", protoBook, "Prototype Sheet Name");

``` txt
BookFx. Composing Excel spreadsheets based on a tree of nested components like the HTML DOM.
Copyright (c) 2019 Zhenya Gusev
Copyright (c) 2019–2022 Zhenya Gusev
```

### Уведомление о лицензии
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ See also the example [S5ProtoSheet.cs][s5protosheet.cs].
- `BoxStyle.Top` - align to the top
- `BoxStyle.Middle` - align at the middle vertically
- `BoxStyle.Bottom` - align to the bottom
- `BoxStyle.Rotate` - rotate the text
- `BoxStyle.RotateCounterclockwise` - rotate the text counterclockwise
- `BoxStyle.RotateClockwise` - rotate the text clockwise
- `BoxStyle.Indent` - define an indent
- `BoxStyle.Format` - define a custom format
- `BoxStyle.DefaultFormat` - define the `General` format
Expand Down Expand Up @@ -402,7 +403,7 @@ The project is licensed under the [LGPL-3.0-or-later](https://spdx.org/licenses/

``` txt
BookFx. Composing Excel spreadsheets based on a tree of nested components like the HTML DOM.
Copyright (c) 2019 Zhenya Gusev
Copyright (c) 2019–2022 Zhenya Gusev
```

### The license notice
Expand Down
4 changes: 3 additions & 1 deletion src/BookFx.Tests/Renders/StyleRenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public void Render_Wrap_Set(bool wrap) =>
[Property(Arbitrary = new[] { typeof(ValidRotationArb) })]
public void Render_Rotation_Set(int rotation) =>
Check(
Make.Style().Rotate(rotation),
rotation <= 90
? Make.Style().RotateCounterclockwise(rotation)
: Make.Style().RotateClockwise(rotation - 90),
range => range.Style.TextRotation.Should().Be(rotation));

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/BookFx.Tests/Validation/BoxValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ public void ColSizeRange_InvalidSizes_Invalid(double size)
[Theory]
[InlineData("_")]
[InlineData("_1")]
[InlineData("_123")]
[InlineData("A")]
[InlineData("name0")]
[InlineData("year")]
[InlineData("год")]
[InlineData("έτος")]
[InlineData("")]
public void Name_ValidName_ValidResult(string rangeName)
{
var box = Make.Value().Name(rangeName).Get;
Expand All @@ -195,6 +200,7 @@ public void Name_ValidName_ValidResult(string rangeName)
[Theory]
[InlineData("")]
[InlineData("1")]
[InlineData("123")]
[InlineData("A1")]
[InlineData("R1C1")]
[InlineData("rc")]
Expand Down
2 changes: 1 addition & 1 deletion src/BookFx/BookFx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageId>BookFx</PackageId>
<Description>Composing Excel spreadsheets based on a tree of nested components like the HTML DOM.</Description>
<Authors>Zhenya Gusev</Authors>
<Copyright>Copyright © 2019 Zhenya Gusev</Copyright>
<Copyright>Copyright © 2019–2022 Zhenya Gusev</Copyright>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>excel;xlsx;openxml;ooxml</PackageTags>
Expand Down
9 changes: 8 additions & 1 deletion src/BookFx/BoxBorder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace BookFx
{
using System;
using System.Drawing;
using BookFx.Cores;
using JetBrains.Annotations;
Expand All @@ -10,10 +11,16 @@
[PublicAPI]
public sealed class BoxBorder
{
/// <summary>
/// The default <see cref="BoxBorder"/>. All border parts are thin.
/// </summary>
public static readonly BoxBorder Default = BoxBorderCore.Default;

/// <summary>
/// The empty <see cref="BoxBorder"/>.
/// </summary>
public static readonly BoxBorder Empty = BoxBorderCore.Empty;
[Obsolete("Use Default instead.")]
public static readonly BoxBorder Empty = BoxBorderCore.Default;

private BoxBorder(BoxBorderCore core) => Get = core;

Expand Down
16 changes: 16 additions & 0 deletions src/BookFx/BoxStyle.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace BookFx
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
Expand Down Expand Up @@ -257,10 +258,25 @@ public BoxStyle Font(string name, double size, Color color) =>
[Pure]
public BoxStyle Bottom() => Align(VAlign.Bottom);

/// <summary>
/// Rotate the text counterclockwise.
/// </summary>
/// <param name="degrees">An angle of rotation in degrees from 0 to 90.</param>
[Pure]
public BoxStyle RotateCounterclockwise(int degrees) => Get.With(rotation: degrees);

/// <summary>
/// Rotate the text clockwise.
/// </summary>
/// <param name="degrees">An angle of rotation in degrees from 1 to 90.</param>
[Pure]
public BoxStyle RotateClockwise(int degrees) => Get.With(rotation: 90 + degrees);

/// <summary>
/// Rotate the text counterclockwise.
/// </summary>
/// <param name="degrees">An angle of rotation in degrees from 0 to 180.</param>
[Obsolete("Use RotateCounterclockwise or RotateClockwise instead.")]
[Pure]
public BoxStyle Rotate(int degrees) => Get.With(rotation: degrees);

Expand Down
4 changes: 2 additions & 2 deletions src/BookFx/Cores/BoxBorderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[PublicAPI]
public sealed class BoxBorderCore
{
internal static readonly BoxBorderCore Empty = new BoxBorderCore(
internal static readonly BoxBorderCore Default = new(
parts: None,
style: None,
color: None);
Expand Down Expand Up @@ -46,7 +46,7 @@ internal BoxBorderCore With(
Option<BorderParts>? parts = null,
Option<BorderStyle>? style = null,
Option<Color>? color = null) =>
new BoxBorderCore(
new(
parts ?? Parts,
style ?? Style,
color ?? Color);
Expand Down
5 changes: 5 additions & 0 deletions src/BookFx/Cores/BoxStyleCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ private BoxStyleCore(

/// <summary>
/// Gets the text rotation in degrees.
/// Values are in the range 0 to 180. The first letter of the text is considered the center-point of the arc.
/// For 0 - 90, the value represents degrees above horizon.
/// For 91 - 180 the degrees below the horizon is calculated as:
/// <code>DegreesBelowHorizon = 90 - Rotation</code>
/// See also ECMA-376 - Office Open XML Part 1 - Fundamentals And Markup Language Reference - 18.8 Styles.
/// </summary>
public Option<int> Rotation { get; }

Expand Down
8 changes: 4 additions & 4 deletions src/BookFx/Epplus/Constraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ internal static class Constraint

internal const int MaxScale = 400;

internal static readonly Regex SheetNameRegex = new Regex(@"^[^:\\/?*[\]]{1,31}$");
internal static readonly Regex SheetNameRegex = new(@"^[^:\\/?*[\]]{1,31}$");

internal static readonly Regex RangeNameRegex = new Regex(@"(?i)^[a-z_]\w*$");
internal static readonly Regex RangeNameRegex = new(@"(?i)^(?=\D)\w+$");

internal static readonly Regex A1RangeNameRegex = new Regex(@"(?i)^[a-z]{1,3}\d{1,7}$");
internal static readonly Regex A1RangeNameRegex = new(@"(?i)^[a-z]{1,3}\d{1,7}$");

internal static readonly Regex R1C1RangeNameRegex = new Regex(@"(?i)^(?:(?:r|c)(?:[-\[\]\d]*)){1,2}$");
internal static readonly Regex R1C1RangeNameRegex = new(@"(?i)^(?:(?:r|c)(?:[-\[\]\d]*)){1,2}$");
}
}
10 changes: 5 additions & 5 deletions src/BookFx/Make.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,24 +421,24 @@ public static BoxStyle Style(
Style(others.Prepend(b).Prepend(a));

/// <summary>
/// Creates an empty <see cref="BoxBorder"/>.
/// Creates a default <see cref="BoxBorder"/>. All border parts are thin.
/// </summary>
[Pure]
public static BoxBorder Border() => BoxBorder.Empty;
public static BoxBorder Border() => BoxBorder.Default;

/// <summary>
/// Creates a <see cref="BoxBorder"/> with restriction to a <paramref name="parts"/>.
/// </summary>
/// <param name="parts">Parts of border. This is a flags enum.</param>
[Pure]
public static BoxBorder Border(BorderParts parts) => BoxBorder.Empty.Restrict(parts);
public static BoxBorder Border(BorderParts parts) => BoxBorder.Default.Restrict(parts);

/// <summary>
/// Creates a <see cref="BoxBorder"/> a border style.
/// </summary>
/// <param name="style">The border style.</param>
[Pure]
public static BoxBorder Border(BorderStyle style) => BoxBorder.Empty.Style(style);
public static BoxBorder Border(BorderStyle style) => BoxBorder.Default.Style(style);

/// <summary>
/// Creates a <see cref="BoxBorder"/> with a <paramref name="style"/> applied to a <paramref name="parts"/>.
Expand All @@ -447,6 +447,6 @@ public static BoxStyle Style(
/// <param name="style">The border style.</param>
[Pure]
public static BoxBorder Border(BorderParts parts, BorderStyle style) =>
BoxBorder.Empty.Restrict(parts).Style(style);
BoxBorder.Default.Restrict(parts).Style(style);
}
}

0 comments on commit 734d0f1

Please sign in to comment.