Font selection now generates and saves a TGA sample.
authorsl
Wed, 21 May 2014 10:19:22 +0200
changeset 8631f53604811
parent 7 e8c05ae7f418
child 9 e6c42e1e2a96
Font selection now generates and saves a TGA sample.
MainWindow.h
test.cpp
     1.1 --- a/MainWindow.h	Wed May 21 09:03:40 2014 +0200
     1.2 +++ b/MainWindow.h	Wed May 21 10:19:22 2014 +0200
     1.3 @@ -118,6 +118,7 @@
     1.4      unsigned char iDimming; //Current VFD dimming
     1.5      FXFontDesc iCurrentFontDesc;
     1.6      FXFont* iCurrentFont;
     1.7 +    FXTGAImage* iFontImage;
     1.8  
     1.9      struct hid_device_info *devices;
    1.10      hid_device *connected_device;
     2.1 --- a/test.cpp	Wed May 21 09:03:40 2014 +0200
     2.2 +++ b/test.cpp	Wed May 21 10:19:22 2014 +0200
     2.3 @@ -52,7 +52,8 @@
     2.4  
     2.5  MainWindow::MainWindow(FXApp *app)
     2.6  	: FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900),
     2.7 -    iCurrentFont(NULL)
     2.8 +    iCurrentFont(NULL),
     2.9 +    iFontImage(NULL)
    2.10  {
    2.11  	iDimming=0x35;
    2.12  	devices = NULL;
    2.13 @@ -178,6 +179,9 @@
    2.14      delete iCurrentFont;
    2.15      iCurrentFont = NULL;
    2.16  
    2.17 +    delete iFontImage;
    2.18 +    iFontImage = NULL;
    2.19 +
    2.20  	if (connected_device)
    2.21  		hid_close(connected_device);
    2.22  	hid_exit();
    2.23 @@ -750,6 +754,35 @@
    2.24          delete iCurrentFont;
    2.25          iCurrentFont = NULL;
    2.26          iCurrentFont = new FXFont(getApp(),iCurrentFontDesc);
    2.27 +        iCurrentFont->create();
    2.28 +        //
    2.29 +        delete iFontImage;
    2.30 +        iFontImage = NULL;
    2.31 +        //
    2.32 +        FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
    2.33 +        //Create an image the proper size for our text
    2.34 +        iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
    2.35 +        iFontImage->create();
    2.36 +        //Perform our drawing
    2.37 +            {
    2.38 +            FXDCWindow dc(iFontImage);
    2.39 +            //dc.begin(iFontImage);
    2.40 +            dc.setFont(iCurrentFont);
    2.41 +            dc.setForeground(0xFFFFFFFF);
    2.42 +            //dc.setBackground(0xFF000000);
    2.43 +            //dc.setFillStyle(FILL_SOLID);
    2.44 +            dc.fillRectangle(0,0,iFontImage->getWidth(),iFontImage->getHeight());
    2.45 +            dc.setForeground(0xFF000000);
    2.46 +            dc.drawText(0,iCurrentFont->getFontAscent(),text);
    2.47 +            //dc.end();
    2.48 +            }
    2.49 +        FXFileStream file;
    2.50 +        file.open("fonttest.tga",FXStreamSave);
    2.51 +        iFontImage->restore();
    2.52 +        iFontImage->savePixels(file);
    2.53 +        file.close();
    2.54 +
    2.55 +        //
    2.56  
    2.57          }
    2.58