-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
CSS Text Modifiers for Canvas2D #5617
Comments
The WebKit team feels this is a good direction. |
In principle this was closed by #6560, but it seems there's some late feedback in w3ctag/design-reviews#627 about the naming. @whatwg/canvas do we want to revisit this? Personally I'm not convinced that changing the shape of the API is the way to go. CSS properties are themselves exposed in camel case as well through |
This was fixed in #6560. |
Oh, oops, I see there was discussion about revisiting the naming, hmm... |
@yiyix @mysteryDate is the intention still to change |
Thank you for the reminder! It is still the plan! I will submit a renaming change and code change. |
@yiyix I'm on the fence. I can see some value in renaming these, but they do not directly map to CSS properties (e.g., these are doubles and don't accept all the various values they would in CSS). So either way seems okay. If this is already shipping in more than one implementation I don't think we should rename. |
Linking the preexisting discussion OpenType Features and Variable Fonts for Canvas |
@annevk, based on the status of the two bug I created to add these attributes on firefox and safari, I believe we are still the only browser who has implemented it. ref bug: |
@annevk Please note that the feedback we provided was not just my opinion, but the consensus from the relevant discussion with the rest of the TAG. I can bring it back to the group in light of this new info to discuss again and update the design review thread. |
Thanks @LeaVerou, appreciate it! |
I don't think we have opinions about naming. |
@yiyix if Chromium wants to rename these and take the hit, I don't see a problem. |
There is another issue for letterSpacing and wordSpacing attributes. Now these attributes are defined as |
I'm personally not really convinced by this idea. I guess it would be interesting to check the usage of such units in the |
I agree that usually string properties can be annoying. The reason this one may be different, is that letterSpacing/wordSpacing usually make more sense when defined relative to the font size (like with This case is different from setting the font size, because the value is always in relation to the canvas' font size (so it won't matter if the canvas is disconnected or not). It's true that this is not a major problem, as anyone can just compute Do you think it would be better if we allowed both? Numbers as px and string as CSS values? |
Oh right,
Would that work? Would the internal
I thought of this too, but I fear this would make for a very confusing API, no? Given your arguments, I am less strongly opposed to this idea, I still kind-of dislike having to compose strings, but |
I don't know how far along CSSOM types are, but they could be another alternative here. |
In our current design, after each font change, the letterSpacing and wordSpacing will be re-applied. So all the relative units will be automatically related to the new font. |
I am fine with this suggestion - taking doubles as |
Yes, this seems like a serious concern to me. I think using doubles as ems for these properties would be bad. |
I tried looking through https://drafts.css-houdini.org/css-typed-om . I think this might work? ctx.letterSpacing = CSS.em(0.2).to("px"); but this is a bit confusing because it seems like it should need a context in which to perform the em -> px conversion... and indeed, Chrome Canary throws when I try @tabatkins, any hope for something like |
Unless I'm missing something I believe CSS Typed OM types would not be of great help here. ctx.font = "20px sans-serif";
ctx.letterSpacing = "0.2em"; // resolves to 4px
ctx.fillText(txt, x, y);
// ...
// then some times later
ctx.font = "40px sans-serif";
// here letterSpacing is still "0.2em", but it now resolves to 8px
ctx.fillText(txt, x, y); The conversion But I agree that having only these two properties take in ratios rather than In my mind, the side effect of changing Now one advantage of accepting a DOMString like |
@Kaiido explained better than I did. Based on our discussion so far, we believe 1. making letterSpacing/wordSpacing takes String and double is confusing to the devs. 2. Having only letterSpacing/wordSpacing taking ration, i.e. Maybe we can make letterSpacing and wordSpacing accept dimension-token in String form? a number with its length unit? |
Switching entirely to string properties seems fine to me. Probably following the model that the |
textLetterSpacing → letterSpacing, and textWordSpacing → wordSpacing. Closes whatwg#5617.
textLetterSpacing → letterSpacing, and textWordSpacing → wordSpacing. Closes whatwg#5617.
Currently, some CSS text rendering properties can't be used for canvas text. Some browsers do support setting them a Canvas style object, for an attached canvas. This spec tries to bring those properties inside canvas.
Working proposal: https://github.com/fserb/canvas2D/blob/master/spec/text-modifiers.md
(cc @whatwg/canvas )
The text was updated successfully, but these errors were encountered: