Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef FONTS_HPP
00044 #define FONTS_HPP 1
00045
00046
00047 #include <string>
00048 #include <vector>
00049 #include <cairo.h>
00050 #include <fontconfig/fontconfig.h>
00051 #include <ft2build.h>
00052 #include FT_FREETYPE_H
00053
00054
00055
00058 class Font
00059 {
00060 cairo_font_face_t *_cff;
00061 FcPattern *_pmatch;
00062
00063 std::string _family;
00064 cairo_font_slant_t _slant;
00068 cairo_font_weight_t _weight;
00073 public:
00074
00075 Font( FcPattern *pat );
00076 Font( const std::string &family );
00077 Font( const std::string &family, cairo_font_slant_t slant,
00078 cairo_font_weight_t weight );
00079 Font( const Font &font );
00080
00081 Font &operator=( const Font &font );
00082
00083 ~Font();
00084
00085 std::string family( void ) const;
00086 cairo_font_slant_t slant( void ) const;
00087 cairo_font_weight_t weight( void ) const;
00088 cairo_font_face_t *font_face( void ) const;
00089 FcPattern *fcpattern( void ) const;
00090
00091 void load( class FontLib &fontlib );
00092
00093 };
00094
00095
00098 class FontLib
00099 {
00100
00101 FT_Library _ft;
00102 FcConfig *_fc;
00103
00104 std::vector<Font> _search;
00105 std::vector<Font> _loaded;
00106
00107 int get_font_matrix( cairo_t *cairo, cairo_matrix_t *matrix, cairo_matrix_t *orig_matrix );
00108 int process_substr( cairo_t *cairo, const std::string &str, cairo_text_extents_t *extents,
00109 double x0, double y0, double &x, double &y );
00110 void process( cairo_t *cairo, const std::string &str, cairo_text_extents_t *extents, double &x, double &y );
00111
00112 public:
00113
00114 FontLib();
00115
00116 ~FontLib();
00117
00122 struct Symbolname {
00123 const char *name;
00124 const char *ucode;
00125 };
00126
00133 static void combine_extents( cairo_text_extents_t *extents1, double x1, double y1,
00134 const cairo_text_extents_t *extents2, double x2, double y2 );
00135
00138 static const Symbolname symbols[];
00139
00140
00141 FcConfig *fc( void ) { return( _fc ); }
00142
00143
00144 void push_auto_search_font( const std::string &family );
00145 int pop_auto_search_font( void );
00146
00147
00148
00149 std::string family( void ) const;
00150 cairo_font_slant_t slant( void ) const;
00151 cairo_font_weight_t weight( void ) const;
00152 cairo_font_face_t *font_face( void ) const;
00153 FcPattern *fcpattern( void ) const;
00154
00155
00156 void push_font( FcPattern *pat );
00157 void push_font( const std::string &family, cairo_font_slant_t slant,
00158 cairo_font_weight_t weight );
00159 int pop_font( void );
00160
00161
00162 void text_extents( cairo_t *cairo, const std::string &str, cairo_text_extents_t *extents );
00163
00168 void draw_text( cairo_t *cairo, const std::string &str, double &x, double &y );
00169
00170 };
00171
00172
00175 extern FontLib fontlib;
00176
00177
00178 #endif
00179