From c8e2552ad9b79cd7ab8ba68e8a50fa0ae46b6de5 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Mon, 23 Jun 2008 17:09:53 -0400 Subject: [PATCH] richedit: Trailing spaces should not affect alignment shift length. --- dlls/riched20/wrap.c | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c index 3230ff76dca..adabea13803 100644 --- a/dlls/riched20/wrap.c +++ b/dlls/riched20/wrap.c @@ -58,21 +58,47 @@ static void ME_BeginRow(ME_WrapContext *wc) static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd) { ME_DisplayItem *p, *row, *para; + BOOL bSkippingSpaces = TRUE; int ascent = 0, descent = 0, width=0, shift = 0, align = 0; /* wrap text */ para = ME_GetParagraph(wc->pRowStart); - for (p = wc->pRowStart; p!=pEnd; p = p->next) + + for (p = pEnd->prev; p!=wc->pRowStart->prev; p = p->prev) { - /* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */ - if (p->type==diRun && ((p==wc->pRowStart) || !(p->member.run.nFlags & MERF_ENDPARA))) { /* FIXME add more run types */ - if (p->member.run.nAscent>ascent) - ascent = p->member.run.nAscent; - if (p->member.run.nDescent>descent) - descent = p->member.run.nDescent; - if (!(p->member.run.nFlags & (MERF_ENDPARA|MERF_SKIPPED))) - width += p->member.run.nWidth; - } + /* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */ + if (p->type==diRun && ((p==wc->pRowStart) || !(p->member.run.nFlags & MERF_ENDPARA))) { /* FIXME add more run types */ + if (p->member.run.nAscent>ascent) + ascent = p->member.run.nAscent; + if (p->member.run.nDescent>descent) + descent = p->member.run.nDescent; + if (bSkippingSpaces) + { + /* Exclude space characters from run width. + * Other whitespace or delimiters are not treated this way. */ + SIZE sz; + int len = p->member.run.strText->nLen; + WCHAR *text = p->member.run.strText->szData + len - 1; + + assert (len); + while (len && *(text--) == ' ') + len--; + if (len) + { + if (len == p->member.run.strText->nLen) + { + width += p->member.run.nWidth; + } else { + sz = ME_GetRunSize(wc->context, ¶->member.para, + &p->member.run, len, p->member.run.pt.x); + width += sz.cx; + } + } + bSkippingSpaces = !len; + } else if (!(p->member.run.nFlags & MERF_ENDPARA)) + width += p->member.run.nWidth; + } } + row = ME_MakeRow(ascent+descent, ascent, width); row->member.row.nYPos = wc->pt.y; row->member.row.nLMargin = (!wc->nRow ? wc->nFirstMargin : wc->nLeftMargin); @@ -98,7 +124,7 @@ static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd) static void ME_WrapEndParagraph(ME_WrapContext *wc, ME_DisplayItem *p) { if (wc->pRowStart) - ME_InsertRowStart(wc, p->next); + ME_InsertRowStart(wc, p); /* p = p->member.para.prev_para->next; -- 2.11.4.GIT