00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00053
00054 public:
00059 explicit FontFace(cairo_font_face_t* cobject, bool has_reference = false);
00060
00061
00062 virtual ~FontFace();
00063
00064
00065
00066
00067
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 ,
00239 unsigned long& > 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 ,
00300 const RefPtr<Context>&,
00301 TextExtents& > 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& ,
00358 std::vector<Glyph>& ,
00359 std::vector<TextCluster>& ,
00360 TextClusterFlags& > SlotTextToGlyphs;
00361
00374 void set_text_to_glyphs_func(const SlotTextToGlyphs& text_to_glyphs_func);
00375
00376
00377
00378
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
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
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 }
00496
00497 #endif //__CAIROMM_FONTFACE_H
00498
00499