[whatwg] Processing the zoom level - MS extensions to window.screen

Roger Hågensen rescator at emsai.net
Sat Dec 18 10:11:07 PST 2010


On 2010-12-18 18:58, Charles Pritchard wrote:
> On 11/24/2010 10:23 AM, Boris Zbarsky wrote:
>> On 11/24/10 4:13 AM, Charles Pritchard wrote:
>>>>> > And, these aren't great lengths. It's about 6 lines of javascript.
>>>> Uh... That depends on how your drawing path is set up. If I understand
>>>> correctly what you're doing, you have to get the DPI ration (call 
>>>> it N),
>>>> change the canvas width/height by a factor of N, and change all
>>>> coordinates in all your drawing calls by a factor of N, right?
>>>>
>>> You're correct, I grab DPI, lets call it xN and yN, I change the canvas
>>> width height.
>>> Then I run .scale(xN, xY) before my drawing calls. They're completely
>>> agnostic
>>> to the change.
>>
>> Ah, I see.  I assumed you were actually trying to draw the fonts at 
>> the right size for the viewer, see, as opposed to doing an image 
>> upscale of text rendered at a smaller size.
>>
>
> I frequently use scale(n,n) and scale(1/n,1/n) styles, as well as 
> translate, to set the offsets and ratio of my fillStyle
> when it's a pattern or gradient.
>
> Transformations are widely used by feature-rich canvas apps.
> font = (fontSize * fontScale) + 'px sans-serif';  is by no means foreign.
>
> While  translate can be used as a short-cut, for while-loops,
> its most important purpose is offsetting the fill style when painting 
> on textures.

Wouldn't a global (for the canvas) flag that sets the pixels/values to 
pseudopixels that are automatically translated (and thus DPI 
aware/scaled) make things a lot easier?
Windows does this, and so does the recent versions of MacOS and Linux 
GUIs as well.

In some Windows programs I make I get the OS DPI and calculate a 
modifier, this modifier is applied to all sizes so that 300px is scaled 
by say 1.07 if the user/OS is set at 102.72 DPI (well Windows would show 
this as 103 since it doesn't support float DPI, but my programs do)
But it would have been much easier if the scaling was automated under 
the hood and I could use just pseudo/virtual pixels, currently I have to 
wrap or apply scaling, .NET should handle it for you.
HTML (or rather CSS) has the "em", so canvas should also be able to do 
the same right?


-- 
Roger "Rescator" Hågensen.
Freelancer - http://www.EmSai.net/



More information about the whatwg mailing list