Skip to content

Enabled use of FontFamily enum type - #8420

Merged
bors-servo merged 1 commit into
servo:masterfrom
craftytrickster:8371/generic-font-family
Dec 31, 2015
Merged

bors-servo merged 1 commit into
servo:masterfrom
craftytrickster:8371/generic-font-family

Conversation

@craftytrickster

Copy link
Copy Markdown
Contributor

#8371

In addition to replacing loose strings with the FontFamily enum in font_cache_task.rs, I also centralized the add_generic_font calls into one single function. If centralizing into one function is not desired or if anything else needs to be changed, please let me know.

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 9, 2015
@highfive

highfive commented Nov 9, 2015

Copy link
Copy Markdown

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @glennw (or someone else) soon.

@SimonSapin

Copy link
Copy Markdown
Member

While the style changes look ok (modulo one issue), this doesn’t do the more important part of treating "serif" and serif differently in font code.

I really don’t know our font code at all, so I’d rather that someone who does suggests what to do here. @glennw maybe?


Reviewed 1 of 2 files at r1.
Review status: 1 of 2 files reviewed at latest revision, 4 unresolved discussions.


components/gfx/font_cache_task.rs, line 107 [r1] (raw file):
Nit: remove vec! here to avoid allocating memory. (Use a bare […] array.)


components/gfx/font_cache_task.rs, line 119 [r1] (raw file):
With the vec to array change above, replace these three lines with font (ref font_family, mapped_name) in &font_pairs {


components/style/properties.mako.rs, line 1722 [r1] (raw file):
This method is suspicious: it makes e.g. FontFamily::Serif indistinguishable from FontFamily::FamilyName("serif") which is what this enum is about in the first place. I’d rather remove it, but I don’t know how to update the code that uses it.


components/style/properties.mako.rs, line 1735 [r1] (raw file):
Please replace this with:

                    match *self {
                        FontFamily::FamilyName(ref name) => ::cssparser::serialize_string(name, dest),
                        FontFamily::Serif => dest.write_str("serif"),
                        FontFamily::SansSerif => dest.write_str("sans-serif"),
                        FontFamily::Cursive => dest.write_str("cursive"),
                        FontFamily::Fantasy => dest.write_str("fantasy"),
                        FontFamily::Monospace => dest.write_str("monospace"),
                    }

… which writes a quoted string for non-generic names.


Comments from the review on Reviewable.io

@SimonSapin SimonSapin assigned glennw and unassigned SimonSapin Nov 11, 2015
@craftytrickster

Copy link
Copy Markdown
Contributor Author

components/gfx/font_cache_task.rs, line 107 [r1] (raw file):
Good call. I've been writing too much JavaScript lately where you don't have to think about heap/stack allocations.


Comments from the review on Reviewable.io

@glennw

glennw commented Nov 12, 2015

Copy link
Copy Markdown
Member

@SimonSapin I may be missing the context here, but it sounds like the font cache should take the FontFamily enum as input in its public APIs (rather than a string as it does now). Once this is changed, the internal font cache code could be updated to distinguish between them, by only transforming the font name to a generic one when the specified type is not a FontFamily::FamilyName(Atom).

Does that sound right to you?

@glennw

glennw commented Nov 23, 2015

Copy link
Copy Markdown
Member

@SimonSapin ping

@SimonSapin

Copy link
Copy Markdown
Member

@glennw I don’t know anything about our font code beyond parsing in the style crate, but what you describe sounds about right.

Fixing this should make tests/wpt/css-tests/css21_dev/html4/font-family-rule-012.htm pass, assuming #8374 also lands. That PR make AHEM_serif.ttf available to tests. The name field of that font is serif, so it should match font-family: "serif", but not font-family: serif which should be a UA-chosen default.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #8667) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 25, 2015
@craftytrickster

Copy link
Copy Markdown
Contributor Author

Should I resolve the merge conflicts or should I close the PR?

@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Nov 25, 2015
@jdm

jdm commented Nov 25, 2015

Copy link
Copy Markdown
Member

There shouldn't be any need to close this PR. Any changes to address the previous comments and the merge conflicts can be force pushed to the same branch.

@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from 54cc7b7 to c3cf40a Compare November 26, 2015 00:26
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-rebase There are merge conflict errors. labels Nov 26, 2015
@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from 3a66914 to ac38845 Compare November 29, 2015 21:07
@craftytrickster

Copy link
Copy Markdown
Contributor Author

Added correct email address to commits

Comment thread components/gfx/font_cache_task.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this converts the family to a string here, I don't see how it can differentiate between the enum value and 'serif' as a string when selecting which font to return?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I did this a while ago, I originally tried to pass around the enum FontFamily version instead of using a string, but I ran into problems with some functions that are being called from another module that depend on using a string (they were unsafe blocks that depended on c-like strings). I will look around again to see if there is anything I can do, and I will post my findings.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 3, 2015
@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from ac38845 to 4b667af Compare December 5, 2015 15:43
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 5, 2015
@craftytrickster

Copy link
Copy Markdown
Contributor Author

Please let me know if anything else is missing.

@glennw

glennw commented Dec 7, 2015

Copy link
Copy Markdown
Member

I ran the WPT tests on this PR and got 33 test failures - they seem to be related to our mozilla tests that use the css/ahem.css file.

@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from 4b667af to 8c08b7b Compare December 10, 2015 11:20
Comment thread components/style/properties.mako.rs Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I do this instead in order to avoid a clone?

                pub fn from_atom(input: Atom) -> FontFamily {
                    let option = match_ignore_ascii_case! { &input,
                        super::SERIF => Some(FontFamily::Serif),
                        super::SANS_SERIF => Some(FontFamily::SansSerif),
                        super::CURSIVE => Some(FontFamily::Cursive),
                        super::FANTASY => Some(FontFamily::Fantasy),
                        super::MONOSPACE => Some(FontFamily::Monospace)
                        _ => None
                    };

                    match option {
                        Some(family) => family,
                        None => FontFamily::FamilyName(input)
                    }
                }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloning an atom isn't very expensive (it's atomically reference counted), so it's probably fine. @SimonSapin is there a better way to do this while using that macro?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not expensive, but we have the opportunity to not clone here, so let's do it I guess?

@glennw

glennw commented Dec 17, 2015

Copy link
Copy Markdown
Member

Thanks for the changes. One minor question for Simon to reply with, after that it looks good to me once squashed.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

Thank you for the review.

@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from 0b6fcf5 to e536883 Compare December 17, 2015 02:53
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #9019) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 18, 2015
@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from e536883 to d2dfe3d Compare December 19, 2015 00:48
@nox nox removed the S-needs-rebase There are merge conflict errors. label Dec 30, 2015
@nox

nox commented Dec 30, 2015

Copy link
Copy Markdown
Contributor

@craftytrickster Fix that clone and I'll r=glennw.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 30, 2015
@craftytrickster
craftytrickster force-pushed the 8371/generic-font-family branch from d2dfe3d to d942bfb Compare December 30, 2015 23:21
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 30, 2015
@craftytrickster

Copy link
Copy Markdown
Contributor Author

@nox thanks for checking in on this, I made the change as requested.

@nox

nox commented Dec 30, 2015

Copy link
Copy Markdown
Contributor

@bors-servo r=glennw


Reviewed 2 of 4 files at r5, 3 of 3 files at r6.
Review status: all files reviewed at latest revision, 4 unresolved discussions.


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit d942bfb has been approved by glennw

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 30, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d942bfb with merge a1d7a33...

bors-servo pushed a commit that referenced this pull request Dec 31, 2015
Enabled use of FontFamily enum type

#8371

In addition to replacing loose strings with the FontFamily enum in `font_cache_task.rs`, I also centralized the add_generic_font calls into one single function. If centralizing into one function is not desired or if anything else needs to be changed, please let me know.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8420)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

⛄ The build was interrupted to prioritize another pull request.

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d942bfb with merge 66c8aa8...

bors-servo pushed a commit that referenced this pull request Dec 31, 2015
Enabled use of FontFamily enum type

#8371

In addition to replacing loose strings with the FontFamily enum in `font_cache_task.rs`, I also centralized the add_generic_font calls into one single function. If centralizing into one function is not desired or if anything else needs to be changed, please let me know.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8420)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants