bdf_font.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. bdf_font.h
  3. */
  4. #ifndef _BDF_FONT_H
  5. #define _BDF_FONT_H
  6. #include <stdio.h>
  7. #include "bdf_glyph.h"
  8. #define BDF_LINE_LEN 1024
  9. #define BDF_BBX_MODE_MINIMAL 0
  10. #define BDF_BBX_MODE_HEIGHT 1
  11. #define BDF_BBX_MODE_MAX 2
  12. #define BDF_BBX_MODE_M8 3
  13. #define BDF_BBX_MODE_5X7 4
  14. struct _bdf_font_struct
  15. {
  16. int is_verbose;
  17. bg_t **glyph_list;
  18. int glyph_cnt;
  19. int glyph_max;
  20. /* variables for the parser */
  21. char line_buf[BDF_LINE_LEN];
  22. int line_pos;
  23. int is_bitmap_parsing;
  24. long encoding;
  25. long dwidth_x;
  26. long dwidth_y;
  27. long bbx_w;
  28. long bbx_h;
  29. long bbx_x;
  30. long bbx_y;
  31. int bitmap_x; /* x position within bitmap parsing */
  32. int bitmap_y; /* y position within bitmap parsing */
  33. int glyph_pos; /* the position to which the glyph has been added in the list */
  34. FILE *fp;
  35. char *str_font; /* argument for FONT in bdf file */
  36. char *str_copyright; /* argument for COPYRIGHT in bdf file */
  37. long selected_glyphs; /* number of mapped glyphs */
  38. int bbx_mode; /* bounding box mode, one of BDF_BBX_MODE_xxx */
  39. /* bf_CalculateMaxBBX */
  40. bbx_t max; /* max bbx, calculated from the mapped glyphs by bf_CalculateMaxBBX */
  41. /* remember which encoding has caused the max value */
  42. long enc_w;
  43. long enc_h;
  44. long enc_x;
  45. long enc_y;
  46. /* bf_CalculateMinMaxDWidth */
  47. long dx_min; /* calculated minimum and maximum dwidth value from the mapped glyphs by bf_CalculateMinMaxDWidth */
  48. long dx_max; /* it is a monospaced font if max and min values are identical */
  49. /* bf_CalculateMinMaxDWidth */
  50. long x_min; /* calculated minimum and maximum bbx.x value from the mapped glyphs by bf_CalculateMinMaxDWidth */
  51. long x_max; /* it is a monospaced font if x_min >= 0 */
  52. /* bf_CalculateMaxBitFieldSize */
  53. int bbx_x_max_bit_size;
  54. int bbx_y_max_bit_size;
  55. int bbx_w_max_bit_size;
  56. int bbx_h_max_bit_size;
  57. int dx_max_bit_size;
  58. /* font target data */
  59. uint8_t *target_data;
  60. int target_max;
  61. int target_cnt;
  62. int tile_h_size; // new 2019 8x8 font format
  63. int tile_v_size; // new 2019 8x8 font format
  64. };
  65. /* bdf_font.c */
  66. /* output error & log messages */
  67. void bf_Error(bf_t *bf, char *fmt, ...);
  68. void bf_Log(bf_t *bf, char *fmt, ...);
  69. /* constructor/destructor */
  70. bf_t *bf_Open(int is_verbose, int bbx_mode);
  71. void bf_Close(bf_t *bf);
  72. /* returns glyph position or -1 */
  73. int bf_AddGlyph(bf_t *bf);
  74. /* add binary data */
  75. void bf_ClearTargetData(bf_t *bf);
  76. int bf_AddTargetData(bf_t *bf, uint8_t data);
  77. void bf_CalculateSelectedNumberOfGlyphs(bf_t *bf);
  78. void bf_ReduceAllGlyph(bf_t *bf);
  79. int bf_GetIndexByEncoding(bf_t *bf, long encoding);
  80. /* only shows glyphs, which will be mapped (call bf_Map() first) */
  81. void bf_ShowAllGlyphs(bf_t *bf, bbx_t *bbx);
  82. void bf_ShowMonospaceStatistics(bf_t *bf);
  83. /* calculate the max bbx for all mapped glyphs (call bf_Map() first) */
  84. void bf_CalculateMaxBBX(bf_t *bf);
  85. void bf_CalculateMinMaxDWidth(bf_t *bf);
  86. void bf_copy_bbx_and_update_shift(bf_t *bf, bbx_t *target_bbx, bg_t *bg);
  87. void bf_CalculateMaxBitFieldSize(bf_t *bf);
  88. void bf_RLECompressAllGlyphs(bf_t *bf);
  89. void bf_Generate8x8Font(bf_t *bf, int xo, int yo);
  90. int bf_WriteUCGCByFilename(bf_t *bf, const char *filename, const char *fontname, const char *indent);
  91. int bf_WriteU8G2CByFilename(bf_t *bf, const char *filename, const char *fontname, const char *indent);
  92. bf_t *bf_OpenFromFile(const char *bdf_filename, int is_verbose, int bbx_mode, const char *map_str, const char *map_file_name, const char *utf8_file_name, int font_format, int xo, int yo, int th, int tv);
  93. /* bdf_parser.c */
  94. int bf_ParseFile(bf_t *bf, const char *name);
  95. /* bdf_map.c */
  96. void bf_Map(bf_t *bf, const char *map_cmd_list);
  97. int bf_MapFile(bf_t *bf, const char *map_file_name);
  98. int bf_Utf8File(bf_t *bf, const char *utf8_file_name);
  99. /* bdf_tga.c */
  100. int tga_init(uint16_t w, uint16_t h);
  101. void tga_clear(void);
  102. void tga_set_pixel(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b);
  103. void tga_save(const char *name);
  104. void tga_set_font(uint8_t *font);
  105. uint8_t *tga_get_glyph_data(uint16_t encoding);
  106. int tga_get_char_width(void);
  107. int tga_get_char_height(void);
  108. unsigned tga_draw_glyph(unsigned x, unsigned y, uint16_t encoding, int is_hints);
  109. unsigned tga_draw_string(unsigned x, unsigned y, const char *s, int is_hints, unsigned max_dx);
  110. int tga_is_pixel_intersection(void);
  111. void tga_clear_pixel_intersection(void);
  112. /* bdf_kern.c */
  113. unsigned bdf_calculate_kerning(uint8_t *font, uint16_t e1, uint16_t e2, uint8_t min_distance_in_per_cent_of_char_width);
  114. void bdf_calculate_all_kerning(bf_t *bf, const char *filename, const char *fontname, uint8_t min_distance_in_per_cent_of_char_width);
  115. #endif