lynx-dev
[Top][All Lists]
Advanced

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

Re: lynx-dev GridText.c patch with new HText_trimHightext


From: Leonid Pauzner
Subject: Re: lynx-dev GridText.c patch with new HText_trimHightext
Date: Tue, 24 Nov 1998 22:42:59 +0300 (MSK)

24-Nov-98 05:00 Klaus Weide wrote:
> Here is a patch which hopefully removes problems with form field
> display during partial rendering.  Please test.

Thanks, it works!
I've just removed "disable_trace" flag because it is redundant now:
HText_trimHightext never trim the same anchor twice.
(I haven't removed `detected_forms_input_partial' yet,
but it now redundant also)
Resync against _dev.7_ included, for Tom.


> 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.

Wrong. You got a blinking hightext garbage line
on the top of the display if you do so.
I would also note that forms field looks differently
with/without highlighted text ("____" normally and "...." if no hightext),
we got such blinking without calls to HText_trimHightext before dispaly_page().


> * 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.


diff -u old/gridtext.c ./gridtext.c
--- old/gridtext.c      Tue Nov 24 01:21:48 1998
+++ ./gridtext.c        Tue Nov 24 22:09:44 1998
@@ -61,6 +61,17 @@
        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 */
@@ -1143,6 +1154,10 @@
        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;
@@ -3274,7 +3289,7 @@
      *  Fix up the anchor structure values and
      *  create the hightext strings. - FM
      */
-    HText_trimHightext(text, FALSE);
+    HText_trimHightext(text, TRUE);
 }


@@ -3286,25 +3301,37 @@
 **  `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).
+**  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 ARGS2(
        HText *,        text,
-       BOOLEAN,        disable_trace)
+       BOOLEAN,        final)
 {
     int cur_line, cur_char, cur_shift;
     TextAnchor *anchor_ptr;
+    TextAnchor *prev_a = NULL;
     HTLine *line_ptr;
     unsigned char ch;

     if (!text)
        return;

-    CTRACE(tfp,"Gridtext: Entering HText_trimHightext\n");
-
-    if (disable_trace)
-    CTRACE(tfp,"HText_trimHightext: trace disabled in display_partial mode\n");
+    CTRACE(tfp,"Gridtext: Entering HText_trimHightext %s\n",
+               final ? "(final)" : "(partial)");

     /*
      *  Get the first line.
@@ -3312,37 +3339,71 @@
     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) {
+        anchor_ptr;
+        prev_a = anchor_ptr, anchor_ptr=anchor_ptr->next) {
 re_parse:
        /*
         *  Find the right line.
         */
-       for (; anchor_ptr->start >= cur_char;
+       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)
+       if (anchor_ptr->line_pos < 0) {
+           anchor_ptr->start -= anchor_ptr->line_pos;
            anchor_ptr->line_pos = 0;
+           anchor_ptr->line_num = cur_line;
+       }
+       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);

-       if (!disable_trace)
-       CTRACE(tfp, "Gridtext: Anchor found on line:%d col:%d\n",
-                           cur_line, anchor_ptr->line_pos);
-
+       cur_shift = 0;
        /*
         *  Strip off any spaces or SpecialAttrChars at the beginning,
         *  if they exist, but only on HYPERTEXT_ANCHORS.
@@ -3360,22 +3421,29 @@
        if (anchor_ptr->extent < 0) {
            anchor_ptr->extent = 0;
        }
+       anchor_ptr->start += cur_shift;

-       if (!disable_trace)
        CTRACE(tfp, "anchor text: '%s'\n",
                                           line_ptr->data);
        /*
         *  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;
+        *  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");
+           }
        }
-       cur_shift = 0;

        /*
         *  Copy the link name into the data structure.
@@ -3395,6 +3463,13 @@
         */
        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.
@@ -3439,9 +3514,9 @@
        anchor_ptr->line_pos += line_ptr->offset;
        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);
+       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!
@@ -4101,11 +4176,11 @@
        **  So we start HText_trimHightext() to forget this side effect.
        **  This function was split-out from HText_endAppend().
        **  It may not be the best solution but it works. - LP
-       **  (TRUE =  to disable annoying repeated trace messages)
        **
-       **  Side effect is reported from multiply call of HText_trimHightext.
+       **  (FALSE =  indicate that we are in partial mode)
+       **  Multiply calls of HText_trimHightext works without problem now.
        */
-       HText_trimHightext(HTMainText, TRUE);
+       HText_trimHightext(HTMainText, FALSE);
     }
     detected_forms_input_partial = FALSE;
 #endif
@@ -6216,6 +6291,14 @@
        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) {
diff -u old/gridtext.h ./gridtext.h
--- old/gridtext.h      Wed Oct 14 05:23:56 1998
+++ ./gridtext.h        Tue Nov 24 21:05:18 1998
@@ -202,7 +202,7 @@
        InputFieldData *I));
 extern void HText_trimHightext PARAMS((
        HText *         text,
-       BOOLEAN         disable_trace));
+       BOOLEAN         final));
 extern void HText_SubmitForm PARAMS((
        FormInfo *      submit_item,
        document *      doc,



reply via email to

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