Mercurial > mplayer.hg
comparison libvo/font_load_ft.c @ 19208:99d6ca895c46
Avoid large amounts of data on the stack (> 900k on 64 bit systems).
Patch by Tobias Diedrich (ranma at tdiedrich de) with minor modifications by me.
author | reimar |
---|---|
date | Fri, 28 Jul 2006 13:50:08 +0000 |
parents | 3f01e230c898 |
children | d7c2e093e406 |
comparison
equal
deleted
inserted
replaced
19207:c636a4e9565a | 19208:99d6ca895c46 |
---|---|
953 return f266ToInt(kern.x); | 953 return f266ToInt(kern.x); |
954 } | 954 } |
955 | 955 |
956 font_desc_t* read_font_desc_ft(const char *fname, int movie_width, int movie_height) | 956 font_desc_t* read_font_desc_ft(const char *fname, int movie_width, int movie_height) |
957 { | 957 { |
958 font_desc_t *desc; | 958 font_desc_t *desc = NULL; |
959 | 959 |
960 FT_Face face; | 960 FT_Face face; |
961 | 961 |
962 FT_ULong my_charset[MAX_CHARSET_SIZE]; /* characters we want to render; Unicode */ | 962 FT_ULong *my_charset = malloc(MAX_CHARSET_SIZE * sizeof(FT_ULong)); /* characters we want to render; Unicode */ |
963 FT_ULong my_charcodes[MAX_CHARSET_SIZE]; /* character codes in 'encoding' */ | 963 FT_ULong *my_charcodes = malloc(MAX_CHARSET_SIZE * sizeof(FT_ULong)); /* character codes in 'encoding' */ |
964 | 964 |
965 char *charmap = "ucs-4"; | 965 char *charmap = "ucs-4"; |
966 int err; | 966 int err; |
967 int charset_size; | 967 int charset_size; |
968 int i, j; | 968 int i, j; |
970 | 970 |
971 float movie_size; | 971 float movie_size; |
972 | 972 |
973 float subtitle_font_ppem; | 973 float subtitle_font_ppem; |
974 float osd_font_ppem; | 974 float osd_font_ppem; |
975 | |
976 if (my_charset == NULL || my_charcodes == NULL) { | |
977 mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: malloc failed.\n"); | |
978 goto err_out; | |
979 } | |
975 | 980 |
976 switch (subtitle_autoscale) { | 981 switch (subtitle_autoscale) { |
977 case 1: | 982 case 1: |
978 movie_size = movie_height; | 983 movie_size = movie_height; |
979 break; | 984 break; |
1003 } else { | 1008 } else { |
1004 unicode = 0; | 1009 unicode = 0; |
1005 } | 1010 } |
1006 | 1011 |
1007 desc = init_font_desc(); | 1012 desc = init_font_desc(); |
1008 if(!desc) return NULL; | 1013 if(!desc) goto err_out; |
1009 | 1014 |
1010 // t=GetTimer(); | 1015 // t=GetTimer(); |
1011 | 1016 |
1012 /* generate the subtitle font */ | 1017 /* generate the subtitle font */ |
1013 err = load_sub_face(fname, &face); | 1018 err = load_sub_face(fname, &face); |
1028 } | 1033 } |
1029 } | 1034 } |
1030 | 1035 |
1031 if (charset_size < 0) { | 1036 if (charset_size < 0) { |
1032 mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: prepare_charset failed.\n"); | 1037 mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: prepare_charset failed.\n"); |
1033 free_font_desc(desc); | 1038 goto err_out; |
1034 return NULL; | |
1035 } | 1039 } |
1036 #else | 1040 #else |
1037 return NULL; | 1041 goto err_out; |
1038 #endif | 1042 #endif |
1039 | 1043 |
1040 // fprintf(stderr, "fg: prepare t = %lf\n", GetTimer()-t); | 1044 // fprintf(stderr, "fg: prepare t = %lf\n", GetTimer()-t); |
1041 | 1045 |
1042 err = prepare_font(desc, face, subtitle_font_ppem, desc->face_cnt-1, | 1046 err = prepare_font(desc, face, subtitle_font_ppem, desc->face_cnt-1, |
1043 charset_size, my_charset, my_charcodes, unicode, | 1047 charset_size, my_charset, my_charcodes, unicode, |
1044 subtitle_font_thickness, subtitle_font_radius); | 1048 subtitle_font_thickness, subtitle_font_radius); |
1045 | 1049 |
1046 if (err) { | 1050 if (err) { |
1047 mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare subtitle font.\n"); | 1051 mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare subtitle font.\n"); |
1048 free_font_desc(desc); | 1052 goto err_out; |
1049 return NULL; | |
1050 } | 1053 } |
1051 | 1054 |
1052 gen_osd: | 1055 gen_osd: |
1053 | 1056 |
1054 /* generate the OSD font */ | 1057 /* generate the OSD font */ |
1055 err = load_osd_face(&face); | 1058 err = load_osd_face(&face); |
1056 if (err) { | 1059 if (err) { |
1057 free_font_desc(desc); | 1060 goto err_out; |
1058 return NULL; | |
1059 } | 1061 } |
1060 desc->face_cnt++; | 1062 desc->face_cnt++; |
1061 | 1063 |
1062 err = prepare_font(desc, face, osd_font_ppem, desc->face_cnt-1, | 1064 err = prepare_font(desc, face, osd_font_ppem, desc->face_cnt-1, |
1063 OSD_CHARSET_SIZE, osd_charset, osd_charcodes, 0, | 1065 OSD_CHARSET_SIZE, osd_charset, osd_charcodes, 0, |
1064 subtitle_font_thickness, subtitle_font_radius); | 1066 subtitle_font_thickness, subtitle_font_radius); |
1065 | 1067 |
1066 if (err) { | 1068 if (err) { |
1067 mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare OSD font.\n"); | 1069 mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare OSD font.\n"); |
1068 free_font_desc(desc); | 1070 goto err_out; |
1069 return NULL; | |
1070 } | 1071 } |
1071 | 1072 |
1072 err = generate_tables(desc, subtitle_font_thickness, subtitle_font_radius); | 1073 err = generate_tables(desc, subtitle_font_thickness, subtitle_font_radius); |
1073 | 1074 |
1074 if (err) { | 1075 if (err) { |
1075 mp_msg(MSGT_OSD, MSGL_ERR, "Cannot generate tables.\n"); | 1076 mp_msg(MSGT_OSD, MSGL_ERR, "Cannot generate tables.\n"); |
1076 free_font_desc(desc); | 1077 goto err_out; |
1077 return NULL; | |
1078 } | 1078 } |
1079 | 1079 |
1080 // final cleanup | 1080 // final cleanup |
1081 desc->font[' ']=-1; | 1081 desc->font[' ']=-1; |
1082 desc->width[' ']=desc->spacewidth; | 1082 desc->width[' ']=desc->spacewidth; |
1090 desc->start[i] = desc->start[j]; | 1090 desc->start[i] = desc->start[j]; |
1091 desc->width[i] = desc->width[j]; | 1091 desc->width[i] = desc->width[j]; |
1092 desc->font[i] = desc->font[j]; | 1092 desc->font[i] = desc->font[j]; |
1093 } | 1093 } |
1094 } | 1094 } |
1095 free(my_charset); | |
1096 free(my_charcodes); | |
1095 return desc; | 1097 return desc; |
1098 | |
1099 err_out: | |
1100 if (desc) | |
1101 free_font_desc(desc); | |
1102 free(my_charset); | |
1103 free(my_charcodes); | |
1104 return NULL; | |
1096 } | 1105 } |
1097 | 1106 |
1098 int init_freetype(void) | 1107 int init_freetype(void) |
1099 { | 1108 { |
1100 int err; | 1109 int err; |