[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bugs-dist
Subject:    [Bug 33855] Konqueror does not handle soft-hyphen
From:       Germain Garand <germain () ebooksfrance ! com>
Date:       2005-10-08 20:20:01
Message-ID: 20051008202001.29560.qmail () ktown ! kde ! org
[Download RAW message or body]

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
         
http://bugs.kde.org/show_bug.cgi?id=33855         
germain ebooksfrance com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From germain ebooksfrance com  2005-10-08 22:19 -------
SVN commit 468638 by ggarand:

Port soft-hyphen support from WebCore

BUG: 33855, 113900



 M  +8 -0      ChangeLog  
 M  +65 -4     rendering/bidi.cpp  
 M  +5 -1      rendering/render_text.cpp  
 M  +3 -0      rendering/render_text.h  


--- branches/KDE/3.5/kdelibs/khtml/ChangeLog #468637:468638
 @ -1,5 +1,13  @
 2005-10-08  Germain Garand  <germain ebooksfrance org>
 
+        Port soft-hyphen support from WebCore
+
+        * rendering/bidi.cpp (findNextLineBreak): main skipping/breaking logic
+
+        * rendering/render_text.{cpp,h} (calcMinMaxWidth): account for soft hyphen
+
+2005-10-08  Germain Garand  <germain ebooksfrance org>
+
         Follow Mozilla/Opera in considering the Window object as an implementation \
                of the AbstractView/ViewCSS 
         DOM2 interfaces. Return the Window object when available ; an AbstractView \
if not.  
--- branches/KDE/3.5/kdelibs/khtml/rendering/bidi.cpp #468637:468638
 @ -420,6 +420,19  @
         sLastBidiRun = startRun;
 }
 
+static void chopMidpointsAt(RenderObject* obj, uint pos)
+{
+    if (!sNumMidpoints) return;
+    BidiIterator* midpoints = smidpoints->data();
+    for (uint i = 0; i < sNumMidpoints; i++) {
+        const BidiIterator& point = midpoints[i];
+        if (point.obj == obj && point.pos == pos) {
+            sNumMidpoints = i;
+            break;
+        }
+    }
+}
+
 static void checkMidpoints(BidiIterator& lBreak, BidiState &bidi)
 {
     // Check to see if our last midpoint is a start point beyond the line break.  If \
so,  @ -435,8 +448,16  @
         if (currpoint == lBreak) {
             // We hit the line break before the start point.  Shave off the start \
point.  sNumMidpoints--;
-            if (!endpoint.obj->style()->preserveWS())
+            if (!endpoint.obj->style()->preserveWS()) {
+                if (endpoint.obj->isText()) {
+                    // Don't shave a character off the endpoint if it was from a \
soft hyphen. +                    RenderText* textObj = \
static_cast<RenderText*>(endpoint.obj); +                    if (endpoint.pos+1 < \
textObj->length() && +                        \
textObj->text()[endpoint.pos+1].unicode() == SOFT_HYPHEN) +                        \
return; +                }
                 endpoint.pos--;
+            }
         }
     }
 }
 @ -1817,19 +1838,47  @
             bool appliedStartWidth = pos > 0; // If the span originated on a \
                previous line,
                                               // then assume the start width has \
been applied.  bool appliedEndWidth = false;
+            bool nextIsSoftBreakable = false;
 
             while(len) {
                 bool previousCharacterIsSpace = currentCharacterIsSpace;
+                bool isSoftBreakable = nextIsSoftBreakable;
+                nextIsSoftBreakable = false;
                 const QChar c = str[pos];
                 currentCharacterIsSpace = c == ' ';
 
                 if (preserveWS || !currentCharacterIsSpace)
                     isLineEmpty = false;
 
+                // Check for soft hyphens.  Go ahead and ignore them.
+                if (c.unicode() == SOFT_HYPHEN && pos > 0) {
+                    nextIsSoftBreakable = true;
+                    if (!ignoringSpaces) {
+                        // Ignore soft hyphens
+                        BidiIterator endMid(0, o, pos-1);
+                        addMidpoint(endMid);
+                        
+                        // Add the width up to but not including the hyphen.
+                        tmpW += t->width(lastSpace, pos - lastSpace, f);
+                        
+                        // For whitespace normal only, include the hyphen.  We need \
to ensure it will fit +                        // on the line if it shows when we \
break. +                        if (o->style()->whiteSpace() == NORMAL)
+                            tmpW += t->width(pos, 1, f);
+                        
+                        BidiIterator startMid(0, o, pos+1);
+                        addMidpoint(startMid);
+                    }
+                    
+                    pos++;
+                    len--;
+                    lastSpace = pos; // Cheesy hack to prevent adding in widths of \
the run twice. +                    continue;
+                }
 #ifdef APPLE_CHANGES    // KDE applies wordspacing differently
                 bool applyWordSpacing = false;
 #endif
-                if ( (preserveLF && c == '\n') || (autoWrap && isBreakable( str, \
pos, strlen )) ) { +                if ( (preserveLF && c == '\n') || (autoWrap && \
(isBreakable( str, pos, strlen ) || isSoftBreakable)) ) {  if (ignoringSpaces) {
                         if (!currentCharacterIsSpace) {
                             // Stop ignoring spaces and begin at this
 @ -1880,8 +1929,12  @
                         }
                     }
 
-                    if (w + tmpW > width && autoWrap) {
-                        goto end;
+                    if (autoWrap) {
+                        if (w+tmpW > width)
+                            goto end;
+                        else if ( (pos > 1 && str[pos-1].unicode() == SOFT_HYPHEN) )
+                            // Subtract the width of the soft hyphen out since we \
fit on a line. +                            tmpW -= t->width(pos-1, 1, f);            \
  }
 
                     if( preserveLF && *(str+pos) == '\n' ) {
 @ -2114,6 +2167,14  @
         lBreak.increment(bidi);
     }
 
+    if (lBreak.obj && lBreak.pos >= 2 && lBreak.obj->isText()) {
+        // For soft hyphens on line breaks, we have to chop out the midpoints that \
made us +        // ignore the hyphen so that it will render at the end of the line.
+        QChar c = static_cast<RenderText*>(lBreak.obj)->text()[lBreak.pos-1];
+        if (c.unicode() == SOFT_HYPHEN)
+            chopMidpointsAt(lBreak.obj, lBreak.pos-2);
+    }
+
     return lBreak;
 }
 
--- branches/KDE/3.5/kdelibs/khtml/rendering/render_text.cpp #468637:468638
 @ -1041,9 +1041,13  @
             m_hasBeginWS = true;
         if ((isSpace || isNewline) && i == len-1)
             m_hasEndWS = true;
+        
+        if (i && c == SOFT_HYPHEN)
+            continue;
 
         int wordlen = 0;
-        while( i+wordlen < len && !(isBreakable( str->s, i+wordlen, str->l )) )
+        while( i+wordlen < len && (i+wordlen == 0 || str->s[i+wordlen].unicode() != \
SOFT_HYPHEN) && +               !(isBreakable( str->s, i+wordlen, str->l )) )
             wordlen++;
 
         if (wordlen)
--- branches/KDE/3.5/kdelibs/khtml/rendering/render_text.h #468637:468638
 @ -36,6 +36,9  @
 class QPainter;
 class QFontMetrics;
 
+// Define a constant for soft hyphen's unicode value.
+#define SOFT_HYPHEN 173
+
 namespace khtml
 {
     class RenderText;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic