The contents of a Text would wander to the left with center and
right alignment because some size calculations don't take the
maximum available width into account.
The database is not empty, as the changed expect() suggests, but instead
it just means that the family could not be found. This can happen for
example with something like this:
export App := Window {
Text {
text: "Ok";
font-family: "Non-existent";
}
}
or it can also happen when loading the printer demo in the online
editor, where a custom font is supposed to be available but that's not
implemented for wasm builds.
So instead of panicing, fall back to querying for a last-resort
sans-serif family.
For Linux, we register fontconfig's choice for sans-serif, otherwise
fontdb has defaults for macOS and Windows, and for wasm we register our
copy of DejaVu. So that cannot really fail....
When processing window specific events, or generally when accessing
the ALL_WINDOWS refcell, keep the time for borrow to an absolute
miniumum. That way any subsequent method calls may further acquire the
refcell.
This patch re-organizes the entire deeply nested window event handling
in a function with slightly less indentation.
Fixes a panic when calling hide on a Window from within a callback
handler.
Fixes#539
Use the new fontdb API:
* When registering embedded fonts, we don't need to make a copy of the
embedded font data anymore.
* We don't have to mmap the font files ourselves anymore, fontdb can
do this now for us.
Don't apply constraints to the winit window if we're in fullscreen mode,
as that might result in us allocating a surface that's bigger than the
screen, which in turn may result in the process exiting right away.
Fixes#532
Various third-party bumps and femtovg bumped to include a fix for exact
GLES 2.0 detection. Glutin may give us a 3.x GLES context even if we ask
for 2.0 (https://github.com/rust-windowing/glutin/issues/1282) and I can
reproduce that for example on Raspbian with MESA. But femtovg should
work with both, hence the update.
It works with the Qt backend, and it should work with the GL backend as
well. usvg supports it, uses the same underlying shaper and the API even
allows sharing the font database.
We default to querying GlLatest from glutin, which might run into a code
path in glutin's `bind_and_get_api` in `egl/mod.rs` that will return
None as version and pass that to `choose_fbconfig`. That function will
panic with unimplemented() if the bound API is GLES, because we need to
know which version of GLES. The bound API in turn might be GLES if
desktop GL is not supported.
To accomodate for this situation, this patch changes the GL context
creation logic to first try explicitly GLES 2.0 and then fall back to
the GlLatest variants.
In addition this pulls in a newer version of femtovg to fix FBO
rendering with stencil with GLES 2.0.
This version doesn't require the change to fontdb yet, but uses the new
femtovg API to allow feeding in shared (mmapped) font data. On macOS
this saves 4-5 MB of ram just for the gallery, on my default Ubuntu it's
roughly ~40MB.
Copypasta's wayland clipboard requires a different API that we don't cater to yet, so
for now to fix the build, disable the clipboard (use in-app nop).
The GL backend defaults to enabling X11. The default crate depends on
the GL backend but it doesn't specify default-features = false,
therefore x11 is basically always enabled.
In line with commit 1fd8c7236a, this
change makes sure that the defaults are defined in the tree entry
points: The Rust API crate, the interpreter crate and the CMake project
define the defaults. The latter already enabled X11 by default, but the
first two did not.
The checkmark and reload have always been missing in some circumstances.
The recent fixes with glyph coverage check helped, but they do not account for the fact that
characters like the check mark map to the same script (Common). So for these scripts
we need to perform an exact glyph coverage check.
Avoid the dance of using font-kit to re-discover the same .ttf file and
read it all into memory every time we need to render text where the primary font
provides insufficient coverage.
The font resolution function querying fontdb is fast now, so we can
always call it when rendering text. That way we don't need all the
indirection in the text_size(), etc. functions, we don't need an entry
in the item graphics cache for the font and we can avoid a lot of
property dependencies.
Instead of always mapping the face (from disk), first fan out existing
cached coverage information. Any unchecked scripts are then checked
in the slow code path with `with_face_data` later.
Use the static (but long) fallback list that we get from fontconfig in the beginning.
This works, but can be optimized to operate on a trimmed and shorter list,
which will speed up the fallback. But for now this makes it work.
Unfortunately the text property was not included in the property dependency chain
for the cached Font.
This is fixed by delaying that with a getter function, but in the mid term
we should be able to remove this again once
femtovg learns lazy font resolution.
The basic idea is to use fontdb's load_system_fonts() mechanism, in
conjunction with its built-in mmap support, to get an overview over all
installed fonts on macOS, Windows and Linux.
This isn't quite perfect in terms of discovering systems defaults, but
it's much faster than font-kit's approach of querying the system (good)
but reading the matched files into memory (not using mmap). And we have
the option of perfecting it by using fontconfig directly on Linux (where
the backend is most important).
This also paves the way for better fallback handling, as now we have a
list of all available families and we can use system APIs to query for
fallbacks.
Set QStyle::State_Active conditional to whether the window is active,
which maps to Qt's active window concept and winit's has-focus (until we
render popups differently).
The srgb workaround from commit a0e827e200
appears to work with the AMD GL driver, without which the GL context
creation works (as tested by the reporter).
So instead of panicing, fall back to the glutin default with possibly an
srgb framebuffer, when trying to create a GL context. If that also
fails, provide a better error message than "called unwrap on an err".
cc #481
As tests/cases/examples/image_rendering.60 itself demonstrates, the png file
should be loaded into the CPU side image cache once, but the two textures
should be cached independently.
cc #465
Improve the granularity of the borrow of the mapped window, to avoid
that when applying window properties we recurse into a borrow due to
the call for setting the geometry triggering a notify that borrows.
Like CSS image-rendering it has "smooth" and "pixelated" options.
Only OpenGL has been tested right now, have not tested WASM or Qt.
Right now the first instance of a @image-url() will set the scaling
for that specific image. The same image used from memory on the otherhand
can all have a different scaling property.