You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**[txh]********************************************************************
  2. Copyright 1996-2003 by Salvador Eduardo Tropea (SET)
  3. This file is covered by the GPL license.
  4. Module: TVFontCollection
  5. ***************************************************************************/
  6. #if defined(Uses_TVFontCollection) && !defined(TVFontCollection_Included)
  7. #define TVFontCollection_Included 1
  8. struct TVBitmapFont
  9. {
  10. int first, last; // Currently is barely supported. The range includes both ends.
  11. unsigned lines; // Height
  12. unsigned width; // Width in pixels
  13. // --- Not in disk:
  14. int wBytes; // Width in bytes. To avoid computing it all the time
  15. uchar *fontFull; // last-first+1 chars
  16. uchar *font; // 256 according to the code page
  17. };
  18. struct TVBitmapFontDesc
  19. {
  20. const char *name;
  21. const char *file;
  22. TStringCollection *sizes;
  23. };
  24. class TVBitmapFontDescCol : public TStringCollection
  25. {
  26. public:
  27. TVBitmapFontDescCol() : TStringCollection(8,4) {}
  28. virtual void freeItem(void *item);
  29. virtual void *keyOf(void *item);
  30. };
  31. class TVBitmapFontDescLBox : public TSortedListBox
  32. {
  33. public:
  34. TVBitmapFontDescLBox(const TRect& bounds, ushort aNumCols,
  35. TScrollBar *aHScrollBar, TScrollBar *aVScrollBar) :
  36. TSortedListBox(bounds,aNumCols,aHScrollBar,aVScrollBar) {}
  37. virtual void getText(char *dest, ccIndex item, short maxChars);
  38. };
  39. struct TVBitmapFontSize
  40. {
  41. unsigned w,h;
  42. };
  43. class TVBitmapFontSizeCol : public TStringCollection
  44. {
  45. public:
  46. TVBitmapFontSizeCol() : TStringCollection(3,3) {}
  47. virtual int compare(void *key1, void *key2);
  48. };
  49. class TVBitmapFontSizeLBox : public TSortedListBox
  50. {
  51. public:
  52. TVBitmapFontSizeLBox(const TRect& bounds, ushort aNumCols,
  53. TScrollBar *aHScrollBar, TScrollBar *aVScrollBar) :
  54. TSortedListBox(bounds,aNumCols,aHScrollBar,aVScrollBar) {}
  55. virtual void getText(char *dest, ccIndex item, short maxChars);
  56. };
  57. class TVFontCollection : public TNSCollection
  58. {
  59. public:
  60. TVFontCollection(const char *file, int cp);
  61. ~TVFontCollection();
  62. virtual void freeItem(void *item);
  63. static void ReduceOne(uchar *dest, uchar *ori, int height, int wBytes, int num=256);
  64. static void EnlargeOne(uchar *dest, uchar *ori, int height, int wBytes, int num=256);
  65. uchar *GetFont(int width, int height);
  66. uchar *GetFontFull(int width, int height, int &first, int &last);
  67. void SetCodePage(int id);
  68. int GetError() { return error; }
  69. const char *GetFileName() { return fileName; }
  70. const char *GetFontName() { return fontName; }
  71. static TVBitmapFontDescCol *CreateListOfFonts(const char *dir, unsigned wmin=0,
  72. unsigned wmax=256, unsigned hmin=0, unsigned hmax=256);
  73. static void Size2Str(char *buffer, unsigned w, unsigned h);
  74. static void Str2Size(const char *buffer, unsigned &w, unsigned &h);
  75. protected:
  76. static Boolean CheckForLines(void *item, void *arg);
  77. static void CreateFont(void *item, void *arg);
  78. const static char Signature[];
  79. const static char SFTExtension[];
  80. static int CheckSignature(FILE *f);
  81. static char *ReadName(FILE *f);
  82. static void ReadVersionNum(FILE *f, int *version, int *numfonts);
  83. static unsigned ReadFontInfo(FILE *f, int version, TVBitmapFont *p);
  84. static void Swap(int *value);
  85. static void Swap(unsigned *value) { Swap((int *)value); };
  86. static void Swap(uint16 *value);
  87. // !=0 if the file was created with the reverse endian style.
  88. // Only used during load.
  89. static int invertEndian;
  90. int error;
  91. char *fileName;
  92. char *fontName;
  93. };
  94. #endif