OSDLFont.h

Go to the documentation of this file.
00001 #ifndef OSDL_FONT_H_
00002 #define OSDL_FONT_H_
00003 
00004 
00005 
00006 #include "OSDLVideo.h"        // for VideoException
00007 #include "OSDLVideoTypes.h"   // for Length, SignedLength, etc.
00008 #include "OSDLPixel.h"        // for ColorElement, ColorDefinition
00009 #include "OSDLSurface.h"      // for Surface
00010 
00011 #include "Ceylan.h"           // for Uint32, inheritance
00012 
00013 #include <string>
00014 
00015     
00016 
00017 
00018 namespace OSDL
00019 {
00020 
00021 
00022     namespace Video
00023     {
00024 
00025 
00026         // Fonts are rendered to surfaces.
00027         class Surface ;
00028 
00029 
00030         namespace TwoDimensional
00031         {
00032             
00033             
00034             
00036             class OSDL_DLL TextException: public VideoException 
00037             { 
00038             
00039                 public: 
00040                 
00041                     explicit TextException( const std::string & reason ) 
00042                         throw() ; 
00043                     virtual ~TextException() throw() ; 
00044                     
00045             } ;
00046                 
00047             
00048             
00049             namespace Text
00050             {   
00051             
00052 
00054                 typedef Length PointSize ;
00055                 
00056                 
00062                 typedef Ceylan::Uint16 FontIndex ;
00063                 
00064                 
00065                 
00067                 typedef Ceylan::Uint16 Height ;
00068                 
00070                 typedef Ceylan::Sint16 SignedHeight ;
00071                 
00072                 
00074                 typedef Ceylan::Uint16 Width ;
00075                 
00077                 typedef Ceylan::Sint16 SignedWidth ;
00078                 
00079                 
00081                 typedef int RenderingStyle ;
00082                 
00083                                 
00089                 typedef Ceylan::Uint16 TextIndex ;
00090                     
00091                                     
00098                 typedef Ceylan::Uint16 LineNumber ;
00099                                     
00100                                     
00101                 
00103                 enum HorizontalAlignment { Left, WidthCentered, Right } ;
00104                 
00106                 enum VerticalAlignment { Top, HeightCentered, Bottom } ;
00107                 
00108                 
00109                 
00177                 class OSDL_DLL Font : public Ceylan::TextDisplayable
00178                 {
00179                 
00180                 
00181                     public:
00182                     
00183 
00184 
00277                         enum RenderQuality { Solid, Shaded, Blended } ;
00278                 
00279 
00280 
00281                         /*
00282                          * The Ceylan cache manager allows to reference
00283                          * resources based on their key. 
00284                          * 
00285                          * Here, the resource is a text rendering (a surface)
00286                          * and the key is made from the corresponding text 
00287                          * (be it Latin-1 char or std::string) <em>and</em> 
00288                          * from the text color <em>and</em> from the desired
00289                          * rendering quality. 
00290                          *
00291                          * I.e we request a red 'Solid' 'c', or a blue 'Shaded'
00292                          * "Some text", and we expect the cache to return a
00293                          * corresponding already computed rendering, i.e. a
00294                          * surface, if available.
00295                          *
00296                          * The key therefore is a composite type (a text, a
00297                          * color and a quality), which could be modeled at 
00298                          * least thanks to two patterns :
00299                          *   - a triple made from STL : when quality was not
00300                          * specifically managed, a
00301                          * std::pair<Latin1Char,ColorDefinition> could be 
00302                          * used, since the STL pairs have the '<' (less)
00303                          * operators defined (necessary for the ordering
00304                          * of the std::map ordering). 
00305                          * However ColorDefinition is a struct, with no
00306                          * specific '<' operator defined, which would be 
00307                          * needed here. 
00308                          * Moreover, for three parameters, the STL is 
00309                          * probably less useful
00310                          *   - a dedicated key class, which defines that same
00311                          * operator '<' 
00312                          *
00313                          * We thus chose the latter solution here.
00314                          *
00315                          */
00316 
00317                         
00326                         class OSDL_DLL CharColorQualityKey
00327                         {
00328                         
00329                         
00330                             public:
00331                                 
00332                                 
00333                                 CharColorQualityKey( 
00334                                         Ceylan::Latin1Char character, 
00335                                         Pixels::ColorDefinition color,
00336                                         RenderQuality quality ) throw() :
00337                                     _character( character ),
00338                                     _color( color ),
00339                                     _quality( quality )
00340                                 {
00341                                 
00342                                 }
00343                                 
00344                                 
00346                                 inline bool operator < ( 
00347                                         const CharColorQualityKey & other ) 
00348                                     const throw() 
00349                                 {
00350 
00351                                     if ( _character < other._character )
00352                                         return true ;
00353         
00354                                     if ( _character > other._character )
00355                                         return false ;
00356         
00357                                     if ( Pixels::isLess( _color, 
00358                                             other._color ) )
00359                                         return true ;
00360                                     
00361                                     if ( Pixels::isLess( other._color, 
00362                                             _color ) )
00363                                         return false ;
00364                                     
00365                                     return _quality < other._quality ;
00366                                                                             
00367                                 }   
00368                                 
00369                                 
00370                             private:                                
00371                             
00372                                 Ceylan::Latin1Char _character ;
00373                                 
00374                                 Pixels::ColorDefinition _color ;
00375                                     
00376                                 RenderQuality _quality ;
00377                         
00378                         
00379                         } ;
00380                         
00381                                 
00382 
00388                         class OSDL_DLL StringColorQualityKey
00389                         {
00390                         
00391 
00392                             public:
00393                                 
00394                                 
00395                                 StringColorQualityKey( 
00396                                     const std::string & text, 
00397                                     Pixels::ColorDefinition color, 
00398                                     RenderQuality quality )
00399                                         throw() :
00400                                     _text( text ),
00401                                     _color( color ),
00402                                     _quality( quality )
00403                                 {
00404                                 
00405                                 }
00406 
00407                                 
00408                                 inline bool operator < ( 
00409                                         const StringColorQualityKey & other ) 
00410                                     const throw() 
00411                                 {   
00412                                     
00413                                     /*
00414                                      * Comparisons between strings are done
00415                                      * lexicographically.
00416                                      *
00417                                      */
00418                                     
00419                                     if ( _text < other._text )
00420                                         return true ;
00421         
00422                                     if ( _text > other._text )
00423                                         return false ;
00424         
00425                                     if ( Pixels::isLess( _color, 
00426                                             other._color ) )
00427                                         return true ;
00428                                     
00429                                     if ( Pixels::isLess( other._color,
00430                                              _color ) )
00431                                         return false ;
00432                                     
00433                                     return _quality < other._quality ;
00434         
00435                                 }   
00436                                 
00437                                 
00438                             private:                                
00439                             
00440                                 std::string _text ;
00441                                 Pixels::ColorDefinition _color ;    
00442                                 RenderQuality _quality ;
00443                                 
00444                         
00445                         } ;
00446                         
00447 
00448 
00449                     
00470                         enum RenderCache { 
00471                             None, GlyphCached, WordCached, TextCached } ;
00472                         
00473                     
00497                         enum AllowedCachePolicy { 
00498                             NeverDrop, DropLessRequestedFirst } ;
00499                         
00500                         
00539                         explicit Font( 
00540                             bool convertToDisplay = true, 
00541                             RenderCache cacheSettings = GlyphCached, 
00542                             AllowedCachePolicy cachePolicy 
00543                                 = DropLessRequestedFirst,
00544                             Ceylan::System::Size quota = 0 ) throw() ;
00545                         
00546                         
00548                         virtual ~Font() throw() ;
00549 
00550                         
00555                         virtual RenderingStyle getRenderingStyle() const
00556                             throw() ;
00557                         
00558                         
00574                         virtual void setRenderingStyle( 
00575                             RenderingStyle newStyle ) throw( TextException ) ;
00576                         
00577 
00589                         virtual void setBackgroundColor( 
00590                                 Pixels::ColorDefinition newBackgroundColor ) 
00591                             throw() ;   
00592                             
00593                     
00603                         Pixels::ColorDefinition getBackgroundColor() 
00604                             const throw() ;
00605                                                 
00606                         
00622                         virtual Width getWidth( Ceylan::Latin1Char character ) 
00623                             const throw( TextException) = 0 ;
00624                          
00625                          
00641                         virtual SignedWidth getWidthOffset( 
00642                                 Ceylan::Latin1Char character ) 
00643                             const throw( TextException ) = 0 ;
00644 
00645 
00657                         virtual SignedHeight getHeightAboveBaseline(
00658                                 Ceylan::Latin1Char character )
00659                             const throw( TextException ) = 0 ;
00660 
00661                          
00679                         virtual SignedLength getAdvance( 
00680                                 Ceylan::Latin1Char character ) 
00681                             const throw( TextException ) = 0 ;
00682                          
00683                          
00698                         virtual Width getInterGlyphWidth() const throw() ;
00699                          
00700                                                 
00716                         virtual Height getHeight() const throw() = 0 ;
00717                         
00718                         
00719                          
00735                         virtual SignedHeight getAscent() const throw() = 0 ;
00736                          
00737                          
00757                         virtual SignedHeight getDescent() const throw() = 0 ;
00758                          
00759                          
00768                         virtual Height getLineSkip() const throw() = 0 ;
00769                         
00770                         
00771                         
00777                         virtual Width getAlineaWidth() const throw() ;
00778                         
00779                         
00790                         virtual void setAlineaWidth( Width newAlineaWidth )
00791                             throw() ;   
00792                          
00793                          
00794                          
00805                         virtual std::string describeGlyphFor( 
00806                                 Ceylan::Latin1Char character )
00807                             const throw() ;
00808                         
00809                         
00810                         
00811                         // Render section.
00812                                                          
00813 
00845                         virtual Surface & renderLatin1Glyph( 
00846                                 Ceylan::Latin1Char character, 
00847                                 RenderQuality quality = Solid, 
00848                                 Pixels::ColorDefinition glyphColor 
00849                                     = Pixels::White ) 
00850                             throw( TextException ) = 0 ;
00851 
00852 
00877                         virtual void blitLatin1Glyph( 
00878                                 Surface & targetSurface,
00879                                 Coordinate x, 
00880                                 Coordinate y, 
00881                                 Ceylan::Latin1Char character, 
00882                                 RenderQuality quality = Solid, 
00883                                 Pixels::ColorDefinition glyphColor 
00884                                     = Pixels::White )  
00885                             throw( TextException )= 0 ;
00886                             
00887                                 
00888                                 
00910                         virtual Surface & renderLatin1Text( 
00911                                 const std::string & text, 
00912                                 RenderQuality quality = Solid,
00913                                 Pixels::ColorDefinition textColor 
00914                                     = Pixels::White ) 
00915                             throw( TextException ) ;
00916                             
00917                             
00918                             
00945                         virtual void blitLatin1Text( 
00946                                 Surface & targetSurface,
00947                                 Coordinate x, 
00948                                 Coordinate y, 
00949                                 const std::string & text, 
00950                                 RenderQuality quality = Solid,
00951                                 Pixels::ColorDefinition textColor 
00952                                     = Pixels::White ) 
00953                             throw( TextException ) ;
00954                             
00955 
00956                                 
01035                         virtual Surface & renderLatin1MultiLineText( 
01036                                 Length width, 
01037                                 Length height,
01038                                 const std::string & text,
01039                                 TextIndex & renderIndex,
01040                                 Coordinate & lastOrdinateUsed,
01041                                 RenderQuality quality = Solid,
01042                                 Pixels::ColorDefinition textColor 
01043                                     = Pixels::White,
01044                                 bool justified = true ) 
01045                             throw( TextException ) ;
01046 
01047 
01105                         virtual void blitLatin1MultiLineText( 
01106                                 Surface & targetSurface,
01107                                 const UprightRectangle & clientArea, 
01108                                 const std::string & text,
01109                                 TextIndex & renderIndex,
01110                                 RenderQuality quality = Solid,
01111                                 Pixels::ColorDefinition textColor 
01112                                     = Pixels::White,
01113                                 bool justified = true ) 
01114                             throw( TextException ) ;
01115 
01116 
01181                         virtual void blitLatin1MultiLineText( 
01182                                 Surface & targetSurface,
01183                                 Coordinate x, 
01184                                 Coordinate y,
01185                                 Length width, 
01186                                 Length height,
01187                                 const std::string & text,
01188                                 TextIndex & renderIndex,
01189                                 RenderQuality quality = Solid,
01190                                 Pixels::ColorDefinition textColor 
01191                                     = Pixels::White,
01192                                 bool justified = true ) 
01193                             throw( TextException ) ;
01194 
01195 
01196 
01209                         virtual const std::string toString( 
01210                                 Ceylan::VerbosityLevels level = Ceylan::high ) 
01211                             const throw() ;
01212 
01213                         
01214                         
01215                         
01216                         // Static section.
01217                         
01218                                                 
01225                         static std::string FontPathEnvironmentVariable  ;
01226                         
01227                         
01237                         static Ceylan::System::FileLocator FontFileLocator ;
01238                         
01239                         
01247                         static std::string InterpretRenderingStyle(
01248                             RenderingStyle style ) throw() ;
01249                         
01250                         
01251                         /*
01252                          * Rendering styles can be combined for some fonts : 
01253                          * 'Bold | Italic' selects for example a bold italic
01254                          * rendering style.
01255                          * 
01256                          */
01257                         
01259                         static const RenderingStyle Normal ;
01260                 
01261                                 
01263                         static const RenderingStyle Bold ;
01264                 
01265                         
01267                         static const RenderingStyle Italic ;
01268                 
01269                         
01271                         static const RenderingStyle Underline ;
01272 
01273 
01282                         static const Ceylan::System::Size
01283                             DefaultGlyphCachedQuota ;
01284                         
01285                         
01294                         static const Ceylan::System::Size 
01295                             DefaultWordCachedQuota ;
01296                         
01297                         
01306                         static const Ceylan::System::Size 
01307                             DefaultTextCachedQuota ;
01308                         
01309                                                 
01315                         static const Ceylan::Uint8 
01316                             DefaultSpaceBasedAlineaWidth ;
01317                         
01318                         
01319                         
01320                         
01321                     protected:
01322 
01323 
01324                         
01346                         Surface & renderLatin1TextWithWordCached( 
01347                                 const std::string & text,
01348                                 RenderQuality quality, 
01349                                 Pixels::ColorDefinition textColor ) 
01350                             throw( TextException ) ;
01351                             
01352                             
01353                             
01375                         Surface & renderLatin1TextWithTextCached( 
01376                                 const std::string & text,
01377                                 RenderQuality quality, 
01378                                 Pixels::ColorDefinition textColor ) 
01379                             throw( TextException ) ;
01380                             
01381 
01382                         
01415                         virtual void blitLatin1Word( 
01416                                 Surface & targetSurface,
01417                                 Coordinate x, 
01418                                 Coordinate y, 
01419                                 const std::string & word, 
01420                                 RenderQuality quality = Solid, 
01421                                 Pixels::ColorDefinition wordColor 
01422                                     = Pixels::White ) 
01423                             throw( TextException ) ;
01424                         
01425 
01426 
01463                         virtual const Surface & getConstLatin1WordFromCache( 
01464                                 const std::string & word, 
01465                                 RenderQuality quality,
01466                                 Pixels::ColorDefinition wordColor )
01467                             throw( TextException ) ;
01468 
01469                             
01491                         Surface & basicRenderLatin1Text( 
01492                                 const std::string & text,
01493                                 RenderQuality quality, 
01494                                 Pixels::ColorDefinition textColor ) 
01495                             throw( TextException ) ;
01496                             
01497                             
01503                         RenderingStyle _renderingStyle ;
01504                     
01505                     
01511                         bool _convertToDisplay ;
01512                         
01513                                                                         
01515                         RenderCache _cacheSettings ;
01516 
01517                          
01527                         Ceylan::SmartResourceManager<CharColorQualityKey> *
01528                             _glyphCache ;
01529                         
01530                         
01540                         Ceylan::SmartResourceManager<StringColorQualityKey> *
01541                             _textCache ;
01542 
01543                         
01549                         Pixels::ColorDefinition _backgroundColor ;
01550                         
01551                         
01564                         Width _spaceWidth ;
01565                             
01566                             
01575                         Width _alineaWidth ;
01576                             
01577                 
01578                 
01579                     private:
01580                     
01581                 
01582                                     
01591                         Font( const Font & source ) throw() ;
01592             
01593             
01602                         Font & operator = ( const Font & source ) throw() ;
01603                         
01604                         
01605                 } ;                         
01606                 
01607             } 
01608             
01609         }   
01610             
01611     }
01612     
01613 }       
01614 
01615 
01616 
01617 #endif // OSDL_FONT_H_
01618 

Generated on Fri Mar 30 14:46:59 2007 for OSDL by  doxygen 1.5.1