summaryrefslogtreecommitdiff
path: root/tvision/include/tv/fontcoll.h
blob: 0713f8bdc12ae06cbff7d009cb6d03c62c6ff1f9 (plain)
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
/**[txh]********************************************************************

  Copyright 1996-2002 by Salvador Eduardo Tropea (SET)
  This file is covered by the GPL license.

  Module: TVFontCollection

***************************************************************************/

#if defined(Uses_TVFontCollection) && !defined(TVFontCollection_Included)
#define TVFontCollection_Included 1

struct TVBitmapFont
{
 int first, last; // Currently is barely supported. The range includes both ends.
 unsigned lines;       // Height
 unsigned width;       // Width in pixels
 // --- Not in disk:
 int wBytes;      // Width in bytes. To avoid computing it all the time
 uchar *fontFull; // last-first+1 chars
 uchar *font;     // 256 according to the code page
};

struct TVBitmapFontDesc
{
 const char *name;
 const char *file;
 TStringCollection *sizes;
};

class CLY_EXPORT TVBitmapFontDescCol : public TStringCollection
{
public:
 TVBitmapFontDescCol() : TStringCollection(8,4) {}
 virtual void  freeItem(void *item);
 virtual void *keyOf(void *item);
};

class CLY_EXPORT TVBitmapFontDescLBox : public TSortedListBox
{
public:
 TVBitmapFontDescLBox(const TRect& bounds, ushort aNumCols,
                      TScrollBar *aHScrollBar, TScrollBar *aVScrollBar,
                      Boolean aCenterOps=False) :
  TSortedListBox(bounds,aNumCols,aHScrollBar,aVScrollBar,aCenterOps) {}
 virtual void getText(char *dest, ccIndex item, short maxChars);
};

struct TVBitmapFontSize
{
 unsigned w,h;
};

class CLY_EXPORT TVBitmapFontSizeCol : public TStringCollection
{
public:
 TVBitmapFontSizeCol() : TStringCollection(3,3) {}
 virtual int compare(void *key1, void *key2);
 // do not use the default delete[]
 virtual void freeItem(void *item) { delete (TVBitmapFontSize *)item; }
};

class CLY_EXPORT TVBitmapFontSizeLBox : public TSortedListBox
{
public:
 TVBitmapFontSizeLBox(const TRect& bounds, ushort aNumCols,
                      TScrollBar *aHScrollBar, TScrollBar *aVScrollBar,
                      Boolean aCenterOps=False) :
  TSortedListBox(bounds,aNumCols,aHScrollBar,aVScrollBar,aCenterOps) {}
 virtual void getText(char *dest, ccIndex item, short maxChars);
};

class CLY_EXPORT TVFontCollection : public TNSCollection
{
public:
 TVFontCollection(const char *file, int cp);
 ~TVFontCollection();

 virtual void freeItem(void *item);
 static void ReduceOne(uchar *dest, uchar *ori, int height, int wBytes, int num=256);
 static void EnlargeOne(uchar *dest, uchar *ori, int height, int wBytes, int num=256);
 uchar *GetFont(int width, int height);
 void   SetCodePage(int id);
 int    GetError() { return error; }
 const char *GetFileName() { return fileName; }
 const char *GetFontName() { return fontName; }
 static TVBitmapFontDescCol *CreateListOfFonts(const char *dir, unsigned wmin=0,
          unsigned wmax=256, unsigned hmin=0, unsigned hmax=256);
 static void Size2Str(char *buffer, unsigned w, unsigned h);
 static void Str2Size(const char *buffer, unsigned &w, unsigned &h);

protected:
 static Boolean CheckForLines(void *item, void *arg);
 static void    CreateFont(void *item, void *arg);
 const static char Signature[];
 const static char SFTExtension[];
 static int      CheckSignature(FILE *f);
 static char    *ReadName(FILE *f);
 static void     ReadVersionNum(FILE *f, int *version, int *numfonts);
 static unsigned ReadFontInfo(FILE *f, int version, TVBitmapFont *p);
 static void     Swap(int *value);
 static void     Swap(unsigned *value) { Swap((int *)value); };
 static void     Swap(uint16 *value);
 // !=0 if the file was created with the reverse endian style.
 // Only used during load.
 static int      invertEndian;
 int   error;
 char *fileName;
 char *fontName;
};

#endif