Files
melekhin e373d4108a
All checks were successful
Publish NuGet packages / publish (push) Successful in 28s
many debugs
2026-06-19 15:06:40 +07:00

29 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace QWERTYkez.ExcelProcessor;
/// <summary>
/// Предоставляет типобезопасное представление высоты строки в Excel с поддержкой различных единиц измерения.
/// </summary>
public readonly struct RowHeight(double points)
{
const double POINTS_PER_INCH = 72.0;
const double INCH_PER_CM = 1.0 / 2.54;
const double POINTS_PER_CM = POINTS_PER_INCH * INCH_PER_CM; // ≈ 28.3464566929
const double POINTS_PER_MM = POINTS_PER_CM / 10.0; // ≈ 2.83464566929
const double DXA_PER_POINT = 20.0; // 1 point = 20 dxa
const double POINTS_PER_DXA = 1.0 / DXA_PER_POINT;
/// <summary>Высота в пунктах (points).</summary>
public double Points { get; } = points;
public static RowHeight FromPoints(double points) => new(points);
public static RowHeight FromInch(double inch) => new(inch * POINTS_PER_INCH);
public static RowHeight FromDXA(double dxa) => new(dxa * POINTS_PER_DXA);
public static RowHeight FromCM(double cm) => new(cm * POINTS_PER_CM);
public static RowHeight FromMM(double mm) => new(mm * POINTS_PER_MM);
public double Inch => Points / POINTS_PER_INCH;
public double DXA => Points / POINTS_PER_DXA;
public double CM => Points / POINTS_PER_CM;
public double MM => Points / POINTS_PER_MM;
}