diff --git a/tests/Makefile.in b/tests/Makefile.in index d3a512dfa5..062cfc5002 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -150,7 +150,8 @@ TEST_DRAWING_OBJECTS = \ test_drawing_test.o \ test_drawing_drawing.o \ test_drawing_plugindriver.o \ - test_drawing_basictest.o + test_drawing_basictest.o \ + test_drawing_fonttest.o TEST_DRAWING_ODEP = \ $(_____pch_testprec_test_drawing_testprec_h_gch___depname) TEST_DRAWINGPLUGIN_CXXFLAGS = -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \ @@ -755,6 +756,9 @@ test_drawing_plugindriver.o: $(srcdir)/drawing/plugindriver.cpp $(TEST_DRAWING_O test_drawing_basictest.o: $(srcdir)/drawing/basictest.cpp $(TEST_DRAWING_ODEP) $(CXXC) -c -o $@ $(TEST_DRAWING_CXXFLAGS) $(srcdir)/drawing/basictest.cpp +test_drawing_fonttest.o: $(srcdir)/drawing/fonttest.cpp $(TEST_DRAWING_ODEP) + $(CXXC) -c -o $@ $(TEST_DRAWING_CXXFLAGS) $(srcdir)/drawing/fonttest.cpp + test_drawingplugin_pluginsample.o: $(srcdir)/drawing/pluginsample.cpp $(CXXC) -c -o $@ $(TEST_DRAWINGPLUGIN_CXXFLAGS) $(srcdir)/drawing/pluginsample.cpp diff --git a/tests/drawing/drawing.h b/tests/drawing/drawing.h index 6719cbe899..bc04a0d258 100644 --- a/tests/drawing/drawing.h +++ b/tests/drawing/drawing.h @@ -13,6 +13,8 @@ #if wxUSE_TEST_GC_DRAWING +#include "wx/math.h" + #if wxUSE_SVG #include "wx/dcsvg.h" #endif @@ -43,6 +45,17 @@ private: // CPPUNIT_TEST( DrawToSVG_Basics ); #endif CPPUNIT_TEST( DrawToPlugins_Basics ); + + // FIXME: Reference data files are currently not found when using Unix + // build system, so these tests are failing there, fix this and remove + // this ifdef. +#ifdef __WINDOWS__ + CPPUNIT_TEST( DrawToImage_Fonts ); +#if wxUSE_SVG +// CPPUNIT_TEST( DrawToSVG_Fonts ); +#endif + CPPUNIT_TEST( DrawToPlugins_Fonts ); +#endif // __WINDOWS__ CPPUNIT_TEST_SUITE_END(); class ImageGraphicsContextLifeCycle: public DrawingTestGCFactory @@ -99,9 +112,11 @@ private: // test cases static const DrawingTestCase ms_drawingBasicTc; + static const DrawingTestCase ms_drawingFontTc; // cases functions void DoBasicDrawings (wxGraphicsContext *gc); + void DoFontDrawings (wxGraphicsContext *gc); void RunIndividualDrawingCase ( DrawingTestGCFactory& gcFactory, @@ -127,6 +142,17 @@ private: void DrawToPlugins_Basics() { RunPluginsDrawingCase (ms_drawingBasicTc); } + void DrawToImage_Fonts() { + RunIndividualDrawingCase (ms_imageLifeCycle, ms_drawingFontTc); + } +#if wxUSE_SVG + void DrawToSVG_Fonts() { + RunIndividualDrawingCase (ms_svgLifeCycle, ms_drawingFontTc); + } +#endif + void DrawToPlugins_Fonts() { + RunPluginsDrawingCase (ms_drawingFontTc); + } bool GetBuildReference() const; diff --git a/tests/drawing/fonttest.cpp b/tests/drawing/fonttest.cpp new file mode 100644 index 0000000000..c7c0a0457d --- /dev/null +++ b/tests/drawing/fonttest.cpp @@ -0,0 +1,115 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/drawing/basictest.cpp +// Purpose: Basic tests for wxGraphicsContext +// Author: Armel Asselin +// Created: 2014-02-28 +// Copyright: (c) 2014 ElliƩ Computing +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/font.h" +#endif // WX_PRECOMP + +#include "drawing.h" + +#ifdef __WXGTK__ +#include "glib-object.h" +#endif + +#if wxUSE_TEST_GC_DRAWING + +const GraphicsContextDrawingTestCase::DrawingTestCase +GraphicsContextDrawingTestCase::ms_drawingFontTc = { + 2, &GraphicsContextDrawingTestCase::DoFontDrawings, 800, 600, 72., false +}; + +void GraphicsContextDrawingTestCase::DoFontDrawings (wxGraphicsContext *gc) +{ +#ifdef __WXGTK__ + g_type_init(); +#endif + + // This test is expected to treat about fonts/texts. Fonts are a bit special + // because we cannot expect the same rendering by several engines, and the + // dimensions of the same text in same font will vary. + + wxGraphicsBrush gbBackground = + gc->CreateBrush( wxBrush ( wxColour ( 240, 240, 240 ) ) ); + + gc->SetBrush( gbBackground ); + gc->DrawRectangle(0, 0, 800, 600); + + wxGraphicsBrush gbTextBackground = + gc->CreateBrush( wxBrush ( wxColour ( 192, 192, 192 ) ) ); + + // set underlined font for testing + gc->SetFont( wxFont(wxFontInfo(12).Family(wxFONTFAMILY_MODERN).Underlined()), *wxBLACK ); + gc->DrawText( wxT("This is text"), 110, 10, gbTextBackground ); + gc->DrawText( wxT("That is text"), 20, 10, wxDegToRad(-45), gbTextBackground ); + + // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated + // under Win9x (it is not TrueType) + gc->SetFont( wxFont(wxFontInfo(12).Family(wxFONTFAMILY_SWISS)), *wxBLACK ); + + wxString text; + + for ( int n = -180; n < 180; n += 30 ) + { + text.Printf(wxT(" %d rotated text"), n); + gc->DrawText(text , 400, 400, wxDegToRad(n) ); + } + + wxFont swissDcFont( wxFontInfo(18).Family(wxFONTFAMILY_SWISS) ); + wxGraphicsFont swissFont = gc->CreateFont( swissDcFont, *wxBLACK ); + gc->SetFont( swissFont ); + + gc->DrawText( wxT("This is Swiss 18pt text."), 110, 40 ); + + wxDouble length; + wxDouble height; + wxDouble descent; + gc->GetTextExtent( wxT("This is Swiss 18pt text."), &length, &height, &descent ); + text.Printf( wxT("Dimensions are length %f, height %f, descent %f"), length, height, descent ); + gc->DrawText( text, 110, 80 ); + + // (did not find equivalent to CharHeight()) + + gc->SetBrush( *wxWHITE_BRUSH ); + + gc->DrawRectangle( 100, 40, 4, height ); + + // test the logical function effect + wxCoord y = 150; + // text drawing should ignore logical function + gc->DrawText( wxT("There should be a text below"), 110, 150 ); + gc->DrawRectangle( 110, y, 100, height ); + + y += height; + gc->DrawText( wxT("Visible text"), 110, y ); + gc->DrawRectangle( 110, y, 100, height ); + gc->DrawText( wxT("Visible text"), 110, y ); + gc->DrawRectangle( 110, y, 100, height ); + + y += height; + gc->DrawRectangle( 110, y, 100, height ); + gc->DrawText( wxT("Another visible text"), 110, y ); + + y += height; + gc->DrawText("And\nmore\ntext on\nmultiple\nlines", 110, y); + y += 5*height; + + gc->SetFont( swissDcFont, *wxBLUE ); + gc->DrawText( "Rotated text\ncan have\nmultiple lines\nas well", 110, y, wxDegToRad(15) ); +} + +#endif // wxUSE_TEST_GC_DRAWING diff --git a/tests/drawing/references/image_test_image_cairo-1.8_2_ref.png b/tests/drawing/references/image_test_image_cairo-1.8_2_ref.png new file mode 100644 index 0000000000..6a1f932a56 Binary files /dev/null and b/tests/drawing/references/image_test_image_cairo-1.8_2_ref.png differ diff --git a/tests/drawing/references/image_test_image_cg-10.5_2_ref.png b/tests/drawing/references/image_test_image_cg-10.5_2_ref.png new file mode 100644 index 0000000000..f0a68eb810 Binary files /dev/null and b/tests/drawing/references/image_test_image_cg-10.5_2_ref.png differ diff --git a/tests/drawing/references/image_test_image_gdiplus-6.1_2_ref.png b/tests/drawing/references/image_test_image_gdiplus-6.1_2_ref.png new file mode 100644 index 0000000000..f24a5601e9 Binary files /dev/null and b/tests/drawing/references/image_test_image_gdiplus-6.1_2_ref.png differ diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 4f67ddc447..cb40018253 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -134,7 +134,8 @@ TEST_DRAWING_OBJECTS = \ $(OBJS)\test_drawing_test.obj \ $(OBJS)\test_drawing_drawing.obj \ $(OBJS)\test_drawing_plugindriver.obj \ - $(OBJS)\test_drawing_basictest.obj + $(OBJS)\test_drawing_basictest.obj \ + $(OBJS)\test_drawing_fonttest.obj TEST_DRAWINGPLUGIN_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include \ $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG_2) -D__WXMSW__ \ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__NDEBUG_DEFINE_p) \ @@ -798,6 +799,9 @@ $(OBJS)\test_drawing_plugindriver.obj: .\drawing\plugindriver.cpp $(OBJS)\test_drawing_basictest.obj: .\drawing\basictest.cpp $(CXX) -q -c -P -o$@ $(TEST_DRAWING_CXXFLAGS) .\drawing\basictest.cpp +$(OBJS)\test_drawing_fonttest.obj: .\drawing\fonttest.cpp + $(CXX) -q -c -P -o$@ $(TEST_DRAWING_CXXFLAGS) .\drawing\fonttest.cpp + $(OBJS)\test_drawingplugin_pluginsample.obj: .\drawing\pluginsample.cpp $(CXX) -q -c -P -o$@ $(TEST_DRAWINGPLUGIN_CXXFLAGS) .\drawing\pluginsample.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 7ec7bd15cc..ecfbd819dd 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -126,7 +126,8 @@ TEST_DRAWING_OBJECTS = \ $(OBJS)\test_drawing_test.o \ $(OBJS)\test_drawing_drawing.o \ $(OBJS)\test_drawing_plugindriver.o \ - $(OBJS)\test_drawing_basictest.o + $(OBJS)\test_drawing_basictest.o \ + $(OBJS)\test_drawing_fonttest.o TEST_DRAWINGPLUGIN_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) \ $(__THREADSFLAG) $(GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ \ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__NDEBUG_DEFINE_p) \ @@ -774,6 +775,9 @@ $(OBJS)\test_drawing_plugindriver.o: ./drawing/plugindriver.cpp $(OBJS)\test_drawing_basictest.o: ./drawing/basictest.cpp $(CXX) -c -o $@ $(TEST_DRAWING_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_drawing_fonttest.o: ./drawing/fonttest.cpp + $(CXX) -c -o $@ $(TEST_DRAWING_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_drawingplugin_pluginsample.o: ./drawing/pluginsample.cpp $(CXX) -c -o $@ $(TEST_DRAWINGPLUGIN_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index f2cdb7f941..d3eaaaa740 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -132,7 +132,8 @@ TEST_DRAWING_OBJECTS = \ $(OBJS)\test_drawing_test.obj \ $(OBJS)\test_drawing_drawing.obj \ $(OBJS)\test_drawing_plugindriver.obj \ - $(OBJS)\test_drawing_basictest.obj + $(OBJS)\test_drawing_basictest.obj \ + $(OBJS)\test_drawing_fonttest.obj TEST_DRAWINGPLUGIN_CXXFLAGS = /M$(__RUNTIME_LIBS_45)$(__DEBUGRUNTIME) /DWIN32 \ $(__DEBUGINFO) /Fd$(OBJS)\test_drawingplugin.pdb $(____DEBUGRUNTIME) \ $(__OPTIMIZEFLAG) /D_CRT_SECURE_NO_DEPRECATE=1 \ @@ -975,6 +976,9 @@ $(OBJS)\test_drawing_plugindriver.obj: .\drawing\plugindriver.cpp $(OBJS)\test_drawing_basictest.obj: .\drawing\basictest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_DRAWING_CXXFLAGS) .\drawing\basictest.cpp +$(OBJS)\test_drawing_fonttest.obj: .\drawing\fonttest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_DRAWING_CXXFLAGS) .\drawing\fonttest.cpp + $(OBJS)\test_drawingplugin_pluginsample.obj: .\drawing\pluginsample.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_DRAWINGPLUGIN_CXXFLAGS) .\drawing\pluginsample.cpp diff --git a/tests/test.bkl b/tests/test.bkl index c38df527ce..f618e50b8c 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -133,6 +133,7 @@ drawing/drawing.cpp drawing/plugindriver.cpp drawing/basictest.cpp + drawing/fonttest.cpp core net diff --git a/tests/test_vc7_test_drawing.vcproj b/tests/test_vc7_test_drawing.vcproj index 09284b6dff..2733b85037 100644 --- a/tests/test_vc7_test_drawing.vcproj +++ b/tests/test_vc7_test_drawing.vcproj @@ -328,6 +328,9 @@ UsePrecompiledHeader="1"/> + + diff --git a/tests/test_vc8_test_drawing.vcproj b/tests/test_vc8_test_drawing.vcproj index 72ffe3a653..fef328990c 100644 --- a/tests/test_vc8_test_drawing.vcproj +++ b/tests/test_vc8_test_drawing.vcproj @@ -473,6 +473,10 @@ /> + + diff --git a/tests/test_vc9_test_drawing.vcproj b/tests/test_vc9_test_drawing.vcproj index 5d23d27d63..df3982e38b 100644 --- a/tests/test_vc9_test_drawing.vcproj +++ b/tests/test_vc9_test_drawing.vcproj @@ -459,6 +459,10 @@ /> + +