fix: render psd text layers without distortion
This commit is contained in:
parent
5776c852ba
commit
566449becd
@ -1353,6 +1353,15 @@ function getResolvedTextPreview(
|
||||
: layer.placeholder || layer.layerName;
|
||||
}
|
||||
|
||||
function hasRenderableTextLayerPreview(
|
||||
layer: AgentPsdTemplateTextLayerSlot,
|
||||
value?: string
|
||||
) {
|
||||
return Boolean(
|
||||
String(value || "").trim() || String(layer.placeholder || "").trim()
|
||||
);
|
||||
}
|
||||
|
||||
function getResolvedTextLayerColor(
|
||||
layer: AgentPsdTemplateTextLayerSlot,
|
||||
value?: string
|
||||
@ -4232,18 +4241,13 @@ export function AgentPsdTemplateEditorDialog({
|
||||
const textPositionOffset =
|
||||
effectiveTextPositionOffsets[layer.id] ||
|
||||
normalizeTextPositionOffset();
|
||||
const shouldUseEditedPreview =
|
||||
hasCustomizedTextLayerAppearance(
|
||||
layer,
|
||||
value,
|
||||
resolvedTextColor,
|
||||
textPositionOffset
|
||||
);
|
||||
const hasRenderableText =
|
||||
hasRenderableTextLayerPreview(layer, value);
|
||||
const layerPreviewSourceUrl =
|
||||
getPsdLayerPreviewSourceUrl(layer);
|
||||
|
||||
if (
|
||||
!shouldUseEditedPreview &&
|
||||
!hasRenderableText &&
|
||||
layerPreviewSourceUrl
|
||||
) {
|
||||
return (
|
||||
@ -4299,7 +4303,7 @@ export function AgentPsdTemplateEditorDialog({
|
||||
);
|
||||
}
|
||||
|
||||
if (!value && !layer.placeholder) {
|
||||
if (!hasRenderableText) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -4592,7 +4596,13 @@ export function AgentPsdTemplateEditorDialog({
|
||||
layer.textColor;
|
||||
const layerPreviewSourceUrl =
|
||||
getPsdLayerPreviewSourceUrl(layer);
|
||||
const hasRenderableText =
|
||||
hasRenderableTextLayerPreview(
|
||||
layer,
|
||||
currentValue
|
||||
);
|
||||
const preserveSourceAppearance =
|
||||
!hasRenderableText &&
|
||||
!!layerPreviewSourceUrl &&
|
||||
!hasCustomizedTextLayerAppearance(
|
||||
layer,
|
||||
@ -4639,7 +4649,8 @@ export function AgentPsdTemplateEditorDialog({
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
{preserveSourceAppearance ? null : (
|
||||
{!preserveSourceAppearance &&
|
||||
hasRenderableText ? (
|
||||
<div
|
||||
className="absolute"
|
||||
style={{
|
||||
@ -4655,7 +4666,7 @@ export function AgentPsdTemplateEditorDialog({
|
||||
resolvedTextColor
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -60,15 +60,6 @@ function normalizeTextPositionOffset(
|
||||
};
|
||||
}
|
||||
|
||||
function hasTextPositionOffset(
|
||||
value?: Partial<AgentPsdTextPositionOffset> | null
|
||||
) {
|
||||
const normalized = normalizeTextPositionOffset(value);
|
||||
return (
|
||||
Math.abs(normalized.offsetX) > 0.01 || Math.abs(normalized.offsetY) > 0.01
|
||||
);
|
||||
}
|
||||
|
||||
async function getSharp() {
|
||||
const sharp = await import("sharp");
|
||||
return sharp.default;
|
||||
@ -548,27 +539,15 @@ export async function renderAgentPsdTemplate(params: {
|
||||
const text = String(
|
||||
hasTextAssignment ? (textAssignments[layer.id] ?? "") : defaultText
|
||||
).trim();
|
||||
const textColor = normalizeHexColor(
|
||||
textColorAssignments[layer.id] || layer.textColor,
|
||||
layer.textColor
|
||||
);
|
||||
const hasColorChange =
|
||||
normalizeHexColor(textColor, layer.textColor) !==
|
||||
normalizeHexColor(layer.textColor);
|
||||
const textPositionOffset = normalizeTextPositionOffset(
|
||||
textPositionOffsets[layer.id]
|
||||
);
|
||||
const hasPositionChange = hasTextPositionOffset(textPositionOffset);
|
||||
|
||||
if (
|
||||
(!text && !hasTextAssignment) ||
|
||||
(text === defaultText && !hasColorChange && !hasPositionChange)
|
||||
) {
|
||||
pushAsset(
|
||||
storedLayerSourceUrl,
|
||||
"PSD 图层素材",
|
||||
shouldUseRenderBaseFallback
|
||||
);
|
||||
if (!text) {
|
||||
if (!hasTextAssignment) {
|
||||
pushAsset(
|
||||
storedLayerSourceUrl,
|
||||
"PSD 图层素材",
|
||||
shouldUseRenderBaseFallback
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const font = layer.fontId ? fontMap.get(layer.fontId) : undefined;
|
||||
pushAsset(font?.fileUrl, "PSD 字体资源", true);
|
||||
@ -858,14 +837,10 @@ export async function renderAgentPsdTemplate(params: {
|
||||
textColorAssignments[layer.id] || layer.textColor,
|
||||
layer.textColor
|
||||
);
|
||||
const hasColorChange =
|
||||
normalizeHexColor(textColor, layer.textColor) !==
|
||||
normalizeHexColor(layer.textColor);
|
||||
const layerPositionOffset = getLayerPositionOffset(layer.id);
|
||||
const textPositionOffset = normalizeTextPositionOffset(
|
||||
textPositionOffsets[layer.id]
|
||||
);
|
||||
const hasPositionChange = hasTextPositionOffset(textPositionOffset);
|
||||
if (!text) {
|
||||
if (!hasTextAssignment) {
|
||||
await appendStoredLayer(layer, {
|
||||
@ -874,12 +849,6 @@ export async function renderAgentPsdTemplate(params: {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (text === defaultText && !hasColorChange && !hasPositionChange) {
|
||||
await appendStoredLayer(layer, {
|
||||
optional: shouldUseRenderBaseFallback,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const textAlign = resolveAgentPsdTextLayerEffectiveAlign(layer);
|
||||
|
||||
const font = layer.fontId ? fontMap.get(layer.fontId) : undefined;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user