Page 1 of 1

How does SetZoomLevel work?

PostPosted: Fri Feb 14, 2014 12:11 pm
by nickb
There is a method on the browser called SetZoomLevel. This takes a double. I know that 0.0 means 100%; positive values are greater than 100% and negative ones are less. But say I wanted a zoom level of 150%, what value would I supply? A value of 1.5 seems to give around 130% zoom.


Re: How does SetZoomLevel work?

PostPosted: Tue Apr 15, 2014 10:44 am
by pchuong
I also would like to know how the zoom level correlated to the zoom percentage of a given page.


Re: How does SetZoomLevel work?

PostPosted: Wed May 14, 2014 2:33 pm
by fasecero
I wonder if anyone has found a solution for this problem? The relation between zoom level and percent seems not to be lineal.

Re: How does SetZoomLevel work?

PostPosted: Wed May 14, 2014 3:40 pm
by Czarek
That's the code I use to adjust zoom level to DPI settings in OS:
Code: Select all
    // Win7:
    // text size Larger 150% => ppix/ppiy 144
    // text size Medium 125% => ppix/ppiy 120
    // text size Smaller 100% => ppix/ppiy 96
    HWND cefHandle = cefBrowser->GetHost()->GetWindowHandle();
    HDC hdc = GetDC(cefHandle);
    int ppix = GetDeviceCaps(hdc, LOGPIXELSX);
    int ppiy = GetDeviceCaps(hdc, LOGPIXELSY);
    ReleaseDC(cefHandle, hdc);

    if (ppix > 96) {
        newZoomLevel = (ppix - 96) / 24;

It may not be exact/perfect scale, but it works well.

Re: How does SetZoomLevel work?

PostPosted: Wed May 14, 2014 6:03 pm
by fasecero
Thanks. Based in your code I managed to create these two functions that gives (it seems) approximate results too:

Code: Select all
int ZoomLevelToPercentage(double zoomlevel)
   return int((zoomlevel*25.0)+100.0);

double PercentageToToZoomLevel(int percent)
   return (double(percent-100))/25.0;

At least is right when you use zoomlevel = 0 and percentage = 100 :mrgreen:

Re: How does SetZoomLevel work?

PostPosted: Wed Jun 18, 2014 3:29 am
by dam4rus
I found this in the chromium issue tracker: ... l?id=71484

"Each zoom level increases the zoom by 20%. So you get 100%, 120%, 144%, and so on."

so, for positive values setting zoom level to 2.0 means the page is scaled to 144%, for negative values -2.0 means 1.0 / 1.44 = 69.4%. i think this is a pretty bad design choice on their part (i mean the WebKit team, this is a WebKit feature...) and i would like, if CEF somehow move away from this horrible concept.

Re: How does SetZoomLevel work?

PostPosted: Wed Jun 18, 2014 5:54 am
by nedyalkov
Hello Everybody,
Thank you very much for the information you shared! From what dam4rus said it seems to me that the actual scale factor is 1.2 on the grade of the zoom level as follows:
1.2^(-2.0) = 1.0/1.44 = 69.4%
1.2^2.0 = 1.44 = 144%
1.2^1.0 = 1.2 = 120%
1.2^0 = 1.0 = 100%
I tried this assumption with the CEF framework and the Chrome browser side by side and it seems to work flawlessly!

Re: How does SetZoomLevel work?

PostPosted: Wed Oct 29, 2014 7:00 pm
by Bytexpert
Thank you for this topic, I used this conversion:

Scale := 1.2 ^ ZoomLevel;
ZoomLevel := LogN(1.2, Scale);

Re: How does SetZoomLevel work?

PostPosted: Mon Mar 06, 2017 5:46 am
by corinet
I had measured zoom level display size of Internet Explorer 11 and cefclient with screen ruler and then mad two regression function with MS Excel.
y = 176e0.1831x , y = 1.7676x

I made this function by equation solving.
y = 5.46149645ln(x) - 25.12

- log(percent) means ln(percent)

double delta = 5.46149645*log(percent) - 25.12;