changeset 1256:6a1e98ad782e

a Textblock::addText() that takes len arg
author corvid <corvid@lavabit.com>
date Sun, 02 Aug 2009 04:24:42 +0000
parents 5d6869b28e4d
children a86cedaec1b4
files dw/textblock.cc dw/textblock.hh src/html.cc
diffstat 3 files changed, 17 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/dw/textblock.cc	Sun Aug 02 03:59:14 2009 +0000
+++ b/dw/textblock.cc	Sun Aug 02 04:24:42 2009 +0000
@@ -1601,11 +1601,11 @@
 /**
  * Calculate the size of a text word.
  */
-void Textblock::calcTextSize (const char *text, core::style::Style *style,
+void Textblock::calcTextSize (const char *text, size_t len,
+                              core::style::Style *style,
                               core::Requisition *size)
 {
-   size->width =
-      layout->textWidth (style->font, text, strlen (text));
+   size->width = layout->textWidth (style->font, text, len);
    size->ascent = style->font->ascent;
    size->descent = style->font->descent;
 
@@ -1623,15 +1623,16 @@
  * Add a word to the page structure. Stashes the argument pointer in
  * the page data structure so that it will be deallocated on destroy.
  */
-void Textblock::addText (const char *text, core::style::Style *style)
+void Textblock::addText (const char *text, size_t len,
+                         core::style::Style *style)
 {
    Word *word;
    core::Requisition size;
 
-   calcTextSize (text, style, &size);
+   calcTextSize (text, len, style, &size);
    word = addWord (size.width, size.ascent, size.descent, style);
    word->content.type = core::Content::TEXT;
-   word->content.text = layout->textZone->strdup(text);
+   word->content.text = layout->textZone->strndup(text, len);
 
    //DBG_OBJ_ARRSET_STR (page, "words.%d.content.text", page->num_words - 1,
    //                    word->content.text);
--- a/dw/textblock.hh	Sun Aug 02 03:59:14 2009 +0000
+++ b/dw/textblock.hh	Sun Aug 02 04:24:42 2009 +0000
@@ -272,7 +272,7 @@
 
    Word *addWord (int width, int ascent, int descent,
                   core::style::Style *style);
-   void calcTextSize (const char *text, core::style::Style *style,
+   void calcTextSize (const char *text, size_t len, core::style::Style *style,
                       core::Requisition *size);
 
 
@@ -371,7 +371,11 @@
 
    void flush ();
 
-   void addText (const char *text, core::style::Style *style);
+   void addText (const char *text, size_t len, core::style::Style *style);
+   inline void addText (const char *text, core::style::Style *style)
+   {
+      addText (text, strlen(text), style);
+   }
    void addWidget (core::Widget *widget, core::style::Style *style);
    bool addAnchor (const char *name, core::style::Style *style);
    void addSpace(core::style::Style *style);
--- a/src/html.cc	Sun Aug 02 03:59:14 2009 +0000
+++ b/src/html.cc	Sun Aug 02 04:24:42 2009 +0000
@@ -1125,7 +1125,7 @@
 static void Html_process_word(DilloHtml *html, char *word, int size)
 {
    int i, j, start;
-   char *Pword, ch;
+   char *Pword;
    DilloHtmlParseMode parse_mode = S_TOP(html)->parse_mode;
 
    if (parse_mode == DILLO_HTML_PARSE_MODE_STASH ||
@@ -1156,11 +1156,8 @@
             Html_process_space(html, Pword + start, i - start);
          } else {
             while (Pword[++i] && !isspace(Pword[i])) ;
-            ch = Pword[i];
-            Pword[i] = 0;
-            HT2TB(html)->addText(Pword + start,
+            HT2TB(html)->addText(Pword + start, i - start,
                                      html->styleEngine->wordStyle ());
-            Pword[i] = ch;
             html->pre_column += i - start;
             html->PreFirstChar = false;
          }
@@ -1196,22 +1193,16 @@
             Html_process_space(html, Pword + start, i - start);
          } else if (a_Utf8_ideographic(Pword+i, Pword_end, &len)) {
             i += len;
-            ch = Pword[i];
-            Pword[i] = '\0';
-            HT2TB(html)->addText(Pword + start,
+            HT2TB(html)->addText(Pword + start, i - start,
                                  html->styleEngine->wordStyle ());
-            Pword[i] = ch;
             html->PrevWasSPC = false;
          } else {
             do {
                i += len;
             } while (Pword[i] && !isspace(Pword[i]) &&
                      (!a_Utf8_ideographic(Pword+i, Pword_end, &len)));
-            ch = Pword[i];
-            Pword[i] = 0;
-            HT2TB(html)->addText(Pword + start,
+            HT2TB(html)->addText(Pword + start, i - start,
                                  html->styleEngine->wordStyle ());
-            Pword[i] = ch;
             html->PrevWasSPC = false;
          }
       }