unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Accessing rendered image data
@ 2016-06-28 13:52 Lars Magne Ingebrigtsen
  2016-06-28 15:37 ` Lars Magne Ingebrigtsen
  2016-06-28 16:25 ` Eli Zaretskii
  0 siblings, 2 replies; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 13:52 UTC (permalink / raw)
  To: emacs-devel

If I have an image in a buffer, is there a way to access the displayed
image glyph data from Emacs Lisp?

The glyph is presumably a ... block of bytes with a width/height
number...  or something.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 13:52 Accessing rendered image data Lars Magne Ingebrigtsen
@ 2016-06-28 15:37 ` Lars Magne Ingebrigtsen
  2016-06-28 16:36   ` Eli Zaretskii
  2016-06-28 17:23   ` Eli Zaretskii
  2016-06-28 16:25 ` Eli Zaretskii
  1 sibling, 2 replies; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 15:37 UTC (permalink / raw)
  To: emacs-devel

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> If I have an image in a buffer, is there a way to access the displayed
> image glyph data from Emacs Lisp?
>
> The glyph is presumably a ... block of bytes with a width/height
> number...  or something.

The reason I'm asking is because I'm trying to asses the width of
rendered text in an SVG image, but perhaps I can just render the text
normally in Emacs.

However, I can't make head or tails or the "advanced" face/font stuff in
the manual.

If I say

emacs -nw "futura:size=40"

I get all the text rendered in Futura.

(find-font (font-spec :name "futura" :size 40))
#<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) (:name . "futura"))>

That's seems OK, doesn't it?

But if I say

(insert (propertize "FOO" 'face (list :font (find-font (font-spec :name "futura" :size 40)))))
FOO

and then say (font-at (point)) on that FOO, I get:

#<font-object "-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1">

Same with

(insert (propertize "FOO" 'face (list :font (find-font (font-spec :name "futura:size=40")))))

which is supposed to work, according to the manual.

What am I missing?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 13:52 Accessing rendered image data Lars Magne Ingebrigtsen
  2016-06-28 15:37 ` Lars Magne Ingebrigtsen
@ 2016-06-28 16:25 ` Eli Zaretskii
  2016-06-28 16:30   ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 16:25 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Date: Tue, 28 Jun 2016 15:52:40 +0200
> 
> If I have an image in a buffer, is there a way to access the displayed
> image glyph data from Emacs Lisp?

What data, specifically?  The glyph structure is very large.  In
general, it is only accessible from C, but maybe what you want can be
had in Lisp.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 16:25 ` Eli Zaretskii
@ 2016-06-28 16:30   ` Lars Magne Ingebrigtsen
  2016-06-28 17:03     ` Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 16:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
>> Date: Tue, 28 Jun 2016 15:52:40 +0200
>> 
>> If I have an image in a buffer, is there a way to access the displayed
>> image glyph data from Emacs Lisp?
>
> What data, specifically?  The glyph structure is very large.  In
> general, it is only accessible from C, but maybe what you want can be
> had in Lisp.

All the data from the image glyph, so that I can see what has been
rendered where...  It's probably impractically slow to do anything
useful with that data from Lisp, though, so I'm not sure it's something
that would actually be useful.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 15:37 ` Lars Magne Ingebrigtsen
@ 2016-06-28 16:36   ` Eli Zaretskii
  2016-06-28 16:46     ` Lars Magne Ingebrigtsen
  2016-06-28 17:23   ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 16:36 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Date: Tue, 28 Jun 2016 17:37:23 +0200
> 
> Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
> 
> > If I have an image in a buffer, is there a way to access the displayed
> > image glyph data from Emacs Lisp?
> >
> > The glyph is presumably a ... block of bytes with a width/height
> > number...  or something.
> 
> The reason I'm asking is because I'm trying to asses the width of
> rendered text in an SVG image, but perhaps I can just render the text
> normally in Emacs.

I don't understand what that means.  You can obtain the size of an SVG
image by using image-size.  Text that is part of an image is not
accessible to Emacs, AFAIK, so what exactly did you have in mind?

> However, I can't make head or tails or the "advanced" face/font stuff in
> the manual.

Why font is relevant to the size of the text?  Does
window-text-pixel-size do what you want?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 16:36   ` Eli Zaretskii
@ 2016-06-28 16:46     ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 16:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> The reason I'm asking is because I'm trying to asses the width of
>> rendered text in an SVG image, but perhaps I can just render the text
>> normally in Emacs.
>
> I don't understand what that means.  You can obtain the size of an SVG
> image by using image-size.  Text that is part of an image is not
> accessible to Emacs, AFAIK, so what exactly did you have in mind?

I'm trying to find the width of the text rendered inside the SVG.

>> However, I can't make head or tails or the "advanced" face/font stuff in
>> the manual.
>
> Why font is relevant to the size of the text?  Does
> window-text-pixel-size do what you want?

See the other mail about `face (:font ...)' apparently not working.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 16:30   ` Lars Magne Ingebrigtsen
@ 2016-06-28 17:03     ` Eli Zaretskii
  0 siblings, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 17:03 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Tue, 28 Jun 2016 18:30:45 +0200
> 
> > What data, specifically?  The glyph structure is very large.  In
> > general, it is only accessible from C, but maybe what you want can be
> > had in Lisp.
> 
> All the data from the image glyph, so that I can see what has been
> rendered where...

The actual data of the image is not in the glyph, it's in the image
cache; the glyph just holds the index of the slot in the cache where
the data is stored.

And no, you cannot access that from Lisp.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 15:37 ` Lars Magne Ingebrigtsen
  2016-06-28 16:36   ` Eli Zaretskii
@ 2016-06-28 17:23   ` Eli Zaretskii
  2016-06-28 17:37     ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 17:23 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Date: Tue, 28 Jun 2016 17:37:23 +0200
> 
> But if I say
> 
> (insert (propertize "FOO" 'face (list :font (find-font (font-spec :name "futura" :size 40)))))
> FOO
> 
> and then say (font-at (point)) on that FOO, I get:
> 
> #<font-object "-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1">

Did you turn off font-lock in that buffer?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 17:23   ` Eli Zaretskii
@ 2016-06-28 17:37     ` Lars Magne Ingebrigtsen
  2016-06-28 18:10       ` Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 17:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
>> Date: Tue, 28 Jun 2016 17:37:23 +0200
>> 
>> But if I say
>> 
>> (insert (propertize "FOO" 'face (list :font (find-font (font-spec
>> :name "futura" :size 40)))))
>> FOO
>> 
>> and then say (font-at (point)) on that FOO, I get:
>> 
>> #<font-object "-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1">
>
> Did you turn off font-lock in that buffer?

It's a fundamental mode buffer, so I would hope that there's no font
locking...

And 

(insert (propertize "FOO" 'face (list :family "futura")))

gives me something Futura, but not with the font features I want to
specify (like size).

Either there's something wrong with 'face '(:font ...) somewhere, or I
have a syntax error of some kind in my invocation, but it's hard to
tell, because the font documentation doesn't really give any relevant
examples that I can see...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 17:37     ` Lars Magne Ingebrigtsen
@ 2016-06-28 18:10       ` Eli Zaretskii
  2016-06-28 18:15         ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 18:10 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Tue, 28 Jun 2016 19:37:52 +0200
> 
> (insert (propertize "FOO" 'face (list :family "futura")))
> 
> gives me something Futura, but not with the font features I want to
> specify (like size).
> 
> Either there's something wrong with 'face '(:font ...) somewhere, or I
> have a syntax error of some kind in my invocation, but it's hard to
> tell, because the font documentation doesn't really give any relevant
> examples that I can see...

And I still don't understand how all this helps you to get what you
want.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:10       ` Eli Zaretskii
@ 2016-06-28 18:15         ` Lars Magne Ingebrigtsen
  2016-06-28 18:21           ` Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 18:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> And I still don't understand how all this helps you to get what you
> want.

It does.  Trust me.  :-)

In any case, shouldn't this work?  

(insert (propertize "FOO" 'face (list :font (find-font (font-spec :name "futura" :size 40)))))

It doesn't work, and I wonder why.  Do more specs in the font-spec need
to be specified for Emacs to decide to use the Futura font?  

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:15         ` Lars Magne Ingebrigtsen
@ 2016-06-28 18:21           ` Eli Zaretskii
  2016-06-28 18:29             ` Lars Magne Ingebrigtsen
  2016-06-28 18:35             ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 18:21 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Tue, 28 Jun 2016 20:15:05 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > And I still don't understand how all this helps you to get what you
> > want.
> 
> It does.  Trust me.  :-)

And you should trust me that I don't like wasting my time on digging
into problems whose purpose I don't fully understand ;-)

> In any case, shouldn't this work?  

Should I care?

> (insert (propertize "FOO" 'face (list :font (find-font (font-spec :name "futura" :size 40)))))
> 
> It doesn't work, and I wonder why.  Do more specs in the font-spec need
> to be specified for Emacs to decide to use the Futura font?  

How should I know?  This stuff is not documented at all, so you are
asking me to step in a debugger through gobs of unfamiliar and
complicated code, without ever understanding what is it that I'm
trying to accomplish.  That's not in my job description.

If you want my help, try telling more.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:21           ` Eli Zaretskii
@ 2016-06-28 18:29             ` Lars Magne Ingebrigtsen
  2016-06-28 18:48               ` Eli Zaretskii
  2016-06-30 15:12               ` Ted Zlatanov
  2016-06-28 18:35             ` Lars Magne Ingebrigtsen
  1 sibling, 2 replies; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 18:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> And you should trust me that I don't like wasting my time on digging
> into problems whose purpose I don't fully understand ;-)

As I said earlier in this thread, I wanted to figure out how much space
text rendered in an SVG takes.  Since Emacs doesn't expose this data
back to Elisp land, I hit upon the idea of rendering the text in a
buffer instead (with the same fonts that would have been used in the
SVG).

This will give me approximate sizes that'll be good enough.

> How should I know?  This stuff is not documented at all, so you are
> asking me to step in a debugger through gobs of unfamiliar and
> complicated code, without ever understanding what is it that I'm
> trying to accomplish.  That's not in my job description.
>
> If you want my help, try telling more.

It is documented in

(info "(lisp)Low-Level Font")

In particular:

 -- Function: font-spec &rest arguments
     Return a new font spec using the specifications in ARGUMENTS,
     which should come in `property'-`value' pairs.  The possible
     specifications are as follows:

    `:name'
          The font name (a string), in either XLFD, Fontconfig, or GTK
          format.  *Note Fonts: (emacs)Fonts.

[...]

    `:size'
          The font size--either a non-negative integer that specifies
          the pixel size, or a floating-point number that specifies the
          point size.


An XLFD would look like "futura:size=40".

(insert (propertize "FOO" 'face (list :font (find-font (font-spec :name "futura:size=40")))))

Does not work.  Either this is a bug, or there are missing bits in the
manual that says what find-font and/or 'face wants here.  Or there's
something else I'm missing.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:21           ` Eli Zaretskii
  2016-06-28 18:29             ` Lars Magne Ingebrigtsen
@ 2016-06-28 18:35             ` Lars Magne Ingebrigtsen
  2016-06-28 18:51               ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 18:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Oh, I see...  find-font doesn't return a font object, but a font entity
object...  And 'face (:font...  wants a font object?  Is that the
problem?  If so, how does one get a font object from a font entity
object?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:29             ` Lars Magne Ingebrigtsen
@ 2016-06-28 18:48               ` Eli Zaretskii
  2016-06-28 18:58                 ` Lars Magne Ingebrigtsen
  2016-06-30 15:12               ` Ted Zlatanov
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 18:48 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Tue, 28 Jun 2016 20:29:58 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > And you should trust me that I don't like wasting my time on digging
> > into problems whose purpose I don't fully understand ;-)
> 
> As I said earlier in this thread, I wanted to figure out how much space
> text rendered in an SVG takes.  Since Emacs doesn't expose this data
> back to Elisp land, I hit upon the idea of rendering the text in a
> buffer instead (with the same fonts that would have been used in the
> SVG).

How do you know which fonts are used by SVG?  They use similar font
selection machinery as Emacs with similar fallbacks.  The font that is
stated in the SVG file will not necessarily be used.

> It is documented in
> 
> (info "(lisp)Low-Level Font")
> 
> In particular:
> 
>  -- Function: font-spec &rest arguments
>      Return a new font spec using the specifications in ARGUMENTS,
>      which should come in `property'-`value' pairs.  The possible
>      specifications are as follows:
> 
>     `:name'
>           The font name (a string), in either XLFD, Fontconfig, or GTK
>           format.  *Note Fonts: (emacs)Fonts.
> 
> [...]
> 
>     `:size'
>           The font size--either a non-negative integer that specifies
>           the pixel size, or a floating-point number that specifies the
>           point size.
> 
> 
> An XLFD would look like "futura:size=40".

I already know about that.  This all works, and you have also shown an
example that tells it worked for you.

> (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.

What if you use just :font "font-name-as-a-string", does that do what
you want?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:35             ` Lars Magne Ingebrigtsen
@ 2016-06-28 18:51               ` Eli Zaretskii
  0 siblings, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-28 18:51 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Tue, 28 Jun 2016 20:35:53 +0200
> 
> Oh, I see...  find-font doesn't return a font object, but a font entity
> object...  And 'face (:font...  wants a font object?  Is that the
> problem?

Not according to documentation:

  ‘:font’
       The font used to display the face.  Its value should be a font
       object.  *Note Low-Level Font::, for information about font
       objects, font specs, and font entities.

       When specifying this attribute using ‘set-face-attribute’ (*note
       Attribute Functions::), you may also supply a font spec, a font
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       entity, or a string.  Emacs converts such values to an appropriate
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       font object, and stores that font object as the actual attribute
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       value.  If you specify a string, the contents of the string should
       ^^^^^
       be a font name (*note (emacs)Fonts::); if the font name is an XLFD
       containing wildcards, Emacs chooses the first font matching those
       wildcards.  Specifying this attribute also changes the values of
       the ‘:family’, ‘:foundry’, ‘:width’, ‘:height’, ‘:weight’, and
       ‘:slant’ attributes.

So maybe you should use set-face-attribute, and only it.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:48               ` Eli Zaretskii
@ 2016-06-28 18:58                 ` Lars Magne Ingebrigtsen
  2016-06-28 19:06                   ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 18:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> How do you know which fonts are used by SVG?  They use similar font
> selection machinery as Emacs with similar fallbacks.  The font that is
> stated in the SVG file will not necessarily be used.

There will be some differences; yes, but it should be near enough.

>> (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.

I does not work in that it doesn't give me the font I want.

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

(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*

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

(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?

> What if you use just :font "font-name-as-a-string", does that do what
> you want?

:font "futura:size=20" does not work.  If you mean

(insert (propertize "FOO" 'face (list :font "-adobe-Futura-ultrabold-normal-normal-*-20-*-*-*-*-0-iso10646-1")))

that doesn't work either.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:58                 ` Lars Magne Ingebrigtsen
@ 2016-06-28 19:06                   ` Lars Magne Ingebrigtsen
  2016-06-28 19:38                     ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 19:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> #<font-object "-adobe-Futura-ultrabold-normal-normal-*-2-*-*-*-*-0-iso10646-1">
>
> That's pretty close, although the size is 2 instead of 20...  *sigh*
>
> :size doesn't seem to have any effect at all here.

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".  But I haven't even been able to find
the code that does that anywhere.  :-)

Still looking...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 19:06                   ` Lars Magne Ingebrigtsen
@ 2016-06-28 19:38                     ` Lars Magne Ingebrigtsen
  2016-06-28 20:17                       ` Lars Magne Ingebrigtsen
  2016-06-30 15:08                       ` Eli Zaretskii
  0 siblings, 2 replies; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 19:38 UTC (permalink / raw)
  To: emacs-devel

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> 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".  But I haven't even been able to find
> the code that does that anywhere.  :-)
>
> Still looking...

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 went with

    (let ((face (make-face 'meme-face)))
      (set-face-font
       foo
       (format "-monotype-%s-normal-normal-condensed-*-%s-*-*-*-*-0-iso10646-1"
	       (capitalize family)
	       font-size))
      (insert (propertize string 'face foo))

instead, which is completely yucky, because I don't want to create that
face.

But it works, at least.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 19:38                     ` Lars Magne Ingebrigtsen
@ 2016-06-28 20:17                       ` Lars Magne Ingebrigtsen
  2016-06-28 20:26                         ` Robert Weiner
  2016-06-30 15:08                       ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-28 20:17 UTC (permalink / raw)
  To: emacs-devel

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> But it works, at least.

I think you'll all feel that this was worth all this work:

https://lars.ingebrigtsen.no/2016/06/28/emacs-can-haz-fancy-meme/

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 20:17                       ` Lars Magne Ingebrigtsen
@ 2016-06-28 20:26                         ` Robert Weiner
  0 siblings, 0 replies; 25+ messages in thread
From: Robert Weiner @ 2016-06-28 20:26 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

On Tue, Jun 28, 2016 at 4:17 PM, Lars Magne Ingebrigtsen <larsi@gnus.org>
wrote:

> I think you'll all feel that this was worth all this work:


​Very nice work, as always.​

Bob

[-- Attachment #2: Type: text/html, Size: 770 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 19:38                     ` Lars Magne Ingebrigtsen
  2016-06-28 20:17                       ` Lars Magne Ingebrigtsen
@ 2016-06-30 15:08                       ` Eli Zaretskii
  1 sibling, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2016-06-30 15:08 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> 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?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-28 18:29             ` Lars Magne Ingebrigtsen
  2016-06-28 18:48               ` Eli Zaretskii
@ 2016-06-30 15:12               ` Ted Zlatanov
  2016-06-30 15:38                 ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 25+ messages in thread
From: Ted Zlatanov @ 2016-06-30 15:12 UTC (permalink / raw)
  To: emacs-devel

On Tue, 28 Jun 2016 20:29:58 +0200 Lars Magne Ingebrigtsen <larsi@gnus.org> wrote: 

LMI> I wanted to figure out how much space text rendered in an SVG
LMI> takes.

SVG is supposed to take care of layout and sizes, isn't it? It has all
that scaling and positioning in the spec... so maybe you can just use
the SVG facilities?

Ted




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-30 15:12               ` Ted Zlatanov
@ 2016-06-30 15:38                 ` Lars Magne Ingebrigtsen
  2016-06-30 16:11                   ` Ted Zlatanov
  0 siblings, 1 reply; 25+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-06-30 15:38 UTC (permalink / raw)
  To: emacs-devel

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Tue, 28 Jun 2016 20:29:58 +0200 Lars Magne Ingebrigtsen
> <larsi@gnus.org> wrote:
>
> LMI> I wanted to figure out how much space text rendered in an SVG
> LMI> takes.
>
> SVG is supposed to take care of layout and sizes, isn't it? It has all
> that scaling and positioning in the spec... so maybe you can just use
> the SVG facilities?

I need to do the line folding, I think?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Accessing rendered image data
  2016-06-30 15:38                 ` Lars Magne Ingebrigtsen
@ 2016-06-30 16:11                   ` Ted Zlatanov
  0 siblings, 0 replies; 25+ messages in thread
From: Ted Zlatanov @ 2016-06-30 16:11 UTC (permalink / raw)
  To: emacs-devel

On Thu, 30 Jun 2016 17:38:55 +0200 Lars Magne Ingebrigtsen <larsi@gnus.org> wrote: 

LMI> Ted Zlatanov <tzz@lifelogs.com> writes:
>> On Tue, 28 Jun 2016 20:29:58 +0200 Lars Magne Ingebrigtsen
>> <larsi@gnus.org> wrote:
>> 
LMI> I wanted to figure out how much space text rendered in an SVG
LMI> takes.
>> 
>> SVG is supposed to take care of layout and sizes, isn't it? It has all
>> that scaling and positioning in the spec... so maybe you can just use
>> the SVG facilities?

LMI> I need to do the line folding, I think?

Try tspan or the other magic like "dominant-baseline":

http://tutorials.jenkov.com/svg/tspan-element.html

https://stackoverflow.com/questions/4991171/auto-line-wrapping-in-svg-text

Multi-line text seems to be the hard part. Sorry, this may be a huge
pain after all.

Ted




^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2016-06-30 16:11 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-28 13:52 Accessing rendered image data Lars Magne Ingebrigtsen
2016-06-28 15:37 ` Lars Magne Ingebrigtsen
2016-06-28 16:36   ` Eli Zaretskii
2016-06-28 16:46     ` Lars Magne Ingebrigtsen
2016-06-28 17:23   ` Eli Zaretskii
2016-06-28 17:37     ` Lars Magne Ingebrigtsen
2016-06-28 18:10       ` Eli Zaretskii
2016-06-28 18:15         ` Lars Magne Ingebrigtsen
2016-06-28 18:21           ` Eli Zaretskii
2016-06-28 18:29             ` Lars Magne Ingebrigtsen
2016-06-28 18:48               ` Eli Zaretskii
2016-06-28 18:58                 ` Lars Magne Ingebrigtsen
2016-06-28 19:06                   ` Lars Magne Ingebrigtsen
2016-06-28 19:38                     ` Lars Magne Ingebrigtsen
2016-06-28 20:17                       ` Lars Magne Ingebrigtsen
2016-06-28 20:26                         ` Robert Weiner
2016-06-30 15:08                       ` Eli Zaretskii
2016-06-30 15:12               ` Ted Zlatanov
2016-06-30 15:38                 ` Lars Magne Ingebrigtsen
2016-06-30 16:11                   ` Ted Zlatanov
2016-06-28 18:35             ` Lars Magne Ingebrigtsen
2016-06-28 18:51               ` Eli Zaretskii
2016-06-28 16:25 ` Eli Zaretskii
2016-06-28 16:30   ` Lars Magne Ingebrigtsen
2016-06-28 17:03     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).