[quad] dynamically query for a character width #33

Closed
opened 4 years ago by sorawee · 8 comments
sorawee commented 4 years ago (Migrated from github.com)

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).

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 (Migrated from github.com)

Knowing the character width would not make this layout possible.

Knowing the character width would not make this layout possible.
mbutterick commented 4 years ago (Migrated from github.com)

Would you rather have real PDF form fields?

Would you rather have real PDF form fields?
sorawee commented 4 years ago (Migrated from github.com)

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!

> 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 (Migrated from github.com)

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.

> 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 (Migrated from github.com)
#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

``` #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](https://user-images.githubusercontent.com/1425051/75498901-52040280-597d-11ea-9902-521b9867c491.gif)
sorawee commented 4 years ago (Migrated from github.com)

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.

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 (Migrated from github.com)

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.

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 (Migrated from github.com)

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

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](https://user-images.githubusercontent.com/1425051/75599413-9795fd80-5a59-11ea-8e59-0a538b48d71f.gif)
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#33
Loading…
There is no content yet.