/* $Id: context.hg,v 1.7 2006/06/10 15:26:24 murrayc Exp $ */

/* context.h
 * 
 * Copyright (C) 1998-1999 The gtkmm Development Team 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


#include <glibmm/object.h>
#include <glibmm/arrayhandle.h>
#include <glibmm/listhandle.h>
#include <pangomm/fontdescription.h>
#include <pangomm/fontmetrics.h>
#include <pangomm/fontset.h>
#include <pangomm/fontmap.h>
#include <pangomm/item.h>
#include <pangomm/attrlist.h>
#include <pangomm/types.h> //For Matrix
#include <pango/pango-context.h>
#include <cairomm/context.h>
#include <cairomm/fontoptions.h>

_DEFS(pangomm,pango)
_PINCLUDE(glibmm/private/object_p.h)

namespace Pango
{

_CC_INCLUDE(pango/pango-enum-types.h)
_WRAP_ENUM(Direction, PangoDirection, decl_prefix PANGOMM_API)
_WRAP_ENUM(GravityHint, PangoGravityHint, decl_prefix PANGOMM_API)


/** A Pango::Context stores global information used to control the itemization process.
 * You can retrieve a Pango::Context object with Gtk::Widget::create_pango_context() or
 * Gtk::Widget::get_pango_context(). If you don't use gtkmm call some c function of the
 * pango backend you intend to use and create a wrapper for the returned context,
 * e.g. Glib::wrap(pango_x_get_context()).
 *
 * Creating a Pango::Context object is the starting point of every rendering process.
 * You can either use it to create a high level Pango::Layout object which does all
 * the hard work for you by passing it into
 * Pango::Layout::create() or to generate glyph strings from character strings with
 * the help of itemize() and Pango::Item::shape() subsequently.
 *
 * Which fonts are used for rendering can be influenced by setting the default
 * font description, language and base direction of the context.
 *
 * If you want to calculate the space some text will need to be displayed you
 * might find the functions of Pango::FontMetrics useful. Use get_metrics() to
 * obtain the Pango::FontMetrics object for a specific Pango::FontDescription.
 * For more detailed calculations in a rendering-system-independant manner
 * and to determine whether specific characters can be represented by the
 * font that would be used for a specific Pango::FontDescription load a
 * Pango::Fontset with load_fontset() (load_font() returns the Pango::Font
 * that is the closest match for a Pango::FontDescription; however that's not
 * necessarily the font that will be used for rendering).
 */
class PANGOMM_API Context : public Glib::Object
{
   _CLASS_GOBJECT(Context, PangoContext, PANGO_CONTEXT, Glib::Object, GObject, , , PANGOMM_API)
   _IGNORE(pango_context_set_font_map) //PANGO_ENABLE_BACKEND
   _IGNORE(pango_context_list_families)
protected:
  _CTOR_DEFAULT
  _IGNORE(pango_context_new)
  
public:
  /** List all available font families for a context.
   * You can specify one of these as your desired font family in the Pango::FontDesciption
   * objects you use, e.g. in the default font description of the context.
   * @return An array of Pango::FontFamily objects.
   */
  Glib::ArrayHandle< Glib::RefPtr<FontFamily> > list_families() const;
  
  _IGNORE(pango_context_changed)

  _WRAP_METHOD(void set_font_map(const Glib::RefPtr<FontMap>& font_map), pango_context_set_font_map)

  _WRAP_METHOD(Glib::RefPtr<FontMap> get_font_map(), pango_context_get_font_map)
  _WRAP_METHOD(Glib::RefPtr<const FontMap> get_font_map() const, pango_context_get_font_map)

  _WRAP_METHOD(guint get_serial() const, pango_context_get_serial)

  _WRAP_METHOD(Glib::RefPtr<Font> load_font(const FontDescription& desc) const, pango_context_load_font)
  _WRAP_METHOD(Glib::RefPtr<Fontset> load_fontset(const FontDescription& desc, const Language& language) const, pango_context_load_fontset)

  /** Get overall metric information for a particular font description.
   * The metrics may be substantially different for different scripts. However this
   * function overload returns the metrics of the entire font.
   * @param desc A Pango::FontDescription object.
   * @return A Pango::FontMetrics object.
   */
  FontMetrics get_metrics(const FontDescription& desc) const;
  _WRAP_METHOD(FontMetrics get_metrics(const FontDescription& desc, const Language& language) const, pango_context_get_metrics)
  _WRAP_METHOD(void set_font_description(const FontDescription& desc), pango_context_set_font_description)
  _WRAP_METHOD(FontDescription get_font_description() const, pango_context_get_font_description)
  _WRAP_METHOD(Language get_language() const, pango_context_get_language)
  _WRAP_METHOD(void set_language(const Language& language), pango_context_set_language)
  _WRAP_METHOD(void set_base_dir(Direction direction), pango_context_set_base_dir)
  _WRAP_METHOD(Direction get_base_dir() const, pango_context_get_base_dir)

  _WRAP_METHOD(void set_base_gravity(Gravity gravity), pango_context_set_base_gravity)
  _WRAP_METHOD(Gravity get_base_gravity() const, pango_context_get_base_gravity)
  _WRAP_METHOD(Gravity get_gravity() const, pango_context_get_gravity)
  _WRAP_METHOD(void set_gravity_hint(GravityHint hint), pango_context_set_gravity_hint)
  _WRAP_METHOD(GravityHint get_gravity_hint() const, pango_context_get_gravity_hint)

  _WRAP_METHOD(void set_matrix(const Matrix& matrix), pango_context_set_matrix)

  Matrix get_matrix() const;
  _IGNORE(pango_context_get_matrix)

  /** Breaks a piece of text into segments with consistent directional level and shaping engine.
   * Each byte of @a text will be contained in exactly one of the items in the returned list.
   * The generated list of items will be in logical order (the start offsets of the items
   * are ascending).
   * @param text The text to itemize.
   * @param attrs The set of attributes that apply.
   * @return A list of Pango::Item objects.
   */
  ListHandle_Item itemize(const Glib::ustring& text, const AttrList& attrs) const;

  /** Breaks a piece of text into segments with consistent directional level and shaping engine.
   * Each byte of @a text will be contained in exactly one of the items in the returned list. 
   * The generated list of items will be in logical order (the start offsets of the items
   * are ascending).
   *
   * @a cached_iter should be an iterator over @a attrs currently positioned at a range before
   * or containing @a start_index. @a cached_iter will be advanced to the range covering the
   * position just after @a start_index + @a length. (i.e. if itemizing in a loop, just keep
   * passing in the same @a cached_iter).
   *
   * @param text The text to itemize.
   * @param start_index First byte in @a text to process.
   * @param length The number of bytes (not characters) to process after @a start_index. This must be >= <tt>0</tt>.
   * @param attrs The set of attributes that apply to @a text.
   * @param cached_iter Cached attribute iterator.
   * @return A list of Pango::Item structures.
   */
  ListHandle_Item itemize(const Glib::ustring& text, int start_index, int length,
                          const AttrList& attrs, AttrIter& cached_iter) const;

  /** Updates a Pango Context previously created for use with Cairo to
   * match the current transformation and target surface of a Cairo
   * Context. If any layouts have been created for the context,
   * it's necessary to call Pango::Layout::context_changed() on those
   * layouts.
   *
   * @param context A Cairo context, from CairoFontMap::create_context().
   */
  void update_from_cairo_context(const Cairo::RefPtr<Cairo::Context>& context);


  _WRAP_METHOD(void set_cairo_font_options(const Cairo::FontOptions& options), pango_cairo_context_set_font_options)

#m4 _CONVERSION(`const cairo_font_options_t*',`Cairo::FontOptions',`Cairo::FontOptions(const_cast< cairo_font_options_t*>($3), false /* take_copy */)')
  _WRAP_METHOD(Cairo::FontOptions get_font_options() const, pango_cairo_context_get_font_options)

  _WRAP_METHOD(void set_resolution(double dpi), pango_cairo_context_set_resolution)
  _WRAP_METHOD(double get_resolution() const, pango_cairo_context_get_resolution)

};

} /* namespace Pango */

