summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2011-03-22 19:37:28 +0000
committerMagnus Holmgren <magnushol@gmail.com>2011-03-22 19:37:28 +0000
commit671127c65de3b93e3cbce6161ca748ecb388688d (patch)
treecd1c652ecba4b95b3344eb384b368f90ba264820 /tools
parentf4e152bdefe4eaad148e47afc8d69dff5c060762 (diff)
downloadrockbox-671127c65de3b93e3cbce6161ca748ecb388688d.tar.gz
rockbox-671127c65de3b93e3cbce6161ca748ecb388688d.zip
Commit FS#12000: confttv - try to make digits equally wide (-w to disable)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29633 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rw-r--r--tools/convttf.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/tools/convttf.c b/tools/convttf.c
index ca9e4fbb4d..24cf14ab9c 100644
--- a/tools/convttf.c
+++ b/tools/convttf.c
@@ -89,12 +89,12 @@ static int eid = DEFAULT_ENCODING_ID;
89static FT_UShort nocmap; 89static FT_UShort nocmap;
90 90
91int pct = 0; /* display ttc table if it is not zero. */ 91int pct = 0; /* display ttc table if it is not zero. */
92unsigned long max_char = 65535; 92FT_Long max_char = 65535;
93int pixel_size = 15; 93int pixel_size = 15;
94unsigned long start_char = 0; 94FT_Long start_char = 0;
95unsigned long limit_char; 95FT_Long limit_char;
96unsigned long firstchar = 0; 96FT_Long firstchar = 0;
97unsigned long lastchar; 97FT_Long lastchar;
98FT_Long ttc_index = -1; 98FT_Long ttc_index = -1;
99int flg_all_ttc = 0; 99int flg_all_ttc = 0;
100short antialias = 1; /* smooth fonts with gray levels */ 100short antialias = 1; /* smooth fonts with gray levels */
@@ -104,6 +104,7 @@ float between_chr = 0.0f;
104float between_row = 0.0f; 104float between_row = 0.0f;
105int hv_resolution = 60; 105int hv_resolution = 60;
106int dump_glyphs = 0; 106int dump_glyphs = 0;
107int digits_equally_wide = 1; /* Try to make digits equally wide */
107int trimming = 0; 108int trimming = 0;
108int trim_dp = 0; /* trim descent percent */ 109int trim_dp = 0; /* trim descent percent */
109int trim_da = 0; /* trim descnet actual */ 110int trim_da = 0; /* trim descnet actual */
@@ -204,6 +205,7 @@ void usage(void)
204 " -tt Display the True Type Collection tables available in the font\n" 205 " -tt Display the True Type Collection tables available in the font\n"
205 " -t N Index of true type collection. It must be start from 0.(default N=0).\n" 206 " -t N Index of true type collection. It must be start from 0.(default N=0).\n"
206 " -ta Convert all fonts in ttc (ignores outfile option)\n" 207 " -ta Convert all fonts in ttc (ignores outfile option)\n"
208 " -w Don't try to make digits (0-9) equally wide\n"
207 }; 209 };
208 fprintf(stderr, "%s", help); 210 fprintf(stderr, "%s", help);
209 exit( 1 ); 211 exit( 1 );
@@ -503,22 +505,54 @@ void print_raw_glyph( FT_Face face)
503 printf("----End-----\n"); 505 printf("----End-----\n");
504} 506}
505 507
506int glyph_width( FT_Face face) 508int glyph_width( FT_Face face, FT_Long code, FT_Long digit_width )
507{ 509{
508 int pitch, h_adv, width; 510 int width;
509 unsigned spacing = (unsigned)(between_chr * (1<<6));/* convert to fixed point */
510 511
511 pitch = ABS(face->glyph->bitmap.pitch); 512 if (code >= '0' && code <= '9' && digit_width)
512 h_adv = face->glyph->metrics.horiAdvance >> 6; 513 {
513 width = (face->glyph->metrics.width + spacing) >> 6; 514 width = digit_width;
515 }
516 else
517 {
518 int pitch, h_adv;
519 unsigned spacing = (unsigned)(between_chr * (1<<6));/* convert to fixed point */
520
521 pitch = ABS(face->glyph->bitmap.pitch);
522 h_adv = face->glyph->metrics.horiAdvance >> 6;
523 width = (face->glyph->metrics.width + spacing) >> 6;
514 524
515 if(pitch == 0) pitch = h_adv; 525 if(pitch == 0) pitch = h_adv;
516 if(width < pitch) width = pitch; 526 if(width < pitch) width = pitch;
517 if(width == 0) return 0; 527 }
518 528
519 return width; 529 return width;
520} 530}
521 531
532FT_Long check_digit_width( FT_Face face )
533{
534 FT_Long code;
535 FT_Long last_advance = -1;
536
537 for (code='0'; code <= '9'; ++code)
538 {
539 FT_Glyph_Metrics* metrics;
540
541 FT_Load_Char(face, code, FT_LOAD_RENDER | FT_LOAD_NO_BITMAP);
542 metrics = &face->glyph->metrics;
543
544 if ((last_advance != -1 && last_advance != metrics->horiAdvance) ||
545 metrics->horiBearingX < 0)
546 {
547 last_advance = 0;
548 break;
549 }
550
551 last_advance = metrics->horiAdvance;
552 }
553
554 return last_advance >> 6;
555}
522 556
523void trim_glyph( FT_GlyphSlot glyph, int *empty_first_col, 557void trim_glyph( FT_GlyphSlot glyph, int *empty_first_col,
524 int *empty_last_col, int *width ) 558 int *empty_last_col, int *width )
@@ -574,6 +608,7 @@ void convttf(char* path, char* destfile, FT_Long face_index)
574 FT_Long charindex; 608 FT_Long charindex;
575 FT_Long index = 0; 609 FT_Long index = 0;
576 FT_Long code; 610 FT_Long code;
611 FT_Long digit_width = 0;
577 612
578 int depth = 2; 613 int depth = 2;
579 unsigned char bit_shift = 1 << depth; 614 unsigned char bit_shift = 1 << depth;
@@ -626,6 +661,9 @@ void convttf(char* path, char* destfile, FT_Long face_index)
626 firstchar = limit_char; 661 firstchar = limit_char;
627 lastchar = start_char; 662 lastchar = start_char;
628 663
664 if (digits_equally_wide)
665 digit_width = check_digit_width(face);
666
629 /* calculate memory usage */ 667 /* calculate memory usage */
630 for(code = start_char; code <= limit_char ; code++ ) 668 for(code = start_char; code <= limit_char ; code++ )
631 { 669 {
@@ -634,8 +672,8 @@ void convttf(char* path, char* destfile, FT_Long face_index)
634 error = FT_Load_Glyph( face, charindex, 672 error = FT_Load_Glyph( face, charindex,
635 (FT_LOAD_RENDER | FT_LOAD_NO_BITMAP) ); 673 (FT_LOAD_RENDER | FT_LOAD_NO_BITMAP) );
636 if ( error ) continue; 674 if ( error ) continue;
637 675
638 w = glyph_width( face ); 676 w = glyph_width( face, code, digit_width );
639 if (w == 0) continue; 677 if (w == 0) continue;
640 empty_first_col = empty_last_col = 0; 678 empty_first_col = empty_last_col = 0;
641 if(trimming) 679 if(trimming)
@@ -715,7 +753,7 @@ void convttf(char* path, char* destfile, FT_Long face_index)
715 FT_GlyphSlot slot = face->glyph; 753 FT_GlyphSlot slot = face->glyph;
716 FT_Bitmap* source = &slot->bitmap; 754 FT_Bitmap* source = &slot->bitmap;
717 //print_raw_glyph( face ); 755 //print_raw_glyph( face );
718 w = glyph_width( face ); 756 w = glyph_width( face, code, digit_width );
719 if (w == 0) continue; 757 if (w == 0) continue;
720 empty_first_col = empty_last_col = 0; 758 empty_first_col = empty_last_col = 0;
721 759
@@ -1179,6 +1217,11 @@ void getopts(int *pac, char ***pav)
1179 ttc_index = atoi(av[0]); 1217 ttc_index = atoi(av[0]);
1180 } 1218 }
1181 break; 1219 break;
1220 case 'w': /* Don't try to make digits equally wide */
1221 digits_equally_wide = 0;
1222 while (*p && *p != ' ')
1223 p++;
1224 break;
1182 1225
1183 default: 1226 default:
1184 fprintf(stderr, "Unknown option ignored: %s\n", p-1); 1227 fprintf(stderr, "Unknown option ignored: %s\n", p-1);