From f72dd544dd18488ac3f5f08cd5aace93e52a3f55 Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Tue, 11 Aug 2026 19:40:39 +0300 Subject: [PATCH] =?UTF-8?q?fix(mxl-compile):=20=D0=BD=D0=B5=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=8C=20=D0=B2=20=D0=BF=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D1=82=D1=80=D1=83=20=D1=88=D1=80=D0=B8=D1=84=D1=82,=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D1=82=D0=BE=20=D0=BD=D0=B5=20=D1=81=D1=81=D1=8B?= =?UTF-8?q?=D0=BB=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Мы всегда заводили шрифт Arial 10 по умолчанию, даже когда его никто не использует. Платформа так не делает: у макета без оформления элемента нет вовсе. Неиспользуемые шрифты теперь отбрасываются, ссылки перенумеровываются (индексы шрифтов позиционные). Проверено на контролируемом стенде: после правки простейший макет расходится с платформенным ровно одной строкой — объявлением языков в шапке. Кейс font-fractional-size дополнен: стиль, задающий ТОЛЬКО шрифт по умолчанию, равнозначен отсутствию оформления (ячейка получает 0), поэтому шрифт остаётся неиспользованным. Чтобы кейс продолжал проверять целый размер, стилю добавлено второе свойство. Co-Authored-By: Claude Opus 5 (1M context) --- .../mxl-compile/scripts/mxl-compile.ps1 | 26 +++++++- .../skills/mxl-compile/scripts/mxl-compile.py | 18 +++++- .../mxl-compile/font-fractional-size.json | 62 ++++++++++++++++--- .../font-fractional-size/Template.xml | 19 +++++- .../Демо/Templates/Макет/Ext/Template.xml | 1 - .../lenient-implicit-cols/Template.xml | 1 - .../snapshots/lenient-key-case/Template.xml | 1 - .../snapshots/minimal/Template.xml | 1 - .../Templates/Макет/Ext/Template.xml | 1 - .../snapshots/simple-template/Template.xml | 1 - .../styles-fonts-borders/Template.xml | 7 +-- .../snapshots/text-languages/Template.xml | 1 - .../output-absolute-path/Template.xml | 1 - .../snapshots/output-absolute-path/back.json | 2 +- .../roundtrip-text-languages/Template.xml | 1 - .../snapshots/roundtrip/Template.xml | 1 - .../snapshots/template-overview/Template.xml | 1 - .../snapshots/valid-template/Template.xml | 1 - 18 files changed, 115 insertions(+), 31 deletions(-) diff --git a/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 b/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 index 8acb1e82..50445a79 100644 --- a/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 +++ b/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 @@ -1,4 +1,4 @@ -# mxl-compile v1.34 — Compile 1C spreadsheet from JSON +# mxl-compile v1.35 — Compile 1C spreadsheet from JSON # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [Parameter(Mandatory)] @@ -1021,6 +1021,30 @@ foreach ($area in $def.areas) { # Формат по умолчанию — последняя запись палитры (см. выше). $defaultFormatIndex = Register-Format @{ width = $defaultWidth } +# Шрифт, на который не ссылается ни один формат, платформа в палитру не кладёт: у макета +# без оформления элемента нет вовсе. Мы же всегда заводили Arial 10 по умолчанию. +# Отбрасываем неиспользуемые и перенумеровываем ссылки — индексы шрифтов позиционные. +$usedFonts = @{} +foreach ($k in $formatRegistry.Keys) { + $fp = $formatRegistry[$k] + if ($fp.ContainsKey('font')) { $usedFonts[[int]$fp['font']] = $true } +} +if ($usedFonts.Count -lt $fontEntries.Count) { + $fontRemap = @{} + $kept = @() + for ($i = 0; $i -lt $fontEntries.Count; $i++) { + if ($usedFonts.ContainsKey($i)) { + $fontRemap[$i] = $kept.Count + $kept += $fontEntries[$i] + } + } + foreach ($k in @($formatRegistry.Keys)) { + $fp = $formatRegistry[$k] + if ($fp.ContainsKey('font')) { $fp['font'] = $fontRemap[[int]$fp['font']] } + } + $fontEntries = $kept +} + # --- 7. Generate XML --- $xml = New-Object System.Text.StringBuilder 4096 diff --git a/.claude/skills/mxl-compile/scripts/mxl-compile.py b/.claude/skills/mxl-compile/scripts/mxl-compile.py index 3b27e8ee..e58a2cb3 100644 --- a/.claude/skills/mxl-compile/scripts/mxl-compile.py +++ b/.claude/skills/mxl-compile/scripts/mxl-compile.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# mxl-compile v1.34 — Compile 1C spreadsheet from JSON +# mxl-compile v1.35 — Compile 1C spreadsheet from JSON # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills import argparse import hashlib @@ -1044,6 +1044,22 @@ def main(): # Формат по умолчанию — последняя запись палитры (см. выше). default_format_index = register_format({'width': default_width}) + # Шрифт, на который не ссылается ни один формат, платформа в палитру не кладёт: у макета + # без оформления элемента нет вовсе. Мы же всегда заводили Arial 10 по умолчанию. + # Отбрасываем неиспользуемые и перенумеровываем ссылки — индексы шрифтов позиционные. + used_fonts = {int(fp['font']) for fp in format_registry.values() if 'font' in fp} + if len(used_fonts) < len(font_entries): + font_remap = {} + kept = [] + for i in range(len(font_entries)): + if i in used_fonts: + font_remap[i] = len(kept) + kept.append(font_entries[i]) + for fp in format_registry.values(): + if 'font' in fp: + fp['font'] = font_remap[int(fp['font'])] + font_entries = kept + # --- 7. Generate XML --- lines = [] diff --git a/tests/skills/cases/mxl-compile/font-fractional-size.json b/tests/skills/cases/mxl-compile/font-fractional-size.json index 588cf0e2..9eb6cdcb 100644 --- a/tests/skills/cases/mxl-compile/font-fractional-size.json +++ b/tests/skills/cases/mxl-compile/font-fractional-size.json @@ -1,21 +1,57 @@ { "name": "Дробный размер шрифта сохраняется", "input": { - "columns": 2, + "columns": 3, "fonts": { - "default": { "face": "Arial", "size": 10 }, - "мелкий": { "face": "Arial", "size": 8.3 }, - "крупный": { "face": "Arial", "size": 11.3, "bold": true } + "default": { + "face": "Arial", + "size": 10 + }, + "мелкий": { + "face": "Arial", + "size": 8.3 + }, + "крупный": { + "face": "Arial", + "size": 11.3, + "bold": true + } }, "styles": { - "мелкий": { "font": "мелкий" }, - "крупный": { "font": "крупный" } + "мелкий": { + "font": "мелкий" + }, + "крупный": { + "font": "крупный" + }, + "обычный": { + "font": "default", + "horizontalAlignment": "Center" + } }, "areas": [ { "name": "Шапка", "rows": [ - { "cells": [{ "col": 1, "style": "крупный", "text": "Заголовок" }, { "col": 2, "style": "мелкий", "text": "сноска" }] } + { + "cells": [ + { + "col": 1, + "style": "крупный", + "text": "Заголовок" + }, + { + "col": 2, + "style": "мелкий", + "text": "сноска" + }, + { + "col": 3, + "style": "обычный", + "text": "обычный" + } + ] + } ] } ] @@ -25,10 +61,16 @@ }, "validatePath": "Template.xml", "expect": { - "files": ["Template.xml"], + "files": [ + "Template.xml" + ], "fileContains": { "file": "Template.xml", - "text": ["height=\"8.3\"", "height=\"11.3\"", "height=\"10\""] + "text": [ + "height=\"8.3\"", + "height=\"11.3\"", + "height=\"10\"" + ] } } -} +} \ No newline at end of file diff --git a/tests/skills/cases/mxl-compile/snapshots/font-fractional-size/Template.xml b/tests/skills/cases/mxl-compile/snapshots/font-fractional-size/Template.xml index ddf3e8bb..62f93059 100644 --- a/tests/skills/cases/mxl-compile/snapshots/font-fractional-size/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/font-fractional-size/Template.xml @@ -10,7 +10,7 @@ - 2 + 3 0 @@ -37,10 +37,21 @@ + + + 3 + + + ru + обычный + + + + true - 3 + 4 1 1 @@ -62,6 +73,10 @@ 1 + + 0 + Center + 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/guard-allow-external/print-forms/Демо/Templates/Макет/Ext/Template.xml b/tests/skills/cases/mxl-compile/snapshots/guard-allow-external/print-forms/Демо/Templates/Макет/Ext/Template.xml index 43c2069e..c15a2c06 100644 --- a/tests/skills/cases/mxl-compile/snapshots/guard-allow-external/print-forms/Демо/Templates/Макет/Ext/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/guard-allow-external/print-forms/Демо/Templates/Макет/Ext/Template.xml @@ -42,7 +42,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/lenient-implicit-cols/Template.xml b/tests/skills/cases/mxl-compile/snapshots/lenient-implicit-cols/Template.xml index 5e162bf2..70347a8b 100644 --- a/tests/skills/cases/mxl-compile/snapshots/lenient-implicit-cols/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/lenient-implicit-cols/Template.xml @@ -169,7 +169,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/lenient-key-case/Template.xml b/tests/skills/cases/mxl-compile/snapshots/lenient-key-case/Template.xml index 9730ab83..2a5e77eb 100644 --- a/tests/skills/cases/mxl-compile/snapshots/lenient-key-case/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/lenient-key-case/Template.xml @@ -64,7 +64,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/minimal/Template.xml b/tests/skills/cases/mxl-compile/snapshots/minimal/Template.xml index 2ee2927a..3ee316a1 100644 --- a/tests/skills/cases/mxl-compile/snapshots/minimal/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/minimal/Template.xml @@ -42,7 +42,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/nested-output-dir/Templates/Макет/Ext/Template.xml b/tests/skills/cases/mxl-compile/snapshots/nested-output-dir/Templates/Макет/Ext/Template.xml index 5b303f7f..f0112ad4 100644 --- a/tests/skills/cases/mxl-compile/snapshots/nested-output-dir/Templates/Макет/Ext/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/nested-output-dir/Templates/Макет/Ext/Template.xml @@ -42,7 +42,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/simple-template/Template.xml b/tests/skills/cases/mxl-compile/snapshots/simple-template/Template.xml index 9730ab83..2a5e77eb 100644 --- a/tests/skills/cases/mxl-compile/snapshots/simple-template/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/simple-template/Template.xml @@ -64,7 +64,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-compile/snapshots/styles-fonts-borders/Template.xml b/tests/skills/cases/mxl-compile/snapshots/styles-fonts-borders/Template.xml index 09d72786..3add3720 100644 --- a/tests/skills/cases/mxl-compile/snapshots/styles-fonts-borders/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/styles-fonts-borders/Template.xml @@ -280,7 +280,6 @@ - @@ -288,7 +287,7 @@ 25 - 3 + 2 Center @@ -296,7 +295,7 @@ 0 - 5 + 4 Parameter @@ -340,7 +339,7 @@ Parameter - 4 + 3 Center diff --git a/tests/skills/cases/mxl-compile/snapshots/text-languages/Template.xml b/tests/skills/cases/mxl-compile/snapshots/text-languages/Template.xml index 05fd4121..d00d2128 100644 --- a/tests/skills/cases/mxl-compile/snapshots/text-languages/Template.xml +++ b/tests/skills/cases/mxl-compile/snapshots/text-languages/Template.xml @@ -61,7 +61,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/Template.xml b/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/Template.xml index 7d4eb860..5ebbac09 100644 --- a/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/Template.xml +++ b/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/Template.xml @@ -53,7 +53,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/back.json b/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/back.json index e10c9948..84121a49 100644 --- a/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/back.json +++ b/tests/skills/cases/mxl-decompile/snapshots/output-absolute-path/back.json @@ -1 +1 @@ -{ "columns": 2, "defaultWidth": 10, "fonts": { "default": { "face": "Arial", "size": 10 } }, "styles": {}, "areas": [{ "name": "Test", "rows": [["A", "B"]] }] } \ No newline at end of file +{ "columns": 2, "defaultWidth": 10, "fonts": {}, "styles": {}, "areas": [{ "name": "Test", "rows": [["A", "B"]] }] } \ No newline at end of file diff --git a/tests/skills/cases/mxl-decompile/snapshots/roundtrip-text-languages/Template.xml b/tests/skills/cases/mxl-decompile/snapshots/roundtrip-text-languages/Template.xml index 85e9a3d6..e07b102c 100644 --- a/tests/skills/cases/mxl-decompile/snapshots/roundtrip-text-languages/Template.xml +++ b/tests/skills/cases/mxl-decompile/snapshots/roundtrip-text-languages/Template.xml @@ -61,7 +61,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-decompile/snapshots/roundtrip/Template.xml b/tests/skills/cases/mxl-decompile/snapshots/roundtrip/Template.xml index 5a286987..4efabfbe 100644 --- a/tests/skills/cases/mxl-decompile/snapshots/roundtrip/Template.xml +++ b/tests/skills/cases/mxl-decompile/snapshots/roundtrip/Template.xml @@ -64,7 +64,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-info/snapshots/template-overview/Template.xml b/tests/skills/cases/mxl-info/snapshots/template-overview/Template.xml index fe6e83df..3312aa47 100644 --- a/tests/skills/cases/mxl-info/snapshots/template-overview/Template.xml +++ b/tests/skills/cases/mxl-info/snapshots/template-overview/Template.xml @@ -64,7 +64,6 @@ -1 - 10 diff --git a/tests/skills/cases/mxl-validate/snapshots/valid-template/Template.xml b/tests/skills/cases/mxl-validate/snapshots/valid-template/Template.xml index 5a286987..4efabfbe 100644 --- a/tests/skills/cases/mxl-validate/snapshots/valid-template/Template.xml +++ b/tests/skills/cases/mxl-validate/snapshots/valid-template/Template.xml @@ -64,7 +64,6 @@ -1 - 10