-
Notifications
You must be signed in to change notification settings - Fork 125
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
Control text leading trim #193
Comments
That's an interesting suggestion! I wasn't aware of the I'm not sure if I'd want to implement those as currently defined in the working draft, since they pretty clearly say "do not implement (yet)" and I'd like to avoid future compat issues. But, I do think it would be fairly trivial to do the following:
Do those sound like they'd enable what you want? In the meantime you should be able to infer some of those from what's currently provided ... for example in Note to self: this will become more complicated with the multiple fonts per line work, I'll need to give that more thought. |
That makes sense not to preemptively add anything until the spec is finalized! Love the idea of being able to use I think your suggestion of using I appreciate the quick reply! Again, thanks for such a cool text implementation! I was working on my own with things like text wrapping and very happy to see all of the wonderful work done here with things like text kerning and even selection! 🙏 |
Made some progress this week on getting all of the proper values, thanks for the half-leading tip! Curious if you have any ideas for how I can achieve I think I have all of the info I need now, just not sure how I should go about counteracting your line height calculation. Is this a feature you'd be open to supporting as well? Having more control of how line height is applied will make creating designs like this easier: |
Absolutely! If I'm understanding correctly, if the whole text block was just shifted upward by |
Awesome! 🎉 That equation for offsetting the text block to align the top to the cap height works great! But yeah, for a Using a simple example, I'd like to pass <Text capHeight={1} lineGap={0.5} /> I want this to size the text so the cap size is exactly 1 world unit and the space between the baseline and next cap height is 0.5 world units. To get the proper const capHeightScale = fontMetrics.capHeight / fontMetrics.unitsPerEm
const fontSize = capHeight / capHeightScale This works great and sizes the cap height appropriately to one world unit, but then I run into trouble trying to calculate the offset for the Happy to help with PRs here btw 😁 I can start something once I get some time here probably later in the month. |
Thank you for the examples! I'm starting to understand better now. 😁 I've added a couple things to get closer:
I think the big missing piece now is that the font sizing (and therefore line height) is solely based on the "em height" as defined in CSS, whereas you want to have it use the cap height as the basis, does that sound accurate? I'll ponder this some more. |
Woot, appreciate you getting those in! 🙌
Yeah, exactly! Ideally, being able to control spacing between the baseline and next cap height or the spacing between the descender and next cap height would be amazing. This is how traditional graphic designers controlled the spacing between lines which unfortunately never made its way into CSS. |
Giving some more thought to what an API could look like, maybe allowing control of start/end of the {
fontSize: 1.35,
lineHeight: 1.125,
lineHeightStart: 'descender', // or baseline
lineHeightEnd: 'cap'
} Not sure how this would translate to the current functionality to prevent any breaking changes though. |
I've been toying with the idea of a It may not hit all use cases, but I feel like that could make a lot of the things you're trying to do easier ... once you can control the exact height of the "cap" using fontSize, for instance, then since lineHeight is always relative to the fontSize then you can control the gap between "cap"s using simple math. lineHeight = (fontSize + "line gap") / fontSize |
That sounds great! 😍 I've been trying to hack around it this week with no luck so a more first-class way to do it would be wonderful! Related, I was wondering how line height relates to the browser's line height? I've been thinking of world units as rems, but not sure if that's a correct way to think about it. I made an example here to illustrate what I'm doing in web with rem units and then when trying to do it with trokia it seems the line height is much more dramatic with the same values. |
Cool, I'll give that a shot then.
I guess you could think of world units that way? I tend to think of them like real-world meters, though. But for lineHeight specifically, remember that a numeric lineHeight is always relative to the fontSize. So if your calculated line height is in rems or px or some other absolute length, you probably need to divide it by the fontSize. |
Ah, ok that makes way more sense now! Dividing the line height by the font size is exactly what I was looking for and looks like it works with Capsize as expected now 😎. I was definitely overcomplicating that lol. Thank you so much for all of your help on this so far and for adding the extra needed info and features! Happy to help test the |
Hello, thank you for this amazing library! I'm currently using the
Text
component in@react-three/drei
and wondering if there's a way to achieve control over leading trim? I was looking to use Capsize to possibly do it, but then came across #82 which saysblockBounds
andvisibleBounds
were added which seems like could be helpful here. I would love a first-class way to control this, but interested if you have a suggestion to hack a solution for now? Happy to help look into a PR for support if you're interested 🙂The text was updated successfully, but these errors were encountered: