Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing high-dpi check because it is not necessary anymore (and wrong implemented) #145

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

Falke-Design
Copy link
Contributor

With the commit 2e2239e a fix for screens with 150% resolution (#81) was added:

var margin = this.getPageMargin() * 2 * (window.devicePixelRatio || 1);
size.Width = Math.floor(size.Width - margin) + 'mm';
size.Height = Math.floor(size.Height - margin) + 'mm';
return size;

With the V2 rewrite the logic was implemented wrong. Before the devicePixelRatio was added to the margin and subtracted from the size, now it is multipled with the size.

var topbottom = orientaion === 'Portrait' ? parseFloat(pageMargin.top) + parseFloat(pageMargin.bottom) : parseFloat(pageMargin.left) + parseFloat(pageMargin.right);
var leftright = orientaion === 'Portrait' ? parseFloat(pageMargin.left) + parseFloat(pageMargin.right) : parseFloat(pageMargin.top) + parseFloat(pageMargin.bottom);
var height = Math.floor(size.Height - topbottom);
var width = Math.floor(size.Width - leftright);
size.Width = width * (window.devicePixelRatio || 1) + 'mm';
size.Height = height * (window.devicePixelRatio || 1) + 'mm';
return size;

Which causes that for displays with 150% scale, the map is rendered on two pages:
grafik

Removing the devicePixelRatio fixes the issue:
grafik

I checked out the old commit 2e2239e to see for which reasons the devicePixelRatio was added but it looks like it was never necessary? Maybe the browsers have changed printing too

var margin = this.getPageMargin() * 2 * (window.devicePixelRatio || 1);
size.Width = Math.floor(size.Width - margin) + 'mm';
size.Height = Math.floor(size.Height - margin) + 'mm';
return size;

Here are images of the commit with and without devicePixelRatio:

With devicePixelRatio: smaller margin and additional content is on the first page:
grafik

Without devicePixelRatio the margins are equal:
grafik

@Igor-Vladyka are you able to find out if the changes of 2e2239e are still needed?

Falke-Design added a commit to Falke-Design/leaflet.browser.print that referenced this pull request Dec 25, 2024
@Igor-Vladyka
Copy link
Owner

@Falke-Design nope, I don't remember why it was needed in a first place. Nice, thanks.

@Igor-Vladyka Igor-Vladyka merged commit 82cec52 into Igor-Vladyka:master Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants