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

List:       kde-commits
Subject:    kdelibs/khtml/rendering
From:       Allan Sandfeld Jensen <kde () carewolf ! com>
Date:       2005-04-18 12:33:41
Message-ID: 20050418123341.F3213643 () office ! kde ! org
[Download RAW message or body]

CVS commit by carewolf: 

Improve positioning of list-markers especially in RTL lists.
Merged from WC


  M +38 -16    render_list.cpp   1.108


--- kdelibs/khtml/rendering/render_list.cpp  #1.107:1.108
@@ -44,4 +44,6 @@ using namespace khtml;
 using namespace Enumerate;
 
+const int cMarkerPadding = 7;
+
 // -------------------------------------------------------------------------
 
@@ -241,5 +243,4 @@ void RenderListMarker::paint(PaintInfo& 
     p->setFont(style()->font());
     const QFontMetrics fm = p->fontMetrics();
-    int offset = fm.ascent()*2/3;
 
 
@@ -290,13 +291,23 @@ void RenderListMarker::paint(PaintInfo& 
     }
 
+    int offset = fm.ascent()*2/3;
+    bool haveImage = m_listImage && !m_listImage->isErrorImage();
+    if (haveImage)
+        offset = m_listImage->pixmap().width();
 
     int xoff = 0;
     int yoff = fm.ascent() - offset;
 
-    if (!listPositionInside())
+    int bulletWidth = offset/2;
+    if (offset%2)
+        bulletWidth++;
+    if (!listPositionInside()) {
         if (listItem->style()->direction() == LTR)
-            xoff = -7 - offset;
+            xoff = -cMarkerPadding - offset;
         else
-            xoff = offset;
+            xoff = cMarkerPadding + (haveImage ? 0 : (offset - bulletWidth));
+    }
+    else if (style()->direction() == RTL)
+        xoff += haveImage ? cMarkerPadding : (m_width - bulletWidth);
 
     if ( m_listImage && !m_listImage->isErrorImage()) {
@@ -353,15 +364,27 @@ void RenderListMarker::paint(PaintInfo& 
         return;
     default:
-        if (!m_item.isNull()) {
+        if (!m_item.isEmpty()) {
             if(listPositionInside()) {
-                if(style()->direction() == LTR)
+                if( style()->direction() == LTR) {
                     p->drawText(_tx, _ty, 0, 0, Qt::AlignLeft|Qt::DontClip, m_item);
-                else
-                    p->drawText(_tx, _ty, 0, 0, Qt::AlignRight|Qt::DontClip, \
m_item); +                    p->drawText(_tx + fm.width(m_item), _ty, 0, 0, \
Qt::AlignLeft|Qt::DontClip, +                                QString::fromLatin1(". \
")); +                }
+                else {
+                    const QString& punct(QString::fromLatin1(" ."));
+                    p->drawText(_tx, _ty, 0, 0, Qt::AlignLeft|Qt::DontClip, punct);
+                    p->drawText(_tx + fm.width(punct), _ty, 0, 0, \
Qt::AlignLeft|Qt::DontClip, m_item); +                }
             } else {
-                if(style()->direction() == LTR)
-                    p->drawText(_tx-offset/2, _ty, 0, 0, \
                Qt::AlignRight|Qt::DontClip, m_item);
-                else
-                    p->drawText(_tx+offset/2 + parent()->width(), _ty, 0, 0, \
Qt::AlignLeft|Qt::DontClip, m_item); +                if (style()->direction() == \
LTR) { +                    const QString& punct(QString::fromLatin1(". "));
+                    p->drawText(_tx-offset/2, _ty, 0, 0, \
Qt::AlignRight|Qt::DontClip, punct); +                    \
p->drawText(_tx-offset/2-fm.width(punct), _ty, 0, 0, Qt::AlignRight|Qt::DontClip, \
m_item); +                }
+                else {
+                    const QString& punct(QString::fromLatin1(" ."));
+                    p->drawText(_tx+offset/2, _ty, 0, 0, Qt::AlignLeft|Qt::DontClip, \
punct); +                    p->drawText(_tx+offset/2+fm.width(punct), _ty, 0, 0, \
Qt::AlignLeft|Qt::DontClip, m_item); +                }
             }
         }
@@ -399,5 +422,5 @@ void RenderListMarker::calcMinMaxWidth()
 
     if(m_listImage) {
-        m_markerWidth = m_listImage->pixmap().width() + 5;
+        m_markerWidth = m_listImage->pixmap().width() + cMarkerPadding;
         if (listPositionInside())
             m_width = m_markerWidth;
@@ -524,6 +547,5 @@ void RenderListMarker::calcMinMaxWidth()
         KHTMLAssert(false);
     }
-    m_item += QString::fromLatin1(". ");
-    m_markerWidth = fm.width(m_item);
+    m_markerWidth = fm.width(m_item) + fm.width(QString::fromLatin1(". "));
     }
 


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

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