# scaledfont.h

Go to the documentation of this file.

    00001 /* Copyright (C) 2006 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_SCALEDFONT_H
    00020 #define __CAIROMM_SCALEDFONT_H
    00021
    00022 #include <cairomm/refptr.h>
    00023 #include <cairomm/fontoptions.h>
    00024 #include <cairomm/fontface.h>
    00025 #include <cairomm/matrix.h>
    00026 #include <cairomm/types.h>
    00027 #include <vector>
    00028
    00029 #ifdef CAIRO_HAS_FT_FONT
    00030 #include <cairo-ft.h>
    00031 #endif // CAIRO_HAS_FT_FONT
    00032
    00033 namespace Cairo
    00034 {
    00035
    00040 class ScaledFont
    00041 {
    00042
    00043 public:
    00045   typedef cairo_scaled_font_t cobject;
    00046
    00048   inline cobject* cobj() { return m_cobject; }
    00049
    00051   inline const cobject* cobj() const { return m_cobject; }
    00052
    00053 #ifndef DOXYGEN_IGNORE_THIS
    00054   // For use only by the cairomm implementation.
    00055   inline ErrorStatus get_status() const
    00056   { return cairo_scaled_font_status(const_cast<cairo_scaled_font_t*>(cobj())); }
    00057
    00058   // for RefPtr
    00059   void reference() const { cairo_scaled_font_reference(m_cobject); }
    00060   void unreference() const { cairo_scaled_font_destroy(m_cobject); }
    00061 #endif //DOXYGEN_IGNORE_THIS
    00062
    00066   explicit ScaledFont(cobject* cobj, bool has_reference = false);
    00067
    00068   ~ScaledFont();
    00069
    00083   static RefPtr<ScaledFont> create(const RefPtr<FontFace>& font_face, const Matrix& font_matrix,
    00084       const Matrix& ctm, const FontOptions& options = FontOptions());
    00085   /* To keep 1.6.x ABI  */
    00086   static RefPtr<ScaledFont> create(const RefPtr<FontFace>& font_face, const cairo_matrix_t& font_matrix,
    00087       const cairo_matrix_t& ctm, const FontOptions& options = FontOptions());
    00088   // NOTE: the constructor doesn't take a RefPtr<const FontFace> because the
    00089   // FontFace object can be changed in this constructor (in the case of user
    00090   // fonts, the FontFace becomes immutable, i.e. you can't call any set_*_func()
    00091   // functions any longer)
    00092
    00093   //We use an output paramter instead of the return value,
    00094   //for consistency with other get_*extents() methods in other classes,
    00095   //though they should probably all use the return value instead.
    00096   //but it is too late to change that now. murrayc:
    00097
    00101   void get_extents(FontExtents& extents) const;
    00102
    00106   void extents(FontExtents& extents) const;
    00107
    00128   void get_text_extents(const std::string& utf8, TextExtents& extents) const;
    00132   void text_extents(const std::string& utf8, TextExtents& extents) const;
    00133
    00149   void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents);
    00150
    00154   void glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents);
    00155
    00159   RefPtr<FontFace> get_font_face() const;
    00160
    00164   void get_font_options(FontOptions& options) const;
    00165
    00169   void get_font_matrix(Matrix& font_matrix) const;
    00170   /* To keep 1.6.x ABI  */
    00171   void get_font_matrix(cairo_matrix_t& font_matrix) const;
    00172
    00176   void get_ctm(Matrix& ctm) const;
    00177   /* To keep 1.6.x ABI  */
    00178   void get_ctm(cairo_matrix_t& ctm) const;
    00179
    00183   FontType get_type() const;
    00184
    00185   // FIXME: it'd be really nice not to assume a specific container (e.g.
    00186   // std::vector) here
    00207   void text_to_glyphs(double x,
    00208                       double y,
    00209                       const std::string& utf8,
    00210                       std::vector<Glyph>& glyphs,
    00211                       std::vector<TextCluster>& clusters,
    00212                       TextClusterFlags& cluster_flags);
    00213
    00222   void get_scale_matrix(Matrix& scale_matrix) const;
    00223
    00224 protected:
    00225   /* Cairo::Matrix parameters changed to cairo_matrix_t */
    00226   ScaledFont(const RefPtr<FontFace>& font_face, const cairo_matrix_t& font_matrix,
    00227              const cairo_matrix_t& ctm, const FontOptions& options = FontOptions());
    00229   cobject* m_cobject;
    00230 };
    00231
    00232 #ifdef CAIRO_HAS_FT_FONT
    00233
    00234 //TODO: Documentation.
    00238 class FtScaledFont : public ScaledFont
    00239 {
    00240 public:
    00245   static RefPtr<FtScaledFont> create(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
    00246       const Matrix& ctm, const FontOptions& options = FontOptions());
    00247
    00270   FT_Face lock_face();
    00271
    00276   void unlock_face();
    00277
    00278 protected:
    00279   FtScaledFont(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
    00280       const Matrix& ctm, const FontOptions& options = FontOptions());
    00281 };
    00282 #endif // CAIRO_HAS_FT_FONT
    00283
    00284 }
    00285
    00286 #endif // __CAIROMM_SCALEDFONT_H
    00287 // vim: ts=2 sw=2 et