add new sigc++2 directory
[ardour.git] / libs / cairomm / cairomm / scaledfont.cc
1 /* Copyright (C) 2006 The cairomm Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA.
17  */
18
19 #include <cairomm/scaledfont.h>
20 #include <cairomm/private.h>  // for check_status_and_throw_exception
21
22 namespace Cairo
23 {
24
25 ScaledFont::ScaledFont(cobject* cobj, bool has_reference)
26 {
27   if(has_reference)
28     m_cobject = cobj;
29   else
30     m_cobject = cairo_scaled_font_reference(cobj);
31 }
32
33 RefPtr<ScaledFont> ScaledFont::create(FontFace& font_face, const Matrix& font_matrix,
34     const Matrix& ctm, const FontOptions& options)
35 {
36   cairo_scaled_font_t* cobj = cairo_scaled_font_create(font_face.cobj(), &font_matrix, &ctm, options.cobj());
37   check_status_and_throw_exception(cairo_scaled_font_status(cobj));
38   return RefPtr<ScaledFont>(new ScaledFont(cobj, false));
39 }
40
41 void ScaledFont::extents(FontExtents& extents) const
42 {
43   cairo_scaled_font_extents(m_cobject, static_cast<cairo_font_extents_t*>(&extents));
44   check_object_status_and_throw_exception(*this);
45 }
46
47 void ScaledFont::text_extents(const std::string& utf8, TextExtents& extents) const
48 {
49   cairo_scaled_font_text_extents(m_cobject, utf8.c_str(), static_cast<cairo_text_extents_t*>(&extents));
50   check_object_status_and_throw_exception(*this);
51 }
52
53 void ScaledFont::glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents)
54 {
55   // copy the data from the vector to a standard C array.  I don't believe
56   // this will be a frequently used function so I think the performance hit is
57   // more than offset by the increased flexibility of the STL interface.
58   
59   // Use new to allocate memory as MSCV complains about non-const array size with
60   // Glyph glyph_array[glyphs.size()]
61   Glyph* glyph_array= new Glyph[glyphs.size()];
62   std::copy(glyphs.begin(), glyphs.end(), glyph_array);
63
64   cairo_scaled_font_glyph_extents(m_cobject, glyph_array, glyphs.size(),
65       static_cast<cairo_text_extents_t*>(&extents));
66   check_object_status_and_throw_exception(*this);
67   delete[] glyph_array;
68 }
69
70 RefPtr<FontFace> ScaledFont::get_font_face() const
71 {
72   cairo_font_face_t* face = cairo_scaled_font_get_font_face(m_cobject);
73   check_object_status_and_throw_exception(*this);
74   return RefPtr<FontFace>(new FontFace(face, true));
75 }
76
77 void ScaledFont::get_font_options(FontOptions& options) const
78 {
79   cairo_scaled_font_get_font_options(m_cobject, options.cobj());
80   check_object_status_and_throw_exception(*this);
81 }
82
83 void ScaledFont::get_font_matrix(Matrix& font_matrix) const
84 {
85   cairo_scaled_font_get_font_matrix(m_cobject,
86       static_cast<cairo_matrix_t*>(&font_matrix));
87   check_object_status_and_throw_exception(*this);
88 }
89
90 void ScaledFont::get_ctm(Matrix& ctm) const
91 {
92   cairo_scaled_font_get_ctm(m_cobject, static_cast<cairo_matrix_t*>(&ctm));
93   check_object_status_and_throw_exception(*this);
94 }
95
96 FontType ScaledFont::get_type() const
97 {
98   cairo_font_type_t font_type = cairo_scaled_font_get_type(m_cobject);
99   check_object_status_and_throw_exception(*this);
100   return static_cast<FontType>(font_type);
101 }
102
103 }   // namespace Cairo
104 // vim: ts=2 sw=2 et