atom-community / markdown-preview-plus

Markdown Preview + Community Features
https://atom.io/packages/markdown-preview-plus
Other
370 stars 85 forks source link

Image scaling issues with non-standard PPI OS settings #405

Closed kiwi0fruit closed 6 years ago

kiwi0fruit commented 6 years ago

There is one on Windows when screen scale is set to more than 96 px per inch (for example to 120). May be it's also on Linux - who knows. It's actually a webkit/electron (and other browsers as well) bug.

It happens on images of low resolution. In order to look good their size should not exceed the real size in pixels. Browser keeps their size below the real size... in px. The problem is that the browser's px is larger when scale is larger. So the image is displayed stretched and a bit blurry. I doubt that this would be fixed on browser side (or we can help bring the onset of this event).

For now this can be fixed via setting image size: ![Pic caption](pic/img.png){#fig:1 style="max-height: 400px;"} where 400px = real_size/1.25 for 1.25 scaled display. I guess this can be automated via js, I even tested script (and it worked):

function findFirstPositive(b, a, i, c) {
  c=(d,e)=>e>=d?(a=d+(e-d)/2,0<b(a)&&(a==d||0>=b(a-1))?a:0>=b(a)?c(a+1,e):c(d,a-1)):-1
  for (i = 1; 0 >= b(i);) i *= 2
  return c(i / 2, i)|0
}

var dpi = findFirstPositive(x => matchMedia(`(max-resolution: ${x}dpi)`).matches)

console.log(dpi)

I plan to fix it in future...

lierdakil commented 6 years ago

Not inclined to try to fix UI scaling issues on our end, that way lies madness. At least for now, this is a "wontfix", sorry.

kiwi0fruit commented 6 years ago

Unfortunately that's the only place to fix this issue. Dirty hacks are not madness but a working solutions ;)

lierdakil commented 6 years ago

Dirty hacks are unmaintainable by definition and we have plenty of those as is. In any case, I don't find the issue of "low-res images looking a bit crap with higher-than-usual PPI settings" to be bad enough to call for drastic measures on our end. Consider complaining on Chromium's bugtracker.

lierdakil commented 6 years ago

"Fixing" such issues on the client end is somewhat akin to "fixing" a blown fuse in a house by running an extension cord from a neighbour's power outlet. Works in a pinch, but not a viable long-term solution by any stretch of the imagination.

kiwi0fruit commented 6 years ago

That "non-standard" PPI settings are the de-facto standard on modern non 4K monitors. The problem is that when 4K would be the most common monitors the current behavior - scaling crappy images not preserving it's pixwidth - would be the best one. So I bet they won't fix it. It's already necessary on Windows (maybe non-Windows too) tablets with high PDI.

O don't really want you to fix this issue. So when/if I fix it then there at least would be something to discuss. I track this issue myself so if you want you can close it.

kiwi0fruit commented 6 years ago

I guess your analogy is not correct. It's all about doing things and not doing (and "nobody but us"). But I agree: that's not that awful issue :)

kiwi0fruit commented 6 years ago

I won't fix it either.