mbutterick / pollen-users

please use https://forums.matthewbutterick.com/c/typesetting/ instead
https://forums.matthewbutterick.com/c/typesetting/
52 stars 0 forks source link

[quad] dynamically query for a character width #33

Closed sorawee closed 4 years ago

sorawee commented 4 years ago

For non-monospace font, each character could have different width. For instance . would be much less narrow than m. Is there a way to query for how wide each character is in quad?

Here's a use case. I am creating a form. In the unfilled state, the document could look like this:

Name: ................................
Age: .................................

In the filled state, it would look like this:

Name: ...Jane Doe.....................
Age: ...100...........................

The challenge is, how do I make sure that the length of the first line will be the same as the length of the second line? Particularly, it looks like I need a way to compute how wide the label in each line is, how wide the filled text in each line is, and subtract that from the desired length to determine how many dots I should put in.

Another solution would be something like \dotfill in LaTeX which automatically fills the rest of the line with dots. I then can use left-inset and right-inset to limit how much it can fill.

(http://joshua.smcvt.edu/latex2e/_005chrulefill-_0026-_005cdotfill.html documents \dotfill and how to use it to create a form like this).

mbutterick commented 4 years ago

Knowing the character width would not make this layout possible.

mbutterick commented 4 years ago

Would you rather have real PDF form fields?

sorawee commented 4 years ago

Would you rather have real PDF form fields?

For my use-case, no. The document that I'm producing really needs these ugly dots. But for the sake of completeness of quadwriter, yes!

sorawee commented 4 years ago

Knowing the character width would not make this layout possible.

I guess something similar to \dotfill is the way to go, then? The question is how to implement it.

mbutterick commented 4 years ago
#lang quadwriter

'(q ((line-height "14pt"))
    (q ((font-size "14pt")(space-after "-18pt")) "Name ................................")
    (para-break)
    (q ((inset-left "60pt")) "Jane Doe")
    (para-break)
    (q ((font-size "14pt")(space-after "-18pt")) "Age ...................................")
    (para-break)
    (q ((inset-left "60pt")) "100")
    )

Screen Shot 2020-02-27 at Feb 27  4 22 03 PM

sorawee commented 4 years ago

This would suffice for my use-case. Thanks!

By the way, I realize that I recently posted here a lot. If I generated too much noise, please let me know, and I will tone it down.

Another thing is, I do have a working document in LaTeX already, but it's not really sane. That's why I want to try quad and see if it could make my life easier. That being said, I realize that quad is in its infancy and might not right now be the right tool for what I eventually want to do. So please don't hesitate to tell me that if it's the case.

mbutterick commented 4 years ago

Not at all — I appreciate that you’re trying out the software and discovering its limits. I have pinched plenty of ideas from LaTeX already, though as you point out, many LaTeX documents are “not really sane”. I feel comfortable saying that preserving sanity is a design goal of Quad.

mbutterick commented 4 years ago

I forgot about font-baseline-shift, another option:

#lang quadwriter

'(q ((line-height "14pt"))
    (q ((space-after "-14pt")) "Name " (q ((font-size "0.7em") (font-baseline-shift "-4pt")) "............................................."))
    (para-break)
    (q ((inset-left "60pt")) "Jane Doe")
    (para-break)
    (q ((space-after "-14pt")) "Age " (q ((font-size "0.7em") (font-baseline-shift "-4pt")) "................................................."))
    (para-break)
    (q ((inset-left "60pt")) "100"))

Screen Shot 2020-02-28 at Feb 28  6 38 54 PM