Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.4
   Version 1.0.4dev
      Class Index
      File List
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.
00001 
00005 /* Copyright (c) 2005-2009,2011 Taneli Kalvas. All rights reserved.
00006  *
00007  * You can redistribute this software and/or modify it under the terms
00008  * of the GNU General Public License as published by the Free Software
00009  * Foundation; either version 2 of the License, or (at your option)
00010  * any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this library (file "COPYING" included in the package);
00019  * if not, write to the Free Software Foundation, Inc., 51 Franklin
00020  * Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  * 
00022  * If you have questions about your rights to use or distribute this
00023  * software, please contact Berkeley Lab's Technology Transfer
00024  * Department at TTD@lbl.gov. Other questions, comments and bug
00025  * reports should be sent directly to the author via email at
00026  * taneli.kalvas@jyu.fi.
00027  * 
00028  * NOTICE. This software was developed under partial funding from the
00029  * U.S.  Department of Energy.  As such, the U.S. Government has been
00030  * granted for itself and others acting on its behalf a paid-up,
00031  * nonexclusive, irrevocable, worldwide license in the Software to
00032  * reproduce, prepare derivative works, and perform publicly and
00033  * display publicly.  Beginning five (5) years after the date
00034  * permission to assert copyright is obtained from the U.S. Department
00035  * of Energy, and subject to any subsequent five (5) year renewals,
00036  * the U.S. Government is granted for itself and others acting on its
00037  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
00038  * the Software to reproduce, prepare derivative works, distribute
00039  * copies to the public, perform publicly and display publicly, and to
00040  * permit others to do so.
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


Reference manual for Ion Beam Simulator 1.0.4dev
Generated by Doxygen 1.7.1 on Wed May 18 2011 23:03:47.