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
00028
00029
00030 #ifdef nil
00031 #undef nil
00032 #endif
00033
00034
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
00061
00062 public:
00067 explicit FontFace(cairo_font_face_t* cobject, bool has_reference = false);
00068
00069
00070 virtual ~FontFace();
00071
00072
00073
00074
00075
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
00218
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
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
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 }
00480
00481 #endif //__CAIROMM_FONTFACE_H
00482
00483