1 //------------------------------------------------------------------------------ 2 // emFontCache.h 3 // 4 // Copyright (C) 2009,2016 Oliver Hamann. 5 // 6 // Homepage: http://eaglemode.sourceforge.net/ 7 // 8 // This program is free software: you can redistribute it and/or modify it under 9 // the terms of the GNU General Public License version 3 as published by the 10 // Free Software Foundation. 11 // 12 // This program is distributed in the hope that it will be useful, but WITHOUT 13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for 15 // more details. 16 // 17 // You should have received a copy of the GNU General Public License version 3 18 // along with this program. If not, see <http://www.gnu.org/licenses/>. 19 //------------------------------------------------------------------------------ 20 21 #ifndef emFontCache_h 22 #define emFontCache_h 23 24 #ifndef emModel_h 25 #include <emCore/emModel.h> 26 #endif 27 28 #ifndef emImage_h 29 #include <emCore/emImage.h> 30 #endif 31 32 #ifndef emThread_h 33 #include <emCore/emThread.h> 34 #endif 35 36 37 class emFontCache : public emModel { 38 39 public: 40 41 // This class is only for internal use by emPainter. 42 43 static emRef<emFontCache> Acquire(emRootContext & rootContext); 44 45 void GetChar( 46 int unicode, double tgtW, double tgtH, emImage * * ppImg, 47 int * pImgX, int * pImgY, int * pImgW, int * pImgH 48 ); 49 50 protected: 51 52 emFontCache(emContext & context, const emString & name); 53 virtual ~emFontCache(); 54 55 virtual bool Cycle(); 56 57 private: 58 59 struct Entry { 60 emString FilePath; 61 int FirstCode, LastCode; 62 int CharWidth, CharHeight; 63 bool Loaded; 64 bool LoadedInEarlierTimeSlice; 65 int ColumnCount; 66 emUInt64 LastUseClock; 67 emUInt64 MemoryNeed; 68 emImage Image; 69 }; 70 71 void LoadEntry(Entry * entry); 72 void UnloadEntry(Entry * entry); 73 void LoadFontDir(); 74 void Clear(); 75 76 emString FontDir; 77 emImage ImgUnknownChar; 78 emImage ImgCostlyChar; 79 emThreadMutex Mutex; 80 bool SomeLoadedNewly; 81 Entry * * EntryArray; 82 int EntryCount; 83 double Stress; 84 emUInt64 Clock; 85 emUInt64 LastLoadTime; 86 emUInt64 MemoryUse; 87 88 static const double StressHalfLifePeriodMS; 89 static const double StressSensitivity; 90 static const unsigned MaxMegabytes; 91 }; 92 93 94 #endif 95