diff --git a/src/app/api/orders/[id]/design-spec/route.ts b/src/app/api/orders/[id]/design-spec/route.ts index 558d3d3..194bc23 100644 --- a/src/app/api/orders/[id]/design-spec/route.ts +++ b/src/app/api/orders/[id]/design-spec/route.ts @@ -45,24 +45,20 @@ export async function GET(req: Request, { params }: { params: { id: string } }) const printAreaWidthPx = DISPLAY * (printArea.wPct / 100); const printAreaHeightPx = DISPLAY * (printArea.hPct / 100); - // Scale: how many millimeters per pixel - const mmPerPx = printAreaWidthMm / printAreaWidthPx; + // Scale: how many centimeters per pixel + // printAreaWidthMm / printAreaWidthPx = mm/px + // Then divide by 10 to get cm/px + const cmPerPx = (printAreaWidthMm / printAreaWidthPx) / 10; // Convert pixel measurements to CM - // First: subtract the print area offset to get position within print area - // Then: multiply by mmPerPx to get millimeters - // Finally: divide by 10 to get centimeters - const convertToCm = (px: number, elementPx: number | null = null) => { - if (elementPx !== null) { - // For element positions: subtract offset and scale - const relativeToStart = elementPx - px; - const mm = Math.max(0, relativeToStart * mmPerPx); - return (mm / 10).toFixed(1); - } else { - // For dimensions: just scale - const mm = px * mmPerPx; - return (mm / 10).toFixed(1); - } + const convertToCm = (px: number) => { + return (px * cmPerPx).toFixed(1); + }; + + // Convert element position (subtract offset first, then scale) + const convertPositionToCm = (elementPx: number, offsetPx: number) => { + const relativeToStart = Math.max(0, elementPx - offsetPx); + return (relativeToStart * cmPerPx).toFixed(1); }; const generateDesignSection = (designElements: any[], side: 'Front' | 'Back', placement: string | null, designPreview: string | null) => { @@ -129,11 +125,11 @@ export async function GET(req: Request, { params }: { params: { id: string } }) E${idx + 1} ${el.type === 'text' ? '📝 Text' : '🖼️ Image'} - X: ${convertToCm(printAreaStartX, el.x)} | Y: ${convertToCm(printAreaStartY, el.y)} + X: ${convertPositionToCm(el.x, printAreaStartX)} | Y: ${convertPositionToCm(el.y, printAreaStartY)} ${el.type === 'image' ? `${convertToCm(el.width)} × ${convertToCm(el.height)}` : 'N/A'} ${el.type === 'text' ? ` - Font: ${el.fontFamily}, ${Math.round(el.fontSize * mmPerPx / 10)}pt
+ Font: ${el.fontFamily}, ${Math.round(el.fontSize * cmPerPx * 2.834)}pt
Color: ${el.fill}
Text: "${el.text}"
Rotation: ${Math.round(el.rotation)}°