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   // NOTE: the constructor doesn't take a RefPtr<const FontFace> because the
00086   // FontFace object can be changed in this constructor (in the case of user
00087   // fonts, the FontFace becomes immutable, i.e. you can't call any set_*_func()
00088   // functions any longer)
00089 
00090   //We use an output paramter instead of the return value,
00091   //for consistency with other get_*extents() methods in other classes,
00092   //though they should probably all use the return value instead.
00093   //but it is too late to change that now. murrayc:
00094 
00098   void get_extents(FontExtents& extents) const;
00099 
00103   void extents(FontExtents& extents) const;
00104 
00125   void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00129   void text_extents(const std::string& utf8, TextExtents& extents) const;
00130 
00146   void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents);
00147 
00151   void glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents);
00152 
00156   RefPtr<FontFace> get_font_face() const;
00157 
00161   void get_font_options(FontOptions& options) const;
00162 
00166   void get_font_matrix(Matrix& font_matrix) const;
00167 
00171   void get_ctm(Matrix& ctm) const;
00172 
00176   FontType get_type() const;
00177 
00178   // FIXME: it'd be really nice not to assume a specific container (e.g.
00179   // std::vector) here
00200   void text_to_glyphs(double x,
00201                       double y,
00202                       const std::string& utf8,
00203                       std::vector<Glyph>& glyphs,
00204                       std::vector<TextCluster>& clusters,
00205                       TextClusterFlags& cluster_flags);
00206 
00215   void get_scale_matrix(Matrix& scale_matrix) const;
00216 
00217 protected:
00218   ScaledFont(const RefPtr<FontFace>& font_face, const Matrix& font_matrix,
00219              const Matrix& ctm, const FontOptions& options = FontOptions());
00221   cobject* m_cobject;
00222 };
00223 
00224 #ifdef CAIRO_HAS_FT_FONT
00225 
00226 //TODO: Documentation.
00230 class FtScaledFont : public ScaledFont
00231 {
00232 public:
00237   static RefPtr<FtScaledFont> create(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
00238       const Matrix& ctm, const FontOptions& options = FontOptions());
00239 
00262   FT_Face lock_face();
00263 
00268   void unlock_face();
00269 
00270 protected:
00271   FtScaledFont(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
00272       const Matrix& ctm, const FontOptions& options = FontOptions());
00273 };
00274 #endif // CAIRO_HAS_FT_FONT
00275 
00276 }
00277 
00278 #endif // __CAIROMM_SCALEDFONT_H
00279 // vim: ts=2 sw=2 et

Generated on Sat Feb 28 14:12:24 2009 for cairomm by  doxygen 1.5.4