Skip to content

Conversation

litherum
Copy link
Contributor

@litherum litherum commented Jun 8, 2022

10cdfcb

Cache system font shorthand information
https://bugs.webkit.org/show_bug.cgi?id=241404

Reviewed by Cameron McCormack.

This is the fourth piece of https://bugs.webkit.org/show_bug.cgi?id=237817.

System font shorthands are things like "font: caption" or "font: -apple-system-body".

There used to be a cache that was supposed to map each shorthand value to a CTFontDescriptor.
However, the cache didn't work, so I deleted it in
6ead527 This patch
reimplements it, but does so in platform/graphics/SystemFontDatabase, which is the natural
place to put it.

One of the repercussions of putting it in platform/ is that it can't use real CSSValuesIDs
as keys into the cache (because it's a layering violation to make things in platform/ see
CSS things). Therefore, this patch creates its own enum, which lives in platform/, which
conveniently exactly matches the relevant values from CSSValueID.

The Cocoa ports already have a SystemFontDatabaseCoreText which does similar things, but this
new cache is not platform-specific, so I'm putting it in SystemFontDatabase instead of
SystemFontDatabaseCoreText. SystemFontDatabaseCoreText will now inherit from SystemFontDatabase,
with 0 virtual methods. I've also taken the existing code that populates the previous cache
and temporarily duplicated it in SystemFontDabase***.cpp to make it populate this cache.

This patch doesn't actually _call_ the new cache, because doing so is somewhat complicated and
deserves its own patch. This patch just implements the cache itself. Also, because callers
aren't migrated to use this new cache yet, this patch doesn't delete the old cache either.
Both of those things will come in a follow-up patch.

* Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h:
* Source/WebCore/PlatformPlayStation.cmake:
* Source/WebCore/PlatformWin.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/SourcesGTK.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/SystemFontDatabase.cpp: Added.
(WebCore::SystemFontDatabase::systemFontShorthandInfo const):
(WebCore::SystemFontDatabase::systemFontShorthandFamily):
(WebCore::SystemFontDatabase::systemFontShorthandSize):
(WebCore::SystemFontDatabase::systemFontShorthandWeight):
(WebCore::SystemFontDatabase::clear):
* Source/WebCore/platform/graphics/SystemFontDatabase.h: Added.
* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::normalizeCTWeight):
(WebCore::denormalizeCTWeight):
* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h:
* Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm: Added.
(WebCore::cocoaFontClass):
(WebCore::SystemFontDatabaseCoreText::smallCaptionFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::menuFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::statusBarFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::miniControlFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::smallControlFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::controlFontDescriptor):
* Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabaseCoreText::clear):
(WebCore::cssWeightOfSystemFontDescriptor):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h:
* Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp: Added.
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp: Added.
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp: Added.
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::getReplacementTextGeometry const):

Canonical link: https://commits.webkit.org/251416@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295410 268f45cc-cd09-0410-ab3c-d52691b4dbfc

@litherum litherum self-assigned this Jun 8, 2022
@litherum litherum added Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 8, 2022
@litherum litherum requested review from heycam, nt1m, smfr and alanbaradlay June 8, 2022 06:33
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jun 8, 2022
@litherum litherum removed merging-blocked Applied to prevent a change from being merged Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 8, 2022
@litherum litherum force-pushed the eng/Cache-system-font-shorthand-information branch from 5522d4e to ef91774 Compare June 8, 2022 06:40
@litherum litherum added Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 8, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jun 8, 2022
@litherum litherum removed merging-blocked Applied to prevent a change from being merged Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 8, 2022
@litherum litherum force-pushed the eng/Cache-system-font-shorthand-information branch from ef91774 to f3ee595 Compare June 8, 2022 07:27
@litherum litherum added Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 8, 2022
Copy link
Contributor

@heycam heycam left a comment

Choose a reason for hiding this comment

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

I didn't check closely that the SystemFontDatabaseCoreText::xxxFontDescriptor functions are looking up the correct fonts, or that the table mapping CTFontWeights <=> CSS weights are reasonable. And I assume the Gtk/PS/Windows port code is just being moved.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to have a similar comment in CSSValueKeywords.in.

Comment on lines 69 to 71
Copy link
Contributor

@heycam heycam Jun 8, 2022

Choose a reason for hiding this comment

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

Not asking you to change this, and I guess it's not prevailing WebKit style to do this (only see a few instances of it), but I prefer the idiom of adding a Count value as the last value of an enum, when that's a thing that's needed. It would remove the risk of fontShorthandCount not being updated correctly. (I know that this means you'll get some non-exhaustive switch statement errors for that new value, but I think adding a dummy case for Count is a reasonable price to pay.)

I wouldn't bother subtracting the Caption value, if these enums won't have explicitly assigned values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually think I disagree 😕 I guess kind of feel that A) the whole point of enums is to restrict the representable values of an int to just the ones that are valid, but if you add new values which aren't valid, you've lost the whole philosophical purpose of enums, and B) more pragmatically, I'm more bothered by extra cases in switches (or the siren's song of just using default instead) than I am about having some things in WebKit have to match other things - which is already true about lots of things in WebKit, including some other things in this patch itself.

Comment on lines 91 to 92
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good idea, but I think it's a bit outside the scope of this change. I'll do this in a follow-up patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 394 to 395
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition took me too long to work out. :-) It would be easier to understand as:

if (value >= before.ctWeight && value <= after.ctWeight) {
    ...
    return ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in general in WebKit we prefer early-return style, but I'm happy to reorganize this code to make it more readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

"Normalize" and "denormalize" don't sound like the right terms to me. What about convertCTWeightToCSSWeight and vice versa?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 I use normalize in other places, under the assumption that we are a web engine so of course the "normal" form will be the CSS form. I think I take your point, though - I'll rename all the places in a follow-up patch.

Comment on lines 419 to 420
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jun 8, 2022
Copy link
Contributor

Choose a reason for hiding this comment

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

“Adwaita” refers to the default GTK theme for user interface controls, which we do reuse in the WPE port. I guess the idea is using this implementation for the WPE port, given that the GTK port gets its own version of the code. If that's the case, it would make more sense to call if SystemFontDatabaseWPE.cpp or even SystemFontDatabaseDefault.cpp because there is nothing specific about WPE in the code 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, no problem 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

@litherum litherum removed merging-blocked Applied to prevent a change from being merged Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 9, 2022
@litherum litherum force-pushed the eng/Cache-system-font-shorthand-information branch from f3ee595 to 8d161b2 Compare June 9, 2022 02:01
@litherum litherum added Text For bugs in text layout and rendering, including international text support. WebKit Nightly Build labels Jun 9, 2022
@litherum litherum force-pushed the eng/Cache-system-font-shorthand-information branch from 8d161b2 to c048c5d Compare June 9, 2022 03:03
@litherum litherum added the merge-queue Applied to send a pull request to merge-queue label Jun 9, 2022
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/Cache-system-font-shorthand-information branch from c048c5d to 10cdfcb Compare June 9, 2022 05:12
@webkit-early-warning-system webkit-early-warning-system merged commit 10cdfcb into WebKit:main Jun 9, 2022
@webkit-early-warning-system
Copy link
Collaborator

Committed r295410 (251416@main): https://commits.webkit.org/251416@main

Reviewed commits have been landed. Closing PR #1369 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system removed the merge-queue Applied to send a pull request to merge-queue label Jun 9, 2022
@philn
Copy link
Member

philn commented Jun 9, 2022

This broke GTK build btw...

@philn
Copy link
Member

philn commented Jun 9, 2022

eocanha pushed a commit to eocanha/WebKit that referenced this pull request Dec 20, 2024
…ki/2.38/do_not_stop_navigation_when_fragment_navigation_starts

Do not stop navigation when fragment navigation starts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Text For bugs in text layout and rendering, including international text support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants