Dylan Smith : richedit: Trailing spaces should not affect alignment shift length.

Alexandre Julliard julliard at winehq.org
Wed Jun 25 04:47:44 CDT 2008


Module: wine
Branch: master
Commit: c8e2552ad9b79cd7ab8ba68e8a50fa0ae46b6de5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c8e2552ad9b79cd7ab8ba68e8a50fa0ae46b6de5

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Mon Jun 23 17:09:53 2008 -0400

richedit: Trailing spaces should not affect alignment shift length.

---

 dlls/riched20/wrap.c |   48 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index 3230ff7..adabea1 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, &para->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;




More information about the wine-cvs mailing list