Blame cairomm/scaledfont.h

Packit Service e3b512
/* Copyright (C) 2006 The cairomm Development Team
Packit Service e3b512
 *
Packit Service e3b512
 * This library is free software; you can redistribute it and/or
Packit Service e3b512
 * modify it under the terms of the GNU Library General Public
Packit Service e3b512
 * License as published by the Free Software Foundation; either
Packit Service e3b512
 * version 2 of the License, or (at your option) any later version.
Packit Service e3b512
 *
Packit Service e3b512
 * This library is distributed in the hope that it will be useful,
Packit Service e3b512
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service e3b512
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service e3b512
 * Library General Public License for more details.
Packit Service e3b512
 *
Packit Service e3b512
 * You should have received a copy of the GNU Library General Public
Packit Service e3b512
 * License along with this library; if not, write to the Free Software
Packit Service e3b512
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service e3b512
 * 02110-1301, USA.
Packit Service e3b512
 */
Packit Service e3b512
Packit Service e3b512
#ifndef __CAIROMM_SCALEDFONT_H
Packit Service e3b512
#define __CAIROMM_SCALEDFONT_H
Packit Service e3b512
Packit Service e3b512
#include <cairomm/refptr.h>
Packit Service e3b512
#include <cairomm/fontoptions.h>
Packit Service e3b512
#include <cairomm/fontface.h>
Packit Service e3b512
#include <cairomm/matrix.h>
Packit Service e3b512
#include <cairomm/types.h>
Packit Service e3b512
#include <vector>
Packit Service e3b512
Packit Service e3b512
#ifdef CAIRO_HAS_FT_FONT
Packit Service e3b512
#include <cairo-ft.h>
Packit Service e3b512
#endif // CAIRO_HAS_FT_FONT
Packit Service e3b512
Packit Service e3b512
namespace Cairo
Packit Service e3b512
{
Packit Service e3b512
Packit Service e3b512
/** A ScaledFont is a font scaled to a particular size and device resolution. It
Packit Service e3b512
 * is most useful for low-level font usage where a library or application wants
Packit Service e3b512
 * to cache a reference to a scaled font to speed up the computation of metrics.
Packit Service e3b512
 */
Packit Service e3b512
class ScaledFont
Packit Service e3b512
{
Packit Service e3b512
Packit Service e3b512
public: 
Packit Service e3b512
  /** The underlying C cairo object type */
Packit Service e3b512
  typedef cairo_scaled_font_t cobject;
Packit Service e3b512
Packit Service e3b512
  /** Provides acces to the underlying C cairo object */
Packit Service e3b512
  inline cobject* cobj() { return m_cobject; }
Packit Service e3b512
Packit Service e3b512
  /** Provides acces to the underlying C cairo object */
Packit Service e3b512
  inline const cobject* cobj() const { return m_cobject; }
Packit Service e3b512
Packit Service e3b512
#ifndef DOXYGEN_IGNORE_THIS
Packit Service e3b512
  // For use only by the cairomm implementation.
Packit Service e3b512
  inline ErrorStatus get_status() const
Packit Service e3b512
  { return cairo_scaled_font_status(const_cast<cairo_scaled_font_t*>(cobj())); }
Packit Service e3b512
Packit Service e3b512
  // for RefPtr
Packit Service e3b512
  void reference() const { cairo_scaled_font_reference(m_cobject); }
Packit Service e3b512
  void unreference() const { cairo_scaled_font_destroy(m_cobject); }
Packit Service e3b512
#endif //DOXYGEN_IGNORE_THIS
Packit Service e3b512
Packit Service e3b512
  /** Create a C++ wrapper object from the C instance.  This C++ object should
Packit Service e3b512
   * then be given to a RefPtr.
Packit Service e3b512
   */
Packit Service e3b512
  explicit ScaledFont(cobject* cobj, bool has_reference = false);
Packit Service e3b512
Packit Service e3b512
  ScaledFont(const ScaledFont&) = delete;
Packit Service e3b512
  ScaledFont& operator=(const ScaledFont&) = delete;
Packit Service e3b512
Packit Service e3b512
  virtual ~ScaledFont();
Packit Service e3b512
Packit Service e3b512
  /** Creates a ScaledFont object from a font face and matrices that describe
Packit Service e3b512
   * the size of the font and the environment in which it will be used.
Packit Service e3b512
   *
Packit Service e3b512
   * @param font_face A font face.
Packit Service e3b512
   * @param font_matrix font space to user space transformation matrix for the
Packit Service e3b512
   * font. In the simplest case of a N point font, this matrix is just a scale
Packit Service e3b512
   * by N, but it can also be used to shear the font or stretch it unequally
Packit Service e3b512
   * along the two axes. See Context::set_font_matrix().
Packit Service e3b512
   * @param ctm user to device transformation matrix with which the font will be
Packit Service e3b512
   * used.
Packit Service e3b512
   * @param options options to use when getting metrics for the font and
Packit Service e3b512
   * rendering with it.
Packit Service e3b512
   */
Packit Service e3b512
  static RefPtr<ScaledFont> create(const RefPtr<FontFace>& font_face, const Matrix& font_matrix,
Packit Service e3b512
      const Matrix& ctm, const FontOptions& options = FontOptions());
Packit Service e3b512
  /* To keep 1.6.x ABI  */
Packit Service e3b512
  static RefPtr<ScaledFont> create(const RefPtr<FontFace>& font_face, const cairo_matrix_t& font_matrix,
Packit Service e3b512
      const cairo_matrix_t& ctm, const FontOptions& options = FontOptions());
Packit Service e3b512
  // NOTE: the constructor doesn't take a RefPtr<const FontFace> because the
Packit Service e3b512
  // FontFace object can be changed in this constructor (in the case of user
Packit Service e3b512
  // fonts, the FontFace becomes immutable, i.e. you can't call any set_*_func()
Packit Service e3b512
  // functions any longer)
Packit Service e3b512
Packit Service e3b512
  //We use an output paramter instead of the return value,
Packit Service e3b512
  //for consistency with other get_*extents() methods in other classes,
Packit Service e3b512
  //though they should probably all use the return value instead.
Packit Service e3b512
  //but it is too late to change that now. murrayc:
Packit Service e3b512
Packit Service e3b512
  /** Gets the metrics for a ScaledFont
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   * */
Packit Service e3b512
  void get_extents(FontExtents& extents) const;
Packit Service e3b512
Packit Service e3b512
  /** @deprecated Use get_extents() instead
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   * */
Packit Service e3b512
  void extents(FontExtents& extents) const;
Packit Service e3b512
Packit Service e3b512
  /** Gets the extents for a string of text. The extents describe a user-space
Packit Service e3b512
   * rectangle that encloses the "inked" portion of the text drawn at the origin
Packit Service e3b512
   * (0,0) (as it would be drawn by Context::show_text() if the cairo graphics
Packit Service e3b512
   * state were set to the same font_face, font_matrix, ctm, and font_options as
Packit Service e3b512
   * the ScaledFont object).  Additionally, the x_advance and y_advance values
Packit Service e3b512
   * indicate the amount by which the current point would be advanced by
Packit Service e3b512
   * Context::show_text().
Packit Service e3b512
   *
Packit Service e3b512
   * Note that whitespace characters do not directly contribute to the size of
Packit Service e3b512
   * the rectangle (extents.width and extents.height). They do contribute
Packit Service e3b512
   * indirectly by changing the position of non-whitespace characters. In
Packit Service e3b512
   * particular, trailing whitespace characters are likely to not affect the
Packit Service e3b512
   * size of the rectangle, though they will affect the x_advance and y_advance
Packit Service e3b512
   * values.
Packit Service e3b512
   *
Packit Service e3b512
   * @param utf8  a string of text, encoded in UTF-8.
Packit Service e3b512
   * @param extents Returns the extents of the given string.
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   */
Packit Service e3b512
  void get_text_extents(const std::string& utf8, TextExtents& extents) const;
Packit Service e3b512
  /** @deprecated Use get_text_extents() instead
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   * */
Packit Service e3b512
  void text_extents(const std::string& utf8, TextExtents& extents) const;
Packit Service e3b512
Packit Service e3b512
  /** Gets the extents for an array of glyphs. The extents describe a user-space
Packit Service e3b512
   * rectangle that encloses the "inked" portion of the glyphs, (as they would
Packit Service e3b512
   * be drawn by Context::show_glyphs() if the cairo graphics state were set to the
Packit Service e3b512
   * same font_face, font_matrix, ctm, and font_options as the ScaledFont
Packit Service e3b512
   * object).  Additionally, the x_advance and y_advance values indicate the
Packit Service e3b512
   * amount by which the current point would be advanced by Context::show_glyphs().
Packit Service e3b512
   *
Packit Service e3b512
   * Note that whitespace glyphs do not contribute to the size of the rectangle
Packit Service e3b512
   * (extents.width and extents.height).
Packit Service e3b512
   *
Packit Service e3b512
   * @param glyphs A vector of glyphs to calculate the extents of.
Packit Service e3b512
   * @param extents Returns the extents for the array of glyphs.
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   **/
Packit Service e3b512
  void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents);
Packit Service e3b512
Packit Service e3b512
  /** @deprecated Use get_glyph_extents() instead
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   * */
Packit Service e3b512
  void glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents);
Packit Service e3b512
Packit Service e3b512
  /** The FontFace with which this ScaledFont was created.
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   */
Packit Service e3b512
  RefPtr<FontFace> get_font_face() const;
Packit Service e3b512
Packit Service e3b512
  /** Gets the FontOptions with which the ScaledFont was created.
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   */
Packit Service e3b512
  void get_font_options(FontOptions& options) const;
Packit Service e3b512
Packit Service e3b512
  /** Gets the font matrix with which the ScaledFont was created.
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   */
Packit Service e3b512
  void get_font_matrix(Matrix& font_matrix) const;
Packit Service e3b512
  /* To keep 1.6.x ABI  */
Packit Service e3b512
  void get_font_matrix(cairo_matrix_t& font_matrix) const;
Packit Service e3b512
Packit Service e3b512
  /** Gets the CTM with which the ScaledFont was created.
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   */
Packit Service e3b512
  void get_ctm(Matrix& ctm) const;
Packit Service e3b512
  /* To keep 1.6.x ABI  */
Packit Service e3b512
  void get_ctm(cairo_matrix_t& ctm) const;
Packit Service e3b512
Packit Service e3b512
  /** Gets the type of scaled Font
Packit Service e3b512
   * @since 1.2
Packit Service e3b512
   */
Packit Service e3b512
  FontType get_type() const;
Packit Service e3b512
Packit Service e3b512
  // FIXME: it'd be really nice not to assume a specific container (e.g.
Packit Service e3b512
  // std::vector) here
Packit Service e3b512
  /**
Packit Service e3b512
   * @param x X position to place first glyph.
Packit Service e3b512
   * @param y Y position to place first glyph.
Packit Service e3b512
   * @param utf8 a string of text encoded in UTF-8.
Packit Service e3b512
   * @param glyphs pointer to array of glyphs to fill.
Packit Service e3b512
   * @param clusters pointer to array of cluster mapping information to fill.
Packit Service e3b512
   * @cluster_flags cluster mapping flags
Packit Service e3b512
   *
Packit Service e3b512
   * Converts UTF-8 text to an array of glyphs, with cluster mapping, that can be
Packit Service e3b512
   * used to render later.
Packit Service e3b512
   *
Packit Service e3b512
   * For details of how (@a clusters and @a cluster_flags map input
Packit Service e3b512
   * UTF-8 text to the output glyphs see Context::show_text_glyphs().
Packit Service e3b512
   *
Packit Service e3b512
   * The output values can be readily passed to Context::show_text_glyphs()
Packit Service e3b512
   * Context::show_glyphs(), or related functions, assuming that the exact
Packit Service e3b512
   * same scaled font is used for the operation.
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   **/
Packit Service e3b512
  void text_to_glyphs(double x,
Packit Service e3b512
                      double y,
Packit Service e3b512
                      const std::string& utf8,
Packit Service e3b512
                      std::vector<Glyph>& glyphs,
Packit Service e3b512
                      std::vector<TextCluster>& clusters,
Packit Service e3b512
                      TextClusterFlags& cluster_flags);
Packit Service e3b512
Packit Service e3b512
  /** Stores the scale matrix of this scaled font into matrix. The scale matrix
Packit Service e3b512
   * is product of the font matrix and the ctm associated with the scaled font,
Packit Service e3b512
   * and hence is the matrix mapping from font space to device space.
Packit Service e3b512
   *
Packit Service e3b512
   * @param scale_matrix return value for the matrix.
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   */
Packit Service e3b512
  void get_scale_matrix(Matrix& scale_matrix) const;
Packit Service e3b512
Packit Service e3b512
protected:
Packit Service e3b512
  /* Cairo::Matrix parameters changed to cairo_matrix_t */
Packit Service e3b512
  ScaledFont(const RefPtr<FontFace>& font_face, const cairo_matrix_t& font_matrix,
Packit Service e3b512
             const cairo_matrix_t& ctm, const FontOptions& options = FontOptions());
Packit Service e3b512
  /** The underlying C cairo object that is wrapped by this ScaledFont */
Packit Service e3b512
  cobject* m_cobject;
Packit Service e3b512
};
Packit Service e3b512
Packit Service e3b512
#ifdef CAIRO_HAS_FT_FONT
Packit Service e3b512
Packit Service e3b512
//TODO: Documentation.
Packit Service e3b512
/**
Packit Service e3b512
 * @since 1.8
Packit Service e3b512
 */
Packit Service e3b512
class FtScaledFont : public ScaledFont
Packit Service e3b512
{
Packit Service e3b512
public:
Packit Service e3b512
  /** Creates a ScaledFont From a FtFontFace.
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   */
Packit Service e3b512
  static RefPtr<FtScaledFont> create(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
Packit Service e3b512
      const Matrix& ctm, const FontOptions& options = FontOptions());
Packit Service e3b512
Packit Service e3b512
  /** Gets the FT_Face object from a FreeType backend font and scales it
Packit Service e3b512
   * appropriately for the font. You must release the face with
Packit Service e3b512
   * unlock_face() when you are done using it. Since the FT_Face object can be
Packit Service e3b512
   * shared between multiple ScaledFont objects, you must not lock any other
Packit Service e3b512
   * font objects until you unlock this one. A count is kept of the number of
Packit Service e3b512
   * times lock_face() is called.  unlock_face() must be called the same number
Packit Service e3b512
   * of times.
Packit Service e3b512
   *
Packit Service e3b512
   * You must be careful when using this function in a library or in a threaded
Packit Service e3b512
   * application, because freetype's design makes it unsafe to call freetype
Packit Service e3b512
   * functions simultaneously from multiple threads, (even if using distinct
Packit Service e3b512
   * FT_Face objects). Because of this, application code that acquires an
Packit Service e3b512
   * FT_Face object with this call must add it's own locking to protect any use
Packit Service e3b512
   * of that object, (and which also must protect any other calls into cairo as
Packit Service e3b512
   * almost any cairo function might result in a call into the freetype
Packit Service e3b512
   * library).
Packit Service e3b512
   *
Packit Service e3b512
   * @return The FT_Face object for font, scaled appropriately, or NULL if
Packit Service e3b512
   * scaled_font is in an error state or there is insufficient memory.
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   */
Packit Service e3b512
  FT_Face lock_face();
Packit Service e3b512
Packit Service e3b512
  /** Releases a face obtained with lock_face().
Packit Service e3b512
   *
Packit Service e3b512
   * @since 1.8
Packit Service e3b512
   */
Packit Service e3b512
  void unlock_face();
Packit Service e3b512
Packit Service e3b512
protected:
Packit Service e3b512
  FtScaledFont(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
Packit Service e3b512
      const Matrix& ctm, const FontOptions& options = FontOptions());
Packit Service e3b512
};
Packit Service e3b512
#endif // CAIRO_HAS_FT_FONT
Packit Service e3b512
Packit Service e3b512
}
Packit Service e3b512
Packit Service e3b512
#endif // __CAIROMM_SCALEDFONT_H
Packit Service e3b512
// vim: ts=2 sw=2 et