cgv
font.h
1 #pragma once
2 
3 #include <cgv/base/base.h>
4 #include <vector>
5 #include <string>
6 
7 #include "lib_begin.h"
8 
9 #ifdef WIN32
10 #pragma warning(disable:4275)
11 #pragma warning(disable:4231)
12 #endif
13 
14 namespace cgv {
15  namespace media {
17  namespace font {
18 
21 {
22  FFA_REGULAR = 0,
23  FFA_BOLD = 1,
24  FFA_ITALIC = 2,
25  FFA_BOLD_ITALIC = 3
26 };
27 
29 class CGV_API font_face : public base::base
30 {
31 protected:
33  int ffa;
34 public:
36  font_face(int _ffa);
38  std::string get_type_name() const;
40  virtual int get_attributes() const;
42  virtual void enumerate_sizes(std::vector<int>& supported_sizes) const = 0;
44  virtual float measure_text_width(const std::string& text, float font_size) const = 0;
46  virtual void enable(void* context_ptr, float _font_size) = 0;
48  virtual void draw_text(float& x, float& y, const std::string& text) const = 0;
49 };
50 
53 
55 class CGV_API font : public base::base
56 {
57 public:
59  std::string get_type_name() const;
61  virtual const char* get_name() const = 0;
63  virtual bool supports_font_face(int ffa) const = 0;
65  virtual font_face_ptr get_font_face(int ffa) const = 0;
67  virtual void enumerate_sizes(std::vector<int>& supported_sizes) const = 0;
68 };
69 
72 
74 extern CGV_API font_ptr find_font(const std::string& font_name);
75 
77 extern CGV_API font_ptr default_font(bool mono_space = false);
78 
79 
81 extern CGV_API void enumerate_font_names(std::vector<const char*>& font_names);
82 
83 #if _MSC_VER >= 1400
84 CGV_TEMPLATE template class CGV_API data::ref_ptr<font>;
85 CGV_TEMPLATE template class CGV_API data::ref_ptr<font_face>;
86 #endif
87 
88  }
89  }
90 }
91 
92 #include <cgv/config/lib_end.h>
cgv::media::font::font_face::ffa
int ffa
store the actual attributes of the font face
Definition: font.h:33
cgv::media::font::font
interface class for fonts. Construct font with the find_font function
Definition: font.h:56
cgv::media::font::font_face::draw_text
virtual void draw_text(float &x, float &y, const std::string &text) const =0
draw text at given location with font_face implementation dependent rendering api and advance locatio...
cgv::media::font::font_face::measure_text_width
virtual float measure_text_width(const std::string &text, float font_size) const =0
return the width of a text printed in the given size, which is measured in pixels
cgv::media::font::font::get_font_face
virtual font_face_ptr get_font_face(int ffa) const =0
return a pointer to a font face
cgv::media::font::font::supports_font_face
virtual bool supports_font_face(int ffa) const =0
check whether the given font includes a face that include the possibly or-ed together selection of fo...
cgv::data::ref_ptr< font_face >
cgv::media::font::FontFaceAttributes
FontFaceAttributes
declaration of supported attributes of font faces
Definition: font.h:21
cgv::media::font::font::enumerate_sizes
virtual void enumerate_sizes(std::vector< int > &supported_sizes) const =0
enumerate the supported font sizes
cgv::media::font::find_font
font_ptr find_font(const std::string &font_name)
find an installed font by name
Definition: font.cxx:32
cgv::media::font::font_face_ptr
data::ref_ptr< font_face > font_face_ptr
always use this ref counted pointer to store font faces
Definition: font.h:52
cgv::media::font::font::get_name
virtual const char * get_name() const =0
return the name of the font
cgv::media::font::font_ptr
data::ref_ptr< font > font_ptr
always use this ref counted pointer to store fonts
Definition: font.h:71
cgv::media::font::enumerate_font_names
void enumerate_font_names(std::vector< const char * > &font_names)
enumerate the names of all installed fonts
Definition: font.cxx:48
cgv::media::font::font_face::enumerate_sizes
virtual void enumerate_sizes(std::vector< int > &supported_sizes) const =0
enumerate the supported sizes; if nothing is enumerated any size is supported
cgv::base::base
Definition: base.h:57
cgv::media::font::default_font
font_ptr default_font(bool mono_space)
return platform dependend default font
Definition: font.cxx:40
cgv::media::font::font_face
interface class for different faces of a font, which can be constructed from a font
Definition: font.h:30
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::media::font::font_face::enable
virtual void enable(void *context_ptr, float _font_size)=0
enables font face of given size and should be called once before calling draw_text functions