Use the Noto fonts from the C++ build of the printer demo

This adds API to register a font by path from C++
This commit is contained in:
Simon Hausmann 2021-02-18 15:01:09 +01:00 committed by Olivier Goffart
parent 0a1b93593b
commit 1b870959e6
5 changed files with 41 additions and 0 deletions

View file

@ -19,6 +19,7 @@ LICENSE END */
#include <algorithm>
#include <iostream> // FIXME: remove: iostream always bring it lots of code so we should not have it in this header
#include <chrono>
#include <optional>
namespace sixtyfps::cbindgen_private {
// Workaround https://github.com/eqrion/cbindgen/issues/43
@ -669,4 +670,18 @@ void run_event_loop()
cbindgen_private::sixtyfps_run_event_loop();
}
/// Registers a font by the specified path. The path must refer to an existing
/// TrueType font font.
/// \returns an empty optional on success, otherwise an error string
std::optional<SharedString> register_font_from_path(const SharedString &path)
{
SharedString maybe_err;
cbindgen_private::sixtyfps_register_font_from_path(&path, &maybe_err);
if (!maybe_err.empty()) {
return maybe_err;
} else {
return {};
}
}
} // namespace sixtyfps

View file

@ -85,6 +85,9 @@ struct SharedString
const char *begin() const { return data(); }
const char *end() const { return &*std::string_view(*this).end(); }
/// \return true if the string contains no characters; false otherwise.
bool empty() const { return std::string_view(*this).empty(); }
/// Creates a new SharedString from the given number \a n. The string representation of the
/// number uses a minimal formatting scheme: If \a n has no fractional part, the number will be
/// formatted as an integer.