How does SetZoomLevel work?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How does SetZoomLevel work?

Postby nickb » Fri Feb 14, 2014 12:11 pm

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.

-Nick
nickb
Techie
 
Posts: 13
Joined: Mon Oct 08, 2012 6:41 am

Re: How does SetZoomLevel work?

Postby pchuong » Tue Apr 15, 2014 10:44 am

I also would like to know how the zoom level correlated to the zoom percentage of a given page.

Thanks,
Patrick
pchuong
Mentor
 
Posts: 73
Joined: Tue Nov 06, 2012 1:41 pm

Re: How does SetZoomLevel work?

Postby fasecero » Wed May 14, 2014 2:33 pm

I wonder if anyone has found a solution for this problem? The relation between zoom level and percent seems not to be lineal.
fasecero
Mentor
 
Posts: 60
Joined: Mon May 12, 2014 2:53 pm

Re: How does SetZoomLevel work?

Postby Czarek » Wed May 14, 2014 3:40 pm

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.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How does SetZoomLevel work?

Postby fasecero » Wed May 14, 2014 6:03 pm

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:
fasecero
Mentor
 
Posts: 60
Joined: Mon May 12, 2014 2:53 pm

Re: How does SetZoomLevel work?

Postby dam4rus » Wed Jun 18, 2014 3:29 am

I found this in the chromium issue tracker: https://code.google.com/p/chromium/issu ... 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.
dam4rus
Techie
 
Posts: 20
Joined: Thu Jul 25, 2013 4:01 am

Re: How does SetZoomLevel work?

Postby nedyalkov » Wed Jun 18, 2014 5:54 am

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!
nedyalkov
Newbie
 
Posts: 1
Joined: Wed Jun 18, 2014 5:48 am

Re: How does SetZoomLevel work?

Postby Bytexpert » Wed Oct 29, 2014 7:00 pm

Thank you for this topic, I used this conversion:

Scale := 1.2 ^ ZoomLevel;
ZoomLevel := LogN(1.2, Scale);
Bytexpert
Newbie
 
Posts: 1
Joined: Wed Oct 29, 2014 6:54 pm

Re: How does SetZoomLevel work?

Postby corinet » Mon Mar 06, 2017 5:46 am

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;
browser->GetHost()->SetZoomLevel(delta);
corinet
Newbie
 
Posts: 1
Joined: Mon Mar 06, 2017 5:43 am

Re: How does SetZoomLevel work?

Postby Rister » Tue Feb 14, 2023 4:42 am

taking nedyalkov formula (base = 1.2, which makes sense) the correct formula imho for high dpi match avoiding magic numbers and corrections is this

Code: Select all
SetZoomLevel(
  ln( ReportedDpi / 96 ) / ln(1.2)
)


ReportedDpi can be obtained with GetDeviceCaps(hdc, LOGPIXELSY)

For ReportedDpi: 96 = 0
For ReportedDpi: 120 (When Windows suggests 125% Increase) = 1.2239010857
For ReportedDpi: 192 (200%) = 3.8017840169
Rister
Newbie
 
Posts: 2
Joined: Thu Nov 17, 2022 6:55 am

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 38 guests