diff options
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | cairomm/context.cc | 11 | ||||
-rw-r--r-- | cairomm/context.h | 4 | ||||
-rw-r--r-- | cairomm/enums.h | 15 | ||||
-rw-r--r-- | cairomm/fontface.cc | 10 | ||||
-rw-r--r-- | cairomm/fontface.h | 6 | ||||
-rw-r--r-- | cairomm/fontoptions.cc | 15 | ||||
-rw-r--r-- | cairomm/fontoptions.h | 22 | ||||
-rw-r--r-- | cairomm/scaledfont.cc | 4 | ||||
-rw-r--r-- | cairomm/scaledfont.h | 6 | ||||
-rw-r--r-- | cairomm/surface.cc | 9 | ||||
-rw-r--r-- | cairomm/surface.h | 14 | ||||
-rw-r--r-- | tests/test-context.cc | 13 | ||||
-rw-r--r-- | tests/test-font-face.cc | 2 | ||||
-rw-r--r-- | tests/test-font-options.cc | 38 | ||||
-rw-r--r-- | tests/test-scaled-font.cc | 4 | ||||
-rw-r--r-- | tests/test-surface.cc | 11 |
17 files changed, 107 insertions, 100 deletions
@@ -1,3 +1,26 @@ +2008-10-07 Jonathon Jongsma <jonathon@quotidian.org> + + * cairomm/context.cc: + * cairomm/context.h: remove has_show_text_glyphs() (moved to Surface) + * cairomm/surface.cc: + * cairomm/surface.h: added has_show_text_glyphs() (moved from Context) + * cairomm/enums.h: removed LcdFilter enum, added a TextClusterFlags enum + * cairomm/fontface.cc: + * cairomm/fontface.h: changed the 'backwards' bool argument of + SlotTextToGlyphs to use TextClusterFlags instead. Same general change for the + C callback text_to_glyphs_cb + * cairomm/fontoptions.cc: + * cairomm/fontoptions.h: remove get/set_lcd_filter() since it was removed from + cairo just before the 1.8 release + * cairomm/scaledfont.cc: + * cairomm/scaledfont.h: changed the 'backwards' bool argument of + text_to_glyphs() to use TextClusterFlags instead + * tests/test-context.cc: + * tests/test-font-face.cc: + * tests/test-font-options.cc: + * tests/test-scaled-font.cc: + * tests/test-surface.cc: update tests for API changes + 2008-10-05 Jonathon Jongsma <jonathon@quotidian.org> * cairomm/matrix.cc: diff --git a/cairomm/context.cc b/cairomm/context.cc index 78e9b53..a9df045 100644 --- a/cairomm/context.cc +++ b/cairomm/context.cc @@ -504,22 +504,15 @@ void Context::show_text(const std::string& utf8) check_object_status_and_throw_exception(*this); } -bool Context::has_show_text_glyphs() const -{ - bool result = cairo_has_show_text_glyphs(const_cast<cairo_t*>(cobj())); - check_object_status_and_throw_exception(*this); - return result; -} - void Context::show_text_glyphs(const std::string& utf8, const std::vector<Glyph>& glyphs, const std::vector<TextCluster>& clusters, - bool backward) + TextClusterFlags cluster_flags) { cairo_show_text_glyphs(cobj(), utf8.c_str(), utf8.size(), &glyphs[0], glyphs.size(), &clusters[0], clusters.size(), - backward); + static_cast<cairo_text_cluster_flags_t>(cluster_flags)); check_object_status_and_throw_exception(*this); } diff --git a/cairomm/context.h b/cairomm/context.h index 33926a7..54b51d8 100644 --- a/cairomm/context.h +++ b/cairomm/context.h @@ -724,11 +724,11 @@ public: //TODO: Documentation: void show_text(const std::string& utf8); void show_glyphs(const std::vector<Glyph>& glyphs); - bool has_show_text_glyphs() const; + /** @since 1.8 */ void show_text_glyphs(const std::string& utf8, const std::vector<Glyph>& glyphs, const std::vector<TextCluster>& clusters, - bool backward); + TextClusterFlags cluster_flags); RefPtr<FontFace> get_font_face(); RefPtr<const FontFace> get_font_face() const; diff --git a/cairomm/enums.h b/cairomm/enums.h index f2f1653..b698fb7 100644 --- a/cairomm/enums.h +++ b/cairomm/enums.h @@ -221,19 +221,14 @@ typedef enum FONT_TYPE_USER = CAIRO_FONT_TYPE_USER } FontType; -/** - * The LCD filter specifies the low-pass filter applied to LCD-optimized - * bitmaps generated with an antialiasing mode of ANTIALIAS_SUBPIXEL. +/** Specifies properties of a text cluster mapping. * * @since 1.8 **/ -typedef enum { - LCD_FILTER_DEFAULT = CAIRO_LCD_FILTER_DEFAULT, /**< Use the default LCD filter for font backend and target device */ - LCD_FILTER_NONE = CAIRO_LCD_FILTER_NONE, /**< Do not perform LCD filtering */ - LCD_FILTER_INTRA_PIXEL = CAIRO_LCD_FILTER_INTRA_PIXEL, /**< Intra-pixel filter */ - LCD_FILTER_FIR3 = CAIRO_LCD_FILTER_FIR3, /**< FIR filter with a 3x3 kernel */ - LCD_FILTER_FIR5 = CAIRO_LCD_FILTER_FIR5 /**< FIR filter with a 5x5 kernel */ -} LcdFilter; +typedef enum +{ + TEXT_CLUSTER_FLAG_BACKWARD = CAIRO_TEXT_CLUSTER_FLAG_BACKWARD /**< The clusters in the cluster array map to glyphs in the glyph array from end to start. */ +} TextClusterFlags; } // namespace Cairo diff --git a/cairomm/fontface.cc b/cairomm/fontface.cc index a8a3bf7..2246a1b 100644 --- a/cairomm/fontface.cc +++ b/cairomm/fontface.cc @@ -201,7 +201,7 @@ UserFontFace::text_to_glyphs_cb(cairo_scaled_font_t *scaled_font, int *num_glyphs, cairo_text_cluster_t **clusters, int *num_clusters, - cairo_bool_t *backward) + cairo_text_cluster_flags_t *cluster_flags) { cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); // we've stored a pointer to the wrapper object in the C object's user_data @@ -216,7 +216,7 @@ UserFontFace::text_to_glyphs_cb(cairo_scaled_font_t *scaled_font, std::vector<Glyph> glyph_v; std::vector<TextCluster> cluster_v; const std::string utf8_str(utf8, utf8 + utf8_len); - bool local_backwards = false; + TextClusterFlags local_flags = static_cast<TextClusterFlags>(0); ErrorStatus status = (instance->m_priv->m_text_to_glyphs_slot)(RefPtr<ScaledFont>(new @@ -224,7 +224,7 @@ UserFontFace::text_to_glyphs_cb(cairo_scaled_font_t *scaled_font, utf8_str, glyph_v, cluster_v, - local_backwards); + local_flags); // TODO: we re-allocate a new array and pass it back to the caller since // cairo will free the the returned array. It sucks to do this excessive @@ -254,8 +254,8 @@ UserFontFace::text_to_glyphs_cb(cairo_scaled_font_t *scaled_font, } } - if(backward) - *backward = local_backwards; + if(cluster_flags) + *cluster_flags = static_cast<cairo_text_cluster_flags_t>(local_flags); return status; } diff --git a/cairomm/fontface.h b/cairomm/fontface.h index e3435b3..ee7621e 100644 --- a/cairomm/fontface.h +++ b/cairomm/fontface.h @@ -348,7 +348,7 @@ public: * @param utf8 a string of text encoded in UTF-8. * @param glyphs An array of glyphs to fill, in font space. * @param clusters An array of cluster mapping information to fill. - * @param backward This will be set, to specify whether the text to glyphs mapping goes backward. + * @param cluster_flags This will be set, to specify the text to glyphs mapping flags * * Since: 1.8 **/ @@ -357,7 +357,7 @@ public: const std::string& /*utf8*/, std::vector<Glyph>& /*glyphs*/, std::vector<TextCluster>& /*clusters*/, - bool& /*backward*/> SlotTextToGlyphs; + TextClusterFlags& /*cluster_flags*/> SlotTextToGlyphs; /** Sets the text-to-glyphs conversion function of a user-font. * See SlotTextToGlyphs for details of how the callback @@ -410,7 +410,7 @@ private: int *num_glyphs, cairo_text_cluster_t **clusters, int *num_clusters, - cairo_bool_t *backward); + cairo_text_cluster_flags_t *cluster_flags); }; // font system support diff --git a/cairomm/fontoptions.cc b/cairomm/fontoptions.cc index f574eb9..fc5ebbb 100644 --- a/cairomm/fontoptions.cc +++ b/cairomm/fontoptions.cc @@ -154,21 +154,6 @@ HintMetrics FontOptions::get_hint_metrics() const return result; } -void FontOptions::set_lcd_filter(LcdFilter lcd_filter) -{ - cairo_font_options_set_lcd_filter(m_cobject, - static_cast<cairo_lcd_filter_t>(lcd_filter)); - check_object_status_and_throw_exception(*this); -} - -LcdFilter FontOptions::get_lcd_filter() -{ - const LcdFilter result = - static_cast<LcdFilter>(cairo_font_options_get_lcd_filter(cobj())); - check_object_status_and_throw_exception(*this); - return result; -} - #ifdef CAIRO_HAS_FT_FONT void FontOptions::substitute(FcPattern* pattern) { diff --git a/cairomm/fontoptions.h b/cairomm/fontoptions.h index 1a0d1c3..a487937 100644 --- a/cairomm/fontoptions.h +++ b/cairomm/fontoptions.h @@ -132,28 +132,6 @@ public: **/ HintMetrics get_hint_metrics() const; - /** - * Sets the LCD filter for the font options object. The LCD filter specifies how - * pixels are filtered when rendered with an antialiasing mode of - * ANTIALIAS_SUBPIXEL. See the documentation for - * LcdFilter for full details. - * - * @param lcd_filter the new LCD filter. - * - * @since 1.8 - **/ - void set_lcd_filter(LcdFilter lcd_filter); - - /** - * Gets the LCD filter for the font options object. - * See the documentation for LcdFilter for full details. - * - * @return the LCD filter for the font options object. - * - * @since 1.8 - **/ - LcdFilter get_lcd_filter(); - #ifdef CAIRO_HAS_FT_FONT /** Add options to a FcPattern based on a cairo_font_options_t font options * object. Options that are already in the pattern, are not overridden, so you diff --git a/cairomm/scaledfont.cc b/cairomm/scaledfont.cc index bde5707..9f890ca 100644 --- a/cairomm/scaledfont.cc +++ b/cairomm/scaledfont.cc @@ -116,7 +116,7 @@ ScaledFont::text_to_glyphs (double x, const std::string& utf8, std::vector<Glyph>& glyphs, std::vector<TextCluster>& clusters, - bool& backward) + TextClusterFlags& cluster_flags) { int num_glyphs = -1; int num_clusters = -1; @@ -129,7 +129,7 @@ ScaledFont::text_to_glyphs (double x, &num_glyphs, &c_clusters, &num_clusters, - reinterpret_cast<cairo_bool_t*>(&backward)); + reinterpret_cast<cairo_text_cluster_flags_t*>(&cluster_flags)); if (num_glyphs > 0 && c_glyphs) { glyphs.assign(static_cast<Glyph*>(c_glyphs), static_cast<Glyph*>(c_glyphs + num_glyphs)); diff --git a/cairomm/scaledfont.h b/cairomm/scaledfont.h index 2bf473a..87b433b 100644 --- a/cairomm/scaledfont.h +++ b/cairomm/scaledfont.h @@ -181,12 +181,12 @@ public: * @param utf8 a string of text encoded in UTF-8. * @param glyphs pointer to array of glyphs to fill. * @param clusters pointer to array of cluster mapping information to fill. - * @backward whether the text to glyphs mapping goes backward. + * @cluster_flags cluster mapping flags * * Converts UTF-8 text to an array of glyphs, with cluster mapping, that can be * used to render later. * - * For details of how (@a clusters and @a backward map input + * For details of how (@a clusters and @a cluster_flags map input * UTF-8 text to the output glyphs see Context::show_text_glyphs(). * * The output values can be readily passed to Context::show_text_glyphs() @@ -200,7 +200,7 @@ public: const std::string& utf8, std::vector<Glyph>& glyphs, std::vector<TextCluster>& clusters, - bool& backward); + TextClusterFlags& cluster_flags); /** Stores the scale matrix of this scaled font into matrix. The scale matrix * is product of the font matrix and the ctm associated with the scaled font, diff --git a/cairomm/surface.cc b/cairomm/surface.cc index dba1df7..eb527e6 100644 --- a/cairomm/surface.cc +++ b/cairomm/surface.cc @@ -169,6 +169,15 @@ void Surface::show_page() check_object_status_and_throw_exception(*this); } +bool Surface::has_show_text_glyphs() const +{ + bool result = cairo_surface_has_show_text_glyphs(const_cast<cairo_surface_t*>(cobj())); + check_object_status_and_throw_exception(*this); + return result; +} + + + #ifdef CAIRO_HAS_PNG_FUNCTIONS void Surface::write_to_png(const std::string& filename) { diff --git a/cairomm/surface.h b/cairomm/surface.h index e66d6b2..f3d316f 100644 --- a/cairomm/surface.h +++ b/cairomm/surface.h @@ -215,6 +215,20 @@ public: */ void show_page(); + /** Returns whether the surface supports sophisticated + * Context::show_text_glyphs() operations. That is, whether it actually uses + * the provided text and cluster data to a Context::show_text_glyphs() call. + * + * Note: Even if this function returns %FALSE, a Context::show_text_glyphs() + * operation targeted at this surface will still succeed. It just will act + * like a Context::show_glyphs() operation. Users can use this function to + * avoid computing UTF-8 text and cluster mapping if the target surface does + * not use it. + * + * @since 1.8 + **/ + bool has_show_text_glyphs() const; + #ifdef CAIRO_HAS_PNG_FUNCTIONS /** Writes the contents of surface to a new file filename as a PNG image. diff --git a/tests/test-context.cc b/tests/test-context.cc index fee9565..471581d 100644 --- a/tests/test-context.cc +++ b/tests/test-context.cc @@ -352,18 +352,6 @@ void test_font_options() BOOST_CHECK(options == other); } -void test_show_text_glyphs() -{ - // image surface doesn't support show_text_glyphs - Cairo::RefPtr<Cairo::Surface> surf = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 10, 10); \ - Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surf); - BOOST_CHECK(!cr->has_show_text_glyphs()); - // but pdf surface should - surf = Cairo::PdfSurface::create("test.pdf", 10.0, 10.0); - cr = Cairo::Context::create(surf); - BOOST_CHECK(cr->has_show_text_glyphs()); -} - test_suite* init_unit_test_suite(int argc, char* argv[]) { @@ -391,7 +379,6 @@ init_unit_test_suite(int argc, char* argv[]) test->add (BOOST_TEST_CASE (&test_target)); test->add (BOOST_TEST_CASE (&test_scaled_font)); test->add (BOOST_TEST_CASE (&test_font_options)); - test->add (BOOST_TEST_CASE (&test_show_text_glyphs)); return test; } diff --git a/tests/test-font-face.cc b/tests/test-font-face.cc index 57a4a99..0ebe91e 100644 --- a/tests/test-font-face.cc +++ b/tests/test-font-face.cc @@ -75,7 +75,7 @@ Cairo::ErrorStatus my_render_glyph(const Cairo::RefPtr<Cairo::ScaledFont>&, unsi } static unsigned int text_to_glyphs_call_count = 0; -Cairo::ErrorStatus my_text_to_glyphs(const Cairo::RefPtr<Cairo::ScaledFont>&, const std::string& utf8, std::vector<Cairo::Glyph>& glyphs, std::vector<Cairo::TextCluster>& /*clusters*/, bool& /*backward*/) +Cairo::ErrorStatus my_text_to_glyphs(const Cairo::RefPtr<Cairo::ScaledFont>&, const std::string& utf8, std::vector<Cairo::Glyph>& glyphs, std::vector<Cairo::TextCluster>& /*clusters*/, Cairo::TextClusterFlags& /*cluster_flags*/) { text_to_glyphs_call_count++; if (glyphs.size()) diff --git a/tests/test-font-options.cc b/tests/test-font-options.cc index 25a0cda..a6690f8 100644 --- a/tests/test-font-options.cc +++ b/tests/test-font-options.cc @@ -7,19 +7,31 @@ using namespace boost::unit_test; using namespace Cairo; -void test_lcd_filter() +void test_excercise() { - FontOptions fo; - fo.set_lcd_filter(LCD_FILTER_DEFAULT); - BOOST_CHECK_EQUAL(fo.get_lcd_filter(), LCD_FILTER_DEFAULT); - fo.set_lcd_filter(LCD_FILTER_NONE); - BOOST_CHECK_EQUAL(fo.get_lcd_filter(), LCD_FILTER_NONE); - fo.set_lcd_filter(LCD_FILTER_INTRA_PIXEL); - BOOST_CHECK_EQUAL(fo.get_lcd_filter(), LCD_FILTER_INTRA_PIXEL); - fo.set_lcd_filter(LCD_FILTER_FIR3); - BOOST_CHECK_EQUAL(fo.get_lcd_filter(), LCD_FILTER_FIR3); - fo.set_lcd_filter(LCD_FILTER_FIR5); - BOOST_CHECK_EQUAL(fo.get_lcd_filter(), LCD_FILTER_FIR5); + // just excercise all of the methods + Cairo::FontOptions options; + + Cairo::FontOptions other; + options.merge(other); + + options.hash(); + + options.set_antialias(Cairo::ANTIALIAS_SUBPIXEL); + Cairo::Antialias antialias = options.get_antialias(); + BOOST_CHECK_EQUAL(Cairo::ANTIALIAS_SUBPIXEL, antialias); + + options.set_subpixel_order(Cairo::SUBPIXEL_ORDER_DEFAULT); + Cairo::SubpixelOrder order = options.get_subpixel_order(); + BOOST_CHECK_EQUAL(Cairo::SUBPIXEL_ORDER_DEFAULT, order); + + options.set_hint_style(Cairo::HINT_STYLE_SLIGHT); + Cairo::HintStyle hint_style = options.get_hint_style(); + BOOST_CHECK_EQUAL(Cairo::HINT_STYLE_SLIGHT, hint_style); + + options.set_hint_metrics(Cairo::HINT_METRICS_OFF); + Cairo::HintMetrics metrics = options.get_hint_metrics(); + BOOST_CHECK_EQUAL(Cairo::HINT_METRICS_OFF, metrics); } test_suite* @@ -30,7 +42,7 @@ init_unit_test_suite(int argc, char* argv[]) test_suite* test= BOOST_TEST_SUITE( "Cairo::Context Tests" ); - test->add (BOOST_TEST_CASE (&test_lcd_filter)); + test->add (BOOST_TEST_CASE (&test_excercise)); return test; } diff --git a/tests/test-scaled-font.cc b/tests/test-scaled-font.cc index 2bb5e69..62bbd6e 100644 --- a/tests/test-scaled-font.cc +++ b/tests/test-scaled-font.cc @@ -29,8 +29,8 @@ void test_text_to_glyphs() std::vector<Glyph> glyphs; std::vector<TextCluster> clusters; - bool backwards = false; - font->text_to_glyphs(0, 0, "foo", glyphs, clusters, backwards); + TextClusterFlags flags; + font->text_to_glyphs(0, 0, "foo", glyphs, clusters, flags); BOOST_CHECK_EQUAL(3, glyphs.size()); BOOST_CHECK_EQUAL(3, clusters.size()); diff --git a/tests/test-surface.cc b/tests/test-surface.cc index 3a5e6ae..c1654ca 100644 --- a/tests/test-surface.cc +++ b/tests/test-surface.cc @@ -114,6 +114,16 @@ void test_fallback_resolution() BOOST_CHECK_EQUAL(y, new_y); } +void test_show_text_glyphs() +{ + // image surface doesn't support show_text_glyphs + Cairo::RefPtr<Cairo::Surface> surf = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 10, 10); \ + BOOST_CHECK(!surf->has_show_text_glyphs()); + // but pdf surface should + surf = Cairo::PdfSurface::create("test.pdf", 10.0, 10.0); + BOOST_CHECK(surf->has_show_text_glyphs()); +} + test_suite* init_unit_test_suite(int argc, char* argv[]) @@ -130,6 +140,7 @@ init_unit_test_suite(int argc, char* argv[]) test->add (BOOST_TEST_CASE (&test_create_from_png)); test->add (BOOST_TEST_CASE (&test_ps_eps)); test->add (BOOST_TEST_CASE (&test_content)); + test->add (BOOST_TEST_CASE (&test_show_text_glyphs)); return test; } |