Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

convttf: Switch to c99 fixed size integers for fnt file header

Change-Id: Idff55a88a9bddaec42e568cf3c3ff3f6df15ec34

+53 -52
+53 -52
tools/convttf.c
··· 35 35 #include FT_TRUETYPE_TABLES_H 36 36 37 37 #include <string.h> 38 + #include <stdint.h> 38 39 /* 39 40 * Set the default values used to generate a BDF font. 40 41 */ ··· 114 115 int ft_load_opts = FT_LOAD_RENDER | FT_LOAD_NO_BITMAP; 115 116 116 117 struct font_header_struct { 117 - char header[4]; /* magic number and version bytes */ 118 - unsigned short maxwidth; /* max width in pixels */ 119 - unsigned short height; /* height in pixels */ 120 - unsigned short ascent; /* ascent (baseline) height */ 121 - unsigned short depth; /* depth 0=1-bit, 1=4-bit */ 122 - unsigned long firstchar; /* first character in font */ 123 - unsigned long defaultchar; /* default character in font */ 124 - unsigned long size; /* # characters in font */ 125 - unsigned long nbits; /* # bytes imagebits data in file */ /* = bits_size */ 118 + uint8_t header[4]; /* magic number and version bytes */ 119 + uint16_t maxwidth; /* max width in pixels */ 120 + uint16_t height; /* height in pixels */ 121 + uint16_t ascent; /* ascent (baseline) height */ 122 + uint16_t depth; /* depth 0=1-bit, 1=4-bit */ 123 + uint32_t firstchar; /* first character in font */ 124 + uint32_t defaultchar; /* default character in font */ 125 + uint32_t size; /* # characters in font */ 126 + uint32_t nbits; /* # bytes imagebits data in file */ /* = bits_size */ 126 127 127 - FT_Long noffset; /* # longs offset data in file */ 128 - FT_Long nwidth; /* # bytes width data in file */ 128 + uint32_t noffset; /* # longs offset data in file */ 129 + uint32_t nwidth; /* # bytes width data in file */ 129 130 }; 130 131 131 132 struct font_struct { 132 133 struct font_header_struct header; 133 - unsigned char *chars_data; 134 - unsigned short *offset; 135 - FT_Long *offset_long; 136 - unsigned char *width; 134 + uint8_t *chars_data; 135 + uint16_t *offset; 136 + uint32_t *offset_long; 137 + uint8_t *width; 137 138 }; 138 139 139 140 struct ttc_table{ ··· 189 190 " Default output-file : <font-size>-<basename>.fnt.\n" 190 191 " When '-ta' or '-tc' is specified in command line,\n " 191 192 " default output-file is: \n" 192 - " <font-size>-<internal postscript-name of input-file>.fnt.\n" 193 + " <font-size>-<internal postscript-name of input-file>.fnt.\n" 193 194 "Options:\n" 194 195 " -s N Start output at character encodings >= N\n" 195 196 " -l N Limit output to character encodings <= N\n" ··· 421 422 ttcname->ttc_count = 0; 422 423 423 424 /* Initialize engine */ 424 - if ( ( err = FT_Init_FreeType( &library ) ) != 0 ) 425 + if ( ( err = FT_Init_FreeType( &library ) ) != 0 ) 425 426 { 426 427 panic( "Error while initializing engine" ); 427 428 return err; ··· 499 500 width = face->glyph->metrics.width >> 6; 500 501 501 502 printf("\n---Raw-Glyph---\n"); 502 - for(row=0; row < face->glyph->metrics.height >> 6; row++) 503 + for(row=0; row < face->glyph->metrics.height >> 6; row++) 503 504 { 504 505 printf("_"); 505 506 for(col=0; col < width; col++) 506 - { 507 + { 507 508 pixel = *(face->glyph->bitmap.buffer+width*row+col)/26; 508 509 if ( pixel ) printf("%d",pixel); else printf(" "); 509 510 } ··· 561 562 return last_advance >> 6; 562 563 } 563 564 564 - void trim_glyph( FT_GlyphSlot glyph, int *empty_first_col, 565 + void trim_glyph( FT_GlyphSlot glyph, int *empty_first_col, 565 566 int *empty_last_col, int *width ) 566 567 { 567 568 int row; ··· 629 630 unsigned char pixel_per_byte = CHAR_BIT / bit_shift; 630 631 struct font_struct export_font; 631 632 char pad[] = {0,0,0,0}; 632 - int skip,i; 633 + unsigned int skip,i; 633 634 FILE *file; 634 635 635 636 /* Initialize engine */ ··· 697 698 empty_first_col = empty_last_col = 0; 698 699 if(trimming) 699 700 trim_glyph( face->glyph, &empty_first_col, &empty_last_col, &w); 700 - 701 - if (export_font.header.maxwidth < w) 701 + 702 + if (export_font.header.maxwidth < w) 702 703 export_font.header.maxwidth = w; 703 704 704 705 ··· 717 718 export_font.header.nbits = idx; 718 719 export_font.header.noffset = export_font.header.size; 719 720 export_font.header.nwidth = export_font.header.size; 720 - 721 + 721 722 /* check if we need to use long offsets */ 722 723 use_long_offset = (export_font.header.nbits >= 0xFFDB ); 723 724 ··· 725 726 export_font.offset = NULL; 726 727 export_font.offset_long = NULL; 727 728 if (use_long_offset) 728 - export_font.offset_long = 729 + export_font.offset_long = 729 730 malloc( sizeof(FT_Long)* export_font.header.noffset ); 730 731 else 731 - export_font.offset = 732 + export_font.offset = 732 733 malloc( sizeof(unsigned short)* export_font.header.noffset ); 733 734 734 - export_font.width = 735 + export_font.width = 735 736 malloc( sizeof(unsigned char) * export_font.header.nwidth ); 736 - export_font.chars_data = 737 + export_font.chars_data = 737 738 malloc( sizeof(unsigned char) * export_font.header.nbits ); 738 - 739 + 739 740 /* for now we use the full height for each character */ 740 741 h = export_font.header.height; 741 742 ··· 761 762 762 763 /* Get gylph index from the char and render it */ 763 764 charindex = getcharindex( face, code); 764 - if ( !charindex ) 765 + if ( !charindex ) 765 766 { 766 767 if ( use_long_offset ) 767 768 export_font.offset_long[code - firstchar] = export_font.offset_long[0]; ··· 770 771 export_font.width[code - firstchar] = export_font.width[0]; 771 772 continue; 772 773 } 773 - 774 + 774 775 err = FT_Load_Glyph(face, charindex, ft_load_opts); 775 776 if ( err ) { 776 777 continue; ··· 791 792 792 793 if(trimming) 793 794 trim_glyph( face->glyph, &empty_first_col, &empty_last_col, &w ); 794 - 795 + 795 796 if ( use_long_offset ) 796 797 export_font.offset_long[code - firstchar] = idx; 797 798 else ··· 839 840 field = 0; 840 841 numbits = pixel_per_byte; 841 842 842 - for(row=0; row < h; row++) 843 + for(row=0; row < h; row++) 843 844 { 844 845 for(col=0; col < w; col++) 845 846 { ··· 937 938 writeint(file, export_font.header.noffset); 938 939 writeint(file, export_font.header.nwidth); 939 940 940 - fwrite( (char*)export_font.chars_data, 1, 941 + fwrite( (char*)export_font.chars_data, 1, 941 942 export_font.header.nbits, file); 942 943 free(export_font.chars_data); 943 944 944 945 945 946 946 - if ( use_long_offset ) 947 + if ( use_long_offset ) 947 948 { 948 - skip = ((export_font.header.nbits + 3) & ~3) - 949 + skip = ((export_font.header.nbits + 3) & ~3) - 949 950 export_font.header.nbits; 950 951 fwrite(pad, 1, skip, file); /* pad */ 951 952 for(i = 0; i < export_font.header.noffset; i++) 952 953 writeint(file, export_font.offset_long[i]); 953 954 } 954 - else 955 + else 955 956 { 956 - skip = ((export_font.header.nbits + 1) & ~1) - 957 + skip = ((export_font.header.nbits + 1) & ~1) - 957 958 export_font.header.nbits; 958 959 fwrite(pad, 1, skip, file); /* pad */ 959 960 for(i = 0; i < export_font.header.noffset; i++) ··· 964 965 writebyte(file, export_font.width[i]); 965 966 free(export_font.width); 966 967 967 - if ( use_long_offset ) 968 + if ( use_long_offset ) 968 969 free(export_font.offset_long); 969 - else 970 + else 970 971 free(export_font.offset); 971 972 972 973 fclose(file); ··· 984 985 985 986 get_ttc_table(path, &ttcname); 986 987 987 - if (ttcname.ttc_count == 0) 988 + if (ttcname.ttc_count == 0) 988 989 { 989 990 printf("This file is a not true type font.\n"); 990 991 return; 991 992 } 992 993 993 994 /* default */ 994 - if (!flg_all_ttc && ttc_index == -1) 995 + if (!flg_all_ttc && ttc_index == -1) 995 996 { 996 997 if (!oflag) 997 998 { /* generate filename */ ··· 1005 1006 else if (!flg_all_ttc) 1006 1007 { 1007 1008 print_ttc_table(path); 1008 - if ( !oflag ) 1009 + if ( !oflag ) 1009 1010 { 1010 - if (ttc_index >= 0 && 1011 + if (ttc_index >= 0 && 1011 1012 ttc_index < ttcname.ttc_count) 1012 1013 { 1013 - if (strcmp(ttcname.ttf_name[ttc_index], "") != 0) 1014 + if (strcmp(ttcname.ttf_name[ttc_index], "") != 0) 1014 1015 { 1015 1016 snprintf(outfile, sizeof(outfile), "%d-%s.fnt", 1016 1017 pixel_size, ttcname.ttf_name[ttc_index]); ··· 1060 1061 start_char = 0; 1061 1062 1062 1063 while (ac > 0 && av[0][0] == '-') { 1063 - p = &av[0][1]; 1064 + p = &av[0][1]; 1064 1065 while( *p) 1065 1066 switch(*p++) { 1066 1067 case 'h':case 'H': ··· 1278 1279 1279 1280 getopts(&ac, &av); /* read command line options*/ 1280 1281 1281 - if (ac < 1) 1282 + if (ac < 1) 1282 1283 { 1283 1284 usage(); 1284 1285 } 1285 - if (oflag) 1286 + if (oflag) 1286 1287 { 1287 - if (ac > 1) 1288 + if (ac > 1) 1288 1289 { 1289 1290 usage(); 1290 1291 } ··· 1296 1297 exit(0); 1297 1298 } 1298 1299 1299 - while (pct && ac > 0) 1300 + while (pct && ac > 0) 1300 1301 { 1301 1302 print_ttc_table(av[0]); 1302 1303 ++av; --ac; 1303 1304 exit(0); 1304 1305 } 1305 1306 1306 - while (ac > 0) 1307 + while (ac > 0) 1307 1308 { 1308 1309 convttc(av[0]); 1309 1310 ++av; --ac; ··· 1330 1331 static node_t *nodes; 1331 1332 static unsigned long nodes_used = 0; 1332 1333 1333 - int 1334 + int 1334 1335 otf2bdf_remap(unsigned short *code) 1335 1336 { 1336 1337 unsigned long i, n, t;