Skip to content

Commit

Permalink
fix: page dpi (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikischin authored Jun 24, 2024
1 parent dd29fea commit 8e6a832
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .changeset/pretty-jars-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@react-pdf/layout': minor
'@react-pdf/pdfkit': minor
'@react-pdf/render': minor
'@react-pdf/stylesheet': minor
'@react-pdf/types': minor
---

fix: fix dpi
9 changes: 5 additions & 4 deletions packages/layout/src/page/getSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const flipSizeObject = (v) => ({ width: v.height, height: v.width });
* @returns {{ width: number, height: number }} adjusted size object
*/
const adjustDpi = (v, dpi) => ({
width: v.width ? v.width * dpi : v.width,
height: v.height ? v.height * dpi : v.height,
width: v.width ? v.width * (72 / dpi) : v.width,
height: v.height ? v.height * (72 / dpi) : v.height,
});

/**
Expand Down Expand Up @@ -121,14 +121,15 @@ const getSize = (page) => {
size = getStringSize(value);
} else if (Array.isArray(value)) {
size = toSizeObject(value);
size = adjustDpi(size, dpi);
} else if (type === 'number') {
size = getNumberSize(value);
size = adjustDpi(size, dpi);
} else {
size = value;
size = adjustDpi(size, dpi);
}

size = adjustDpi(size, dpi / 72);

return isLandscape(page) ? flipSizeObject(size) : size;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/steps/resolveStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const resolveNodeStyles = (container) => (node) => {
* @returns {Object} document page with resolved styles
*/
export const resolvePageStyles = (page) => {
const dpi = page.props?.dpi || 72;
const dpi = 72; // Removed: page.props?.dpi || 72;
const width = page.box?.width || page.style.width;
const height = page.box?.height || page.style.height;
const orientation = page.props?.orientation || 'portrait';
Expand Down
2 changes: 1 addition & 1 deletion packages/stylesheet/src/transform/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const parseValue = (value) => {
const transformUnit = (container, value) => {
const scalar = parseValue(value);

const dpi = container.dpi || 72;
const dpi = 72; // Removed: container.dpi || 72
const mmFactor = (1 / 25.4) * dpi;
const cmFactor = (1 / 2.54) * dpi;

Expand Down

0 comments on commit 8e6a832

Please sign in to comment.