Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
fonts.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2009,2011,2012 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef FONTS_HPP
44 #define FONTS_HPP 1
45 
46 
47 #include <string>
48 #include <vector>
49 #include <cairo.h>
50 #include <fontconfig/fontconfig.h>
51 #include <ft2build.h>
52 #include FT_FREETYPE_H
53 
54 
55 
58 class Font
59 {
60  cairo_font_face_t *_cff;
61  FcPattern *_pmatch;
62 
63  std::string _family;
64  cairo_font_slant_t _slant;
68  cairo_font_weight_t _weight;
73 public:
74 
75  Font( FcPattern *pat );
76  Font( const std::string &family );
77  Font( const std::string &family, cairo_font_slant_t slant,
78  cairo_font_weight_t weight );
79  Font( const Font &font );
80 
81  Font &operator=( const Font &font );
82 
83  ~Font();
84 
85  std::string family( void ) const;
86  cairo_font_slant_t slant( void ) const;
87  cairo_font_weight_t weight( void ) const;
88  cairo_font_face_t *font_face( void ) const;
89  FcPattern *fcpattern( void ) const;
90 
91  void load( class FontLib &fontlib );
92 
93 };
94 
95 
98 class FontLib
99 {
100 
101  FT_Library _ft;
102  FcConfig *_fc;
103 
104  std::vector<Font> _search;
105  std::vector<Font> _loaded;
106 
107  int get_font_matrix( cairo_t *cairo, cairo_matrix_t *matrix, cairo_matrix_t *orig_matrix );
108  int process_substr( cairo_t *cairo, const std::string &str, cairo_text_extents_t *extents,
109  double x0, double y0, double &x, double &y );
110  void process( cairo_t *cairo, const std::string &str, cairo_text_extents_t *extents, double &x, double &y );
111 
112 public:
113 
114  FontLib();
115 
116  ~FontLib();
117 
122  struct Symbolname {
123  const char *name;
124  const char *ucode;
125  };
126 
133  static void combine_extents( cairo_text_extents_t *extents1, double x1, double y1,
134  const cairo_text_extents_t *extents2, double x2, double y2 );
135 
138  static const Symbolname symbols[];
139 
140 
141  FcConfig *fc( void ) { return( _fc ); }
142 
143 
144  void push_auto_search_font( const std::string &family );
145  int pop_auto_search_font( void );
146 
147 
148 
149  std::string family( void ) const;
150  cairo_font_slant_t slant( void ) const;
151  cairo_font_weight_t weight( void ) const;
152  cairo_font_face_t *font_face( void ) const;
153  FcPattern *fcpattern( void ) const;
154 
155 
156  void push_font( FcPattern *pat );
157  void push_font( const std::string &family, cairo_font_slant_t slant,
158  cairo_font_weight_t weight );
159  int pop_font( void );
160 
161 
162  void text_extents( cairo_t *cairo, const std::string &str, cairo_text_extents_t *extents );
163 
168  void draw_text( cairo_t *cairo, const std::string &str, double &x, double &y );
169 
170 };
171 
172 
175 extern FontLib fontlib;
176 
177 
180 std::string wstring_to_utf8( const std::wstring &in );
181 
182 
183 #endif
184 
Font engine using FreeType, FontConfig and cairographics.
Definition: fonts.hpp:99
static void combine_extents(cairo_text_extents_t *extents1, double x1, double y1, const cairo_text_extents_t *extents2, double x2, double y2)
Combine extents.
Definition: fonts.cpp:441
static const Symbolname symbols[]
Chart of glyph symbol names.
Definition: fonts.hpp:138
void draw_text(cairo_t *cairo, const std::string &str, double &x, double &y)
Draw piece of text at (x,y)
Definition: fonts.cpp:651
Font for FontLib engine.
Definition: fonts.hpp:59
std::string wstring_to_utf8(const std::wstring &in)
Convert wide string to utf8.
Definition: fonts.cpp:60
FontLib fontlib
Global instance of class FontLib.
Definition: fonts.cpp:53
Glyph symbol name entry.
Definition: fonts.hpp:122


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.