On Sun, Dec 26, 2021 at 07:29:27PM +0100, Hiltjo Posthuma wrote:
> > Thanks for the patch. It uses indeed less resources for very long lines and
> > it
> > makes more sense to do it this way.
> >
> > A small change for the test script, you probably want to add a newline
> > (echo)
> > between it:
> >
> > for i in $(seq 20); do
> > cat /dev/urandom | base64 | tr -d '\n' | head -c 1000000
> > echo
> > done | ./dmenu -l 10
> >
> > I synced the code to dwm and the libsl repository too.
> >
> > --
> > Kind regards,
> > Hiltjo
> >
>
> Hi,
>
> This patch had issues so it was reverted for now. Anyone have time to work on
> this during the holidays maybe?
>
> The drw.c drw_text() text truncation code using "..." is also incorrect
> currently for UTF-8 and when multiple fallback fonts are used.
Hi,
I assume the reason for this was that with loop condition `n < limit`
the loop would stop when `n >= limit`, meaning that n might
"over-shoot".
If that was the case, then just having another loop cleanup the
over-shoot should fix the issue. Testing with the test script in this
thread, I see proper truncation identical to mainline dmenu without this
patch.
However I still saw some problems with emojies/unicode truncation, the
test file is attached.
./dmenu < unicringe.txt
Changing the first loop condition from `len < MIN(..)` to `len <=
MIN(..)` fixes that as well for me.
NB: I'm not really sure weather this patch is *actually* correct or not.
But since both of my test-cases are passing, sending the patch.
- NRK
๐ ๐ ๐ ๐ ๐ ๐
๐คฃ ๐ ๐ ๐ ๐ ๐ ๐ ๐ฅฐ ๐ ๐คฉ ๐ ๐ โบ๏ธ ๐ ๐ ๐ฅฒ ๐ ๐ ๐ ๐คช ๐ ๐ค ๐ค ๐คญ ๐คซ ๐ค ๐ค ๐คจ ๐ ๐ ๐ถ ๐ ๐
๐ ๐ฌ ๐คฅ ๐ ๐ ๐ช ๐คค ๐ด ๐ท ๐ค ๐ค ๐คข ๐คฎ ๐คง ๐ฅต ๐ฅถ ๐ฅด ๐ต ๐คฏ ๐ค ๐ฅณ ๐ฅธ ๐ ๐ค ๐ง ๐ ๐ ๐ โน๏ธ ๐ฎ ๐ฏ ๐ฒ ๐ณ ๐ฅบ ๐ฆ ๐ง ๐จ ๐ฐ ๐ฅ
๐ข ๐ญ ๐ฑ ๐ ๐ฃ ๐ ๐ ๐ฉ ๐ซ ๐ฅฑ ๐ค ๐ก ๐ ๐คฌ ๐ ๐ฟ ๐ โ ๏ธ ๐ฉ ๐คก ๐น ๐บ
>From 0ce7d6adfe1cdd460eabf26a4de6477dc65012a3 Mon Sep 17 00:00:00 2001
From: NRK <[email protected]>
Date: Sun, 13 Mar 2022 15:48:41 +0600
Subject: [PATCH] optimize drw_text() for large strings
... but correctly (hopefully =])
based on Miles Alan's patch.
---
drw.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drw.c b/drw.c
index 4cdbcbe..e66e137 100644
--- a/drw.c
+++ b/drw.c
@@ -310,8 +310,14 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
if (utf8strlen) {
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
/* shorten text if necessary */
- for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
- drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ if (ew > w) {
+ for (ew = 0, len = 0; ew < w && len <= MIN(utf8strlen, sizeof(buf) - 1); len++)
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ for (; ew > w && len; --len) /* mop-up incase of overshoot */
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ } else {
+ len = MIN(utf8strlen, sizeof(buf) - 1);
+ }
if (len) {
memcpy(buf, utf8str, len);
--
2.34.1