diff options
author | Jonathon Jongsma <jonathon.jongsma@collabora.co.uk> | 2008-08-14 09:59:13 -0500 |
---|---|---|
committer | Jonathon Jongsma <jonathon.jongsma@collabora.co.uk> | 2008-08-14 09:59:13 -0500 |
commit | fdda3cf2c56d8b06a89a4233166dd27c8ec9fa2e (patch) | |
tree | 573dea55bb01c61cc49da83c23787442940c3640 | |
parent | c8f07e579c84af18b93f504614f7c903afe4749d (diff) |
Implement the ToyFontFace class
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | cairomm/fontface.cc | 32 | ||||
-rw-r--r-- | cairomm/fontface.h | 15 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | examples/Makefile.am | 2 | ||||
-rw-r--r-- | examples/text-rotate/.cvsignore | 6 | ||||
-rw-r--r-- | examples/text/Makefile.am (renamed from examples/text-rotate/Makefile.am) | 6 | ||||
-rw-r--r-- | examples/text/text-rotate.cc (renamed from examples/text-rotate/text-rotate.cc) | 0 | ||||
-rw-r--r-- | examples/text/toy-text.cc | 35 | ||||
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/test-font-face.cc | 52 |
12 files changed, 162 insertions, 13 deletions
@@ -31,9 +31,13 @@ examples/pdf-surface/example_pdf_file examples/png_file/example_png_file examples/ps-surface/example_ps_file examples/svg-surface/example_svg_file -examples/text-rotate/text_rotate +examples/text/text_rotate +examples/text/toy-text tests/test-context +tests/test-font-face cairomm/cairommconfig.h* cairomm/stamp-* m4/libtool.m4 m4/lt*.m4 +releases/ +tags @@ -1,5 +1,19 @@ 2008-08-14 Jonathon Jongsma <jjongsma@gnome.org> + * .gitignore: added new files to ignore + * cairomm/fontface.cc: + * cairomm/fontface.h: implement the ToyFontFace class + * configure.in: + * examples/Makefile.am: + * examples/text/Makefile.am: Renamed from examples/text-rotate/Makefile.am. + * examples/text/text-rotate.cc: Renamed from examples/text-rotate/text-rotate.cc. + * examples/text/toy-text.cc: Added. + * tests/Makefile.am: + * tests/test-font-face.cc: Added. excercise the functionality of + ToyFontFace slightly + +2008-08-14 Jonathon Jongsma <jjongsma@gnome.org> + * m4/ax_boost_test_exec_monitor.m4: added this file which was forgotten earlier. I'm not entirely sure if it's necessary, but just in case... diff --git a/cairomm/fontface.cc b/cairomm/fontface.cc index 0e1642a..f7cf8cd 100644 --- a/cairomm/fontface.cc +++ b/cairomm/fontface.cc @@ -69,6 +69,38 @@ FontType FontFace::get_type() const return static_cast<FontType>(font_type); } +// 'Toy' fonts +RefPtr<ToyFontFace> +ToyFontFace::create(const std::string& family, FontSlant slant, FontWeight weight) +{ + return RefPtr<ToyFontFace>(new ToyFontFace(family, slant, weight)); +} + +ToyFontFace::ToyFontFace(const std::string& family, FontSlant slant, FontWeight weight) : + FontFace(cairo_toy_font_face_create (family.c_str(), + static_cast<cairo_font_slant_t>(slant), + static_cast<cairo_font_weight_t>(weight)), + true /* has reference*/) +{ + check_status_and_throw_exception(cairo_font_face_status(m_cobject)); +} + +std::string ToyFontFace::get_family() const +{ + return std::string(cairo_toy_font_face_get_family(m_cobject)); +} + +FontSlant ToyFontFace::get_slant() const +{ + return FontSlant(cairo_toy_font_face_get_slant(m_cobject)); +} + +FontWeight ToyFontFace::get_weight() const +{ + return FontWeight(cairo_toy_font_face_get_weight(m_cobject)); +} + + } //namespace Cairo // vim: ts=2 sw=2 et diff --git a/cairomm/fontface.h b/cairomm/fontface.h index 612820c..ed6da61 100644 --- a/cairomm/fontface.h +++ b/cairomm/fontface.h @@ -19,7 +19,9 @@ #ifndef __CAIROMM_FONTFACE_H #define __CAIROMM_FONTFACE_H +#include <string> #include <cairomm/enums.h> +#include <cairomm/refptr.h> #include <cairo.h> @@ -72,6 +74,19 @@ protected: cobject* m_cobject; }; + +class ToyFontFace : public FontFace +{ +public: + static RefPtr<ToyFontFace> create(const std::string& family, FontSlant slant, FontWeight weight); + std::string get_family() const; + FontSlant get_slant() const; + FontWeight get_weight() const; + +protected: + ToyFontFace(const std::string& family, FontSlant slant, FontWeight weight); +}; + } // namespace Cairo #endif //__CAIROMM_FONTFACE_H diff --git a/configure.in b/configure.in index a59bcec..6392656 100644 --- a/configure.in +++ b/configure.in @@ -195,7 +195,7 @@ AC_CONFIG_FILES( examples/pdf-surface/Makefile examples/ps-surface/Makefile examples/svg-surface/Makefile - examples/text-rotate/Makefile + examples/text/Makefile tests/Makefile diff --git a/examples/Makefile.am b/examples/Makefile.am index 0c42e94..b361432 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,3 +1,3 @@ -SUBDIRS = png_file pdf-surface ps-surface svg-surface text-rotate +SUBDIRS = png_file pdf-surface ps-surface svg-surface text EXTRA_DIST = README Makefile.am_fragment diff --git a/examples/text-rotate/.cvsignore b/examples/text-rotate/.cvsignore deleted file mode 100644 index c64b95d..0000000 --- a/examples/text-rotate/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -text_rotate -text-rotate.png diff --git a/examples/text-rotate/Makefile.am b/examples/text/Makefile.am index 9809f5f..adb68b0 100644 --- a/examples/text-rotate/Makefile.am +++ b/examples/text/Makefile.am @@ -1,7 +1,9 @@ include $(top_srcdir)/examples/Makefile.am_fragment # build the executable but don't install it -noinst_PROGRAMS = text_rotate +noinst_PROGRAMS = text_rotate toy-text + text_rotate_SOURCES = text-rotate.cc +toy_text_SOURCES=toy-text.cc -CLEANFILES = text-rotate.png +CLEANFILES = text-rotate.png toy-text.png diff --git a/examples/text-rotate/text-rotate.cc b/examples/text/text-rotate.cc index 4a78829..4a78829 100644 --- a/examples/text-rotate/text-rotate.cc +++ b/examples/text/text-rotate.cc diff --git a/examples/text/toy-text.cc b/examples/text/toy-text.cc new file mode 100644 index 0000000..1f22521 --- /dev/null +++ b/examples/text/toy-text.cc @@ -0,0 +1,35 @@ +#include <cairomm/cairomm.h> + +const double HEIGHT = 200.0; +const double WIDTH = 400.0; +const double FONT_SIZE = 64.0; +const double TEXT_ORIGIN_Y = (HEIGHT / 2.0) + (FONT_SIZE / 2.0); +const double TEXT_ORIGIN_X = 50.0; // arbitrary + +int main(int, char**) +{ + Cairo::RefPtr<Cairo::ImageSurface> surface = + Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, WIDTH, HEIGHT); + Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); + // fill background in white + cr->set_source_rgb(1.0, 1.0, 1.0); + cr->paint(); + + // draw a little dot at the point where text will be drawn + cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2*M_PI); + cr->set_source_rgba(0.0, 1.0, 0.0, 0.5); + cr->fill(); + + // draw the text + cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y); + cr->set_source_rgb(0.8, 0.2, 0.2); + Cairo::RefPtr<Cairo::ToyFontFace> font = + Cairo::ToyFontFace::create("Bitstream Charter", + Cairo::FONT_SLANT_ITALIC, + Cairo::FONT_WEIGHT_BOLD); + cr->set_font_face(font); + cr->set_font_size(FONT_SIZE); + cr->show_text("cairomm!"); + surface->write_to_png("toy-text.png"); + return 0; +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 7f69eb0..03e58a0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,9 +1,10 @@ if AUTOTESTS # build automated 'tests' -noinst_PROGRAMS = test-context +TESTS=test-context test-font-face +noinst_PROGRAMS = $(TESTS) test_context_SOURCES=test-context.cc -TESTS=test-context +test_font_face_SOURCES=test-font-face.cc else diff --git a/tests/test-font-face.cc b/tests/test-font-face.cc new file mode 100644 index 0000000..973f956 --- /dev/null +++ b/tests/test-font-face.cc @@ -0,0 +1,52 @@ +// vim: ts=2 sw=2 et +/* + * These tests are of limited usefulness. In fact, you might even say that + * they're not really tests at all. But I felt that it would be useful to have + * some basic usage of most functions just to verify that things compile and + * work generally + */ + +#include <cfloat> +#include <boost/test/unit_test.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/test/floating_point_comparison.hpp> +using namespace boost::unit_test; +#include <cairomm/fontface.h> + +void +test_create_toy () +{ + Cairo::RefPtr<Cairo::ToyFontFace> toy = + Cairo::ToyFontFace::create("sans", + Cairo::FONT_SLANT_ITALIC, + Cairo::FONT_WEIGHT_NORMAL); + BOOST_CHECK (toy); + BOOST_CHECK_EQUAL (CAIRO_STATUS_SUCCESS, toy->get_status()); +} + +void test_toy_getters () +{ + Cairo::RefPtr<Cairo::ToyFontFace> toy = + Cairo::ToyFontFace::create("sans", + Cairo::FONT_SLANT_ITALIC, + Cairo::FONT_WEIGHT_NORMAL); + BOOST_CHECK_EQUAL ("sans", toy->get_family()); + BOOST_CHECK_EQUAL (Cairo::FONT_SLANT_ITALIC, toy->get_slant()); + BOOST_CHECK_EQUAL (Cairo::FONT_WEIGHT_NORMAL, toy->get_weight()); + BOOST_CHECK_EQUAL (Cairo::FONT_TYPE_TOY, toy->get_type()); +} + + +test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + // compile even with -Werror + if (argc && argv) {} + + test_suite* test= BOOST_TEST_SUITE( "Cairo::FontFace Tests" ); + + test->add (BOOST_TEST_CASE (&test_create_toy)); + test->add (BOOST_TEST_CASE (&test_toy_getters)); + + return test; +} |