Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / gtkmm2 / pango / src / context.hg
1 /* $Id: context.hg,v 1.7 2006/06/10 15:26:24 murrayc Exp $ */
2
3 /* context.h
4  * 
5  * Copyright (C) 1998-1999 The gtkmm Development Team 
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the Free
19  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22
23 #include <glibmm/object.h>
24 #include <glibmm/arrayhandle.h>
25 #include <glibmm/listhandle.h>
26 #include <pangomm/fontdescription.h>
27 #include <pangomm/fontmetrics.h>
28 #include <pangomm/fontset.h>
29 #include <pangomm/fontmap.h>
30 #include <pangomm/item.h>
31 #include <pangomm/attrlist.h>
32 #include <pangomm/types.h> //For Matrix
33 #include <pango/pango-context.h>
34 #include <cairomm/context.h>
35 #include <cairomm/fontoptions.h>
36
37 _DEFS(pangomm,pango)
38 _PINCLUDE(glibmm/private/object_p.h)
39
40 namespace Pango
41 {
42
43 _CC_INCLUDE(pango/pango-enum-types.h)
44 _WRAP_ENUM(Direction, PangoDirection)
45 _WRAP_ENUM(GravityHint, PangoGravityHint)
46
47
48 /** A Pango::Context stores global information used to control the itemization process.
49  * You can retrieve a Pango::Context object with Gtk::Widget::create_pango_context() or
50  * Gtk::Widget::get_pango_context(). If you don't use gtkmm call some c function of the
51  * pango backend you intend to use and create a wrapper for the returned context,
52  * e.g. Glib::wrap(pango_x_get_context()).
53  *
54  * Creating a Pango::Context object is the starting point of every rendering process.
55  * You can either use it to create a high level Pango::Layout object which does all
56  * the hard work for you by passing it into
57  * Pango::Layout::create() or to generate glyph strings from character strings with
58  * the help of itemize() and Pango::Item::shape() subsequently.
59  *
60  * Which fonts are used for rendering can be influenced by setting the default
61  * font description, language and base direction of the context.
62  *
63  * If you want to calculate the space some text will need to be displayed you
64  * might find the functions of Pango::FontMetrics useful. Use get_metrics() to
65  * obtain the Pango::FontMetrics object for a specific Pango::FontDescription.
66  * For more detailed calculations in a rendering-system-independant manner
67  * and to determine whether specific characters can be represented by the
68  * font that would be used for a specific Pango::FontDescription load a
69  * Pango::Fontset with load_fontset() (load_font() returns the Pango::Font
70  * that is the closest match for a Pango::FontDescription; however that's not
71  * necessarily the font that will be used for rendering).
72  */
73 class Context : public Glib::Object
74 {
75    _CLASS_GOBJECT(Context, PangoContext, PANGO_CONTEXT, Glib::Object, GObject)
76    _IGNORE(pango_context_new, pango_context_set_font_map) //PANGO_ENABLE_BACKEND
77    _IGNORE(pango_context_list_families)
78 protected:
79   _CTOR_DEFAULT
80   
81 public:
82   /** List all available font families for a context.
83    * You can specify one of these as your desired font family in the Pango::FontDesciption
84    * objects you use, e.g. in the default font description of the context.
85    * @return An array of Pango::FontFamily objects.
86    */
87   Glib::ArrayHandle< Glib::RefPtr<FontFamily> > list_families() const;
88   
89   _WRAP_METHOD(Glib::RefPtr<FontMap> get_font_map(), pango_context_get_font_map)
90   _WRAP_METHOD(Glib::RefPtr<const FontMap> get_font_map() const, pango_context_get_font_map)  
91
92   _WRAP_METHOD(Glib::RefPtr<Font> load_font(const FontDescription& desc) const, pango_context_load_font)
93   _WRAP_METHOD(Glib::RefPtr<Fontset> load_fontset(const FontDescription& desc, const Language& language) const, pango_context_load_fontset)
94
95   /** Get overall metric information for a particular font description.
96    * The metrics may be substantially different for different scripts. However this
97    * function overload returns the metrics of the entire font.
98    * @param desc A Pango::FontDescription object.
99    * @return A Pango::FontMetrics object.
100    */
101   FontMetrics get_metrics(const FontDescription& desc) const;
102   _WRAP_METHOD(FontMetrics get_metrics(const FontDescription& desc, const Language& language) const, pango_context_get_metrics)
103   _WRAP_METHOD(void set_font_description(const FontDescription& desc), pango_context_set_font_description)
104   _WRAP_METHOD(FontDescription get_font_description() const, pango_context_get_font_description)
105   _WRAP_METHOD(Language get_language() const, pango_context_get_language)
106   _WRAP_METHOD(void set_language(const Language& language), pango_context_set_language)
107   _WRAP_METHOD(void set_base_dir(Direction direction), pango_context_set_base_dir)
108   _WRAP_METHOD(Direction get_base_dir() const, pango_context_get_base_dir)
109
110   _WRAP_METHOD(void set_base_gravity(Gravity gravity), pango_context_set_base_gravity)
111   _WRAP_METHOD(Gravity get_base_gravity() const, pango_context_get_base_gravity)
112   _WRAP_METHOD(Gravity get_gravity() const, pango_context_get_gravity)
113   _WRAP_METHOD(void set_gravity_hint(GravityHint hint), pango_context_set_gravity_hint)
114   _WRAP_METHOD(GravityHint get_gravity_hint() const, pango_context_get_gravity_hint)
115
116   _WRAP_METHOD(void set_matrix(const Matrix& matrix), pango_context_set_matrix)
117
118   Matrix get_matrix() const;
119   _IGNORE(pango_context_get_matrix)
120
121   /** Breaks a piece of text into segments with consistent directional level and shaping engine.
122    * Each byte of @a text will be contained in exactly one of the items in the returned list.
123    * The generated list of items will be in logical order (the start offsets of the items
124    * are ascending).
125    * @param text The text to itemize.
126    * @param attrs The set of attributes that apply.
127    * @return A list of Pango::Item objects.
128    */
129   ListHandle_Item itemize(const Glib::ustring& text, const AttrList& attrs) const;
130
131   /** Breaks a piece of text into segments with consistent directional level and shaping engine.
132    * Each byte of @a text will be contained in exactly one of the items in the returned list. 
133    * The generated list of items will be in logical order (the start offsets of the items
134    * are ascending).
135    *
136    * @a cached_iter should be an iterator over @a attrs currently positioned at a range before
137    * or containing @a start_index. @a cached_iter will be advanced to the range covering the
138    * position just after @a start_index + @a length. (i.e. if itemizing in a loop, just keep
139    * passing in the same @a cached_iter).
140    *
141    * @param text The text to itemize.
142    * @param start_index First byte in @a text to process.
143    * @param length The number of bytes (not characters) to process after @a start_index. This must be >= <tt>0</tt>.
144    * @param attrs The set of attributes that apply to @a text.
145    * @param cached_iter Cached attribute iterator.
146    * @return A list of Pango::Item structures.
147    */
148   ListHandle_Item itemize(const Glib::ustring& text, int start_index, int length,
149                           const AttrList& attrs, AttrIter& cached_iter) const;
150
151   /** Updates a Pango Context previously created for use with Cairo to
152    * match the current transformation and target surface of a Cairo
153    * Context. If any layouts have been created for the context,
154    * it's necessary to call Pango::Layout::context_changed() on those
155    * layouts.
156    *
157    * @param context A Cairo context, from CairoFontMap::create_context().
158    */
159   void update_from_cairo_context(const Cairo::RefPtr<Cairo::Context>& context);
160
161
162   _WRAP_METHOD(void set_cairo_font_options(const Cairo::FontOptions& options), pango_cairo_context_set_font_options)
163
164 #m4 _CONVERSION(`const cairo_font_options_t*',`Cairo::FontOptions',`Cairo::FontOptions(const_cast< cairo_font_options_t*>($3), false /* take_copy */)')
165   _WRAP_METHOD(Cairo::FontOptions get_font_options() const, pango_cairo_context_get_font_options)
166
167   _WRAP_METHOD(void set_resolution(double dpi), pango_cairo_context_set_resolution)
168   _WRAP_METHOD(double get_resolution() const, pango_cairo_context_get_resolution)
169
170 };
171
172 } /* namespace Pango */
173