diff options
author | Jonathon Jongsma <jjongsma@gnome.org> | 2007-07-04 15:27:43 -0500 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@gnome.org> | 2007-07-04 15:27:43 -0500 |
commit | df2c191f05f941620215ecabb19519550ed5c730 (patch) | |
tree | 1c0d1e5fab288bc152ed046000e128c0bbea413a | |
parent | e10c4e12f7948cd6325812cbb089537231b1144e (diff) |
Fix dynamic casting of Pattern retrieved with Context::get_source()
* cairomm/context.cc: when getting the source pattern of a Cairo::Context,
check which type of Pattern it is so that we create the correct C++ wrapper.
Without this, RefPtr<>::cast_dynamic() doesn't seem to work as we would expect
it to.
* tests/test-context.cc: improve the Context::get_source() /
Context::set_source () tests now that dynamic casting works correctly
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | cairomm/context.cc | 19 | ||||
-rw-r--r-- | tests/test-context.cc | 60 |
3 files changed, 69 insertions, 19 deletions
@@ -1,5 +1,14 @@ 2007-07-04 Jonathon Jongsma <jjongsma@gnome.org> + * cairomm/context.cc: when getting the source pattern of a Cairo::Context, + check which type of Pattern it is so that we create the correct C++ wrapper. + Without this, RefPtr<>::cast_dynamic() doesn't seem to work as we would + expect it to. + * tests/test-context.cc: improve the Context::get_source() / + Context::set_source () tests now that dynamic casting works correctly + +2007-07-04 Jonathon Jongsma <jjongsma@gnome.org> + * examples/pdf-surface/main.cc: * examples/png_file/main.cc: * examples/ps-surface/main.cc: diff --git a/cairomm/context.cc b/cairomm/context.cc index 21855ac..1cbc7ee 100644 --- a/cairomm/context.cc +++ b/cairomm/context.cc @@ -536,7 +536,24 @@ RefPtr<Pattern> Context::get_source() { cairo_pattern_t* pattern = cairo_get_source(m_cobject); check_object_status_and_throw_exception(*this); - return RefPtr<Pattern>(new Pattern(pattern, false /* does not have reference */)); + cairo_pattern_type_t pattern_type = cairo_pattern_get_type (pattern); + switch (pattern_type) + { + case CAIRO_PATTERN_TYPE_SOLID: + return RefPtr<SolidPattern>(new SolidPattern(pattern, false /* does not have reference */)); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + return RefPtr<SurfacePattern>(new SurfacePattern(pattern, false /* does not have reference */)); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + return RefPtr<LinearGradient>(new LinearGradient(pattern, false /* does not have reference */)); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + return RefPtr<RadialGradient>(new RadialGradient(pattern, false /* does not have reference */)); + break; + default: + return RefPtr<Pattern>(new Pattern(pattern, false /* does not have reference */)); + } } RefPtr<const Pattern> Context::get_source() const diff --git a/tests/test-context.cc b/tests/test-context.cc index 2cbd246..11088b1 100644 --- a/tests/test-context.cc +++ b/tests/test-context.cc @@ -74,29 +74,53 @@ test_source () // there doesn't seem to be any way to compare the retrieved pattern to the // one that was set... for now, just excercise the function calls. cr->set_source (solid_pattern); - //BOOST_CHECK (cr->get_source () == solid_pattern); + { + Cairo::RefPtr<Cairo::SolidPattern> retrieved_solid = + Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ()); + BOOST_REQUIRE (retrieved_solid); + double r, g, b, a; + retrieved_solid->get_rgba (r, g, b, a); + BOOST_CHECK (r == 1.0); + BOOST_CHECK (g == 0.5); + BOOST_CHECK (b == 0.25); + } cr->set_source (gradient_pattern); - //BOOST_CHECK (cr->get_source () == gradient_pattern); + { + Cairo::RefPtr<Cairo::LinearGradient> retrieved_linear = + Cairo::RefPtr<Cairo::LinearGradient>::cast_dynamic(cr->get_source ()); + BOOST_REQUIRE (retrieved_linear); + double x0, x1, y0, y1; + retrieved_linear->get_linear_points (x0, y0, x1, y1); + BOOST_CHECK (x0 == 0.0); + BOOST_CHECK (y0 == 0.0); + BOOST_CHECK (x1 == 1.0); + BOOST_CHECK (y1 == 1.0); + } cr->set_source_rgb (1.0, 0.5, 0.25); - Cairo::RefPtr<Cairo::SolidPattern> solid = - Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ()); - BOOST_REQUIRE (solid); - double rx, gx, bx, ax; - solid->get_rgba (rx, gx, bx, ax); - BOOST_CHECK (rx == 1.0); - BOOST_CHECK (gx == 0.5); - BOOST_CHECK (bx == 0.25); + { + Cairo::RefPtr<Cairo::SolidPattern> solid = + Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ()); + BOOST_REQUIRE (solid); + double rx, gx, bx, ax; + solid->get_rgba (rx, gx, bx, ax); + BOOST_CHECK (rx == 1.0); + BOOST_CHECK (gx == 0.5); + BOOST_CHECK (bx == 0.25); + } cr->set_source_rgba (0.1, 0.3, 0.5, 0.7); - solid = - Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ()); - BOOST_REQUIRE (solid); - solid->get_rgba (rx, gx, bx, ax); - BOOST_CHECK (rx == 0.1); - BOOST_CHECK (gx == 0.3); - BOOST_CHECK (bx == 0.5); - BOOST_CHECK (ax == 0.7); + { + Cairo::RefPtr<Cairo::SolidPattern> solid = + Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ()); + BOOST_REQUIRE (solid); + double rx, gx, bx, ax; + solid->get_rgba (rx, gx, bx, ax); + BOOST_CHECK (rx == 0.1); + BOOST_CHECK (gx == 0.3); + BOOST_CHECK (bx == 0.5); + BOOST_CHECK (ax == 0.7); + } } void |