fix: preserve psd text padding alignment
This commit is contained in:
parent
43083ff90c
commit
d1ee239fd6
@ -589,6 +589,17 @@ export async function preparePsdTemplateRenderAssets(params: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentLayer.paddingX <= 0 &&
|
||||||
|
Number.isFinite(Number(analysis.suggestedPaddingX)) &&
|
||||||
|
Number(analysis.suggestedPaddingX) > 0
|
||||||
|
) {
|
||||||
|
nextLayer = {
|
||||||
|
...nextLayer,
|
||||||
|
paddingX: Math.max(0, Number(analysis.suggestedPaddingX)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (nextLayer !== currentLayer) {
|
if (nextLayer !== currentLayer) {
|
||||||
nextLayers[layerIndex] = nextLayer;
|
nextLayers[layerIndex] = nextLayer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,6 +131,17 @@ export async function resolveAgentPsdTemplateTextStyles(template: AgentPsdTempla
|
|||||||
textAlign: analysis.inferredTextAlign,
|
textAlign: analysis.inferredTextAlign,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
Number(nextLayer.paddingX || 0) <= 0 &&
|
||||||
|
Number.isFinite(Number(analysis?.suggestedPaddingX)) &&
|
||||||
|
Number(analysis?.suggestedPaddingX) > 0
|
||||||
|
) {
|
||||||
|
nextLayer = {
|
||||||
|
...nextLayer,
|
||||||
|
paddingX: Math.max(0, Number(analysis?.suggestedPaddingX)),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextLayer !== layer) {
|
if (nextLayer !== layer) {
|
||||||
|
|||||||
@ -199,20 +199,28 @@ export function analyzeTextLayerPixels(params: {
|
|||||||
);
|
);
|
||||||
const leftGap = minX;
|
const leftGap = minX;
|
||||||
const rightGap = Math.max(0, width - maxX - 1);
|
const rightGap = Math.max(0, width - maxX - 1);
|
||||||
const tolerance = Math.max(4, width * 0.08);
|
const centerTolerance = Math.max(4, width * 0.06);
|
||||||
const visibleWidth = maxX - minX + 1;
|
const edgeTolerance = Math.max(6, width * 0.08);
|
||||||
|
const contentCenterX = (minX + maxX) / 2;
|
||||||
|
const stageCenterX = (width - 1) / 2;
|
||||||
const inferredTextAlign: AgentPsdTextAlign =
|
const inferredTextAlign: AgentPsdTextAlign =
|
||||||
visibleWidth >= width * 0.92
|
Math.abs(contentCenterX - stageCenterX) <= centerTolerance &&
|
||||||
? "left"
|
Math.abs(leftGap - rightGap) <= edgeTolerance
|
||||||
: Math.abs(leftGap - rightGap) <= tolerance
|
|
||||||
? "center"
|
? "center"
|
||||||
: leftGap > rightGap
|
: leftGap > rightGap + edgeTolerance
|
||||||
? "right"
|
? "right"
|
||||||
: "left";
|
: "left";
|
||||||
|
const suggestedPaddingX =
|
||||||
|
inferredTextAlign === "right"
|
||||||
|
? Math.max(0, Math.round(rightGap))
|
||||||
|
: inferredTextAlign === "center"
|
||||||
|
? Math.max(0, Math.round(Math.min(leftGap, rightGap)))
|
||||||
|
: Math.max(0, Math.round(leftGap));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dominantColor,
|
dominantColor,
|
||||||
inferredTextAlign,
|
inferredTextAlign,
|
||||||
|
suggestedPaddingX,
|
||||||
visibleBounds: {
|
visibleBounds: {
|
||||||
minX,
|
minX,
|
||||||
minY,
|
minY,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user