add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / pango / src / glyphstring.ccg
1 // -*- c++ -*-
2 /* $Id: glyphstring.ccg,v 1.2 2006/05/30 17:14:21 murrayc Exp $ */
3
4 /*
5  *
6  * Copyright 1998-2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <glibmm/utility.h>
24 #include <pango/pangocairo.h>
25
26 namespace Pango
27 {
28
29 GlyphString::GlyphString(const Glib::ustring& text, const Analysis& analysis)
30 :
31   gobject_(pango_glyph_string_new())
32 {
33   pango_shape(text.c_str(), text.bytes(), const_cast<PangoAnalysis*>(analysis.gobj()), gobj());
34 }
35
36 Rectangle GlyphString::get_ink_extents(const Glib::RefPtr<const Font>& font) const
37 {
38   Rectangle ink_rect;
39   pango_glyph_string_extents(const_cast<PangoGlyphString*>(gobj()), const_cast<PangoFont*>(font->gobj()), ink_rect.gobj(), 0);
40   return ink_rect;
41 }
42
43 Rectangle GlyphString::get_ink_extents(int start, int end, const Glib::RefPtr<const Font>& font) const
44 {
45   Rectangle ink_rect;
46   pango_glyph_string_extents_range(const_cast<PangoGlyphString*>(gobj()), start, end, const_cast<PangoFont*>(font->gobj()), ink_rect.gobj(), 0);
47   return ink_rect;
48 }
49
50 Rectangle GlyphString::get_logical_extents(const Glib::RefPtr<const Font>& font) const
51 {
52   Rectangle logical_rect;
53   pango_glyph_string_extents(const_cast<PangoGlyphString*>(gobj()), const_cast<PangoFont*>(font->gobj()), 0, logical_rect.gobj());
54   return logical_rect;
55 }
56
57 Rectangle GlyphString::get_logical_extents(int start, int end, const Glib::RefPtr<const Font>& font) const
58 {
59   Rectangle logical_rect;
60   pango_glyph_string_extents_range(const_cast<PangoGlyphString*>(gobj()), start, end, const_cast<PangoFont*>(font->gobj()), 0, logical_rect.gobj());
61   return logical_rect;
62 }
63
64 Glib::ArrayHandle<int> GlyphString::get_logical_widths(const Glib::ustring& text, int embedding_level) const
65 {
66   int* logical_widths = g_new(int, text.length());
67   pango_glyph_string_get_logical_widths(const_cast<PangoGlyphString*>(gobj()), text.c_str(), text.bytes(), embedding_level, logical_widths);
68   return Glib::ArrayHandle<int>(logical_widths, text.length(), Glib::OWNERSHIP_SHALLOW);
69 }
70
71 int GlyphString::index_to_x(const Glib::ustring& text, const Analysis& analysis, int index, bool trailing) const
72 {
73   int x_pos;
74   pango_glyph_string_index_to_x(const_cast<PangoGlyphString*>(gobj()), const_cast<gchar*>(text.c_str()), text.bytes(), const_cast<PangoAnalysis*>(analysis.gobj()), index, static_cast<int>(trailing), &x_pos);
75   return x_pos;
76 }
77
78 void GlyphString::x_to_index(const Glib::ustring& text, const Analysis& analysis, int x_pos, int& index, bool& trailing) const
79 {
80   gboolean trailing_temp = FALSE;
81   pango_glyph_string_x_to_index(const_cast<PangoGlyphString*>(gobj()), const_cast<char*>(text.c_str()), text.bytes(), const_cast<PangoAnalysis*>(analysis.gobj()), x_pos, &index, &trailing_temp);
82   trailing = trailing_temp;
83 }
84
85 Glib::ArrayHandle<GlyphInfo> GlyphString::get_glyphs() const
86 {
87   return Glib::ArrayHandle<GlyphInfo>(reinterpret_cast<GlyphInfo*>(gobj()->glyphs), gobj()->num_glyphs, Glib::OWNERSHIP_NONE);
88 }
89
90 } //namespace Pango