[Top][All Lists]

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

width of strings/characters in a proportional font

From: Oliver Scholz
Subject: width of strings/characters in a proportional font
Date: Sun, 15 Sep 2002 22:08:29 +0200
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i686-pc-linux-gnu)

How can I check how wide a string in a proportional font is?

I have read the following in the Emacs Lisp reference:

,----[ Display ==> Width ]
| Width
| =====
|    Since not all characters have the same width, these functions let you
| check the width of a character.  *Note Primitive Indent::, and *Note
| Screen Lines::, for related functions.
|  - Function: string-width string
|      This function returns the width in columns of the string STRING,
|      if it were displayed in the current buffer and the selected window.

>From this I would have guessed that the following returns a fraction,
for example 3.5, meaning that the string has the width of 3.5 columns
in the default font:

(string-width (propertize "Test." 'face 'variable-pitch))

But it returns 5. So what am I missing here?

1. How is `string-width' supposed to be used? In what respects is it
   different from `(length string)'?

2. How do I get information about the width of a string in a
   proportional font (or in a different font size)? Suppose I want to
   write a face-sensitive fill-function, or I want to write a function
   that puts text inside a box and DTRT with proportional fonts.

    -- Oliver

29 Fructidor an 210 de la Révolution
Liberté, Egalité, Fraternité!

reply via email to

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