Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Add bitmap .fon input converted per size to TTF, OTF, WOFF, WOFF2 and EOT
SeoJCalive095fe1f1b150
diff --git a/README.ar.md b/README.ar.mdindex 2e83d7ce..29d745ab 100644--- a/README.ar.md+++ b/README.ar.md@@ -167,7 +167,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **الترجمة**: SRT, ASS/SSA, WebVTT، SAMI (SMI)، LRC, TTML, MicroDVD, SCC | فيما بينها بترميز UTF-8 (تُقرأ ملفات CP949 الكورية بشكل صحيح) || **الأرشيفات**: ZIP، وANSYS Workbench (WBPZ)، و7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG وغيرها | الاستخراج، ZIP, 7Z, TAR, TAR.GZ؛<br>وجمع أي ملفات في ZIP واحد || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **الخطوط**: TTF, OTF, WOFF, WOFF2, EOT | فيما بينها |+| **الخطوط**: TTF, OTF, WOFF, WOFF2, EOT؛ FON (NE وFNT v2/v3 أحادي اللون وترميزات أحادية البايت المدعومة، إدخال فقط) | تحويل إلى الصيغ الخمس، ملف لكل حجم (دون لاحقة حجم للمورد الواحد). لا يدعم PE أو الخطوط المتجهية أو FNT المنفرد || **البيانات**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | فيما بينها، وإلى CSV وXLSX (للجداول)؛<br>vCard, iCalendar ↔ CSV || **النماذج ثلاثية الأبعاد**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY؛<br>وFBX للقراءة | فيما بينها، معاينة PNG || **البيانات الجغرافية المتجهية**: Shapefile, GeoJSON, KML, KMZ, GPX<br>ملفات CSV فيها إحداثيات؛<br>وGarmin FIT للقراءة | فيما بينها، وإلى CSV / XLSX / JSON؛<br>وتُحوَّل البيانات المُسقَطة (UTM, Web Mercator, Lambert, Albers) إلى خطوط الطول والعرض في WGS 84 |diff --git a/README.es.md b/README.es.mdindex 1d74252f..0ad81cbc 100644--- a/README.es.md+++ b/README.es.md@@ -161,7 +161,7 @@ Para deshacerlo, quita esas entradas en Seguridad de Windows → Control de apli| **Subtítulos**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | entre sí, en UTF-8 (los archivos coreanos en CP949 se leen correctamente) || **Archivos comprimidos**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | extraer, ZIP, 7Z, TAR, TAR.GZ;<br>cualquier conjunto de archivos → un ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Tipografías**: TTF, OTF, WOFF, WOFF2, EOT | entre sí |+| **Tipografías**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE, FNT v2/v3 monocromo y juegos de un byte compatibles; solo entrada) | conversión entre los cinco formatos, un archivo por tamaño (sin sufijo si hay un solo recurso). Sin PE, fuentes vectoriales ni FNT independiente || **Datos**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | entre sí, CSV y XLSX (tablas);<br>vCard, iCalendar ↔ CSV || **Modelos 3D**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>FBX solo lectura | entre sí, vista previa en PNG || **Datos geoespaciales vectoriales**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV con coordenadas;<br>Garmin FIT solo lectura | entre sí y a CSV / XLSX / JSON;<br>los datos proyectados (UTM, Web Mercator, Lambert, Albers) salen como longitud / latitud WGS 84 |diff --git a/README.fr.md b/README.fr.mdindex 813b3536..a3484c1c 100644--- a/README.fr.md+++ b/README.fr.md@@ -161,7 +161,7 @@ Pour annuler, supprimez ces entrées dans Sécurité Windows → Contrôle des a| **Sous-titres** : SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | entre eux, en UTF-8 (les fichiers coréens en CP949 sont lus correctement) || **Archives** : ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | extraire, ZIP, 7Z, TAR, TAR.GZ ;<br>n'importe quels fichiers → un seul ZIP || **CAO** : DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Polices** : TTF, OTF, WOFF, WOFF2, EOT | entre elles |+| **Polices** : TTF, OTF, WOFF, WOFF2, EOT ; FON (NE, FNT v2/v3 monochrome et jeux de caractères mono-octet pris en charge, entrée seule) | conversion entre les cinq formats, un fichier par taille (sans suffixe pour une seule ressource). PE, polices vectorielles et FNT autonome exclus || **Données** : JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | entre eux, CSV et XLSX (tableaux) ;<br>vCard, iCalendar ↔ CSV || **Modèles 3D** : GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY ;<br>FBX en lecture | entre eux, aperçu PNG || **Données géospatiales vectorielles** : Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV avec coordonnées ;<br>Garmin FIT en lecture | entre eux et CSV / XLSX / JSON ;<br>les données projetées (UTM, Web Mercator, Lambert, Albers) sortent en longitude / latitude WGS 84 |diff --git a/README.hi.md b/README.hi.mdindex 4d4de153..bca7cf91 100644--- a/README.hi.md+++ b/README.hi.md@@ -161,7 +161,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **सबटाइटल**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | आपस में, UTF-8 में (कोरियाई CP949 फ़ाइलें भी सही पढ़ी जाती हैं) || **आर्काइव**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | निकालना, ZIP, 7Z, TAR, TAR.GZ;<br>कोई भी फ़ाइलें → एक ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **फ़ॉन्ट**: TTF, OTF, WOFF, WOFF2, EOT | आपस में |+| **फ़ॉन्ट**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE मोनोक्रोम FNT v2/v3 और समर्थित एक-बाइट वर्णसेट; केवल इनपुट) | पाँच प्रारूपों में रूपांतरण, हर आकार की अलग फ़ाइल (एक संसाधन पर आकार प्रत्यय नहीं)। PE, वेक्टर और अलग FNT असमर्थित || **डेटा**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | आपस में, CSV और XLSX (टेबल);<br>vCard, iCalendar ↔ CSV || **3D मॉडल**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>FBX सिर्फ़ पढ़ने के लिए | आपस में, PNG प्रीव्यू || **भू-स्थानिक वेक्टर**: Shapefile, GeoJSON, KML, KMZ, GPX<br>निर्देशांक वाली CSV;<br>Garmin FIT सिर्फ़ पढ़ने के लिए | आपस में और CSV / XLSX / JSON;<br>प्रोजेक्टेड डेटा (UTM, Web Mercator, Lambert, Albers) WGS 84 देशांतर / अक्षांश में बदलकर आता है |diff --git a/README.ja.md b/README.ja.mdindex d060f6d6..1294d041 100644--- a/README.ja.md+++ b/README.ja.md@@ -164,7 +164,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **字幕**:SRT、ASS/SSA、WebVTT、SAMI(SMI)、LRC、TTML、MicroDVD、SCC | 相互変換、UTF-8で保存(CP949の韓国語ファイルも正しく読み込み) || **アーカイブ**:ZIP、ANSYS Workbench(WBPZ)、7Z、RAR、TAR、TAR.GZ、TAR.BZ2、TAR.XZ、GZ、ISO、CAB、DMG、ALZ、EGG など | 展開、ZIP、7Z、TAR、TAR.GZ。<br>複数のファイル → 1つのZIP || **CAD**:DWG、DXF | PDF、SVG、PNG、DWG ↔ DXF |-| **フォント**:TTF、OTF、WOFF、WOFF2、EOT | 相互変換 |+| **フォント**:TTF、OTF、WOFF、WOFF2、EOT;FON(NE・単色 FNT v2/v3・対応する1バイト文字セット、入力専用) | 5形式間の変換、サイズごとに1ファイル(単一リソースはサイズ接尾辞なし)。PE・ベクター・単独FNTは対象外 || **データ**:JSON、JSON Lines、YAML、TOML、XML<br>vCard、iCalendar | 相互変換、CSVとXLSX(表形式のデータ)。<br>vCard、iCalendar ↔ CSV || **3Dモデル**:GLB、glTF、STL、OBJ(+ MTL)、3MF、PLY。<br>FBXは読み込みのみ | 相互変換、PNGプレビュー || **地理空間ベクターデータ**:Shapefile、GeoJSON、KML、KMZ、GPX<br>座標付きのCSV。<br>Garmin FITは読み込みのみ | 相互変換、CSV/XLSX/JSON。<br>投影座標系(UTM、Webメルカトル、ランベルト、アルベルス)のデータはWGS 84の経度/緯度で出力 |diff --git a/README.ko.md b/README.ko.mdindex 2c0d5094..321aec90 100644--- a/README.ko.md+++ b/README.ko.md@@ -162,7 +162,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **자막**: SRT, ASS/SSA, WebVTT, SAMI(SMI), LRC, TTML, MicroDVD, SCC | 서로 변환, UTF-8로 저장(CP949 한글 자막도 깨지지 않아요) || **압축 파일**: ZIP, ANSYS Workbench(WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG 등 | 압축 풀기, ZIP, 7Z, TAR, TAR.GZ;<br>여러 파일 → ZIP 하나 || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **글꼴**: TTF, OTF, WOFF, WOFF2, EOT | 서로 변환 |+| **글꼴**: TTF, OTF, WOFF, WOFF2, EOT; FON(NE 단색 FNT v2/v3·지원 단일 바이트, 입력 전용) | 다섯 형식으로 변환, 비트맵 크기마다 파일 하나(리소스 하나면 크기 접미사 없음). PE·벡터·독립 FNT 제외 || **데이터**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | 서로 변환, CSV·XLSX(표 모양 데이터);<br>vCard, iCalendar ↔ CSV || **3D 모델**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>FBX는 읽기 | 서로 변환, PNG 미리보기 || **지리 정보(벡터)**: Shapefile, GeoJSON, KML, KMZ, GPX<br>좌표가 있는 CSV;<br>Garmin FIT는 읽기 | 서로 변환, CSV·XLSX·JSON;<br>투영 좌표계(UTM, 웹 메르카토르, 람베르트, 알버스)는 WGS 84 경위도로 변환 |diff --git a/README.md b/README.mdindex fe3b8222..bec67ad3 100644--- a/README.md+++ b/README.md@@ -161,7 +161,7 @@ To undo it, remove the entries in Windows Security → App & browser control →| **Subtitles**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | each other as UTF-8 (Korean CP949 files read correctly) || **Archives**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | extract, ZIP, 7Z, TAR, TAR.GZ;<br>any files → one ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Fonts**: TTF, OTF, WOFF, WOFF2, EOT | each other |+| **Fonts**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE monochrome FNT v2/v3, supported single-byte charsets; input only) | TTF, OTF, WOFF, WOFF2, EOT; one file per bitmap size (one resource: no size suffix). No PE, vector or standalone FNT support || **Data**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | each other, CSV and XLSX (tables);<br>vCard, iCalendar ↔ CSV || **3D models**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>FBX read | each other, PNG preview || **Geospatial vectors**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV with coordinates; Garmin FIT read | each other and CSV / XLSX / JSON;<br>projected data (UTM, Web Mercator, Lambert, Albers) comes out as WGS 84 longitude / latitude |diff --git a/README.pl.md b/README.pl.mdindex 228af92e..795ca692 100644--- a/README.pl.md+++ b/README.pl.md@@ -161,7 +161,7 @@ Aby to cofnąć, usuń te wpisy w Zabezpieczenia Windows → Kontrola aplikacji| **Napisy**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | między sobą, w UTF-8 (koreańskie pliki CP949 są odczytywane poprawnie) || **Archiwa**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | rozpakowanie, ZIP, 7Z, TAR, TAR.GZ;<br>dowolne pliki → jeden ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Czcionki**: TTF, OTF, WOFF, WOFF2, EOT | między sobą |+| **Czcionki**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE, monochromatyczny FNT v2/v3 i obsługiwane zestawy jednobajtowe; tylko wejście) | konwersja między pięcioma formatami, plik na rozmiar (bez sufiksu przy jednym zasobie). Bez PE, fontów wektorowych i samodzielnego FNT || **Dane**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | między sobą, CSV i XLSX (tabele);<br>vCard, iCalendar ↔ CSV || **Modele 3D**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>FBX tylko odczyt | między sobą, podgląd PNG || **Dane geoprzestrzenne (wektorowe)**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV ze współrzędnymi;<br>Garmin FIT tylko odczyt | między sobą oraz CSV / XLSX / JSON;<br>dane w odwzorowaniach (UTM, Web Mercator, Lambert, Albers) wychodzą jako długość / szerokość geograficzna WGS 84 |diff --git a/README.pt-BR.md b/README.pt-BR.mdindex 148464d7..8a25bc8f 100644--- a/README.pt-BR.md+++ b/README.pt-BR.md@@ -161,7 +161,7 @@ Para desfazer, remova essas entradas em Segurança do Windows → Controle de ap| **Legendas**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | entre si, em UTF-8 (arquivos coreanos em CP949 são lidos corretamente) || **Arquivos compactados**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | extrair, ZIP, 7Z, TAR, TAR.GZ;<br>quaisquer arquivos → um ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Fontes**: TTF, OTF, WOFF, WOFF2, EOT | entre si |+| **Fontes**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE, FNT v2/v3 monocromático e conjuntos de um byte compatíveis; somente entrada) | conversão entre os cinco formatos, um arquivo por tamanho (sem sufixo com um recurso). PE, fontes vetoriais e FNT avulso não são aceitos || **Dados**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | entre si, CSV e XLSX (tabelas);<br>vCard, iCalendar ↔ CSV || **Modelos 3D**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>leitura de FBX | entre si, prévia em PNG || **Vetores geoespaciais**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV com coordenadas;<br>leitura de Garmin FIT | entre si e CSV / XLSX / JSON;<br>dados projetados (UTM, Web Mercator, Lambert, Albers) saem como longitude / latitude em WGS 84 |diff --git a/README.pt-PT.md b/README.pt-PT.mdindex 26abe04c..f8b4d468 100644--- a/README.pt-PT.md+++ b/README.pt-PT.md@@ -161,7 +161,7 @@ Para reverter a alteração, remove as entradas em Segurança do Windows → Con| **Legendas**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | conversão entre estes formatos em UTF-8 (leitura correta de ficheiros coreanos em CP949) || **Arquivos**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | extrair, ZIP, 7Z, TAR, TAR.GZ;<br>quaisquer ficheiros → um ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Tipos de letra**: TTF, OTF, WOFF, WOFF2, EOT | conversão entre estes formatos |+| **Tipos de letra**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE, FNT v2/v3 monocromático e conjuntos de um byte compatíveis; apenas entrada) | conversão entre os cinco formatos, um ficheiro por tamanho (sem sufixo com um recurso). PE, tipos de letra vetoriais e FNT avulso não são aceites || **Dados**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | conversão entre estes formatos, CSV e XLSX (tabelas);<br>vCard, iCalendar ↔ CSV || **Modelos 3D**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>leitura de FBX | conversão entre estes formatos, pré-visualização em PNG || **Vetores geoespaciais**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV com coordenadas | conversão entre estes formatos e CSV / XLSX / JSON;<br>os dados projetados (UTM, Web Mercator, Lambert, Albers) são convertidos em longitude / latitude WGS 84 |diff --git a/README.ru.md b/README.ru.mdindex d71e55d2..df9cabd9 100644--- a/README.ru.md+++ b/README.ru.md@@ -161,7 +161,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **Субтитры**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | друг в друга, в UTF-8 (корейские файлы в CP949 читаются правильно) || **Архивы**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | распаковка, ZIP, 7Z, TAR, TAR.GZ;<br>любые файлы → один ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **Шрифты**: TTF, OTF, WOFF, WOFF2, EOT | друг в друга |+| **Шрифты**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE, монохромный FNT v2/v3 и поддерживаемые однобайтовые кодировки; только ввод) | взаимное преобразование пяти форматов, файл на размер (без суффикса для одного ресурса). PE, векторные и отдельные FNT не поддерживаются || **Данные**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | друг в друга, CSV и XLSX (таблицы);<br>vCard, iCalendar ↔ CSV || **3D-модели**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>FBX только чтение | друг в друга, превью в PNG || **Геоданные (векторные)**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV с координатами;<br>Garmin FIT только чтение | друг в друга и CSV / XLSX / JSON;<br>данные в проекциях (UTM, Web Mercator, Ламберта, Альберса) переводятся в долготу / широту WGS 84 |diff --git a/README.th.md b/README.th.mdindex 9ea1d204..42b122d7 100644--- a/README.th.md+++ b/README.th.md@@ -161,7 +161,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **คำบรรยาย**: SRT, ASS/SSA, WebVTT, SAMI (SMI), LRC, TTML, MicroDVD, SCC | แปลงสลับกันเป็น UTF-8 (อ่านไฟล์ SMI/SRT เกาหลีรหัส CP949 ได้ถูกต้อง) || **ไฟล์บีบอัด**: ZIP, ANSYS Workbench (WBPZ), 7Z, RAR, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, GZ, ISO, CAB, DMG, ALZ, EGG, … | แตกไฟล์, บีบอัดเป็น ZIP, 7Z, TAR, TAR.GZ;<br>รวมทุกไฟล์เป็นหนึ่ง ZIP || **CAD**: DWG, DXF | PDF, SVG, PNG, DWG ↔ DXF |-| **ฟอนต์**: TTF, OTF, WOFF, WOFF2, EOT | แปลงสลับกันได้ |+| **ฟอนต์**: TTF, OTF, WOFF, WOFF2, EOT; FON (NE, FNT v2/v3 ขาวดำ และชุดอักขระไบต์เดียวที่รองรับ; อินพุตเท่านั้น) | แปลงระหว่างห้ารูปแบบ ออกหนึ่งไฟล์ต่อขนาด (ทรัพยากรเดียวไม่เติมขนาด) ไม่รองรับ PE, เวกเตอร์ หรือ FNT เดี่ยว || **ข้อมูล**: JSON, JSON Lines, YAML, TOML, XML<br>vCard, iCalendar | แปลงสลับกันได้, CSV และ XLSX (ตาราง);<br>vCard, iCalendar ↔ CSV || **โมเดล 3D**: GLB, glTF, STL, OBJ (+ MTL), 3MF, PLY;<br>อ่าน FBX | แปลงสลับกันได้, แสดงภาพตัวอย่าง PNG || **ข้อมูลเวกเตอร์เชิงพื้นที่**: Shapefile, GeoJSON, KML, KMZ, GPX<br>CSV พร้อมพิกัด;<br>อ่าน Garmin FIT | แปลงสลับกันได้ และเป็น CSV / XLSX / JSON<br>โดยพิกัดโปรเจกชัน (UTM, Web Mercator, Lambert, Albers) จะถูกแปลงเป็น WGS 84 ลองจิจูด/ละติจูด |diff --git a/README.zh-CN.md b/README.zh-CN.mdindex c5615960..895cb1ed 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -161,7 +161,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **字幕** SRT、ASS/SSA、WebVTT、SAMI(SMI)、LRC、TTML、MicroDVD、SCC | 互相转换,保存为 UTF-8(也能读取 CP949 韩文字幕) || **压缩包** ZIP、ANSYS Workbench(WBPZ)、7Z、RAR、TAR、TAR.GZ、TAR.BZ2、TAR.XZ、GZ、ISO、CAB、DMG、ALZ、EGG 等 | 解压、ZIP、7Z、TAR、TAR.GZ,<br>多个文件 → 一个 ZIP || **CAD** DWG、DXF | PDF、SVG、PNG、DWG ↔ DXF |-| **字体** TTF、OTF、WOFF、WOFF2、EOT | 互相转换 |+| **字体** TTF、OTF、WOFF、WOFF2、EOT;FON(NE、单色 FNT v2/v3、支持的单字节字符集,仅输入) | 五种格式相互转换,每个尺寸输出一个文件(单资源不加尺寸后缀);不支持 PE、矢量或独立 FNT || **数据** JSON、JSON Lines、YAML、TOML、XML<br>vCard、iCalendar | 互相转换、CSV 和 XLSX(表格数据)、<br>vCard、iCalendar ↔ CSV || **3D 模型** GLB、glTF、STL、OBJ(+ MTL)、3MF、PLY,<br>FBX 仅读取 | 互相转换、PNG 预览 || **地理信息(矢量)** Shapefile、GeoJSON、KML、KMZ、GPX<br>带坐标的 CSV,<br>Garmin FIT 仅读取 | 互相转换、CSV / XLSX / JSON,<br>投影坐标系(UTM、Web 墨卡托、兰伯特、阿尔伯斯)会转换为 WGS 84 经纬度 |diff --git a/README.zh-TW.md b/README.zh-TW.mdindex 5ebe922b..cf7eda3a 100644--- a/README.zh-TW.md+++ b/README.zh-TW.md@@ -161,7 +161,7 @@ Set-ProcessMitigation -Name filee-cli.exe -Disable UserShadowStack| **字幕** SRT、ASS/SSA、WebVTT、SAMI(SMI)、LRC、TTML、MicroDVD、SCC | 互相轉換,儲存為 UTF-8(也能讀取 CP949 韓文字幕) || **壓縮檔** ZIP、ANSYS Workbench(WBPZ)、7Z、RAR、TAR、TAR.GZ、TAR.BZ2、TAR.XZ、GZ、ISO、CAB、DMG、ALZ、EGG 等 | 解壓縮、ZIP、7Z、TAR、TAR.GZ,<br>多個檔案 → 一個 ZIP || **CAD** DWG、DXF | PDF、SVG、PNG、DWG ↔ DXF |-| **字型** TTF、OTF、WOFF、WOFF2、EOT | 互相轉換 |+| **字型** TTF、OTF、WOFF、WOFF2、EOT;FON(NE、單色 FNT v2/v3、支援的單位元組字元集,僅輸入) | 五種格式相互轉換,每個尺寸輸出一個檔案(單一資源不加尺寸後綴);不支援 PE、向量或獨立 FNT || **資料** JSON、JSON Lines、YAML、TOML、XML<br>vCard、iCalendar | 互相轉換、CSV 和 XLSX(表格資料)、<br>vCard、iCalendar ↔ CSV || **3D 模型** GLB、glTF、STL、OBJ(+ MTL)、3MF、PLY,<br>FBX 僅讀取 | 互相轉換、PNG 預覽 || **地理資訊(向量)** Shapefile、GeoJSON、KML、KMZ、GPX<br>帶座標的 CSV,<br>Garmin FIT 僅讀取 | 互相轉換、CSV / XLSX / JSON,<br>投影座標系統(UTM、Web 麥卡托、蘭伯特、阿爾伯斯)會轉換為 WGS 84 經緯度 |diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex cd7db0ac..c06f5369 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -15,7 +15,7 @@ Filee chooses engines automatically. Settings → *Engines* shows their status,| Text & Markdown (Markdig) | built in (library) | **Markdown → HTML, TXT**; **TXT, LOG, PY, PAC, BAT, COMMAND, LUA, CSS, PS1 → UTF-8 TXT**, preserving source text without running scripts (and → PDF / DOCX through the HWPX writer, rhwp or LibreOffice) || Spreadsheets (ExcelDataReader for XLS) | built in (library) | **XLSX, XLS, ODS, CSV, TSV → XLSX, ODS, CSV, TSV** (one CSV / TSV per sheet) || Office Open XML | built in | **DOCM / DOTX / DOTM ↔ DOCX, XLSM / XLTX ↔ XLSX, PPTM / POTX / POTM / PPSX ↔ PPTX** (macros removed for macro-free types) |-| Fonts | built in | **TTF, OTF, WOFF, WOFF2, EOT ↔ each other**; CFF (PostScript) outlines become TrueType for TTF and EOT |+| Fonts | built in | **TTF, OTF, WOFF, WOFF2, EOT ↔ each other**; **FON (NE monochrome FNT v2/v3, supported single-byte charsets) → TTF, OTF, WOFF, WOFF2, EOT only**; CFF (PostScript) outlines become TrueType for TTF and EOT || **HWPX writer** | built in | **DOCX (+ DOCM/DOTX/DOTM), XLSX (+ XLSM/XLTX), XLS, ODS, CSV, TSV, PPTX (+ PPTM/POTX/POTM/PPSX), PDF, OFD, HTML, MHTML, EPUB, MOBI/AZW3, FB2, HWPX, TXT, Markdown → HWPX** (and with rhwp → PDF and images); ODT, RTF, reStructuredText, LaTeX → HWPX with Pandoc || **DOCX writer** | built in | **HWPX (and HWP through rhwp), PDF, OFD, HTML, MHTML, EPUB, MOBI/AZW3, FB2, Markdown, TXT, XLSX, XLS, ODS, CSV, PPTX (+ variants) → DOCX** || PDF text | built in (PdfPig) | **PDF → TXT, Markdown** (reading order, also two columns; Markdown keeps headings, emphasis, links and the pictures; no OCR) |@@ -461,7 +461,8 @@ built-in XLSX route reads the workbook into Filee's document model.## FontsFonts are converted in-process (`Filee.Engines/Fonts`); zlib and Brotli come with .NET. The input format is-recognised by content, so a mislabelled file still converts.+recognised by content, so a mislabelled file still converts. FON is the exception: it is chosen by its `.fon`+extension, and the file must then have an NE header with FNT resources.- **WOFF 1.0**: every table zlib-compressed (stored as-is when that isn't smaller). Lossless both ways.- **WOFF2**: one Brotli stream at the highest quality with the glyf/loca transform and, where it applies, the hmtx@@ -481,12 +482,27 @@ recognised by content, so a mislabelled file still converts.CID fonts) are built; head, hhea, hmtx and, from VORG, vmtx are updated; CFF, VORG and DSIG are dropped; everyother table (cmap, name, OS/2, GSUB, GPOS, kern, ...) is kept. PostScript hints are not converted: the font gets agasp table (smoothing at every size) and a prep that switches on dropout control instead.+- **FON → TTF, OTF, WOFF, WOFF2, EOT** (input only): Filee reads the monochrome FNT v2/v3 bitmap resources of an NE+ executable and turns each lit pixel into a straight, grid-aligned TrueType outline. The result retains the+ original pixel shape, per-glyph advance, ascent and baseline; there is no smoothing or curve tracing. A FON with a+ single font resource produces `Name.ttf` (or the corresponding OTF/WOFF/WOFF2/EOT extension). Several resources+ produce one file per strike, such as `Name-13px.ttf`, `Name-13px-2.ttf` and `Name-14px.ttf`; the font family names+ also distinguish the sizes and repeated heights. Existing output files follow the usual Skip, Rename and Overwrite+ policies independently for each strike. Invalid resources fail the whole input before output files are allocated.+ Character mapping uses the Windows single-byte code page indicated by the resource charset, not the computer's+ locale. Undefined bytes (including those that Windows decodes to Private Use code points in the Greek, Hebrew,+ Baltic and Thai code pages), non-round-tripping bytes and Unicode control characters retain their glyphs and+ spacing but receive no text mapping; charset hints cannot recover the meaning of custom glyphs. PE resources, vector or+ externally stored bitmaps, color FNT, standalone `.fnt` files and double-byte or unrecognized charsets are not+ supported. FON cannot be an output format.- Not supported: CFF2 (variable) outlines to TTF or EOT (to WOFF, WOFF2 and OTF they convert), writing fontcollections, and WOFF/WOFF2 extended metadata (dropped).`tests/Filee.Engines.Tests/FontTests.cs` checks every conversion with small OFL fonts in`tests/Filee.Engines.Tests/Fonts` (see `OFL.txt` there): round trips keep every table byte for byte, a WOFF2 madeby Google's encoder decodes to the source font, and converted CFF glyphs are compared with the originals in Skia.+`tests/Filee.Engines.Tests/FonTests.cs` converts the synthetic `Fon-*.fon` samples that `make-test-fon.py` draws+from pixel art (see `FON-FIXTURES.md`) and compares every rendered glyph with its source bitmap.## DOCX writerdiff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.jsonindex db491825..6bf3d191 100644--- a/src/Filee.App/Assets/i18n/ar.json+++ b/src/Filee.App/Assets/i18n/ar.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "تحويل أيقونات تطبيقات macOS (ICNS) من الصور وإليها.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "التحويل بين الخطوط: TTF وOTF وWOFF وWOFF2 وEOT.",+ "engine.font.description": "التحويل بين TTF وOTF وWOFF وWOFF2 وEOT؛ قراءة FON بنمط NE أحادي اللون وبترميز أحادي البايت فقط.","engine.cad.name": "CAD (built-in)","engine.cad.description": "رسومات AutoCAD: التحويل بين DWG وDXF، وتحويل كليهما إلى PDF وSVG وPNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex 63d8e6af..b816284d 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "macOS app icons (ICNS) from and to images.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "Fonts: TTF, OTF, WOFF, WOFF2 and EOT into each other.",+ "engine.font.description": "Convert between TTF, OTF, WOFF, WOFF2 and EOT; read-only FON input (NE, monochrome, single-byte).","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD drawings: DWG ↔ DXF, and both to PDF, SVG and PNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.jsonindex 951937fc..f6a3f815 100644--- a/src/Filee.App/Assets/i18n/es.json+++ b/src/Filee.App/Assets/i18n/es.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "Iconos de apps de macOS (ICNS) desde y hacia imágenes.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "Tipografías: TTF, OTF, WOFF, WOFF2 y EOT entre sí.",+ "engine.font.description": "Convierte entre TTF, OTF, WOFF, WOFF2 y EOT; FON solo de entrada (NE, monocromo, un byte).","engine.cad.name": "CAD (built-in)","engine.cad.description": "Planos de AutoCAD: DWG ↔ DXF, y ambos a PDF, SVG y PNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.jsonindex d6d5b6a2..cfa24007 100644--- a/src/Filee.App/Assets/i18n/fr.json+++ b/src/Filee.App/Assets/i18n/fr.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "Icônes d'apps macOS (ICNS) depuis et vers des images.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "Polices : TTF, OTF, WOFF, WOFF2 et EOT entre eux.",+ "engine.font.description": "Convertit entre TTF, OTF, WOFF, WOFF2 et EOT ; FON en entrée uniquement (NE, monochrome, un octet).","engine.cad.name": "CAD (built-in)","engine.cad.description": "Dessins AutoCAD : DWG ↔ DXF, et les deux en PDF, SVG et PNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.jsonindex 85e95ede..093937a4 100644--- a/src/Filee.App/Assets/i18n/hi.json+++ b/src/Filee.App/Assets/i18n/hi.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "इमेज से और इमेज में macOS ऐप आइकन (ICNS)।","engine.font.name": "Fonts (built-in)",- "engine.font.description": "फ़ॉन्ट: TTF, OTF, WOFF, WOFF2 और EOT एक-दूसरे में।",+ "engine.font.description": "TTF, OTF, WOFF, WOFF2 और EOT के बीच बदलें; FON केवल इनपुट (NE, एकरंगी, एक-बाइट)।","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD ड्रॉइंग: DWG ↔ DXF, और दोनों से PDF, SVG और PNG।","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.jsonindex e521133e..8da00aee 100644--- a/src/Filee.App/Assets/i18n/ja.json+++ b/src/Filee.App/Assets/i18n/ja.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "macOSアプリのアイコン(ICNS)を画像と相互変換します。","engine.font.name": "Fonts (built-in)",- "engine.font.description": "フォント形式(TTF、OTF、WOFF、WOFF2、EOT)を相互変換します。",+ "engine.font.description": "TTF、OTF、WOFF、WOFF2、EOTを相互変換します。FONは入力専用(NE・単色・1バイト)です。","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD図面に対応します。DWGとDXFの相互変換、および両形式からPDF、SVG、PNGへの変換ができます。","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex 1d765e27..9abda378 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "macOS 앱 아이콘(ICNS)을 이미지로, 이미지를 ICNS로.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "글꼴: TTF, OTF, WOFF, WOFF2, EOT를 서로 변환해요.",+ "engine.font.description": "TTF, OTF, WOFF, WOFF2, EOT를 서로 변환해요. FON은 NE·단색·단일 바이트 입력만 읽어요.","engine.cad.name": "CAD (built-in)","engine.cad.description": "오토캐드 도면: DWG ↔ DXF, 그리고 둘 다 PDF, SVG, PNG로.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.jsonindex 41ddfa88..2b79bedc 100644--- a/src/Filee.App/Assets/i18n/ne.json+++ b/src/Filee.App/Assets/i18n/ne.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "छविहरूबाट र छविहरूमा macOS एप आइकन (ICNS)।","engine.font.name": "Fonts (built-in)",- "engine.font.description": "TTF, OTF, WOFF, WOFF2 फन्टहरू एकअर्कामा रूपान्तरण गर्दछ।",+ "engine.font.description": "TTF, OTF, WOFF, WOFF2 र EOT बीच रूपान्तरण; FON इनपुट मात्र (NE, एकरङ्गी, एक-बाइट)।","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD रेखाचित्रहरू: DWG ↔ DXF, र दुवैबाट PDF, SVG र PNG।","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.jsonindex 7c12a4d4..9b80e10e 100644--- a/src/Filee.App/Assets/i18n/pl.json+++ b/src/Filee.App/Assets/i18n/pl.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "Ikony aplikacji macOS (ICNS) z obrazów i do obrazów.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "Czcionki: TTF, OTF, WOFF, WOFF2 i EOT między sobą.",+ "engine.font.description": "Konwertuje między TTF, OTF, WOFF, WOFF2 i EOT; FON tylko na wejściu (NE, monochromatyczny, jednobajtowy).","engine.cad.name": "CAD (built-in)","engine.cad.description": "Rysunki AutoCAD: DWG ↔ DXF, oba także do PDF, SVG i PNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.jsonindex 3a77563a..d5722144 100644--- a/src/Filee.App/Assets/i18n/pt-BR.json+++ b/src/Filee.App/Assets/i18n/pt-BR.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (mecanismo integrado)","engine.icns.description": "Ícones de apps do macOS (ICNS) a partir de imagens e para imagens.","engine.font.name": "Fontes (mecanismo integrado)",- "engine.font.description": "Fontes: TTF, OTF, WOFF, WOFF2 e EOT entre si.",+ "engine.font.description": "Converte entre TTF, OTF, WOFF, WOFF2 e EOT; FON somente como entrada (NE, monocromático, um byte).","engine.cad.name": "CAD (mecanismo integrado)","engine.cad.description": "Desenhos do AutoCAD: DWG ↔ DXF, e os dois para PDF, SVG e PNG.","engine.model3d.name": "Modelos 3D (mecanismo integrado)",diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.jsonindex 7dcdecb8..c92436f4 100644--- a/src/Filee.App/Assets/i18n/pt-PT.json+++ b/src/Filee.App/Assets/i18n/pt-PT.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (motor integrado)","engine.icns.description": "Ícones de aplicações macOS (ICNS) para imagens e vice-versa.","engine.font.name": "Tipos de letra (motor integrado)",- "engine.font.description": "Converte tipos de letra entre TTF, OTF, WOFF, WOFF2 e EOT.",+ "engine.font.description": "Converte tipos de letra entre TTF, OTF, WOFF, WOFF2 e EOT; FON apenas como entrada (NE, monocromático, um byte).","engine.cad.name": "CAD (motor integrado)","engine.cad.description": "Desenhos AutoCAD: DWG ↔ DXF e ambos para PDF, SVG e PNG.","engine.model3d.name": "Modelos 3D (motor integrado)",diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.jsonindex 4fc991f1..8624ad12 100644--- a/src/Filee.App/Assets/i18n/ru.json+++ b/src/Filee.App/Assets/i18n/ru.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "Значки приложений macOS (ICNS) из картинок и в картинки.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "Шрифты: TTF, OTF, WOFF, WOFF2 и EOT друг в друга.",+ "engine.font.description": "Преобразует TTF, OTF, WOFF, WOFF2 и EOT друг в друга; FON только на вход (NE, монохромный, однобайтовый).","engine.cad.name": "CAD (built-in)","engine.cad.description": "Чертежи AutoCAD: DWG ↔ DXF, и оба — в PDF, SVG и PNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.jsonindex 50c594f1..ceeee4e3 100644--- a/src/Filee.App/Assets/i18n/th.json+++ b/src/Filee.App/Assets/i18n/th.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "ไอคอนแอป macOS (ICNS) จากและเป็นรูปภาพ","engine.font.name": "Fonts (built-in)",- "engine.font.description": "ฟอนต์: TTF, OTF, WOFF, WOFF2 และ EOT สลับกันได้",+ "engine.font.description": "แปลง TTF, OTF, WOFF, WOFF2 ไปมารวมถึง EOT; FON ใช้เป็นอินพุตเท่านั้น (NE, ขาวดำ, ไบต์เดียว)","engine.cad.name": "CAD (built-in)","engine.cad.description": "แบบแปลน AutoCAD: DWG ↔ DXF และแปลงทั้งสองเป็น PDF, SVG และ PNG","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.jsonindex a805dcdf..ead356c0 100644--- a/src/Filee.App/Assets/i18n/tr.json+++ b/src/Filee.App/Assets/i18n/tr.json@@ -180,7 +180,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "macOS uygulama simgeleri (ICNS) ile görseller arasında dönüştürme.","engine.font.name": "Fonts (built-in)",- "engine.font.description": "Yazı tipleri: TTF, OTF, WOFF, WOFF2 ve EOT arasında dönüştürme.",+ "engine.font.description": "TTF, OTF, WOFF, WOFF2 ve EOT arasında dönüştürür; FON yalnızca girdi (NE, tek renk, tek bayt).","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD çizimleri: DWG ↔ DXF ve her ikisinden PDF, SVG ve PNG.","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex 87bbadd0..77048b17 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "macOS 应用图标(ICNS)与图片互转。","engine.font.name": "Fonts (built-in)",- "engine.font.description": "字体:TTF、OTF、WOFF、WOFF2 和 EOT 互相转换。",+ "engine.font.description": "TTF、OTF、WOFF、WOFF2 和 EOT 相互转换;FON 仅作输入(NE、单色、单字节)。","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD 图纸:DWG ↔ DXF,并可转为 PDF、SVG 和 PNG。","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.jsonindex 4d6b6475..2776ef22 100644--- a/src/Filee.App/Assets/i18n/zh-TW.json+++ b/src/Filee.App/Assets/i18n/zh-TW.json@@ -187,7 +187,7 @@"engine.icns.name": "ICNS (built-in)","engine.icns.description": "macOS 應用程式圖示(ICNS)與圖片互轉。","engine.font.name": "Fonts (built-in)",- "engine.font.description": "字型:TTF、OTF、WOFF、WOFF2 和 EOT 互相轉換。",+ "engine.font.description": "TTF、OTF、WOFF、WOFF2 和 EOT 相互轉換;FON 僅作輸入(NE、單色、單位元組)。","engine.cad.name": "CAD (built-in)","engine.cad.description": "AutoCAD 圖紙:DWG ↔ DXF,並可轉為 PDF、SVG 和 PNG。","engine.model3d.name": "3D models (built-in)",diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.csindex c036e172..02f7d689 100644--- a/src/Filee.Core/Formats/FormatRegistry.cs+++ b/src/Filee.Core/Formats/FormatRegistry.cs@@ -304,6 +304,7 @@ public static class FormatRegistrynew("woff", "WOFF", FormatCategory.Font, ["woff"]),new("woff2", "WOFF2", FormatCategory.Font, ["woff2"]),new("eot", "EOT", FormatCategory.Font, ["eot"]),+ new("fon", "FON", FormatCategory.Font, ["fon"], Writable: false),// Subtitles (text)new("srt", "SRT", FormatCategory.Subtitle, ["srt"]),diff --git a/src/Filee.Engines/Fonts/FonOutlineBuilder.cs b/src/Filee.Engines/Fonts/FonOutlineBuilder.csnew file mode 100644index 00000000..de9a6b7c--- /dev/null+++ b/src/Filee.Engines/Fonts/FonOutlineBuilder.cs@@ -0,0 +1,395 @@+using System.Buffers.Binary;+using System.Globalization;+using System.Security.Cryptography;+using System.Text;++namespace Filee.Engines.Fonts;++/// <summary>Turns a validated monochrome FNT strike into an unhinted TrueType outline font.</summary>+internal static class FonOutlineBuilder+{+ private readonly record struct Corner(int X, int Y);+ private readonly record struct Edge(Corner From, Corner To);++ public static SfntFont Build(FonStrike strike, int resourceCount = 1, int sameHeightOrdinal = 1)+ {+ if (resourceCount < 1 || sameHeightOrdinal < 1 || strike.Glyphs.Count is < 1 or > 65534)+ throw new InvalidDataException("FON resource or glyph count exceeds TrueType limits.");+ var height = strike.PixelHeight;+ var scale = height <= 1024 ? 1024 / height : 1;+ var upem = checked(height * scale);+ if (upem is < 16 or > 16384)+ throw new InvalidDataException("FON pixel height exceeds TrueType units-per-em limits.");+ var ascent = Signed(strike.Ascent * scale);+ var descent = Signed(-(height - strike.Ascent) * scale);+ var lineGap = Signed(strike.ExternalLeading * scale);++ var glyphs = new List<TrueTypeGlyph?> { null };+ var widths = new List<int> { 0 };+ var cmap = new SortedDictionary<int, int>();+ var encoding = FonReader.CharSetEncoding(strike.CharSet);+ foreach (var source in strike.Glyphs)+ {+ var advance = checked(source.Width * scale);+ if (advance > ushort.MaxValue)+ throw new InvalidDataException("FON glyph advance exceeds TrueType limits.");+ glyphs.Add(Outline(source, strike.Ascent, scale));+ widths.Add(advance);+ try+ {+ var text = encoding.GetString([source.ByteValue]);+ if (text.EnumerateRunes().Count() != 1)+ continue;+ var scalar = Rune.GetRuneAt(text, 0);+ // Windows best-fit tables decode undefined bytes of CP1253/1255/1257/874 to Private Use code points.+ if (scalar.Value > ushort.MaxValue ||+ Rune.GetUnicodeCategory(scalar) is UnicodeCategory.Control or UnicodeCategory.PrivateUse ||+ !encoding.GetBytes(text).AsSpan().SequenceEqual([source.ByteValue]))+ continue;+ cmap.TryAdd(scalar.Value, glyphs.Count - 1);+ }+ catch (DecoderFallbackException) { }+ catch (EncoderFallbackException) { }+ }+ glyphs[0] = glyphs[strike.DefaultChar + 1];+ widths[0] = widths[strike.DefaultChar + 1];+ var (glyf, loca, longLoca) = GlyfTable.Build(+ [.. glyphs.Select(g => g?.Serialize() ?? [])], longFormat: false, alignment: 2);+ var leftBearings = glyphs.Select(g => g?.XMin ?? (short)0).ToArray();+ var covered = glyphs.Where(g => g is not null).Cast<TrueTypeGlyph>().ToArray();+ var xMin = covered.Length == 0 ? 0 : covered.Min(g => g.XMin);+ var xMax = covered.Length == 0 ? 0 : covered.Max(g => g.XMax);+ var yMin = covered.Length == 0 ? 0 : covered.Min(g => g.YMin);+ var yMax = covered.Length == 0 ? 0 : covered.Max(g => g.YMax);+ var minRight = covered.Length == 0 ? 0 : glyphs.Select((g, i) => (g, i))+ .Where(p => p.g is not null).Min(p => widths[p.i] - p.g!.XMax);+ var maxPoints = covered.Length == 0 ? 0 : covered.Max(g => g.Points.Length);+ var maxContours = covered.Length == 0 ? 0 : covered.Max(g => g.NumberOfContours);++ var weight = strike.Weight;+ var bold = weight >= 700;+ var baseName = resourceCount == 1 ? strike.Face :+ $"{strike.Face} {height}px{(sameHeightOrdinal > 1 ? $"-{sameHeightOrdinal}" : "")}";+ var family = weight is 400 or 700 ? baseName : $"{baseName} Weight{weight}";+ var style = (bold, strike.Italic) switch+ {+ (true, true) => "Bold Italic",+ (true, false) => "Bold",+ (false, true) => "Italic",+ _ => "Regular"+ };+ var full = $"{family} {style}";+ var psName = PostScriptName(full);+ var font = new SfntFont(SfntFont.TrueTypeFlavor);+ font.Tables["glyf"] = glyf;+ font.Tables["loca"] = loca;+ font.Tables["hmtx"] = Metrics(widths, leftBearings);+ font.Tables["head"] = Head(upem, xMin, yMin, xMax, yMax, longLoca,+ (bold ? 1 : 0) | (strike.Italic ? 2 : 0));+ font.Tables["hhea"] = Hhea(ascent, descent, lineGap, widths.Max(),+ covered.Length == 0 ? 0 : covered.Min(g => g.XMin), minRight,+ covered.Length == 0 ? 0 : covered.Max(g => g.XMax), glyphs.Count);+ font.Tables["maxp"] = Maxp(glyphs.Count, maxPoints, maxContours);+ font.Tables["OS/2"] = Os2(strike, widths, cmap, encoding.CodePage, weight, bold,+ ascent, descent, lineGap, yMin, yMax);+ font.Tables["name"] = Name(family, style, full, psName);+ font.Tables["cmap"] = Cmap(cmap);+ var post = new byte[32];+ Put32(post, 0, 0x00030000);+ Put32(post, 12, strike.Glyphs.Select(g => g.Width).Distinct().Count() == 1 ? 1u : 0u);+ font.Tables["post"] = post;+ return font;+ }++ private static TrueTypeGlyph? Outline(FonGlyph source, int ascent, int scale)+ {+ var height = source.Pixels.GetLength(0);+ if (source.Pixels.GetLength(1) != source.Width)+ throw new InvalidDataException("FON glyph pixels and width disagree.");+ // Extend identical horizontal runs into maximal rectangles, then cancel each shared unit edge.+ var active = new Dictionary<(int, int), (int Start, int End)>();+ var rectangles = new List<(int X0, int X1, int Y0, int Y1)>();+ for (var y = 0; y <= height; y++)+ {+ var runs = new HashSet<(int, int)>();+ if (y < height)+ for (var x = 0; x < source.Width;)+ {+ if (!source.Pixels[y, x]) { x++; continue; }+ var start = x;+ while (x < source.Width && source.Pixels[y, x]) x++;+ runs.Add((start, x));+ }+ foreach (var (run, interval) in active.ToArray())+ if (!runs.Contains(run))+ {+ rectangles.Add((run.Item1, run.Item2, interval.Start, y));+ active.Remove(run);+ }+ foreach (var run in runs)+ if (!active.ContainsKey(run))+ active[run] = (y, y);+ }+ if (rectangles.Count == 0)+ return null;+ var edges = new HashSet<Edge>();+ void Add(Corner from, Corner to)+ {+ if (!edges.Remove(new Edge(to, from)))+ edges.Add(new Edge(from, to));+ }+ foreach (var (x0, x1, y0, y1) in rectangles)+ {+ for (var x = x0; x < x1; x++)+ {+ Add(new(x, y0), new(x + 1, y0));+ Add(new(x + 1, y1), new(x, y1));+ }+ for (var y = y0; y < y1; y++)+ {+ Add(new(x1, y), new(x1, y + 1));+ Add(new(x0, y + 1), new(x0, y));+ }+ }+ var outgoing = edges.GroupBy(e => e.From).ToDictionary(g => g.Key, g => g.ToList());+ var points = new List<GlyphPoint>();+ var ends = new List<ushort>();+ while (edges.Count != 0)+ {+ var start = edges.First();+ var edge = start;+ var loop = new List<Corner>();+ do+ {+ if (!edges.Remove(edge))+ throw new InvalidDataException("FON outline has an open boundary.");+ loop.Add(edge.From);+ if (edge.To == start.From)+ break;+ if (!outgoing.TryGetValue(edge.To, out var choices))+ throw new InvalidDataException("FON outline has an open boundary.");+ var dx = edge.To.X - edge.From.X;+ var dy = edge.To.Y - edge.From.Y;+ edge = choices.Where(edges.Contains).OrderByDescending(e =>+ dx * (e.To.Y - e.From.Y) - dy * (e.To.X - e.From.X)).FirstOrDefault();+ if (edge == default)+ throw new InvalidDataException("FON outline has an open boundary.");+ } while (true);+ for (var i = 0; i < loop.Count; i++)+ {+ var prev = loop[(i + loop.Count - 1) % loop.Count];+ var curr = loop[i];+ var next = loop[(i + 1) % loop.Count];+ if ((curr.X - prev.X) * (next.Y - curr.Y) ==+ (curr.Y - prev.Y) * (next.X - curr.X))+ continue;+ var x = checked(curr.X * scale);+ var y = checked((ascent - curr.Y) * scale);+ points.Add(new GlyphPoint(Signed(x), Signed(y), true));+ }+ if (points.Count > ushort.MaxValue || ends.Count == short.MaxValue)+ throw new InvalidDataException("FON outline exceeds TrueType point or contour limits.");+ ends.Add((ushort)(points.Count - 1));+ }+ var result = new TrueTypeGlyph+ {+ NumberOfContours = (short)ends.Count,+ Points = [.. points],+ EndPoints = [.. ends]+ };+ (result.XMin, result.YMin, result.XMax, result.YMax) = result.ComputeBounds();+ return result;+ }++ private static byte[] Head(int upem, int xMin, int yMin, int xMax, int yMax, bool longLoca, int style)+ {+ var b = new byte[54];+ Put32(b, 0, 0x00010000); Put32(b, 4, 0x00010000);+ Put32(b, 12, 0x5F0F3CF5); Put16(b, 16, 3); Put16(b, 18, upem);+ Put16(b, 36, xMin); Put16(b, 38, yMin); Put16(b, 40, xMax); Put16(b, 42, yMax);+ Put16(b, 44, style); Put16(b, 46, 8); Put16(b, 48, 2); Put16(b, 50, longLoca ? 1 : 0);+ return b;+ }++ private static byte[] Hhea(int asc, int desc, int gap, int maxAdvance,+ int minLsb, int minRsb, int extent, int count)+ {+ var b = new byte[36];+ Put32(b, 0, 0x00010000);+ Put16(b, 4, asc); Put16(b, 6, desc); Put16(b, 8, gap);+ Put16(b, 10, maxAdvance); Put16(b, 12, Signed(minLsb));+ Put16(b, 14, Signed(minRsb)); Put16(b, 16, Signed(extent));+ Put16(b, 18, 1); Put16(b, 34, count);+ return b;+ }++ private static byte[] Maxp(int count, int points, int contours)+ {+ var b = new byte[32];+ Put32(b, 0, 0x00010000);+ Put16(b, 4, count); Put16(b, 6, points); Put16(b, 8, contours);+ Put16(b, 14, 1); // maxZones: no twilight zone+ return b;+ }++ private static byte[] Metrics(List<int> widths, short[] bearings)+ {+ var b = new byte[widths.Count * 4];+ for (var i = 0; i < widths.Count; i++)+ {+ Put16(b, i * 4, widths[i]);+ Put16(b, i * 4 + 2, bearings[i]);+ }+ return b;+ }++ private static byte[] Os2(FonStrike strike, List<int> widths, SortedDictionary<int, int> cmap,+ int cp, int weight, bool bold, int asc, int desc, int gap, int yMin, int yMax)+ {+ var b = new byte[86];+ Put16(b, 0, 1);+ Put16(b, 2, Signed((int)Math.Round(widths.Skip(1).Average())));+ Put16(b, 4, weight); Put16(b, 6, 5);+ // The PANOSE field is left zero (no invented classification).+ foreach (var scalar in cmap.Keys)+ {+ var bit = scalar switch+ {+ <= 0x007F => 0,+ <= 0x00FF => 1,+ <= 0x017F => 2,+ <= 0x024F => 3,+ <= 0x02AF => 4,+ <= 0x02FF => 5,+ >= 0x0300 and <= 0x036F => 6,+ >= 0x0370 and <= 0x03FF => 7,+ >= 0x0400 and <= 0x052F => 9,+ >= 0x0590 and <= 0x05FF => 11,+ >= 0x0600 and <= 0x06FF => 13,+ >= 0x0E00 and <= 0x0E7F => 24,+ >= 0x1E00 and <= 0x1EFF => 29,+ >= 0x2000 and <= 0x206F => 31,+ >= 0x20A0 and <= 0x20CF => 33,+ >= 0x2100 and <= 0x214F => 35,+ _ => -1+ };+ if (bit >= 0)+ Put32(b, 42 + bit / 32 * 4, Get32(b, 42 + bit / 32 * 4) | (1u << (bit % 32)));+ }+ b[58] = (byte)'F'; b[59] = (byte)'I'; b[60] = (byte)'L'; b[61] = (byte)'E';+ Put16(b, 62, (strike.Italic ? 1 : 0) | (bold ? 0x20 : 0) |+ (!strike.Italic && !bold ? 0x40 : 0));+ Put16(b, 64, cmap.Count == 0 ? 0 : cmap.Keys.First());+ Put16(b, 66, cmap.Count == 0 ? 0 : cmap.Keys.Last());+ Put16(b, 68, asc); Put16(b, 70, desc); Put16(b, 72, gap);+ Put16(b, 74, Math.Max(0, Math.Max(asc, yMax)));+ Put16(b, 76, Math.Max(0, -Math.Min(desc, yMin)));+ var cpBit = cp == 874 ? 16 : cp switch+ {+ 1252 => 0,+ 1250 => 1,+ 1251 => 2,+ 1253 => 3,+ 1254 => 4,+ 1255 => 5,+ 1256 => 6,+ 1257 => 7,+ 1258 => 8,+ _ => throw new InvalidDataException("FON code page is invalid.")+ };+ Put32(b, 78, 1u << cpBit);+ return b;+ }++ private static byte[] Name(string family, string style, string full, string psName)+ {+ var names = new SortedDictionary<int, string>+ {+ [1] = family,+ [2] = style,+ [3] = psName,+ [4] = full,+ [5] = "Version 1.0",+ [6] = psName+ };+ var records = (from platform in new[] { 0, 3 }+ from pair in names+ select (Platform: platform, Encoding: platform == 0 ? 3 : 1,+ Language: platform == 0 ? 0 : 0x409, Id: pair.Key,+ Bytes: Encoding.BigEndianUnicode.GetBytes(pair.Value))).ToArray();+ var w = new BigEndianWriter();+ w.U16(0); w.U16(records.Length); w.U16(6 + records.Length * 12);+ var offset = 0;+ foreach (var record in records)+ {+ if (record.Bytes.Length > ushort.MaxValue || offset > ushort.MaxValue - record.Bytes.Length)+ throw new InvalidDataException("FON name strings exceed TrueType limits.");+ w.U16(record.Platform); w.U16(record.Encoding); w.U16(record.Language);+ w.U16(record.Id); w.U16(record.Bytes.Length); w.U16(offset);+ offset += record.Bytes.Length;+ }+ foreach (var record in records) w.Bytes(record.Bytes);+ return w.ToArray();+ }++ private static string PostScriptName(string full)+ {+ var bytes = Encoding.UTF8.GetBytes(full);+ var tokens = bytes.Select(b =>+ b is >= (byte)'A' and <= (byte)'Z' or >= (byte)'a' and <= (byte)'z' or+ >= (byte)'0' and <= (byte)'9' or (byte)'-'+ ? ((char)b).ToString() : $"_{b:X2}").ToArray();+ var name = string.Concat(tokens);+ if (name.Length <= 63) return name;+ var prefix = new StringBuilder();+ foreach (var token in tokens)+ {+ if (prefix.Length + token.Length > 50) break;+ prefix.Append(token);+ }+ return $"{prefix}-{Convert.ToHexString(SHA256.HashData(bytes).AsSpan(0, 6))}";+ }++ private static byte[] Cmap(SortedDictionary<int, int> map)+ {+ var count = map.Count + 1;+ var length = 16 + 8 * count;+ var sub = new byte[length];+ Put16(sub, 0, 4); Put16(sub, 2, length);+ Put16(sub, 6, count * 2);+ var pow = 1;+ var selector = 0;+ while (pow * 2 <= count) { pow *= 2; selector++; }+ Put16(sub, 8, pow * 2); Put16(sub, 10, selector); Put16(sub, 12, count * 2 - pow * 2);+ var i = 0;+ foreach (var (scalar, gid) in map)+ {+ Put16(sub, 14 + i * 2, scalar);+ Put16(sub, 16 + count * 2 + i * 2, scalar);+ Put16(sub, 16 + count * 4 + i * 2, (gid - scalar) & 0xffff);+ i++;+ }+ Put16(sub, 14 + i * 2, 0xffff);+ Put16(sub, 16 + count * 2 + i * 2, 0xffff);+ Put16(sub, 16 + count * 4 + i * 2, 1);+ var w = new BigEndianWriter();+ w.U16(0); w.U16(2);+ w.U16(0); w.U16(3); w.U32(20);+ w.U16(3); w.U16(1); w.U32(20);+ w.Bytes(sub);+ return w.ToArray();+ }++ private static short Signed(int value) =>+ value is >= short.MinValue and <= short.MaxValue+ ? (short)value : throw new InvalidDataException("FON outline or metrics exceed signed TrueType limits.");++ private static void Put16(byte[] b, int offset, int value) =>+ BinaryPrimitives.WriteUInt16BigEndian(b.AsSpan(offset), checked((ushort)(value & 0xffff)));++ private static void Put32(byte[] b, int offset, uint value) =>+ BinaryPrimitives.WriteUInt32BigEndian(b.AsSpan(offset), value);++ private static uint Get32(byte[] b, int offset) =>+ BinaryPrimitives.ReadUInt32BigEndian(b.AsSpan(offset));+}diff --git a/src/Filee.Engines/Fonts/FonReader.cs b/src/Filee.Engines/Fonts/FonReader.csnew file mode 100644index 00000000..df651320--- /dev/null+++ b/src/Filee.Engines/Fonts/FonReader.cs@@ -0,0 +1,193 @@+using System.Buffers.Binary;+using System.Text;++namespace Filee.Engines.Fonts;++/// <summary>A validated raster glyph; pixels are indexed by row, then column.</summary>+internal sealed record FonGlyph(byte ByteValue, int Width, bool[,] Pixels);++/// <summary>One RT_FONT resource, independent of its NE container.</summary>+internal sealed record FonStrike(+ int Version, int PixelWidth, int PixelHeight, int Ascent, int ExternalLeading,+ bool Italic, int Weight, byte CharSet, string Face, int DefaultChar, int BreakChar,+ IReadOnlyList<FonGlyph> Glyphs);++/// <summary>Reads the monochrome FNT v2/v3 resources of a 16-bit NE font library.</summary>+internal static class FonReader+{+ public static IReadOnlyList<FonStrike> Read(byte[] data)+ {+ if (data.Length < 0x40 || data[0] != 'M' || data[1] != 'Z')+ throw new InvalidDataException("FON requires an MZ executable header.");++ var ne = (long)BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(0x3c));+ if (!Fits(data.Length, ne, 0x28))+ throw new InvalidDataException("FON has a truncated NE header.");+ if (data[ne] == 'P' && data[ne + 1] == 'E')+ throw new NotSupportedException("PE FON resources are not supported; an NE font is required.");+ if (data[ne] != 'N' || data[ne + 1] != 'E')+ throw new InvalidDataException("FON has no NE executable header.");++ var table = ne + U16(data, ne + 0x24);+ var end = ne + U16(data, ne + 0x26);+ if (end <= table || !Fits(data.Length, table, 2) || end > data.Length)+ throw new InvalidDataException("FON has an invalid NE resource table.");+ var shift = U16(data, table);+ if (shift > 15)+ throw new InvalidDataException("FON has an invalid NE resource alignment shift.");++ var strikes = new List<FonStrike>();+ var ranges = new List<(long Start, long End)>();+ var cursor = table + 2;+ var terminated = false;+ while (Fits(end, cursor, 2))+ {+ var type = U16(data, cursor);+ if (type == 0)+ {+ terminated = true;+ break;+ }+ if (!Fits(end, cursor, 8))+ throw new InvalidDataException("FON has a truncated NE resource type.");+ var count = U16(data, cursor + 2);+ cursor += 8;+ if (!Fits(end, cursor, (long)count * 12))+ throw new InvalidDataException("FON has a truncated NE resource name table.");+ if (type == 0x8008)+ {+ for (var i = 0; i < count; i++)+ {+ var entry = cursor + (long)i * 12;+ var start = (long)U16(data, entry) << shift;+ var length = (long)U16(data, entry + 2) << shift;+ if (length == 0 || start < end || !Fits(data.Length, start, length) ||+ ranges.Any(r => start < r.End && r.Start < start + length))+ throw new InvalidDataException("FON has an overlapping or out-of-bounds RT_FONT resource.");+ ranges.Add((start, start + length));+ strikes.Add(ReadFnt(data.AsSpan((int)start, (int)length)));+ }+ }+ cursor += (long)count * 12;+ }+ if (!terminated)+ throw new InvalidDataException("FON has an unterminated NE resource table.");+ if (strikes.Count == 0)+ throw new InvalidDataException("FON contains no RT_FONT resources.");+ return strikes;+ }++ private static FonStrike ReadFnt(ReadOnlySpan<byte> resource)+ {+ if (resource.Length < 6)+ throw new InvalidDataException("RT_FONT has a truncated FNT header.");+ var version = U16(resource, 0);+ if (version is not (0x0200 or 0x0300))+ throw new NotSupportedException($"FNT version 0x{version:X4} is not supported (only v2/v3).");+ var header = version == 0x0200 ? 0x76 : 0x94;+ var size = (long)U32(resource, 2);+ if (size < header || size > resource.Length)+ throw new InvalidDataException("RT_FONT has an invalid FNT dfSize or truncated header.");+ var fnt = resource[..(int)size];+ var type = U16(fnt, 0x42);+ if ((type & 1) != 0)+ throw new NotSupportedException("Vector FNT fonts are not supported.");+ if ((type & 4) != 0)+ throw new NotSupportedException("FNT bitmap pixels stored outside the file are not supported.");+ if (version == 0x0300)+ {+ var flags = U32(fnt, 0x76);+ if (flags is not (1 or 2))+ throw new NotSupportedException($"FNT v3 dfFlags 0x{flags:X8} uses an unsupported glyph table or color format.");+ }++ var height = U16(fnt, 0x58);+ var ascent = U16(fnt, 0x4a);+ var first = fnt[0x5f];+ var last = fnt[0x60];+ var count = last - first + 1;+ if (height == 0 || ascent > height || count <= 0)+ throw new InvalidDataException("FNT has an invalid height, ascent or character range.");+ var defaultChar = fnt[0x61];+ var breakChar = fnt[0x62];+ if (defaultChar >= count || breakChar >= count)+ throw new InvalidDataException("FNT default/break characters must be relative indices within the glyph range.");+ var weight = U16(fnt, 0x53);+ if (weight > 1000)+ throw new InvalidDataException("FNT weight is outside the supported 0..1000 range.");+ var charset = fnt[0x55];+ var encoding = CharSetEncoding(charset);+ var faceOffset = (long)U32(fnt, 0x69);+ if (!Fits(size, faceOffset, 1))+ throw new InvalidDataException("FNT face offset is outside the resource.");+ var faceEnd = fnt[(int)faceOffset..].IndexOf((byte)0);+ if (faceEnd < 0)+ throw new InvalidDataException("FNT face name is not NUL terminated.");+ string face;+ try+ {+ face = encoding.GetString(fnt.Slice((int)faceOffset, faceEnd)).Trim();+ }+ catch (DecoderFallbackException ex)+ {+ throw new InvalidDataException("FNT face name cannot be decoded with its character set.", ex);+ }+ if (face.Length == 0)+ throw new InvalidDataException("FNT face name is empty.");++ var entrySize = version == 0x0200 ? 4 : 6;+ var tableEnd = header + (long)(count + 1) * entrySize;+ if (tableEnd > size)+ throw new InvalidDataException("FNT character table or sentinel is truncated.");+ var bitsOffset = (long)U32(fnt, 0x71);+ if (bitsOffset < tableEnd || bitsOffset > size)+ throw new InvalidDataException("FNT bitmap region offset is outside the resource.");+ var glyphs = new List<FonGlyph>(count);+ for (var i = 0; i < count; i++)+ {+ var entry = header + i * entrySize;+ var width = U16(fnt, entry);+ var offset = version == 0x0200 ? U16(fnt, entry + 2) : U32(fnt, entry + 2);+ var bytes = ((long)width + 7) / 8 * height;+ if (offset < bitsOffset || !Fits(size, offset, bytes))+ throw new InvalidDataException($"FNT bitmap for character {first + i} is outside the resource.");+ var pixels = new bool[height, width];+ for (var y = 0; y < height; y++)+ for (var x = 0; x < width; x++)+ pixels[y, x] = (fnt[(int)(offset + (long)(x / 8) * height + y)] & (0x80 >> (x % 8))) != 0;+ glyphs.Add(new FonGlyph((byte)(first + i), width, pixels));+ }+ return new FonStrike(version, U16(fnt, 0x56), height, ascent, U16(fnt, 0x4e),+ fnt[0x50] != 0, weight == 0 ? 400 : weight, charset, face, defaultChar, breakChar, glyphs);+ }++ /// <summary>The strict Windows code page encoding of a supported single-byte FNT charset.</summary>+ internal static Encoding CharSetEncoding(byte charset)+ {+ var codePage = charset switch+ {+ 0 => 1252,+ 238 => 1250,+ 204 => 1251,+ 161 => 1253,+ 162 => 1254,+ 177 => 1255,+ 178 => 1256,+ 186 => 1257,+ 163 => 1258,+ 222 => 874,+ _ => throw new NotSupportedException($"FNT character set {charset} is not a supported single-byte Windows charset.")+ };+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);+ return Encoding.GetEncoding(codePage, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);+ }++ private static bool Fits(long limit, long start, long length) =>+ start >= 0 && length >= 0 && start <= limit && length <= limit - start;++ private static ushort U16(ReadOnlySpan<byte> data, long offset) =>+ BinaryPrimitives.ReadUInt16LittleEndian(data.Slice((int)offset, 2));++ private static uint U32(ReadOnlySpan<byte> data, long offset) =>+ BinaryPrimitives.ReadUInt32LittleEndian(data.Slice((int)offset, 4));+}diff --git a/src/Filee.Engines/Fonts/FontConverter.cs b/src/Filee.Engines/Fonts/FontConverter.csindex b41a9206..52907832 100644--- a/src/Filee.Engines/Fonts/FontConverter.cs+++ b/src/Filee.Engines/Fonts/FontConverter.cs@@ -13,15 +13,22 @@ public sealed class FontConverter : IConverterpublic string DisplayName => "Fonts (built-in)";public int MaxParallelism => 0;- /// <summary>Every format to every other one, directly.</summary>+ /// <summary>Every format to every other one, directly, plus read-only Windows bitmap FON to each of them.</summary>public IReadOnlyList<ConversionEdge> Edges { get; } =- [.. from source in FontFile.Formats from target in FontFile.Formats where source != target select new ConversionEdge(source, target)];+ [+ .. from source in FontFile.Formats from target in FontFile.Formats where source != target select new ConversionEdge(source, target),+ .. FontFile.Formats.Select(target => new ConversionEdge("fon", target)),+ ];- public EngineStatus GetStatus() => EngineStatus.Available("TTF, OTF, WOFF, WOFF2, EOT", EngineVersions.BuiltIn);+ public EngineStatus GetStatus() => EngineStatus.Available(+ "TTF, OTF, WOFF, WOFF2, EOT; FON input only (NE, monochrome FNT v2/v3, supported single-byte charsets; no PE or vector fonts)",+ EngineVersions.BuiltIn);public Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken) =>Task.Run<IReadOnlyList<string>>(() =>{+ if (step.From == "fon")+ return ConvertFon(step, progress, cancellationToken);var font = FontFile.Load(File.ReadAllBytes(step.InputPath), cancellationToken);progress?.Report(0.2);var outlines = progress is null ? null : new SubProgress(progress, 0.2, 0.6);@@ -36,6 +43,45 @@ public sealed class FontConverter : IConverterreturn [output];}, cancellationToken);+ /// <summary>+ /// One output per RT_FONT resource. Every resource is parsed and every output is built in memory before the first+ /// path is allocated, so a failure or cancellation before writing leaves no new file and no existing file changed.+ /// </summary>+ private static IReadOnlyList<string> ConvertFon(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)+ {+ var strikes = FonReader.Read(File.ReadAllBytes(step.InputPath));+ cancellationToken.ThrowIfCancellationRequested();+ progress?.Report(0.1);++ // Same-height ordinals and the resource count are fixed now, so skipped outputs never rename the others.+ var ordinals = new int[strikes.Count];+ for (var i = 0; i < strikes.Count; i++)+ ordinals[i] = strikes.Take(i + 1).Count(s => s.PixelHeight == strikes[i].PixelHeight);++ var results = new byte[strikes.Count][];+ for (var i = 0; i < strikes.Count; i++)+ {+ var font = FonOutlineBuilder.Build(strikes[i], strikes.Count, ordinals[i]);+ results[i] = FontFile.Save(font, step.To, cancellationToken);+ progress?.Report(i == 0 ? 0.85 : 0.85 + 0.05 * i / strikes.Count);+ cancellationToken.ThrowIfCancellationRequested();+ }+ cancellationToken.ThrowIfCancellationRequested();++ var outputs = new List<string>();+ for (var i = 0; i < strikes.Count; i++)+ {+ var suffix = strikes.Count == 1 ? null+ : $"-{strikes[i].PixelHeight}px{(ordinals[i] > 1 ? $"-{ordinals[i]}" : "")}";+ if (step.Output.Allocate(step.To, suffix) is not { } output)+ continue;+ File.WriteAllBytes(output, results[i]);+ outputs.Add(output);+ }+ progress?.Report(1);+ return outputs;+ }+/// <summary>Maps 0–1 progress of one phase onto a slice of the step's progress, synchronously.</summary>private sealed class SubProgress(IProgress<double> parent, double start, double length) : IProgress<double>{diff --git a/tests/Filee.App.Tests/EnginesPageTests.cs b/tests/Filee.App.Tests/EnginesPageTests.csindex f1c6edec..eb6f4d66 100644--- a/tests/Filee.App.Tests/EnginesPageTests.cs+++ b/tests/Filee.App.Tests/EnginesPageTests.cs@@ -85,6 +85,40 @@ public class EnginesPageTests}}+ [AvaloniaFact]+ public void Font_card_describes_fon_input_only()+ {+ TestServices.EnsureInitialized("en");+ var vm = new MainWindowViewModel(AppHost.Services, AppHost.Get<ILocalizer>(), AppHost.Get<UpdateService>());+ vm.Navigate("engines");+ var window = new MainWindow { DataContext = vm, Width = 1080, Height = 820 };+ window.Show();+ Pump();+ try+ {+ var page = window.GetVisualDescendants().OfType<EnginesPage>().Single();+ var engines = ((EnginesPageViewModel)page.DataContext!).Engines;+ var font = engines.Single(e => e.Converter.Id == "font");+ var card = page.FindControl<ItemsControl>("EngineList")!.ContainerFromIndex(engines.IndexOf(font))!;++ // The card's tooltip is the engine's own detail, and FON is only ever a source.+ var tip = card.GetVisualDescendants().OfType<StackPanel>().Select(ToolTip.GetTip).OfType<string>().Single();+ Assert.Equal(font.Converter.GetStatus().Detail, tip);+ Assert.Contains("FON", tip);+ Assert.Equal(["eot", "otf", "ttf", "woff", "woff2"], font.Converter.Edges.Where(e => e.From == "fon").Select(e => e.To).Order());+ Assert.DoesNotContain(font.Converter.Edges, e => e.To == "fon");++ var description = AppHost.Get<ILocalizer>()["engine.font.description"];+ Assert.Equal(description, font.Description);+ Assert.Contains(card.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == description && t.IsVisible);+ Assert.Contains("FON", description);+ }+ finally+ {+ window.Close();+ }+ }+[AvaloniaFact]public void Only_LibreOffice_has_settings_and_they_change_the_saved_switches(){diff --git a/tests/Filee.App.Tests/PresetEditorTargetTests.cs b/tests/Filee.App.Tests/PresetEditorTargetTests.csnew file mode 100644index 00000000..0ba2c581--- /dev/null+++ b/tests/Filee.App.Tests/PresetEditorTargetTests.cs@@ -0,0 +1,45 @@+// The preset editor's target list offers only formats Filee can write: read-only FON (#177) is a source, never a target.++using Avalonia.Controls;+using Avalonia.Headless;+using Avalonia.Headless.XUnit;+using Avalonia.Threading;+using Avalonia.VisualTree;+using Filee.App.Services;+using Filee.App.ViewModels;+using Filee.App.Views;+using Filee.Core.Localization;+using Filee.Core.Settings;++namespace Filee.App.Tests;++public class PresetEditorTargetTests+{+ [AvaloniaFact]+ public void Preset_editor_target_box_excludes_fon_and_shows_ttf()+ {+ TestServices.EnsureInitialized("en");+ var store = AppHost.Get<UserDataStore>();+ var editor = new PresetEditorViewModel(store.FindPreset("to-ttf")!, AppHost.Get<ILocalizer>());+ var window = new PresetEditorWindow { DataContext = editor, Height = 900 };+ window.Show();+ for (var i = 0; i < 20; i++)+ {+ Dispatcher.UIThread.RunJobs();+ AvaloniaHeadlessPlatform.ForceRenderTimerTick();+ }+ try+ {+ var box = window.GetVisualDescendants().OfType<ComboBox>().Single(c => c.Name == "TargetBox");+ var targets = box.Items.OfType<Choice<string>>().Select(c => c.Value).ToList();+ Assert.NotEmpty(targets);+ Assert.DoesNotContain("fon", targets);+ Assert.Single(targets, t => t == "ttf");+ Assert.Equal("ttf", ((Choice<string>)box.SelectedItem!).Value);+ }+ finally+ {+ window.Close();+ }+ }+}diff --git a/tests/Filee.Cli.Tests/CliTests.cs b/tests/Filee.Cli.Tests/CliTests.csindex 88ad21cd..4c36b21c 100644--- a/tests/Filee.Cli.Tests/CliTests.cs+++ b/tests/Filee.Cli.Tests/CliTests.cs@@ -437,6 +437,137 @@ public sealed class CliTests : IDisposableAssert.True(File.Exists(source));}+ // ──────────── Windows bitmap fonts (#177): the engine tests' committed samples, linked into this project ────────────++ private static readonly string[] FontFormats = ["ttf", "otf", "woff", "woff2", "eot"];++ private static string FonSample(string name) => Path.Combine(AppContext.BaseDirectory, "Fonts", name);++ /// <summary>Copies a committed sample to <c>Name.fon</c> in this test's folder (or a sub folder of it).</summary>+ private string Fon(string sample, string? folder = null)+ {+ folder = Path.Combine(_folder, folder ?? "");+ Directory.CreateDirectory(folder);+ var path = Path.Combine(folder, "Name.fon");+ File.Copy(FonSample(sample), path);+ return path;+ }++ private static string[] Outputs(string json)+ {+ using var document = JsonDocument.Parse(json);+ return [.. document.RootElement.GetProperty("files")[0].GetProperty("outputs").EnumerateArray().Select(o => o.GetString()!)];+ }++ [Fact]+ public void Committed_fon_samples_are_copied_to_cli_output()+ {+ foreach (var sample in new[] { "Fon-v2-fixed.fon", "Fon-multi.fon" })+ {+ var bytes = File.ReadAllBytes(FonSample(sample));+ Assert.Equal("MZ"u8.ToArray(), bytes[..2]);+ Assert.Equal(bytes, File.ReadAllBytes(Fon(sample, Path.GetFileNameWithoutExtension(sample))));+ }+ }++ [Theory]+ [InlineData("ttf")]+ [InlineData("otf")]+ [InlineData("woff")]+ [InlineData("woff2")]+ [InlineData("eot")]+ public async Task Fon_single_resource_omits_size_suffix_in_all_five_formats(string format)+ {+ var source = Fon("Fon-v2-fixed.fon");+ var json = Path.Combine(_folder, "json");+ var text = Path.Combine(_folder, "text");++ var (code, output, errors) = await Run("convert", source, "--to", format, "-o", json, "--json");+ Assert.Equal(Cli.Success, code);+ Assert.Equal("", errors);+ Assert.Equal([Path.Combine(json, "Name." + format)], Outputs(output));+ Assert.Equal(["Name." + format], Directory.EnumerateFiles(json).Select(Path.GetFileName));++ (code, output, _) = await Run("convert", source, "--to", format, "-o", text);+ Assert.Equal(Cli.Success, code);+ Assert.Contains("Name." + format, output);+ Assert.DoesNotContain("13px", output);+ Assert.Equal(["Name." + format], Directory.EnumerateFiles(text).Select(Path.GetFileName));+ }++ [Fact]+ public async Task Fon_reports_each_strike_and_obeys_conflicts()+ {+ var source = Fon("Fon-multi.fon");+ string[] names = ["Name-13px.ttf", "Name-13px-2.ttf", "Name-14px.ttf"];++ // No conflict, in each format: one file per RT_FONT resource, every path in the text and JSON output.+ foreach (var format in FontFormats)+ {+ var clean = Path.Combine(_folder, "clean-" + format);+ var (code, output, _) = await Run("convert", source, "--to", format, "-o", clean, "--json");+ Assert.Equal(Cli.Success, code);+ Assert.Equal(names.Select(n => Path.Combine(clean, Path.ChangeExtension(n, format))), Outputs(output));+ }+ var seed = Path.Combine(_folder, "clean-ttf");+ var (textCode, text, _) = await Run("convert", source, "--to", "ttf", "-o", Path.Combine(_folder, "text"));+ Assert.Equal(Cli.Success, textCode);+ Assert.All(names, n => Assert.Contains(n, text));++ // One size already there: skip writes the other two, rename and overwrite write three.+ string Folder(string name)+ {+ var folder = Path.Combine(_folder, name);+ Directory.CreateDirectory(folder);+ File.WriteAllText(Path.Combine(folder, "Name-13px.ttf"), "old");+ return folder;+ }++ var skip = Folder("skip");+ var (skipCode, skipped, _) = await Run("convert", source, "--to", "ttf", "-o", skip, "--skip", "--json");+ Assert.Equal(Cli.Success, skipCode);+ Assert.Equal([Path.Combine(skip, "Name-13px-2.ttf"), Path.Combine(skip, "Name-14px.ttf")], Outputs(skipped));+ Assert.Equal("old", File.ReadAllText(Path.Combine(skip, "Name-13px.ttf")));++ var rename = Folder("rename");+ var (renameCode, renamed, _) = await Run("convert", source, "--to", "ttf", "-o", rename, "--json");+ Assert.Equal(Cli.Success, renameCode);+ Assert.Equal([Path.Combine(rename, "Name-13px (2).ttf"), Path.Combine(rename, "Name-13px-2.ttf"), Path.Combine(rename, "Name-14px.ttf")],+ Outputs(renamed));+ Assert.Equal("old", File.ReadAllText(Path.Combine(rename, "Name-13px.ttf")));++ var overwrite = Folder("overwrite");+ var (overwriteCode, overwritten, _) = await Run("convert", source, "--to", "ttf", "-o", overwrite, "--overwrite", "--json");+ Assert.Equal(Cli.Success, overwriteCode);+ Assert.Equal(names.Select(n => Path.Combine(overwrite, n)), Outputs(overwritten));+ Assert.All(names, n => Assert.Equal(File.ReadAllBytes(Path.Combine(seed, n)), File.ReadAllBytes(Path.Combine(overwrite, n))));++ // Every size there: skipped, with no outputs.+ var (allCode, all, _) = await Run("convert", source, "--to", "ttf", "-o", seed, "--skip", "--json");+ Assert.Equal(Cli.Success, allCode);+ using var json = JsonDocument.Parse(all);+ Assert.Equal("skipped", json.RootElement.GetProperty("files")[0].GetProperty("state").GetString());+ Assert.Equal(0, json.RootElement.GetProperty("files")[0].GetProperty("outputs").GetArrayLength());+ }++ [Fact]+ public async Task Fon_formats_are_read_only_and_no_to_fon()+ {+ var (code, output, _) = await Run("formats");+ Assert.Equal(Cli.Success, code);+ Assert.Contains(output.Split('\n'), line => line.TrimStart().StartsWith("fon ", StringComparison.Ordinal) && line.Contains("(read only)"));++ (code, output, _) = await Run("formats", "fon");+ Assert.Equal(Cli.Success, code);+ var targets = output.Split('\n')[1].Split(',', StringSplitOptions.TrimEntries);+ Assert.Equal(FontFormats.Order(), targets.Order());++ var (refused, _, errors) = await Run("convert", Fon("Fon-v2-fixed.fon"), "--to", "fon");+ Assert.Equal(Cli.UsageError, refused);+ Assert.Contains("can't write", errors);+ Assert.Equal(["Name.fon"], Directory.EnumerateFiles(_folder).Select(Path.GetFileName));+ }+[Fact]public async Task Refuses_tool_presets(){diff --git a/tests/Filee.Cli.Tests/Filee.Cli.Tests.csproj b/tests/Filee.Cli.Tests/Filee.Cli.Tests.csprojindex 488b0a46..fab82bdb 100644--- a/tests/Filee.Cli.Tests/Filee.Cli.Tests.csproj+++ b/tests/Filee.Cli.Tests/Filee.Cli.Tests.csproj@@ -18,4 +18,8 @@<ItemGroup><Using Include="Xunit" /></ItemGroup>++ <ItemGroup>+ <None Include="..\Filee.Engines.Tests\Fonts\Fon-*.fon" Link="Fonts\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />+ </ItemGroup></Project>diff --git a/tests/Filee.Core.Tests/FonFormatTests.cs b/tests/Filee.Core.Tests/FonFormatTests.csnew file mode 100644index 00000000..eeb47a89--- /dev/null+++ b/tests/Filee.Core.Tests/FonFormatTests.cs@@ -0,0 +1,36 @@+// Windows bitmap fonts (issue #177): .fon is a read-only font format; a new library's fonts donut takes it.++using Filee.Core.Formats;+using Filee.Core.Presets;+using Filee.Core.Profiles;++namespace Filee.Core.Tests;++public class FonFormatTests+{+ [Theory]+ [InlineData("Fixed.fon")]+ [InlineData("SERIFE.FON")]+ public void Fon_is_input_only(string file)+ {+ var format = FormatRegistry.Detect(file);++ Assert.Equal("fon", format?.Id);+ Assert.Equal(FormatCategory.Font, format!.Category);+ Assert.False(format.Writable);+ Assert.Null(FormatRegistry.Detect("font.fnt"));+ }++ [Fact]+ public void Fon_is_read_only_and_new_font_profile_claims_it()+ {+ var profiles = BuiltInData.CreateProfiles();+ var fonts = ProfileSelector.Select(profiles, ["Fixed.fon"]);++ Assert.Equal("fonts", fonts?.Id);+ Assert.Contains("fon", fonts!.Extensions);+ var targets = fonts.PresetIds.Select(id => BuiltInData.CreatePresets().Single(p => p.Id == id).TargetFormat).Order();+ Assert.Equal(["eot", "otf", "ttf", "woff", "woff2"], targets);+ Assert.All(targets, t => Assert.True(FormatRegistry.Known.Single(f => f.Id == t).Writable));+ }+}diff --git a/tests/Filee.Engines.Tests/Filee.Engines.Tests.csproj b/tests/Filee.Engines.Tests/Filee.Engines.Tests.csprojindex 90946d30..6a640661 100644--- a/tests/Filee.Engines.Tests/Filee.Engines.Tests.csproj+++ b/tests/Filee.Engines.Tests/Filee.Engines.Tests.csproj@@ -22,7 +22,7 @@<ItemGroup><!-- Small OFL test fonts for FontTests (see Fonts/OFL.txt and Fonts/make-test-fonts.py). -->- <None Update="Fonts\*.ttf;Fonts\*.otf;Fonts\*.woff2" CopyToOutputDirectory="PreserveNewest" />+ <None Update="Fonts\*.ttf;Fonts\*.otf;Fonts\*.woff2;Fonts\*.fon" CopyToOutputDirectory="PreserveNewest" /><!-- Small Shapefiles written by GDAL for the geospatial tests (synthetic data; Geo/make-test-geo.py recreates them). --><None Update="Geo\*" CopyToOutputDirectory="PreserveNewest" /></ItemGroup>diff --git a/tests/Filee.Engines.Tests/FonTests.cs b/tests/Filee.Engines.Tests/FonTests.csnew file mode 100644index 00000000..f0fdaf0f--- /dev/null+++ b/tests/Filee.Engines.Tests/FonTests.cs@@ -0,0 +1,1099 @@+// Windows bitmap FON (NE + FNT v2/v3) to TTF/OTF/WOFF/WOFF2/EOT (issue #177). The committed Fonts/Fon-*.fon files are+// synthetic, made by Fonts/make-test-fon.py; the expected pixels below are written from that generator's art, never+// from the engine's own reader.++using System.Buffers.Binary;+using System.Globalization;+using System.Security.Cryptography;+using System.Text;+using Filee.Core.Conversion;+using Filee.Core.Presets;+using Filee.Engines.Fonts;+using SkiaSharp;++namespace Filee.Engines.Tests;++public class FonTests(EngineFixture fx) : IClassFixture<EngineFixture>+{+ private static readonly string[] Formats = ["ttf", "otf", "woff", "woff2", "eot"];++ private static string Sample(string name) => Path.Combine(AppContext.BaseDirectory, "Fonts", name);++ private static byte[] Data(string name) => File.ReadAllBytes(Sample(name));++ private static int FntStart(byte[] data, int resource = 0)+ {+ var ne = (int)BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(0x3c));+ var table = ne + BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(ne + 0x24));+ var entry = table + 2 + 8 + 12 + 8 + resource * 12;+ return BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(entry));+ }++ // ───────────────────────── The generator's art, independent of the reader ─────────────────────────++ /// <summary>One committed single-resource sample: FNT version, fixed or proportional, first character.</summary>+ public sealed record Kind(string File, bool Fixed, int First);++ private static readonly Kind[] Kinds =+ [+ new("Fon-v2-fixed.fon", true, 32),+ new("Fon-v2-proportional.fon", false, 0),+ new("Fon-v3-fixed.fon", true, 32),+ new("Fon-v3-proportional.fon", false, 32),+ ];++ private static int ArtWidth(int code, bool isFixed) => isFixed ? 8 : code == 32 ? 0 : code % 2 == 1 ? 5 : 9;++ private static bool ArtLit(int code, int x, int y, int width, int height)+ {+ if (x >= width || code == 32)+ return false;+ var rows = Math.Min(height, 7);+ return code switch+ {+ 33 => x == 2 && y == 0,+ 34 => x == 2 + y % Math.Max(1, width - 2),+ _ => x >= 2 && y < rows && (x == 2 || x == width - 1 || y == 0 || y == rows - 1),+ };+ }++ private static int ArtAscent(int height) => Math.Min(height, 10);++ private static int Scale(int height) => 1024 / height;++ // ───────────────────────── Samples and queue helpers ─────────────────────────++ [Theory]+ [InlineData("Fon-v2-fixed.fon", 0x200, 8)]+ [InlineData("Fon-v2-proportional.fon", 0x200, 0)]+ [InlineData("Fon-v3-fixed.fon", 0x300, 8)]+ [InlineData("Fon-v3-proportional.fon", 0x300, 0)]+ [InlineData("Fon-multi.fon", 0x200, 8)]+ [InlineData("Fon-edge.fon", 0x300, 8)]+ public void Committed_fon_samples_are_copied_to_test_output(string name, int version, int width)+ {+ var bytes = Data(name);+ Assert.Equal("MZ", Encoding.ASCII.GetString(bytes, 0, 2));+ var strikes = FonReader.Read(bytes);+ Assert.Equal(name == "Fon-multi.fon" ? 3 : name == "Fon-edge.fon" ? 2 : 1, strikes.Count);+ Assert.Equal(version, strikes[0].Version);+ Assert.Equal(width, strikes[0].PixelWidth);+ Assert.Equal("Fixed", strikes[0].Face);+ }++ /// <summary>A folder holding <paramref name="data"/> as <c>Name.fon</c>.</summary>+ private string Source(byte[] data, out string folder)+ {+ folder = fx.NewFolder();+ var path = Path.Combine(folder, "Name.fon");+ File.WriteAllBytes(path, data);+ return path;+ }++ private static Preset PresetFor(string target, ConflictPolicy conflict = ConflictPolicy.Rename) =>+ new() { TargetFormat = target, Output = { Location = OutputLocation.SameFolder, Conflict = conflict } };++ /// <summary>Every file below <paramref name="folder"/> with the SHA-256 of its bytes.</summary>+ private static Dictionary<string, string> Snapshot(string folder) =>+ Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories)+ .ToDictionary(p => Path.GetRelativePath(folder, p), p => Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(p))));++ /// <summary>SFNT bytes Skia can read on every platform (web containers are decoded by Filee first).</summary>+ private static byte[] SfntBytes(string path, string format)+ {+ var bytes = File.ReadAllBytes(path);+ return format is "ttf" or "otf" ? bytes : FontFile.Load(bytes).Write();+ }++ // ───────────────────────── Rendering, tables ─────────────────────────++ private const int Pad = 2;++ /// <summary>+ /// The glyph drawn by Skia at its original pixel size, unhinted and aliased, with the cell's top-left at+ /// (<see cref="Pad"/>, <see cref="Pad"/>); the padding shows pixels drawn outside the cell.+ /// </summary>+ private static bool[,] Render(SKTypeface face, int gid, int height, int ascent, int width)+ {+ using var font = new SKFont(face, height) { Hinting = SKFontHinting.None, Edging = SKFontEdging.Alias, Subpixel = false };+ using var path = font.GetGlyphPath((ushort)gid) ?? new SKPath();+ var (w, h) = (width + Pad * 2, height + Pad * 2);+ using var bitmap = new SKBitmap(new SKImageInfo(w, h, SKColorType.Alpha8));+ using (var canvas = new SKCanvas(bitmap))+ using (var paint = new SKPaint { IsAntialias = false, Color = SKColors.Black })+ {+ canvas.Clear(SKColors.Transparent);+ canvas.Translate(Pad, Pad + ascent);+ canvas.DrawPath(path, paint);+ }+ var bytes = bitmap.Bytes;+ var mask = new bool[h, w];+ for (var y = 0; y < h; y++)+ for (var x = 0; x < w; x++)+ mask[y, x] = bytes[y * bitmap.RowBytes + x] > 127;+ return mask;+ }++ private static bool[,] ExpectedMask(int code, int width, int height)+ {+ var mask = new bool[height + Pad * 2, width + Pad * 2];+ for (var y = 0; y < height; y++)+ for (var x = 0; x < width; x++)+ mask[y + Pad, x + Pad] = ArtLit(code, x, y, width, height);+ return mask;+ }++ private static void AssertMask(bool[,] expected, bool[,] actual, string what)+ {+ Assert.Equal(expected.GetLength(0), actual.GetLength(0));+ Assert.Equal(expected.GetLength(1), actual.GetLength(1));+ for (var y = 0; y < expected.GetLength(0); y++)+ for (var x = 0; x < expected.GetLength(1); x++)+ Assert.True(expected[y, x] == actual[y, x], $"{what}: pixel ({x - Pad}, {y - Pad}) should be {(expected[y, x] ? "on" : "off")}");+ }++ private static int U16(byte[] table, int offset) => BinaryPrimitives.ReadUInt16BigEndian(table.AsSpan(offset));++ private static int I16(byte[] table, int offset) => BinaryPrimitives.ReadInt16BigEndian(table.AsSpan(offset));++ private static int Advance(SfntFont font, int gid) => U16(font.Require("hmtx"), gid * 4);++ private static int Lsb(SfntFont font, int gid) => I16(font.Require("hmtx"), gid * 4 + 2);++ /// <summary>The set bits of OS/2 ulUnicodeRange1..4.</summary>+ private static int[] UnicodeRangeBits(SfntFont font) =>+ [.. Enumerable.Range(0, 128).Where(bit =>+ (BinaryPrimitives.ReadUInt32BigEndian(font.Require("OS/2").AsSpan(42 + bit / 32 * 4)) & (1u << (bit % 32))) != 0)];++ /// <summary>The Windows Unicode BMP (3, 1) format 4 subtable as code point → glyph id.</summary>+ private static Dictionary<int, int> Cmap(SfntFont font)+ {+ var t = font.Require("cmap");+ var result = new Dictionary<int, int>();+ for (var i = 0; i < U16(t, 2); i++)+ {+ if (U16(t, 4 + i * 8) != 3 || U16(t, 6 + i * 8) != 1)+ continue;+ var at = (int)BinaryPrimitives.ReadUInt32BigEndian(t.AsSpan(8 + i * 8));+ Assert.Equal(4, U16(t, at));+ var segX2 = U16(t, at + 6);+ for (var s = 0; s < segX2 / 2; s++)+ {+ var end = U16(t, at + 14 + s * 2);+ var start = U16(t, at + 16 + segX2 + s * 2);+ var delta = U16(t, at + 16 + segX2 * 2 + s * 2);+ var rangeAt = at + 16 + segX2 * 3 + s * 2;+ var range = U16(t, rangeAt);+ for (var c = start; c <= end && c != 0xFFFF; c++)+ {+ var gid = range == 0 ? (c + delta) & 0xFFFF : U16(t, rangeAt + range + (c - start) * 2);+ if (range != 0 && gid != 0)+ gid = (gid + delta) & 0xFFFF;+ if (gid != 0)+ result[c] = gid;+ }+ }+ return result;+ }+ throw new Xunit.Sdk.XunitException("no Windows Unicode BMP cmap");+ }++ private static string? Name(SfntFont font, int id)+ {+ var table = font.Require("name");+ var count = U16(table, 2);+ var strings = U16(table, 4);+ for (var i = 0; i < count; i++)+ {+ var offset = 6 + i * 12;+ if (U16(table, offset) != 3 || U16(table, offset + 6) != id)+ continue;+ return Encoding.BigEndianUnicode.GetString(table, strings + U16(table, offset + 10), U16(table, offset + 8));+ }+ return null;+ }++ // ───────────────────────── C1: every version and width, every target ─────────────────────────++ public static TheoryData<int, string> KindsAndFormats()+ {+ var data = new TheoryData<int, string>();+ for (var k = 0; k < Kinds.Length; k++)+ foreach (var format in Formats)+ data.Add(k, format);+ return data;+ }++ [Theory]+ [MemberData(nameof(KindsAndFormats))]+ public async Task Fon_v2_v3_each_strike_opens_in_all_five_formats(int kindIndex, string format)+ {+ var kind = Kinds[kindIndex];+ var source = Source(Data(kind.File), out var folder);+ var job = await fx.ConvertAsync([source], PresetFor(format));++ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ var output = Assert.Single(job.Outputs);+ Assert.Equal(Path.Combine(folder, "Name." + format), output);+ var bytes = File.ReadAllBytes(output);+ var signature = BinaryPrimitives.ReadUInt32BigEndian(bytes);+ switch (format)+ {+ case "ttf" or "otf": Assert.Equal(0x00010000u, signature); break;+ case "woff": Assert.Equal(0x774F4646u, signature); break;+ case "woff2": Assert.Equal(0x774F4632u, signature); break;+ case "eot": Assert.Equal(bytes.Length, (int)BinaryPrimitives.ReadUInt32LittleEndian(bytes)); break;+ }++ var font = FontFile.Load(bytes, TestContext.Current.CancellationToken);+ Assert.Equal(SfntFont.TrueTypeFlavor, font.Flavor);+ foreach (var tag in new[] { "head", "hhea", "maxp", "OS/2", "name", "cmap", "post", "glyf", "loca", "hmtx" })+ Assert.NotNull(font[tag]);+ Assert.Equal(1, U16(font.Require("maxp"), 14)); // maxZones+ Assert.Equal(2, I16(font.Require("head"), 48)); // fontDirectionHint+ var codes = Enumerable.Range(kind.First, 127 - kind.First + 1).ToArray();+ Assert.Equal(codes.Length + 1, font.GlyphCount);++ using var face = SKTypeface.FromStream(new MemoryStream(SfntBytes(output, format)));+ Assert.NotNull(face);+ Assert.Equal(codes.Length + 1, face.GlyphCount);+ var s = Scale(13);+ for (var i = 0; i < codes.Length; i++)+ {+ var width = ArtWidth(codes[i], kind.Fixed);+ Assert.Equal(width * s, Advance(font, i + 1));+ AssertMask(ExpectedMask(codes[i], width, 13), Render(face, i + 1, 13, ArtAscent(13), width), $"{kind.File} {format} code {codes[i]}");+ }+ }++ // ───────────────────────── C2: pixel masks ─────────────────────────++ [Theory]+ [InlineData(0)]+ [InlineData(1)]+ [InlineData(2)]+ [InlineData(3)]+ public void Every_bitmap_mask_matches_unhinted_integer_raster(int kindIndex)+ {+ var kind = Kinds[kindIndex];+ var font = FonOutlineBuilder.Build(Assert.Single(FonReader.Read(Data(kind.File))));+ var glyphs = GlyfTable.ReadAll(font);+ using var face = SKTypeface.FromStream(new MemoryStream(font.Write()));+ var codes = Enumerable.Range(kind.First, 127 - kind.First + 1).ToArray();+ // Single pixel (33), diagonal (34), a box with a hole (35+), blank space (32), and control glyphs (0..31, 127).+ Assert.Contains(33, codes);+ Assert.Contains(34, codes);+ for (var i = 0; i < codes.Length; i++)+ {+ var width = ArtWidth(codes[i], kind.Fixed);+ if (glyphs[i + 1] is { } glyph)+ Assert.All(glyph.Points, p => Assert.True(p.OnCurve, $"code {codes[i]} has an off-curve point"));+ AssertMask(ExpectedMask(codes[i], width, 13), Render(face, i + 1, 13, ArtAscent(13), width), $"{kind.File} code {codes[i]}");+ }+ // The first lit column is x=2: two blank columns on the left survive.+ var box = glyphs[35 - kind.First + 1]!;+ Assert.Equal(2 * Scale(13), box.XMin);+ Assert.Equal(2, box.NumberOfContours); // the outline and its hole+ }++ // ───────────────────────── C3: cmap ─────────────────────────++ /// <summary>CP1252 0x80..0x9F; 0 marks the five undefined bytes.</summary>+ private static readonly int[] Cp1252High =+ [+ 0x20AC, 0, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0, 0x017D, 0,+ 0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0, 0x017E, 0x0178,+ ];++ [Fact]+ public void Cmap_excludes_controls_and_undefined_bytes_without_losing_glyphs()+ {+ // 0x00..0x7F from the committed sample: controls 0x00..0x1F and DEL 0x7F keep glyphs but no cmap entry.+ var strike = Assert.Single(FonReader.Read(Data("Fon-v2-proportional.fon")));+ var font = FonOutlineBuilder.Build(strike);+ var glyphs = GlyfTable.ReadAll(font);+ Assert.Equal(128 + 1, font.GlyphCount);+ var expected = Enumerable.Range(0x20, 0x7F - 0x20).ToDictionary(c => c, c => c + 1);+ Assert.Equal(expected.OrderBy(p => p.Key), Cmap(font).OrderBy(p => p.Key));+ foreach (var code in Enumerable.Range(0, 0x20).Append(0x7F))+ {+ Assert.NotNull(glyphs[code + 1]);+ Assert.Equal(ArtWidth(code, false) * Scale(13), Advance(font, code + 1));+ }++ // 0x7E..0xA0: the CP1252 high half, its five undefined bytes, and NBSP.+ var pixels = new bool[13, 8];+ pixels[0, 2] = true;+ var high = strike with+ {+ Glyphs = [.. Enumerable.Range(0x7E, 0xA0 - 0x7E + 1).Select(b => new FonGlyph((byte)b, 8, pixels))],+ DefaultChar = 0,+ };+ font = FonOutlineBuilder.Build(high);+ glyphs = GlyfTable.ReadAll(font);+ Assert.Equal(high.Glyphs.Count + 1, font.GlyphCount);+ var map = new Dictionary<int, int> { [0x7E] = 1, [0xA0] = high.Glyphs.Count };+ for (var b = 0x80; b <= 0x9F; b++)+ if (Cp1252High[b - 0x80] != 0)+ map[Cp1252High[b - 0x80]] = b - 0x7E + 1;+ Assert.Equal(map.OrderBy(p => p.Key), Cmap(font).OrderBy(p => p.Key));+ Assert.Equal(map.Count, Cmap(font).Values.Distinct().Count());+ Assert.All(Enumerable.Range(1, high.Glyphs.Count), gid =>+ {+ Assert.NotNull(glyphs[gid]);+ Assert.Equal(8 * Scale(13), Advance(font, gid));+ });+ Assert.DoesNotContain(0xFFFD, Cmap(font).Keys);+ // Basic Latin, Latin-1, Latin Extended-A/B, spacing modifiers, punctuation, currency and letterlike symbols.+ Assert.Equal([0, 1, 2, 3, 5, 31, 33, 35], UnicodeRangeBits(font));+ }++ [Fact]+ public void Supported_charsets_are_locale_independent()+ {+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);+ var charsets = new Dictionary<byte, int>+ {+ [0] = 1252,+ [238] = 1250,+ [204] = 1251,+ [161] = 1253,+ [162] = 1254,+ [177] = 1255,+ [178] = 1256,+ [186] = 1257,+ [163] = 1258,+ [222] = 874,+ };+ var strike = Assert.Single(FonReader.Read(Data("Fon-v2-fixed.fon")));+ var pixels = new bool[13, 8];+ pixels[1, 3] = true;+ var glyphs = Enumerable.Range(0xA1, 0xFE - 0xA1 + 1).Select(b => new FonGlyph((byte)b, 8, pixels)).ToList();+ var culture = CultureInfo.CurrentCulture;+ try+ {+ foreach (var locale in new[] { "tr-TR", "ja-JP", "ru-RU" })+ {+ CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = new CultureInfo(locale);+ foreach (var (charset, codePage) in charsets)+ {+ var encoding = Encoding.GetEncoding(codePage, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);+ var expected = new Dictionary<int, int>();+ for (var i = 0; i < glyphs.Count; i++)+ {+ string text;+ try { text = encoding.GetString([glyphs[i].ByteValue]); }+ catch (DecoderFallbackException) { continue; }+ if (text.Length != 1 || char.IsControl(text[0]) || char.IsSurrogate(text[0]) ||+ encoding.GetBytes(text).Single() != glyphs[i].ByteValue ||+ UndefinedHigh.GetValueOrDefault(charset, []).Contains(glyphs[i].ByteValue))+ continue;+ expected.TryAdd(text[0], i + 1);+ }+ var cmap = Cmap(FonOutlineBuilder.Build(strike with { CharSet = charset, Glyphs = glyphs, DefaultChar = 0 }));+ Assert.Equal(expected.OrderBy(p => p.Key), cmap.OrderBy(p => p.Key));+ }+ }+ }+ finally+ {+ CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = culture;+ }+ // Spot checks that the tables really differ: 0xC0 is À, А (Cyrillic) or ภ (Thai) depending on the charset.+ Assert.Equal(0xC0 - 0xA1 + 1, Cmap(FonOutlineBuilder.Build(strike with { CharSet = 0, Glyphs = glyphs, DefaultChar = 0 }))[0x00C0]);+ Assert.Equal(0xC0 - 0xA1 + 1, Cmap(FonOutlineBuilder.Build(strike with { CharSet = 204, Glyphs = glyphs, DefaultChar = 0 }))[0x0410]);+ Assert.Equal(0xC0 - 0xA1 + 1, Cmap(FonOutlineBuilder.Build(strike with { CharSet = 222, Glyphs = glyphs, DefaultChar = 0 }))[0x0E20]);+ // ulUnicodeRange follows the mapped blocks of 0xA1..0xFE in each code page.+ Assert.Equal([1, 2, 5], UnicodeRangeBits(FonOutlineBuilder.Build(strike with { CharSet = 238, Glyphs = glyphs, DefaultChar = 0 })));+ Assert.Equal([1, 2, 3, 6, 33], UnicodeRangeBits(FonOutlineBuilder.Build(strike with { CharSet = 163, Glyphs = glyphs, DefaultChar = 0 })));+ Assert.Equal([24], UnicodeRangeBits(FonOutlineBuilder.Build(strike with { CharSet = 222, Glyphs = glyphs, DefaultChar = 0 })));+ }++ /// <summary>Bytes the Unicode MICSFT tables mark UNDEFINED that .NET decodes to Private Use code points, by charset.</summary>+ private static readonly Dictionary<byte, int[]> UndefinedHigh = new()+ {+ [161] = [0xAA, 0xD2, 0xFF], // CP1253+ [177] = [0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xFB, 0xFC, 0xFF], // CP1255+ [186] = [0xA1, 0xA5], // CP1257+ [222] = [0xDB, 0xDC, 0xDD, 0xDE, 0xFC, 0xFD, 0xFE, 0xFF], // CP874+ };++ [Theory]+ [InlineData(161)]+ [InlineData(177)]+ [InlineData(186)]+ [InlineData(222)]+ public void Undefined_bytes_decoded_to_private_use_keep_glyphs_but_no_cmap(int charset)+ {+ var strike = Assert.Single(FonReader.Read(Data("Fon-v2-fixed.fon")));+ var pixels = new bool[13, 8];+ pixels[1, 3] = true;+ var glyphs = Enumerable.Range(0x80, 0x80).Select(b => new FonGlyph((byte)b, 8, pixels)).ToList();+ var font = FonOutlineBuilder.Build(strike with { CharSet = (byte)charset, Glyphs = glyphs, DefaultChar = 0 });+ var cmap = Cmap(font);+ var outlines = GlyfTable.ReadAll(font);+ foreach (var b in UndefinedHigh[(byte)charset])+ {+ var gid = b - 0x80 + 1;+ Assert.DoesNotContain(gid, cmap.Values);+ Assert.NotNull(outlines[gid]);+ Assert.Equal(8 * Scale(13), Advance(font, gid));+ }+ Assert.DoesNotContain(cmap.Keys, c => c is >= 0xE000 and <= 0xF8FF);+ Assert.Equal(cmap.Keys.Max(), U16(font.Require("OS/2"), 66)); // usLastCharIndex+ Assert.True(U16(font.Require("OS/2"), 66) < 0xE000);+ Assert.DoesNotContain(60, UnicodeRangeBits(font)); // Private Use Area+ }++ // ───────────────────────── C4: metrics ─────────────────────────++ [Theory]+ [InlineData(0)]+ [InlineData(1)]+ public async Task Metrics_preserve_ascent_baseline_proportional_and_space(int kindIndex)+ {+ var kind = Kinds[kindIndex];+ var job = await fx.ConvertAsync([Source(Data(kind.File), out _)], PresetFor("ttf"));+ var output = Assert.Single(job.Outputs);+ var font = FontFile.Load(File.ReadAllBytes(output), TestContext.Current.CancellationToken);+ var upem = U16(font.Require("head"), 18);+ var s = upem / 13;+ Assert.Equal(13 * s, upem);+ var (hhea, os2) = (font.Require("hhea"), font.Require("OS/2"));+ Assert.Equal((10 * s, -3 * s, 2 * s), (I16(hhea, 4), I16(hhea, 6), I16(hhea, 8)));+ Assert.Equal((10 * s, -3 * s, 2 * s), (I16(os2, 68), I16(os2, 70), I16(os2, 72)));++ var glyphs = GlyfTable.ReadAll(font);+ using var face = SKTypeface.FromFile(output);+ using var skFont = new SKFont(face, 13) { Hinting = SKFontHinting.None, Subpixel = true };+ Assert.Equal(-10f, skFont.Metrics.Ascent, 3);+ Assert.Equal(3f, skFont.Metrics.Descent, 3);+ var codes = Enumerable.Range(kind.First, 127 - kind.First + 1).ToArray();+ var widths = new float[codes.Length + 1];+ skFont.GetGlyphWidths([.. Enumerable.Range(0, codes.Length + 1).Select(g => (ushort)g)], widths, []);+ for (var i = 0; i < codes.Length; i++)+ {+ var width = ArtWidth(codes[i], kind.Fixed);+ Assert.Equal(width * s, Advance(font, i + 1));+ Assert.Equal(width, widths[i + 1], 3);+ if (codes[i] == 32)+ {+ Assert.Null(glyphs[i + 1]);+ Assert.Equal(0, Lsb(font, i + 1));+ continue;+ }+ var firstLit = Enumerable.Range(0, width).First(x => Enumerable.Range(0, 13).Any(y => ArtLit(codes[i], x, y, width, 13)));+ Assert.Equal(2, firstLit);+ Assert.Equal(firstLit * s, glyphs[i + 1]!.XMin);+ Assert.Equal(glyphs[i + 1]!.XMin, Lsb(font, i + 1)); // pp1 = xMin - lsb = 0+ var mask = Render(face, i + 1, 13, 10, width);+ var renderedFirst = Enumerable.Range(0, width + Pad * 2).First(x => Enumerable.Range(0, 13 + Pad * 2).Any(y => mask[y, x])) - Pad;+ Assert.Equal(2, renderedFirst);+ }+ // Proportional widths stay different; the fixed sample's blank space keeps its 8 pixels.+ Assert.Equal(kind.Fixed ? 1 : 3, codes.Select(c => ArtWidth(c, kind.Fixed)).Distinct().Count());+ Assert.Equal(ArtWidth(32, kind.Fixed) * s, Advance(font, 32 - kind.First + 1));+ }++ [Fact]+ public void Hhea_extrema_and_caret_match_contoured_glyphs()+ {+ var kind = Kinds[1]; // proportional, 0x00..0x7F, default char 0+ var font = FonOutlineBuilder.Build(Assert.Single(FonReader.Read(Data(kind.File))));+ var s = Scale(13);+ var contoured = new List<(int Advance, int Lsb, int XMin, int XMax)>();+ var advances = new List<int>();+ foreach (var code in new[] { kind.First }.Concat(Enumerable.Range(kind.First, 128))) // .notdef copies code 0+ {+ var width = ArtWidth(code, false);+ advances.Add(width * s);+ var lit = Enumerable.Range(0, width).Where(x => Enumerable.Range(0, 13).Any(y => ArtLit(code, x, y, width, 13))).ToList();+ if (lit.Count > 0)+ contoured.Add((width * s, lit.Min() * s, lit.Min() * s, (lit.Max() + 1) * s));+ }+ var hhea = font.Require("hhea");+ Assert.Equal(advances.Max(), U16(hhea, 10));+ Assert.Equal(contoured.Min(g => g.Lsb), I16(hhea, 12));+ Assert.Equal(contoured.Min(g => g.Advance - (g.Lsb + g.XMax - g.XMin)), I16(hhea, 14));+ Assert.Equal(contoured.Max(g => g.Lsb + g.XMax - g.XMin), I16(hhea, 16));+ Assert.Equal((1, 0, 0), (I16(hhea, 18), I16(hhea, 20), I16(hhea, 22)));+ Assert.Equal([0, 0, 0, 0, 0], new[] { I16(hhea, 24), I16(hhea, 26), I16(hhea, 28), I16(hhea, 30), I16(hhea, 32) });+ Assert.Equal(font.GlyphCount, U16(hhea, 34));+ }++ // ───────────────────────── C5: names ─────────────────────────++ private static string PsEscape(string full) => string.Concat(Encoding.UTF8.GetBytes(full).Select(b =>+ char.IsAsciiLetterOrDigit((char)b) || b == '-' ? ((char)b).ToString() : $"_{b:X2}"));++ [Fact]+ public void Names_and_style_bits_match_each_resource()+ {+ var single = Assert.Single(FonReader.Read(Data("Fon-v2-fixed.fon")));+ void Check(FonStrike strike, string family, string style, int weight, int fsSelection, int macStyle, int count = 1, int ordinal = 1)+ {+ var font = FonOutlineBuilder.Build(strike, count, ordinal);+ var full = $"{family} {style}";+ Assert.Equal(family, Name(font, 1));+ Assert.Equal(style, Name(font, 2));+ Assert.Equal(full, Name(font, 4));+ var ps = PsEscape(full);+ Assert.Equal(ps.Length <= 63 ? ps : Name(font, 6), Name(font, 6));+ Assert.Null(Name(font, 16));+ Assert.Null(Name(font, 17));+ Assert.Equal(weight, U16(font.Require("OS/2"), 4));+ Assert.Equal(fsSelection, U16(font.Require("OS/2"), 62));+ Assert.Equal(macStyle, U16(font.Require("head"), 44));+ }++ Check(single, "Fixed", "Regular", 400, 0x40, 0);+ Assert.Equal("Fixed_20Regular", Name(FonOutlineBuilder.Build(single), 6));+ Check(single with { Weight = 700, Italic = true }, "Fixed", "Bold Italic", 700, 0x21, 3);+ Check(single with { Weight = 700 }, "Fixed", "Bold", 700, 0x20, 1);+ Check(single with { Italic = true }, "Fixed", "Italic", 400, 0x01, 2);+ var unweighted = Data("Fon-v2-fixed.fon");+ BinaryPrimitives.WriteUInt16LittleEndian(unweighted.AsSpan(FntStart(unweighted) + 0x53), 0);+ Check(Assert.Single(FonReader.Read(unweighted)), "Fixed", "Regular", 400, 0x40, 0);+ Check(single with { Weight = 500 }, "Fixed Weight500", "Regular", 500, 0x40, 0);+ Check(single, "Fixed 13px", "Regular", 400, 0x40, 0, count: 3);+ Check(single, "Fixed 13px-2", "Regular", 400, 0x40, 0, count: 3, ordinal: 2);+ Assert.Equal("Fixed_2013px-2_20Regular", Name(FonOutlineBuilder.Build(single, 3, 2), 6));++ // A long non-ASCII face: nameID 6 is cut at a token boundary (at most 50) and gets a hash of the full name.+ var face = string.Concat(Enumerable.Repeat("Ä", 40));+ var font = FonOutlineBuilder.Build(single with { Face = face });+ var full = $"{face} Regular";+ var ps = Name(font, 6)!;+ var hash = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(full)).AsSpan(0, 6));+ Assert.Equal(PsEscape(full)[..48] + "-" + hash, ps);+ Assert.True(ps.Length <= 63);+ Assert.Equal(face, Name(font, 1));+ }++ [Theory]+ [InlineData("ttf")]+ [InlineData("otf")]+ [InlineData("woff")]+ [InlineData("woff2")]+ [InlineData("eot")]+ public async Task Multi_resource_outputs_have_distinct_name_ids(string format)+ {+ var source = Source(Data("Fon-multi.fon"), out var folder);+ var job = await fx.ConvertAsync([source], PresetFor(format));+ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ var expected = new[]+ {+ ("Name-13px", "Fixed 13px", "Fixed_2013px_20Regular"),+ ("Name-13px-2", "Fixed 13px-2", "Fixed_2013px-2_20Regular"),+ ("Name-14px", "Fixed 14px", "Fixed_2014px_20Regular"),+ };+ Assert.Equal(expected.Select(e => Path.Combine(folder, $"{e.Item1}.{format}")), job.Outputs);+ var names = new List<(string?, string?, string?)>();+ foreach (var (file, family, ps) in expected)+ {+ var font = FontFile.Load(File.ReadAllBytes(Path.Combine(folder, $"{file}.{format}")), TestContext.Current.CancellationToken);+ Assert.Equal(family, Name(font, 1));+ Assert.Equal("Regular", Name(font, 2));+ Assert.Equal(family + " Regular", Name(font, 4));+ Assert.Equal(ps, Name(font, 6));+ Assert.Null(Name(font, 16));+ Assert.Null(Name(font, 17));+ names.Add((Name(font, 1), Name(font, 4), Name(font, 6)));+ }+ Assert.Equal(3, names.Select(n => n.Item1).Distinct().Count());+ Assert.Equal(3, names.Select(n => n.Item2).Distinct().Count());+ Assert.Equal(3, names.Select(n => n.Item3).Distinct().Count());+ }++ /// <summary>Hands out <c>Name{suffix}.{ext}</c> paths in a folder and records each request.</summary>+ private sealed class RecordingAllocator(string folder) : IOutputAllocator+ {+ public List<string?> Suffixes { get; } = [];++ public string? Allocate(string extension, string? suffix = null)+ {+ Suffixes.Add(suffix);+ return Path.Combine(folder, $"Name{suffix}.{extension}");+ }+ }++ private sealed class SyncProgress(Action<double> report) : IProgress<double>+ {+ public void Report(double value) => report(value);+ }++ [Fact]+ public async Task Same_height_resources_remain_separate()+ {+ var data = Data("Fon-multi.fon");+ var second = FntStart(data, 1);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(second + 0x53), 700);+ data[second + 0x50] = 1;+ var source = Source(data, out var folder);+ var allocator = new RecordingAllocator(folder);+ var outputs = await new FontConverter().ConvertAsync(+ new ConversionStep(source, "fon", "ttf", PresetFor("ttf"), allocator, fx.NewFolder()), null, TestContext.Current.CancellationToken);++ Assert.Equal(["-13px", "-13px-2", "-14px"], allocator.Suffixes);+ Assert.Equal(3, outputs.Count);+ var fonts = outputs.Select(o => FontFile.Load(File.ReadAllBytes(o))).ToArray();+ Assert.Equal(["Fixed 13px", "Fixed 13px-2", "Fixed 14px"], fonts.Select(f => Name(f, 1)));+ Assert.Equal(["Regular", "Bold Italic", "Regular"], fonts.Select(f => Name(f, 2)));+ Assert.Equal(3, outputs.Select(o => Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(o)))).Distinct().Count());+ Assert.Equal(fonts[0].Require("glyf"), fonts[1].Require("glyf")); // same pixels, still two fonts+ }++ // ───────────────────────── C6/C8: queue post-processing ─────────────────────────++ [Fact]+ public async Task Single_strike_subfolder_only_follows_queue_postprocessing()+ {+ Preset Subfolder(ConflictPolicy conflict) => new()+ {+ TargetFormat = "ttf",+ Output = { Location = OutputLocation.Subfolder, SubfolderOnlyForSeveralFiles = true, Conflict = conflict },+ };++ // No conflict: the one file goes next to the source, without a size suffix, and no subfolder is left.+ var source = Source(Data("Fon-v2-fixed.fon"), out var folder);+ var job = await fx.ConvertAsync([source], Subfolder(ConflictPolicy.Rename));+ Assert.Equal([Path.Combine(folder, "Name.ttf")], job.Outputs);+ Assert.False(Directory.Exists(Path.Combine(folder, "converted")));++ // Skip: the existing file next to the source stays, the result stays in the subfolder.+ source = Source(Data("Fon-v2-fixed.fon"), out folder);+ var existing = Path.Combine(folder, "Name.ttf");+ File.WriteAllText(existing, "old");+ job = await fx.ConvertAsync([source], Subfolder(ConflictPolicy.Skip));+ Assert.Equal(FileState.Done, job.Files[0].State);+ Assert.Equal([Path.Combine(folder, "converted", "Name.ttf")], job.Outputs);+ Assert.Equal("old", File.ReadAllText(existing));++ // Overwrite: the result replaces it.+ source = Source(Data("Fon-v2-fixed.fon"), out folder);+ existing = Path.Combine(folder, "Name.ttf");+ File.WriteAllText(existing, "old");+ job = await fx.ConvertAsync([source], Subfolder(ConflictPolicy.Overwrite));+ Assert.Equal([existing], job.Outputs);+ Assert.Equal(0x00010000u, BinaryPrimitives.ReadUInt32BigEndian(File.ReadAllBytes(existing)));+ Assert.False(Directory.Exists(Path.Combine(folder, "converted")));++ // The move fails (a folder holds the name): the queue keeps the result where it was written.+ source = Source(Data("Fon-v2-fixed.fon"), out folder);+ Directory.CreateDirectory(Path.Combine(folder, "Name.ttf"));+ job = await fx.ConvertAsync([source], Subfolder(ConflictPolicy.Overwrite));+ Assert.Equal([Path.Combine(folder, "converted", "Name.ttf")], job.Outputs);+ Assert.True(Directory.Exists(Path.Combine(folder, "Name.ttf")));+ }++ // ───────────────────────── C8: nothing written before every output is built ─────────────────────────++ private static byte[] Resource(byte[] fon, int index)+ {+ var ne = (int)BinaryPrimitives.ReadUInt32LittleEndian(fon.AsSpan(0x3c));+ var table = ne + BinaryPrimitives.ReadUInt16LittleEndian(fon.AsSpan(ne + 0x24));+ var entry = table + 2 + 8 + 12 + 8 + index * 12;+ var start = BinaryPrimitives.ReadUInt16LittleEndian(fon.AsSpan(entry));+ return fon[start..(start + BinaryPrimitives.ReadUInt16LittleEndian(fon.AsSpan(entry + 2)))];+ }++ /// <summary>MZ/NE with a FONTDIR and the given RT_FONT resources (the layout of make-test-fon.py).</summary>+ private static byte[] Container(params byte[][] resources)+ {+ const int ne = 0x40, table = ne + 0x40;+ var payload = table + 2 + 8 + 12 + 8 + 12 * resources.Length + 2;+ var data = new byte[payload + 1 + resources.Sum(r => r.Length)];+ data[0] = (byte)'M';+ data[1] = (byte)'Z';+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(0x3c), ne);+ data[ne] = (byte)'N';+ data[ne + 1] = (byte)'E';+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(ne + 0x24), table - ne);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(ne + 0x26), (ushort)(payload - ne));+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 2), 0x8007);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 4), 1);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 10), (ushort)payload);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 12), 1);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 22), 0x8008);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 24), (ushort)resources.Length);+ var at = payload + 1;+ for (var i = 0; i < resources.Length; i++)+ {+ var entry = table + 30 + i * 12;+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(entry), (ushort)at);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(entry + 2), (ushort)resources[i].Length);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(entry + 6), (ushort)(0x8001 + i));+ resources[i].CopyTo(data, at);+ at += resources[i].Length;+ }+ return data;+ }++ /// <summary>A valid FNT v2: 1 pixel high, one glyph 33 pixels wide whose last column (x=32) is lit.</summary>+ private static byte[] WideOnePixelFnt()+ {+ const int table = 0x76, face = table + 2 * 4, bits = face + 6;+ var data = new byte[bits + 5];+ BinaryPrimitives.WriteUInt16LittleEndian(data, 0x0200);+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(2), (uint)data.Length);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(0x4a), 1);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(0x53), 400);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(0x58), 1);+ data[0x5f] = data[0x60] = 32;+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(0x69), face);+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(0x71), bits);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table), 33);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 2), bits);+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 6), (ushort)data.Length);+ "Fixed\0"u8.CopyTo(data.AsSpan(face));+ data[bits + 4] = 0x80;+ return data;+ }++ /// <summary>+ /// Runs <paramref name="data"/> as Name.fon under each conflict policy, with every name it would write already+ /// taken, and checks that nothing changed and nothing was reported.+ /// </summary>+ private async Task AssertNothingWrittenAsync(byte[] data, string[] taken, FileState state, string? error = null)+ {+ foreach (var policy in Enum.GetValues<ConflictPolicy>())+ {+ var source = Source(data, out var folder);+ for (var i = 0; i < taken.Length; i++)+ File.WriteAllText(Path.Combine(folder, taken[i]), $"old {i}");+ var before = Snapshot(folder);++ var job = await fx.ConvertAsync([source], PresetFor("ttf", policy));++ var file = Assert.Single(job.Files);+ Assert.Equal(state, file.State);+ if (error is not null)+ Assert.Contains(error, file.ErrorDetail);+ Assert.Empty(job.Outputs);+ Assert.Equal(before.OrderBy(p => p.Key), Snapshot(folder).OrderBy(p => p.Key));+ }+ }++ [Fact]+ public async Task Fon_prewrite_parser_failure_preserves_outputs_under_each_conflict_policy()+ {+ // The second RT_FONT's first bitmap points outside the resource: the reader fails before any output is built.+ var data = Data("Fon-multi.fon");+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(FntStart(data, 1) + 0x94 + 2), 0x7fffffff);+ Assert.Throws<InvalidDataException>(() => FonReader.Read(data));++ await AssertNothingWrittenAsync(data, ["Name-13px.ttf", "Name-13px-2.ttf", "Name-14px.ttf"], FileState.Failed, "outside the resource");+ }++ [Fact]+ public async Task Fon_prewrite_builder_failure_preserves_outputs_under_each_conflict_policy()+ {+ var first = Resource(Data("Fon-multi.fon"), 0);+ var data = Container(first, WideOnePixelFnt());+ var strikes = FonReader.Read(data);+ Assert.Equal([13, 1], strikes.Select(s => s.PixelHeight));+ // The first resource builds completely on its own; the second passes the reader but not the builder.+ Assert.NotEmpty(FontFile.Save(FonOutlineBuilder.Build(strikes[0], 2), "ttf", TestContext.Current.CancellationToken));+ Assert.Contains("limits", Assert.Throws<InvalidDataException>(() => FonOutlineBuilder.Build(strikes[1], 2)).Message);++ await AssertNothingWrittenAsync(data, ["Name-13px.ttf", "Name-1px.ttf"], FileState.Failed, "limits");+ }++ [Fact]+ public async Task Fon_prewrite_cancellation_leaves_no_outputs()+ {+ var source = Source(Data("Fon-multi.fon"), out var folder);+ File.WriteAllText(Path.Combine(folder, "Name-13px.ttf"), "old");+ var before = Snapshot(folder);+ var allocator = new RecordingAllocator(folder);+ using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);+ var reports = new List<double>();+ // Synchronous: the report right after the first output was built cancels before anything else happens.+ var progress = new SyncProgress(value =>+ {+ reports.Add(value);+ if (value == 0.85)+ cts.Cancel();+ });++ var conversion = new FontConverter().ConvertAsync(+ new ConversionStep(source, "fon", "ttf", PresetFor("ttf"), allocator, fx.NewFolder()), progress, cts.Token);++ await Assert.ThrowsAnyAsync<OperationCanceledException>(() => conversion.WaitAsync(TimeSpan.FromSeconds(60), TestContext.Current.CancellationToken));+ Assert.Contains(0.85, reports);+ Assert.Empty(allocator.Suffixes);+ Assert.Equal(before.OrderBy(p => p.Key), Snapshot(folder).OrderBy(p => p.Key));+ }++ [Fact]+ public async Task Queue_precancel_preserves_existing_outputs()+ {+ foreach (var policy in Enum.GetValues<ConflictPolicy>())+ {+ var source = Source(Data("Fon-multi.fon"), out var folder);+ File.WriteAllText(Path.Combine(folder, "Name-13px.ttf"), "old");+ var before = Snapshot(folder);+ await using var queue = new JobQueue(fx.Catalog);+ var job = new ConversionJob([source], PresetFor("ttf", policy), "test");+ job.Cancel();++ await queue.RunAsync(job);++ Assert.Equal(JobState.Cancelled, job.State);+ Assert.Equal(FileState.Cancelled, Assert.Single(job.Files).State);+ Assert.Empty(job.Outputs);+ Assert.Equal(before.OrderBy(p => p.Key), Snapshot(folder).OrderBy(p => p.Key));+ }+ }++ // ───────────────────────── C9: extremes ─────────────────────────++ [Fact]+ public async Task Extreme_heights_preserve_masks_and_overflows_fail()+ {+ var strikes = FonReader.Read(Data("Fon-edge.fon"));+ Assert.Equal([1, 256], strikes.Select(s => s.PixelHeight));+ foreach (var strike in strikes)+ {+ var height = strike.PixelHeight;+ var font = FonOutlineBuilder.Build(strike);+ Assert.Equal(1024, U16(font.Require("head"), 18));+ using var face = SKTypeface.FromStream(new MemoryStream(font.Write()));+ for (var code = 32; code <= 34; code++)+ AssertMask(ExpectedMask(code, 8, height), Render(face, code - 32 + 1, height, ArtAscent(height), 8), $"{height}px code {code}");+ }++ // x=32 at 1024 units per pixel is 32768: past signed 16-bit, an explicit error, never a wrapped coordinate.+ var pixels = new bool[1, 33];+ pixels[0, 32] = true;+ var overflowing = strikes[0] with { Glyphs = [new FonGlyph(32, 33, pixels)], DefaultChar = 0 };+ Assert.Contains("limits", Assert.Throws<InvalidDataException>(() => FonOutlineBuilder.Build(overflowing)).Message);+ // 31 pixels wide, x=30 lit: every coordinate and advance ends at 31 * 1024 = 31744 and fits.+ pixels = new bool[1, 31];+ pixels[0, 30] = true;+ var fits = FonOutlineBuilder.Build(strikes[0] with { Glyphs = [new FonGlyph(32, 31, pixels)], DefaultChar = 0 });+ Assert.Equal(31 * 1024, GlyfTable.ReadAll(fits)[1]!.XMax);++ // A bitmap that ends exactly at the end of the resource is read; one byte further is a clear error.+ var data = Data("Fon-v2-fixed.fon");+ var fnt = FntStart(data);+ var size = (int)BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(fnt + 2));+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(fnt + 0x76 + 2), (ushort)(size - 13));+ Assert.Single(FonReader.Read(data));+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(fnt + 0x76 + 2), (ushort)(size - 12));+ Assert.Contains("outside the resource", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);++ // Through the queue: an overflowing resource writes nothing.+ var source = Source(Container(WideOnePixelFnt()), out var folder);+ var job = await fx.ConvertAsync([source], PresetFor("ttf"));+ Assert.Equal(FileState.Failed, Assert.Single(job.Files).State);+ Assert.Equal(["Name.fon"], Directory.EnumerateFiles(folder).Select(Path.GetFileName));+ }++ // ───────────────────────── C10/C12: routes ─────────────────────────++ [Fact]+ public void Fon_edges_only_leave_existing_font_routes_intact()+ {+ var converter = fx.Converters.OfType<FontConverter>().Single();+ Assert.Equal(Formats.Select(t => ("fon", t)).Order(), converter.Edges.Where(e => e.From == "fon").Select(e => (e.From, e.To)).Order());+ Assert.DoesNotContain(fx.Converters.SelectMany(c => c.Edges), e => e.To == "fon");+ foreach (var from in Formats)+ foreach (var to in Formats.Where(t => t != from))+ Assert.Contains(new ConversionEdge(from, to), converter.Edges);+ Assert.Equal(20 + 5, converter.Edges.Count);++ var planner = fx.Catalog.CreatePlanner();+ foreach (var target in Formats)+ {+ Assert.Equal("font", Assert.Single(planner.Plan("fon", target)!.Steps).Converter.Id);+ Assert.Null(planner.Plan(target, "fon"));+ }+ }++ // ───────────────────────── Edge cases (problem definition, section 6) ─────────────────────────++ [Fact]+ public void Zero_pix_width_uses_each_entry_width()+ {+ var strike = Assert.Single(FonReader.Read(Data("Fon-v3-proportional.fon")));+ Assert.Equal(0, strike.PixelWidth);+ Assert.Equal(0, strike.Glyphs[0].Width);+ Assert.Equal(5, strike.Glyphs[1].Width);+ Assert.Equal(9, strike.Glyphs[2].Width);+ Assert.Equal((13, 5), (strike.Glyphs[1].Pixels.GetLength(0), strike.Glyphs[1].Pixels.GetLength(1)));+ Assert.True(strike.Glyphs[1].Pixels[0, 2]);+ Assert.False(strike.Glyphs[0].Pixels.Cast<bool>().Any());+ }++ [Fact]+ public void Control_bytes_and_delete_keep_glyphs()+ {+ var strike = Assert.Single(FonReader.Read(Data("Fon-v2-proportional.fon")));+ Assert.Equal(128, strike.Glyphs.Count);+ Assert.Equal((byte)0, strike.Glyphs[0].ByteValue);+ Assert.Equal((byte)31, strike.Glyphs[31].ByteValue);+ Assert.Equal((byte)127, strike.Glyphs[127].ByteValue);+ Assert.True(strike.Glyphs[127].Pixels[0, 2]);+ }++ [Theory]+ [InlineData("Fon-v2-fixed.fon", true)]+ [InlineData("Fon-v3-proportional.fon", false)]+ public void Blank_and_zero_width_glyphs_keep_metrics(string sample, bool isFixed)+ {+ var strike = Assert.Single(FonReader.Read(Data(sample)));+ var font = FonOutlineBuilder.Build(strike);+ var glyphs = GlyfTable.ReadAll(font);+ Assert.Equal(96 + 1, font.GlyphCount);+ Assert.Null(glyphs[1]); // the blank space, 0 or 8 pixels wide+ Assert.Equal((isFixed ? 8 : 0) * Scale(13), Advance(font, 1));+ Assert.Equal(0, Lsb(font, 1));+ Assert.Equal(1, Cmap(font)[0x20]);+ for (var code = 33; code <= 127; code++)+ Assert.Equal(ArtWidth(code, isFixed) * Scale(13), Advance(font, code - 32 + 1));+ }++ [Fact]+ public void Default_and_break_are_relative_indices()+ {+ var data = Data("Fon-v2-fixed.fon");+ var fnt = FntStart(data);+ data[fnt + 0x61] = 1;+ data[fnt + 0x62] = 2;+ var strike = Assert.Single(FonReader.Read(data));+ Assert.Equal((1, 2, (byte)33), (strike.DefaultChar, strike.BreakChar, strike.Glyphs[strike.DefaultChar].ByteValue));+ // .notdef is the default glyph (code 33, the single pixel); the break glyph (34) is not forced onto U+0020.+ var font = FonOutlineBuilder.Build(strike);+ var glyphs = GlyfTable.ReadAll(font);+ Assert.Equal(glyphs[2]!.Serialize(), glyphs[0]!.Serialize());+ Assert.Equal(Advance(font, 2), Advance(font, 0));+ Assert.Equal(1, Cmap(font)[0x20]);+ Assert.Equal(3, Cmap(font)[0x22]);++ data[fnt + 0x61] = 96;+ Assert.Contains("relative indices", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);+ }++ [Theory]+ [InlineData(0x04)]+ [InlineData(0x08)]+ [InlineData(0x10)]+ [InlineData(0x20)]+ [InlineData(0x40)]+ [InlineData(0x80)]+ public void V3_non_six_byte_flags_are_rejected_before_glyph_table(int flag)+ {+ var data = Data($"Fon-v3-flags-{flag:x2}.fon");+ var error = Assert.Throws<NotSupportedException>(() => FonReader.Read(data));+ Assert.Contains($"dfFlags 0x{flag:X8}", error.Message);+ }++ [Theory]+ [InlineData(0u)]+ [InlineData(3u)]+ [InlineData(5u)]+ public void V3_zero_or_mixed_flags_are_rejected(uint flags)+ {+ var data = Data("Fon-v3-fixed.fon");+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(FntStart(data) + 0x76), flags);+ var error = Assert.Throws<NotSupportedException>(() => FonReader.Read(data));+ Assert.Contains($"dfFlags 0x{flags:X8}", error.Message);+ }++ [Fact]+ public void Unsupported_containers_charsets_and_resources_fail_as_a_whole()+ {+ var data = Data("Fon-multi.fon");+ var second = FntStart(data, 1);+ data[second + 0x42] = 1;+ Assert.Contains("Vector", Assert.Throws<NotSupportedException>(() => FonReader.Read(data)).Message);+ data[second + 0x42] = 4;+ Assert.Contains("outside the file", Assert.Throws<NotSupportedException>(() => FonReader.Read(data)).Message);+ data[second + 0x42] = 0;+ foreach (var charset in new byte[] { 128, 129, 130, 134, 136, 2, 1, 255, 77, 99 }) // DBCS, SYMBOL, DEFAULT, OEM, MAC, unknown+ {+ data[second + 0x55] = charset;+ Assert.Contains("character set", Assert.Throws<NotSupportedException>(() => FonReader.Read(data)).Message);+ }+ data[second + 0x55] = 0;+ data[second] = 0;+ data[second + 1] = 1;+ Assert.Contains("version", Assert.Throws<NotSupportedException>(() => FonReader.Read(data)).Message);++ var pe = Data("Fon-v2-fixed.fon");+ pe[0x40] = (byte)'P';+ pe[0x41] = (byte)'E';+ Assert.Contains("PE FON", Assert.Throws<NotSupportedException>(() => FonReader.Read(pe)).Message);+ // A bare FNT and an MZ program without fonts.+ var fixedFon = Data("Fon-v2-fixed.fon");+ Assert.Contains("MZ", Assert.Throws<InvalidDataException>(() => FonReader.Read(fixedFon[FntStart(fixedFon)..])).Message);+ var program = Data("Fon-v2-fixed.fon");+ var ne = 0x40;+ var table = ne + BinaryPrimitives.ReadUInt16LittleEndian(program.AsSpan(ne + 0x24));+ BinaryPrimitives.WriteUInt16LittleEndian(program.AsSpan(table + 22), 0x8006);+ Assert.Contains("no RT_FONT", Assert.Throws<InvalidDataException>(() => FonReader.Read(program)).Message);+ }++ [Fact]+ public void Truncated_ne_fnt_and_face_never_produce_outputs()+ {+ var source = Data("Fon-v2-fixed.fon");+ Assert.Contains("NE header", Assert.Throws<InvalidDataException>(() => FonReader.Read(source[..0x40])).Message);+ var data = (byte[])source.Clone();+ var ne = 0x40;+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(ne + 0x26), 0x7fff);+ Assert.Contains("resource table", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);++ data = (byte[])source.Clone();+ var table = ne + BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(ne + 0x24));+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(table + 30), (ushort)table);+ Assert.Contains("overlapping", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);++ data = (byte[])source.Clone();+ var fnt = FntStart(data);+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(fnt + 2), 0x7fffffff);+ Assert.Contains("dfSize", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);++ data = (byte[])source.Clone();+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(fnt + 0x69), 0x7fffffff);+ Assert.Contains("face offset", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);++ data = (byte[])source.Clone();+ var size = (int)BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(fnt + 2));+ BinaryPrimitives.WriteUInt32LittleEndian(data.AsSpan(fnt + 0x69), (uint)(size - 1));+ data[fnt + size - 1] = (byte)'F';+ Assert.Contains("NUL", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);++ data = (byte[])source.Clone();+ BinaryPrimitives.WriteUInt16LittleEndian(data.AsSpan(fnt + 0x76 + 2), 0xffff);+ Assert.Contains("bitmap", Assert.Throws<InvalidDataException>(() => FonReader.Read(data)).Message);+ }++ [Fact]+ public void Builder_preserves_pixel_outlines_metrics_and_control_glyphs()+ {+ var strike = Assert.Single(FonReader.Read(Data("Fon-v2-proportional.fon")));+ var font = FonOutlineBuilder.Build(strike);+ Assert.Equal(strike.Glyphs.Count + 1, font.GlyphCount);+ Assert.Equal(13 * (1024 / 13), FontTables.UnitsPerEm(font.Require("head")));+ Assert.Equal(0x00010000u, font.Flavor);+ var glyphs = GlyfTable.ReadAll(font);+ var scaled = 1024 / 13;+ for (var i = 0; i < strike.Glyphs.Count; i++)+ {+ var original = strike.Glyphs[i];+ Assert.Equal(original.Width * scaled, Advance(font, i + 1));+ if (!original.Pixels.Cast<bool>().Any())+ {+ Assert.Null(glyphs[i + 1]);+ Assert.Equal(0, Lsb(font, i + 1));+ continue;+ }+ Assert.NotNull(glyphs[i + 1]);+ Assert.Equal(glyphs[i + 1]!.XMin, Lsb(font, i + 1));+ }+ Assert.Equal(glyphs[strike.DefaultChar + 1]?.Serialize(), glyphs[0]?.Serialize());+ Assert.Equal((ushort)0x40, BinaryPrimitives.ReadUInt16BigEndian(font.Require("OS/2").AsSpan(62)));+ }+}diff --git a/tests/Filee.Engines.Tests/Fonts/FON-FIXTURES.md b/tests/Filee.Engines.Tests/Fonts/FON-FIXTURES.mdnew file mode 100644index 00000000..b9a3384c--- /dev/null+++ b/tests/Filee.Engines.Tests/Fonts/FON-FIXTURES.md@@ -0,0 +1,31 @@+# Synthetic FON test fixtures++`make-test-fon.py` builds NE RT_FONT containers with FNT v2/v3 resources from pixel art defined in the script. No+bytes or outlines are taken from any existing font, so the samples are original synthetic data under the project's+MIT licence. The tests read only the committed files and never run the generator.++Rebuild: `uv run tests/Filee.Engines.Tests/Fonts/make-test-fon.py`++Check: `sha256sum tests/Filee.Engines.Tests/Fonts/Fon-*.fon`++| File | SHA-256 |+|---|---|+| Fon-v2-fixed.fon | `3b1b05572ba5ce6e0c011e5fb7bcc9ecedf367abd1d58fdb31dca161ca75e9f4` |+| Fon-v2-proportional.fon | `802ec675899d50afd8b22907a505c8029cb837d555b59dac76492267e977d4b2` |+| Fon-v3-fixed.fon | `ebc793d05862802a57ee2af3d2abd7425bd97a2957e3f4fd449a50863a8804a8` |+| Fon-v3-proportional.fon | `0744fc346722abd93f735a6bc42540ccdb5248b703d196d1b5c4dd957b88525d` |+| Fon-multi.fon | `e1f5379b11a5d4bddcfbb5b7c03c08556d8bb32528e973e58fcecb3290697273` |+| Fon-edge.fon | `fa8dd5d6424850d6054ae89685cffae30ab2b5757d13be86b97c8d3b24dd8b09` |+| Fon-v3-flags-04.fon | `6c789389ed490fd4f88dd1e67329ba10464cd76e0c22c1acb95eebf17142f03e` |+| Fon-v3-flags-08.fon | `c7f99f904af5d83d9b47603fe13645c701bca7ef1c22f362f181c1d506d0d6a3` |+| Fon-v3-flags-10.fon | `6e5538d1cf78a776f4631861da563163bcd087f7205ebd8898171a6f00071917` |+| Fon-v3-flags-20.fon | `c218cd58e2bfb33653cf0726137f4c6eb6943c73866d815c72feb43e8f77d58d` |+| Fon-v3-flags-40.fon | `86caba38ada299971ca997b458e6c15162f3765149aec8070ce1d7bb79d73365` |+| Fon-v3-flags-80.fon | `89f79b840576b013100e39f87fc306c71d5b161be6bc9eec77e8f5eafa965d5b` |++The basic samples cover 0x20..0x7F at 13 px; only the v2 proportional sample also holds the control codes+0x00..0x1F. The space is blank, `!` is a single pixel at `(2,0)`, `"` is a diagonal, and every other glyph is a+framed rectilinear shape. Proportional widths are 0 px for the space, 9 px for even codes and 5 px for odd codes.+`Fon-multi.fon` holds 13, 13 and 14 px resources, and `Fon-edge.fon` holds 1 and 256 px resources. The flag samples+check that unsupported v3 dfFlags are rejected; each uses a glyph table entry size, widths and offsets that differ+from the allowed 6-byte table. The external `fixed.fon` and `tektite.fon` are not included.diff --git a/tests/Filee.Engines.Tests/Fonts/Fon-edge.fon b/tests/Filee.Engines.Tests/Fonts/Fon-edge.fonnew file mode 100644index 00000000..3e5ff6d9Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-edge.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-multi.fon b/tests/Filee.Engines.Tests/Fonts/Fon-multi.fonnew file mode 100644index 00000000..98a152f4Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-multi.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v2-fixed.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v2-fixed.fonnew file mode 100644index 00000000..e141989cBinary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v2-fixed.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v2-proportional.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v2-proportional.fonnew file mode 100644index 00000000..e9ae81e9Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v2-proportional.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-fixed.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-fixed.fonnew file mode 100644index 00000000..298e1887Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-fixed.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-04.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-04.fonnew file mode 100644index 00000000..344c5192Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-04.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-08.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-08.fonnew file mode 100644index 00000000..c241cefaBinary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-08.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-10.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-10.fonnew file mode 100644index 00000000..abfc2685Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-10.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-20.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-20.fonnew file mode 100644index 00000000..daaa906dBinary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-20.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-40.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-40.fonnew file mode 100644index 00000000..dfa07c58Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-40.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-80.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-80.fonnew file mode 100644index 00000000..a3eddf0dBinary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-flags-80.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/Fon-v3-proportional.fon b/tests/Filee.Engines.Tests/Fonts/Fon-v3-proportional.fonnew file mode 100644index 00000000..f6327a63Binary files /dev/null and b/tests/Filee.Engines.Tests/Fonts/Fon-v3-proportional.fon differdiff --git a/tests/Filee.Engines.Tests/Fonts/make-test-fon.py b/tests/Filee.Engines.Tests/Fonts/make-test-fon.pynew file mode 100644index 00000000..64df49e8--- /dev/null+++ b/tests/Filee.Engines.Tests/Fonts/make-test-fon.py@@ -0,0 +1,136 @@+#!/usr/bin/env -S uv run --script+# /// script+# requires-python = ">=3.10"+# dependencies = []+# ///+# How to run: uv run tests/Filee.Engines.Tests/Fonts/make-test-fon.py+# Rebuild committed synthetic fixtures only when changing the generator; tests never run it.++from __future__ import annotations++import hashlib+import struct+from pathlib import Path++HERE = Path(__file__).resolve().parent+++def put(data: bytearray, offset: int, fmt: str, value: int) -> None:+ struct.pack_into("<" + fmt, data, offset, value)+++def fnt(version: int, height: int = 13, *, fixed: bool = True, first: int = 32,+ last: int = 127, flags: int | None = None) -> bytes:+ """Create a complete, independent FNT resource with column-major bitmaps."""+ count = last - first + 1+ # Rejected flag samples deliberately do not have the allowed 6-byte table.+ entry_size = 4 if version == 2 else 6 if flags is None else 8 + (flags.bit_length() - 3) * 2+ table = 0x76 if version == 2 else 0x94+ face = table + (count + 1) * entry_size+ bits = face + len(b"Fixed\0")+ data = bytearray(bits)+ put(data, 0, "H", version << 8)+ put(data, 0x42, "H", 0)+ put(data, 0x4A, "H", min(height, 10))+ put(data, 0x4E, "H", 2)+ put(data, 0x53, "H", 400)+ data[0x55] = 0+ put(data, 0x56, "H", 8 if fixed else 0)+ put(data, 0x58, "H", height)+ put(data, 0x5D, "H", 9)+ data[0x5F:0x63] = bytes((first, last, 0, 0))+ put(data, 0x69, "I", face)+ put(data, 0x71, "I", bits)+ if version == 3:+ put(data, 0x76, "I", flags if flags is not None else (1 if fixed else 2))+ if flags is not None:+ put(data, 0x7A, "H", flags + 1)+ put(data, 0x7C, "H", flags + 2)+ put(data, 0x7E, "H", flags + 3)+ data[face:bits] = b"Fixed\0"++ for index, code in enumerate(range(first, last + 1)):+ width = (flags + index % 3) if flags is not None else (+ 8 if fixed else (0 if code == 32 else 5 if code % 2 else 9))+ entry = table + index * entry_size+ put(data, entry, "H", width)+ if flags is not None:+ put(data, entry + 2, "H", flags + index % 3)+ put(data, entry + 4, "I", len(data))+ else:+ put(data, entry + 2, "H" if version == 2 else "I", len(data))+ # x=2 creates a left bearing; an isolated pixel, diagonal and hole are+ # defined independently of the parser. Space and zero-width glyphs are blank.+ for column in range((width + 7) // 8):+ for y in range(height):+ value = 0+ for bit in range(8):+ x = column * 8 + bit+ if x >= width or code == 32:+ continue+ lit = (code == 33 and x == 2 and y == 0) or (+ code == 34 and x == 2 + y % max(1, width - 2)) or (+ code != 33 and code != 34 and+ 2 <= x < width and y < min(height, 7) and+ (x in (2, width - 1) or y in (0, min(height, 7) - 1)))+ if lit:+ value |= 0x80 >> bit+ data.append(value)+ sentinel = table + count * entry_size+ put(data, sentinel, "H", 0)+ put(data, sentinel + (4 if flags is not None else 2),+ "I" if flags is not None or version == 3 else "H", len(data))+ put(data, 2, "I", len(data))+ return bytes(data)+++def fon(resources: list[bytes]) -> bytes:+ """Write MZ/NE, a FONTDIR entry, RT_FONT entries, and aligned FNT payloads."""+ ne = 0x40+ table = ne + 0x40+ payload = table + 2 + 8 + 12 + 8 + 12 * len(resources) + 2+ data = bytearray(payload)+ data[:2] = b"MZ"+ put(data, 0x3C, "I", ne)+ data[ne:ne + 2] = b"NE"+ put(data, ne + 0x24, "H", table - ne)+ put(data, ne + 0x26, "H", payload - ne)+ put(data, table + 2, "H", 0x8007)+ put(data, table + 4, "H", 1)+ put(data, table + 10, "H", len(data))+ put(data, table + 12, "H", 1)+ data.append(0)+ font_type = table + 22+ put(data, font_type, "H", 0x8008)+ put(data, font_type + 2, "H", len(resources))+ for index, resource in enumerate(resources):+ if len(data) > 0xFFFF or len(resource) > 0xFFFF:+ raise OverflowError("NE unshifted resource exceeds WORD range")+ entry = font_type + 8 + index * 12+ put(data, entry, "H", len(data))+ put(data, entry + 2, "H", len(resource))+ put(data, entry + 6, "H", 0x8001 + index)+ data.extend(resource)+ return bytes(data)+++def main() -> None:+ samples = {+ "Fon-v2-fixed.fon": [fnt(2)],+ "Fon-v2-proportional.fon": [fnt(2, fixed=False, first=0)],+ "Fon-v3-fixed.fon": [fnt(3)],+ "Fon-v3-proportional.fon": [fnt(3, fixed=False)],+ "Fon-multi.fon": [fnt(2), fnt(3), fnt(3, 14)],+ "Fon-edge.fon": [fnt(3, 1, first=32, last=34), fnt(3, 256, first=32, last=34)],+ }+ for flag in (0x04, 0x08, 0x10, 0x20, 0x40, 0x80):+ samples[f"Fon-v3-flags-{flag:02x}.fon"] = [fnt(3, flags=flag)]+ for name, resources in samples.items():+ path = HERE / name+ contents = fon(resources)+ path.write_bytes(contents)+ print(f"{hashlib.sha256(contents).hexdigest()} {path.name}")+++if __name__ == "__main__":+ main()