00001 #ifndef OSDL_FONT_H_
00002 #define OSDL_FONT_H_
00003
00004
00005
00006 #include "OSDLVideo.h"
00007 #include "OSDLVideoTypes.h"
00008 #include "OSDLPixel.h"
00009 #include "OSDLSurface.h"
00010
00011 #include "Ceylan.h"
00012
00013 #include <string>
00014
00015
00016
00017
00018 namespace OSDL
00019 {
00020
00021
00022 namespace Video
00023 {
00024
00025
00026
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
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
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
00415
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
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
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
01253
01254
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