|
Packit |
908522 |
/* Copyright (C) 2006 The cairomm Development Team
|
|
Packit |
908522 |
*
|
|
Packit |
908522 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
908522 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
908522 |
* License as published by the Free Software Foundation; either
|
|
Packit |
908522 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
908522 |
*
|
|
Packit |
908522 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
908522 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
908522 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
908522 |
* Library General Public License for more details.
|
|
Packit |
908522 |
*
|
|
Packit |
908522 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
908522 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
908522 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
908522 |
* 02110-1301, USA.
|
|
Packit |
908522 |
*/
|
|
Packit |
908522 |
|
|
Packit |
908522 |
#include <cairomm/scaledfont.h>
|
|
Packit |
908522 |
#include <cairomm/fontface.h>
|
|
Packit |
908522 |
#include <cairomm/private.h> // for check_status_and_throw_exception
|
|
Packit |
908522 |
|
|
Packit |
908522 |
namespace Cairo
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
|
|
Packit |
908522 |
ScaledFont::ScaledFont(cobject* cobj, bool has_reference)
|
|
Packit |
908522 |
: m_cobject(nullptr)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
if(has_reference)
|
|
Packit |
908522 |
m_cobject = cobj;
|
|
Packit |
908522 |
else
|
|
Packit |
908522 |
m_cobject = cairo_scaled_font_reference(cobj);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
ScaledFont::ScaledFont(const RefPtr<FontFace>& font_face, const cairo_matrix_t& font_matrix,
|
|
Packit |
908522 |
const cairo_matrix_t& ctm, const FontOptions& options)
|
|
Packit |
908522 |
: m_cobject(nullptr)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
m_cobject =
|
|
Packit |
908522 |
cairo_scaled_font_create(font_face->cobj(),
|
|
Packit |
908522 |
&font_matrix,
|
|
Packit |
908522 |
&ctm,
|
|
Packit |
908522 |
options.cobj());
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
ScaledFont::~ScaledFont()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
if (cobj())
|
|
Packit |
908522 |
cairo_scaled_font_destroy(cobj());
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
RefPtr<ScaledFont> ScaledFont::create(const RefPtr<FontFace>& font_face, const Matrix& font_matrix,
|
|
Packit |
908522 |
const Matrix& ctm, const FontOptions& options)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
return RefPtr<ScaledFont>(new ScaledFont(font_face, font_matrix, ctm, options));
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
RefPtr<ScaledFont> ScaledFont::create(const RefPtr<FontFace>& font_face, const cairo_matrix_t& font_matrix,
|
|
Packit |
908522 |
const cairo_matrix_t& ctm, const FontOptions& options)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
return RefPtr<ScaledFont>(new ScaledFont(font_face, font_matrix, ctm, options));
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::extents(FontExtents& extents) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
get_extents(extents);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_extents(FontExtents& extents) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_extents(m_cobject, static_cast<cairo_font_extents_t*>(&extents));
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::text_extents(const std::string& utf8, TextExtents& extents) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_text_extents(m_cobject, utf8.c_str(), static_cast<cairo_text_extents_t*>(&extents));
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
// copy the data from the vector to a standard C array. I don't believe
|
|
Packit |
908522 |
// this will be a frequently used function so I think the performance hit is
|
|
Packit |
908522 |
// more than offset by the increased flexibility of the STL interface.
|
|
Packit |
908522 |
|
|
Packit |
908522 |
// Use new to allocate memory as MSCV complains about non-const array size with
|
|
Packit |
908522 |
// Glyph glyph_array[glyphs.size()]
|
|
Packit |
908522 |
Glyph* glyph_array= new Glyph[glyphs.size()];
|
|
Packit |
908522 |
std::copy(glyphs.begin(), glyphs.end(), glyph_array);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
cairo_scaled_font_glyph_extents(m_cobject, glyph_array, glyphs.size(),
|
|
Packit |
908522 |
static_cast<cairo_text_extents_t*>(&extents));
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
delete[] glyph_array;
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
RefPtr<FontFace> ScaledFont::get_font_face() const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto face = cairo_scaled_font_get_font_face(m_cobject);
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
return RefPtr<FontFace>(new FontFace(face, false /* returned face doesn't have a reference */));
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_font_options(FontOptions& options) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_get_font_options(m_cobject, options.cobj());
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_font_matrix(Matrix& font_matrix) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_get_font_matrix(m_cobject,
|
|
Packit |
908522 |
&font_matrix);
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_font_matrix(cairo_matrix_t& font_matrix) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_get_font_matrix(m_cobject,
|
|
Packit |
908522 |
&font_matrix);
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_ctm(Matrix& ctm) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_get_ctm(m_cobject, &ctm;;
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_ctm(cairo_matrix_t& ctm) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_get_ctm(m_cobject, &ctm;;
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
FontType ScaledFont::get_type() const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto font_type = cairo_scaled_font_get_type(m_cobject);
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
return static_cast<FontType>(font_type);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void
|
|
Packit |
908522 |
ScaledFont::text_to_glyphs (double x,
|
|
Packit |
908522 |
double y,
|
|
Packit |
908522 |
const std::string& utf8,
|
|
Packit |
908522 |
std::vector<Glyph>& glyphs,
|
|
Packit |
908522 |
std::vector<TextCluster>& clusters,
|
|
Packit |
908522 |
TextClusterFlags& cluster_flags)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
int num_glyphs = -1;
|
|
Packit |
908522 |
int num_clusters = -1;
|
|
Packit |
908522 |
cairo_glyph_t* c_glyphs = nullptr;
|
|
Packit |
908522 |
cairo_text_cluster_t* c_clusters = nullptr;
|
|
Packit |
908522 |
auto status = cairo_scaled_font_text_to_glyphs(cobj(), x, y,
|
|
Packit |
908522 |
utf8.c_str(),
|
|
Packit |
908522 |
utf8.size(),
|
|
Packit |
908522 |
&c_glyphs,
|
|
Packit |
908522 |
&num_glyphs,
|
|
Packit |
908522 |
&c_clusters,
|
|
Packit |
908522 |
&num_clusters,
|
|
Packit |
908522 |
reinterpret_cast<cairo_text_cluster_flags_t*>(&cluster_flags));
|
|
Packit |
908522 |
if (num_glyphs > 0 && c_glyphs) {
|
|
Packit |
908522 |
glyphs.assign(static_cast<Glyph*>(c_glyphs),
|
|
Packit |
908522 |
static_cast<Glyph*>(c_glyphs + num_glyphs));
|
|
Packit |
908522 |
cairo_glyph_free(c_glyphs);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
if (num_clusters > 0 && c_clusters) {
|
|
Packit |
908522 |
clusters.assign(static_cast<TextCluster*>(c_clusters),
|
|
Packit |
908522 |
static_cast<TextCluster*>(c_clusters + num_clusters));
|
|
Packit |
908522 |
cairo_text_cluster_free(c_clusters);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
check_status_and_throw_exception(status);
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void ScaledFont::get_scale_matrix(Matrix& scale_matrix) const
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_scaled_font_get_scale_matrix(const_cast<cairo_scaled_font_t*>(cobj()), &scale_matrix);
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
#ifdef CAIRO_HAS_FT_FONT
|
|
Packit |
908522 |
FtScaledFont::FtScaledFont(const RefPtr<FtFontFace>& font_face, const Matrix& font_matrix,
|
|
Packit |
908522 |
const Matrix& ctm, const FontOptions& options) :
|
|
Packit |
908522 |
ScaledFont(font_face, font_matrix, ctm, options)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
RefPtr<FtScaledFont>
|
|
Packit |
908522 |
FtScaledFont::create(const RefPtr<FtFontFace>& font_face,
|
|
Packit |
908522 |
const Matrix& font_matrix, const Matrix& ctm,
|
|
Packit |
908522 |
const FontOptions& options)
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
return RefPtr<FtScaledFont>(new FtScaledFont(font_face, font_matrix, ctm, options));
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
FT_Face FtScaledFont::lock_face()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto face = cairo_ft_scaled_font_lock_face(cobj());
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
return face;
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void FtScaledFont::unlock_face()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
cairo_ft_scaled_font_unlock_face(cobj());
|
|
Packit |
908522 |
check_object_status_and_throw_exception(*this);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
#endif // CAIRO_HAS_FT_FONT
|
|
Packit |
908522 |
|
|
Packit |
908522 |
} // namespace Cairo
|
|
Packit |
908522 |
// vim: ts=2 sw=2 et
|