|
Packit |
908522 |
#include <boost/test/unit_test.hpp>
|
|
Packit |
908522 |
#include <boost/test/test_tools.hpp>
|
|
Packit |
908522 |
#include <boost/test/floating_point_comparison.hpp>
|
|
Packit |
908522 |
using namespace boost::unit_test;
|
|
Packit |
908522 |
#include <cairomm/scaledfont.h>
|
|
Packit |
908522 |
#include <iostream>
|
|
Packit |
908522 |
|
|
Packit |
908522 |
using namespace Cairo;
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void test_construction()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto face = ToyFontFace::create("sans", FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL);
|
|
Packit |
908522 |
Matrix identity;
|
|
Packit |
908522 |
cairo_matrix_init_identity(&identity);
|
|
Packit |
908522 |
auto font = ScaledFont::create(face, identity, identity, FontOptions());
|
|
Packit |
908522 |
BOOST_REQUIRE(font);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
// now use the default argument for font_options
|
|
Packit |
908522 |
font = ScaledFont::create(face, identity, identity);
|
|
Packit |
908522 |
BOOST_REQUIRE(font);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void test_text_to_glyphs()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto face = ToyFontFace::create("sans", FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL);
|
|
Packit |
908522 |
Matrix identity;
|
|
Packit |
908522 |
cairo_matrix_init_identity(&identity);
|
|
Packit |
908522 |
auto font = ScaledFont::create(face, identity, identity, FontOptions());
|
|
Packit |
908522 |
BOOST_REQUIRE(font);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
std::vector<Glyph> glyphs;
|
|
Packit |
908522 |
std::vector<TextCluster> clusters;
|
|
Packit |
908522 |
TextClusterFlags flags;
|
|
Packit |
908522 |
font->text_to_glyphs(0, 0, "foo", glyphs, clusters, flags);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
BOOST_CHECK_EQUAL(3, glyphs.size());
|
|
Packit |
908522 |
BOOST_CHECK_EQUAL(3, clusters.size());
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void test_scale_matrix()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto face = ToyFontFace::create("sans", FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL);
|
|
Packit |
908522 |
Matrix m;
|
|
Packit |
908522 |
cairo_matrix_init_scale(&m, 2.0, 4.0);
|
|
Packit |
908522 |
auto font = ScaledFont::create(face, m, m, FontOptions());
|
|
Packit |
908522 |
BOOST_REQUIRE(font);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
Matrix result;
|
|
Packit |
908522 |
font->get_scale_matrix(result);
|
|
Packit |
908522 |
// no real test, just excercising the functionality
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
void test_get_font_face()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
// this is to test for a bug where we were accidentally freeing the resulting
|
|
Packit |
908522 |
// font face from a call to ScaledFont::get_font_face() when we didn't hold a
|
|
Packit |
908522 |
// reference to it
|
|
Packit |
908522 |
auto face = ToyFontFace::create("sans", FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL);
|
|
Packit |
908522 |
Matrix identity;
|
|
Packit |
908522 |
cairo_matrix_init_identity(&identity);
|
|
Packit |
908522 |
auto font = ScaledFont::create(face, identity, identity, FontOptions());
|
|
Packit |
908522 |
BOOST_REQUIRE(font);
|
|
Packit |
908522 |
const int refcount = cairo_font_face_get_reference_count(face->cobj());
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto got_face = font->get_font_face();
|
|
Packit |
908522 |
} // scope ensure that the font face is destroyed
|
|
Packit |
908522 |
// after creating and destroying the FontFace in get_font_face, our reference
|
|
Packit |
908522 |
// count should be the same
|
|
Packit |
908522 |
BOOST_REQUIRE_EQUAL(cairo_font_face_get_reference_count(face->cobj()), refcount);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
#ifdef CAIRO_HAS_FT_FONT
|
|
Packit |
908522 |
void test_ft_scaled_font()
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto invalid = FcPatternCreate();
|
|
Packit |
908522 |
Cairo::RefPtr<Cairo::FtFontFace> invalid_face;
|
|
Packit |
908522 |
BOOST_CHECK_THROW(invalid_face = Cairo::FtFontFace::create(invalid), std::bad_alloc);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
// basically taken from the cairo test case -- we don't care what font we're
|
|
Packit |
908522 |
// using so just create an empty pattern and do the minimal substitution to
|
|
Packit |
908522 |
// get a valid pattern
|
|
Packit |
908522 |
auto pattern = FcPatternCreate();
|
|
Packit |
908522 |
FcConfigSubstitute (NULL, pattern, FcMatchPattern);
|
|
Packit |
908522 |
FcDefaultSubstitute (pattern);
|
|
Packit |
908522 |
FcResult result;
|
|
Packit |
908522 |
auto resolved = FcFontMatch (NULL, pattern, &result);
|
|
Packit |
908522 |
auto face = Cairo::FtFontFace::create(resolved);
|
|
Packit |
908522 |
BOOST_CHECK(face);
|
|
Packit |
908522 |
|
|
Packit |
908522 |
cairo_scaled_font_t* c_scaled_font = nullptr;
|
|
Packit |
908522 |
int refcount = 0;
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
auto scaled_font =
|
|
Packit |
908522 |
FtScaledFont::create(face,
|
|
Packit |
908522 |
Cairo::identity_matrix(),
|
|
Packit |
908522 |
Cairo::identity_matrix(),
|
|
Packit |
908522 |
FontOptions());
|
|
Packit |
908522 |
c_scaled_font = scaled_font->cobj();
|
|
Packit |
908522 |
refcount = cairo_scaled_font_get_reference_count(c_scaled_font);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
// make sure that the base destructor is called
|
|
Packit |
908522 |
BOOST_CHECK_EQUAL(cairo_scaled_font_get_reference_count(c_scaled_font), refcount -1);
|
|
Packit |
908522 |
}
|
|
Packit |
908522 |
#endif // CAIRO_HAS_FT_FONT
|
|
Packit |
908522 |
|
|
Packit |
908522 |
|
|
Packit |
908522 |
test_suite*
|
|
Packit |
908522 |
init_unit_test_suite(int argc, char* argv[])
|
|
Packit |
908522 |
{
|
|
Packit |
908522 |
// compile even with -Werror
|
|
Packit |
908522 |
if (argc && argv) {}
|
|
Packit |
908522 |
|
|
Packit |
908522 |
test_suite* test= BOOST_TEST_SUITE( "Cairo::ScaledFont Tests" );
|
|
Packit |
908522 |
|
|
Packit |
908522 |
test->add(BOOST_TEST_CASE(&test_construction));
|
|
Packit |
908522 |
test->add(BOOST_TEST_CASE(&test_text_to_glyphs));
|
|
Packit |
908522 |
test->add(BOOST_TEST_CASE(&test_scale_matrix));
|
|
Packit |
908522 |
test->add(BOOST_TEST_CASE(&test_get_font_face));
|
|
Packit |
908522 |
#ifdef CAIRO_HAS_FT_FONT
|
|
Packit |
908522 |
test->add(BOOST_TEST_CASE(&test_ft_scaled_font));
|
|
Packit |
908522 |
#endif // CAIRO_HAS_FT_FONT
|
|
Packit |
908522 |
|
|
Packit |
908522 |
return test;
|
|
Packit |
908522 |
}
|