From cairo Wed Mar 20 11:36:34 2024 From: Federico Angelilli Date: Wed, 20 Mar 2024 11:36:34 +0000 To: cairo Subject: Re: Implementing HiDpi scaling Message-Id: <5FD945CD-5641-4A63-963F-3140F6513831 () fedang ! net> X-MARC-Message: https://marc.info/?l=cairo&m=171093447028476 MIME-Version: 1 Content-Type: multipart/mixed; boundary="------76MKK3S31ZRNSLHPNNUNRC84ZSRMQJ" ------76MKK3S31ZRNSLHPNNUNRC84ZSRMQJ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Sorry for the late reply=2E I am using cairo for drawing and pango for the text=2E I am creating a win= dow with xcb and using cairo_xcb_surface=2E I can easily extract the dpi information from the xrandr api calls=2E Now = that I have this ratio, I have to use it somewhere to scale my canvas appro= priately=2E I will try using cairo_scale, and should I also scale the size of the xcb_= surface by the same ratio? Anyway my main concern about antialising is that since I am making layered= shapes (think buttons) the border and the background will not match up pix= el perfect (which is something that I have seen in other project using cair= o)=2E Does what I described about scaling the surface makes sense or am I misint= erpreting cairo_scale? Regards Ps: I will soon try and post the results=20 On March 18, 2024 1:46:54 PM GMT+01:00, Dov Grobgeld wrote: >I think that you should describe in detail what you expect=2E > >In pure vector graphics a contour may cut through a pixel and partially >obscure it, and it is then the responsibility of the graphics engine to >create anti-aliased graphics by mixing the colors of the background and t= he >foreground=2E As a user you typically don't need to concern yourself with >that as it is done automatically=2E > >However, e=2Eg=2E for text this may cause "fuzzy" characters and the engi= ne >will then fallback to moving the contours and scale the font so that the >glyphs fall on whole pixels=2E > >Note that the use of anti-aliased graphics is less needed, and less >visible, for an HDPI device=2E > >In any case all that you will typically need is cairo_scale() as Uli >Shlachter already described=2E > >Try it! > >Regards, > > >On Sun, Mar 17, 2024 at 12:46=E2=80=AFPM Federico Angelilli wrote: > >> Hi >> >> Will cairo_scale make a pixel perfect image for non integer scales? To = my >> understanding the scale matrix will be multiplied to all the coordinate= s >> scaling the coordinates appropriately=2E Should I also scale the whole >> surface by that same factor? >> >> Regards >> >> >> On March 16, 2024 6:27:56 PM GMT+01:00, Uli Schlachter >> wrote: >> >>> Hi >>> >>> Am 14=2E03=2E24 um 16:34 schrieb fedang: >>> >>>> Hello all, >>>> >>>> I am writing a small X11 app using cairo as the drawing backend=2E I = was wondering if and how to implement >>>> fractional scaling to accommodate high dpi screens=2E After searching= online I found almost nothing, so here I am=2E >>>> >>>> Can someone give me some pointers on what to do? I can get a scale fa= ctor for the screens (depending on the size) >>>> but I have no idea how to actually use it in the draw code=2E >>>> >>> >>> I'm not sure if I understand the question=2E You can use cairo_scale()= to set a scale factor for all drawing=2E So I would say that you can just = apply the scale factor with cairo_scale() before drawing=2E >>> >>> Of course, this assumes that you don't use cairo_identity_matrix() or = cairo_set_matrix() in your drawing=2E Instead, cairo_save() and cairo_resto= re() should be used around temporary modifications of the transformations= =2E >>> >>> Cheers, >>> Uli >>> >>> ------76MKK3S31ZRNSLHPNNUNRC84ZSRMQJ Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello,
Sorry for the late rep= ly=2E

I am using cairo for drawing and pango for the text=2E I am cr= eating a window with xcb and using cairo_xcb_surface=2E

I can easily= extract the dpi information from the xrandr api calls=2E Now that I have t= his ratio, I have to use it somewhere to scale my canvas appropriately=2E
I will try using cairo_scale, and should I also scale the size of the= xcb_surface by the same ratio?

Anyway my main concern about antiali= sing is that since I am making layered shapes (think buttons) the border an= d the background will not match up pixel perfect (which is something that I= have seen in other project using cairo)=2E

Does what I described ab= out scaling the surface makes sense or am I misinterpreting cairo_scale?
Regards

Ps:
I will soon try and post the results
<= br>
On March 18, 2024 1:46:= 54 PM GMT+01:00, Dov Grobgeld <dov=2Egrobgeld@gmail=2Ecom> wrote:
I think that you should describe in detail what you ex= pect=2E

In pure vector graphics a contour may cut thro= ugh a pixel and partially obscure it, and it is then the responsibility of = the graphics engine to create anti-aliased graphics by mixing the colors of= the background and the foreground=2E As a user you typically don't need to= concern yourself with that as it is done automatically=2E

However, e=2Eg=2E for text this may cause "fuzzy" characters and the = engine will then fallback to moving the contours and scale the font so that= the glyphs fall on whole pixels=2E

Note that the use = of anti-aliased graphics is less needed, and less visible, for an HDPI devi= ce=2E

In any case all that you will typically need is = cairo_scale() as Uli Shlachter already described=2E

=
Try it!

Regards,


On Sun, Mar 17, = 2024 at 12:46=E2=80=AFPM Federico Angelilli <list@fedang=2Enet> wrote:
Hi

Will cairo_sc= ale make a pixel perfect image for non integer scales? To my understanding = the scale matrix will be multiplied to all the coordinates scaling the coor= dinates appropriately=2E Should I also scale the whole surface by that same= factor?

Regards


On March 16, 2024 6:27:56 PM GMT+01:00, Uli Schlachter <psychon@znc=2Ein> wro= te:
Hi

Am 14=2E03=2E24 um 16:34 schrieb fedang:<= br>
Hello all,

I am writing a small X11 app using cairo as the drawi= ng backend=2E I was wondering if and how to implement
fractional scaling= to accommodate high dpi screens=2E After searching online I found almost n= othing, so here I am=2E

Can someone give me some pointers on what to= do? I can get a scale factor for the screens (depending on the size)
bu= t I have no idea how to actually use it in the draw code=2E

I'm not sure if I understand the question=2E Y= ou can use cairo_scale() to set a scale factor for all drawing=2E So I woul= d say that you can just apply the scale factor with cairo_scale() before dr= awing=2E

Of course, this assumes that you don't use cairo_identity_m= atrix() or cairo_set_matrix() in your drawing=2E Instead, cairo_save() and = cairo_restore() should be used around temporary modifications of the transf= ormations=2E

Cheers,
Uli
=
------76MKK3S31ZRNSLHPNNUNRC84ZSRMQJ--