draw icon indicating copy to clipboard operation
draw copied to clipboard

[Feature Request] draw font% does not expose kerning

Open ceving opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. It is not possible to draw the letters "V" and "A" correctly next to each other, because the library racket/draw does not expose the kerning table of a font.

Describe the solution you'd like I would like to have a function, which returns the kerning similar to kerning-value of "sfont".

It would be nice to have a function, which calculates the kerning between two strings or characters. It seems to me that currently this is the only way to calculate the kerning between two strings:

#lang racket/gui

(define font (make-font #:size 16 #:face "Latin Modern Roman"))

(define frame (new frame% [label ""]))
(define canvas (new canvas% [parent frame]))

(define dc (send canvas get-dc))

(define left "A")
(define right "V")
(define both (string-append left right))

(define-values (left-text-width left-text-height left-baseline-height left-extra-height)
  (send dc get-text-extent left font #t))
(values left-text-width left-text-height left-baseline-height left-extra-height)
(printf "\n")

(define-values (right-text-width right-text-height right-baseline-height right-extra-height)
  (send dc get-text-extent right font #t))
(values right-text-width right-text-height right-baseline-height right-extra-height)
(printf "\n")

(define-values (both-text-width both-text-height both-baseline-height both-extra-height)
  (send dc get-text-extent both font #t))
(values both-text-width both-text-height both-baseline-height both-extra-height)
(printf "\n")

(- (+ left-text-width right-text-width)
   both-text-width)

ceving avatar Nov 22 '23 08:11 ceving