fontface.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 The cairomm Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Library General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301, USA.
00017  */
00018 
00019 #ifndef __CAIROMM_FONTFACE_H
00020 #define __CAIROMM_FONTFACE_H
00021 
00022 #include <string>
00023 #include <vector>
00024 #include <cairomm/enums.h>
00025 #include <cairomm/types.h>
00026 #include <cairomm/refptr.h>
00027 
00028 /* following is required for OS X */
00029 
00030 #ifdef nil
00031 #undef nil
00032 #endif
00033 
00034 /* end OS X */
00035 
00036 #include <cairo.h>
00037 #ifdef CAIRO_HAS_FT_FONT
00038 #include <cairo-ft.h>
00039 #endif //CAIRO_HAS_FT_FONT
00040 
00041 
00042 namespace Cairo
00043 {
00044 
00045 class ScaledFont;
00046 class Context;
00047 
00056 class FontFace
00057 {
00058 protected:
00059 
00060   //TODO?: FontFace(cairo_font_face_t *target);
00061 
00062 public:
00067   explicit FontFace(cairo_font_face_t* cobject, bool has_reference = false);
00068 
00069 
00070   virtual ~FontFace();
00071 
00072   /* Don't wrap these until we know what they are good for.
00073   void* get_user_data(const cairo_user_data_key_t *key);
00074 
00075   void set_user_data(const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy);
00076   */
00077 
00078   FontType get_type() const;
00079 
00080   typedef cairo_font_face_t cobject;
00081   inline cobject* cobj() { return m_cobject; }
00082   inline const cobject* cobj() const { return m_cobject; }
00083 
00084   #ifndef DOXYGEN_IGNORE_THIS
00086   inline ErrorStatus get_status() const
00087   { return cairo_font_face_status(const_cast<cairo_font_face_t*>(cobj())); }
00088   #endif //DOXYGEN_IGNORE_THIS
00089 
00090   void reference() const;
00091   void unreference() const;
00092 
00093 protected:
00094 
00095   cobject* m_cobject;
00096 };
00097 
00098 
00107 class ToyFontFace : public FontFace
00108 {
00109 public:
00110 
00126   static RefPtr<ToyFontFace> create(const std::string& family, FontSlant slant, FontWeight weight);
00127 
00131   std::string get_family() const;
00132 
00136   FontSlant get_slant() const;
00137 
00141   FontWeight get_weight() const;
00142 
00143 protected:
00144   ToyFontFace(const std::string& family, FontSlant slant, FontWeight weight);
00145 };
00146 
00147 
00210 class UserFontFace : public FontFace
00211 {
00212 public:
00213 
00214   virtual ~UserFontFace();
00215 
00216   /*
00217   static RefPtr<UserFontFace> create();
00218   static RefPtr<UserFontFace> create(cairo_font_face_t* cobject, bool has_reference = false);
00219   */
00220 
00221 protected:
00222 
00251   virtual ErrorStatus init(const RefPtr<ScaledFont>& scaled_font,
00252                            const RefPtr<Context>& cr,
00253                            FontExtents& extents);
00254 
00283   virtual ErrorStatus unicode_to_glyph(const RefPtr<ScaledFont>& scaled_font,
00284                                        unsigned long unicode,
00285                                        unsigned long& glyph);
00286 
00287 
00325   virtual ErrorStatus render_glyph(const RefPtr<ScaledFont>& scaled_font,
00326                                    unsigned long glyph,
00327                                    const RefPtr<Context>& cr,
00328                                    TextExtents& metrics) = 0;
00329 
00330 
00361   virtual ErrorStatus text_to_glyphs(const RefPtr<ScaledFont>& scaled_font,
00362                                      const std::string& utf8,
00363                                      std::vector<Glyph>& glyphs,
00364                                      std::vector<TextCluster>& clusters,
00365                                      TextClusterFlags& cluster_flags);
00366 
00367 
00368 
00369   UserFontFace();
00370 
00371 private:
00372   static cairo_status_t
00373   init_cb(cairo_scaled_font_t* scaled_font,
00374           cairo_t *cr,
00375           cairo_font_extents_t* metrics);
00376 
00377   static cairo_status_t
00378   unicode_to_glyph_cb(cairo_scaled_font_t *scaled_font,
00379                       unsigned long        unicode,
00380                       unsigned long       *glyph);
00381 
00382   static cairo_status_t
00383   render_glyph_cb(cairo_scaled_font_t  *scaled_font,
00384                   unsigned long         glyph,
00385                   cairo_t              *cr,
00386                   cairo_text_extents_t *metrics);
00387 
00388   static cairo_status_t
00389   text_to_glyphs_cb (cairo_scaled_font_t *scaled_font,
00390                      const char *utf8,
00391                      int utf8_len,
00392                      cairo_glyph_t **glyphs,
00393                      int *num_glyphs,
00394                      cairo_text_cluster_t **clusters,
00395                      int *num_clusters,
00396                      cairo_text_cluster_flags_t *cluster_flags);
00397 };
00398 
00399 
00400 // font system support
00401 #ifdef CAIRO_HAS_FT_FONT
00402 
00403 class FtFontFace : public FontFace
00404 {
00405 public:
00439   static RefPtr<FtFontFace> create(FT_Face face, int load_flags);
00440   //TODO: Add a suitable default value for load_flags?
00441 
00470   static RefPtr<FtFontFace> create(FcPattern* pattern);
00471 
00472 protected:
00473   FtFontFace(FT_Face face, int load_flags);
00474   FtFontFace(FcPattern* pattern);
00475 };
00476 
00477 #endif // CAIRO_HAS_FT_FONT
00478 
00479 } // namespace Cairo
00480 
00481 #endif //__CAIROMM_FONTFACE_H
00482 
00483 // vim: ts=2 sw=2 et

Generated on Tue Jul 21 09:10:58 2009 for cairomm by  doxygen 1.5.8