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) {
|
||||
nextLayers[layerIndex] = nextLayer;
|
||||
}
|
||||
|
||||
@ -131,6 +131,17 @@ export async function resolveAgentPsdTemplateTextStyles(template: AgentPsdTempla
|
||||
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) {
|
||||
|
||||
@ -199,20 +199,28 @@ export function analyzeTextLayerPixels(params: {
|
||||
);
|
||||
const leftGap = minX;
|
||||
const rightGap = Math.max(0, width - maxX - 1);
|
||||
const tolerance = Math.max(4, width * 0.08);
|
||||
const visibleWidth = maxX - minX + 1;
|
||||
const centerTolerance = Math.max(4, width * 0.06);
|
||||
const edgeTolerance = Math.max(6, width * 0.08);
|
||||
const contentCenterX = (minX + maxX) / 2;
|
||||
const stageCenterX = (width - 1) / 2;
|
||||
const inferredTextAlign: AgentPsdTextAlign =
|
||||
visibleWidth >= width * 0.92
|
||||
? "left"
|
||||
: Math.abs(leftGap - rightGap) <= tolerance
|
||||
Math.abs(contentCenterX - stageCenterX) <= centerTolerance &&
|
||||
Math.abs(leftGap - rightGap) <= edgeTolerance
|
||||
? "center"
|
||||
: leftGap > rightGap
|
||||
: leftGap > rightGap + edgeTolerance
|
||||
? "right"
|
||||
: "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 {
|
||||
dominantColor,
|
||||
inferredTextAlign,
|
||||
suggestedPaddingX,
|
||||
visibleBounds: {
|
||||
minX,
|
||||
minY,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user