Colorful emojis in Unicode are not isolated to specific ranges
of code points like other writing systems. Instead, there are
a set of rules defining whether a sequence of characters should
be displayed in color or black/white.
http://www.unicode.org/reports/tr51/
For instance, appending a variation selector to a character can
turn it into a color emoji, even if it is a code point that
predates the invention of emojis.
In addition, sequences of joined characters that are determined
to be a color emoji sequence should be parsed by a single emoji
font, so that it can apply things like skin color, etc.
In general, users expect emojis and emoji sequences to be shown
in the preferred color font of the system, even if a selected
font has black/white characters for the symbols.
This patch applies the emoji segmenter to strings to isolate
sequences that should be in color. As an implementation hack,
we mark this in the QScriptItems as a special "emoji" script.
Note that this is not a real Unicode script and only exists
internally for this reason, because the "emojiness" of the
resulting glyph overrides the original script of the
individual characters when selecting fonts. This way, we can
use a lot of the same logic for itemizing the strings and
looking up fonts, and we don't need to increase the size of
the QScriptItem. (It is just an implementation detail and
is not exposed to the user, so it can be replaced by other
approaches later if we need to.)
When matching an emoji sequence, we always try to apply a
color font and ignore all others. The exception is if there
is no color font at all on the system, then we will find a
black and white font which supports the characters instead
as a final failsafe.
In addition, each platform will put its default emoji font
at the top of the fallbacks list in order to make this the
preference in case there are more than one. This patch also
adds API to override this with an application-defined emoji
font, since this is a common use case.
Note: The font includes an environment variable to disable
the feature as a fail safe. A flag to disable it per QFont
will be added in a follow-up.
Fixes: QTBUG-111801
Change-Id: I9431ec34d56772ab8688814963073b83b23002ae
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Reviewed-by: <carl@carlschwan.eu>
We are already including the 'DejaVu' font, which is a
further development of Vera and includes the same glyphs.
Change-Id: I2eb58967751101489158ecbf268102a72b9b2bea
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
This makes Qt read the following config options at startup:
- qt.requestLocalFontsPermission
- qt.localFontFamiliesCollection
- qt.extraLocalFontFamilies
And adds the following instance function
- qtLoadLocalFontFamilies
These can be used to control which local fonts Qt will
use, and also if Qt should ask for local fonts permission
on startup.
Also register a startup task for font loading. Font
loading completes asynchronously at some point after
the initial startup, and this way we can prevent showing
the application until the requested fonts are available.
Change-Id: I2b353c8b9c1a4976dddeb447d1f867aa2adf7588
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This makes the code easier to follow since it is now
implemented in terms of the generic "val" type, and
also allows moving string conversions to behind the
family() etc accessors.
Change-Id: I17364de7f56bc14826e048ce70644c1e14508752
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Populate a subset of the font families at startup if the local fonts
access API is supported, and the access permission has been given.
Since this code runs at app startup there is no opportunity to request
font access. That should be done in response to user action, for
example by having a "load local fonts" button in the application.
Pick-to: 6.5
Change-Id: Ib6826deeec06ee3def0e793dd1462977710462be
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Found in API review: from/toUintArray() is too generic a name, make
sure its name gives enough context.
Pick-to: 6.5
Change-Id: Ie10ff06ae11a5e168c4c91b60a9698a41d0429fc
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Use the new QByteAaray::fromUint8Array() function.
Change-Id: I7bb7a8184e1bfde2a89af2efb331db64f0b4d285
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Add fallback font which supports emoji.
Similar logic of addding additional fallback fonts is used
for some other platforms.
Pick-to: 6.4
Fixes: QTBUG-87339
Change-Id: Iad9e7071bcc3c5bb1c11c6c745fd86f7d0f7860b
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
The font database on WASM attempts to call navigator.permissions.request
which might not exist on certain browsers. Check for undefined before
calling.
Change-Id: I079c8a127339cf6b83bc3f9c3106c752226e5d84
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Add support for accessing local fonts via local-fonts API.
Local fonts API is available in Chrome 103 and above.
Fixes: QTBUG-81736
Change-Id: Iac47b3a30c7a22933cbdbfc97ce0791edb63b5bd
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.
Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
As a drive-by, fix qsizetype -> int narrowing conversion warnings for
the touched lines.
Task-number: QTBUG-98434
Change-Id: I7fadd3cf27ad099028d70f05956303e3af62c0f5
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
The family name of a font is ambiguous and without additional
information there is no way to separate one font from another
inside that family.
In order to make it possible to expose more info about application
fonts from FontLoader in Qt Quick, we need to store them in the font
database.
Task-number: QTBUG-68829
Change-Id: I931e1c2c004437ac0a21d4d88e55d176de676f34
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
The content is static, so a dynamic container is overkill. Use a C array.
Don't make it static, as that creates more problems than is solves (static
initialization).
Change-Id: I07534c3336efbb6bbc19bfa1b8dad0c578d4e274
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Also define our default font so as to return something we actually have
Task-number: QTBUG-75587
Change-Id: I26e3c62921d369c3017af9796c0a20f7ac06d07c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This is the squashed diff from wip/webassembly to dev.
Done-with: Peng Wu <peng.wu@intopalo.com>
Done-with: Sami Enne <sami.enne@intopalo.com>
Done-with: Morten Johan Sørvig <morten.sorvig@qt.io>
Started-by: Andrew Knight <andrew.knight@intopalo.com>
Change-Id: I6562433c0a38d6ec49ab675e0f104f2665f3392d
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>