1
mirror of https://github.com/mpv-player/mpv synced 2025-01-01 04:36:24 +01:00

Added --unicode switch. This is for UTF-8 encoded subtitles.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1676 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
zybi 2001-08-24 08:55:00 +00:00
parent 8892bf54b0
commit 9d6896679b
2 changed files with 44 additions and 31 deletions

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
#unicode="--unicode"
font=arial.ttf font=arial.ttf
#font=verdana.ttf #font=verdana.ttf
encoding=iso-8859-2 encoding=iso-8859-2
@ -10,7 +11,7 @@ outline=1.5
make || exit make || exit
./subfont --blur $blur --outline $outline "$encoding" $fontsize "$font" || exit ./subfont $unicode --blur $blur --outline $outline "$encoding" $fontsize "$font" || exit
./subfont --append --blur $blur --outline $outline encodings/osd-mplayer $symbolssize osd/osd.pfb || exit ./subfont --append --blur $blur --outline $outline encodings/osd-mplayer $symbolssize osd/osd.pfb || exit
#cp font.desc *.raw ~/.mplayer/font/ #cp font.desc *.raw ~/.mplayer/font/

View File

@ -38,11 +38,10 @@
char *encoding = "iso-8859-1"; /* target encoding */ char *encoding = "iso-8859-1"; /* target encoding */
char *charmap = "ucs-4"; /* font charmap encoding, I hope ucs-4 is always big endian */ char *charmap = "ucs-4"; /* font charmap encoding, I hope ucs-4 is always big endian */
/* gcc 2.1.3 doesn't support ucs-4le, but supports ucs-4 (==ucs-4be) */ /* gcc 2.1.3 doesn't support ucs-4le, but supports ucs-4 (==ucs-4be) */
int ppem = 22; /* font size in pixels */ float ppem = 22; /* font size in pixels */
double radius = 2; /* blur radius */ double radius = 2; /* blur radius */
double thickness = 1.5; /* outline thickness */ double thickness = 1.5; /* outline thickness */
int padding;
char* font_desc = "font.desc"; char* font_desc = "font.desc";
//char* font_desc = "/dev/stdout"; //char* font_desc = "/dev/stdout";
@ -62,9 +61,11 @@ char *encoding_name;
char *font_path; char *font_path;
//char *font_metrics; //char *font_metrics;
int append_mode = 0; int append_mode = 0;
int unicode_desc = 0;
unsigned char *bbuffer, *abuffer; unsigned char *bbuffer, *abuffer;
int width, height; int width, height;
int padding;
static FT_ULong charset[max_charset_size]; /* characters we want to render; Unicode */ static FT_ULong charset[max_charset_size]; /* characters we want to render; Unicode */
static FT_ULong charcodes[max_charset_size]; /* character codes in 'encoding' */ static FT_ULong charcodes[max_charset_size]; /* character codes in 'encoding' */
iconv_t cd; // iconv conversion descriptor iconv_t cd; // iconv conversion descriptor
@ -83,6 +84,7 @@ iconv_t cd; // iconv conversion descriptor
#define f266CeilToInt(x) (((x)+63)>>6) // ceiling #define f266CeilToInt(x) (((x)+63)>>6) // ceiling
#define f266FloorToInt(x) ((x)>>6) // floor #define f266FloorToInt(x) ((x)>>6) // floor
#define f1616ToInt(x) (((x)+0x8000)>>16) // 16.16 #define f1616ToInt(x) (((x)+0x8000)>>16) // 16.16
#define floatTof266(x) ((int)((x)*(1<<6)+0.5))
#define ALIGN(x) (((x)+7)&~7) // 8 byte align #define ALIGN(x) (((x)+7)&~7) // 8 byte align
@ -197,21 +199,22 @@ void render() {
/* set size */ /* set size */
if (FT_IS_SCALABLE(face)) { if (FT_IS_SCALABLE(face)) {
error = FT_Set_Pixel_Sizes(face, ppem, ppem); error = FT_Set_Char_Size(face, floatTof266(ppem), 0, 0, 0);
if (error) WARNING("FT_Set_Char_Size failed.");
} else { } else {
int j = 0; int j = 0;
int jppem = face->available_sizes[0].height; int jppem = face->available_sizes[0].height;
/* find closest size */ /* find closest size */
for (i = 0; i<face->num_fixed_sizes; ++i) { for (i = 0; i<face->num_fixed_sizes; ++i) {
if (abs(face->available_sizes[i].height - ppem) < abs(face->available_sizes[i].height - jppem)) { if (fabs(face->available_sizes[i].height - ppem) < abs(face->available_sizes[i].height - jppem)) {
j = i; j = i;
jppem = face->available_sizes[i].height; jppem = face->available_sizes[i].height;
} }
} }
WARNING("Selected font is not scalable. Using ppem=%i.", face->available_sizes[j].height); WARNING("Selected font is not scalable. Using ppem=%i.", face->available_sizes[j].height);
error = FT_Set_Pixel_Sizes(face, face->available_sizes[j].width, face->available_sizes[j].height); error = FT_Set_Pixel_Sizes(face, face->available_sizes[j].width, face->available_sizes[j].height);
if (error) WARNING("FT_Set_Pixel_Sizes failed.");
} }
if (error) WARNING("FT_Set_Pixel_Sizes failed.");
if (FT_IS_FIXED_WIDTH(face)) if (FT_IS_FIXED_WIDTH(face))
@ -231,19 +234,21 @@ void render() {
/* print font.desc header */ /* print font.desc header */
if (append_mode) { if (append_mode) {
fprintf(f, "\n\n# Subtitle font for %s encoding, face \"%s%s%s\", ppem=%i\n", fprintf(f, "\n\n# ");
encoding_name,
face->family_name,
face->style_name ? " ":"", face->style_name ? face->style_name:"",
ppem);
} else { } else {
fprintf(f, "# This file was generated with subfont for Mplayer.\n# Subfont by Artur Zaprzala <zybi@fanthom.irc.pl>.\n\n"); fprintf(f, "# This file was generated with subfont for Mplayer.\n"
"# Subfont by Artur Zaprzala <zybi@fanthom.irc.pl>.\n\n");
fprintf(f, "[info]\n"); fprintf(f, "[info]\n");
fprintf(f, "name 'Subtitle font for %s encoding, face \"%s%s%s\", ppem=%i'\n", }
encoding_name,
face->family_name, fprintf(f, "name 'Subtitle font for %s %s, \"%s%s%s\" face, size: %.1f pixels.'\n",
face->style_name ? " ":"", face->style_name ? face->style_name:"", encoding_name,
ppem); unicode_desc ? "charset, Unicode encoding":"encoding",
face->family_name,
face->style_name ? " ":"", face->style_name ? face->style_name:"",
ppem);
if (!append_mode) {
#ifdef NEW_DESC #ifdef NEW_DESC
fprintf(f, "descversion 2\n"); fprintf(f, "descversion 2\n");
#else #else
@ -321,7 +326,7 @@ void render() {
pen_xa = pen_x + glyph->bitmap.width + 2*padding; pen_xa = pen_x + glyph->bitmap.width + 2*padding;
// font.desc // font.desc
fprintf(f, "0x%02x %i %i %i %i %i %i;\tU+%04X|%c\n", code, fprintf(f, "0x%04x %i %i %i %i %i %i;\tU+%04X|%c\n", unicode_desc ? character:code,
pen_x, // bitmap start pen_x, // bitmap start
glyph->bitmap.width + 2*padding, // bitmap width glyph->bitmap.width + 2*padding, // bitmap width
glyph->bitmap.rows + 2*padding, // bitmap height glyph->bitmap.rows + 2*padding, // bitmap height
@ -344,7 +349,10 @@ void render() {
pen_xa = pen_x + f266ToInt(slot->advance.x) + 2*padding; pen_xa = pen_x + f266ToInt(slot->advance.x) + 2*padding;
/* font.desc */ /* font.desc */
fprintf(f, "0x%02x %i %i;\tU+%04X|%c\n", code, pen_x, pen_xa-1, character, code<' '||code>255 ? '.':code); fprintf(f, "0x%04x %i %i;\tU+%04X|%c\n", unicode_desc ? character:code,
pen_x, // bitmap start
pen_xa-1, // bitmap end
character, code<' '||code>255 ? '.':code);
#endif #endif
pen_x = ALIGN(pen_xa); pen_x = ALIGN(pen_xa);
} }
@ -662,16 +670,17 @@ void alpha() {
void usage() { void usage() {
printf("Usage: %s [--append] [--blur b] [--outline o] encoding ppem font\n", command); printf("Usage: %s [--append] [--unicode] [--blur b] [--outline o] encoding ppem font\n", command);
printf("\n" printf("\n"
" Program creates 3 files: font.desc, <encoding>-a.raw, <encoding>-b.raw.\n" " Program creates 3 files: font.desc, <encoding>-a.raw, <encoding>-b.raw.\n"
"\n" "\n"
" --append append results to existing font.desc.\n" " --append append results to existing font.desc, suppress info header.\n"
" --unicode use Unicode in font.desc. This will work with -utf8 option of mplayer.\n"
" --blur b specify blur radius, float.\n" " --blur b specify blur radius, float.\n"
" --outline o specify outline thickness, float.\n" " --outline o specify outline thickness, float.\n"
" encoding must be an 8 bit encoding, like iso-8859-2, or path to custom encoding file (see README).\n" " encoding must be an 8 bit encoding, like iso-8859-2, or path to custom encoding file (see README).\n"
" To list encodings available on your system use iconv --list.\n" " To list encodings available on your system use iconv --list.\n"
" ppem Font size in pixels (e.g. 24).\n" " ppem Font size in pixels (default 24), float.\n"
" font Font file path. Any format supported by the freetype library (*.ttf, *.pfb, ...).\n" " font Font file path. Any format supported by the freetype library (*.ttf, *.pfb, ...).\n"
); );
exit(1); exit(1);
@ -687,15 +696,17 @@ void parse_args(int argc, char **argv) {
else ++command; else ++command;
++a; --argc; ++a; --argc;
if (argc==0) usage(); if (argc>=1 && strcmp(argv[a], "--append")==0) {
if (strcmp(argv[a], "--append")==0) {
append_mode = 1; append_mode = 1;
++a; --argc; ++a; --argc;
} }
if (argc>=1 && strcmp(argv[a], "--unicode")==0) {
unicode_desc = 1;
++a; --argc;
}
if (argc==0) usage(); if (argc>=1 && strcmp(argv[a], "--blur")==0) {
if (strcmp(argv[a], "--blur")==0) {
++a; --argc; ++a; --argc;
if (argc==0) usage(); if (argc==0) usage();
@ -705,8 +716,7 @@ void parse_args(int argc, char **argv) {
++a; --argc; ++a; --argc;
} }
if (argc==0) usage(); if (argc>=1 && strcmp(argv[a], "--outline")==0) {
if (strcmp(argv[a], "--outline")==0) {
++a; --argc; ++a; --argc;
if (argc==0) usage(); if (argc==0) usage();
@ -718,18 +728,20 @@ void parse_args(int argc, char **argv) {
if (argc<3) usage(); if (argc<3) usage();
// encoding
if (argv[a][0]!=0) if (argv[a][0]!=0)
encoding = argv[a]; encoding = argv[a];
encoding_name = strrchr(encoding, '/'); encoding_name = strrchr(encoding, '/');
if (!encoding_name) encoding_name=encoding; if (!encoding_name) encoding_name=encoding;
else ++encoding_name; else ++encoding_name;
++a; --argc; ++a; --argc;
i = atoi(argv[a]); // ppem
if (i>1) ppem = i; d = atof(argv[a]);
if (d>2.) ppem = d;
++a; --argc; ++a; --argc;
// font
font_path = argv[a]; font_path = argv[a];
++a; --argc; ++a; --argc;
} }