1 /* Copyright (C) 2006 The cairomm Development Team
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.
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.
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
19 #include <cairomm/scaledfont.h>
20 #include <cairomm/private.h> // for check_status_and_throw_exception
25 ScaledFont::ScaledFont(cobject* cobj, bool has_reference)
30 m_cobject = cairo_scaled_font_reference(cobj);
33 RefPtr<ScaledFont> ScaledFont::create(FontFace& font_face, const Matrix& font_matrix,
34 const Matrix& ctm, const FontOptions& options)
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));
41 void ScaledFont::extents(FontExtents& extents) const
43 cairo_scaled_font_extents(m_cobject, static_cast<cairo_font_extents_t*>(&extents));
44 check_object_status_and_throw_exception(*this);
47 void ScaledFont::text_extents(const std::string& utf8, TextExtents& extents) const
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);
53 void ScaledFont::glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents)
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.
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);
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);
70 RefPtr<FontFace> ScaledFont::get_font_face() const
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));
77 void ScaledFont::get_font_options(FontOptions& options) const
79 cairo_scaled_font_get_font_options(m_cobject, options.cobj());
80 check_object_status_and_throw_exception(*this);
83 void ScaledFont::get_font_matrix(Matrix& font_matrix) const
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);
90 void ScaledFont::get_ctm(Matrix& ctm) const
92 cairo_scaled_font_get_ctm(m_cobject, static_cast<cairo_matrix_t*>(&ctm));
93 check_object_status_and_throw_exception(*this);
96 FontType ScaledFont::get_type() const
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);