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

List:       kde-commits
Subject:    kdelibs/khtml
From:       Allan Sandfeld Jensen <kde () carewolf ! com>
Date:       2004-12-01 0:30:59
Message-ID: 20041201003059.52A181B95D () office ! kde ! org
[Download RAW message or body]

CVS commit by carewolf: 

Implement decimal-leading-zero list-style-type.
(Throwing in the code to do arabic and persian numerics as a bonus)
FEATURE: 59508


  M +4 -0      ChangeLog   1.345
  M +66 -3     rendering/render_list.cpp   1.98
  M +3 -1      rendering/render_list.h   1.38


--- kdelibs/khtml/ChangeLog  #1.344:1.345
@@ -1,2 +1,6 @@
+2004-12-01  Allan Sandfeld Jensen <kde@carewolf.com>
+
+        * render/render_list.{cpp,h}: Implement list-style-type: decimal-leading-zero
+
 2004-11-30  Germain Garand  <germain@ebooksfrance.org>
 

--- kdelibs/khtml/rendering/render_list.cpp  #1.97:1.98
@@ -118,4 +118,19 @@ static QString toHebrew( int number ) {
 }
 
+static QString toNumeric( int number, int base ) {
+    QString letter = QString::number(number);
+    for(int i = 0; i < letter.length(); i++) {
+        letter[i] = QChar(letter[i].digitValue()+base);
+    }
+}
+
+inline static QString toArabicIndic( int number ) {
+    return toNumeric(number, 0x660);
+}
+
+inline static QString toPersianUrdu( int number ) {
+    return toNumeric(number, 0x6F0);
+}
+
 // -------------------------------------------------------------------------
 
@@ -273,8 +288,42 @@ void RenderListItem::calcListValue()
 }
 
+void RenderListItem::calcListTotal()
+{
+    // only called from the marker so..
+    KHTMLAssert(m_marker);
+
+    // first see if our siblings have already counted the total
+    RenderObject *o = previousSibling();
+    while ( o && (!o->isListItem() || o->style()->listStyleType() == LNONE) )
+        o = o->previousSibling();
+    if( o && o->isListItem() && o->style()->listStyleType() != LNONE ) {
+        RenderListItem *item = static_cast<RenderListItem *>(o);
+        m_marker->m_total = item->m_marker->m_total;
+    }
+    else {
+        // count total number of sibling items
+        const RenderObject* o = parent();
+        while ( o && o->isAnonymous() )
+            o = o->parent();
+
+        unsigned int count;
+        if (o->element() && o->element()->id() == ID_OL)
+            count = static_cast<DOM::HTMLOListElementImpl*>(o->element())->start() - 1;
+        else
+            count = 0;
+
+        o = o->firstChild();
+        while (o) {
+            if (o->isListItem()) count++;
+            o = o->nextSibling();
+        }
+        m_marker->m_total = count;
+    }
+}
+
 // -----------------------------------------------------------
 
 RenderListMarker::RenderListMarker(DOM::DocumentImpl* node)
-    : RenderBox(node), m_listImage(0), m_value(-1)
+    : RenderBox(node), m_listImage(0), m_value(-1), m_total(-1)
 {
     // init RenderObject attributes
@@ -498,9 +547,23 @@ void RenderListMarker::calcMinMaxWidth()
     case HIRAGANA_IROHA:
     case KATAKANA_IROHA:
-    case DECIMAL_LEADING_ZERO:
         // ### unsupported, we use decimal instead
     case LDECIMAL:
-        m_item.sprintf( "%2ld", m_value );
+        m_item.setNum ( m_value );
         break;
+    case DECIMAL_LEADING_ZERO: {
+        if (m_total < 0)
+            m_listItem->calcListTotal();
+        int decimals = 2;
+        int t = m_total/100;
+        while (t>0) {
+            t = t/10;
+            decimals++;
+        }
+        decimals = kMax(decimals, 2);
+        QString num = QString::number(m_value);
+        m_item.fill('0',decimals-num.length());
+        m_item.append(num);
+        break;
+    }
     case LOWER_ROMAN:
         m_item = toRoman( m_value, false );

--- kdelibs/khtml/rendering/render_list.h  #1.37:1.38
@@ -55,4 +55,5 @@ public:
     void setValue( long v ) { predefVal = v; }
     void calcListValue();
+    void calcListTotal();
 
     virtual void layout( );
@@ -110,5 +111,6 @@ protected:
     QString m_item;
     CachedImage *m_listImage;
-    long m_value;
+    int m_value;
+    int m_total;
     RenderListItem* m_listItem;
 };


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

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