mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-08-18 09:10:21 +03:00
feat(mxl-compile,mxl-decompile): параметр картинки у ячейки, прозрачность одним ключом
Ячейка получила третий параметр — pictureParameter, имя параметра, которым
подставляют картинку. Сама картинка задаётся оформлением (picIndex), а этот
тег живёт у ячейки, последним из её параметров, и уживается с текстом.
В корпусе таких ячеек 21 в 9 макетах; теперь все 21 возвращаются обратно.
Прозрачность картинки сведена к одному ключу transparent: false — фона нет,
{ x, y } — прозрачен цвет пикселя с этими координатами. Два способа записи
у платформы исключают друг друга (t принимает только false, включённую
прозрачность выражают tx/ty), так что двум ключам DSL соответствовал один
флажок диалога.
Заодно выровнен порядок ключей в проверке «объект описывает ячейку»: в
py-порте не хватало note.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# mxl-compile v1.49 — Compile 1C spreadsheet from JSON
|
||||
# mxl-compile v1.50 — Compile 1C spreadsheet from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -1307,7 +1307,7 @@ function Set-CellProp {
|
||||
function Test-CellObject {
|
||||
param($el)
|
||||
$cellKeys = @('col', 'span', 'rowspan', 'style', 'param', 'detail', 'text', 'template',
|
||||
'valueType', 'controlType', 'value', 'control', 'note')
|
||||
'valueType', 'controlType', 'value', 'control', 'note', 'pictureParameter')
|
||||
foreach ($p in $el.PSObject.Properties) {
|
||||
if ($cellKeys -contains $p.Name) { return $true }
|
||||
}
|
||||
@@ -1603,16 +1603,23 @@ if ($def.pictures) {
|
||||
$entry = @{ Ref = ''; Data = ''; Transparent = ''; PixelX = ''; PixelY = '' }
|
||||
if ($pr.Value.ref) { $entry.Ref = "$($pr.Value.ref)" }
|
||||
if ($null -ne $pr.Value.data) { $entry.Data = "$($pr.Value.data)" }
|
||||
if ($null -ne $pr.Value.transparent) {
|
||||
$entry.Transparent = if ($pr.Value.transparent -eq $true -or "$($pr.Value.transparent)" -eq 'true') { 'true' } else { 'false' }
|
||||
# Прозрачность — одна сущность диалога, записанная двумя способами: выключенную
|
||||
# платформа хранит атрибутом, включённую — координатами пикселя, чей цвет прозрачен.
|
||||
# Поэтому и ключ один, а форма значения выбирает способ.
|
||||
$tr = $pr.Value.transparent
|
||||
if ($null -ne $tr) {
|
||||
if ($tr -is [bool] -or "$tr" -ceq 'true' -or "$tr" -ceq 'false') {
|
||||
$entry.Transparent = if ($tr -eq $true -or "$tr" -ceq 'true') { 'true' } else { 'false' }
|
||||
} elseif ($null -ne $tr.x -and $null -ne $tr.y) {
|
||||
$entry.PixelX = "$([int]$tr.x)"
|
||||
$entry.PixelY = "$([int]$tr.y)"
|
||||
} else {
|
||||
[Console]::Error.WriteLine("pictures[$($pr.Name)]: 'transparent' is either false/true or { x, y }")
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
if ($null -ne $pr.Value.transparentPixel) {
|
||||
$entry.PixelX = "$([int]$pr.Value.transparentPixel.x)"
|
||||
$entry.PixelY = "$([int]$pr.Value.transparentPixel.y)"
|
||||
}
|
||||
if (-not $entry.Ref -and -not $entry.Data -and
|
||||
($entry.Transparent -or $entry.PixelX)) {
|
||||
[Console]::Error.WriteLine("pictures[$($pr.Name)]: 'transparent' and 'transparentPixel' require 'ref' or 'data'")
|
||||
if (-not $entry.Ref -and -not $entry.Data -and ($entry.Transparent -or $entry.PixelX)) {
|
||||
[Console]::Error.WriteLine("pictures[$($pr.Name)]: 'transparent' requires 'ref' or 'data'")
|
||||
exit 1
|
||||
}
|
||||
$pictureEntries += $entry
|
||||
@@ -1976,8 +1983,9 @@ foreach ($area in $def.areas) {
|
||||
$cellInfo = @{
|
||||
Col = $colStart - 1 # 0-based
|
||||
FormatIdx = $fmtIdx
|
||||
Param = $cell.param
|
||||
Detail = $cell.detail
|
||||
Param = $cell.param
|
||||
Detail = $cell.detail
|
||||
PictureParam = $cell.pictureParameter
|
||||
Text = $cell.text
|
||||
Template = $cell.template
|
||||
Value = $(if ($vp.Count -gt 0) { Get-CellValue $cell "$($vp['valueType'])" "area `"$areaName`", row $($localRow + 1)" } else { $null })
|
||||
@@ -2118,6 +2126,13 @@ foreach ($area in $def.areas) {
|
||||
X "`t`t`t`t`t<detailParameter>$($cellInfo.Detail)</detailParameter>"
|
||||
}
|
||||
|
||||
# Третий параметр ячейки — имя параметра, которым подставляют картинку. Сама
|
||||
# картинка при этом задаётся оформлением (picIndex), а параметр — тут, последним
|
||||
# из параметров ячейки (21 ячейка корпуса, порядок везде такой).
|
||||
if ($cellInfo.PictureParam) {
|
||||
X "`t`t`t`t`t<pictureParameter>$(Esc-XmlText $cellInfo.PictureParam)</pictureParameter>"
|
||||
}
|
||||
|
||||
# Якорь конца примечания — координаты самой ячейки, поэтому его не задают:
|
||||
# он выводится здесь, при эмиссии.
|
||||
if ($null -ne $cellInfo.Note) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# mxl-compile v1.49 — Compile 1C spreadsheet from JSON
|
||||
# mxl-compile v1.50 — Compile 1C spreadsheet from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
import argparse
|
||||
import hashlib
|
||||
@@ -1299,7 +1299,7 @@ def main():
|
||||
ключей есть ключ схемы ячейки, во втором ключи — идентификаторы языков. Пересечений
|
||||
нет: в корпусе это ru, en, ru1, Русский."""
|
||||
cell_keys = ('col', 'span', 'rowspan', 'style', 'param', 'detail', 'text', 'template',
|
||||
'valueType', 'controlType', 'value', 'control')
|
||||
'valueType', 'controlType', 'value', 'control', 'note', 'pictureParameter')
|
||||
return any(k in el for k in cell_keys)
|
||||
|
||||
def expand_shorthand_row(row, area_name, row_idx, open_by_col, max_cols):
|
||||
@@ -1560,14 +1560,21 @@ def main():
|
||||
entry['Ref'] = str(pic_def['ref'])
|
||||
if pic_def.get('data') is not None:
|
||||
entry['Data'] = str(pic_def['data'])
|
||||
if pic_def.get('transparent') is not None:
|
||||
entry['Transparent'] = 'true' if (pic_def['transparent'] is True
|
||||
or str(pic_def['transparent']).lower() == 'true') else 'false'
|
||||
if pic_def.get('transparentPixel') is not None:
|
||||
entry['PixelX'] = str(int(pic_def['transparentPixel'].get('x', 0)))
|
||||
entry['PixelY'] = str(int(pic_def['transparentPixel'].get('y', 0)))
|
||||
# Прозрачность — одна сущность диалога, записанная двумя способами: выключенную
|
||||
# платформа хранит атрибутом, включённую — координатами пикселя, чей цвет прозрачен.
|
||||
# Поэтому и ключ один, а форма значения выбирает способ.
|
||||
tr = pic_def.get('transparent')
|
||||
if tr is not None:
|
||||
if isinstance(tr, bool) or str(tr).lower() in ('true', 'false'):
|
||||
entry['Transparent'] = 'true' if (tr is True or str(tr).lower() == 'true') else 'false'
|
||||
elif isinstance(tr, dict) and 'x' in tr and 'y' in tr:
|
||||
entry['PixelX'] = str(int(tr['x']))
|
||||
entry['PixelY'] = str(int(tr['y']))
|
||||
else:
|
||||
print(f"pictures[{pic_name}]: 'transparent' is either false/true or {{ x, y }}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if not entry['Ref'] and not entry['Data'] and (entry['Transparent'] or entry['PixelX']):
|
||||
print(f"pictures[{pic_name}]: 'transparent' and 'transparentPixel' require 'ref' or 'data'", file=sys.stderr)
|
||||
print(f"pictures[{pic_name}]: 'transparent' requires 'ref' or 'data'", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
picture_entries.append(entry)
|
||||
picture_names[pic_name] = len(picture_entries)
|
||||
@@ -1885,6 +1892,7 @@ def main():
|
||||
'FormatIdx': fmt_idx,
|
||||
'Param': cell.get('param'),
|
||||
'Detail': cell.get('detail'),
|
||||
'PictureParam': cell.get('pictureParameter'),
|
||||
'Text': cell.get('text'),
|
||||
'Template': cell.get('template'),
|
||||
'Value': (cell_value(cell, vp.get('valueType', ''),
|
||||
@@ -2015,6 +2023,13 @@ def main():
|
||||
if cell_info['Detail']:
|
||||
lines.append(f'\t\t\t\t\t<detailParameter>{cell_info["Detail"]}</detailParameter>')
|
||||
|
||||
# Третий параметр ячейки — имя параметра, которым подставляют картинку. Сама
|
||||
# картинка при этом задаётся оформлением (picIndex), а параметр — тут, последним
|
||||
# из параметров ячейки (21 ячейка корпуса, порядок везде такой).
|
||||
if cell_info.get('PictureParam'):
|
||||
lines.append('\t\t\t\t\t<pictureParameter>'
|
||||
f'{esc_xml_text(cell_info["PictureParam"])}</pictureParameter>')
|
||||
|
||||
# Якорь конца примечания — координаты самой ячейки, поэтому его не задают:
|
||||
# он выводится здесь, при эмиссии.
|
||||
if cell_info.get('Note') is not None:
|
||||
|
||||
Reference in New Issue
Block a user