multistring support in gui_label
Quoted 1 line
Please don't use // comments.
O.k. I won't.
Quoted 2 lines
This code completely forgets the cases
when even the first word doesn't fit in the available space.
Mmm. It can handle this case actually.
Quoted 1 line
The code as whole breaks some unicode concepts like e.g. bidi stack.
Didn't get what you mean.
Quoted 4 lines
Could you reuse the already available line-vreaking algorithm in
normal/term.candnormal/charset.c? Since the line-breaking is artificially disabled for labels it should require only minor adjustments to be reenabled.
Yep! Here it is (patch included)!
Nevertheless, two problems appeared and I don't sure how exactly should I fix them.
1) Handling of some long word. If this word is not first in line and it's length is more than label's width
then the length of the first fragment of the word will be counted as if it will be drawn on the same line,
but actually it will be printed on the next line.
2) There is funny handling of UTF-8 symbols. Each symbol have "device_width" parameter,
which is used in calculation of string's length. But, when we are going to actually print a symbol,
it's length (with spaces) is calculated in other way. First, all symbols that have special connection with
current symbol are looked through. Then device_width is replaced with maximum of printed lengths in all cases.
So, for some special symbols (eg "`", used in @KEYMAP_LONG@) actual length will be more than pre-counted.
How should I fix these problems?
1st one - for example, I can slightly update line-breaking mechanism. 2nd one - more interesting, harder. I suggest utf-8 printing mechanism (charset.c unicode.c etc) should be remade. So symbol connections will be counted in more intelligent way (e.g. while counting spaces - take into consideration nearby symbols). It is interesting. :) I can do it. Would be happy, if someone could give me some advices.
Problem2.png
text = "@KEYMAP_LONG@"
t is misprinted
Problem1.png
text = "short short short HereWeHaveSomeVeryLongWordSoItCannotBePrintedEntirelyOnOneLine" See how the line-breaking works.
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
grub-core/gfxmenu/font.c +88 -0
@@ -75,6 +75,94 @@return GRUB_ERR_NONE ; } +/* Differs from grub_font_draw_line only in multiline output */ +grub_err_t +grub_font_draw_multiline (const char *str,grub_font_t font, +grub_video_color_t color, +int baseline_y,int font_height, +int max_width,int max_height, +int align) +{ +int x; +struct grub_font_glyph *glyph; +grub_uint32_t *logical; +grub_ssize_t logical_len, visual_len; +struct grub_unicode_glyph *visual, *ptr, *pos; + +grub_err_t print_line () + { +while (pos != ptr) + { +grub_err_t err; + glyph =grub_font_construct_glyph (font, pos); +if (!glyph) +return grub_errno; + err =grub_font_draw_glyph (glyph, color, x, baseline_y); + x += glyph->device_width; +grub_free (glyph); +if (err) +return err; + pos ++; + } + +return GRUB_ERR_NONE ; + } + + logical_len =grub_utf8_to_ucs4_alloc (str, &logical,0 ); +if (logical_len <0 ) +return grub_errno; + + autogrub_ssize_t getcharwidth (const struct grub_unicode_glyph *c); +grub_ssize_t getcharwidth (const struct grub_unicode_glyph *c) + { +return grub_font_get_constructed_device_width (font, c); + } + + visual_len =grub_bidi_logical_to_visual (logical, logical_len, &visual, + getcharwidth, max_width,0 ); +grub_free (logical); +if (visual_len <0 ) +return grub_errno; + + pos = visual; +for (ptr = visual, x =0 ; ptr <= visual + visual_len; ptr++) + { +if (baseline_y > max_height) +break ; +if (ptr->base =='\n' || ptr == visual + visual_len) + { +int left_x; +if (align ==1 ) + left_x = (max_width - x) /2 ; +else if (align ==2 ) + left_x = max_width - x; +else + left_x =0 ; + + x = left_x; + +grub_err_t err; + err =print_line (); +if (err !=GRUB_ERR_NONE ) +return err; + + baseline_y += font_height; + x =0 ; +while ((ptr +1 < visual + visual_len) + && ((ptr +1 )->base ==' ' + || (ptr +1 )->base =='\t' )) + ptr ++; + pos = ptr +1 ; + } +else + x +=grub_font_get_constructed_device_width (font, ptr); + } + +grub_free (visual); + +return GRUB_ERR_NONE ; +} +/* Get the width in pixels of the specified UTF-8 string, when rendered in in the specified font (but falling back on other fonts for glyphs that are missing). */
grub-core/gfxmenu/gui_label.c +51 -21
106 lines not on this page · raw message
include/grub/gfxmenu_view.h +6 -0
@@ -66,6 +66,12 @@grub_font_t font, grub_video_color_t color, int left_x, int baseline_y); +grub_err_t grub_font_draw_multiline (const char *str, +grub_font_t font, +grub_video_color_t color, +int baseline_y,int font_height, +int max_width,int max_height, +int align);int grub_font_get_string_width (grub_font_t font,const char *str);
В Tue, 16 Apr 2013 13:04:28 +0400
Vladimir Testov <[email protected]> пишет:
Quoted 16 lines
Quoted 1 line
Please don't use // comments.
O.k. I won't.
Quoted 2 lines
This code completely forgets the cases
when even the first word doesn't fit in the available space.Mmm. It can handle this case actually.
Quoted 1 line
The code as whole breaks some unicode concepts like e.g. bidi stack.
Didn't get what you mean.
Quoted 4 lines
Could you reuse the already available line-vreaking algorithm in
normal/term.candnormal/charset.c? Since the line-breaking is artificially disabled for labels it should require only minor adjustments to be reenabled.
Quoted 4 lines
Yep! Here it is (patch included)!
+/* Differs from
grub_font_draw_lineonly in multiline output */
You mean grub_font_draw_string? Is it possible to extend this function instead of duplicating it?
Quoted 7 lines
grub-core/gfxmenu/font.c +6
-0+grub_err_t +grub_font_draw_multiline (const char *str,grub_font_t font, +grub_video_color_t color, +int baseline_y,int font_height, +int max_width,int max_height, +int align)
grub-core/gfxmenu/font.c line 119
Quoted 10 lines
grub-core/gfxmenu/font.c +9
-0+ +grub_err_t print_line () + { +while (pos != ptr) + auto grub_ssize_t getcharwidth (const struct grub_unicode_glyph *c); +grub_ssize_t getcharwidth (const struct grub_unicode_glyph *c) + { +return grub_font_get_constructed_device_width (font, c); + }
All nested functions were removed from trunk. Please do not reintroduce them. This should not even compile.
Quoted 4 lines · Andrey Borzenkov
Quoted 1 line
+/* Differs from
grub_font_draw_lineonly in multiline output */You mean
grub_font_draw_string? Is it possible to extend this function instead of duplicating it?
Hmmm... I'll think through it. Would it be wise? The sets of parameteres in these two functions are very different and the code is totally different...
Quoted 2 lines
All nested functions were removed from trunk. Please do not reintroduce them. This should not even compile.
My fault. Made the patch for grub-2.00, and forgot to remade it for upstream version. I've noticed that nested functions were removed. I will remake it soon.
I've included the patch more for seeing the idea. It is not complete and (I think) shouldn't be included in the upstream until two problems, I've mentioned in previous letter, are not fixed. :)
Thank for the reply.
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
Quoted 18 lines · Vladimir Testov
Quoted 1 line
Please don't use // comments.
O.k. I won't.
Quoted 2 lines
This code completely forgets the cases
when even the first word doesn't fit in the available space.Mmm. It can handle this case actually.
Quoted 1 line
The code as whole breaks some unicode concepts like e.g. bidi stack.
Didn't get what you mean.
Quoted 4 lines
Could you reuse the already available line-vreaking algorithm in
normal/term.candnormal/charset.c? Since the line-breaking is artificially disabled for labels it should require only minor adjustments to be reenabled.Yep! Here it is (patch included)!
Quoted 7 lines
Nevertheless, two problems appeared and I don't sure how exactly should I fix them.
1) Handling of some long word. If this word is not first in line and it's length is more than label's width
then the length of the first fragment of the word will be counted as if it will be drawn on the same line,
but actually it will be printed on the next line.
Don't write any line-breaking at all yourself.
Quoted 3 lines
2) There is funny handling of UTF-8 symbols. Each symbol have "
device_width" parameter,
which is used in calculation of string's length.
Where is it used? Show exactly. It must be some leftover code.
Quoted 7 lines
How should I fix these problems?
1st one - for example, I can slightly update line-breaking mechanism. 2nd one - more interesting, harder. I suggest utf-8 printing mechanism (charset.cunicode.cetc) should be remade. So symbol connections will be counted in more intelligent way (e.g. while counting spaces - take into consideration nearby symbols). It is interesting. :) I can do it. Would be happy, if someone could give me some advices.
We don't do any kerning. No need to change algorithm.
Quoted 17 lines
Problem2.png
text = "@KEYMAP_LONG@"
t is misprintedProblem1.png
text = "short short short HereWeHaveSomeVeryLongWordSoItCannotBePrintedEntirelyOnOneLine" See how the line-breaking works._______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Don't write any line-breaking at all yourself.
I did not write any line-breaking. It is existing line-breaking. And it have one algorithmic problem. Do not see any problem if I will fix the problem.
The problem persists when we have some long word which cannot be printed entirely on one line...
Quoted 7 lines
Quoted 3 lines
2) There is funny handling of UTF-8 symbols. Each symbol have "
device_width" parameter,
which is used in calculation of string's length.Where is it used? Show exactly. It must be some leftover code.
We don't do any kerning. No need to change algorithm.
O.k. Here it is.
from grub-core/font/font.c line 1387 function blit_comb :
Quoted 8 lines
do_blit (combining_glyphs[i],
main_glyph->device_width
+ combining_glyphs[i]->offset_x,
-(combining_glyphs[i]->height
+ combining_glyphs[i]->offset_y), &ctx);
add_device_width (combining_glyphs[i]->device_width, &ctx);
}
}Quoted 9 lines
}
add_device_width((above_rightx>
below_rightx?above_rightx:below_rightx) -
(main_glyph->offset_x+main_glyph->width), &ctx);
add_device_width(above_leftx-main_glyph->offset_x, &ctx); if (glyph &&glyph->device_width<min_devwidth)
glyph->device_width=min_devwidth;
if (device_width&&*device_width<min_devwidth)
*device_width=min_devwidth;
***device_width is changed sometimes.
from grub-core/font/font.c line 1458 function grub_font_construct_dry_run :
Quoted 19 lines
if (
device_width)
*device_width=main_glyph->device_width;if (!glyph_id->ncomb && !glyph_id->attributes)
returnmain_glyph;
combining_glyphs=grub_malloc(sizeof (combining_glyphs[0])
*glyph_id->ncomb);
if (glyph_id->ncomb&& !combining_glyphs){ grub_errno = GRUB_ERR_NONE; return main_glyph;}
for (i = 0; i <
glyph_id->ncomb; i++)
combining_glyphs[i]= grub_font_get_glyph_with_fallback (main_glyph->font, glyph_id->combining[i].code);
Quoted 8 lines
blit_comb(glyph_id, NULL, bounds,main_glyph,combining_glyphs,device_width);if (
combining_glyphs_out)
*combining_glyphs_out=combining_glyphs;
else
grub_free(combining_glyphs);return
main_glyph;
***return value *device_width set to main_glyph->device_width before main_glyph->device_width is changed during execution of blit_comb
If we want to get device_width of some glyph - we use function get_constructed_device_width. It returns device_width parameter of the asked glyph with parameter *device_width of the function grub_font_construct_dry_run.
When we actually construct glyph, we take device_width from glyph-
Quoted 1 line
device_width.
The most adequate way to find device_width of grub_unicode_glyph is to call grub_font_get_constructed_device_width. But it is miscalculated in some cases.
So these two values are different in some cases (This is all about problem 2)
Suggested patch to fix this problem (second one) is attached.
I will remake the patch for multistring support for the upstream version.
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
grub-core/font/font.c +5 -0
@@ -1476,6 +1476,11 @@blit_comb (glyph_id,NULL , bounds, main_glyph, combining_glyphs, device_width); + +/* The value could have been changed */ +if (device_width) + *device_width = main_glyph->device_width; +if (combining_glyphs_out) *combining_glyphs_out = combining_glyphs;else
Quoted 1 line · Vladimir Testov
Suggested patch to fix this problem (second one) is attached.
Nope, it won't help. I'll think again...
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
Quoted 97 lines · Vladimir Testov
O.k. Here it is.
from
grub-core/font/font.cline 1387 functionblit_comb:Quoted 23 lines
do_blit (combining_glyphs[i], main_glyph->device_width + combining_glyphs[i]->offset_x, -(combining_glyphs[i]->height + combining_glyphs[i]->offset_y), &ctx); add_device_width (combining_glyphs[i]->device_width, &ctx); } }}
add_device_width((above_rightx>
below_rightx?above_rightx:below_rightx) -(
main_glyph->offset_x+main_glyph->width), &ctx);Quoted 8 lines
add_device_width(above_leftx-main_glyph->offset_x, &ctx); if (glyph &&glyph->device_width<min_devwidth)glyph->device_width = min_devwidth;if (
device_width&&*device_width<min_devwidth)*device_width = min_devwidth;***device_width is changed sometimes.
from
grub-core/font/font.cline 1458 functiongrub_font_construct_dry_run:Quoted 35 lines
if (
device_width)*device_width = main_glyph->device_width;if (!glyph_id->ncomb && !glyph_id->attributes)
return main_glyph;
combining_glyphs=grub_malloc(sizeof (combining_glyphs[0])*
glyph_id->ncomb);if (
glyph_id->ncomb&& !combining_glyphs){grub_errno = GRUB_ERR_NONE; return main_glyph;}for (i = 0; i <
glyph_id->ncomb; i++)combining_glyphs[i] = grub_font_get_glyph_with_fallback (main_glyph->font, glyph_id->combining[i].code);
blit_comb(glyph_id, NULL, bounds,main_glyph,combining_glyphs,device_width);if (
combining_glyphs_out)Quoted 7 lines
*combining_glyphs_out = combining_glyphs;else
grub_free (combining_glyphs);return
main_glyph;***return value
*device_widthset tomain_glyph->device_widthbeforemain_glyph->device_widthis changed during execution ofblit_combIf we want to get
device_widthof some glyph - we use functionget_constructed_device_width. It returnsdevice_widthparameter of the asked glyph with parameter*device_widthof the functiongrub_font_construct_dry_run.When we actually construct glyph, we take
device_widthfrom glyph-Quoted 1 line
device_width.The most adequate way to find
device_widthofgrub_unicode_glyphis to callgrub_font_get_constructed_device_width. But it is miscalculated in some cases.
Quoted 6 lines
So these two values are different in some cases (This is all about problem
2)Suggested patch to fix this problem (second one) is attached.
I will remake the patch for multistring support for the upstream version.
Looks like I've misunderstood something... Sorry. Can't see where the problem is...
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
Quoted 4 lines
Looks like I've misunderstood something... Sorry. Can't see where the problem is...
blit_comb has dry run mode and it's what's used to get constructed length.
Meanwhile,
patch was rebuild for upstream version
still has two problems I've mentioned before
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
grub-core/gfxmenu/font.c +89 -0
@@ -75,6 +75,95 @@return GRUB_ERR_NONE ; } +/* Printing function for grub_font_draw_multiline. */ +static grub_err_t +print_line (grub_font_t font,grub_video_color_t color, +int start_x,int baseline_y, +struct grub_unicode_glyph *pos,struct grub_unicode_glyph *end) +{ +struct grub_font_glyph *glyph; +while (pos != end) + { +grub_err_t err; + glyph =grub_font_construct_glyph (font, pos); +if (!glyph) +return grub_errno; + err =grub_font_draw_glyph (glyph, color, start_x, baseline_y); + start_x += glyph->device_width; +grub_free (glyph); +if (err) +return err; + pos ++; + } +return GRUB_ERR_NONE ; +} + +/* Get character's printing width. */ +static grub_ssize_t +font_getcharwidth (const struct grub_unicode_glyph *c,void *font) +{ +return grub_font_get_constructed_device_width (font, c); +} + +/* Analog of grub_font_draw_line with multiline output. */ +grub_err_t +grub_font_draw_multiline (const char *str,grub_font_t font, +grub_video_color_t color, +int baseline_y,int font_height, +int max_width,int max_height, +int align) +{ +int x; +grub_uint32_t *logical; +grub_ssize_t logical_len, visual_len; +struct grub_unicode_glyph *visual, *ptr, *pos; + + logical_len =grub_utf8_to_ucs4_alloc (str, &logical,0 ); +if (logical_len <0 ) +return grub_errno; + + visual_len =grub_bidi_logical_to_visual (logical, logical_len, &visual, + font_getcharwidth, font, max_width,0 ,0 ,0 ,0 ); +grub_free (logical); +if (visual_len <0 ) +return grub_errno; + + pos = visual; +for (ptr = visual, x =0 ; ptr <= visual + visual_len; ptr++) + { +if (baseline_y > max_height) +break ; +if (ptr->base =='\n' || ptr == visual + visual_len) + { +if (align ==1 ) + x = (max_width - x) /2 ; +else if (align ==2 ) + x = max_width - x; +else + x =0 ; + +grub_err_t err; + err =print_line (font, color, x, baseline_y, pos, ptr); +if (err !=GRUB_ERR_NONE ) +return err; + + baseline_y += font_height; + x =0 ; +while ((ptr +1 < visual + visual_len) + && ((ptr +1 )->base ==' ' + || (ptr +1 )->base =='\t' )) + ptr ++; + pos = ptr +1 ; + } +else + x +=grub_font_get_constructed_device_width (font, ptr); + } + +grub_free (visual); + +return GRUB_ERR_NONE ; +} +/* Get the width in pixels of the specified UTF-8 string, when rendered in in the specified font (but falling back on other fonts for glyphs that are missing). */
grub-core/gfxmenu/gui_label.c +51 -21
106 lines not on this page · raw message
include/grub/gfxmenu_view.h +6 -0
@@ -66,6 +66,12 @@grub_font_t font, grub_video_color_t color, int left_x, int baseline_y); +grub_err_t grub_font_draw_multiline (const char *str, +grub_font_t font, +grub_video_color_t color, +int baseline_y,int font_height, +int max_width,int max_height, +int align);int grub_font_get_string_width (grub_font_t font,const char *str);
RFC PATCH 1/1 multistring support in gui_label
Hi, folks!
Quoted 1 line · Vladimir Testov
still has two problems I've mentioned before
I can't get what I have missed.
text = "@KEYMAP_LONG@"
muiltiline = "true"
the problem lays in the first quote near 'e'. (see screenshot attached) This symbol's length during bidi_line_wrap is less than it's font symbol's device_width.
I suppose it is somehow connected with bidi \ join algorithms. Can't get through.
Please help!
Did I make some mistake in printing alrorithm? Or have I misunderstood smth?
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru