File: wxwidgets_agg.cpp

package info (click to toggle)
plplot 5.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,280 kB
  • ctags: 13,512
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,210; makefile: 199; lisp: 75; sed: 25; fortran: 7
file content (608 lines) | stat: -rw-r--r-- 20,724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
// $Id: wxwidgets_agg.cpp 12334 2013-05-04 16:43:33Z airwin $
//
// Copyright (C) 2008  Werner Smekal
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//

// TODO:
// - let the AGG library process the text. In the moment most of the relevant code
//   is commented out, since there are problems with the affine transformation
//

// wxwidgets headers
#include <wx/wx.h>
#include <wx/strconv.h>

#include "plDevs.h"

// plplot headers
#include "plplotP.h"
#include "plfci-truetype.h"

// std and driver headers
#include "wxwidgets.h"
#include <wchar.h>

// helper functions
#if !defined ( WIN32 ) || defined ( __GNUC__ )
  #include <unistd.h>
#else
  #define F_OK    1
  #include <stdio.h>
int access( char *filename, int flag )
{
    FILE *infile;
    infile = fopen( filename, "r" );
    if ( infile != NULL )
    {
        fclose( infile );
        return 0;
    }
    else
        return 1;
}
#endif

#define makeunixslash( b )    do { char *I; for ( I = b; *I != 0; *I++ ) if ( *I == '\\' ) *I = '/';} while ( 0 )

//--------------------------------------------------------------------------
//  wxPLDevAGG::wxPLDevAGG()
//
//  Constructor of the AGG wxWidgets device based on the wxPLDevBase
//  class. Initialisations of variables and objects are done.
//--------------------------------------------------------------------------
wxPLDevAGG::wxPLDevAGG() :
    wxPLDevBase( wxBACKEND_AGG ),
    mRenderingBuffer(),
    mPixFormat( mRenderingBuffer ),
    mRendererBase( mPixFormat ),
    mRendererSolid( mRendererBase ),

    mPath(),
    mTransform(),
    mConvCurve( mPath ),
    mConvStroke( mConvCurve ),
    mPathTransform( mConvCurve, mTransform ),
    mStrokeTransform( mConvStroke, mTransform ),

    mFontEngine(),
    mFontManager( mFontEngine ),
    mCurves( mFontManager.path_adaptor() ),
    mContour( mCurves ),

    mBuffer( NULL ),
    mStrokeWidth( 1.0 ),
    mStrokeOpacity( 255 ),
    mColorRedStroke( 255 ),
    mColorGreenStroke( 255 ),
    mColorBlueStroke( 255 ),
    mColorRedFill( 0 ),
    mColorGreenFill( 0 ),
    mColorBlueFill( 0 )
{
    mCurves.approximation_scale( 2.0 );
    mContour.auto_detect_orientation( false );
    mConvStroke.line_join( agg::round_join );
    mConvStroke.line_cap( agg::round_cap );

    // determine font directory
#if defined ( WIN32 )
    //static char *default_font_names[]={"arial.ttf","times.ttf","timesi.ttf","arial.ttf",
    //                                 "symbol.ttf"};
    // char WINDIR_PATH[255];
    // char *b;
    // b=getenv("WINDIR");
    // strncpy(WINDIR_PATH,b,255);

//
// Work out if we have Win95+ or Win3.?... sort of.
// Actually, this just tries to find the place where the fonts live by looking
// for arial, which should be on all windows machines.
// At present, it only looks in two places, on one drive. I might change this
// soon.
//
    //if (WINDIR_PATH==NULL)
    // {
    //  if (access("c:\\windows\\fonts\\arial.ttf", F_OK)==0) {
    //      strcpy(font_dir,"c:/windows/fonts/");
    //  }
    //  else if ( access("c:\\windows\\system\\arial.ttf", F_OK)==0) {
    //      strcpy(font_dir,"c:/windows/system/");
    //  }
    //  else
    //  plwarn("Could not find font path; I sure hope you have defined fonts manually !");
    // }
    // else
    // {
    // strncat(WINDIR_PATH,"\\fonts\\arial.ttf",255);
    // if (access(WINDIR_PATH, F_OK)==0)
    //  {
    //    b=strrchr(WINDIR_PATH,'\\');
    //    b++;
    //b=0;
    //    makeunixslash(WINDIR_PATH);
    //    strcpy(font_dir,WINDIR_PATH);
    //  }
    // else
    //  plwarn("Could not find font path; I sure hope you have defined fonts manually !");
    // }
    //
    // 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,
    //  but the user can override this by setting the environmental variable
    //  "PLPLOT_FREETYPE_FONT_DIR" to something else.
    //  NOTE WELL - the trailing slash must be added for now !
    //
    // const char *str;
    //
    // fontdir.Clear();
    // if( (str=getenv("PLPLOT_FREETYPE_FONT_DIR"))!=NULL )
    //      fontdir.Append( wxString(str, wxConvFile) );
    // else
    //      fontdir.Append( wxT(PL_FREETYPE_FONT_DIR) );
    //
    // //printf("fontdir=%s, len=%d\n", fontdir.c_str(), fontdir.Length() );
#endif
}


//--------------------------------------------------------------------------
//  wxPLDevAGG::~wxPLDevAGG()
//
//  Deconstructor frees allocated buffer.
//--------------------------------------------------------------------------
wxPLDevAGG::~wxPLDevAGG()
{
    if ( ownGUI )
        if ( mBuffer )
            delete mBuffer;
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::drawPath( drawPathFlag flag )
//
//  Common function which either draws a stroke along a path or a filled
//  polygon surrounded by a stroke depending on flag.
//--------------------------------------------------------------------------
void wxPLDevAGG::drawPath( drawPathFlag flag )
{
    mRasterizer.reset();

    switch ( flag )
    {
    case Stroke:
        if ( mStrokeOpacity && mStrokeWidth > 0.0 )
        {
            mConvStroke.width( mStrokeWidth );
            mRasterizer.add_path( mStrokeTransform );
            mRendererSolid.color( agg::rgba8( mColorRedStroke, mColorGreenStroke, mColorBlueStroke, mStrokeOpacity ) );
            agg::render_scanlines( mRasterizer, mScanLine, mRendererSolid );
        }
        break;
    case FillAndStroke:
        if ( mStrokeOpacity )
        {
            mRasterizer.add_path( mPathTransform );
            mRendererSolid.color( agg::rgba8( mColorRedStroke, mColorGreenStroke, mColorBlueStroke, mStrokeOpacity ) );
            agg::render_scanlines( mRasterizer, mScanLine, mRendererSolid );
        }

        if ( mStrokeOpacity && mStrokeWidth > 0.0 )
        {
            mConvStroke.width( mStrokeWidth );
            mRasterizer.add_path( mStrokeTransform );
            mRendererSolid.color( agg::rgba8( mColorRedStroke, mColorGreenStroke, mColorBlueStroke, mStrokeOpacity ) );
            agg::render_scanlines( mRasterizer, mScanLine, mRendererSolid );
        }
        break;
    }
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::DrawLine( short x1a, short y1a, short x2a, short y2a )
//
//  Draw a line from (x1a, y1a) to (x2a, y2a).
//--------------------------------------------------------------------------
void wxPLDevAGG::DrawLine( short x1a, short y1a, short x2a, short y2a )
{
    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 )
//
//  Draw a poly line - coordinates are in the xa and ya arrays.
//--------------------------------------------------------------------------
void wxPLDevAGG::DrawPolyline( short *xa, short *ya, PLINT npts )
{
    mPath.remove_all();
    mPath.move_to( xa[0], ya[0] );
    for ( PLINT i = 1; i < npts; i++ )
    {
        mPath.line_to( xa[i], ya[i] );
        if ( !resizing && ownGUI )
            AGGAddtoClipRegion( xa[i - 1], ya[i - 1], xa[i], ya[i] );
    }

    drawPath( Stroke );
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::ClearBackground( PLINT bgr, PLINT bgg, PLINT bgb,
//                                    PLINT x1, PLINT y1, PLINT x2, PLINT y2 )
//
//  Clear parts ((x1,y1) to (x2,y2)) of the background in color (bgr,bgg,bgb).
//--------------------------------------------------------------------------
void wxPLDevAGG::ClearBackground( PLINT bgr, PLINT bgg, PLINT bgb, PLINT x1, PLINT y1, PLINT x2, PLINT y2 )
{
    if ( x1 < 0 && y1 < 0 && x2 < 0 && y2 < 0 )
    {
        mRendererBase.clear( agg::rgba8( bgr, bgg, bgb ) );
        if ( !resizing && ownGUI )
            AddtoClipRegion( 0, 0, width, height );
    }
    else
    {
        mPath.remove_all();
        mPath.move_to( x1, y1 );
        mPath.line_to( x2, y1 );
        mPath.line_to( x2, y2 );
        mPath.line_to( x1, y2 );
        mPath.close_polygon();

        mRasterizer.reset();
        mRasterizer.add_path( mPathTransform );
        mRendererSolid.color( agg::rgba8( bgr, bgg, bgb, 255 ) );
        agg::render_scanlines( mRasterizer, mScanLine, mRendererSolid );

        mConvStroke.width( 1.0 );
        mRasterizer.add_path( mStrokeTransform );
        mRendererSolid.color( agg::rgba8( bgr, bgg, bgb, 255 ) );
        agg::render_scanlines( mRasterizer, mScanLine, mRendererSolid );

        if ( !resizing && ownGUI )
            AGGAddtoClipRegion( x1, y1, x2, y2 );
    }
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::AGGAddtoClipRegion( short x1, short y1,
//                                       short x2, short y2 )
//
//  Adds the region (x1,y1)-(x2,y2) to the regions which needs to be
//  updated/redrawn.
//--------------------------------------------------------------------------
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 )
//
//  Draw a filled polygon.
//--------------------------------------------------------------------------
void wxPLDevAGG::FillPolygon( PLStream *pls )
{
    short *xa = pls->dev_x;
    short *ya = pls->dev_y;

    mPath.remove_all();
    mPath.move_to( xa[0], ya[0] );
    for ( PLINT i = 1; i < pls->dev_npts; i++ )
    {
        mPath.line_to( xa[i], ya[i] );
        if ( !resizing && ownGUI )
            AGGAddtoClipRegion( xa[i - 1], ya[i - 1], xa[i], ya[i] );
    }
    mPath.line_to( xa[0], ya[0] );
    mPath.close_polygon();

    drawPath( FillAndStroke );
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::BlitRectangle( wxDC* dc, int vX, int vY,
//                                  int vW, int vH )
//
//  Copy/Blit a rectangle ((vX,vY) to (vX+vW,vY+vH)) into given dc.
//--------------------------------------------------------------------------
void wxPLDevAGG::BlitRectangle( wxDC* dc, int vX, int vY, int vW, int vH )
{
    if ( mBuffer )
    {
        wxMemoryDC MemoryDC;
        wxBitmap   bitmap( mBuffer->GetSubImage( wxRect( vX, vY, vW, vH ) ), -1 );
        MemoryDC.SelectObject( bitmap );
        dc->Blit( vX, vY, vW, vH, &MemoryDC, 0, 0 );
        MemoryDC.SelectObject( wxNullBitmap );
    }
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::CreateCanvas( void )
//
//  Create canvas (bitmap and dc) if the driver provides the GUI.
//--------------------------------------------------------------------------
void wxPLDevAGG::CreateCanvas()
{
    if ( ownGUI )
    {
        // get a new wxImage (image buffer)
        if ( mBuffer )
            delete mBuffer;
        mBuffer = new wxImage( bm_width, bm_height );
        mRenderingBuffer.attach( mBuffer->GetData(), bm_width, bm_height, bm_width * 3 );
    }
    else
        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 )
//
//  Set the width of the drawing pen.
//--------------------------------------------------------------------------
void wxPLDevAGG::SetWidth( PLStream *pls )
{
    mStrokeWidth = ( scalex + scaley ) / 2.0 * ( pls->width > 0 ? pls->width : 1 ); // TODO: why and when ist width 0???
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::SetColor0( PLStream *pls )
//
//  Set color from colormap 0.
//--------------------------------------------------------------------------
void wxPLDevAGG::SetColor0( PLStream *pls )
{
    mColorRedStroke   = pls->curcolor.r;
    mColorGreenStroke = pls->curcolor.g;
    mColorBlueStroke  = pls->curcolor.b;
    mStrokeOpacity    = (wxUint8) ( pls->curcolor.a * 255 );
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::SetColor1( PLStream *pls )
//
//  Set color from colormap 1.
//--------------------------------------------------------------------------
void wxPLDevAGG::SetColor1( PLStream *pls )
{
    mColorRedStroke   = pls->curcolor.r;
    mColorGreenStroke = pls->curcolor.g;
    mColorBlueStroke  = pls->curcolor.b;
    mStrokeOpacity    = (wxUint8) ( pls->curcolor.a * 255 );
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::SetExternalBuffer( void* dc )
//
//  Adds a dc to the device. In that case, the drivers doesn't provide
//  a GUI. A new buffer (image) will be created and set up.
//--------------------------------------------------------------------------
void wxPLDevAGG::SetExternalBuffer( void* image )
{
    mBuffer = (wxImage *) image; // Add the image to the device
    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;
}


#ifdef PL_HAVE_FREETYPE

//--------------------------------------------------------------------------
//  void wxPLDevAGG::PutPixel( short x, short y, PLINT color )
//
//  Draw a pixel in color color @ (x,y).
//--------------------------------------------------------------------------
void wxPLDevAGG::PutPixel( short x, short y, PLINT color )
{
    mBuffer->SetRGB( x, y, GetRValue( color ), GetGValue( color ), GetBValue( color ) );
    AddtoClipRegion( x, y, x, y );
}


//--------------------------------------------------------------------------
//  void wxPLDevAGG::PutPixel( short x, short y )
//
//  Draw a pixel in current color @ (x,y).
//--------------------------------------------------------------------------
void wxPLDevAGG::PutPixel( short x, short y )
{
    mBuffer->SetRGB( x, y, mColorRedStroke, mColorGreenStroke, mColorBlueStroke );
    AddtoClipRegion( x, y, x, y );
}


//--------------------------------------------------------------------------
//  PLINT wxPLDevAGG::GetPixel( short x, short y )
//
//  Get color information from pixel @ (x,y).
//--------------------------------------------------------------------------
PLINT wxPLDevAGG::GetPixel( short x, short y )
{
    return RGB( mBuffer->GetRed( x, y ), mBuffer->GetGreen( x, y ), mBuffer->GetBlue( x, y ) );
}

#endif // PL_HAVE_FREETYPE


void wxPLDevAGG::PSDrawTextToDC( char* utf8_string, bool drawText )
{
    // Log_Verbose( "%s", __FUNCTION__ );
    printf( "utf8_string=%s\n", utf8_string );

    double start_x = 0.0;
    double start_y = 0.0;

    //wchar_t str[512];
    //size_t len=wxConvUTF8.ToWChar( str, 512, utf8_string );
    size_t len   = strlen( utf8_string );
    char   * str = utf8_string;
    printf( "len=%lu\n", (unsigned long) len );

    const agg::glyph_cache* glyph;
    if ( !drawText )
    {
        double x         = 0;
        double y         = 0;
        bool   first     = true;
        char   * saveStr = str;
        while ( *str && len )
        {
            glyph = mFontManager.glyph( *str );
            if ( glyph )
            {
                if ( !first )
                    mFontManager.add_kerning( &x, &y );
                x    += glyph->advance_x;
                y    += glyph->advance_y;
                first = false;
            }
            textHeight = textHeight > ( glyph->bounds.y2 - glyph->bounds.y1 + yOffset ) ?
                         textHeight : ( glyph->bounds.y2 - glyph->bounds.y1 + yOffset );
            ++str; --len;
        }
        textWidth = x;
        printf( "str: %s, textWidth=%lf\n", saveStr, textWidth );
    }
    else
    {
        for ( size_t i = 0; i < len && str[i]; i++ )
        {
            glyph = mFontManager.glyph( str[i] );
            if ( glyph )
            {
                printf( "before: start_x=%f, start_y=%f\n", start_x, start_y );
                if ( i )
                    mFontManager.add_kerning( &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 );

                mRendererSolid.color( agg::rgba8( mColorRedStroke, mColorGreenStroke, mColorBlueStroke, mStrokeOpacity ) );
                agg::render_scanlines( mFontManager.gray8_adaptor(), mFontManager.gray8_scanline(), mRendererSolid );

                start_x += glyph->advance_x / scalex;
                //start_y += glyph->advance_y/scaley;
            }
        }
    }

    memset( utf8_string, '\0', max_string_length );
}


void wxPLDevAGG::PSSetFont( PLUNICODE fci )
{
    // convert the fci to Base14/Type1 font information
    wxString fontname = fontdir + wxString( plP_FCI2FontName( fci, TrueTypeLookup, N_TrueTypeLookup ), *wxConvCurrent );

    if ( !mFontEngine.load_font( "/usr/share/fonts/truetype/freefont/FreeSans.ttf", 0, agg::glyph_ren_agg_gray8 ) )
        plabort( "Font could not be loaded" );
    //mFontEngine.load_font( "c:\\windows\\fonts\\arial.ttf", 0, agg::glyph_ren_agg_gray8 );
    mFontEngine.height( fontSize * fontScale );
    mFontEngine.width( fontSize * fontScale );
    mFontEngine.hinting( true );
    mFontEngine.flip_y( false );
    mContour.width( fontSize * fontScale * 0.2 );
}


void wxPLDevAGG::ProcessString( PLStream* pls, EscText* args )
{
    plabort( "The AGG backend can't process the text yet own its own!" );

    // Check that we got unicode, warning message and return if not
    if ( args->unicode_array_len == 0 )
    {
        printf( "Non unicode string passed to a wxWidgets driver, ignoring\n" );
        return;
    }

    // Check that unicode string isn't longer then the max we allow
    if ( args->unicode_array_len >= 500 )
    {
        printf( "Sorry, the wxWidgets drivers only handles strings of length < %d\n", 500 );
        return;
    }

    // Calculate the font size (in pixels)
    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_shear = cos( shear );
    sin_shear = sin( shear );

    PSDrawText( args->unicode_array, args->unicode_array_len, false );
    printf( "textWidth=%f, textHeight=%f\n", textWidth, textHeight );

    agg::trans_affine mtx;
    mtx.reset();
    mtx *= agg::trans_affine_translation( args->x, args->y );
    //mtx *= agg::trans_affine_rotation( rotation );
    //mtx *= agg::trans_affine_skewing( shear, shear );
    mtx *= mTransform;
    mtx *= agg::trans_affine_translation( -args->just * textWidth / scalex, -0.5 * textHeight );
    mtx *= agg::trans_affine_translation( -args->just * textWidth / scalex, -0.5 * textHeight );
    mFontEngine.transform( mtx );

    PSDrawText( args->unicode_array, args->unicode_array_len, true );

    AddtoClipRegion( 0, 0, width, height );
}