Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 244 | chris | 1 | #ifndef __IMAGEFONT_H__ |
| 2 | #define __IMAGEFONT_H__ |
||
| 3 | |||
| 4 | #include "Font.h" |
||
| 5 | #include "DescParser.h" |
||
| 6 | #include "SharedImage.h" |
||
| 7 | |||
| 8 | namespace Sexy |
||
| 9 | { |
||
| 10 | |||
| 11 | class SexyAppBase; |
||
| 12 | class Image; |
||
| 13 | |||
| 14 | class CharData |
||
| 15 | { |
||
| 16 | public: |
||
| 17 | Rect mImageRect; |
||
| 18 | Point mOffset; |
||
| 19 | char mKerningOffsets[256]; |
||
| 20 | int mWidth; |
||
| 21 | int mOrder; |
||
| 22 | |||
| 23 | public: |
||
| 24 | CharData(); |
||
| 25 | }; |
||
| 26 | |||
| 27 | class FontData; |
||
| 28 | |||
| 29 | class FontLayer |
||
| 30 | { |
||
| 31 | public: |
||
| 32 | FontData* mFontData; |
||
| 33 | StringVector mRequiredTags; |
||
| 34 | StringVector mExcludedTags; |
||
| 35 | CharData mCharData[256]; |
||
| 36 | Color mColorMult; |
||
| 37 | Color mColorAdd; |
||
| 38 | SharedImageRef mImage; |
||
| 39 | int mDrawMode; |
||
| 40 | Point mOffset; |
||
| 41 | int mSpacing; |
||
| 42 | int mMinPointSize; |
||
| 43 | int mMaxPointSize; |
||
| 44 | int mPointSize; |
||
| 45 | int mAscent; |
||
| 46 | int mAscentPadding; // How much space is above the avg uppercase char |
||
| 47 | int mHeight; // |
||
| 48 | int mDefaultHeight; // Max height of font character image rects |
||
| 49 | int mLineSpacingOffset; // This plus height should get added between lines |
||
| 50 | int mBaseOrder; |
||
| 51 | |||
| 52 | public: |
||
| 53 | FontLayer(FontData* theFontData); |
||
| 54 | FontLayer(const FontLayer& theFontLayer); |
||
| 55 | }; |
||
| 56 | |||
| 57 | typedef std::list<FontLayer> FontLayerList; |
||
| 58 | typedef std::map<std::string, FontLayer*> FontLayerMap; |
||
| 59 | typedef std::list<Rect> RectList; |
||
| 60 | |||
| 61 | class FontData : public DescParser |
||
| 62 | { |
||
| 63 | public: |
||
| 64 | bool mInitialized; |
||
| 65 | int mRefCount; |
||
| 66 | SexyAppBase* mApp; |
||
| 67 | |||
| 68 | int mDefaultPointSize; |
||
| 69 | uchar mCharMap[256]; |
||
| 70 | FontLayerList mFontLayerList; |
||
| 71 | FontLayerMap mFontLayerMap; |
||
| 72 | |||
| 73 | std::string mSourceFile; |
||
| 74 | std::string mFontErrorHeader; |
||
| 75 | |||
| 76 | public: |
||
| 77 | virtual bool Error(const std::string& theError); |
||
| 78 | |||
| 79 | bool GetColorFromDataElement(DataElement *theElement, Color &theColor); |
||
| 80 | bool DataToLayer(DataElement* theSource, FontLayer** theFontLayer); |
||
| 81 | virtual bool HandleCommand(const ListDataElement& theParams); |
||
| 82 | |||
| 83 | public: |
||
| 84 | FontData(); |
||
| 85 | virtual ~FontData(); |
||
| 86 | |||
| 87 | void Ref(); |
||
| 88 | void DeRef(); |
||
| 89 | |||
| 90 | bool Load(SexyAppBase* theSexyApp, const std::string& theFontDescFileName); |
||
| 91 | bool LoadLegacy(Image* theFontImage, const std::string& theFontDescFileName); |
||
| 92 | }; |
||
| 93 | |||
| 94 | class ActiveFontLayer |
||
| 95 | { |
||
| 96 | public: |
||
| 97 | FontLayer* mBaseFontLayer; |
||
| 98 | |||
| 99 | Image* mScaledImage; |
||
| 100 | bool mOwnsImage; |
||
| 101 | Rect mScaledCharImageRects[256]; |
||
| 102 | |||
| 103 | public: |
||
| 104 | ActiveFontLayer(); |
||
| 105 | ActiveFontLayer(const ActiveFontLayer& theActiveFontLayer); |
||
| 106 | virtual ~ActiveFontLayer(); |
||
| 107 | }; |
||
| 108 | |||
| 109 | typedef std::list<ActiveFontLayer> ActiveFontLayerList; |
||
| 110 | |||
| 111 | class RenderCommand |
||
| 112 | { |
||
| 113 | public: |
||
| 114 | Image* mImage; |
||
| 115 | int mDest[2]; |
||
| 116 | int mSrc[4]; |
||
| 117 | int mMode; |
||
| 118 | Color mColor; |
||
| 119 | RenderCommand* mNext; |
||
| 120 | }; |
||
| 121 | |||
| 122 | typedef std::multimap<int, RenderCommand> RenderCommandMap; |
||
| 123 | |||
| 124 | class ImageFont : public Font |
||
| 125 | { |
||
| 126 | public: |
||
| 127 | FontData* mFontData; |
||
| 128 | int mPointSize; |
||
| 129 | StringVector mTagVector; |
||
| 130 | |||
| 131 | bool mActiveListValid; |
||
| 132 | ActiveFontLayerList mActiveLayerList; |
||
| 133 | double mScale; |
||
| 134 | bool mForceScaledImagesWhite; |
||
| 135 | |||
| 136 | public: |
||
| 137 | virtual void GenerateActiveFontLayers(); |
||
| 138 | virtual void DrawStringEx(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect* theClipRect, RectList* theDrawnAreas, int* theWidth); |
||
| 139 | |||
| 140 | public: |
||
| 141 | ImageFont(SexyAppBase* theSexyApp, const std::string& theFontDescFileName); |
||
| 142 | ImageFont(Image *theFontImage); // for constructing your own image font without a file descriptor |
||
| 143 | ImageFont(const ImageFont& theImageFont); |
||
| 144 | virtual ~ImageFont(); |
||
| 145 | |||
| 146 | // Deprecated |
||
| 147 | ImageFont(Image* theFontImage, const std::string& theFontDescFileName); |
||
| 148 | //ImageFont(const ImageFont& theImageFont, Image* theImage); |
||
| 149 | |||
| 150 | virtual int CharWidth(char theChar); |
||
| 151 | virtual int CharWidthKern(char theChar, char thePrevChar); |
||
| 152 | virtual int StringWidth(const SexyString& theString); |
||
| 153 | virtual void DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect); |
||
| 154 | |||
| 155 | virtual Font* Duplicate(); |
||
| 156 | |||
| 157 | virtual void SetPointSize(int thePointSize); |
||
| 158 | virtual int GetPointSize(); |
||
| 159 | virtual void SetScale(double theScale); |
||
| 160 | virtual int GetDefaultPointSize(); |
||
| 161 | virtual bool AddTag(const std::string& theTagName); |
||
| 162 | virtual bool RemoveTag(const std::string& theTagName); |
||
| 163 | virtual bool HasTag(const std::string& theTagName); |
||
| 164 | virtual std::string GetDefine(const std::string& theName); |
||
| 165 | |||
| 166 | virtual void Prepare(); |
||
| 167 | }; |
||
| 168 | |||
| 169 | } |
||
| 170 | |||
| 171 | #endif //__IMAGEFONT_H__ |