00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OSDL_FONT_H_
00028 #define OSDL_FONT_H_
00029
00030
00031
00032 #include "OSDLVideo.h"
00033 #include "OSDLVideoTypes.h"
00034 #include "OSDLPixel.h"
00035 #include "OSDLSurface.h"
00036
00037 #include "Ceylan.h"
00038
00039
00040 #include <string>
00041
00042
00043 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL
00044 #include "SDL.h"
00045 #endif // OSDL_USES_SDL
00046
00047
00048
00049
00050 namespace OSDL
00051 {
00052
00053
00054
00055 namespace Video
00056 {
00057
00058
00059
00060
00061 class Surface ;
00062
00063
00064
00065 namespace TwoDimensional
00066 {
00067
00068
00069
00071 class OSDL_DLL FontException: public VideoException
00072 {
00073
00074 public:
00075
00076 explicit FontException( const std::string & reason ) ;
00077
00078 virtual ~FontException() throw() ;
00079
00080 } ;
00081
00082
00083
00084
00085 namespace Text
00086 {
00087
00088
00089
00091 typedef Length PointSize ;
00092
00093
00094
00100 typedef Ceylan::Uint16 FontIndex ;
00101
00102
00103
00105 typedef Ceylan::Uint16 Height ;
00106
00107
00109 typedef Ceylan::Sint16 SignedHeight ;
00110
00111
00112
00114 typedef Ceylan::Uint16 Width ;
00115
00116
00118 typedef Ceylan::Sint16 SignedWidth ;
00119
00120
00121
00123 typedef Ceylan::Uint32 RenderingStyle ;
00124
00125
00126
00132 typedef Ceylan::Uint16 TextIndex ;
00133
00134
00135
00142 typedef Ceylan::Uint16 LineNumber ;
00143
00144
00145
00146
00148 enum HorizontalAlignment { Left, WidthCentered, Right } ;
00149
00150
00151
00153 enum VerticalAlignment { Top, HeightCentered, Bottom } ;
00154
00155
00156
00224 class OSDL_DLL Font : public Ceylan::TextDisplayable
00225 {
00226
00227
00228
00229 public:
00230
00231
00232
00325 enum RenderQuality { Solid, Shaded, Blended } ;
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00375 class OSDL_DLL CharColorQualityKey
00376 {
00377
00378
00379 public:
00380
00381
00382 CharColorQualityKey(
00383 Ceylan::Latin1Char character,
00384 Pixels::ColorDefinition color,
00385 RenderQuality quality ) :
00386 _character( character ),
00387 _color( color ),
00388 _quality( quality )
00389 {
00390
00391 }
00392
00393
00394
00396 inline bool operator < (
00397 const CharColorQualityKey & other ) const
00398 {
00399
00400 if ( _character < other._character )
00401 return true ;
00402
00403 if ( _character > other._character )
00404 return false ;
00405
00406 if ( Pixels::isLess( _color,
00407 other._color ) )
00408 return true ;
00409
00410 if ( Pixels::isLess( other._color,
00411 _color ) )
00412 return false ;
00413
00414 return _quality < other._quality ;
00415
00416 }
00417
00418
00419
00420 private:
00421
00422 Ceylan::Latin1Char _character ;
00423
00424 Pixels::ColorDefinition _color ;
00425
00426 RenderQuality _quality ;
00427
00428
00429 } ;
00430
00431
00432
00433
00439 class OSDL_DLL StringColorQualityKey
00440 {
00441
00442
00443 public:
00444
00445
00446 StringColorQualityKey(
00447 const std::string & text,
00448 Pixels::ColorDefinition color,
00449 RenderQuality quality ) :
00450 _text( text ),
00451 _color( color ),
00452 _quality( quality )
00453 {
00454
00455 }
00456
00457
00458
00459 inline bool operator < (
00460 const StringColorQualityKey & other ) const
00461 {
00462
00463
00464
00465
00466
00467
00468
00469 if ( _text < other._text )
00470 return true ;
00471
00472 if ( _text > other._text )
00473 return false ;
00474
00475 if ( Pixels::isLess( _color,
00476 other._color ) )
00477 return true ;
00478
00479 if ( Pixels::isLess( other._color,
00480 _color ) )
00481 return false ;
00482
00483 return _quality < other._quality ;
00484
00485 }
00486
00487
00488 private:
00489
00490 std::string _text ;
00491 Pixels::ColorDefinition _color ;
00492 RenderQuality _quality ;
00493
00494
00495 } ;
00496
00497
00498
00499
00520 enum RenderCache {
00521 None, GlyphCached, WordCached, TextCached } ;
00522
00523
00524
00548 enum AllowedCachePolicy {
00549 NeverDrop, DropLessRequestedFirst } ;
00550
00551
00552
00591 explicit Font(
00592 bool convertToDisplay = true,
00593 RenderCache cacheSettings = GlyphCached,
00594 AllowedCachePolicy cachePolicy
00595 = DropLessRequestedFirst,
00596 Ceylan::System::Size quota = 0 ) ;
00597
00598
00599
00601 virtual ~Font() throw() ;
00602
00603
00604
00609 virtual RenderingStyle getRenderingStyle() const ;
00610
00611
00612
00628 virtual void setRenderingStyle(
00629 RenderingStyle newStyle ) ;
00630
00631
00632
00644 virtual void setBackgroundColor(
00645 Pixels::ColorDefinition newBackgroundColor ) ;
00646
00647
00648
00658 Pixels::ColorDefinition getBackgroundColor() const ;
00659
00660
00661
00677 virtual Width getWidth( Ceylan::Latin1Char character )
00678 const = 0 ;
00679
00680
00681
00697 virtual SignedWidth getWidthOffset(
00698 Ceylan::Latin1Char character ) const = 0 ;
00699
00700
00701
00713 virtual SignedHeight getHeightAboveBaseline(
00714 Ceylan::Latin1Char character ) const = 0 ;
00715
00716
00717
00735 virtual SignedLength getAdvance(
00736 Ceylan::Latin1Char character ) const = 0 ;
00737
00738
00739
00754 virtual Width getInterGlyphWidth() const ;
00755
00756
00757
00773 virtual Height getHeight() const = 0 ;
00774
00775
00776
00792 virtual SignedHeight getAscent() const = 0 ;
00793
00794
00795
00815 virtual SignedHeight getDescent() const = 0 ;
00816
00817
00818
00827 virtual Height getLineSkip() const = 0 ;
00828
00829
00830
00836 virtual Width getAlineaWidth() const ;
00837
00838
00839
00850 virtual void setAlineaWidth( Width newAlineaWidth ) ;
00851
00852
00853
00864 virtual std::string describeGlyphFor(
00865 Ceylan::Latin1Char character ) const ;
00866
00867
00868
00869
00870
00871
00872
00873
00905 virtual Surface & renderLatin1Glyph(
00906 Ceylan::Latin1Char character,
00907 RenderQuality quality = Solid,
00908 Pixels::ColorDefinition glyphColor = Pixels::White
00909 ) = 0 ;
00910
00911
00912
00937 virtual void blitLatin1Glyph(
00938 Surface & targetSurface,
00939 Coordinate x,
00940 Coordinate y,
00941 Ceylan::Latin1Char character,
00942 RenderQuality quality = Solid,
00943 Pixels::ColorDefinition glyphColor = Pixels::White )
00944 = 0 ;
00945
00946
00947
00969 virtual Surface & renderLatin1Text(
00970 const std::string & text,
00971 RenderQuality quality = Solid,
00972 Pixels::ColorDefinition textColor = Pixels::White
00973 ) ;
00974
00975
00976
01003 virtual void blitLatin1Text(
01004 Surface & targetSurface,
01005 Coordinate x,
01006 Coordinate y,
01007 const std::string & text,
01008 RenderQuality quality = Solid,
01009 Pixels::ColorDefinition textColor = Pixels::White
01010 ) ;
01011
01012
01013
01096 virtual Surface & renderLatin1MultiLineText(
01097 Length width,
01098 Length height,
01099 const std::string & text,
01100 TextIndex & renderIndex,
01101 Coordinate & lastOrdinateUsed,
01102 RenderQuality quality = Solid,
01103 Pixels::ColorDefinition textColor = Pixels::White,
01104 bool justified = true ) ;
01105
01106
01107
01165 virtual void blitLatin1MultiLineText(
01166 Surface & targetSurface,
01167 const UprightRectangle & clientArea,
01168 const std::string & text,
01169 TextIndex & renderIndex,
01170 RenderQuality quality = Solid,
01171 Pixels::ColorDefinition textColor = Pixels::White,
01172 bool justified = true ) ;
01173
01174
01175
01240 virtual void blitLatin1MultiLineText(
01241 Surface & targetSurface,
01242 Coordinate x,
01243 Coordinate y,
01244 Length width,
01245 Length height,
01246 const std::string & text,
01247 TextIndex & renderIndex,
01248 RenderQuality quality = Solid,
01249 Pixels::ColorDefinition textColor = Pixels::White,
01250 bool justified = true ) ;
01251
01252
01253
01266 virtual const std::string toString(
01267 Ceylan::VerbosityLevels level = Ceylan::high )
01268 const ;
01269
01270
01271
01272
01273
01274
01275
01276
01277
01284 static std::string FontPathEnvironmentVariable ;
01285
01286
01287
01297 static Ceylan::System::FileLocator FontFileLocator ;
01298
01299
01300
01308 static std::string InterpretRenderingStyle(
01309 RenderingStyle style ) ;
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01322 static const RenderingStyle Normal ;
01323
01324
01325
01327 static const RenderingStyle Bold ;
01328
01329
01330
01332 static const RenderingStyle Italic ;
01333
01334
01335
01337 static const RenderingStyle Underline ;
01338
01339
01340
01349 static const Ceylan::System::Size
01350 DefaultGlyphCachedQuota ;
01351
01352
01353
01362 static const Ceylan::System::Size
01363 DefaultWordCachedQuota ;
01364
01365
01366
01375 static const Ceylan::System::Size
01376 DefaultTextCachedQuota ;
01377
01378
01379
01385 static const Ceylan::Uint8
01386 DefaultSpaceBasedAlineaWidth ;
01387
01388
01389
01390
01391
01392 protected:
01393
01394
01395
01417 Surface & renderLatin1TextWithWordCached(
01418 const std::string & text,
01419 RenderQuality quality,
01420 Pixels::ColorDefinition textColor ) ;
01421
01422
01423
01445 Surface & renderLatin1TextWithTextCached(
01446 const std::string & text,
01447 RenderQuality quality,
01448 Pixels::ColorDefinition textColor ) ;
01449
01450
01451
01484 virtual void blitLatin1Word(
01485 Surface & targetSurface,
01486 Coordinate x,
01487 Coordinate y,
01488 const std::string & word,
01489 RenderQuality quality = Solid,
01490 Pixels::ColorDefinition wordColor = Pixels::White
01491 ) ;
01492
01493
01494
01531 virtual const Surface & getConstLatin1WordFromCache(
01532 const std::string & word,
01533 RenderQuality quality,
01534 Pixels::ColorDefinition wordColor ) ;
01535
01536
01537
01559 Surface & basicRenderLatin1Text(
01560 const std::string & text,
01561 RenderQuality quality,
01562 Pixels::ColorDefinition textColor ) ;
01563
01564
01565
01566
01572 RenderingStyle _renderingStyle ;
01573
01574
01575
01581 bool _convertToDisplay ;
01582
01583
01584
01586 RenderCache _cacheSettings ;
01587
01588
01589
01599 Ceylan::SmartResourceManager<CharColorQualityKey> *
01600 _glyphCache ;
01601
01602
01603
01613 Ceylan::SmartResourceManager<StringColorQualityKey> *
01614 _textCache ;
01615
01616
01617
01623 Pixels::ColorDefinition _backgroundColor ;
01624
01625
01626
01639 Width _spaceWidth ;
01640
01641
01642
01651 Width _alineaWidth ;
01652
01653
01654
01655
01656 private:
01657
01658
01659
01668 Font( const Font & source ) ;
01669
01670
01671
01680 Font & operator = ( const Font & source ) ;
01681
01682
01683 } ;
01684
01685
01686
01687 }
01688
01689 }
01690
01691 }
01692
01693 }
01694
01695
01696
01697 #endif // OSDL_FONT_H_
01698