unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* width of propertized string
       [not found] <20ecf6c70806050537k1d343af9r7a05240b5558ea10@mail.gmail.com>
@ 2008-06-05 12:53 ` David Reitter
  2008-06-05 19:47   ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: David Reitter @ 2008-06-05 12:53 UTC (permalink / raw)
  To: Emacs-Devel devel; +Cc: Nathaniel Cunningham

Given a propertized string, how would one find out what its (pixel)  
dimensions are going to be?

This is important to justify text and other graphical elements  
properly.  It is also necessary to correctly wrap (variable-width)  
text before displaying it.

I have asked about this a while ago, but I don't think anything has  
been implemented.  I'd be happy to give it a try, but I need pointers  
as regards which functions to use: I don't know the display engine at  
all.

I'd appreciate any help with this.





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

* Re: width of propertized string
  2008-06-05 12:53 ` width of propertized string David Reitter
@ 2008-06-05 19:47   ` Stefan Monnier
  2008-06-06  8:40     ` David Reitter
  2008-06-06 19:03     ` Richard M Stallman
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2008-06-05 19:47 UTC (permalink / raw)
  To: David Reitter; +Cc: Nathaniel Cunningham, Emacs-Devel devel

> Given a propertized string, how would one find out what its (pixel)
> dimensions are going to be?

Display it, measure its size.

> This is important to justify text and other graphical elements properly.
> It is also necessary to correctly wrap (variable-width) text before
> displaying it.

The font to be used depends on the frame where it's displayed, so the
size of the text needs to be considered in the context where it'll
be displayed.

> I have asked about this a while ago, but I don't think anything has been
> implemented.  I'd be happy to give it a try, but I need pointers as regards
> which functions to use: I don't know the display engine at all.

Indeed, it hasn't been implemented AFAIK.
I guess you'd want to look at move_it_to.


        Stefan





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

* Re: width of propertized string
  2008-06-05 19:47   ` Stefan Monnier
@ 2008-06-06  8:40     ` David Reitter
  2008-06-06 19:16       ` Stefan Monnier
  2008-06-06 19:03     ` Richard M Stallman
  1 sibling, 1 reply; 5+ messages in thread
From: David Reitter @ 2008-06-06  8:40 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Nathaniel Cunningham, Emacs-Devel devel

On 5 Jun 2008, at 20:47, Stefan Monnier wrote:

>> Given a propertized string, how would one find out what its (pixel)
>> dimensions are going to be?
>
> Display it, measure its size.

Tried that (see code below).  This is too slow because we need to  
switch to the temporary buffer.

All of my use cases concern displaying things in the echo area or the  
header line.  Thus, I would want to ignore any font locking and other  
automatically applied properties.

My use cases are:

- adding appropriate spacing and justifying buttons in the header line
- word-wrapping text, primarily in the echo area before displaying it.



(defun visual-pixel-col-at-point ()
  (or
   (car-safe (pos-visible-in-window-p (point) nil 'partial))
   0))


(defun string-pixel-width (text)
   (let ((width))
     (let ((old-buffer (current-buffer)))
	  (with-temp-buffer ;; should be in fundamental-mode
	    ;; this is way too slow.
	    (switch-to-buffer (current-buffer) t)
	    (let ((buffer-undo-list nil) (start (point))
		  (truncate-lines t) (after-change-functions nil))
	      (let ((left (visual-pixel-col-at-point)))
		(insert text)
		(setq width (- (visual-pixel-col-at-point) left)))
	      (delete-region start (point)))
	    (switch-to-buffer old-buffer t)))
       width))





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

* Re: width of propertized string
  2008-06-05 19:47   ` Stefan Monnier
  2008-06-06  8:40     ` David Reitter
@ 2008-06-06 19:03     ` Richard M Stallman
  1 sibling, 0 replies; 5+ messages in thread
From: Richard M Stallman @ 2008-06-06 19:03 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: david.reitter, nathaniel.cunningham, emacs-devel

    > Given a propertized string, how would one find out what its (pixel)
    > dimensions are going to be?

    Display it, measure its size.

That is not adequate when you want to choose other text based the size
of this text.  There needs to be a way to compute the size before
displaying the text.

    The font to be used depends on the frame where it's displayed, so the
    size of the text needs to be considered in the context where it'll
    be displayed.

Indeed, and this way could involve specifying the frame as well as a position
in a buffer.




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

* Re: width of propertized string
  2008-06-06  8:40     ` David Reitter
@ 2008-06-06 19:16       ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2008-06-06 19:16 UTC (permalink / raw)
  To: David Reitter; +Cc: Nathaniel Cunningham, Emacs-Devel devel

>>> Given a propertized string, how would one find out what its (pixel)
>>> dimensions are going to be?
>> Display it, measure its size.
> Tried that (see code below).

I didn't mean it seriously.
We can only do it at the C code level right now, using move_it_to.


        Stefan




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

end of thread, other threads:[~2008-06-06 19:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20ecf6c70806050537k1d343af9r7a05240b5558ea10@mail.gmail.com>
2008-06-05 12:53 ` width of propertized string David Reitter
2008-06-05 19:47   ` Stefan Monnier
2008-06-06  8:40     ` David Reitter
2008-06-06 19:16       ` Stefan Monnier
2008-06-06 19:03     ` Richard M Stallman

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