Skip to contentSkip to conversation

Small unicode problem fix in normal/menu.c

PATCH In review Vincent Pelletier 3 participants 10 messages Jul 3, 2005 – Jul 9, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Small unicode problem fix in normal/menu.c

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

There is an alignment problem when menu is drawn with Unicode chars in titles : there aren't enough spaces written on the right to make the hilight fill horizontaly the menu.

2005-07-03 Vincent Pelletier <[email protected]>

* normal/menu.c
(grub_print_entry): Rely on getxy to get horizontal position.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCyE/4FEQoKRQyjtURAmzYAJwN8/LK9MSCRTnD7lzPvLEsK560BQCfQSHk FFMUG+Zshn0JM1mxxbZMk+o=
=yUWs
-----END PGP SIGNATURE-----

Index: normal/menu.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/menu.c,v
retrieving revision 1.11

menu.c +1 -1
diff -u -p -r1.11 menu.c
@@ -108,7 +108,7 @@ print_entry (int y, int highlight, grub_
 
   for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1;
        x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
-       x++)
+       x=grub_getxy()>>8)
     {
       if (*title && x <= GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
 	{
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

About the grub_getxy function...

Wouldn't it be better to change it ?

ncurses-like (not macros !) :

void grub_getyx (unsigned int &y, unsigned int &x)
void grub_getmaxyx (unsigned int &y, unsigned int &x) /* to get the term size */

Any comment ?

Vincent Pelletier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCyUuKFEQoKRQyjtURAvbHAJ956t5IBtaSiMsVeJTYtfbTyk2RcgCfcfiB J7BWr/ReX2enuBh4DUSe4a0=
=lSNu
-----END PGP SIGNATURE-----

___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com

#2 lore raw
Quoted 5 lines · Vincent Pelletier

ncurses-like (not macros !) :

void grub_getyx (unsigned int &y, unsigned int &x)
void grub_getmaxyx (unsigned int &y, unsigned int &x) /* to get the term size */

My feeling is that it is not convenient to use pointers. For example, when I just want to know if the position is 0 or not in the x axis, I can do this in the current API:

if (grub_getxy () >> 8)

But if I need to use a pointer, this becomes:

unsigned x;
grub_getyx (0, &x);
if (x)

Well, this might be just a preference.

Okuji

#3 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Yoshinori K. Okuji

My feeling is that it is not convenient to use pointers.

Right.
My first idea was to use a struct as return type :

struct coords {
unsigned char x;
unsigned char y;
};

So it becomes :

if (grub_getxy () .x)

Or maybe a struct of bitfields...

I feel structs as being cleaner to use compared to shifts. If someday we have a terminal that exceeds 255 chars in one or both dimensions, we wouldn't have to grep "grub_getxy ()" to find the shifts...

Vincent Pelletier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCyjDWFEQoKRQyjtURAg5+AKCv+0nJXOMzaiiQ/+ePXVAOhuvvlgCeN88f 40Oy4FUN5ihK0USgAUl7ypE=
=M1Xj
-----END PGP SIGNATURE-----

___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com

#4 lore raw
In reply to Yoshinori K. Okuji
Quoted 13 lines · Yoshinori K. Okuji
Quoted 5 lines · Vincent Pelletier

ncurses-like (not macros !) :

void grub_getyx (unsigned int &y, unsigned int &x)
void grub_getmaxyx (unsigned int &y, unsigned int &x) /* to get the term size */

My feeling is that it is not convenient to use pointers. For example, when I just want to know if the position is 0 or not in the x axis, I can do this in the current API:

if (grub_getxy () >> 8)

Quoted 7 lines

But if I need to use a pointer, this becomes:

unsigned x;
grub_getyx (0, &x);
if (x)

Well, this might be just a preference.

Yeah, personally I prefer pointers to do this. how about adding:

inline unsigned
grub_getx (void)
{
return grub_getxy () >> 8;
}

Or a macro or so which does the same.

Thanks,
Marco

#5 lore raw
In reply to Vincent Pelletier
Quoted 3 lines · Vincent Pelletier

There is an alignment problem when menu is drawn with Unicode chars in titles : there aren't enough spaces written on the right to make the hilight fill horizontaly the menu.

You can check in this patch, but this is not the right thing to do. At the moment, it is impossible to know how many columns will be occupied by putting a byte until it is actually putted. This is very bad, and, of course, does not work well in some cases.

So, as I described before, it is necessary to implement a new function which returns the width for a given (Unicode) character. For the menu, I think it would be easier to convert all strings to Unicode strings before rendering. Writing bytes is very, very hard.

Okuji

#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Yoshinori K. Okuji

You can check in this patch, but this is not the right thing to do.

So I prefer not checking it in.
I had the idea to start a Unicode debate on how to handle this. My first idea would be :
unsigned int grub_putcode(...);
unsigned int grub_putchar(...);

Ignoring the return value would make those function act as they do now. Reading it would give the number of char actualy displayed on screen. 0 = Unicode char incomplete (for putchar only, for putcode might be "invalid Unicode" if applies)
1 = one char written
2 = a char as wide as 2 "usual chars" (I think I read somewhere it exists) (and so on)

I was also wondering about the font format. Does any editor exists ? Or is it taken from an existing format ? I'm dying to see Japanese chars on grub menu while playing the tetris theme :] .

Vincent Pelletier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCyu8zFEQoKRQyjtURAiSiAJ98YnZTCJhAFs0nJPj94PNu0tEDCgCgjvmt cal3c1Ca97j3+ARVBoL9vrg=
=6pce
-----END PGP SIGNATURE-----

___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger T�l�chargez cette version sur http://fr.messenger.yahoo.com

#7 lore raw
Quoted 3 lines · Vincent Pelletier

I was also wondering about the font format. Does any editor exists ? Or is it taken from an existing format ? I'm dying to see Japanese chars on grub menu while playing the tetris theme :] .

I described the format here:

http://lists.gnu.org/archive/html/grub-devel/2004-05/msg00020.html

GRUB 2 contains a script unifont2pff.rb in the directory util. You can use this script to convert unifont to PFF format.

Okuji

#8 lore raw
In reply to Vincent Pelletier
Quoted 3 lines · Vincent Pelletier

There is an alignment problem when menu is drawn with Unicode chars in titles : there aren't enough spaces written on the right to make the hilight fill horizontaly the menu.

This sounds like a bug in the terminal to me. In that case it has to be fixed in the terminal and not corrected in the menu.

Thanks,
Marco

#9 lore raw
Quoted 8 lines · Marco Gerards
Quoted 3 lines · Vincent Pelletier

There is an alignment problem when menu is drawn with Unicode chars in titles : there aren't enough spaces written on the right to make the hilight fill horizontaly the menu.

This sounds like a bug in the terminal to me. In that case it has to be fixed in the terminal and not corrected in the menu.

It seems I was confused. Okuji, thanks for explaining about unicode. As you all know, unicode, i18n, etc still confuse me a lot. :)

--
Marco