ScummVM API documentation
wfn_font.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // WFNFont - an immutable AGS font object.
25 //
26 //-----------------------------------------------------------------------------
27 //
28 // WFN format:
29 // - signature ( 15 )
30 // - offsets table offset ( 2 )
31 // - characters table (for unknown number of char items):
32 // - width ( 2 )
33 // - height ( 2 )
34 // - pixel bits ( (width / 8 + 1) * height )
35 // - any unknown data
36 // - offsets table (for X chars):
37 // - character offset ( 2 )
38 //
39 // NOTE: unfortunately, at the moment the format does not provide means to
40 // know the number of supported characters for certain, and the size of the
41 // data (file) is used to determine that.
42 //
43 //=============================================================================
44 
45 #ifndef AGS_SHARED_FONT_WFN_FONT_H
46 #define AGS_SHARED_FONT_WFN_FONT_H
47 
48 #include "common/std/vector.h"
49 #include "ags/shared/core/types.h"
50 
51 namespace AGS3 {
52 
53 namespace AGS {
54 namespace Shared {
55 class Stream;
56 } // namespace Shared
57 } // namespace AGS
58 
59 enum WFNError {
60  kWFNErr_NoError,
61  kWFNErr_BadSignature,
62  kWFNErr_BadTableAddress,
63  kWFNErr_HasBadCharacters
64 };
65 
66 struct WFNChar {
67  uint16_t Width;
68  uint16_t Height;
69  const uint8_t *Data;
70 
71  WFNChar();
72 
73  inline size_t GetRowByteCount() const {
74  return (Width + 7) / 8;
75  }
76 
77  inline size_t GetRequiredPixelSize() const {
78  return GetRowByteCount() * Height;
79  }
80 
81  // Ensure character's width & height fit in given number of pixel bytes
82  void RestrictToBytes(size_t bytes);
83 };
84 
85 
86 class WFNFont {
87 public:
88  inline uint16_t GetCharCount() const {
89  return static_cast<uint16_t>(_refs.size());
90  }
91 
92  // Get WFN character for the given code; if the character is missing, returns empty character
93  const WFNChar &GetChar(uint8_t code) const;
94 
95  void Clear();
96  // Reads WFNFont object, using data_size bytes from stream; if data_size = 0,
97  // the available stream's length is used instead. Returns error code.
98  WFNError ReadFromFile(AGS::Shared::Stream *in, const soff_t data_size = 0);
99 
100 protected:
101  std::vector<const WFNChar *> _refs; // reference array, contains pointers to elements of _items
102  std::vector<WFNChar> _items; // actual character items
103  std::vector<uint8_t> _pixelData; // pixel data array
104 };
105 
106 } // namespace AGS3
107 
108 #endif
Definition: achievements_tables.h:27
Definition: vector.h:39
Definition: wfn_font.h:66
Definition: wfn_font.h:86
Definition: stream.h:52
Definition: ags.h:40