odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

bl_generator.cpp (3483B)


      1 // bl_generator is an application that generates code that is part of Blend2D. It started as a simple-hash generator
      2 // to be able to convert OpenType tags to internal IDs for faster processing, however, it may grow in the future and
      3 // generate more code.
      4 
      5 #include <stdint.h>
      6 #include "bl_generator.h"
      7 
      8 // Supplement some Blend2D types and definitions (this generator is totally standalone).
      9 #define BLEND2D_API_BUILD_P_H_INCLUDED
     10 #define BLEND2D_API_INTERNAL_P_H_INCLUDED
     11 
     12 typedef uint32_t BLTag;
     13 
     14 #define BL_HIDDEN
     15 #define BL_INLINE inline
     16 #define BL_MAKE_TAG(A, B, C, D) ((BLTag)(((BLTag)(A) << 24) | ((BLTag)(B) << 16) | ((BLTag)(C) << 8) | ((BLTag)(D))))
     17 
     18 #include "../../src/blend2d/fonttagdataids_p.h"
     19 #include "../../src/blend2d/fonttagdataids.cpp"
     20 
     21 int main() {
     22   printf("-- Finding table tags to ids hash function --\n");
     23   StupidHash::Finder table_tags_finder(bl::FontTagData::table_id_to_tag_table, bl::FontTagData::kTableIdCount);
     24   if (!table_tags_finder.find_solution()) {
     25     printf("Solution not found!\n");
     26     return 1;
     27   }
     28 
     29   printf("-- Finding script tags to ids hash function --\n");
     30   StupidHash::Finder script_tags_finder(bl::FontTagData::script_id_to_tag_table, bl::FontTagData::kScriptIdCount);
     31   if (!script_tags_finder.find_solution()) {
     32     printf("Solution not found!\n");
     33     return 1;
     34   }
     35 
     36   printf("-- Finding language tags to ids hash function --\n");
     37   StupidHash::Finder language_tags_finder(bl::FontTagData::language_id_to_tag_table, bl::FontTagData::kLanguageIdCount);
     38   if (!language_tags_finder.find_solution()) {
     39     printf("Solution not found!\n");
     40     return 1;
     41   }
     42 
     43   printf("-- Finding feature tags to ids hash function --\n");
     44   StupidHash::Finder feature_tags_finder(bl::FontTagData::feature_id_to_tag_table, bl::FontTagData::kFeatureIdCount);
     45   if (!feature_tags_finder.find_solution()) {
     46     printf("Solution not found!\n");
     47     return 1;
     48   }
     49 
     50   printf("-- Finding baseline tags to ids hash function --\n");
     51   StupidHash::Finder baseline_tags_finder(bl::FontTagData::baseline_id_to_tag_table, bl::FontTagData::kBaselineIdCount);
     52   if (!baseline_tags_finder.find_solution()) {
     53     printf("Solution not found!\n");
     54     return 1;
     55   }
     56 
     57   printf("-- Finding variation tags to ids hash function --\n");
     58   StupidHash::Finder variation_tags_finder(bl::FontTagData::variation_id_to_tag_table, bl::FontTagData::kVariationIdCount);
     59   if (!variation_tags_finder.find_solution()) {
     60     printf("Solution not found!\n");
     61     return 1;
     62   }
     63 
     64   printf("%s\n", table_tags_finder._hf.body("static BL_INLINE uint32_t table_tag_to_id(uint32_t tag) noexcept", "tag", "table_id_to_tag_table[", "]").data());
     65   printf("%s\n", script_tags_finder._hf.body("static BL_INLINE uint32_t script_tag_to_id(uint32_t tag) noexcept", "tag", "script_id_to_tag_table[", "]").data());
     66   printf("%s\n", language_tags_finder._hf.body("static BL_INLINE uint32_t language_tag_to_id(uint32_t tag) noexcept", "tag", "language_id_to_tag_table[", "]").data());
     67   printf("%s\n", feature_tags_finder._hf.body("static BL_INLINE uint32_t feature_tag_to_id(uint32_t tag) noexcept", "tag", "feature_id_to_tag_table[", "]").data());
     68   printf("%s\n", baseline_tags_finder._hf.body("static BL_INLINE uint32_t baseline_tag_to_id(uint32_t tag) noexcept", "tag", "baseline_id_to_tag_table[", "]").data());
     69   printf("%s\n", variation_tags_finder._hf.body("static BL_INLINE uint32_t variation_tag_to_id(uint32_t tag) noexcept", "tag", "variation_id_to_tag_table[", "]").data());
     70 
     71   return 0;
     72 }