fix: Aptly v obrazkoch kariet pre e-mail, pismeno za l s makcenom na riadku
- export vlozi pisma z Adobe Fonts do html-to-image (fontEmbedCSS); kniznica ich sama z CSS na inej domene s @import nenacitala a karty mali nahradne pismo - pritiahnutie za l/t/d cez zoznam dx na <text> namiesto vnoreneho <tspan> - novy kluc obrazkov kariet (v2), aby sa pri dalsom exporte pretvorili Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
31dfa7d336
commit
50af94f954
3 files changed
+63
-10
No files matched your search
+17
-9
@@ -186,23 +186,26 @@ export function renderCleanBadgeSvg(
|
||||
|
||||
// Formátovanie textu: ak obsahuje {cena} alebo {centy}, centy vložíme do <tspan> ako horný index
|
||||
let contentSvg = '';
|
||||
let caronDx = ''; // posuny písmen za ľ/ť/ď (atribút dx na <text>, bez vnorených tspan)
|
||||
if (priceMatch) {
|
||||
const [tokMain, tokSub] = badgePriceParts(priceMatch[1], product);
|
||||
const idx = priceMatch.index || 0;
|
||||
const before = tightenCarons(escapeXml(replaceBadgeTextVars(rawText.slice(0, idx), product)));
|
||||
const after = tightenCarons(escapeXml(replaceBadgeTextVars(rawText.slice(idx + priceMatch[0].length), product)));
|
||||
const before = escapeXml(replaceBadgeTextVars(rawText.slice(0, idx), product));
|
||||
const after = escapeXml(replaceBadgeTextVars(rawText.slice(idx + priceMatch[0].length), product));
|
||||
contentSvg = `${before}${escapeXml(tokMain)}<tspan font-size="${subFontSize}px" dx="${subDx}" dy="${subDy}" font-weight="${fontWeight}">${escapeXml(tokSub)}</tspan>${after ? `<tspan dy="${revertDy}">${after}</tspan>` : ''}`;
|
||||
} else if (rawText.includes('{centy}')) {
|
||||
const parts = rawText.split('{centy}');
|
||||
const before = tightenCarons(escapeXml(parts[0] || ''));
|
||||
const after = tightenCarons(escapeXml(parts[1] || ''));
|
||||
const before = escapeXml(parts[0] || '');
|
||||
const after = escapeXml(parts[1] || '');
|
||||
contentSvg = `${before}<tspan font-size="${subFontSize}px" dx="${subDx}" dy="${subDy}" font-weight="${fontWeight}">${escapeXml(pSub)}</tspan>${after ? `<tspan dy="${revertDy}">${after}</tspan>` : ''}`;
|
||||
} else {
|
||||
contentSvg = tightenCarons(escapeXml(replaceBadgeTextVars(rawText, product)));
|
||||
const plain = replaceBadgeTextVars(rawText, product);
|
||||
contentSvg = escapeXml(plain);
|
||||
caronDx = caronOffsets(plain, fontSize);
|
||||
}
|
||||
|
||||
// data-layer-index: editor cenoviek podľa neho nájde a odmeria vrstvu na plátne
|
||||
return `<text data-layer-index="${layerIndex}" x="${layer.x}" y="${layerY}" text-anchor="${anchor}" dominant-baseline="central"${layer.letterSpacing ? ` letter-spacing="${layer.letterSpacing}em"` : ''} font-family="${fontFamily}" font-size="${fontSize}px" font-weight="${fontWeight}" fill="${fill}">${contentSvg}</text>`;
|
||||
return `<text data-layer-index="${layerIndex}" x="${layer.x}" y="${layerY}" text-anchor="${anchor}" dominant-baseline="central"${caronDx ? ` dx="${caronDx}"` : ''}${layer.letterSpacing ? ` letter-spacing="${layer.letterSpacing}em"` : ''} font-family="${fontFamily}" font-size="${fontSize}px" font-weight="${fontWeight}" fill="${fill}">${contentSvg}</text>`;
|
||||
}).join('\n ');
|
||||
|
||||
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="${vb}" width="${displayWidth}" height="${displayHeight}" style="display:block;max-width:100%;height:auto;">
|
||||
@@ -263,9 +266,14 @@ export async function svgToCleanPng(
|
||||
});
|
||||
}
|
||||
|
||||
// Mäkčeň pri ľ, ť, ď je v písme široký – písmeno za ním trochu pritiahneme (ako v návrhoch z Illustratora)
|
||||
function tightenCarons(text: string): string {
|
||||
return text.replace(/([ľťď])([^\s<&])/g, '$1<tspan dx="-0.05em">$2</tspan>');
|
||||
// Mäkčeň pri ľ, ť, ď je v písme široký – písmeno za ním trochu pritiahneme (ako v návrhoch z Illustratora).
|
||||
// Posun ide do zoznamu dx priamo na <text> (po znakoch), nie do vnoreného <tspan> – ten pri prevode karty
|
||||
// na obrázok strácal zarovnanie na strednú účiaru a písmeno vyskočilo z riadku.
|
||||
function caronOffsets(text: string, fontSize: number): string {
|
||||
const chars = [...text];
|
||||
const shift = -Math.round(fontSize * 0.05 * 100) / 100;
|
||||
const dx = chars.map((c, i) => (i > 0 && /[ľťď]/.test(chars[i - 1]) && !/\s/.test(c) ? shift : 0));
|
||||
return dx.some(Boolean) ? dx.join(' ') : '';
|
||||
}
|
||||
|
||||
function escapeXml(unsafe: string): string {
|
||||
|
||||
Reference in new issue
Block a user