cgv
Loading...
Searching...
No Matches
font_server.cxx
1#include <cgv/media/font/font_server.h>
2
3namespace cgv {
4 namespace media {
5 namespace font {
6
7
8font_server_ptr& ref_font_server()
9{
10 static font_server_ptr fs;
11 return fs;
12}
13
15{
16 return ref_font_server();
17}
18
20{
21 // list typical monospace fonts that should be present on most operating systems
22 static std::vector<std::string> monospace_font_names = {
23 "Consolas", // Windows default, but should also be available on Mac OS.
24 "Courier", // Should be available on Mac OS. Will also match Courier New (Windows) and Courier 10 Pitch (Linux-based systems).
25 "FreeMono", // For Linux-based systems.
26 "DejaVu Sans Mono" // Alternative for Linux-based systems.
27 };
28
29 // list typical sans-serif fonts that should be present on most operating systems
30 static std::vector<std::string> sans_serif_font_names = {
31 "Open Sans", // Microsoft font.
32 "Arial", // Available on Windows. Should also be available on MacOS.
33 "Tahoma", // Available on Windows. Should also be available on MacOS.
34 "DejaVu Sans", // Available on Linux-based systems.
35 "Lucida", // Available on Mac OS. Will also match Lucida Grande.
36 "Helvetica" // Available on Mac OS. Will also match Helvetica Neue.
37 };
38
39 font_ptr f;
40
41 auto& default_font_names = mono_space ? monospace_font_names : sans_serif_font_names;
42 for(const auto& font_name : default_font_names) {
43 f = find_font_by_prefix(font_name);
44 if(f)
45 return f;
46 }
47
48 // select the first listed font if none of the default fonts could be found
49 std::vector<const char*> font_names;
50 enumerate_font_names(font_names);
51
52 if(!font_names.empty())
53 f = find_font(font_names.front());
54
55 return f;
56}
57
59{
60 ref_font_server() = fs;
61}
62
63 }
64 }
65}
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
virtual font_ptr default_font(bool mono_space)
return potentially font driver and platform specific default font or first available font as fallback...
virtual void enumerate_font_names(std::vector< const char * > &font_names)=0
enumerate the names of all installed fonts
virtual font_ptr find_font(const std::string &font_name)=0
find an installed font by name
virtual font_ptr find_font_by_prefix(const std::string &font_name_prefix)=0
find an installed font by name prefix
void register_font_server(font_server_ptr fs)
install a font server, call this in the on_register method of the server implementation
font_server_ptr get_font_server()
return the currently installed font server or 0 if no font server available
data::ref_ptr< font_server > font_server_ptr
ref counted pointer to font server
Definition font_server.h:27
the cgv namespace
Definition print.h:11