mbutterick/quad

Underline

Closed this issue · 5 comments

Is there a way to create a text underline in quad? I attempted to emulate it using border-width-bottom, but its width is page-width rather than the width of the text.

This also leads to a couple of more questions:

  • Is it possible to create a box/block whose width varies with the content.
  • Is it possible to create a box/block whose width is fixed but whose height varies with the content?

Is there a way to create a text underline in quad

I just added a font-underline attribute.

Is it possible to create a box/block whose width varies with the content
Is it possible to create a box/block whose width is fixed but whose height varies with the content

Can you give me an example? In general if you’re looking for HTML/CSS layout tricks, the answer is likely to be “possible, but harder”. The HTML/CSS layout model makes a priority of expanding to fit everything (which is easy, because screen real estate is unlimited). Quad, by contrast, targets PDF, which means that things have to get wrapped, which means being more strict about imposing measurements.

I was thinking about how html has divs and LaTeX has boxes, so I wonder if there's anything equivalent to these in quad. For this particular issue, it would allow me to simulate underline by creating a box that only draws the bottom border, but since you just added that feature directly, I wouldn't pursue this question any further. Still, I think it's a useful concept and there are of course going to be other use cases. I just couldn't come up with one off the top of my head right now.

By the way, for the underline feature that you just added, is there a way to parameterize the base line relative to the underline? For instance, here's how "ขูดรีด" with an underline looks in other word processors:

Screen Shot 2020-02-21 at 17 01 09

And this is how it looks in quad

Screen Shot 2020-02-21 at 17 01 04

A font specifies an underline distance & thickness. I’ll look into reading that info out of the font (instead of drawing an arbitrary line, which is how it works now)

I was thinking about how html has divs and LaTeX has boxes, so I wonder if there's anything equivalent to these in quad.

The name “quad” refers to the underlying box-like data structure. Under the hood, most layout effects (say, in Quadwriter) are achieved by linking quads together in certain ways. What you suggest is possible, but I think it’s a better idea to make the underlining a font-styling attribute (as opposed to an attribute of the surrounding quad.) One reason is that a run of text can wrap across lines, so packaging it in a single quad and then underlining doesn’t make sense.

Fixed in mbutterick/pitfall@61e2c47

font-underline will now use the font-specific fields for underline position & thickness. I don’t know if it matches other word processors. But in principle this seems like the best way of going about it. We will see if it turns out to be true in practice.