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 #include <sigc++/slot.h>
00028 #include <cairo.h>
00029 #ifdef CAIRO_HAS_FT_FONT
00030 #include <cairo-ft.h>
00031 #endif //CAIRO_HAS_FT_FONT
00032 
00033 
00034 namespace Cairo
00035 {
00036 
00037 class ScaledFont;
00038 class Context;
00039 
00048 class FontFace
00049 {
00050 protected:
00051 
00052   //TODO?: FontFace(cairo_font_face_t *target);
00053 
00054 public:
00059   explicit FontFace(cairo_font_face_t* cobject, bool has_reference = false);
00060 
00061 
00062   virtual ~FontFace();
00063 
00064   /* Don't wrap these until we know what they are good for.
00065   void* get_user_data(const cairo_user_data_key_t *key);
00066 
00067   void set_user_data(const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy);
00068   */
00069 
00070   FontType get_type() const;
00071 
00072   typedef cairo_font_face_t cobject;
00073   inline cobject* cobj() { return m_cobject; }
00074   inline const cobject* cobj() const { return m_cobject; }
00075 
00076   #ifndef DOXYGEN_IGNORE_THIS
00078   inline ErrorStatus get_status() const
00079   { return cairo_font_face_status(const_cast<cairo_font_face_t*>(cobj())); }
00080   #endif //DOXYGEN_IGNORE_THIS
00081 
00082   void reference() const;
00083   void unreference() const;
00084 
00085 protected:
00086 
00087   cobject* m_cobject;
00088 };
00089 
00090 
00095 class ToyFontFace : public FontFace
00096 {
00097 public:
00098 
00114   static RefPtr<ToyFontFace> create(const std::string& family, FontSlant slant, FontWeight weight);
00115 
00119   std::string get_family() const;
00120 
00124   FontSlant get_slant() const;
00125 
00129   FontWeight get_weight() const;
00130 
00131 protected:
00132   ToyFontFace(const std::string& family, FontSlant slant, FontWeight weight);
00133 };
00134 
00135 
00145 class UserFontFace : public FontFace
00146 {
00147 public:
00148 
00149   virtual ~UserFontFace();
00150 
00151   static RefPtr<UserFontFace> create();
00152 
00184   typedef sigc::slot<ErrorStatus,
00185                      const RefPtr<ScaledFont>&,
00186                      const RefPtr<Context>&,
00187                      FontExtents&> SlotInit;
00188 
00200   void set_init_func(const SlotInit& init_func);
00201 
00236   typedef sigc::slot<ErrorStatus,
00237                      const RefPtr<ScaledFont>&,
00238                      unsigned long /*unicode*/,
00239                      unsigned long& /*glyph*/> SlotUnicodeToGlyph;
00240 
00241 
00254   void set_unicode_to_glyph_func(const SlotUnicodeToGlyph& unicode_to_glyph_func);
00255 
00256 
00297   typedef sigc::slot<ErrorStatus,
00298                      const RefPtr<ScaledFont>&,
00299                      unsigned long /*glyph*/,
00300                      const RefPtr<Context>&,
00301                      TextExtents& /*metrics*/> SlotRenderGlyph;
00302 
00319   void set_render_glyph_func(const SlotRenderGlyph& render_glyph_func);
00320 
00321 
00355   typedef sigc::slot<ErrorStatus,
00356                      const RefPtr<ScaledFont>&,
00357                      const std::string& /*utf8*/,
00358                      std::vector<Glyph>& /*glyphs*/,
00359                      std::vector<TextCluster>& /*clusters*/,
00360                      TextClusterFlags& /*cluster_flags*/> SlotTextToGlyphs;
00361 
00374   void set_text_to_glyphs_func(const SlotTextToGlyphs& text_to_glyphs_func);
00375 
00376   // Like gtkmm, we don't have get_*_func() methods. They would not be very useful.
00377 
00378   //TODO: Add unset_*_func() methods, to match the use of NULL in the C API?
00379 
00380 
00381 
00382 protected:
00383   UserFontFace();
00384 
00385 private:
00386   struct PrivateData;
00387   PrivateData* m_priv;
00388 
00389   static cairo_status_t
00390   init_cb(cairo_scaled_font_t* scaled_font,
00391           cairo_t *cr,
00392           cairo_font_extents_t* metrics);
00393 
00394   static cairo_status_t
00395   unicode_to_glyph_cb(cairo_scaled_font_t *scaled_font,
00396                       unsigned long        unicode,
00397                       unsigned long       *glyph);
00398 
00399   static cairo_status_t
00400   render_glyph_cb(cairo_scaled_font_t  *scaled_font,
00401                   unsigned long         glyph,
00402                   cairo_t              *cr,
00403                   cairo_text_extents_t *metrics);
00404 
00405   static cairo_status_t
00406   text_to_glyphs_cb (cairo_scaled_font_t *scaled_font,
00407                      const char *utf8,
00408                      int utf8_len,
00409                      cairo_glyph_t **glyphs,
00410                      int *num_glyphs,
00411                      cairo_text_cluster_t **clusters,
00412                      int *num_clusters,
00413                      cairo_text_cluster_flags_t *cluster_flags);
00414 };
00415 
00416 // font system support
00417 #ifdef CAIRO_HAS_FT_FONT
00418 
00419 class FtFontFace : public FontFace
00420 {
00421 public:
00455   static RefPtr<FtFontFace> create(FT_Face face, int load_flags);
00456   //TODO: Add a suitable default value for load_flags?
00457 
00486   static RefPtr<FtFontFace> create(FcPattern* pattern);
00487 
00488 protected:
00489   FtFontFace(FT_Face face, int load_flags);
00490   FtFontFace(FcPattern* pattern);
00491 };
00492 
00493 #endif // CAIRO_HAS_FT_FONT
00494 
00495 } // namespace Cairo
00496 
00497 #endif //__CAIROMM_FONTFACE_H
00498 
00499 // vim: ts=2 sw=2 et

Generated on Sat Oct 25 23:19:50 2008 for cairomm by  doxygen 1.5.5