Skip to content

Commit 956b44d

Browse files
print sizing
1 parent aa908d2 commit 956b44d

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/components/docs/CardDisplay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function CardDisplay({ json, link, docKey }: DocDisplayProps<CardType>) {
1919
}
2020
const frontSvg = front.current.outerHTML
2121
const backSvg = back.current.outerHTML
22-
const name = `bc_${docKey}`
22+
const name = `bc_${docKey}${isCut ? '_cut' : ''}`
2323
await writeFile(dir, `${name}_front.svg`, encode(frontSvg))
2424
await writeFile(dir, `${name}_back.svg`, encode(backSvg))
2525
alert('Done.')

src/components/docs/CardSvg.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactNode, Ref } from "react";
1+
import type { CSSProperties, ReactNode, Ref } from "react";
22
import type { DocDisplayProps } from "@/components/docs/DocsDisplay";
33

44
export const CARD_WIDTH = 910
@@ -17,10 +17,15 @@ export type CardSvgProps = {
1717
ref?: Ref<SVGSVGElement>
1818
}
1919
export function CardSvg ({ isCut, children, background, ref }: CardSvgProps) {
20-
const viewBox = isCut
21-
? `0 0 ${CARD_WIDTH} ${CARD_HEIGHT}`
22-
: `${-PADDING} ${-PADDING} ${CARD_WIDTH + PADDING*2} ${CARD_HEIGHT + PADDING*2}`
23-
return <svg xmlns="http://www.w3.org/2000/svg" className="business-card" ref={ref} viewBox={viewBox} width={isCut ? CARD_WIDTH / 2 : (CARD_WIDTH + PADDING*2)/2}>
20+
const padding = isCut ? 0 : PADDING
21+
const width = CARD_WIDTH + padding * 2
22+
const height = CARD_HEIGHT + padding * 2
23+
const viewBox = `${-padding} ${-padding} ${width} ${height}`
24+
const style: CSSProperties = {
25+
width: `${width / 100}cm`,
26+
height: `${height / 100}cm`,
27+
}
28+
return <svg xmlns="http://www.w3.org/2000/svg" className="business-card" ref={ref} viewBox={viewBox} width={width / 2} style={style}>
2429
<rect x={-PADDING} y={-PADDING} width={CARD_WIDTH + PADDING * 2} height={CARD_HEIGHT + PADDING * 2} fill={background} />
2530
{children}
2631
</svg>

0 commit comments

Comments
 (0)