![]() |
#21 | |
NPPAngband Maintainer
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
![]() |
Quote:
get_encode xchar_trans_hook static const xchar_type latin1_encode byte char_tables[256][CHAR_TABLE_SLOTS] xstr_trans escape_latin1 typedef struct xchar_type xchar_type; my_toupper (there is a whole series of these in z-form.h...my_tolower, my_isprint, my_isspace are examples. ) T->xchar_hook You also have to grab the fonts from NPPAngband (in lib/xtra/font), because those have the extended characters in them. But with all that, I am missing something. Because it only displays the extended characters if a message is formatted instead of printing it directly. For example, in the knowledge screen, where it uses c_put_str, it displays ['e] instead of the accented e. So I am missing a tiny part of the patch, which is why I want to find a copy of the original part of the patch so badly. I will let you know when I find it. |
|
![]() |
![]() |
![]() |
#22 | |
Rookie
Join Date: Jul 2010
Posts: 14
![]() |
Ok thanks!
I'm going to try modify the code. But I've a questions becouse this lines i don't find in the FA or NPPAngband code: Quote:
are an error? Last edited by hernaldo; July 22, 2010 at 06:18. |
|
![]() |
![]() |
![]() |
#23 | |
NPPAngband Maintainer
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
![]() |
Quote:
T->xchar_hook needs to be added to the structure term (line 237 of z-term.h). If you grep xchar_hook you will see you need to add some code in main-win.c (and the other operating systems that can handle the extended characters). It is in the function term_data_link: after these lines: t->wipe_hook = Term_wipe_win; t->text_hook = Term_text_win; t->pict_hook = Term_pict_win; add this: t->xchar_hook = Term_xchar_win; Also, I think I fixed the final problem yesterday...so you won't find this is the source code you downloaded. In z-term.c, you will find a function called term_addstr. Replace that function with the one below. Only the first 6 or 7 lines are different: errr Term_addstr(int n, byte a, cptr buf) { int k; int w = Term->wid; errr res = 0; char s[1024]; /* Copy to a rewriteable string */ my_strcpy(s, buf, 1024); /* Translate it to 7-bit ASCII or system-specific format */ xstr_trans(s, LATIN1); /* Handle "unusable" cursor */ if (Term->scr->cu) return (-1); /* Obtain maximal length */ k = (n < 0) ? (w + 1) : n; /* Obtain the usable string length */ for (n = 0; (n < k) && s[n]; n++) /* loop */; /* React to reaching the edge of the screen */ if (Term->scr->cx + n >= w) res = n = w - Term->scr->cx; /* Queue the first "n" characters for display */ Term_queue_chars(Term->scr->cx, Term->scr->cy, n, a, s); /* Advance the cursor */ Term->scr->cx += n; /* Hack -- Notice "Useless" cursor */ if (res) Term->scr->cu = 1; /* Success (usually) */ return (res); } |
|
![]() |
![]() |
![]() |
#24 |
Rookie
Join Date: Jul 2010
Posts: 14
![]() |
OK, it compile!
![]() But, I don't get see the acents (é), maybe I do something wrong. First: I changed ui-birth.c, the line 135 says: Code:
#define BIRTH_MENU_HELPTEXT \ "{lightblue}Please select your character... Code:
#define BIRTH_MENU_HELPTEXT \ "{lightblue}test á é I think that the text use the "5x8.font", Now it will use "5x8x.font" Also, I changed the "Makefile" file , because it says: Code:
OBJECTIVE_DATA = \ copying.txt:${DATA_PATH}/xtra/font \ 5x8.fon:${DATA_PATH}/xtra/font \ Code:
OBJECTIVE_DATA = \ copying.txt:${DATA_PATH}/xtra/font \ 5x8x.fon:${DATA_PATH}/xtra/font \ Code:
#define DEFAULT_X11_FONT_0 "10x20" #define DEFAULT_X11_FONT_1 "9x15" #define DEFAULT_X11_FONT_2 "9x15" #define DEFAULT_X11_FONT_3 "5x8" #define DEFAULT_X11_FONT_4 "5x8" #define DEFAULT_X11_FONT_5 "5x8" #define DEFAULT_X11_FONT_6 "5x8" #define DEFAULT_X11_FONT_7 "5x8" Code:
#define DEFAULT_X11_FONT_0 "10x20" #define DEFAULT_X11_FONT_1 "9x15" #define DEFAULT_X11_FONT_2 "9x15" #define DEFAULT_X11_FONT_3 "5x8x" #define DEFAULT_X11_FONT_4 "5x8x" #define DEFAULT_X11_FONT_5 "5x8x" #define DEFAULT_X11_FONT_6 "5x8x" #define DEFAULT_X11_FONT_7 "5x8x" I need to do something to make it work? thanks and bye! |
![]() |
![]() |
![]() |
#25 |
NPPAngband Maintainer
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
![]() |
You can't enter the characters directly. The game has to be converted from ASCII to unicode for that to be possible. This patch is just a hack to have them display onscreen.
Take a look at the conversion chart in latin1_encode in z-form.c. You have to type "[~n]" in a string and run it through xstr_trans to get the game to type "ñ" |
![]() |
![]() |
![]() |
#26 |
Rookie
Join Date: Jul 2010
Posts: 14
![]() |
ok, i understand.
I tried for four hours today to link function with accents xstr_trans. I placed several calls in different parts of the "xstr_trans" function, but nothing worked. I put a MessageBox and I see that I don't get the "encode_to_xchar" function. I had forgotten to modify the default font in main-win.c, I changed to: Code:
#define DEFAULT_FONT "8x16x.FON" Code:
#define BIRTH_MENU_HELPTEXT \ {lightblue} test [~n]... Code:
static void print_menu_instructions(void) { /* Clear screen */ Term_clear(); /* Output to the screen */ text_out_hook = text_out_to_screen; /* Indent output */ text_out_indent = QUESTION_COL; Term_gotoxy(QUESTION_COL, HEADER_ROW); /* Display some helpful information */ text_out_e(BIRTH_MENU_HELPTEXT); /* Reset text_out() indentation */ text_out_indent = 0; } Code:
void text_out_e(const char *fmt, ...) { char buf[1024]; char smallbuf[1024]; va_list vp; const char *start, *next, *text, *tag; size_t textlen, taglen = 0; /* Begin the Varargs Stuff */ va_start(vp, fmt); /* Do the va_arg fmt to the buffer */ (void)vstrnfmt(buf, sizeof(buf), fmt, vp); -> here I call to xstr_trans function??? /* End the Varargs Stuff */ va_end(vp); start = buf; while (next_section(start, 0, &text, &textlen, &tag, &taglen, &next)) { int a = -1; memcpy(smallbuf, text, textlen); smallbuf[textlen] = 0; if (tag) { char tagbuffer[11]; /* Colour names are less than 11 characters long. */ assert(taglen < 11); memcpy(tagbuffer, tag, taglen); tagbuffer[taglen] = '\0'; a = color_text_to_attr(tagbuffer); } if (a == -1) a = TERM_WHITE; /* Output now */ text_out_hook(a, smallbuf); -> OR HERE I call to xstr_trans function??? start = next; } } Code:
Extern.h: extern void (*text_out_hook)(byte a, cptr str); Variable.c void (*text_out_hook)(byte a, cptr str); Code:
size_t vstrnfmt(char *buf, size_t max, cptr fmt, va_list vp) { cptr s; /* The argument is "long" */ bool do_long; /* The argument needs "processing" */ bool do_xtra; /* Bytes used in buffer */ size_t n; /* Bytes used in format sequence */ size_t q; /* Format sequence */ char aux[128]; /* Resulting string */ char tmp[1024]; /* Fatal error - no buffer length */ if (!max) quit("Called vstrnfmt() with empty buffer!"); /* Mega-Hack -- treat "no format" as "empty string" */ if (!fmt) fmt = ""; /* Begin the buffer */ n = 0; /* Begin the format string */ s = fmt; /* Scan the format string */ while (TRUE) { type_union tval = END; /* All done */ if (!*s) break; /* Normal character */ if (*s != '%') { /* Check total length */ if (n == max-1) break; /* Save the character */ buf[n++] = *s++; /* Continue */ continue; } /* Skip the "percent" */ s++; /* Pre-process "%%" */ if (*s == '%') { /* Check total length */ if (n == max-1) break; /* Save the percent */ buf[n++] = '%'; /* Skip the "%" */ s++; /* Continue */ continue; } /* Pre-process "%n" */ if (*s == 'n') { size_t *arg; /* Get the next argument */ arg = va_arg(vp, size_t *); /* Save the current length */ (*arg) = n; /* Skip the "n" */ s++; /* Continue */ continue; } /* Begin the "aux" string */ q = 0; /* Save the "percent" */ aux[q++] = '%'; /* Assume no "long" argument */ do_long = FALSE; /* Assume no "xtra" processing */ do_xtra = FALSE; /* Build the "aux" string */ while (TRUE) { /* Error -- format sequence is not terminated */ if (!*s) { /* Terminate the buffer */ buf[0] = '\0'; /* Return "error" */ return (0); } /* Error -- format sequence may be too long */ if (q > 100) { /* Terminate the buffer */ buf[0] = '\0'; /* Return "error" */ return (0); } /* Handle "alphabetic" chars */ if (isalpha((unsigned char)*s)) { /* Hack -- handle "long" request */ if (*s == 'l') { /* Save the character */ aux[q++] = *s++; /* Note the "long" flag */ do_long = TRUE; } /* Mega-Hack -- handle "extra-long" request */ else if (*s == 'L') { /* Error -- illegal format char */ buf[0] = '\0'; /* Return "error" */ return (0); } /* Handle normal end of format sequence */ else { /* Save the character */ aux[q++] = *s++; /* Stop processing the format sequence */ break; } } /* Handle "non-alphabetic" chars */ else { /* Hack -- Handle 'star' (for "variable length" argument) */ if (*s == '*') { int arg; /* Get the next argument */ arg = va_arg(vp, int); /* Hack -- append the "length" */ sprintf(aux + q, "%d", arg); /* Hack -- accept the "length" */ while (aux[q]) q++; /* Skip the "*" */ s++; } /* Mega-Hack -- Handle 'caret' (for "uppercase" request) */ else if (*s == '^') { /* Note the "xtra" flag */ do_xtra = TRUE; /* Skip the "^" */ s++; } /* Collect "normal" characters (digits, "-", "+", ".", etc) */ else { /* Save the character */ aux[q++] = *s++; } } } /* Terminate "aux" */ aux[q] = '\0'; /* Clear "tmp" */ tmp[0] = '\0'; /* Parse a type_union */ if (aux[q-1] == 'y') { tval = va_arg(vp, type_union); if (do_long) { /* Error -- illegal type_union argument */ buf[0] = '\0'; /* Return "error" */ return (0); } /* Replace aux terminator with proper printf char */ if (tval.t == T_CHAR) aux[q-1] = 'c'; else if (tval.t == T_INT) aux[q-1] = 'd'; else if (tval.t == T_FLOAT) aux[q-1] = 'f'; else if (tval.t == T_STRING) aux[q-1] = 's'; else { buf[0] = '\0'; return (0); } } /* Process the "format" symbol */ switch (aux[q-1]) { /* Simple Character -- standard format */ case 'c': { int arg; /* Get the next argument */ arg = tval.t == T_END ? va_arg(vp, int) : tval.u.c; /* Format the argument */ sprintf(tmp, aux, arg); /* Done */ break; } /* Signed Integers -- standard format */ case 'd': case 'i': { if (do_long) { long arg; /* Get the next argument */ arg = va_arg(vp, long); /* Format the argument */ sprintf(tmp, aux, arg); } else { int arg; /* Get the next argument */ arg = tval.t == T_END ? va_arg(vp, int) : tval.u.i; /* Format the argument */ sprintf(tmp, aux, arg); } /* Done */ break; } /* Unsigned Integers -- various formats */ case 'u': case 'o': case 'x': case 'X': { if (do_long) { unsigned long arg; /* Get the next argument */ arg = va_arg(vp, unsigned long); /* Format the argument */ sprintf(tmp, aux, arg); } else { unsigned int arg; /* Get the next argument */ arg = va_arg(vp, unsigned int); /* Format the argument */ sprintf(tmp, aux, arg); } /* Done */ break; } /* Floating Point -- various formats */ case 'f': case 'e': case 'E': case 'g': case 'G': { double arg; /* Get the next argument */ arg = tval.t == T_END ? va_arg(vp, double) : tval.u.f; /* Format the argument */ sprintf(tmp, aux, arg); /* Done */ break; } /* Pointer -- implementation varies */ case 'p': { void *arg; /* Get the next argument */ arg = va_arg(vp, void*); /* Format the argument */ sprintf(tmp, aux, arg); /* Done */ break; } /* String */ case 's': { cptr arg; char arg2[1024]; /* Get the next argument */ arg = tval.t == T_END ? va_arg(vp, cptr) : tval.u.s; /* Hack -- convert NULL to EMPTY */ if (!arg) arg = ""; /* Prevent buffer overflows */ (void)my_strcpy(arg2, arg, sizeof(arg2)); /* Translate it to 8-bit (Latin-1) */ xstr_trans(arg2, LATIN1); /* Format the argument */ sprintf(tmp, aux, arg2); /* Done */ break; } #if 0 /* Later */ /* Binary */ case 'b': { int arg; size_t i, max = 32; u32b bitmask; char out[32 + 1]; /* Get the next argument */ arg = va_arg(vp, int); /* Check our aux string */ switch (aux[0]) { case '1': max = 2; break; case '2': max = 4; break; case '3': max = 8; break; case '4': max = 16; break; default: case '5': max = 32; break; } /* Format specially */ for (i = 1; i <= max; i++, bitmask *= 2) { if (arg & bitmask) out[max - i] = '1'; else out[max - i] = '0'; } /* Terminate */ out[max] = '\0'; /* Append the argument */ my_strcpy(tmp, out, sizeof tmp); /* Done */ break; } #endif /* Oops */ default: { /* Error -- illegal format char */ buf[0] = '\0'; /* Return "error" */ return (0); } } /* Mega-Hack -- handle "capitalization" */ if (do_xtra) { for (q = 0; tmp[q]; q++) { /* Notice first non-space */ if (!my_isspace((unsigned char)tmp[q])) { /* Capitalize if possible */ if (my_islower((unsigned char)tmp[q])) tmp[q] = my_toupper((unsigned char)tmp[q]); /* Done */ break; } } } /* Now append "tmp" to "buf" */ for (q = 0; tmp[q]; q++) { /* Check total length */ if (n == max-1) break; /* Save the character */ buf[n++] = tmp[q]; } } /* Terminate buffer */ buf[n] = '\0'; /* Return length */ return (n); } thanks a lot!! Last edited by hernaldo; July 24, 2010 at 09:47. |
![]() |
![]() |
![]() |
#27 | |
NPPAngband Maintainer
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
![]() |
Quote:
Which operating system are you using to test this? |
|
![]() |
![]() |
![]() |
#28 |
Rookie
Join Date: Jul 2010
Posts: 14
![]() |
I using Windows XP Prof, i compile using Mingw from the command line
> mingw32-make.exe -f makefile.win I checked all and see that it works (finally, yes!) for the dinamic as "Choose New or Open from file Menu" o "STR, Dex points" or "Your 'race' determines various intrinsic factors and bonuses." But for the static text as "Bug reports to ..." or "For resourses and link..." or "Please select your character from the menu below", don't' work yet. It is assumed that when any text is show in the screen, it reaching "vstrnfmt" and there It get to "s" case: Code:
/* String */ case 's': { cptr arg; char arg2[1024]; /* Get the next argument */ arg = va_arg(vp, cptr); /* Hack -- convert NULL to EMPTY */ if (!arg) arg = ""; /* Prevent buffer overflows */ (void)my_strcpy(arg2, arg, sizeof(arg2)); /* Translate it to 8-bit (Latin-1) */ xstr_trans(arg2, LATIN1); ... -I shall not want to copy another function? Besides, is that I can't use the Latin character ¿=191 because it shows "?" in the game. In the "static const xchar_type latin1_encode[]" table does not appear because the table start in the latin character 192, but it appear in "byte char_tables[256][CHAR_TABLE_SLOTS]" table. -that could be happening? I need add this character to the table? or add it in the fonts? thanks for your support! |
![]() |
![]() |
![]() |
#29 |
NPPAngband Maintainer
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
![]() |
I tried your test baove, but I couldn't get it to work either. It only seems to work if it is read from the edit files (look in artifact.txt, or monster.txt for examples), which, up until now, is all we have needed it to work.
A simple one to test is in p-class.txt. Change the entry for Dunadan and change it to: D['u]nadan and then start up a new character and see if it displays correctly. That should work as a starting point. |
![]() |
![]() |
![]() |
#30 | |
Veteran
Join Date: Apr 2007
Posts: 1,950
Donated: $40
![]() |
Quote:
PS. translation is something i've always wanted to support in the game, but I think to do it properly you do really need to have a scripting language to hold the language packs, given the complexity of angband's text handling. maybe we should be bringing lua back...
__________________
takkaria whispers something about options. -more- |
|
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Morgothian programming language | zaimoni | Idle chatter | 2 | April 22, 2009 10:26 |
Angband and language | tigpup | Idle chatter | 1 | February 1, 2009 13:53 |
C Language | momo125 | Vanilla | 11 | February 27, 2008 09:30 |