Lisp HUG Maillist Archive

Centering output-pane text

I'm using gp:draw-string to display text in an output-pane. I'd like  
to center it horizontally (or perhaps right-justify). In order to do  
that, it would be great if there were a function that returns the  
width of the string in pixels.

Question #1: Is there such a function?

I happen to be using a fixed-width font, which means I could  
presumably do a simple computation based on the number of characters,  
but I'd like a more general solution.

For some of my panes (this is a calendar with days that respond to  
clicks and weekly totals that don't), I could use something other than  
an output-pane, but even then I don't see what kind of pane provides  
for centered text.

Question #2: Are there panes that provide for displaying centered text?

Thanks! (LWM 5.1.1)

Laughing Water


Re: Centering output-pane text

On Sat, Jul 19, 2008 at 8:08 PM, Laughing Water <lw@mt.net> wrote:
> I'm using gp:draw-string to display text in an output-pane. I'd like to
> center it horizontally (or perhaps right-justify). In order to do that, it
> would be great if there were a function that returns the width of the string
> in pixels.
>
> Question #1: Is there such a function?

I found an old post with a response by Arthur Lemmens:

""
Subject: 	Re: gp:draw-string with right-ward alignment?
Dr. Atip Asvanund wrote:
    I am drawing y-axis of a chart and I want all the numbers to
    be right-aligned to the y-axis. Is there a parameter in
    gp:-draw-string that  will allow me to induce right-ward
    alignment?
I don't think so.
    Or must this only be done manually? For example, calculating the
    pixel width of the string and shift x accordingly.
Yes, that's how I did it when I needed this.
    If so, is there a  method for calculating the pixel width automatically?
GP:GET-STRING-EXTENT.
I attach some code that I wrote as part of my own chart-drawing library.
Please feel free to use this code.
Arthur
""

and here's an example of its use:

CL-USER 1 > (defvar pane (make-instance 'capi:output-pane))
PANE

CL-USER 2 > (capi:contain pane)
#<CAPI:OUTPUT-PANE  214A5A8F>

CL-USER 3 > (gp:get-string-extent pane "Hello World!")
0
-11
72
3

CL-USER 4 > (gp:get-string-extent pane "Hello")
0
-11
30
3

Doc: http://www.lispworks.com/documentation/lw51/CAPRM/html/capiref-502.htm#marker-890144

-- 
=====================
Joshua Taylor
tayloj@cs.rpi.edu, jtaylor@alum.rpi.edu

"A lot of good things went down one time,
 back in the goodle days."
 John Hartford


Re: In search of string-width [was Centering output-pane text]

On Jul 22, 2008, at 11:49 AM, Laughing Water wrote:

> I actually used the Search at the top of the Help menu (Mac under OS  
> X 10.5.4), and evidently I would do better to use the LispWorks  
> Search dialog instead. What is the Search I used for anyway?

That search cartouche is for entering terms for the Mac OS X Help  
Viewer. If an application does not provide Mac OS X Help Viewer help  
files (usually at MyApp.app/Contents/Resources/Language.lproj/ 
MyAppHelp/) then searching using that cartouche won't find anything.  
LispWorks doesn't provide such help files, but rather has its own help  
system and manuals.

regards,

Ralph









Raffael Cavallaro, Ph.D.
raffaelcavallaro@mac.com


Updated at: 2020-12-10 08:42 UTC