| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | // |
| 17 | // Based on code from ScummVM - Scumm Interpreter |
| 18 | // Copyright (C) 2002-2004 The ScummVM project |
| 19 | //============================================================================ |
| 20 | |
| 21 | #ifndef FONT_HXX |
| 22 | #define FONT_HXX |
| 23 | |
| 24 | #include "bspf.hxx" |
| 25 | |
| 26 | struct BBX |
| 27 | { |
| 28 | Int8 w; |
| 29 | Int8 h; |
| 30 | Int8 x; |
| 31 | Int8 y; |
| 32 | }; |
| 33 | |
| 34 | /* builtin C-based proportional/fixed font structure */ |
| 35 | /* based on The Microwindows Project http://microwindows.org */ |
| 36 | struct FontDesc |
| 37 | { |
| 38 | const char* const name; /* font name */ |
| 39 | int maxwidth; /* max width in pixels */ |
| 40 | int height; /* height in pixels */ |
| 41 | int fbbw, fbbh, fbbx, fbby; /* max bounding box */ |
| 42 | int ascent; /* ascent (baseline) height */ |
| 43 | int firstchar; /* first character in bitmap */ |
| 44 | int size; /* font size in glyphs */ |
| 45 | const uInt16* bits; /* 16-bit right-padded bitmap data */ |
| 46 | const uInt32* offset; /* offsets into bitmap data*/ |
| 47 | const uInt8* width; /* character widths or nullptr if fixed */ |
| 48 | const BBX* bbx; /* character bounding box or nullptr if fixed */ |
| 49 | int defaultchar; /* default char (not glyph index) */ |
| 50 | long bits_size; /* # words of bitmap_t bits */ |
| 51 | }; |
| 52 | |
| 53 | namespace GUI { |
| 54 | |
| 55 | class Font |
| 56 | { |
| 57 | public: |
| 58 | explicit Font(const FontDesc& desc); |
| 59 | |
| 60 | const FontDesc& desc() const { return myFontDesc; } |
| 61 | |
| 62 | int getFontHeight() const { return myFontDesc.height; } |
| 63 | int getLineHeight() const { return myFontDesc.height + 2; } |
| 64 | int getMaxCharWidth() const { return myFontDesc.maxwidth; } |
| 65 | |
| 66 | int getCharWidth(uInt8 chr) const; |
| 67 | |
| 68 | int getStringWidth(const string& str) const; |
| 69 | |
| 70 | private: |
| 71 | FontDesc myFontDesc; |
| 72 | |
| 73 | private: |
| 74 | // Following constructors and assignment operators not supported |
| 75 | Font() = delete; |
| 76 | Font(const Font&) = delete; |
| 77 | Font(Font&&) = delete; |
| 78 | Font& operator=(const Font&) = delete; |
| 79 | Font& operator=(Font&&) = delete; |
| 80 | }; |
| 81 | |
| 82 | } // namespace GUI |
| 83 | |
| 84 | #endif |
| 85 | |