Files
QWERTYkez.OpenXmlProcessors/QWERTYkez.ExcelProcessor/Editors/RowHeight.cs
melekhin f5eb667973 0.9.1
2026-06-08 14:31:31 +07:00

29 lines
1.4 KiB
C#
Raw 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)
{
private const double POINTS_PER_INCH = 72.0;
private const double INCH_PER_CM = 1.0 / 2.54;
private const double POINTS_PER_CM = POINTS_PER_INCH * INCH_PER_CM; // ≈ 28.3464566929
private const double POINTS_PER_MM = POINTS_PER_CM / 10.0; // ≈ 2.83464566929
private const double DXA_PER_POINT = 20.0; // 1 point = 20 dxa
private 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;
}