Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I convert a font% size to style-delta% size? #323

Closed
benknoble opened this issue Jan 3, 2024 · 1 comment
Closed

How do I convert a font% size to style-delta% size? #323

benknoble opened this issue Jan 3, 2024 · 1 comment

Comments

@benknoble
Copy link

A style-delta% can only 'change-size to values of a byte?, but it is documented as taking a "size." Meanwhile a font% reports sizes as (real-in 0.0 1024.0). (A Racket byte? is 0 to 255.)

I'm not even sure how to interpret the values, so it's not clear how to convert one to the other. (I'm already using 'change-size-in-pixels to make sure the style-delta% and font% interpret the size the same way, but they don't speak the same contract…)

I tried using a size of 1, an additive factor of 0, and a multiplicative factor of the font's size, but that produced the wrong results (too big) on normal-control-font, which has a size of 13.0.


Context: I'm trying to convert a font% to a style-delta% so that the different fonts in my application are consistent. All the other properties seem straightforward to translate. Here's the current version of the function, and the results using normal-control-font as the base font (minus the size changes, of course):

(define (font->delta f)
  (define d (new style-delta%))
  (define size-in-pixels? (send f get-size-in-pixels))
  (define size (send f get-size))
  (define family (send f get-family))
  (define face (send f get-face))
  (define style (send f get-style))
  (define weight (send f get-weight))
  (define underline (send f get-underlined))
  (define smoothing (send f get-smoothing))
  (send* d
         (set-delta 'change-size-in-pixels size-in-pixels?)
         #;(set-delta 'change-size size)
         (set-delta 'change-family family)
         (set-face face)
         (set-delta 'change-style style)
         (set-delta 'change-weight weight)
         (set-delta 'change-underline underline)
         (set-delta 'change-smoothing smoothing))
  d)
Window with a label and a rich-text display.

(I'm also hoping to figure out how to scale the pict? in the text so it's the same size, but that's unrelated to this, I think.)

@benknoble
Copy link
Author

It seems the docs are wrong; 'change-size takes any exact-integer?; using exact-truncate is enough for me for now.

rfindler added a commit that referenced this issue Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant