[racket] Interpretation of font information
Hi All,
I want to render simple mathematical formulas using picts.
Consider a simple example, the square root of x:
√x
To make this look nice, I want to introduce an overline that draws a bar over x.
The bar should begin where the root sign ends. To do this I need to know
how high the root sign is. Calculating this has turned out to more complicated
than I expected. If I use a font size of say 30, then the root sign will (in
some fonts) be higher than 30. If I use (text "√" font) to get a pict then
the pict height will be 30 (for most fonts), but the end of the root sign
will stick out of the bounding box. It actually makes sense it stick out,
since this makes it easy to make roots over tall characters such as h.
Anyways, since pict-height didn't return the correct height, I tried:
(send (dc-for-text-size) get-text-extent "√" font))
but I am not able to make sense of the results. For most fonts
I get a height of 30, but others give the height 34 (a number that I didn't
see from pict-height.
Below is a little program that uses pict-height and get-text-extent
to print some info. The attached screen shot was taken on OS X Mavericks.
1) How can I find out how much the root sign sticks out of the bounding box?
2) Why are the numbers from pict-height and get-text-extent different?
#lang racket
(require racket/draw pict)
(define (info p)
(list (list 'h (pict-height p))
(list 'a (pict-ascent p))
(list 'd (pict-descent p))
(list 'a+d (+ (pict-ascent p) (pict-descent p)))
(list 'w (pict-width p))))
(define (map-fonts f)
(for/list ([font-name '("Neo Euler" "Default" "Arial" "Courier" "Palatino")])
(define font (make-object font% 30 font-name 'symbol))
(f font)))
(map-fonts (λ(font) (inset (frame (text "Ax√h" font)) 10)))
"Info from pict box"
(map-fonts (λ(font) (info (text "√" font))))
"Info from get-text-extent"
(map-fonts (λ(font)
(define-values (x y z v) (send (dc-for-text-size)
get-text-extent "√" font))
(list x y z v)))
--
Jens Axel Søgaard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fontinfo.png
Type: image/png
Size: 121130 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20131115/7da360c2/attachment-0001.png>