lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev GridText.c patch with new HText_trimHightext


From: Klaus Weide
Subject: lynx-dev GridText.c patch with new HText_trimHightext
Date: Tue, 24 Nov 1998 05:00:55 -0600 (CST)

Here is a patch which hopefully removes problems with form field
display during partial rendering.  Please test.

I still think that changing the highlight() call in display_page() to

          if (display_partial)
                highlight(OFF, (nlinks - 1), target);

and NOT calling HText_trimHightext() during partial rendering may
also solve the problems, but have not tested it.

The small change for color styles seems to give a big improvement.

Patches are against 2.8.1rel.2 but should also work with dev.x.


* HText_trimHightext (GridText.c): don't apply final adjustment
  repeatedly to an anchor that has already been handled by this
  function; the function may be called repeatedly if partial display
  is enabled.  Some other changes in this function, to interact
  better with the other GridText.c functions, especially for partial
  display mode.  We don't have to handle all anchors if the new
  parameter "final" is not set.
  Also empty anchors should now generally not any more move down over
  empty lines, if they happen at a line end.  Made some trace messages
  give more information.
* color styles: reset screen style cache to avoid random coloring
  when a link is unhighlighted.
* Tweak in HText_setLastOptionValue: if an OPTION tag was directly
  followed by several newlines, characters could be dropped.


*** lynx2-8-1.orig/src/GridText.h       Wed Oct 14 07:23:56 1998
--- lynx2-8-1/src/GridText.h    Sun Nov 15 09:36:04 1998
***************
*** 202,207 ****
--- 202,208 ----
        InputFieldData *I));
  extern void HText_trimHightext PARAMS((
        HText *         text,
+       BOOLEAN         final,
        BOOLEAN         disable_trace));
  extern void HText_SubmitForm PARAMS((
        FormInfo *      submit_item,
*** lynx2-8-1.orig/src/GridText.c       Wed Oct 14 07:23:56 1998
--- lynx2-8-1/src/GridText.c    Tue Nov 24 04:13:43 1998
***************
*** 61,66 ****
--- 61,77 ----
        for (j=0;j<CACHEW;j++)
            cached_styles[i][j]=s_a;
  }
+ #endif
+ #ifdef USE_COLOR_STYLE
+ PRIVATE void LynxResetScreenCache NOARGS
+ {
+     int i,j;
+ 
+     for (i=1; (i<CACHEH && i <= display_lines); i++) {
+       for (j=0;j<CACHEW;j++)
+           cached_styles[i][j]=0;
+     }
+ }
  #endif /* USE_COLOR_STYLE */
  
  struct _HTStream {                    /* only know it as object */
***************
*** 1135,1140 ****
--- 1146,1155 ----
        clear();
      }
  
+ #ifdef USE_COLOR_STYLE
+     LynxResetScreenCache();
+ #endif
+ 
      text->top_of_screen = line_number;
      display_title(text);  /* will move cursor to top of screen */
      display_flag=TRUE;
***************
*** 3248,3254 ****
       *  Fix up the anchor structure values and
       *  create the hightext strings. - FM
       */
!     HText_trimHightext(text, FALSE);
  }
  
  
--- 3263,3269 ----
       *  Fix up the anchor structure values and
       *  create the hightext strings. - FM
       */
!     HText_trimHightext(text, TRUE, FALSE);
  }
  
  
***************
*** 3260,3274 ****
  **  `Forms input' fields cannot be displayed properly without this function
  **  to be invoked (detected in display_partial mode).
  **
! **  (BOOLEAN value allow us to disable annoying repeated trace messages
  **  for display_partial mode).
  */
! PUBLIC void HText_trimHightext ARGS2(
        HText *,        text,
        BOOLEAN,        disable_trace)
  {
      int cur_line, cur_char, cur_shift;
      TextAnchor *anchor_ptr;
      HTLine *line_ptr;
      unsigned char ch;
  
--- 3275,3307 ----
  **  `Forms input' fields cannot be displayed properly without this function
  **  to be invoked (detected in display_partial mode).
  **
! **  (BOOLEAN disable_trace allow us to disable annoying repeated trace 
messages
  **  for display_partial mode).
+ **
+ **  If final is set, this is the final fixup; if not set, we don't have
+ **  to do everything because there should be another call later.
+ **
+ **  BEFORE this function has treated a TextAnchor, its line_pos and
+ **  extent fields are counting bytes in the HTLine data, including
+ **  invisible special attribute chars and counting UTF-8 multibyte
+ **  characters as multiple bytes.
+ **  AFTER the adjustment, the anchor line_pos (and hightext2offset
+ **  if applicable) fields indicate x positions in terms of displayed
+ **  character cells, and the extent field apparently is unimportant;
+ **  the anchor text has been copied to the hightext (and possibly
+ **  hightext2) fields (which should be NULL up to this point), with
+ **  special attribute chars removed.
+ **  This needs to be done so that display_page finds the anchors in the
+ **  form it expects when it sets the links[] elements.
  */
! PUBLIC void HText_trimHightext ARGS3(
        HText *,        text,
+       BOOLEAN,        final,
        BOOLEAN,        disable_trace)
  {
      int cur_line, cur_char, cur_shift;
      TextAnchor *anchor_ptr;
+     TextAnchor *prev_a = NULL;
      HTLine *line_ptr;
      unsigned char ch;
  
***************
*** 3286,3322 ****
      line_ptr = text->last_line->next;
      cur_char = line_ptr->size;
      cur_line = 0;
-     cur_shift = 0;
  
      /*
       *  Fix up the anchor structure values and
       *  create the hightext strings. - FM
       */
      for (anchor_ptr = text->first_anchor;
!        anchor_ptr; anchor_ptr=anchor_ptr->next) {
  re_parse:
        /*
         *  Find the right line.
         */
!       for (; anchor_ptr->start >= cur_char;
               line_ptr = line_ptr->next,
               cur_char += line_ptr->size+1,
               cur_line++) {
            ; /* null body */
        }
        if (anchor_ptr->start == cur_char) {
            anchor_ptr->line_pos = line_ptr->size;
        } else {
            anchor_ptr->line_pos = anchor_ptr->start -
                                   (cur_char - line_ptr->size);
        }
!       if (anchor_ptr->line_pos < 0)
            anchor_ptr->line_pos = 0;
! 
        if (!disable_trace)
!       CTRACE(tfp, "Gridtext: Anchor found on line:%d col:%d\n",
!                           cur_line, anchor_ptr->line_pos);
  
        /*
         *  Strip off any spaces or SpecialAttrChars at the beginning,
         *  if they exist, but only on HYPERTEXT_ANCHORS.
--- 3319,3390 ----
      line_ptr = text->last_line->next;
      cur_char = line_ptr->size;
      cur_line = 0;
  
      /*
       *  Fix up the anchor structure values and
       *  create the hightext strings. - FM
       */
      for (anchor_ptr = text->first_anchor;
!        anchor_ptr;
!        prev_a = anchor_ptr, anchor_ptr=anchor_ptr->next) {
  re_parse:
        /*
         *  Find the right line.
         */
!       for (; anchor_ptr->start > cur_char;
               line_ptr = line_ptr->next,
               cur_char += line_ptr->size+1,
               cur_line++) {
            ; /* null body */
        }
+ 
+       if (!final) {
+           /*
+            *  If this is not the final call, stop when we have reached
+            *  the last line, or the very end of preceding line. 
+            *  The last line is probably still not finished. - kw
+            */
+           if (cur_line >= text->Lines)
+               break;
+           if (anchor_ptr->start >= text->chars - 1)
+               break;
+           /*
+            *  Also skip this anchor if it looks like HText_endAnchor
+            *  is not yet done with it. - kw
+            */
+           if (!anchor_ptr->extent && anchor_ptr->number &&
+               (anchor_ptr->link_type & HYPERTEXT_ANCHOR) &&
+               !anchor_ptr->show_anchor &&
+               anchor_ptr->number == text->last_anchor_number)
+               continue;
+       }
+               
+       /*
+        *  If hightext has already been set, then we must have already
+        *  done the trimming & adjusting for this anchor, so avoid
+        *  doing it a second time. - kw
+        */
+       if (anchor_ptr->hightext)
+           continue;
+ 
        if (anchor_ptr->start == cur_char) {
            anchor_ptr->line_pos = line_ptr->size;
        } else {
            anchor_ptr->line_pos = anchor_ptr->start -
                                   (cur_char - line_ptr->size);
        }
!       if (anchor_ptr->line_pos < 0) {
!           anchor_ptr->start -= anchor_ptr->line_pos;
            anchor_ptr->line_pos = 0;
!           anchor_ptr->line_num = cur_line;
!       }
        if (!disable_trace)
!       CTRACE(tfp,
!              "Gridtext: Anchor found on line:%d col:%d [%d] ext:%d\n",
!              cur_line, anchor_ptr->line_pos,
!              anchor_ptr->number, anchor_ptr->extent);
  
+       cur_shift = 0;
        /*
         *  Strip off any spaces or SpecialAttrChars at the beginning,
         *  if they exist, but only on HYPERTEXT_ANCHORS.
***************
*** 3334,3339 ****
--- 3402,3408 ----
        if (anchor_ptr->extent < 0) {
            anchor_ptr->extent = 0;
        }
+       anchor_ptr->start += cur_shift;
  
        if (!disable_trace)
        CTRACE(tfp, "anchor text: '%s'\n",
***************
*** 3341,3355 ****
        /*
         *  If the link begins with an end of line and we have more
         *  lines, then start the highlighting on the next line. - FM
!        */
!       if ((unsigned)anchor_ptr->line_pos >= strlen(line_ptr->data) &&
!           cur_line < text->Lines) {
!           anchor_ptr->start += (cur_shift + 1);
!           cur_shift = 0;
!           CTRACE(tfp, "found anchor at end of line\n");
!           goto re_parse;
        }
-       cur_shift = 0;
  
        /*
         *  Copy the link name into the data structure.
--- 3410,3431 ----
        /*
         *  If the link begins with an end of line and we have more
         *  lines, then start the highlighting on the next line. - FM
!        *  But if an empty anchor is at the end of line and empty,
!        *  keep it where it is, unless the previous anchor in the list
!        *  (if any) already starts later. - kw
!        */
!       if ((unsigned)anchor_ptr->line_pos >= strlen(line_ptr->data)) {
!           if (cur_line < text->Lines &&
!               (anchor_ptr->extent ||
!                anchor_ptr->line_pos != (int)line_ptr->size ||
!                (prev_a && prev_a->start > anchor_ptr->start))) {
!               anchor_ptr->start++;
!               CTRACE(tfp, "found anchor at end of line\n");
!               goto re_parse;
!           } else {
!               CTRACE(tfp, "found anchor at end of line, leaving it there\n");
!           }
        }
  
        /*
         *  Copy the link name into the data structure.
***************
*** 3369,3374 ****
--- 3445,3457 ----
         */
        if ((unsigned)anchor_ptr->extent > strlen(anchor_ptr->hightext)) {
            HTLine *line_ptr2 = line_ptr->next;
+ 
+           if (!final) {
+               if (cur_line + 1 >= text->Lines) {
+                   FREE(anchor_ptr->hightext); /* bail out */
+                   break;
+               }
+           }
            /*
             *  Double check that we have a line pointer,
             *  and if so, copy into hightext2.
***************
*** 3414,3421 ****
        anchor_ptr->line_num  = cur_line;
  
        if (!disable_trace)
!       CTRACE(tfp, "GridText:     add link on line %d col %d in 
HText_trimHightext\n",
!                   cur_line, anchor_ptr->line_pos);
  
        /*
         *  If this is the last anchor, we're done!
--- 3497,3505 ----
        anchor_ptr->line_num  = cur_line;
  
        if (!disable_trace)
!       CTRACE(tfp, "GridText:     add link on line %d col %d [%d] %s\n",
!              cur_line, anchor_ptr->line_pos,
!              anchor_ptr->number, "in HText_trimHightext");
  
        /*
         *  If this is the last anchor, we're done!
***************
*** 4077,4083 ****
        **
        **  Side effect is reported from multiply call of HText_trimHightext.
        */
!       HText_trimHightext(HTMainText, TRUE);
      }
      detected_forms_input_partial = FALSE;
  #endif
--- 4161,4167 ----
        **
        **  Side effect is reported from multiply call of HText_trimHightext.
        */
!       HText_trimHightext(HTMainText, FALSE, TRUE);
      }
      detected_forms_input_partial = FALSE;
  #endif
***************
*** 6193,6198 ****
--- 6277,6290 ----
        new_ptr->name = NULL;
        new_ptr->cp_submit_value = NULL;
        new_ptr->next = NULL;
+       /*
+        *  Find first non-space again, convert_to_spaces above may have
+        *  changed the string. - kw
+        */
+       cp = value;
+       while (isspace((unsigned char)*cp) ||
+              IsSpecialAttrChar((unsigned char)*cp))
+           cp++;
        for (i = 0, j = 0; cp[i]; i++) {
            if (cp[i] == HT_NON_BREAK_SPACE ||
                cp[i] == HT_EM_SPACE) {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]