From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jimmy Yuen Ho Wong Newsgroups: gmane.emacs.devel Subject: Re: Mechanism to scale SVG images when default face height changes? Date: Mon, 18 Sep 2023 20:10:59 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003a496f0605a6e939" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3258"; mail-complaints-to="usenet@ciao.gmane.io" To: Alan Third , Jimmy Yuen Ho Wong , Emacs-Devel devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 18 21:12:33 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qiJfd-0000g9-6r for ged-emacs-devel@m.gmane-mx.org; Mon, 18 Sep 2023 21:12:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiJem-0004zp-Nf; Mon, 18 Sep 2023 15:11:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiJel-0004zR-70 for emacs-devel@gnu.org; Mon, 18 Sep 2023 15:11:39 -0400 Original-Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiJej-0001Vw-EV for emacs-devel@gnu.org; Mon, 18 Sep 2023 15:11:38 -0400 Original-Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-274b3d48e15so1567448a91.0 for ; Mon, 18 Sep 2023 12:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695064296; x=1695669096; darn=gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=sP6m4VqUjheCpMwanc0jEyu52oh8sM3TZAoMj95hilk=; b=G0I354S9iQLZycvPO9GTAzKu84T+4Txe6SyuKeKULw2X76Bg9g2zfbFmTYSg8cUjAa BShqeedkmfthSQ7B+YzWs+8cu3Rl84TLYtM372YY4gRPjA1ObYn/hXLWeabloMHFviF0 hQcuGOPjPK3OA5wT25y1xwPElMYEQGAIqyNGssm5I/GGeyLM5f77eL/qGDgZUHG29k4F X21pKutAyepc9komCS77CRQl6cXWuP3+LX0w8UXvk3Mebsz3GADng9xUvzisy41WvY6A xv9pWeU06VTQ6ZM7NGCP2l3rX7kHleEjm56KNsgGze/GB8tP8Xx5v+NOQkR51xOQ7Xy9 BH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695064296; x=1695669096; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sP6m4VqUjheCpMwanc0jEyu52oh8sM3TZAoMj95hilk=; b=japkrryakRCFI0hT2g9v2jI072p8NMnJRAEkzZ4s3UnZgc6y0NrCEQ+dApASloeM/Z 6SDRHkbkFW/AY1q026VF92Q12tqQ5xDvgBPurDWnSAws4jvdKUomlA8+Pg6KaEITFHXz oDFrCr8rHRGUIlkQuJr7YOwurTtUIQgfq4ewfC1xRZvTwWuJJ7wzGtdlJgXR+ZXXtuOz CGfIYi4Jx68+Nmh0m3NWn2xUBL0UoJxsmiK+ehOy0YFI+FvT2kWv8nKqBKPh6e2HC2wt AvHthAm60F+rbhLvDGDbpJ6Vo0QU1sRle/+sr399jYZa8vXDsz3zO5aKd6mgdD7Mp0zW d/Lw== X-Gm-Message-State: AOJu0Yy4IZWtOVI05ciSaoaJn68QM735rnjZMoJDGMwW3pzyQkw0Yvi7 4X9xJ2OHFu3mHNu+me7Uqgvl4osY5sq99iNUJOHsKsWSZ6G2Hw== X-Google-Smtp-Source: AGHT+IEJJfNzgiP5ZzZpttVOizomjZw4gIFyyw/WXfQJkJLPSUiYdkdqyozCuKE0ervKVyoEL7AFfQdXtGgnpClGGJc= X-Received: by 2002:a17:90a:528c:b0:268:352c:9d13 with SMTP id w12-20020a17090a528c00b00268352c9d13mr7426938pjh.0.1695064295883; Mon, 18 Sep 2023 12:11:35 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=wyuenho@gmail.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310719 Archived-At: --0000000000003a496f0605a6e939 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ah, I was looking at https://www.gnu.org/software/emacs/manual/html_node/elisp/Pixel-Specificati= on.html, this isn't documented but indeed it scales. ```elisp #("=EF=BF=BC" 0 1 (face all-the-icons-lpurple font-lock-face all-the-icons-lpurple fontified t display (image :type svg :data " " :scale 1 :transform-smoothing t :width (1 . em) :ascent center :margin 1) front-sticky nil rear-nonsticky t)) ``` But this doesn't seem to work, I suppose px is not a unit? ```elisp #("=EF=BF=BC" 0 1 (face all-the-icons-lpurple font-lock-face all-the-icons-lpurple fontified t display (image :type svg :data " " :scale 1 :transform-smoothing t :width (- (1 . em) (1 . px)) :ascent center :margin 1) front-sticky nil rear-nonsticky t)) ``` I like this approach a lot, but I do need pixel precision calculated on demand because I need to add a 1px margin between icons. If I don't subtract 2 px back from the dimensions, the icons will be wider than a character. Jimmy On Mon, Sep 18, 2023 at 7:19=E2=80=AFPM Alan Third wrote: > On Mon, Sep 18, 2023 at 06:42:33PM +0100, Jimmy Yuen Ho Wong wrote: > > In the SVG branch in all-the-icons, all the icons are inserted with a > > `:width` and `:height` properties set on the image, and the face is > applied > > to the propertized string. i.e. > > > > ```elisp > > ELISP> (all-the-icons-icon-for-file "test.js") > > #("=EF=BF=BC" 0 1 > > (face all-the-icons-lpurple font-lock-face all-the-icons-lpurple > > fontified t display > > (image :type svg :data " width=3D\"512\" > > height=3D\"512\"> " :scale 1 > > :transform-smoothing t :width 14 :height 14 :ascent center :margin 1) > > front-sticky nil rear-nonsticky t)) > > ``` > > Do you need to set the size in pixels? If you set the size in em's > (from Emacs 28 up) then it will scale automatically. > > -- > Alan Third > --0000000000003a496f0605a6e939 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ah, I was looking at=C2=A0https:/= /www.gnu.org/software/emacs/manual/html_node/elisp/Pixel-Specification.html= , this isn't documented but indeed it scales.

```elisp
#(= "=EF=BF=BC" 0 1
=C2=A0 (face all-the-icons-lpurple font-lock-f= ace all-the-icons-lpurple fontified t display
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 (image :type svg :data "<svg viewBox=3D\"0 0 512 512\"= ; width=3D\"512\" height=3D\"512\"> <path d=3D\&q= uot;...snip...\"></path></svg>" :scale 1 :transfor= m-smoothing t :width (1 . em) :ascent center :margin 1)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 front-sticky nil rear-nonsticky t))
```

But this do= esn't seem to work, I suppose px is not a unit?

```elisp
#(&q= uot;=EF=BF=BC" 0 1
=C2=A0 (face all-the-icons-lpurple font-lock-fac= e all-the-icons-lpurple fontified t display
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = (image :type svg :data "<svg viewBox=3D\"0 0 512 512\" wi= dth=3D\"512\" height=3D\"512\"> <path d=3D\"= ...snip...\"></path></svg>" :scale 1 :transform-sm= oothing t :width (- (1 . em) (1 . px)) :ascent center :margin 1)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 front-sticky nil rear-nonsticky t))
```
<= br>
I like this approach a lot, but I do need pixel precision cal= culated on demand because I need to add a 1px margin between icons. If I do= n't subtract 2 px back from the dimensions, the icons will be wider tha= n a character.

Jimmy
<= /div>


On Mon, Sep 18, 2023 at 7:19=E2=80=AFPM Alan Third <alan@idiocy.org> wrote:
On Mon, Sep 18, 2023 at 06:42= :33PM +0100, Jimmy Yuen Ho Wong wrote:
> In the SVG branch in all-the-icons, all the icons are inserted with a<= br> > `:width` and `:height` properties set on the image, and the face is ap= plied
> to the propertized string. i.e.
>
> ```elisp
> ELISP> (all-the-icons-icon-for-file "test.js")
> #("=EF=BF=BC" 0 1
>=C2=A0 =C2=A0(face all-the-icons-lpurple font-lock-face all-the-icons-l= purple
> fontified t display
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(image :type svg :data "<svg = viewBox=3D\"0 0 512 512\" width=3D\"512\"
> height=3D\"512\"> <path d=3D\"...snip...\"&g= t;</path></svg>" :scale 1
> :transform-smoothing t :width 14 :height 14 :ascent center :margin 1)<= br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0front-sticky nil rear-nonsticky t)) > ```

Do you need to set the size in pixels? If you set the size in em's
(from Emacs 28 up) then it will scale automatically.

--
Alan Third
--0000000000003a496f0605a6e939--