diff options
37 files changed, 350 insertions, 146 deletions
diff --git a/misc/Makefile.am b/misc/Makefile.am index 5fe7d6f3e..5c9bbe853 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -28,4 +28,4 @@ maintainer-clean-generic: -rm -f Makefile.in xine-fontconv: xine-fontconv.c - $(CC) -g -o xine-fontconv xine-fontconv.c -lfreetype -lz -I/usr/include/freetype2 + $(CC) -W -Wall -g -o xine-fontconv xine-fontconv.c -lz `freetype-config --cflags` `freetype-config --libs` diff --git a/misc/fonts/cc-16.xinefont.gz b/misc/fonts/cc-16.xinefont.gz Binary files differindex b60d2465b..c49d4e8b4 100644 --- a/misc/fonts/cc-16.xinefont.gz +++ b/misc/fonts/cc-16.xinefont.gz diff --git a/misc/fonts/cc-20.xinefont.gz b/misc/fonts/cc-20.xinefont.gz Binary files differindex 7c84598f4..70b4b6bee 100644 --- a/misc/fonts/cc-20.xinefont.gz +++ b/misc/fonts/cc-20.xinefont.gz diff --git a/misc/fonts/cc-24.xinefont.gz b/misc/fonts/cc-24.xinefont.gz Binary files differindex 290ff931c..5e4655818 100644 --- a/misc/fonts/cc-24.xinefont.gz +++ b/misc/fonts/cc-24.xinefont.gz diff --git a/misc/fonts/cc-32.xinefont.gz b/misc/fonts/cc-32.xinefont.gz Binary files differindex 30b7447d8..9b464f706 100644 --- a/misc/fonts/cc-32.xinefont.gz +++ b/misc/fonts/cc-32.xinefont.gz diff --git a/misc/fonts/cci-16.xinefont.gz b/misc/fonts/cci-16.xinefont.gz Binary files differindex dca74dff5..3afbcbda6 100644 --- a/misc/fonts/cci-16.xinefont.gz +++ b/misc/fonts/cci-16.xinefont.gz diff --git a/misc/fonts/cci-20.xinefont.gz b/misc/fonts/cci-20.xinefont.gz Binary files differindex 8e0121a21..209eea071 100644 --- a/misc/fonts/cci-20.xinefont.gz +++ b/misc/fonts/cci-20.xinefont.gz diff --git a/misc/fonts/cci-24.xinefont.gz b/misc/fonts/cci-24.xinefont.gz Binary files differindex d0dde540a..15d342384 100644 --- a/misc/fonts/cci-24.xinefont.gz +++ b/misc/fonts/cci-24.xinefont.gz diff --git a/misc/fonts/cci-32.xinefont.gz b/misc/fonts/cci-32.xinefont.gz Binary files differindex d9df63ce5..b97b28b24 100644 --- a/misc/fonts/cci-32.xinefont.gz +++ b/misc/fonts/cci-32.xinefont.gz diff --git a/misc/fonts/cetus-16.xinefont.gz b/misc/fonts/cetus-16.xinefont.gz Binary files differindex fba19ca94..9057a0189 100644 --- a/misc/fonts/cetus-16.xinefont.gz +++ b/misc/fonts/cetus-16.xinefont.gz diff --git a/misc/fonts/cetus-20.xinefont.gz b/misc/fonts/cetus-20.xinefont.gz Binary files differindex e6150285a..eb8355c76 100644 --- a/misc/fonts/cetus-20.xinefont.gz +++ b/misc/fonts/cetus-20.xinefont.gz diff --git a/misc/fonts/cetus-24.xinefont.gz b/misc/fonts/cetus-24.xinefont.gz Binary files differindex 10935f07b..1c94aa878 100644 --- a/misc/fonts/cetus-24.xinefont.gz +++ b/misc/fonts/cetus-24.xinefont.gz diff --git a/misc/fonts/cetus-32.xinefont.gz b/misc/fonts/cetus-32.xinefont.gz Binary files differindex 01a6888f7..370bc6107 100644 --- a/misc/fonts/cetus-32.xinefont.gz +++ b/misc/fonts/cetus-32.xinefont.gz diff --git a/misc/fonts/mono-16.xinefont.gz b/misc/fonts/mono-16.xinefont.gz Binary files differindex 219c89156..8d1ac9648 100644 --- a/misc/fonts/mono-16.xinefont.gz +++ b/misc/fonts/mono-16.xinefont.gz diff --git a/misc/fonts/mono-20.xinefont.gz b/misc/fonts/mono-20.xinefont.gz Binary files differindex f3ec154d7..902281bb1 100644 --- a/misc/fonts/mono-20.xinefont.gz +++ b/misc/fonts/mono-20.xinefont.gz diff --git a/misc/fonts/mono-24.xinefont.gz b/misc/fonts/mono-24.xinefont.gz Binary files differindex 7b02f4e61..1f9ef9442 100644 --- a/misc/fonts/mono-24.xinefont.gz +++ b/misc/fonts/mono-24.xinefont.gz diff --git a/misc/fonts/mono-32.xinefont.gz b/misc/fonts/mono-32.xinefont.gz Binary files differindex 2181016d7..9d4c5552f 100644 --- a/misc/fonts/mono-32.xinefont.gz +++ b/misc/fonts/mono-32.xinefont.gz diff --git a/misc/fonts/sans-16.xinefont.gz b/misc/fonts/sans-16.xinefont.gz Binary files differindex d713f57ab..ca4516706 100644 --- a/misc/fonts/sans-16.xinefont.gz +++ b/misc/fonts/sans-16.xinefont.gz diff --git a/misc/fonts/sans-20.xinefont.gz b/misc/fonts/sans-20.xinefont.gz Binary files differindex 177dab1ec..e2415c2d5 100644 --- a/misc/fonts/sans-20.xinefont.gz +++ b/misc/fonts/sans-20.xinefont.gz diff --git a/misc/fonts/sans-24.xinefont.gz b/misc/fonts/sans-24.xinefont.gz Binary files differindex c6c71a4b9..583e3506a 100644 --- a/misc/fonts/sans-24.xinefont.gz +++ b/misc/fonts/sans-24.xinefont.gz diff --git a/misc/fonts/sans-32.xinefont.gz b/misc/fonts/sans-32.xinefont.gz Binary files differindex d107d8007..1a15e54f9 100644 --- a/misc/fonts/sans-32.xinefont.gz +++ b/misc/fonts/sans-32.xinefont.gz diff --git a/misc/fonts/sanshu-16.xinefont.gz b/misc/fonts/sanshu-16.xinefont.gz Binary files differindex 4ad4ffbe9..07b08ec8d 100644 --- a/misc/fonts/sanshu-16.xinefont.gz +++ b/misc/fonts/sanshu-16.xinefont.gz diff --git a/misc/fonts/sanshu-20.xinefont.gz b/misc/fonts/sanshu-20.xinefont.gz Binary files differindex 2f2786ba8..b048455ca 100644 --- a/misc/fonts/sanshu-20.xinefont.gz +++ b/misc/fonts/sanshu-20.xinefont.gz diff --git a/misc/fonts/sanshu-24.xinefont.gz b/misc/fonts/sanshu-24.xinefont.gz Binary files differindex 5dc8ae307..207422c7e 100644 --- a/misc/fonts/sanshu-24.xinefont.gz +++ b/misc/fonts/sanshu-24.xinefont.gz diff --git a/misc/fonts/sanshu-32.xinefont.gz b/misc/fonts/sanshu-32.xinefont.gz Binary files differindex 80904af42..4958bafce 100644 --- a/misc/fonts/sanshu-32.xinefont.gz +++ b/misc/fonts/sanshu-32.xinefont.gz diff --git a/misc/fonts/serif-16.xinefont.gz b/misc/fonts/serif-16.xinefont.gz Binary files differindex f2aef91c5..e2eb35efe 100644 --- a/misc/fonts/serif-16.xinefont.gz +++ b/misc/fonts/serif-16.xinefont.gz diff --git a/misc/fonts/serif-20.xinefont.gz b/misc/fonts/serif-20.xinefont.gz Binary files differindex 36a714c86..9e86ae1b1 100644 --- a/misc/fonts/serif-20.xinefont.gz +++ b/misc/fonts/serif-20.xinefont.gz diff --git a/misc/fonts/serif-24.xinefont.gz b/misc/fonts/serif-24.xinefont.gz Binary files differindex 699721d2a..3d4a6efc9 100644 --- a/misc/fonts/serif-24.xinefont.gz +++ b/misc/fonts/serif-24.xinefont.gz diff --git a/misc/fonts/serif-32.xinefont.gz b/misc/fonts/serif-32.xinefont.gz Binary files differindex 912e22b62..e4db6fa33 100644 --- a/misc/fonts/serif-32.xinefont.gz +++ b/misc/fonts/serif-32.xinefont.gz diff --git a/misc/xine-fontconv.c b/misc/xine-fontconv.c index a1be59aae..2fcdbce25 100644 --- a/misc/xine-fontconv.c +++ b/misc/xine-fontconv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001-2002 the xine project + * Copyright (C) 2001-2003 the xine project * * This file is part of xine, a free video player. * @@ -24,18 +24,20 @@ * converts ttf fonts to xine osd fonts * * compile: - * gcc -o xine-fontconv xine-fontconv.c -lfreetype -lz -I/usr/include/freetype2 + * gcc -o xine-fontconv xine-fontconv.c `freetype-config --cflags` -lz `freetype-config --libs` * * usage: - * xine-fontconv font.ttf fontname [encoding] + * xine-fontconv font.ttf fontname [encoding1 [encoding2 [...]]] * * begin : Sat Dec 1 2001 * copyright : (C) 2001 by Miguel Freitas + * unicode stuff : (C) 2003 by Frantisek Dvorak */ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <malloc.h> #include <zlib.h> #include <iconv.h> @@ -55,6 +57,10 @@ #define f266CeilToInt(x) (((x)+63)>>6) /* ceiling */ #define f266FloorToInt(x) ((x)>>6) /* floor */ +/* +#define LOG 1 +*/ + /* xine stuff */ typedef struct osd_fontchar_s osd_fontchar_t; typedef struct osd_font_s osd_font_t; @@ -77,11 +83,127 @@ struct osd_font_s { osd_font_t *next; }; + +/* list */ + +typedef struct item_s item_t; + +struct item_s { + uint16_t code; + item_t *next; +}; + + osd_fontchar_t fontchar; osd_font_t font; -iconv_t cd; // iconv conversion descriptor +static int gzwrite_i16(gzFile *fp, uint16_t number) { + return gzputc(fp, number & 0xFF) != -1 && + gzputc(fp, (number >> 8) & 0xFF) != -1; +} + + +/* search the item with 'code' in the sorted list */ +item_t *list_search(item_t *list, uint16_t code, item_t **parent) { + item_t *item; + + /* searching */ + item = list; + while(item && item->code < code) { + list = item; + item = item->next; + } + + /* parent (or future parent) */ + if (parent) *parent = list == item ? NULL : list; + + if (item && item->code == code) return item; + else return NULL; +} + +/* add new number into sorted list, returns if code is there already */ +int list_insert(item_t **list, uint16_t code) { + item_t *item, *parent; + + if ((item = list_search(*list, code, &parent)) == NULL) { + /* insert new item */ + if ((item = malloc(sizeof(item_t))) == NULL) { + printf("Insufficient memory\n"); + abort(); + } + item->code = code; + if (parent) { + item->next = parent->next; + parent->next = item; + } else { + item->next = *list; + *list = item; + } + return 0; + } else { + /* item is there already */ + return 1; + } +} + +/* free the list */ +void list_free(item_t *list) { + item_t *item; + + while(list != NULL) { + item = list; + list = list->next; + free(item); + } +} + +/* + * generate sorted list with unicodes in all given pages, + * returns number of unicodes in the list + */ +uint16_t generate_unicodes_list(item_t **list, char **pages, int number) { + int page; + uint16_t codes_count = 0; /* unicode counter */ + unsigned char z; /* index in codepage */ + iconv_t cd; /* iconv conversion descriptor */ + + *list = NULL; + + /* process all given codepages */ + for (page = 0; page < number; page++) { + /* prepare encoding */ + if ((cd = iconv_open("UCS-2", pages[page])) == (iconv_t)-1) { + printf("Unsupported encoding \"%s\"\n", pages[page]); + continue; + } + printf("Used encoding \"%s\"\n", pages[page]); + + /* add new unicodes into list */ + for (z = 32; z < 0xff; z++) { + uint16_t unicode; + char *inbuf = (char *)&z; + char *outbuf = (char *)&unicode; + size_t inbytesleft = 1; + size_t outbytesleft = 2; + size_t count; + + /* get unicode value from index 'z' in this codepage 'pages[i]' */ + count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (count == (size_t)-1) { + /* unused index 'z' in this codepage */ + continue; + } + + if (!list_insert(list, unicode)) codes_count++; + } + iconv_close(cd); + } + + return codes_count; +} + +#ifdef LOG void print_bitmap (FT_Bitmap *bitmap) { int x,y; @@ -96,10 +218,14 @@ void print_bitmap (FT_Bitmap *bitmap) { printf("\n"); } } +#endif FT_Bitmap *create_bitmap (int width, int height) { FT_Bitmap * bitmap; + +#ifdef LOG printf("Bitmap char %d %d\n",width,height); +#endif bitmap = malloc( sizeof( FT_Bitmap ) ); bitmap->rows = height; bitmap->width = width; @@ -199,12 +325,14 @@ void add_final_bitmap( FT_Bitmap *dst, FT_Bitmap *src, int left, int top ) } -void render_font (FT_Face face, char *fontname, int size, int thickness) { +void render_font (FT_Face face, char *fontname, int size, int thickness, + item_t *unicodes) { char filename[1024]; FT_Bitmap *out_bitmap; gzFile *fp; int error; + int error_counter; int glyph_index; FT_Glyph glyph; FT_BitmapGlyph glyph_bitmap; @@ -212,7 +340,7 @@ void render_font (FT_Face face, char *fontname, int size, int thickness) { int max_bearing_y = 0; int i; int converted; - unsigned char c; + item_t *item, *error_unicodes; static int border_pos[9][2] = { {-1,0},{1,0},{0,-1},{0,1}, @@ -238,7 +366,11 @@ void render_font (FT_Face face, char *fontname, int size, int thickness) { */ strcpy(font.name, fontname); - font.version = 1; + /* changes from version 1 to version 2: + * 'code' in characters is defined as little endian 16-bit unicode + * characters are sorted by 'code' + */ + font.version = 2; font.num_fontchars = 0; font.size = size; @@ -259,32 +391,30 @@ void render_font (FT_Face face, char *fontname, int size, int thickness) { * this is needed to align all bitmaps by the upper position. */ - for (c = 32; c < 0xff; c++) { - unsigned int o=0; - char *inbuf = &c; - char *outbuf = (char*)&o; - int inbytesleft = 1; - int outbytesleft = sizeof(unsigned int); - - size_t count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - - if (count==-1) - continue; + error_counter = 0; + error_unicodes = NULL; + for (item = unicodes; item; item = item->next) { + glyph_index = FT_Get_Char_Index( face, item->code); - glyph_index = FT_Get_Char_Index( face, o); - - if (!glyph_index) + if (!glyph_index) { + error_counter++; + list_insert(&error_unicodes, item->code); continue; + } error = FT_Load_Glyph (face, /* handle to face object */ glyph_index, /* glyph index */ FT_LOAD_DEFAULT ); /* load flags */ if (error) { + error_counter++; + list_insert(&error_unicodes, item->code); continue; } - printf("bearing_y %d\n",face->glyph->metrics.horiBearingY); +#ifdef LOG + printf("bearing_y %ld\n",face->glyph->metrics.horiBearingY); +#endif if( (face->glyph->metrics.horiBearingY >> 6) > max_bearing_y ) max_bearing_y = (face->glyph->metrics.horiBearingY >> 6); @@ -293,26 +423,17 @@ void render_font (FT_Face face, char *fontname, int size, int thickness) { printf("max_bearing_y: %d\n", max_bearing_y + f266CeilToInt(thickness)); - gzwrite (fp, &font, 40+6); - - for (c = 32; c < 0xff; c++) { - unsigned int o=0; - char *inbuf = &c; - char *outbuf = (char*)&o; - int inbytesleft = 1; - int outbytesleft = sizeof(unsigned int); - - size_t count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + gzwrite(fp, font.name, sizeof(font.name)); + gzwrite_i16(fp, font.version); + gzwrite_i16(fp, font.size); + gzwrite_i16(fp, font.num_fontchars); + for (item = unicodes; item; item = item->next) { converted = 0; - if (count==-1) - continue; - - for( i=0; i < 9; i++ ) { - glyph_index = FT_Get_Char_Index( face, o); + glyph_index = FT_Get_Char_Index( face, item->code); if (glyph_index) { @@ -333,11 +454,12 @@ void render_font (FT_Face face, char *fontname, int size, int thickness) { origin.x = thickness + border_pos[i][0]*thickness; origin.y = thickness + border_pos[i][1]*thickness; - error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, &origin, 1 ); + error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, &origin, 1); if (error) { - printf("error generating bitmap [%d]\n",c); + printf("error generating bitmap [U+%04X]\n", item->code); + destroy_bitmap(out_bitmap); return; } @@ -352,29 +474,46 @@ void render_font (FT_Face face, char *fontname, int size, int thickness) { converted = 1; FT_Done_Glyph( glyph ); - } } } if( converted ) { - printf("[%c:%d] bitmap width: %d height: %d\n", c, c, out_bitmap->width, out_bitmap->rows ); +#ifdef LOG + printf("[U+%04X] bitmap width: %d height: %d\n", item->code, out_bitmap->width, out_bitmap->rows ); /* print_bitmap(out_bitmap); */ - fontchar.code = c; +#endif + fontchar.code = item->code; fontchar.width = out_bitmap->width; fontchar.height = out_bitmap->rows; - gzwrite (fp, &fontchar,6); + gzwrite_i16 (fp, fontchar.code); + gzwrite_i16 (fp, fontchar.width); + gzwrite_i16 (fp, fontchar.height); gzwrite (fp, out_bitmap->buffer, out_bitmap->width*out_bitmap->rows); + + destroy_bitmap(out_bitmap); } } gzclose(fp); + if (error_counter) { + printf("error: %d characters couldn't read: ", error_counter); + /* this unicodes wasn't readed from .ttf font */ + item = error_unicodes; + while(item) { + printf("U+%04X ", item->code); + item = item->next; + } + printf("\n"); + list_free(error_unicodes); + } printf ("generated %s (%d)\n", filename, font.num_fontchars); } + int main(int argc, char *argv[]) { int error; @@ -382,14 +521,17 @@ int main(int argc, char *argv[]) { FT_Library library; FT_Face face; int thickness = 0; - char* encoding; + char *encoding = "iso-8859-1"; + item_t *unicodes = NULL; /* unicode list */ + item_t *item; + uint16_t count; /* * command line parsing */ - if (argc<3 || argc>4) { - printf ("usage:%s font.ttf fontname [encoding]\n", argv[0]); + if (argc < 3) { + printf ("usage: %s font.ttf fontname [encoding1 [encoding2 [...]]]\n", argv[0]); exit (1); } @@ -403,6 +545,7 @@ int main(int argc, char *argv[]) { error = FT_Init_FreeType( &library ); if( error ) { printf("error initializing freetype\n"); + return 1; } error = FT_New_Face( library, @@ -413,25 +556,31 @@ int main(int argc, char *argv[]) { printf("error loading font\n"); return 1; } + error = FT_Select_Charmap( face, ft_encoding_unicode); + if (error) { + printf("error selecting unicode charmap\n"); + return 1; + } - if (argc==4) { - encoding=argv[3]; + if (argc == 3) { + count = generate_unicodes_list(&unicodes, &encoding, 1); } else { - encoding="UNICODE"; //default target charset - no conv - } - - cd = iconv_open("UNICODE", encoding); - if (cd==(iconv_t)-1) { - printf("Unsupported encoding"); - return 1; + count = generate_unicodes_list(&unicodes, argv + 3, argc - 3); } + printf("Prepared %d unicode values: ", count); + for (item = unicodes; item; item = item->next) printf("U+%04X ", item->code); + printf("\n"); - render_font (face, argv[2], 16, thickness); - render_font (face, argv[2], 20, thickness); - render_font (face, argv[2], 24, thickness); - render_font (face, argv[2], 32, thickness); + render_font (face, argv[2], 16, thickness, unicodes); + render_font (face, argv[2], 20, thickness, unicodes); + render_font (face, argv[2], 24, thickness, unicodes); + render_font (face, argv[2], 32, thickness, unicodes); - iconv_close(cd); + list_free(unicodes); + + FT_Done_Face(face); + + FT_Done_FreeType(library); /* * some rgb -> yuv conversion, diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c index 12eac8114..a6e428782 100644 --- a/src/input/input_dvb.c +++ b/src/input/input_dvb.c @@ -369,6 +369,7 @@ static void osd_show_channel (dvb_input_plugin_t *this) { if ( (channel >= 0) && (channel < this->num_channels) ) this->stream->osd_renderer->render_text (this->osd, 10, 10+i*35, this->channels[channel].name, + "iso-8859-1", OSD_TEXT3); channel ++; } diff --git a/src/libspucc/cc_decoder.c b/src/libspucc/cc_decoder.c index fd3238e55..ca52f869e 100644 --- a/src/libspucc/cc_decoder.c +++ b/src/libspucc/cc_decoder.c @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: cc_decoder.c,v 1.19 2003/03/08 14:11:52 mroi Exp $ + * $Id: cc_decoder.c,v 1.20 2003/03/26 11:06:55 miguelfreitas Exp $ * * stuff needed to provide closed captioning decoding and display * @@ -641,9 +641,11 @@ static void ccrow_render(cc_renderer_t *renderer, cc_row_t *this, int rownum) buf[i - seg_pos[seg]] = this->cells[i].c; buf[seg_pos[seg + 1] - seg_pos[seg]] = '\0'; ccrow_set_attributes(renderer, this, seg_attr[seg]); + + /* text is already mapped from EIA-608 into iso-8859-1 */ osd_renderer->render_text(renderer->cap_display, - x + cumulative_seg_width[seg], y, buf, - textcol); + x + cumulative_seg_width[seg], y, buf, + "iso-8859-1", textcol); } pos = ccrow_find_next_text_part(this, endpos); diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c index 53cb182a2..db0c96b59 100644 --- a/src/libsputext/demux_sputext.c +++ b/src/libsputext/demux_sputext.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: demux_sputext.c,v 1.12 2003/02/14 16:58:36 f1rmb Exp $ + * $Id: demux_sputext.c,v 1.13 2003/03/26 11:06:56 miguelfreitas Exp $ * * code based on old libsputext/xine_decoder.c * @@ -42,7 +42,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <ctype.h> -#include <iconv.h> #include "xine_internal.h" #include "xineutils.h" @@ -707,7 +706,6 @@ static subtitle_t *sub_read_file (demux_sputext_t *this) { sub_read_line_aqt }; - iconv_t iconv_descr; this->format=sub_autodetect (this); if (this->format==-1) { @@ -725,10 +723,9 @@ static subtitle_t *sub_read_file (demux_sputext_t *this) { first = (subtitle_t *) xine_xmalloc(n_max*sizeof(subtitle_t)); if(!first) return NULL; - iconv_descr=iconv_open(class->dst_encoding,class->src_encoding); - while(1){ subtitle_t *sub; + if(this->num>=n_max){ n_max+=16; first=realloc(first,n_max*sizeof(subtitle_t)); @@ -746,28 +743,9 @@ static subtitle_t *sub_read_file (demux_sputext_t *this) { if (this->num > 0 && first[this->num-1].end == -1) { first[this->num-1].end = sub->start; } - for(i=0; i<first[this->num].lines; i++) - { char *tmp; - char *in_buff, *out_buff; - int in_len, out_len; - - in_len=strlen(first[this->num].text[i])+1; - tmp=malloc(in_len); - in_buff=first[this->num].text[i]; - out_buff=tmp; - out_len=in_len; - if ((size_t)(-1)!=iconv(iconv_descr,&in_buff,&in_len,&out_buff,&out_len)) - { free(first[this->num].text[i]); - first[this->num].text[i]=tmp; - } - else { - printf("demux_sputext: Can't convert subtitle text\n"); - } - } ++this->num; /* Error vs. Valid */ } } - iconv_close(iconv_descr); printf ("demux_sputext: Read %i subtitles", this->num); if (this->errs) @@ -778,24 +756,6 @@ static subtitle_t *sub_read_file (demux_sputext_t *this) { return first; } -static void update_osd_src_encoding(void *this_gen, xine_cfg_entry_t *entry) -{ - demux_sputext_class_t *class = (demux_sputext_class_t *)this_gen; - - class->src_encoding = entry->str_value; - - printf("demux_sputext: spu_src_encoding = %s\n", class->src_encoding ); -} - -static void update_osd_dst_encoding(void *this_gen, xine_cfg_entry_t *entry) -{ - demux_sputext_class_t *class = (demux_sputext_class_t *)this_gen; - - class->dst_encoding = entry->str_value; - - printf("demux_sputext: spu_dst_encoding = %s\n", class->dst_encoding ); -} - static int demux_sputext_next (demux_sputext_t *this_gen) { demux_sputext_t *this = (demux_sputext_t *) this_gen; buf_element_t *buf; @@ -1022,17 +982,6 @@ static void *init_sputext_demux_class (xine_t *xine, void *data) { this->demux_class.get_extensions = get_demux_extensions; this->demux_class.dispose = demux_class_dispose; - this->src_encoding = xine->config->register_string(xine->config, - "misc.spu_src_encoding", - "windows-1250", - _("source encoding of subtitles"), - NULL, 10, update_osd_src_encoding, this); - this->dst_encoding = xine->config->register_string(xine->config, - "misc.spu_dst_encoding", - "iso-8859-2", - _("target encoding for subtitles (have to match font encoding)"), - NULL, 10, update_osd_dst_encoding, this); - return this; } diff --git a/src/libsputext/xine_decoder.c b/src/libsputext/xine_decoder.c index 3b7a7e1ad..4654b0c36 100644 --- a/src/libsputext/xine_decoder.c +++ b/src/libsputext/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.55 2003/03/20 20:44:18 f1rmb Exp $ + * $Id: xine_decoder.c,v 1.56 2003/03/26 11:06:56 miguelfreitas Exp $ * */ @@ -29,7 +29,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <ctype.h> -#include <iconv.h> #include "buffer.h" #include "xine_internal.h" @@ -57,6 +56,8 @@ typedef enum { typedef struct sputext_class_s { spu_decoder_class_t class; + char *src_encoding; /* encoding of subtitle file */ + xine_t *xine; } sputext_class_t; @@ -79,11 +80,10 @@ typedef struct sputext_decoder_s { int master_started; int slave_started; - char *font; - subtitle_size subtitle_size; + char *font; /* subtitle font */ + subtitle_size subtitle_size; /* size of subtitles */ int vertical_offset; - osd_renderer_t *renderer; osd_object_t *osd; @@ -159,7 +159,8 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su } this->renderer->render_text (this->osd, x, y + line*this->line_height, - this->text[line], OSD_TEXT1); + this->text[line], this->class->src_encoding, + OSD_TEXT1); } if( font_size != this->font_size ) @@ -407,19 +408,19 @@ static spu_decoder_t *sputext_class_open_plugin (spu_decoder_class_t *class_gen, this->stream = stream; this->font = class->xine->config->register_string(class->xine->config, - "codec.spu_font", + "misc.spu_font", "sans", - _("font for avi subtitles"), + _("font for external subtitles"), NULL, 0, update_osd_font, this); this->subtitle_size = class->xine->config->register_enum(class->xine->config, - "codec.spu_subtitle_size", + "misc.spu_subtitle_size", 1, subtitle_size_strings, _("subtitle size (relative window size)"), NULL, 0, update_subtitle_size, this); this->vertical_offset = class->xine->config->register_num(class->xine->config, - "codec.spu_vertical_offset", + "misc.spu_vertical_offset", 0, _("subtitle vertical offset (relative window size)"), NULL, 0, update_vertical_offset, this); @@ -439,6 +440,13 @@ static char *sputext_class_get_description (spu_decoder_class_t *this) { return "external subtitle decoder plugin"; } +static void update_src_encoding(void *this_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *this = (sputext_class_t *)this_gen; + + this->src_encoding = entry->str_value; + printf("libsputext: spu_src_encoding = %s\n", this->src_encoding ); +} static void *init_spu_decoder_plugin (xine_t *xine, void *data) { @@ -457,6 +465,12 @@ static void *init_spu_decoder_plugin (xine_t *xine, void *data) { this->xine = xine; + this->src_encoding = xine->config->register_string(xine->config, + "misc.spu_src_encoding", + "iso-8859-1", + _("encoding of subtitles"), + NULL, 10, update_src_encoding, this); + return &this->class; } diff --git a/src/xine-engine/osd.c b/src/xine-engine/osd.c index 85837ef84..8e896b9e8 100644 --- a/src/xine-engine/osd.c +++ b/src/xine-engine/osd.c @@ -32,6 +32,9 @@ #include <zlib.h> #include <sys/types.h> #include <dirent.h> +#include <errno.h> +#include <iconv.h> +#include <langinfo.h> #include "xine_internal.h" #include "video_out/alphablend.h" @@ -44,6 +47,11 @@ #define LOG_DEBUG 1 */ +#define BINARY_SEARCH 1 + +/* unicode value of alias character (it used if conversion fails) */ +#define ALIAS_CHARACTER ' ' + #ifdef MAX #undef MAX #endif @@ -478,7 +486,7 @@ static uint16_t gzread_i16(gzFile *fp) { load bitmap font into osd engine */ -static void osd_renderer_load_font(osd_renderer_t *this, char *filename) { +static int osd_renderer_load_font(osd_renderer_t *this, char *filename) { gzFile *fp; osd_font_t *font = NULL; @@ -504,14 +512,14 @@ static void osd_renderer_load_font(osd_renderer_t *this, char *filename) { font->fontchar = malloc( sizeof(osd_fontchar_t) * font->num_fontchars ); #ifdef LOG_DEBUG - printf("osd: font %s %d\n",font->name, font->num_fontchars); + printf("osd: font %s %d\n", font->name, font->num_fontchars); #endif for( i = 0; i < font->num_fontchars; i++ ) { font->fontchar[i].code = gzread_i16(fp); font->fontchar[i].width = gzread_i16(fp); font->fontchar[i].height = gzread_i16(fp); font->fontchar[i].bmp = malloc(font->fontchar[i].width*font->fontchar[i].height); - if( gzread(fp,font->fontchar[i].bmp, + if( gzread(fp, font->fontchar[i].bmp, font->fontchar[i].width*font->fontchar[i].height) <= 0 ) break; } @@ -543,6 +551,7 @@ static void osd_renderer_load_font(osd_renderer_t *this, char *filename) { } pthread_mutex_unlock (&this->osd_mutex); + return ret; } /* @@ -582,6 +591,7 @@ static int osd_renderer_unload_font(osd_renderer_t *this, char *fontname ) { else this->fonts = font->next; free( font ); + ret = 1; break; } last = font; @@ -633,18 +643,46 @@ static int osd_set_font( osd_object_t *osd, const char *fontname, int size) { } +#ifdef BINARY_SEARCH +/* + * search the character in the sorted array + */ +static int binsearch(osd_fontchar_t *array, size_t n, uint16_t code) { + size_t i, left, right; + + if (!n) return 0; + + left = 0; + right = n - 1; + while (right > left) { + i = (left + right) >> 1; + if (code <= array[i].code) right = i; + else left = i + 1; + } + + return array[right].code == code ? right : n; +} +#endif + + /* - * render text on x,y position (8 bits version) + * render text on x,y position * no \n yet + * if encoding == NULL current locale encoding is used */ static int osd_render_text (osd_object_t *osd, int x1, int y1, - const char *text, int color_base) { + const char *text, const char *encoding, + int color_base) { osd_renderer_t *this = osd->renderer; osd_font_t *font; int i, y; uint8_t *dst, *src; - int c; + iconv_t cd; + char *inbuf; + uint16_t unicode; + size_t inbytesleft; + int def_charset_flag = 0; #ifdef LOG_DEBUG printf("osd_render_text %p (%d,%d) \"%s\"\n", osd, x1, y1, text); @@ -658,23 +696,74 @@ static int osd_render_text (osd_object_t *osd, int x1, int y1, pthread_mutex_lock (&this->osd_mutex); - font = osd->font; + if ((font = osd->font) == NULL) { + printf(_("osd: font isn't defined\n")); + pthread_mutex_unlock(&this->osd_mutex); + return 0; + } if( x1 < osd->x1 ) osd->x1 = x1; if( y1 < osd->y1 ) osd->y1 = y1; - while( font && *text ) { - c = *text & 0xff; - + inbuf = (char *)text; + inbytesleft = strlen(text); + + if (!encoding) { +#ifdef ENABLE_NLS + if ((encoding = nl_langinfo(CODESET)) == NULL) { + printf(_("osd: can't find out current locale character set\n")); + encoding = "iso-8859-1"; + def_charset_flag = 1; + } +#else + encoding = "iso-8859-1"; + def_charset_flag = 1; +#endif + } + + /* prepare conversion to UCS-2 */ + if ((cd = iconv_open("UCS-2", encoding)) == (iconv_t)-1) { + printf(_("osd: unsupported conversion %s -> UCS-2\n"), encoding); + if (!def_charset_flag) { + printf("osd: trying iso-8859-1 -> UCS-2\n"); + if ((cd = iconv_open("UCS-2", "iso-8859-1")) == (iconv_t)-1) { + printf(_("osd: iconv_open() failed\n")); + pthread_mutex_unlock(&this->osd_mutex); + return 0; + } + } + } + + while( inbytesleft ) { + char *outbuf = (char*)&unicode; + size_t outbytesleft = 2; + size_t count; + + /* get unicode value */ + count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (count == (size_t)-1 && errno != E2BIG) { + /* unknown character or character wider than 16 bits, try skip one byte */ + printf(_("osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", skipping\n"), + inbuf[0] & 0xFF, encoding); + if (!inbytesleft) break; + inbytesleft--; + inbuf++; + unicode = ALIAS_CHARACTER; + } + +#ifdef BINARY_SEARCH + i = binsearch(font->fontchar, font->num_fontchars, unicode); +#else for( i = 0; i < font->num_fontchars; i++ ) { - if( font->fontchar[i].code == c ) + if( font->fontchar[i].code == unicode ) break; } +#endif #ifdef LOG_DEBUG - printf("font %s [%c:%d] %dx%d -> %d,%d\n",font->name, c, font->fontchar[i].code, - font->fontchar[i].width, font->fontchar[i].height, - x1,y1); + printf("font %s [%d, U+%04X] %dx%d -> %d,%d\n", font->name, i, + unicode, font->fontchar[i].code, font->fontchar[i].width, + font->fontchar[i].height, x1, y1); #endif if ( i != font->num_fontchars ) { @@ -701,8 +790,8 @@ static int osd_render_text (osd_object_t *osd, int x1, int y1, if( y1 + font->fontchar[i].height > osd->y2 ) osd->y2 = y1 + font->fontchar[i].height; } - text++; } + iconv_close(cd); pthread_mutex_unlock (&this->osd_mutex); diff --git a/src/xine-engine/osd.h b/src/xine-engine/osd.h index aa4b36baf..9c2959f77 100644 --- a/src/xine-engine/osd.h +++ b/src/xine-engine/osd.h @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * OSD stuff (text and graphic primitives) - * $Id: osd.h,v 1.13 2003/03/08 17:22:16 f1rmb Exp $ + * $Id: osd.h,v 1.14 2003/03/26 11:06:58 miguelfreitas Exp $ */ #ifndef HAVE_OSD_H @@ -152,7 +152,7 @@ struct osd_renderer_s { * Use OSD_TEXT1, OSD_TEXT2, ... for some preasssigned color indices. */ int (*render_text) (osd_object_t *osd, int x1, int y1, - const char *text, int color_base); + const char *text, const char *encoding, int color_base); /* * get width and height of how text will be renderized diff --git a/src/xine-engine/xine_interface.c b/src/xine-engine/xine_interface.c index 430776782..72167bd12 100644 --- a/src/xine-engine/xine_interface.c +++ b/src/xine-engine/xine_interface.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_interface.c,v 1.45 2003/03/08 20:25:52 guenter Exp $ + * $Id: xine_interface.c,v 1.46 2003/03/26 11:06:59 miguelfreitas Exp $ * * convenience/abstraction layer, functions to implement * libxine's public interface @@ -565,7 +565,7 @@ void xine_osd_draw_rect(xine_osd_t *this, int x1, int y1, int x2, int y2, int co } void xine_osd_draw_text(xine_osd_t *this, int x1, int y1, const char *text, int color_base) { - this->osd.renderer->render_text(&this->osd, x1, y1, text, color_base); + this->osd.renderer->render_text(&this->osd, x1, y1, text, NULL, color_base); } void xine_osd_get_text_size(xine_osd_t *this, const char *text, int *width, int *height) { |