From: <sm...@us...> - 2008-10-24 13:06:04
|
Revision: 8957 http://plplot.svn.sourceforge.net/plplot/?rev=8957&view=rev Author: smekal Date: 2008-10-24 13:05:53 +0000 (Fri, 24 Oct 2008) Log Message: ----------- Scaling of the plplot coordinates to the bitmap is now done with affine transformations. Font processing improved, but still problems with positioning and kerning. Modified Paths: -------------- trunk/drivers/wxwidgets.cpp trunk/drivers/wxwidgets.h trunk/drivers/wxwidgets_agg.cpp Modified: trunk/drivers/wxwidgets.cpp =================================================================== --- trunk/drivers/wxwidgets.cpp 2008-10-23 12:38:21 UTC (rev 8956) +++ trunk/drivers/wxwidgets.cpp 2008-10-24 13:05:53 UTC (rev 8957) @@ -735,9 +735,15 @@ wxPLDevBase* dev = (wxPLDevBase*)pls->dev; - /* set new size */ + /* set new size and scale parameters */ dev->width = width; dev->height = height; + dev->scalex=(PLFLT)(dev->xmax-dev->xmin)/dev->width; + dev->scaley=(PLFLT)(dev->ymax-dev->ymin)/dev->height; + + /* recalculate the dpi used in calculation of fontsize */ + pls->xdpi = VIRTUAL_PIXELS_PER_IN/dev->scalex; + pls->ydpi = VIRTUAL_PIXELS_PER_IN/dev->scaley; /* clear background if we have a dc, since it's invalid (TODO: why, since in bop it must be cleared anyway?) */ @@ -749,13 +755,7 @@ dev->ClearBackground( bgr, bgg, bgb ); } - dev->scalex=(PLFLT)(dev->xmax-dev->xmin)/dev->width; - dev->scaley=(PLFLT)(dev->ymax-dev->ymin)/dev->height; - /* recalculate the dpi used in calculation of fontsize */ - pls->xdpi = VIRTUAL_PIXELS_PER_IN/dev->scalex; - pls->ydpi = VIRTUAL_PIXELS_PER_IN/dev->scaley; - /* freetype parameters must also be changed */ #ifdef HAVE_FREETYPE if( dev->freetype ) { Modified: trunk/drivers/wxwidgets.h =================================================================== --- trunk/drivers/wxwidgets.h 2008-10-23 12:38:21 UTC (rev 8956) +++ trunk/drivers/wxwidgets.h 2008-10-24 13:05:53 UTC (rev 8957) @@ -253,7 +253,8 @@ void PSDrawTextToDC( char* utf8_string, bool drawText ); void PSSetFont( PLUNICODE fci ); void drawPath( drawPathFlag flag ); - + void AGGAddtoClipRegion( short x1, short y1, short x2, short y2 ); + private: /* variables */ wxDC* mDC; wxImage* mBuffer; Modified: trunk/drivers/wxwidgets_agg.cpp =================================================================== --- trunk/drivers/wxwidgets_agg.cpp 2008-10-23 12:38:21 UTC (rev 8956) +++ trunk/drivers/wxwidgets_agg.cpp 2008-10-24 13:05:53 UTC (rev 8957) @@ -92,12 +92,12 @@ /* determine font directory */ #if defined(WIN32) - static char *default_font_names[]={"arial.ttf","times.ttf","timesi.ttf","arial.ttf", + /*static char *default_font_names[]={"arial.ttf","times.ttf","timesi.ttf","arial.ttf", "symbol.ttf"}; char WINDIR_PATH[255]; char *b; b=getenv("WINDIR"); - strcpy(WINDIR_PATH,b); + strcpy(WINDIR_PATH,b);*/ /* * Work out if we have Win95+ or Win3.?... sort of. @@ -106,7 +106,7 @@ * At present, it only looks in two places, on one drive. I might change this * soon. */ - if (WINDIR_PATH==NULL) + /*if (WINDIR_PATH==NULL) { if (access("c:\\windows\\fonts\\arial.ttf", F_OK)==0) { strcpy(font_dir,"c:/windows/fonts/"); @@ -132,7 +132,7 @@ plwarn("Could not find font path; I sure hope you have defined fonts manually !"); } - if (pls->debug) fprintf( stderr, "%s\n", font_dir ) ; + if (pls->debug) fprintf( stderr, "%s\n", font_dir ) ;*/ #else /* For Unix systems, we will set the font path up a little differently in * that the configured PL_FREETYPE_FONT_DIR has been set as the default path, @@ -195,30 +195,25 @@ void wxPLDevAGG::DrawLine( short x1a, short y1a, short x2a, short y2a ) { - x1a=(short)(x1a/scalex); y1a=(short)(height-y1a/scaley); - x2a=(short)(x2a/scalex); y2a=(short)(height-y2a/scaley); - mPath.remove_all(); mPath.move_to( x1a, y1a ); mPath.line_to( x2a, y2a ); + if( !resizing && ownGUI ) + AGGAddtoClipRegion( x1a, y1a, x2a, y2a ); + drawPath( Stroke ); } void wxPLDevAGG::DrawPolyline( short *xa, short *ya, PLINT npts ) { - short x1a, y1a, x2a, y2a; - - x2a=(short)(xa[0]/scalex); y2a=(short)(height-ya[0]/scaley); mPath.remove_all(); - mPath.move_to( x2a, y2a ); + mPath.move_to( xa[0], ya[0] ); for ( PLINT i=1; i<npts; i++ ) { - x1a=x2a; y1a=y2a; - x2a=(short)(xa[i]/scalex); y2a=(short)(height-ya[i]/scaley); - mPath.line_to( x2a, y2a ); + mPath.line_to( xa[i], ya[i] ); if( !resizing && ownGUI ) - AddtoClipRegion( (int)x1a, (int)y1a, (int)x2a, (int)y2a ); + AGGAddtoClipRegion( xa[i-1], ya[i-1], xa[i], ya[i] ); } drawPath( Stroke ); @@ -231,21 +226,29 @@ } +void wxPLDevAGG::AGGAddtoClipRegion( short x1, short y1, short x2, short y2 ) +{ + double x1d=x1, x2d=x2, y1d=y1, y2d=y2; + + mTransform.transform( &x1d, &y1d ); + mTransform.transform( &x2d, &y2d ); + AddtoClipRegion( (int)floor(x1d), (int)floor(y1d), (int)ceil(x2d), (int)ceil(y2d) ); +} + + void wxPLDevAGG::FillPolygon( PLStream *pls ) { - short x1a, y1a, x2a, y2a; + short *xa = pls->dev_x; + short *ya = pls->dev_y; mPath.remove_all(); - x2a=(short)(pls->dev_x[0]/scalex); y2a=(short)(height-pls->dev_y[0]/scaley); - mPath.move_to( x2a, y2a ); + mPath.move_to( xa[0], ya[0] ); for ( PLINT i=1; i<pls->dev_npts; i++ ) { - x1a=x2a; y1a=y2a; - x2a=(short)(pls->dev_x[i]/scalex); y2a=(short)(height-pls->dev_y[i]/scaley); - mPath.line_to( x2a, y2a ); - if( !resizing && ownGUI ) - AddtoClipRegion( (int)x1a, (int)y1a, (int)x2a, (int)y2a ); + mPath.line_to( xa[i], ya[i] ); + if( !resizing && ownGUI ) + AGGAddtoClipRegion( xa[i-1], ya[i-1], xa[i], ya[i] ); } - mPath.line_to( pls->dev_x[0]/scalex, height-pls->dev_y[0]/scaley ); + mPath.line_to( xa[0], ya[0] ); mPath.close_polygon(); drawPath( FillAndStroke ); @@ -277,13 +280,16 @@ mRenderingBuffer.attach( mBuffer->GetData(), width, height, width*3 ); mRendererBase.reset_clipping( true ); - + mTransform.reset(); + mTransform.premultiply( agg::trans_affine_translation(0.0, height) ); + mTransform.premultiply( agg::trans_affine_scaling(1.0/scalex, -1.0/scaley) ); + mStrokeWidth = (scalex+scaley)/2.0; } void wxPLDevAGG::SetWidth( PLStream *pls ) { - mStrokeWidth = pls->width>0 ? pls->width : 1; // TODO: why and when ist width 0??? + mStrokeWidth = (scalex+scaley)/2.0*(pls->width>0 ? pls->width : 1); // TODO: why and when ist width 0??? } @@ -320,6 +326,10 @@ mRenderingBuffer.attach( mBuffer->GetData(), width, height, width*3 ); mRendererBase.reset_clipping( true ); + mTransform.reset(); + mTransform.premultiply( agg::trans_affine_translation(0.0, height) ); + mTransform.premultiply( agg::trans_affine_scaling(1.0/scalex, -1.0/scaley) ); + mStrokeWidth = (scalex+scaley)/2.0; ready = true; ownGUI = false; @@ -364,9 +374,10 @@ for( size_t i=0; i<len && str[i]; i++ ) { glyph = mFontManager.glyph( str[i] ); if( glyph ) { - if( i ) + printf( "before: start_x=%f, start_y=%f\n", start_x, start_y ); + //if( i ) mFontManager.add_kerning( &start_x, &start_y ); - printf( "start_x=%f, start_y=%f\n", start_x, start_y ); + printf( "after: start_x=%f, start_y=%f\n", start_x, start_y ); mFontManager.init_embedded_adaptors( glyph, start_x, start_y ); if( drawText ) { @@ -374,9 +385,10 @@ agg::render_scanlines( mFontManager.gray8_adaptor(), mFontManager.gray8_scanline(), mRendererSolid ); } - textHeight = textHeight>(glyph->bounds.y2-glyph->bounds.y1+yOffset/scaley) ? - textHeight : (glyph->bounds.y2-glyph->bounds.y1+yOffset/scaley); - start_x += glyph->advance_x/64; + textHeight = textHeight>(glyph->bounds.y2-glyph->bounds.y1+yOffset) ? + textHeight : (glyph->bounds.y2-glyph->bounds.y1+yOffset); + start_x += glyph->advance_x/scalex; + //start_y += glyph->advance_y; } } @@ -389,12 +401,12 @@ { /* convert the fci to Base14/Type1 font information */ wxString fontname=fontdir + wxString( plP_FCI2FontName(fci, TrueTypeLookup, N_TrueTypeLookup), *wxConvCurrent ); - printf("fontname=%s\n", fontdir.c_str() ); - mFontEngine.load_font( plP_FCI2FontName(fci, TrueTypeLookup, N_TrueTypeLookup), 0, agg::glyph_ren_agg_gray8 ); + mFontEngine.load_font( "c:\\windows\\fonts\\arial.ttf", 0, agg::glyph_ren_agg_gray8 ); mFontEngine.height( fontSize*fontScale ); mFontEngine.width( fontSize*fontScale ); - mFontEngine.flip_y( true ); + mFontEngine.flip_y( false ); + mContour.width( fontSize*fontScale*0.2); } @@ -413,29 +425,26 @@ } /* Calculate the font size (in pixels) */ - fontSize = pls->chrht * DEVICE_PIXELS_PER_MM * 1.2; + fontSize = pls->chrht * DEVICE_PIXELS_PER_MM * 1.2 * scaley; /* calculate rotation of text */ plRotationShear( args->xform, &rotation, &shear, &stride ); rotation -= pls->diorot * M_PI / 2.0; - cos_rot = cos( rotation ); - sin_rot = sin( rotation ); cos_shear = cos(shear); sin_shear = sin(shear); + agg::trans_affine mtx; + mtx *= agg::trans_affine_rotation( rotation ); + mtx *= agg::trans_affine_skewing( shear, shear ); + mtx *= agg::trans_affine_translation( args->x, args->y ); + mtx *= mTransform; + mFontEngine.transform(mtx); + PSDrawText( args->unicode_array, args->unicode_array_len, false ); - - agg::trans_affine mtx; - mtx *= agg::trans_affine_translation( args->x/scalex, height-args->y/scaley ); - //mtx *= agg::trans_affine_rotation( rotation ); - //mtx *= agg::trans_affine_skewing( cos_shear, sin_shear ); printf("textWidth=%f, textHeight=%f\n", textWidth, textHeight ); - mtx *= agg::trans_affine_translation( -args->just*textWidth, -0.5*textHeight ); - mFontEngine.transform(mtx); - - agg::conv_transform<fontManagerType::path_adaptor_type> tr( mFontManager.path_adaptor(), mtx ); - + mtx *= agg::trans_affine_translation( -args->just*textWidth/scalex, -0.5*textHeight/scaley ); + //mFontEngine.transform(mtx); PSDrawText( args->unicode_array, args->unicode_array_len, true ); AddtoClipRegion( 0, 0, width, height ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |