|
|
959f1c6 |
Remove alfont_get_string
|
|
|
959f1c6 |
|
|
|
959f1c6 |
alfont_get_string has a weird, weird API where its destination is char **out,
|
|
|
959f1c6 |
yet it does not return an allocated buffer in out, instead it uses _msize
|
|
|
959f1c6 |
on it to check if the passed in buffer is big enough ?? Which means the
|
|
|
959f1c6 |
parameter could have been a char * just as well ??
|
|
|
959f1c6 |
|
|
|
959f1c6 |
Anyways we don't have _msize on Linux, and no alfont using apps actually use
|
|
|
959f1c6 |
alfont_get_string(), so this patch just removes it completely, fixing the
|
|
|
959f1c6 |
_msize problem.
|
|
|
959f1c6 |
|
|
|
959f1c6 |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
959f1c6 |
diff -up alfont-2.0.9/include/alfont.h~ alfont-2.0.9/include/alfont.h
|
|
|
959f1c6 |
--- alfont-2.0.9/include/alfont.h~ 2012-07-29 11:51:08.000000000 +0200
|
|
|
959f1c6 |
+++ alfont-2.0.9/include/alfont.h 2012-07-29 11:58:53.194121909 +0200
|
|
|
959f1c6 |
@@ -103,8 +103,6 @@ ALFONT_DLL_DECLSPEC int alfont_ugetc(ALF
|
|
|
959f1c6 |
ALFONT_DLL_DECLSPEC int alfont_ugetx(ALFONT_FONT *f, char **s); //Returns the character pointered by `s' in the current encoding format, and advances the pointer to the next character after the one just returned
|
|
|
959f1c6 |
ALFONT_DLL_DECLSPEC int alfont_ugetxc(ALFONT_FONT *f, const char **s); //Returns the character pointered by `s' in the current encoding format, and advances the pointer to the next character after the one just returned
|
|
|
959f1c6 |
|
|
|
959f1c6 |
-ALFONT_DLL_DECLSPEC void alfont_get_string(ALFONT_FONT *f, const char *s , char **out); //Gets the converted string pointered by `s' in the current encoding format
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
ALFONT_DLL_DECLSPEC void alfont_set_font_outline_top(ALFONT_FONT *f, int w); //Sets Font top outline width
|
|
|
959f1c6 |
ALFONT_DLL_DECLSPEC int alfont_get_font_outline_top(ALFONT_FONT *f); //Returns Font top outline width
|
|
|
959f1c6 |
ALFONT_DLL_DECLSPEC void alfont_set_font_outline_bottom(ALFONT_FONT *f, int w); //Sets Font bottom outline width
|
|
|
959f1c6 |
diff -up alfont-2.0.9/src/alfont.c~ alfont-2.0.9/src/alfont.c
|
|
|
959f1c6 |
--- alfont-2.0.9/src/alfont.c~ 2012-07-29 11:51:08.000000000 +0200
|
|
|
959f1c6 |
+++ alfont-2.0.9/src/alfont.c 2012-07-29 11:58:44.277233388 +0200
|
|
|
959f1c6 |
@@ -4156,256 +4156,6 @@ int alfont_ugetxc(ALFONT_FONT *f, const
|
|
|
959f1c6 |
return character;
|
|
|
959f1c6 |
}
|
|
|
959f1c6 |
|
|
|
959f1c6 |
-void alfont_get_string(ALFONT_FONT *f, const char *s , char **out){
|
|
|
959f1c6 |
- char *lpszW;
|
|
|
959f1c6 |
- char *lpszW_pointer=NULL; //used for freeing string
|
|
|
959f1c6 |
- char *s_pointer=NULL; //used for original string fixed by autofix
|
|
|
959f1c6 |
- char *s_pointer_temp=NULL; //temporary used for autofix string
|
|
|
959f1c6 |
- char *precedingchar_pointer=NULL; //used for precedingchar character
|
|
|
959f1c6 |
- int nLen;
|
|
|
959f1c6 |
- int ret; //decide that if the ASCII Code convert to Unicode Code is all OK when used for autofix string or used for general convert.
|
|
|
959f1c6 |
- int curr_uformat;
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifdef ALFONT_DOS
|
|
|
959f1c6 |
- iconv_t c_pt;
|
|
|
959f1c6 |
- size_t fromlen, tolen;
|
|
|
959f1c6 |
- char *sin, *sout;
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if (s == NULL) {
|
|
|
959f1c6 |
- return;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- nLen = strlen(s) + 1;
|
|
|
959f1c6 |
- s_pointer = (char *)malloc(nLen*sizeof(char));
|
|
|
959f1c6 |
- memset(s_pointer, 0, nLen);
|
|
|
959f1c6 |
- strcpy(s_pointer, s);
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- //Auto Fix for cutted string
|
|
|
959f1c6 |
- //For ASCII convert to unicode
|
|
|
959f1c6 |
- //Add the previous character to the s string
|
|
|
959f1c6 |
- //If find the cutted character, store it from the converted s string and remove it from the original s string
|
|
|
959f1c6 |
- if (f->autofix==TRUE) {
|
|
|
959f1c6 |
- if (f->type==2) {
|
|
|
959f1c6 |
- curr_uformat=get_uformat();
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifdef ALFONT_DOS
|
|
|
959f1c6 |
- if ((c_pt = iconv_open("UTF-16LE", f->language)) != (iconv_t)-1) {
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- fromlen = strlen(s) + 1;
|
|
|
959f1c6 |
- tolen = MB_CUR_MAX * fromlen * (sizeof(wchar_t) + 1);
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- //add the previous character to the s string
|
|
|
959f1c6 |
- if (f->precedingchar != 0) {
|
|
|
959f1c6 |
- free(s_pointer);
|
|
|
959f1c6 |
- fromlen = strlen(s) + 1 + 1;
|
|
|
959f1c6 |
- tolen = MB_CUR_MAX * fromlen * (sizeof(wchar_t) + 1);
|
|
|
959f1c6 |
- s_pointer = (char *)malloc(tolen*sizeof(char));
|
|
|
959f1c6 |
- memset(s_pointer, 0, tolen);
|
|
|
959f1c6 |
- precedingchar_pointer=(char *)malloc(2*sizeof(char));
|
|
|
959f1c6 |
- memset(precedingchar_pointer, 0, 2);
|
|
|
959f1c6 |
- sprintf(precedingchar_pointer, "%c", f->precedingchar);
|
|
|
959f1c6 |
- strcpy(s_pointer,precedingchar_pointer);
|
|
|
959f1c6 |
- if (precedingchar_pointer) {
|
|
|
959f1c6 |
- free(precedingchar_pointer);
|
|
|
959f1c6 |
- precedingchar_pointer = NULL;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- strcat(s_pointer, s);
|
|
|
959f1c6 |
- f->precedingchar = 0;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- iconv(c_pt, NULL, NULL, NULL, NULL);
|
|
|
959f1c6 |
- lpszW = (char *)malloc(tolen*sizeof(char));
|
|
|
959f1c6 |
- memset(lpszW, 0, tolen);
|
|
|
959f1c6 |
- sin = s;
|
|
|
959f1c6 |
- sout = lpszW;
|
|
|
959f1c6 |
- ret = iconv(c_pt, &sin, &fromlen, &sout, &tolen);
|
|
|
959f1c6 |
- iconv_close(c_pt);
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- s_pointer_temp = s_pointer;
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if (ret == -1) { //If the ret is -1, the final one will can be a shortcutted character.
|
|
|
959f1c6 |
- //store the last character to precedingchar character
|
|
|
959f1c6 |
- //get the final character
|
|
|
959f1c6 |
- set_uformat(curr_uformat);
|
|
|
959f1c6 |
- while (*s_pointer_temp != '\0') {
|
|
|
959f1c6 |
- f->precedingchar = *s_pointer_temp;
|
|
|
959f1c6 |
- s_pointer_temp++;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- //remove the final character
|
|
|
959f1c6 |
- s_pointer_temp--;
|
|
|
959f1c6 |
- *s_pointer_temp = '\0';
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- if (lpszW) {
|
|
|
959f1c6 |
- free(lpszW);
|
|
|
959f1c6 |
- lpszW = NULL;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- #else
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifdef ALFONT_LINUX
|
|
|
959f1c6 |
- nLen = strlen(s_pointer) * 5 + 1;
|
|
|
959f1c6 |
- #else
|
|
|
959f1c6 |
- nLen = strlen(s_pointer) + 1;
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- //add the previous character to the s string
|
|
|
959f1c6 |
- if (f->precedingchar != 0) {
|
|
|
959f1c6 |
- free(s_pointer);
|
|
|
959f1c6 |
- nLen = strlen(s) + 1 + 1;
|
|
|
959f1c6 |
- s_pointer = (char *)malloc(nLen*sizeof(char));
|
|
|
959f1c6 |
- memset(s_pointer, 0, nLen);
|
|
|
959f1c6 |
- precedingchar_pointer=(char *)malloc(2*sizeof(char));
|
|
|
959f1c6 |
- memset(precedingchar_pointer, 0, 2);
|
|
|
959f1c6 |
- sprintf(precedingchar_pointer, "%c", f->precedingchar);
|
|
|
959f1c6 |
- strcpy(s_pointer,precedingchar_pointer);
|
|
|
959f1c6 |
- if (precedingchar_pointer) {
|
|
|
959f1c6 |
- free(precedingchar_pointer);
|
|
|
959f1c6 |
- precedingchar_pointer = NULL;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- strcat(s_pointer, s);
|
|
|
959f1c6 |
- f->precedingchar = 0;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- setlocale(LC_CTYPE,f->language);
|
|
|
959f1c6 |
- set_uformat(U_UNICODE);
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- lpszW = (char *)malloc(nLen*sizeof(wchar_t));
|
|
|
959f1c6 |
- memset(lpszW, 0, nLen);
|
|
|
959f1c6 |
- ret = mbstowcs((wchar_t *)lpszW, s_pointer, nLen);
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- s_pointer_temp = s_pointer;
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if (ret == -1) { //If the ret is -1, the final one will can be a shortcutted character.
|
|
|
959f1c6 |
- //store the last character to precedingchar character
|
|
|
959f1c6 |
- //get the final character
|
|
|
959f1c6 |
- set_uformat(curr_uformat);
|
|
|
959f1c6 |
- while (*s_pointer_temp != '\0') {
|
|
|
959f1c6 |
- f->precedingchar = *s_pointer_temp;
|
|
|
959f1c6 |
- s_pointer_temp++;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- //remove the final character
|
|
|
959f1c6 |
- s_pointer_temp--;
|
|
|
959f1c6 |
- *s_pointer_temp = '\0';
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- if (lpszW) {
|
|
|
959f1c6 |
- free(lpszW);
|
|
|
959f1c6 |
- lpszW = NULL;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
- //recover to original codepage
|
|
|
959f1c6 |
- set_uformat(curr_uformat);
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- //Font Code Convert
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if (f->type==1) {
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifdef ALFONT_DOS
|
|
|
959f1c6 |
- if ((c_pt = iconv_open(f->language, "UTF-16LE")) == (iconv_t)-1) {
|
|
|
959f1c6 |
- lpszW = (char *)s_pointer;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- else {
|
|
|
959f1c6 |
- iconv(c_pt, NULL, NULL, NULL, NULL);
|
|
|
959f1c6 |
- fromlen = strlen(s_pointer) + 1;
|
|
|
959f1c6 |
- tolen = MB_CUR_MAX * fromlen * (sizeof(wchar_t) + 1);
|
|
|
959f1c6 |
- lpszW = (char *)malloc(tolen*sizeof(char));
|
|
|
959f1c6 |
- memset(lpszW, 0, tolen);
|
|
|
959f1c6 |
- sin = s_pointer;
|
|
|
959f1c6 |
- sout = lpszW;
|
|
|
959f1c6 |
- ret = iconv(c_pt, &sin, &fromlen, &sout, &tolen);
|
|
|
959f1c6 |
- iconv_close(c_pt);
|
|
|
959f1c6 |
- if (ret == -1) {
|
|
|
959f1c6 |
- lpszW = (char *)s_pointer;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- #else
|
|
|
959f1c6 |
- setlocale(LC_CTYPE,f->language);
|
|
|
959f1c6 |
- nLen= MB_CUR_MAX * wcslen((const wchar_t*)s_pointer) + 1;
|
|
|
959f1c6 |
- lpszW = (char *)malloc(nLen*sizeof(char));
|
|
|
959f1c6 |
- memset(lpszW, 0, nLen);
|
|
|
959f1c6 |
- wcstombs(lpszW, (const wchar_t *)s_pointer, nLen);
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- else if(f->type==2) {
|
|
|
959f1c6 |
- curr_uformat=get_uformat();
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifdef ALFONT_DOS
|
|
|
959f1c6 |
- if ((c_pt = iconv_open("UTF-16LE", f->language)) == (iconv_t)-1) {
|
|
|
959f1c6 |
- lpszW = (char *)s_pointer;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- else {
|
|
|
959f1c6 |
- iconv(c_pt, NULL, NULL, NULL, NULL);
|
|
|
959f1c6 |
- fromlen = strlen(s_pointer) + 1;
|
|
|
959f1c6 |
- tolen = MB_CUR_MAX * fromlen * (sizeof(wchar_t) + 1);
|
|
|
959f1c6 |
- lpszW = (char *)malloc(tolen*sizeof(char));
|
|
|
959f1c6 |
- memset(lpszW, 0, tolen);
|
|
|
959f1c6 |
- sin = s_pointer;
|
|
|
959f1c6 |
- sout = lpszW;
|
|
|
959f1c6 |
- ret = iconv(c_pt, &sin, &fromlen, &sout, &tolen);
|
|
|
959f1c6 |
- iconv_close(c_pt);
|
|
|
959f1c6 |
- if (ret == -1) {
|
|
|
959f1c6 |
- lpszW = (char *)s_pointer;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- else {
|
|
|
959f1c6 |
- set_uformat(U_UNICODE);
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- #else
|
|
|
959f1c6 |
- setlocale(LC_CTYPE,f->language);
|
|
|
959f1c6 |
- set_uformat(U_UNICODE);
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifdef ALFONT_LINUX
|
|
|
959f1c6 |
- nLen = strlen(s_pointer) * 5 + 1;
|
|
|
959f1c6 |
- #else
|
|
|
959f1c6 |
- nLen= strlen(s_pointer) + 1;
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- lpszW = (char *)malloc(nLen*sizeof(wchar_t));
|
|
|
959f1c6 |
- memset(lpszW, 0, nLen);
|
|
|
959f1c6 |
- mbstowcs((wchar_t *)lpszW, s_pointer, nLen);
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- else {
|
|
|
959f1c6 |
- #ifdef ALFONT_LINUX
|
|
|
959f1c6 |
- set_uformat(U_UTF8);
|
|
|
959f1c6 |
- nLen= ustrlen(s_pointer) + 1;
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
- lpszW = (char *)s_pointer;
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- memset(*out, 0, _msize(*out));
|
|
|
959f1c6 |
- if (_msize(*out) > 0 && _msize(lpszW) >= _msize(*out))
|
|
|
959f1c6 |
- {
|
|
|
959f1c6 |
- memcpy(*out, lpszW, _msize(*out));
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
- else if (_msize(*out) > 0 && _msize(*out) > _msize(lpszW))
|
|
|
959f1c6 |
- {
|
|
|
959f1c6 |
- memcpy(*out, lpszW, _msize(lpszW));
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if ((f->type==1)||(f->type==2)) {
|
|
|
959f1c6 |
- if (lpszW)
|
|
|
959f1c6 |
- free(lpszW);
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if(s_pointer) {
|
|
|
959f1c6 |
- free(s_pointer);
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- #ifndef ALFONT_DOS
|
|
|
959f1c6 |
- setlocale(LC_CTYPE,"");
|
|
|
959f1c6 |
- #endif
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
- if (f->type==2) {
|
|
|
959f1c6 |
- set_uformat(curr_uformat);
|
|
|
959f1c6 |
- }
|
|
|
959f1c6 |
-}
|
|
|
959f1c6 |
-
|
|
|
959f1c6 |
int alfont_need_uconvert(ALFONT_FONT *f, const char *str) {
|
|
|
959f1c6 |
char *lpszW;
|
|
|
959f1c6 |
char *str_pointer=NULL; //used for original string fixed by autofix
|