Re: Word wrap bug.




See if this works...

Jeff

--------------------------------------
gchar *soft_word_wrap (gchar *text, guint len)
{
   /* wraps text without breaking up `words`
    * allowing `len` chars per line */
   gchar *curpos, *lastspc, *lastbrk;

   for (curpos = lastspc = lastbrk = text; *curpos; curpos++)
   {
      if (*curpos == ' ')
         lastspc = curpos;
      else
         if (*curpos == '\n')
         {
            lastbrk = curpos;
            lastspc = lastbrk;
         }
      if ( (curpos - lastbrk) >= len)
      {
         lastspc = '\n';
         lastbrk = lastspc;
      }
   }
}

gchar *hard_word_wrap (gchar *text, guint len)
{
   /* wraps text at `len` chars per line whether it breaks up a word or not
    * returns a pointer to an allocated string - be sure to free this
memory later!! */
   gchar *curpos, *lastbrk;
   gchar *buffer, *buffpos;
   guint bufflen;

   bufflen = strlen(text) + 1;
   buffer = g_malloc0(bufflen);

   buffpos = buffer;
   for (curpos = text; *curpos; curpos++)
   {
      *buffpos++ = *curpos;
      if (*curpos == '\n')
         lastbrk = curpos;
      if ( (curpos - lastbrk) >= len)
      {
         bufflen++;
         buffer = g_realloc(buffer, bufflen);
         *buffpos++ = '\n';
      }
   }

   return buffer;
}

#define word_wrap (a, b) hard_word_wrap (soft_word_wrap((a), (b)), (b))

void send_body_wrap (Body *body, GtkText *text)
{
   body->buffer = word_wrap(gtk_editable_get_chars (GTK_EDITABLE(text), 0,
-1), balsa_app.wraplength);
}

On 12 Jan 2000, "Jason A . Smith" wrote:
> Date: 12 Jan 2000 00:47:02 -0000
> To: balsa-list@gnome.org
> From: "Jason A . Smith" <smithj4@alum.rpi.edu>
> Reply-To: "Jason A . Smith" <smithj4@alum.rpi.edu>
> Subject: Word wrap bug.
> 
> 
> 	I think I found a minor bug in the word wrapping code in balsa.  If 
> a line contains one really long word, like a long URL for example, then 
> it is cut at the correct place, but a character is missing at the place 
> that the line is cut.  I assume that this is done to cut out the space 
> that is usually between words.  Sorry I don't have the time to go through

> the code and fix it myself to send you a patch.
> 
> 	I also have a question about the line wrapping preference dialog and 
> what the code actually does.  I see in the code, that if the line begins 
> with a ">" it is broken at what the user specifies, otherwise it is cut 6

> spaces before.  I can understand the reason why this is done, but still 
> as a user I would find it odd that when I specify word wrapping at 78 
> characters, the program really wraps it at 72 characters.  Shouldn't it 
> wrap it at the place that the user requests?  Maybe change the default to

> 72 instead of having the program wrap it earlier than what the user 
> specifies.  Also, if you are going to check for a line beginning with ">"

> in the code, it should probably be changed to whatever the user specified

> the reply prefix to instead of hard coding a ">", just in case they 
> changed it.
> 
> -Jason
> 
> P.S.  Nice job!
> 
> 
> |----------------------------------------------------------------------|
> | Jason A. Smith                    E-mail:  smithj4@alum.rpi.edu      |
> | Physics Department                Phone:   (518)276-2050             |
> | Rensselaer Polytechnic Institute  FAX:     (518)276-6680             |
> | Troy, NY 12180-3590               WWW:  http://www.rpi.edu/~smithj4/ |
> |----------------------------------------------------------------------|
> 
> 
> -- 
> 	FAQ: Frequently-Asked Questions at http://www.gnome.org/gnomefaq
>          To unsubscribe: mail balsa-list-request@gnome.org with 
>                        "unsubscribe" as the Subject.
> 

-- 
Linux: May the source be with you...



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]