GraphFont.h

Go to the documentation of this file.
00001 // GraphFont.h
00002 
00003 /*************************************************************/
00004 //
00005 // CGraphFont
00006 //
00007 // Draw antialiased fonts
00008 //
00009 //-------------------------------------------------------------
00010 //
00011 // v 1.7 - 2007/05/31 - Fix for 64bit Linux and correct-rounding return length
00012 // v 1.6 - 2007/04/04 - Smaller font size for tick numbers
00013 // v 1.5 - 2007/03/14 - Fixed single spaces in Cairo
00014 // v 1.4 - 2007/02/17 - Cairo font handling
00015 // v 1.3 - 2007/01/06 - Precision padding of numbers
00016 // v 1.2 - 2006/08/27 - Overloaded with doubles than round near zero
00017 // v 1.1 - 2006/07/07 - Super- and sub-script fonts
00018 // v 1.0 - 2006/04/19 - Initial release
00019 //
00020 // See LICENSE.txt for distribution and usage restrictions
00021 // Copyright (c) 2005-2007 Simon Chorley
00022 // www.mylaboratory.co.uk - greylab@mylaboratory.co.uk
00023 //
00024 /*************************************************************/
00025 
00026 
00027 ///Graph font (Definition)
00028 /**
00029  * Provides CGraphFont class to draw text onto the graphs. Allows superscript, subscript and greek letters.
00030  * @file GraphFont.h
00031  * @version 1.7 - 2007/05/31
00032  */
00033 
00034 
00035 #ifndef _GRAPHFONT_H_
00036 #define _GRAPHFONT_H_
00037 
00038 
00039 #include <fx.h>
00040 
00041 
00042 #ifdef CAIROGRAPHICS
00043 #include <cairo.h>
00044 #endif
00045 
00046 
00047 ///Graph font drawing class
00048 /**
00049  * Maintains the fonts and handles drawing strings onto FXDC surfaces.
00050  */
00051 class CGraphFont
00052 {
00053 private:
00054         FXFont *textFont;       ///<Text font
00055         FXFont *symFont;        ///<Symbol font
00056         FXFont *textSFont;      ///<Text sup/sub font
00057         FXFont *symSFont;       ///<Symbol sup/sub font
00058         FXFont *numFont;        ///<Number font (slightly different size)
00059         int fontbaseline;
00060         int fontSupbaseline;
00061         int fontSubbaseline;
00062         int numfontbaseline;
00063         float fontkernel[3][3]; ///<Gaussian AA kernel
00064         bool aamethod;  ///<Antialiasing method: true == HQ, false == LQ
00065         float numfactor;        ///<Number font enlargement factor
00066 
00067 #ifdef CAIROGRAPHICS
00068         float cairofontraise;
00069         float cairofontlower;
00070 
00071 //      cairo_font_options_t *c_font;
00072 #endif
00073 
00074         FXApp *app;             ///<Application object pointer
00075 
00076         FXString doubleToString(double d);
00077         FXString preciseString(double d, int precision);
00078 
00079 public:
00080         CGraphFont();
00081         ~CGraphFont();
00082 
00083         FXFontDesc textFontdesc;
00084         FXFontDesc symFontdesc;
00085         int fontheight;
00086         int numfontheight;
00087 
00088         void buildFont(FXApp *a, bool hqaa, float nummultiplier);       //initialise using antialiasing mode
00089 
00090         int getPrecision(double d);
00091 
00092         int getStringDimensions(FXString txt);  //return dimensions of the specified string
00093         FXColor* drawAAString(FXString txt, int &length);       //Draw a string to an array of FXColor and return pointer
00094         float* drawAAStringf(FXString txt, int &length);
00095 
00096         //Zero rouunding verions of the above functions
00097         int getStringDimensions(double d, int precision = 0);   //return dimensions of the specified string
00098         FXColor* drawAAString(double d, int &length, int precision = 0);        //Draw a string to an array of FXColor and return pointer
00099         float* drawAAStringf(double d, int &length, int precision = 0);
00100 
00101 #ifdef CAIROGRAPHICS
00102         float cairofontheight;
00103         float cairobaselineheight;
00104         float caironumfontheight;
00105 
00106         void initCairoMeasurements(cairo_t *c);
00107 
00108         float getStringDimensions(cairo_t *c, FXString txt);    //return dimensions of the specified string
00109         float getStringDimensions(cairo_t *c, double d, int precision = 0);     //return dimensions of the specified string
00110         void drawString(cairo_t *c, float x, float y, FXString txt);
00111         void drawString(cairo_t *c, float x, float y, double d, int precision = 0);     //Draw a string
00112 #endif
00113 };
00114 
00115 #endif

Generated on Mon Mar 10 13:55:44 2008 for GreyLab by  doxygen 1.5.3