Add simple font tests for the drawing unit test.

Check that DrawText() results in the expected output.

Currently the tests are disabled for non-Windows systems because of the
problem with the reference file paths there.

See #16261.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76556 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-05-17 12:29:21 +00:00
parent a380c1e46f
commit 268b33d8a3
13 changed files with 173 additions and 4 deletions

View File

@ -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

View File

@ -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;

115
tests/drawing/fonttest.cpp Normal file
View File

@ -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 <opensource@elliecomputing.com>
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -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

View File

@ -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) $<

View File

@ -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

View File

@ -133,6 +133,7 @@
drawing/drawing.cpp
drawing/plugindriver.cpp
drawing/basictest.cpp
drawing/fonttest.cpp
</sources>
<wx-lib>core</wx-lib>
<wx-lib>net</wx-lib>

View File

@ -328,6 +328,9 @@
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
<File
RelativePath=".\drawing\fonttest.cpp">
</File>
<File
RelativePath=".\drawing\plugindriver.cpp">
</File>

View File

@ -473,6 +473,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\drawing\fonttest.cpp"
>
</File>
<File
RelativePath=".\drawing\plugindriver.cpp"
>

View File

@ -459,6 +459,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\drawing\fonttest.cpp"
>
</File>
<File
RelativePath=".\drawing\plugindriver.cpp"
>