1 /** @file lvfntman.h 2 @brief font manager interface 3 4 CoolReader Engine 5 6 (c) Vadim Lopatin, 2000-2006 7 8 This source code is distributed under the terms of 9 GNU General Public License. 10 11 See LICENSE file for details. 12 13 */ 14 15 #ifndef __LV_FNT_MAN_H_INCLUDED__ 16 #define __LV_FNT_MAN_H_INCLUDED__ 17 18 #include <stdlib.h> 19 #include "crsetup.h" 20 #include "lvstring.h" 21 #include "lvstring32collection.h" 22 #include "lvfont.h" 23 24 /// font manager interface class 25 class LVFontManager { 26 protected: 27 bool _allowKerning; 28 int _antialiasMode; 29 shaping_mode_t _shapingMode; 30 hinting_mode_t _hintingMode; 31 public: 32 /// garbage collector frees unused fonts 33 virtual void gc() = 0; 34 35 /// returns most similar font 36 virtual LVFontRef GetFont(int size, int weight, bool italic, css_font_family_t family, lString8 typeface, 37 int features=0, int documentId = -1, bool useBias=false) = 0; 38 39 /// set fallback font face list semicolon separated (returns true if any font is found) SetFallbackFontFaces(lString8 faces)40 virtual bool SetFallbackFontFaces( lString8 faces ) { 41 CR_UNUSED(faces); 42 return false; 43 } 44 45 /// get fallback font face (returns empty string if no fallback font is set) 46 virtual lString8 GetFallbackFontFace(int index = 0) { 47 CR_UNUSED(index); 48 return lString8::empty_str; 49 } 50 51 /// get fallback font faces list (returns empty string list collection if no fallback fonts is set) GetFallbackFontFaces()52 virtual lString8 GetFallbackFontFaces() { return lString8::empty_str; } 53 54 /// get count of fallback fonts GetFallbackFontCount()55 virtual int GetFallbackFontCount() { return 0; } 56 57 /// returns fallback font for specified size 58 virtual LVFontRef GetFallbackFont(int size, int index=0) { 59 CR_UNUSED2(size, index); 60 return LVFontRef(); 61 } 62 /// returns fallback font for specified size, weight and italic 63 virtual LVFontRef GetFallbackFont(int size, int weight=400, bool italic=false, int index=0 ) { 64 CR_UNUSED4(size, weight, italic, index); 65 return LVFontRef(); 66 } 67 /// registers font by name 68 virtual bool RegisterFont( lString8 name ) = 0; 69 /// registers font by name and face RegisterExternalFont(lString32,lString8,bool,bool)70 virtual bool RegisterExternalFont(lString32 /*name*/, lString8 /*face*/, bool /*bold*/, bool /*italic*/) { return false; } 71 /// registers document font 72 virtual bool RegisterDocumentFont(int,LVContainerRef,lString32,lString8,bool,bool)73 RegisterDocumentFont(int /*documentId*/, LVContainerRef /*container*/, lString32 /*name*/, 74 lString8 /*face*/, bool /*bold*/, bool /*italic*/) { return false; } 75 76 /// unregisters all document fonts UnregisterDocumentFonts(int)77 virtual void UnregisterDocumentFonts(int /*documentId*/) {} 78 79 /// initializes font manager 80 virtual bool Init(lString8 path) = 0; 81 82 /// get count of registered fonts 83 virtual int GetFontCount() = 0; 84 85 /// get hash of installed fonts and fallback font GetFontListHash(int)86 virtual lUInt32 GetFontListHash(int /*documentId*/) { return 0; } 87 88 /// clear glyph cache clearGlyphCache()89 virtual void clearGlyphCache() {} 90 91 /// get antialiasing mode GetAntialiasMode()92 virtual int GetAntialiasMode() { return _antialiasMode; } 93 94 /// set antialiasing mode SetAntialiasMode(int mode)95 virtual void SetAntialiasMode(int mode) { 96 _antialiasMode = mode; 97 gc(); 98 clearGlyphCache(); 99 } 100 101 /// get kerning mode: true==ON, false=OFF GetKerning()102 virtual bool GetKerning() { return _allowKerning; } 103 104 /// get kerning mode: true==ON, false=OFF SetKerning(bool kerningEnabled)105 virtual void SetKerning(bool kerningEnabled) { 106 _allowKerning = kerningEnabled; 107 gc(); 108 clearGlyphCache(); 109 } 110 111 /// get shaping mode GetShapingMode()112 virtual shaping_mode_t GetShapingMode() { return _shapingMode; } 113 /// set shaping mode SetShapingMode(shaping_mode_t mode)114 virtual void SetShapingMode( shaping_mode_t mode ) { _shapingMode = mode; gc(); clearGlyphCache(); } 115 /// constructor LVFontManager()116 LVFontManager() : _allowKerning(false), _antialiasMode(font_aa_all), _shapingMode(SHAPING_MODE_FREETYPE), _hintingMode(HINTING_MODE_AUTOHINT) { } 117 /// destructor ~LVFontManager()118 virtual ~LVFontManager() { } 119 /// returns available typefaces getFaceList(lString32Collection &)120 virtual void getFaceList( lString32Collection & ) { } 121 /// returns available font files getFontFileNameList(lString32Collection &)122 virtual void getFontFileNameList( lString32Collection & ) { } 123 /// check font language compatibility checkFontLangCompat(const lString8 & typeface,const lString8 & langCode)124 virtual bool checkFontLangCompat(const lString8 &typeface, const lString8 &langCode) { return true; } 125 /// returns first found face from passed list, or return face for font found by family only 126 virtual lString8 findFontFace(lString8 commaSeparatedFaceList, css_font_family_t fallbackByFamily); 127 /// fills array with list of available gamma levels 128 virtual void GetGammaLevels(LVArray<double> dst); 129 /// returns current gamma level index 130 virtual int GetGammaIndex(); 131 /// sets current gamma level index 132 virtual void SetGammaIndex( int gammaIndex ); 133 /// returns current gamma level 134 virtual double GetGamma(); 135 /// sets current gamma level 136 virtual void SetGamma( double gamma ); 137 /// sets current hinting mode SetHintingMode(hinting_mode_t)138 virtual void SetHintingMode(hinting_mode_t /*mode*/) { } 139 /// returns current hinting mode GetHintingMode()140 virtual hinting_mode_t GetHintingMode() { return HINTING_MODE_AUTOHINT; } 141 /// SetAlias(lString8 alias,lString8 facename,int id,bool italic,bool bold)142 virtual bool SetAlias(lString8 alias, lString8 facename, int id, bool italic, bool bold) { 143 CR_UNUSED5(alias, facename, id, italic, bold); 144 return false; 145 } 146 /// set as preferred font with the given bias to add in CalcMatch algorithm 147 virtual bool SetAsPreferredFontWithBias( lString8 face, int bias, bool clearOthersBias=true ) { 148 CR_UNUSED(face); 149 return false; 150 } 151 }; 152 153 #define LVFONT_TRANSFORM_EMBOLDEN 1 154 155 /// create transform for font 156 LVFontRef LVCreateFontTransform(LVFontRef baseFont, int transformFlags); 157 158 /// current font manager pointer 159 extern LVFontManager *fontMan; 160 161 /// initializes font manager 162 bool InitFontManager(lString8 path); 163 164 /// deletes font manager 165 bool ShutdownFontManager(); 166 167 LVFontRef LoadFontFromFile(const char *fname); 168 169 #endif //__LV_FNT_MAN_H_INCLUDED__ 170