[chore:] font resolver included + various changes

This commit is contained in:
Elias Fierke
2026-01-18 11:38:16 +01:00
parent 013bd4a070
commit 10b0eb5bcd
4 changed files with 120 additions and 22 deletions

View File

@@ -307,7 +307,7 @@
<StackPanel Orientation="Horizontal" Spacing="5">
<TextBox x:Name="TbConfigPath" HorizontalAlignment="Stretch"
Watermark="/home/username/.config/logofclient/config.json" />
<Button IsEnabled="False">
<Button x:Name="BtnConfigPath" HorizontalAlignment="Right">
<Button.Content>
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="File" Width="16" Height="16" Size="16" />
@@ -324,7 +324,24 @@
<StackPanel Orientation="Horizontal" Spacing="5">
<TextBox x:Name="TbWikiPath" HorizontalAlignment="Stretch"
Watermark="/home/username/.config/logofclient/wiki" />
<Button IsEnabled="True" x:Name="BtnWikiPath">
<Button IsEnabled="True" x:Name="BtnWikiPath" HorizontalAlignment="Right">
<Button.Content>
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Folder" Width="16" Height="16" Size="16" />
<Label Content="Öffnen..." VerticalContentAlignment="Center" />
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</StackPanel>
</Grid>
<Grid ColumnDefinitions="400,*">
<Label Grid.Column="0">Font-Pfad</Label>
<StackPanel Grid.Column="1" Orientation="Vertical" Spacing="5">
<StackPanel Orientation="Horizontal" Spacing="5">
<TextBox x:Name="TbFontPath" HorizontalAlignment="Stretch"
Watermark="[App-Direcotry]/assets/fonts/" />
<Button IsEnabled="True" x:Name="BtnFontPath" HorizontalAlignment="Right">
<Button.Content>
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Folder" Width="16" Height="16" Size="16" />

View File

@@ -57,6 +57,8 @@ public partial class MainWindow : Window
try
{
BtnWikiPath.Click += BtnWikiPath_Click;
BtnFontPath.Click += BtnFontPath_Click;
BtnConfigPath.Click += BtnConfigPath_Click;
}
catch
{
@@ -94,23 +96,23 @@ public partial class MainWindow : Window
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
}
private async void StartAddressRepair(Uri path)
{
var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier
var progressWindow = new ProgressWindow();
progressWindow.Show(_instance);
var processor = new AddressRepair(progressWindow);
//var result = await processor.Perform(addresses.Item2, errors);
progressWindow.Close();
//new ResultWindow(result, addresses.Item2).Show();
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
}
// private async void StartAddressRepair(Uri path)
// {
// var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier
// var progressWindow = new ProgressWindow();
//
// progressWindow.Show(_instance);
//
// var processor = new AddressRepair(progressWindow);
// //var result = await processor.Perform(addresses.Item2, errors);
//
//
// progressWindow.Close();
//
//
// //new ResultWindow(result, addresses.Item2).Show();
// //await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
// }
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
{
@@ -302,6 +304,40 @@ public partial class MainWindow : Window
PopulateNavTree();
}
private async void BtnFontPath_Click(object? sender, RoutedEventArgs e)
{
var top = GetTopLevel(this);
var folder = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = "Font Pfad wählen",
AllowMultiple = false
});
if (folder == null || folder.Count == 0) return;
var chosen = folder[0].Path;
TbFontPath.Text = chosen.ToString();
Global._instance.font_path = chosen.ToString();
Global.Save();
}
private async void BtnConfigPath_Click(object? sender, RoutedEventArgs e)
{
var top = GetTopLevel(this);
var folder = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = "Config Pfad wählen",
AllowMultiple = false
});
if (folder == null || folder.Count == 0) return;
var chosen = folder[0].Path;
TbConfigPath.Text = chosen.ToString();
Global._instance.config_path = chosen.ToString();
Global.Save();
MessageBox.Show(this, "Bitte starten Sie das Programm neu, um die Änderungen wirksam zu machen.", "Achtung");
}
private async Task<string> OpenSettingsSaveAsDialog()
{
var settingsFileName = "KAS-Adress-Liste";

View File

@@ -64,6 +64,7 @@ public class Global
public string config_path { get; set; } = "";
public string wiki_storage_path { get; set; } = "";
public List<Country> countries { get; set; } = new();
public string font_path { get; set; } = Path.Combine(AppContext.BaseDirectory, "assets", "fonts");
public static void Save()
{

View File

@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Fonts;
using PdfSharp.Pdf;
namespace Logof_Client;
@@ -12,7 +14,7 @@ public class PdfBuilder
// Table layout
private const int CellsPerRow = 3;
private const int CellsPerPage = 21; // 3 columns × 7 rows
private readonly XFont _boldFont = new("Arial", 9, XFontStyleEx.Bold);
private readonly XFont _boldFont;
private readonly double _cellHeight = 42.43; // mm
private readonly double _cellPaddingBottom = 5; // mm
@@ -32,8 +34,50 @@ public class PdfBuilder
private readonly double _marginLeft = 0; // mm
private readonly double _marginRight = 0; // mm
private readonly double _marginTop = 0; // mm
private readonly XFont _regularFont = new("Arial", 9, XFontStyleEx.Regular);
private readonly XFont _smallFont = new("Arial", 6, XFontStyleEx.Regular);
private readonly XFont _regularFont;
private readonly XFont _smallFont;
public PdfBuilder()
{
EnsureFontResolverRegistered();
// Select first font from build output fonts folder (AppContext.BaseDirectory/fonts)
var chosenFamily = "Arial";
try
{
if (Directory.Exists(Global._instance.font_path))
{
var first = Directory.EnumerateFiles(Global._instance.font_path, "*.ttf").FirstOrDefault();
if (!string.IsNullOrEmpty(first))
chosenFamily = StripStyleSuffix(Path.GetFileNameWithoutExtension(first)) ?? chosenFamily;
}
}
catch
{
chosenFamily = "Arial";
}
_boldFont = new XFont(chosenFamily, 9, XFontStyleEx.Bold);
_regularFont = new XFont(chosenFamily, 9, XFontStyleEx.Regular);
_smallFont = new XFont(chosenFamily, 6, XFontStyleEx.Regular);
}
private static void EnsureFontResolverRegistered()
{
if (GlobalFontSettings.FontResolver != null) return;
//var fontsDir = Path.Combine(AppContext.BaseDirectory, "fonts");
GlobalFontSettings.FontResolver = new StableFontResolver(Global._instance.font_path);
}
private static string StripStyleSuffix(string name)
{
if (string.IsNullOrEmpty(name)) return name;
var idx = name.IndexOf('-');
if (idx < 0) idx = name.IndexOf('_');
if (idx > 0)
return name.Substring(0, idx);
return name;
}
/// <summary>