emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing rendered image data


From: Eli Zaretskii
Subject: Re: Accessing rendered image data
Date: Thu, 30 Jun 2016 18:08:43 +0300

> From: Lars Magne Ingebrigtsen <address@hidden>
> Date: Tue, 28 Jun 2016 21:38:18 +0200
> 
> >> (insert (propertize "FOO" 'face (list :font (find-font (font-spec
> >> :name "futura:size=40")))))
> >> 
> >> Does not work.
> >
> > It does work, sort of.  Try describe-text-properties on :FOO, and see
> > for yourself.
> 
> It does not work in that it doesn't give me the font I want.

That's because a font-entity returned by find-font evidently doesn't
specify the size of TrueType fonts, it specifies zero instead:

  (find-font (font-spec :family "Consolas" :size 14))
    => #<font-entity uniscribe outline Consolas mono iso10646-1
                     bold italic normal 0 nil 110 nil
                                       ^^^
                     ((:format . opentype)
                     (:script symbol symbol thai cyrillic greek
                              phonetic latin latin latin latin))

Instead, their size must be specified when you open the font:

  (open-font (find-font (font-spec :family "Consolas")) 14)
    => #<font-object
         "-outline-Consolas-bold-italic-normal-mono-14-*-*-*-c-*-iso10646-1">
                                                    ^^

(If the font was already opened, and is therefore in the font cache,
find-font might also return an entity with a non-zero size, but that
cannot be relied upon, of course.)

> Anyway, `load-font' almost gets me to where I want to be

You mean, open-font.

> (insert (propertize "FOO" 'face (list :font (open-font (find-font (font-spec 
> :family "futura" :size 20))))))
> 
> gives me text with:
> 
> #<font-object 
> "-adobe-Futura-ultrabold-normal-normal-*-2-*-*-*-*-0-iso10646-1">
> 
> That's pretty close, although the size is 2 instead of 20...  *sigh*

See above.

> :size doesn't seem to have any effect at all here.

With TrueType fonts, you need to specify it explicitly as an argument
to open-font, or else you get the first font that matches the other
attributes, since zero as :size is (rightfully) ignored.

Btw, I also suggest to specify the :weight and :slant in the font-spec
call, because otherwise you get the first matching font of the
family.  E.g., on one of my machines I get a bold-oblique variant of
the font if I don't specify those attributes explicitly.

> (font-info (find-font (font-spec :family "futura" :size 20)))
> =>
> ["-adobe-Futura-ultrabold-normal-normal-*-2-*-*-*-*-0-iso10646-1" 
> "Futura:pixelsize=2:foundry=adobe:weight=ultra-bold:slant=normal:width=normal:scalable=true"
>  2 4 0 0 0 1 3 1 1 1 "/usr/share/fonts/X11/Type1/pfud8a.pfa" (opentype)]
> 
> (font-spec :family "futura" :size 20)
> => #<font-spec nil nil futura nil nil nil nil nil 20 nil nil nil nil>
> 
> (find-font (font-spec :family "futura" :size 20))
> => #<font-entity xft adobe Futura nil iso10646-1 ultra-bold normal normal 0 
> nil 
> nil 0 ((:font-entity "/usr/share/fonts/X11/Type1/pfud8a.pfa" . 0))>
> 
> So...  something got lost in the `find-font' call?

For TrueType fonts, all the font backends deliberately put zero in the
:size slot of the font-entity they create.  I guess that's because the
size of a TrueType font has no meaning, because one can open it with
any size.  But that's a guess; I'm not an expert on this.

To summarize, this works for me:

  (insert (propertize "FOO"
                      'face (list :font
                                  (open-font
                                   (find-font
                                    (font-spec :family "Consolas")) 14))))

> The particularly frustrating thing here is that obviously Emacs has a
> way to select just the correct font I want, since it gives me that if I
> say "emacs -fn futura:size=40".

Because in that case, Emacs opens the font with the specified size.

> Ok, I give up.  I think somebody should either remove the documentation
> of 'face '(:font ...) completely so that people don't accidentally try
> to do something with that form, or document it fully and/or fix bugs in
> that area.

I found no bugs, just subtle and dark corners.  Given the above (and
the fact that open-font is not even mentioned in the ELisp manual),
what would you like to be documented?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]