admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * This file is part of xlslib -- A multiplatform, C/C++ library
 * for dynamic generation of Excel(TM) files.
 *
 * Copyright 2004 Yeico S. A. de C. V. All Rights Reserved.
 * Copyright 2008-2009 David Hoerl All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
#ifndef FONT_H
#define FONT_H
 
#include "../common/xlsys.h"
#include "../common/systype.h"
 
#include "../xlslib/colors.h"    // need enum values
 
 
// #include "common/xls_pshpack2.h"
 
namespace xlslib_core
{
    // Bold style most used values
    // (it can be a number of some range. See Documentation for details):
#define FONT_BOLDNESS_BOLD            700
#define FONT_BOLDNESS_HALF            550
#define FONT_BOLDNESS_NORMAL        400
#define FONT_BOLDNESS_DOUBLE        800
 
    typedef enum
    {
        BOLDNESS_BOLD = 0,
        BOLDNESS_HALF,
        BOLDNESS_NORMAL,
        BOLDNESS_DOUBLE
    } boldness_option_t;
 
 
    // Super/subscript field option values
#define FONT_SCRIPT_NONE            0x0000
#define FONT_SCRIPT_SUPER            0x0001
#define FONT_SCRIPT_SUB                0x0002
 
    typedef enum
    {
        SCRIPT_NONE = 0,
        SCRIPT_SUPER,
        SCRIPT_SUB
    } script_option_t;
 
    // Underline field option values:
#define FONT_UNDERLINE_NONE            0x00
#define FONT_UNDERLINE_SINGLE        0x01
#define FONT_UNDERLINE_DOUBLE        0x02
#define FONT_UNDERLINE_SINGLEACC    0x21
#define FONT_UNDERLINE_DOUBLEACC    0x22
 
    typedef enum
    {
        UNDERLINE_NONE = 0,
        UNDERLINE_SINGLE,
        UNDERLINE_DOUBLE,
        UNDERLINE_SINGLEACC,
        UNDERLINE_DOUBLEACC
    } underline_option_t;
 
 
 
    // The following are default values used when the font's
    // constructor is called without args:
#define FONT_DFLT_FAMILY            0x00
// NONE (don't know, don't care)
#define FONT_DFLT_CHARSET            0x01
// 0 == ANSI Latin, 1 == System Default (this was 0x00 before 12/2008)
#define FONT_DFLT_HEIGHT            0x00c8
#define FONT_DFLT_ATTRIBUTES        0x0000
#define FONT_DFLT_PALETTE            0x7fff
// See Palette record - this is a special flag meaning the window color
#define FONT_DFLT_FONTNAME            std::string("Verdana")
// Was Arial before 12/2008
 
#define FONT_RESERVED                0x00
 
    // The font-record field offsets:
#define FONT_OFFSET_HEIGHT           4
#define FONT_OFFSET_ATTRIBUTES       6
#define FONT_OFFSET_PALETTE          8
#define FONT_OFFSET_BOLDSTYLE        10
#define FONT_OFFSET_SCRIPT            12
#define FONT_OFFSET_UNDERLINE        14
#define FONT_OFFSET_FAMILY            15
#define FONT_OFFSET_CHARSET            16
#define FONT_OFFSET_NAMELENGTH        18
#define FONT_OFFSET_NAME            19
 
 
    // The attribute bit or-masks:
#define FONT_ATTR_BOLD                0x0001
// documented as 'reserved' in the Microsoft Excel 2003 documentation!
#define FONT_ATTR_ITALIC            0x0002
#define FONT_ATTR_UNDERLINED        0x0004
// documented as 'reserved' in the Microsoft Excel 2003 documentation!
#define FONT_ATTR_STRIKEOUT            0x0008
#define FONT_ATTR_OUTLINEMACH        0x0010
#define FONT_ATTR_SHADOWMACH        0x0020
#define FONT_ATTR_CONDENSED            0x00c0
// documented as 'reserved' in the Microsoft Excel 2003 documentation!
#define FONT_ATTR_EXTENDED            0x0080
// documented as 'reserved' in the Microsoft Excel 2003 documentation!
#define FONT_ATTR_UNUSED            0xff00
// documented as 'reserved' in the Microsoft Excel 2003 documentation!
 
    /*
     ******************************
     * CFont class declaration
     ******************************
     */
 
    typedef struct
    {
        std::string name;
        unsigned16_t index;
        unsigned16_t height;
        boldness_option_t boldstyle;
        underline_option_t underline;
        script_option_t script;
        color_name_t color;
        unsigned16_t attributes;
        unsigned8_t family;
        unsigned8_t charset;
    } font_init_t;
 
    class CGlobalRecords;
 
    class font_i
    {
    public:
        font_i() { }
        virtual ~font_i() { }
 
        virtual void fontname(const std::string& fntname) = 0;
        virtual void fontheight(unsigned16_t fntheight) = 0;
        virtual void fontbold(boldness_option_t fntboldness) = 0;
        virtual void fontunderline(underline_option_t fntunderline) = 0;
        virtual void fontscript(script_option_t fntscript) = 0;
        virtual void fontcolor(color_name_t fntcolor) = 0;
        virtual void fontcolor(unsigned8_t fntcolor) = 0;
        virtual void fontitalic(bool italic) = 0;
        virtual void fontstrikeout(bool so) = 0;
        virtual void fontoutline(bool ol) = 0;
        virtual void fontshadow(bool sh) = 0;
    };
 
    class font_t
    {
        friend class CFont;
        friend class CGlobalRecords;
        friend class workbook;
 
    private:
        font_t(CGlobalRecords& gRecords);
        font_t(const font_t& right);
        font_t(CGlobalRecords& gRecords,
               unsigned16_t index, const std::string& name,
               unsigned16_t height, boldness_option_t boldstyle,
               underline_option_t underline, script_option_t script,
               color_name_t color, unsigned16_t attributes,
               unsigned8_t family, unsigned8_t charset);
        virtual ~font_t() {}
        /* MSVC2005: C4512: 'xlslib_core::font_t' : assignment operator could not be generated */
        font_t &operator =(const font_t &src);
 
        /* FONT Index wrappers*/
        void      SetIndex(unsigned16_t fntidx);
 
    public:
        static font_t* fontDup(const font_t* orig)
        {
            font_t*    font = new font_t(*orig);
            return font;
        }
 
        void MarkUsed();
        void UnMarkUsed();
        unsigned32_t Usage() const;
        unsigned16_t GetIndex(void) const;
 
        /* FONT Index wrappers*/
        void   SetName(const std::string& fntname);
        const std::string& GetName(void) const;
 
        /* FONT height wrappers*/
        void         SetHeight(unsigned16_t fntheight);
        unsigned16_t GetHeight(void) const;
 
        /* FONT boldstyle wrappers*/
        void SetBoldStyle(boldness_option_t fntboldness);
        unsigned16_t GetBoldStyle(void) const;
 
        /* FONT underline wrappers*/
        void        SetUnderlineStyle(underline_option_t fntunderline);
        unsigned8_t GetUnderlineStyle(void) const;
 
        /* FONT script wrappers*/
        void         SetScriptStyle(script_option_t fntscript);
        unsigned16_t GetScriptStyle(void) const;
 
        /* FONT script wrappers*/
        void  SetColor(color_name_t fntcolor);
        void  SetColor(unsigned8_t fntcolor);
        unsigned16_t GetColorIdx(void) const;
 
 
        void SetItalic(bool italic);
        bool GetItalic() const;
 
        void SetStrikeout(bool so);
        bool GetStrikeout() const;
 
        // Mac only (old Mac???)
        void SetOutline(bool ol);
        bool GetOutline() const;
        void SetShadow(bool sh);
        bool GetShadow() const;
 
        // Miscellaneous: for super users
        void        SetFamily(unsigned8_t fam);
        unsigned8_t GetFamily(void) const;
 
        void         SetCharset(unsigned8_t chrset);
        unsigned8_t  GetCharset(void) const;
 
        //void operator=(font_t& right);
 
#if 0 // [i_a] xls C i/f & C++ facade export these?
    private:
#else
    public:
#endif
        /* FONT  attributes wrappers */
#if defined(DEPRECATED)
        /* [i_a] can cause reserved/illegal attribute bit combo's to be set; use SetOutline(), etc. instead. */
        void SetAttributes(unsigned16_t attr);
#endif
        unsigned16_t GetAttributes(void) const;
 
    public:
        CGlobalRecords& GetGlobalRecords(void) const { return m_GlobalRecords; }
 
    private:
        CGlobalRecords&   m_GlobalRecords;
        std::string    name;
        unsigned16_t index;
 
        unsigned16_t height;
        unsigned16_t boldstyle;
        unsigned16_t script;
        unsigned16_t attributes;
        unsigned16_t color;             // must handle 0x7FFF special font flag
        unsigned8_t    underline;
        unsigned8_t family;
        unsigned8_t charset;
 
        unsigned32_t m_usage_counter;
 
        static const unsigned16_t BOLD_OPTION_TABLE[];
        static const unsigned16_t SCRIPT_OPTION_TABLE[];
        static const unsigned8_t UNDERLINE_OPTION_TABLE[];
        static const unsigned8_t COLOR_OPTION_TABLE[];
 
        void _SetBoldStyle(unsigned16_t fntboldness);
    };
 
    typedef std::vector<xlslib_core::font_t* XLSLIB_DFLT_ALLOCATOR> Font_Vect_t;
    typedef Font_Vect_t::iterator Font_Vect_Itor_t;
 
 
    // forward ref
    class CDataStorage;
 
    class CFont : public CRecord
    {
        friend class CDataStorage;
 
    protected:
        CFont(CDataStorage &datastore,
              const font_t* fontdef);
    private:
        virtual ~CFont();
    };
}
 
// #include "common/xls_poppack.h"
 
#endif