Добавьте файлы проекта.

This commit is contained in:
melekhin
2026-06-05 15:58:03 +07:00
parent 785bd7dc5d
commit cf8ef7add7
56 changed files with 13478 additions and 0 deletions

View File

@@ -0,0 +1,162 @@
using MathStyle = DocumentFormat.OpenXml.Math.Style;
using MathStyleValues = DocumentFormat.OpenXml.Math.StyleValues;
namespace QWERTYkez.WordProcessor.Builders;
public record FontProps
{
public FontProps(double? size = null) => Size = size ?? 12;
public string? FontFamily { get; init; }
public double? Size
{
get => _SizeD.HasValue ? _SizeD.Value / 2d : null;
init => _SizeD = value.HasValue ? (uint?)(value.Value * 2) : null;
}
uint? _SizeD;
public bool IsItalic { get; init; } = false;
public bool IsBold { get; init; } = false;
public UnderlineValues? Underline { get; init; }
public VerticalPositionValues? SubSup { get; init; }
public string? Color { get; init; }
public bool TryExtract(out List<OpenXmlElement> list)
{
list = [];
if (!string.IsNullOrWhiteSpace(FontFamily))
list.Add(new RunFonts { Ascii = FontFamily, HighAnsi = FontFamily });
if (_SizeD is not null)
list.Add(new FontSize { Val = _SizeD.Value.ToString() });
if (IsBold)
list.Add(new Bold());
if (IsItalic)
list.Add(new Italic());
if (Underline is not null)
list.Add(new Underline { Val = Underline });
if (!string.IsNullOrWhiteSpace(Color))
list.Add(new Color { Val = Color });
if (SubSup is not null)
list.Add(new VerticalTextAlignment { Val = SubSup });
return list.Count > 0;
}
public bool TryExtractWithoutFamily(out List<OpenXmlElement> list)
{
list = [];
if (_SizeD is not null)
list.Add(new FontSize { Val = _SizeD.Value.ToString() });
if (IsBold)
list.Add(new Bold());
if (IsItalic)
list.Add(new Italic());
if (Underline is not null)
list.Add(new Underline { Val = Underline });
if (!string.IsNullOrWhiteSpace(Color))
list.Add(new Color { Val = Color });
if (SubSup is not null)
list.Add(new VerticalTextAlignment { Val = SubSup });
return list.Count > 0;
}
public bool TrySupExtract(out List<OpenXmlElement> list)
{
list = [];
if (!string.IsNullOrWhiteSpace(FontFamily))
list.Add(new RunFonts { Ascii = FontFamily, HighAnsi = FontFamily });
if (_SizeD is not null)
list.Add(new FontSize { Val = _SizeD.Value.ToString() });
if (IsBold)
list.Add(new Bold());
if (IsItalic)
list.Add(new Italic());
if (Underline is not null)
list.Add(new Underline { Val = Underline });
if (!string.IsNullOrWhiteSpace(Color))
list.Add(new Color { Val = Color });
list.Add(new VerticalTextAlignment { Val = VerticalPositionValues.Superscript });
return list.Count > 0;
}
public bool TrySubExtract(out List<OpenXmlElement> list)
{
list = [];
if (!string.IsNullOrWhiteSpace(FontFamily))
list.Add(new RunFonts { Ascii = FontFamily, HighAnsi = FontFamily });
if (_SizeD is not null)
list.Add(new FontSize { Val = _SizeD.Value.ToString() });
if (IsBold)
list.Add(new Bold());
if (IsItalic)
list.Add(new Italic());
if (Underline is not null)
list.Add(new Underline { Val = Underline });
if (!string.IsNullOrWhiteSpace(Color))
list.Add(new Color { Val = Color });
list.Add(new VerticalTextAlignment { Val = VerticalPositionValues.Subscript });
return list.Count > 0;
}
public bool TryExtractForMath(out List<OpenXmlElement> list)
{
list = [];
// Для математики используем только элемент Style
if (IsBold)
list.Add(new MathStyle { Val = MathStyleValues.BoldItalic });
else list.Add(new MathStyle { Val = MathStyleValues.Italic });
// Обычное начертание можно не добавлять, так как по умолчанию и так обычное
// (но если нужно явно сбросить, можно добавить Style { Val = StyleValues.Plain })
return list.Count > 0;
}
// Фабричные методы для создания FontProps
public static FontProps Default => new();
public static FontProps WithFont(string fontFamily, double? size = null) =>
new(size) { FontFamily = fontFamily };
public static FontProps WithSize(double size) =>
new(size);
public static FontProps WithStyle(bool bold = false, bool italic = false) =>
new() { IsBold = bold, IsItalic = italic };
public static FontProps WithColor(string hexColor) =>
new() { Color = hexColor };
}