From: <sm...@us...> - 2008-05-21 18:38:19
|
Revision: 8418 http://plplot.svn.sourceforge.net/plplot/?rev=8418&view=rev Author: smekal Date: 2008-05-21 11:38:20 -0700 (Wed, 21 May 2008) Log Message: ----------- Added method ProcessString which takes care of printing text to the canvas. For the DC backend it's partly implemented, the other backends will be based on this code. The code compiles for Visual C++, wxMSW 2.8.7 but may fail on any other combination. Modified Paths: -------------- trunk/drivers/wxwidgets.cpp trunk/drivers/wxwidgets.h trunk/drivers/wxwidgets_agg.cpp trunk/drivers/wxwidgets_dc.cpp trunk/drivers/wxwidgets_gc.cpp Modified: trunk/drivers/wxwidgets.cpp =================================================================== --- trunk/drivers/wxwidgets.cpp 2008-05-21 17:32:24 UTC (rev 8417) +++ trunk/drivers/wxwidgets.cpp 2008-05-21 18:38:20 UTC (rev 8418) @@ -173,7 +173,6 @@ clipminy=800; clipmaxy=0; - antialized=0; freetype=0; smooth_text=0; @@ -209,7 +208,6 @@ /* default options */ static int freetype=1; static int smooth_text=1; - static int antialized=0; static int backend=0; DrvOpt wx_options[] = { @@ -217,9 +215,6 @@ {"text", DRV_INT, &freetype, "Use driver text (FreeType)"}, {"smooth", DRV_INT, &smooth_text, "Turn text smoothing on (1) or off (0)"}, #endif -#ifdef HAVE_AGG - {"antialized", DRV_INT, &antialized, "Turn antializing on (1) or off (0)"}, -#endif {"backend", DRV_INT, &backend, "Choose backend: (0) standard, (1) using AGG library, (2) using wxGraphicsContext"}, {NULL, DRV_INT, NULL, NULL}}; @@ -229,9 +224,6 @@ dev->smooth_text=smooth_text; dev->freetype=freetype; #endif -#ifdef HAVE_AGG - dev->antialized=antialized; -#endif /* allocate memory for the device storage */ switch( backend ) @@ -274,6 +266,8 @@ pls->graphx = GRAPHICS_MODE; /* No text mode for this driver (at least for now, might add a console window if I ever figure it out and have the inclination) */ pls->dev_clear = 1; /* driver supports clear */ + pls->dev_text = 1; /* want to draw text */ + pls->dev_unicode = 1; /* want unicode */ #ifdef HAVE_FREETYPE if( freetype ) { pls->dev_text = 1; /* want to draw text */ @@ -563,11 +557,12 @@ plD_bop_wxwidgets( pls ); break; -#ifdef HAVE_FREETYPE case PLESC_HAS_TEXT: + dev->ProcessString( pls, (EscText *)ptr ); +#ifdef HAVE_FREETYPE plD_render_freetype_text( pls, (EscText *)ptr ); - break; #endif + break; case PLESC_RESIZE: { wxSize* size=(wxSize*)ptr; @@ -816,17 +811,11 @@ * See if we have a 24 bit device (or better), in which case * we can use the better antialising. */ - if( dev->antialized ) { - FT->BLENDED_ANTIALIASING=1; - FT->read_pixel= (plD_read_pixel_fp)plD_read_pixel_wxwidgets; - FT->set_pixel= (plD_set_pixel_fp)plD_set_pixel_wxwidgets; - } else { - // the bitmap we are using in the antialized case has always - // 32 bit depth - FT->BLENDED_ANTIALIASING=1; - FT->read_pixel= (plD_read_pixel_fp)plD_read_pixel_wxwidgets; - FT->set_pixel= (plD_set_pixel_fp)plD_set_pixel_wxwidgets; - } + // the bitmap we are using in the antialized case has always + // 32 bit depth + FT->BLENDED_ANTIALIASING=1; + FT->read_pixel= (plD_read_pixel_fp)plD_read_pixel_wxwidgets; + FT->set_pixel= (plD_set_pixel_fp)plD_set_pixel_wxwidgets; } Modified: trunk/drivers/wxwidgets.h =================================================================== --- trunk/drivers/wxwidgets.h 2008-05-21 17:32:24 UTC (rev 8417) +++ trunk/drivers/wxwidgets.h 2008-05-21 18:38:20 UTC (rev 8418) @@ -103,6 +103,7 @@ virtual void PutPixel( short x, short y, PLINT color )=0; virtual void PutPixel( short x, short y )=0; virtual PLINT GetPixel( short x, short y )=0; + virtual void ProcessString( PLStream* pls, EscText* args )=0; public: /* variables */ bool ready; @@ -141,7 +142,6 @@ bool newclipregion; /* variables for antializing */ - int antialized; int freetype; int smooth_text; @@ -169,6 +169,7 @@ void PutPixel( short x, short y, PLINT color ); void PutPixel( short x, short y ); PLINT GetPixel( short x, short y ); + void ProcessString( PLStream* pls, EscText* args ); private: /* variables */ wxBitmap* m_bitmap; @@ -206,6 +207,7 @@ void PutPixel( short x, short y, PLINT color ); void PutPixel( short x, short y ); PLINT GetPixel( short x, short y ); + void ProcessString( PLStream* pls, EscText* args ); private: /* variables */ wxImage* m_buffer; @@ -242,6 +244,7 @@ void PutPixel( short x, short y, PLINT color ); void PutPixel( short x, short y ); PLINT GetPixel( short x, short y ); + void ProcessString( PLStream* pls, EscText* args ); private: /* variables */ wxBitmap* m_bitmap; Modified: trunk/drivers/wxwidgets_agg.cpp =================================================================== --- trunk/drivers/wxwidgets_agg.cpp 2008-05-21 17:32:24 UTC (rev 8417) +++ trunk/drivers/wxwidgets_agg.cpp 2008-05-21 18:38:20 UTC (rev 8418) @@ -204,9 +204,12 @@ * Adds a dc to the stream. The associated device is attached to the canvas * as the property "dev". \*--------------------------------------------------------------------------*/ -void wxPLDevAGG::SetExternalBuffer( void* buffer ) +void wxPLDevAGG::SetExternalBuffer( void* dc ) { - m_buffer = (wxImage*)buffer; + m_dc=(wxDC*)dc; /* Add the dc to the device */ + if( m_buffer ) + delete m_buffer; + m_buffer = new wxImage( width, height ); if( m_rendering_buffer ) delete m_rendering_buffer; m_rendering_buffer = new agg::rendering_buffer; @@ -231,4 +234,8 @@ return RGB( m_buffer->GetRed( x, y ), m_buffer->GetGreen( x, y ), m_buffer->GetBlue( x, y ) ); } +void wxPLDevAGG::ProcessString( PLStream* pls, EscText* args ) +{ +} + #endif /* PLD_wxwidgets */ Modified: trunk/drivers/wxwidgets_dc.cpp =================================================================== --- trunk/drivers/wxwidgets_dc.cpp 2008-05-21 17:32:24 UTC (rev 8417) +++ trunk/drivers/wxwidgets_dc.cpp 2008-05-21 18:38:20 UTC (rev 8418) @@ -6,6 +6,41 @@ /* plplot headers */ #include "plplotP.h" +/*--------------------------------------------------------------------- + Font style and weight lookup tables (copied + from the cairo driver). + ---------------------------------------------------------------------*/ +#define NPANGOLOOKUP 5 + +const char *defaultFamilyLookup[NPANGOLOOKUP] = { + "sans", + "serif", + "monospace", + "sans,serif", + "sans,serif" +}; + +const char *envFamilyLookup[NPANGOLOOKUP] = { + "PLPLOT_FREETYPE_SANS_FAMILY", + "PLPLOT_FREETYPE_SERIF_FAMILY", + "PLPLOT_FREETYPE_MONO_FAMILY", + "PLPLOT_FREETYPE_SCRIPT_FAMILY", + "PLPLOT_FREETYPE_SYMBOL_FAMILY" +}; + +char familyLookup[NPANGOLOOKUP][1024]; + +const char *weightLookup[2] = { + "normal", + "bold" +}; + +const char *styleLookup[3] = { + "normal", + "italic", + "oblique" +}; + /* os specific headers */ #ifdef __WIN32__ #include <windows.h> @@ -173,6 +208,90 @@ #endif } + +void wxPLDevDC::ProcessString( PLStream* pls, EscText* args ) +{ + const int max_string_length=500; + + /* Check that we got unicode, warning message and return if not */ + if( args->unicode_array_len == 0 ) { + printf( "Non unicode string passed to a cairo driver, ignoring\n" ); + return; + } + + /* Check that unicode string isn't longer then the max we allow */ + if( args->unicode_array_len >= max_string_length ) { + printf( "Sorry, the cairo drivers only handles strings of length < %d\n", max_string_length ); + return; + } + + /* Calculate the font size (in pixels) */ + float fontSize = pls->chrht * DEVICE_PIXELS_PER_MM; + + /* Set font color */ + m_dc->SetTextForeground( wxColour(pls->cmap0[pls->icol0].r, pls->cmap0[pls->icol0].g, + pls->cmap0[pls->icol0].b)); + m_dc->SetTextBackground( wxColour(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b) ); + + char plplotEsc; + int upDown = 0; + PLUNICODE fci; + char utf8[5]; + char utf8_string[max_string_length]; + memset( utf8_string, '\0', max_string_length ); + + /* Get PLplot escape character */ + plgesc( &plplotEsc ); + + /* Get the curent font */ + plgfci( &fci ); + + /* Parse the string to generate the tags */ + PLUNICODE *ucs4 = args->unicode_array; + int ucs4Len = args->unicode_array_len; + int i = 0; + while( i < ucs4Len ) { + if( ucs4[i] < PL_FCI_MARK ) { /* not a font change */ + if( ucs4[i] != (PLUNICODE)plplotEsc ) { /* a character to display */ + ucs4_to_utf8( ucs4[i], utf8 ); + strcat( utf8_string, utf8 ); + i++; + continue; + } + i++; + if( ucs4[i] == (PLUNICODE)plplotEsc ) { /* a escape character to display */ + ucs4_to_utf8( ucs4[i], utf8 ); + strcat( utf8_string, utf8 ); + i++; + continue; + } else { + if( ucs4[i] == (PLUNICODE)'u' ) { /* Superscript */ + // TODO: superscript + upDown++; + } + if( ucs4[i] == (PLUNICODE)'d' ){ /* Subscript */ + // TODO: subscript + upDown--; + } + i++; + } + } else { /* a font change */ + // TODO: font change + i++; + } + } + + wxString str(wxConvUTF8.cMB2WC(utf8_string), *wxConvCurrent); + + m_dc->SetFont( wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL) ); + m_dc->DrawText( str, args->x/scalex, args->y/scaley ); + + if( !resizing && ownGUI ) + AddtoClipRegion( this, 0, 0, width, height ); + + //Log_Debug( "utf8_string=%s, x=%f, y=%f", utf8_string, args->x/scalex, args->y/scaley ); +} + #endif /* PLD_wxwidgets */ Modified: trunk/drivers/wxwidgets_gc.cpp =================================================================== --- trunk/drivers/wxwidgets_gc.cpp 2008-05-21 17:32:24 UTC (rev 8417) +++ trunk/drivers/wxwidgets_gc.cpp 2008-05-21 18:38:20 UTC (rev 8418) @@ -233,6 +233,10 @@ #endif } +void wxPLDevGC::ProcessString( PLStream* pls, EscText* args ) +{ +} + #endif #endif /* PLD_wxwidgets */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |