-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add font family parser #20
Conversation
I honestly not sure at what point escaping should be done. Technically, |
let ch = self.curr_byte()?; | ||
if ch == b'\'' || ch == b'\"' { | ||
let res = self.parse_string()?; | ||
FontFamily::Named(res.to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return &str
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I should have it take a Cow? because I also need to be able to pass an owned string (see below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? You're never modifying the input string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, here, basically when the font name is given as a list of idents instead of a quoted string:
let joined = idents.join(" ");
// TODO: No CSS keyword must be matched as a family name...
match joined.as_str() {
"serif" => FontFamily::Serif,
"sans-serif" => FontFamily::SansSerif,
"cursive" => FontFamily::Cursive,
"fantasy" => FontFamily::Fantasy,
"monospace" => FontFamily::Monospace,
_ => FontFamily::Named(joined),
}
The spec requires us to parse multiple spaces as a single space (which should again probably be done at the CSS parsing level, but since it's relatively straight-forward I just implemented it here).
Not to mention that Basically, there is an endless amount of work left in resvg. |
At least from my testing it seems like most browsers recognize them. But not sure if it's mentioned anywhere in the specification. |
I haven't seen it in the spec either. Very confusing. |
Thanks! |
I'm planning on adding the font shorthand as well in the next few days and then I'll update it on |
Sounds good! |
Still need to add documentation and maybe some more tests (if you have any suggestions let me know). But I wanted to get some feedback on the technical side first before doing that.
I basically copied the char processing from
simplecss
since it's also what we need.Escape sequences are currently not processed (including normal escape sequences like "). I don't think there are many font names with a quotation mark inside, so I think it should be fine. :p
Let me know what you think!
I also rewrote
resvg
on my branch it it seems to work without problems (one problem I encountered was that in some test files the font "Mplus 1p" was used but it was not put in quotes, which I think is wrong because an ident cannot start with a number. Once I put it in quotes, it worked again with my version.Some relevant links:
https://www.w3.org/TR/2018/REC-css-fonts-3-20180920/#font-family-prop
https://drafts.csswg.org/css-syntax-3/#typedef-ident-token