diff --git a/app/components/SvgImage/index.tsx b/app/components/SvgImage/index.tsx index a9bcde159..bb8b94358 100644 --- a/app/components/SvgImage/index.tsx +++ b/app/components/SvgImage/index.tsx @@ -10,14 +10,14 @@ import './index.scss'; type SvgImageProps = { image: string; isPrint?: boolean; - printOrientation?: 'portrait' | 'landscape'; + printOrientation?: 'portrait' | 'landscape' | 'auto'; }; // These should be same as index.css under @page // Accounts for padding via magical numbers 32 and 16 const INCH_TO_PX = 96; const MAX_PRINT_WIDTH = Math.floor((9 - 0.4 * 2) * INCH_TO_PX) - 32; -const MAX_PRINT_HEIGHT = Math.floor((11.5 - 0.4 * 2) * INCH_TO_PX) - 16; +const MAX_PRINT_HEIGHT = Math.floor((11.5 - 0.4 * 2) * INCH_TO_PX) - 64; const PRINT_WIDTH = 816; const ICON_WIDTH = 48; @@ -70,16 +70,34 @@ const SvgImage = ({ {({ width = PRINT_WIDTH }) => { if (isPrint) { - let overHeightRatio = svgHeight / MAX_PRINT_HEIGHT; - let overWidthRatio = svgWidth / MAX_PRINT_WIDTH; - if (printOrientation === 'landscape') { - overHeightRatio = svgHeight / MAX_PRINT_WIDTH; - overWidthRatio = svgWidth / MAX_PRINT_HEIGHT; + let overHeightRatio; + let overWidthRatio; + + switch (printOrientation) { + case 'landscape': + overHeightRatio = svgHeight / MAX_PRINT_WIDTH; + overWidthRatio = svgWidth / MAX_PRINT_HEIGHT; + break; + case 'auto': + if (svgWidth > svgHeight) { + overHeightRatio = svgHeight / MAX_PRINT_WIDTH; + overWidthRatio = svgWidth / MAX_PRINT_HEIGHT; + } else { + overHeightRatio = svgHeight / MAX_PRINT_HEIGHT; + overWidthRatio = svgWidth / MAX_PRINT_WIDTH; + } + break; + default: + // portrait + overHeightRatio = svgHeight / MAX_PRINT_HEIGHT; + overWidthRatio = svgWidth / MAX_PRINT_WIDTH; + break; } + let nextRatio = 1; if (overHeightRatio > 1 && overWidthRatio > 1) { - // Both over, find higher ratio + // Both over, find higher ratio nextRatio = Math.max(overHeightRatio, overWidthRatio); } else if (overHeightRatio > 1) { nextRatio = overHeightRatio; @@ -87,18 +105,22 @@ const SvgImage = ({ nextRatio = overWidthRatio; } - const nextHeight = svgHeight / nextRatio; - const nextWidth = svgWidth / nextRatio; + let transformCss = ''; + + if ( + printOrientation === 'landscape' + || (printOrientation === 'auto' && svgWidth > svgHeight) + ) { + transformCss = `rotate(90) translate(0 -${svgHeight * nextRatio})`; + } return ( ); diff --git a/package-lock.json b/package-lock.json index 1b05c30b0..1bd479cf6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,6 @@ "react-svg-pan-zoom": "~3.8.1", "react-virtualized-auto-sizer": "~1.0.20", "sanitize-html": "~2.11.0", - "svg-inline-react": "~3.2.1", "svg-pan-zoom": "~3.6.1", "use-debounce": "^9.0.4", "webpack": "^5.88.2", @@ -26526,20 +26525,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/svg-inline-react": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/svg-inline-react/-/svg-inline-react-3.2.1.tgz", - "integrity": "sha512-5/hM6wxca1BG9EyrWy8Q4ZQ6zHLMI805aTFia9ZeIeXu9VT3hdIvROWtBmzRM9at91/7odwylRMJ0B3OiDXUQQ==", - "dependencies": { - "prop-types": "^15.5.0" - }, - "engines": { - "node": ">=4" - }, - "peerDependencies": { - "react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17" - } - }, "node_modules/svg-pan-zoom": { "version": "3.6.1", "resolved": "https://registry.npmjs.org/svg-pan-zoom/-/svg-pan-zoom-3.6.1.tgz", @@ -48525,14 +48510,6 @@ "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" }, - "svg-inline-react": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/svg-inline-react/-/svg-inline-react-3.2.1.tgz", - "integrity": "sha512-5/hM6wxca1BG9EyrWy8Q4ZQ6zHLMI805aTFia9ZeIeXu9VT3hdIvROWtBmzRM9at91/7odwylRMJ0B3OiDXUQQ==", - "requires": { - "prop-types": "^15.5.0" - } - }, "svg-pan-zoom": { "version": "3.6.1", "resolved": "https://registry.npmjs.org/svg-pan-zoom/-/svg-pan-zoom-3.6.1.tgz", diff --git a/package.json b/package.json index f2446c70a..e9d8a86ee 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,6 @@ "react-svg-pan-zoom": "~3.8.1", "react-virtualized-auto-sizer": "~1.0.20", "sanitize-html": "~2.11.0", - "svg-inline-react": "~3.2.1", "svg-pan-zoom": "~3.6.1", "use-debounce": "^9.0.4", "webpack": "^5.88.2",