Hi,
I attached a little patch to IDirectFBFont::GetStringBreak()
There is an off by one bug (in certain cases), which is why
GetStringWidth() can return more characters than what would fit into the
requested maximum.
And also I have some questions regarding this API:
a) It returns the number of _characters_ whereas all the other DirectFB
font APIs expect bytes. This means the string will always be iterated
twice, once in GetStringBreak(), and again in the application to convert
from characters back to bytes. Why is that? Seems like a strange API
design decision, what am I missing?
b) The pixelwidth returned from GetStringBreak() is the (logical) string
width (in pixels) that would be occupied if you were _not_ to split the
line at a <SPACE> or <CR> character, but continue drawing the next word
(within the limits of max_width). The character count returned though is
the character count up to the <SPACE> or <CR> character. Why this
difference?
Cheers,
Andre'
From d992bf11751b44f386bf97a5b886eb80d18b0e85 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Andr=C3=A9=20Draszik?= <andre.dras...@st.com>
Date: Thu, 3 Sep 2009 13:53:51 +0100
Subject: [PATCH] font: fix off-by-one bug in IDirectFBFont_GetStringBreak()
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
GetStringBreak() returns one character too much (in certain cases) in
ret_str_length.
Signed-off-by: André Draszik <andre.dras...@st.com>
---
src/media/idirectfbfont.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/media/idirectfbfont.c b/src/media/idirectfbfont.c
index 1cc9697..cf5c013 100644
--- a/src/media/idirectfbfont.c
+++ b/src/media/idirectfbfont.c
@@ -484,7 +484,6 @@ IDirectFBFont_GetStringBreak( IDirectFBFont *thiz,
do {
*ret_width = width;
- length ++;
current = DIRECT_UTF8_GET_CHAR( string );
@@ -496,6 +495,8 @@ IDirectFBFont_GetStringBreak( IDirectFBFont *thiz,
*ret_width = width;
}
+ length++;
+
ret = dfb_font_decode_character( font, data->encoding, current,
&index );
if (ret)
continue;
--
1.6.0.4
_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev