From eda5c2dc976f2d02cee5c8dc2feaa2d824d40c79 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 3 Nov 2020 20:54:53 -0500 Subject: ui: Fix line wrapping of emoticons While we do want to have special handling of punctuation to help wrap pathologically-long-hyphenated-words-that-go-on-for-kilometers, we don't want to wrap emoticons, so let's adjust the logic to account for this. While we're at it, clean up and add a comment explaining the logic for the benefit of future readers. Fixes rendering of a recent post on CAPCOM at certain window sizes => gemini://rosenzweig.io/lagrange/Before.png Before the change => gemini://rosenzweig.io/lagrange/After.png After the change Notice the wrapping of the ":D" in the second paragraph. Signed-off-by: Alyssa Rosenzweig --- src/ui/text.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/text.c b/src/ui/text.c index 2ceadb75..f998688a 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -586,11 +586,22 @@ static enum iFontId fontId_Text_(const iFont *font) { return font - text_.fonts; } -iLocalDef iBool isWrapBoundary_(iChar a, iChar b) { - if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':' || b == '.') { +/* Line wrapping boundaries are determined by looking at a character and the + * last character processed. We want to wrap at natural word boundaries where + * possible, so normally we wrap at a space followed a non-space character. As + * an exception, we also wrap after punctuation used to break up words, so we + * can wrap text like foo/bar/baz-abc-def.xyz at any puncation boundaries, + * without wrapping on other punctuation used for expressive purposes like + * emoticons :-) */ + +iLocalDef iBool isWrapBoundary_(iChar prevC, iChar c) { + if (isSpace_Char(prevC)) + return iFalse; + + if (c == '/' || c == '-' || c == ',' || c == ';' || c == ':' || c == '.') return iTrue; - } - return !isSpace_Char(a) && isSpace_Char(b); + + return isSpace_Char(c); } iLocalDef iBool isMeasuring_(enum iRunMode mode) { -- cgit v1.2.3