Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
font-discovery.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include <functional>
4#include <glibmm/ustring.h>
5#include <memory>
6#include <sigc++/connection.h>
7#include <sigc++/signal.h>
8#include <vector>
9#include <pangomm.h>
11#include <sigc++/scoped_connection.h>
13#include "statics.h"
14
15namespace Inkscape {
16
17struct FontInfo {
18 Glib::RefPtr<Pango::FontFamily> ff;
19 Glib::RefPtr<Pango::FontFace> face;
20 Glib::ustring variations; // pango-style font variations (if any)
21 double weight = 0; // proxy for font weight - how black it is
22 double width = 0; // proxy for font width - how compressed/extended it is
23 unsigned short family_kind = 0; // OS/2 family class
24 bool monospaced = false; // fixed-width font
25 bool oblique = false; // italic or oblique font
26 bool variable_font = false; // this is variable font
27 bool synthetic = false; // this is an alias, like "Sans" or "Monospace"
28};
29
31
32class FontDiscovery : public Util::EnableSingleton<FontDiscovery, Util::Depends<FontFactory>>
33{
34public:
35 using FontsPayload = std::shared_ptr<const std::vector<FontInfo>>;
37
38 sigc::scoped_connection connect_to_fonts(std::function<void (const MessageType&)> fn);
39
40protected:
42
43private:
45 sigc::scoped_connection _connection;
47 sigc::signal<void (const MessageType&)>_events;
48};
49
50// Use font factory and cached font details to return a list of all fonts available to Inkscape
51std::vector<FontInfo> get_all_fonts();
52
53// change order
54void sort_fonts(std::vector<FontInfo>& fonts, FontOrder order, bool sans_first);
55
56Pango::FontDescription get_font_description(const Glib::RefPtr<Pango::FontFamily>& ff, const Glib::RefPtr<Pango::FontFace>& face);
57
58Glib::ustring get_fontspec(const Glib::ustring& family, const Glib::ustring& face);
59Glib::ustring get_fontspec(const Glib::ustring& family, const Glib::ustring& face, const Glib::ustring& variations);
60
61Glib::ustring get_face_style(const Pango::FontDescription& desc);
62
63Glib::ustring get_fontspec_without_variants(const Glib::ustring& fontspec);
64
65Glib::ustring get_inkscape_fontspec(
66 const Glib::RefPtr<Pango::FontFamily>& ff,
67 const Glib::RefPtr<Pango::FontFace>& face,
68 const Glib::ustring& variations);
69
70// combine font style, weight, stretch and other traits to come up with a value
71// that can be used to order font faces within the same family
72int get_font_style_order(const Pango::FontDescription& desc);
73
74Glib::ustring get_full_font_name(Glib::RefPtr<Pango::FontFamily> ff, Glib::RefPtr<Pango::FontFace> face);
75
76} // namespace Inkscape
Async::Msg::Message< FontsPayload, double, Glib::ustring, std::vector< FontInfo > > MessageType
sigc::signal< void(const MessageType &)> _events
std::shared_ptr< const std::vector< FontInfo > > FontsPayload
Inkscape::Async::OperationStream< FontsPayload, double, Glib::ustring, std::vector< FontInfo > > _loading
sigc::scoped_connection connect_to_fonts(std::function< void(const MessageType &)> fn)
sigc::scoped_connection _connection
const unsigned order
TODO: insert short description here.
std::variant< OperationStarted, OperationProgress< T... >, OperationResult< R >, OperationCancelled, OperationException, OperationFinished > Message
Helper class to stream background task notifications as a series of messages.
Glib::ustring get_inkscape_fontspec(const Glib::RefPtr< Pango::FontFamily > &ff, const Glib::RefPtr< Pango::FontFace > &face, const Glib::ustring &variations)
Glib::ustring get_fontspec_without_variants(const Glib::ustring &fontspec)
int get_font_style_order(const Pango::FontDescription &desc)
void sort_fonts(std::vector< FontInfo > &fonts, FontOrder order, bool sans_first)
Pango::FontDescription get_font_description(const Glib::RefPtr< Pango::FontFamily > &ff, const Glib::RefPtr< Pango::FontFace > &face)
Glib::ustring get_fontspec(const Glib::ustring &family, const Glib::ustring &face, const Glib::ustring &variations)
Glib::ustring get_face_style(const Pango::FontDescription &desc)
std::vector< FontInfo > get_all_fonts()
Glib::ustring get_full_font_name(Glib::RefPtr< Pango::FontFamily > ff, Glib::RefPtr< Pango::FontFace > face)
Static objects with destruction before main() exit.
unsigned short family_kind
Glib::RefPtr< Pango::FontFace > face
Glib::ustring variations
Glib::RefPtr< Pango::FontFamily > ff