/[groff]/groff/src/devices/grohtml/html-text.cpp
ViewVC logotype

Diff of /groff/src/devices/grohtml/html-text.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by wl, Fri Oct 15 05:08:35 2004 UTC revision 1.6 by wl, Wed Feb 16 14:07:24 2005 UTC
# Line 1  Line 1 
1  // -*- C++ -*-  // -*- C++ -*-
2  /* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.  /* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
3     * Free Software Foundation, Inc.
4   *   *
5   *  Gaius Mulley (gaius@glam.ac.uk) wrote html-text.cpp   *  Gaius Mulley (gaius@glam.ac.uk) wrote html-text.cpp
6   *   *
# Line 41  Foundation, 59 Temple Place - Suite 330, Line 42  Foundation, 59 Temple Place - Suite 330,
42  #include "html-text.h"  #include "html-text.h"
43    
44  #undef DEBUGGING  #undef DEBUGGING
45    // #define DEBUGGING
46    
47  html_text::html_text (simple_output *op) :  html_text::html_text (simple_output *op) :
48    stackptr(NULL), lastptr(NULL), out(op), space_emitted(TRUE),    stackptr(NULL), lastptr(NULL), out(op), space_emitted(TRUE),
49    current_indentation(-1), pageoffset(-1), linelength(-1),    current_indentation(-1), pageoffset(-1), linelength(-1),
50    blank_para(TRUE), start_space(TRUE)    blank_para(TRUE), start_space(FALSE)
51  {  {
52  }  }
53    
# Line 146  void html_text::end_tag (tag_definition Line 148  void html_text::end_tag (tag_definition
148    case I_TAG:      out->put_string("</i>"); break;    case I_TAG:      out->put_string("</i>"); break;
149    case B_TAG:      out->put_string("</b>"); break;    case B_TAG:      out->put_string("</b>"); break;
150    case P_TAG:      if (t->indent == NULL) {    case P_TAG:      if (t->indent == NULL) {
151                         if (t->really_issued)                       out->put_string("</p>");
                          out->put_string("</p>");  
152                     } else {                     } else {
153                       delete t->indent;                       delete t->indent;
154                       t->indent = NULL;                       t->indent = NULL;
155                         out->put_string("</p>");
156                     }                     }
157                     out->enable_newlines(FALSE);                     out->enable_newlines(FALSE);
158                     blank_para = TRUE; break;                     blank_para = TRUE; break;
# Line 158  void html_text::end_tag (tag_definition Line 160  void html_text::end_tag (tag_definition
160    case SUP_TAG:    out->put_string("</sup>"); break;    case SUP_TAG:    out->put_string("</sup>"); break;
161    case TT_TAG:     out->put_string("</tt>"); break;    case TT_TAG:     out->put_string("</tt>"); break;
162    case PRE_TAG:    out->put_string("</pre>"); out->enable_newlines(TRUE);    case PRE_TAG:    out->put_string("</pre>"); out->enable_newlines(TRUE);
163                     blank_para = TRUE; break;                     blank_para = TRUE;
164                       if (t->indent != NULL)
165                         delete t->indent;
166                       t->indent = NULL;
167                       break;
168    case SMALL_TAG:  out->put_string("</small>"); break;    case SMALL_TAG:  out->put_string("</small>"); break;
169    case BIG_TAG:    out->put_string("</big>"); break;    case BIG_TAG:    out->put_string("</big>"); break;
170    case COLOR_TAG:  out->put_string("</font>"); break;    case COLOR_TAG:  out->put_string("</font>"); break;
# Line 170  void html_text::end_tag (tag_definition Line 176  void html_text::end_tag (tag_definition
176    
177  /*  /*
178   *  issue_tag - writes out an html tag with argument.   *  issue_tag - writes out an html tag with argument.
179     *              space == 0 if no space is requested
180     *              space == 1 if a space is requested
181     *              space == 2 if tag should not have a space style
182   */   */
183    
184  void html_text::issue_tag (const char *tagname, const char *arg)  void html_text::issue_tag (const char *tagname, const char *arg,
185                               int space)
186  {  {
187    if ((arg == 0) || (strlen(arg) == 0)) {    if ((arg == 0) || (strlen(arg) == 0))
188      out->put_string(tagname);      out->put_string(tagname);
189      out->put_string(">");    else {
   } else {  
190      out->put_string(tagname);      out->put_string(tagname);
191      out->put_string(" ");      out->put_string(" ");
192      out->put_string(arg);      out->put_string(arg);
     out->put_string(">");  
193    }    }
194      if (space == TRUE) {
195        out->put_string(" style=\"margin-top: ");
196        out->put_string(STYLE_VERTICAL_SPACE);
197        out->put_string("\"");
198      }
199      if (space == TRUE || space == FALSE)
200        out->put_string(" valign=\"top\"");
201      out->put_string(">");
202  }  }
203    
204  /*  /*
# Line 221  void html_text::start_tag (tag_definitio Line 237  void html_text::start_tag (tag_definitio
237  #if defined(DEBUGGING)  #if defined(DEBUGGING)
238                       out->simple_comment("INDENTATION");                       out->simple_comment("INDENTATION");
239  #endif  #endif
240                       t->indent->begin(FALSE);                       out->put_string("\n<p");
241                       t->really_issued = FALSE;                       t->indent->begin(start_space);
242                     } else if (start_space) {                       issue_tag("", (char *)t->arg1);
243                       } else {
244                       out->nl();                       out->nl();
245                       issue_tag("\n<p", (char *)t->arg1);                       issue_tag("\n<p", (char *)t->arg1, start_space);
246                       t->really_issued = TRUE;                     }
                    } else  
                      t->really_issued = FALSE;  
247    
248                     out->enable_newlines(TRUE); break;                     out->enable_newlines(TRUE); break;
249    case SUB_TAG:    issue_tag("<sub", (char *)t->arg1); break;    case SUB_TAG:    issue_tag("<sub", (char *)t->arg1); break;
250    case SUP_TAG:    issue_tag("<sup", (char *)t->arg1); break;    case SUP_TAG:    issue_tag("<sup", (char *)t->arg1); break;
251    case TT_TAG:     issue_tag("<tt", (char *)t->arg1); break;    case TT_TAG:     issue_tag("<tt", (char *)t->arg1); break;
252    case PRE_TAG:    if (t->indent != NULL) {    case PRE_TAG:    out->enable_newlines(TRUE);
253                       out->nl();                     out->nl(); out->put_string("<pre");
254  #if defined(DEBUGGING)                     if (t->indent == NULL)
255                       out->simple_comment("INDENTATION");                       issue_tag("", (char *)t->arg1, start_space);
256  #endif                     else {
257                       t->indent->begin(FALSE);                       t->indent->begin(start_space);
258                     }                       issue_tag("", (char *)t->arg1);
259                     out->enable_newlines(TRUE);                     }
                    out->nl(); issue_tag("<pre", (char *)t->arg1);  
260                     out->enable_newlines(FALSE); break;                     out->enable_newlines(FALSE); break;
261    case SMALL_TAG:  issue_tag("<small", (char *)t->arg1); break;    case SMALL_TAG:  issue_tag("<small", (char *)t->arg1); break;
262    case BIG_TAG:    issue_tag("<big", (char *)t->arg1); break;    case BIG_TAG:    issue_tag("<big", (char *)t->arg1); break;
# Line 273  void html_text::flush_text (void) Line 287  void html_text::flush_text (void)
287      free(p);      free(p);
288    }    }
289    lastptr = NULL;    lastptr = NULL;
   start_space = TRUE;  
290  }  }
291    
292  /*  /*
# Line 367  void html_text::push_para (HTML_TAG t, v Line 380  void html_text::push_para (HTML_TAG t, v
380    p->arg1         = arg;    p->arg1         = arg;
381    p->text_emitted = FALSE;    p->text_emitted = FALSE;
382    p->indent       = in;    p->indent       = in;
   p->really_issued= FALSE;  
383    
384    if (t == PRE_TAG && is_present(PRE_TAG))    if (t == PRE_TAG && is_present(PRE_TAG))
385      fatal("cannot have multiple PRE_TAGs");      fatal("cannot have multiple PRE_TAGs");
# Line 389  void html_text::push_para (color *c) Line 401  void html_text::push_para (color *c)
401    p->col          = *c;    p->col          = *c;
402    p->text_emitted = FALSE;    p->text_emitted = FALSE;
403    p->indent       = NULL;    p->indent       = NULL;
   p->really_issued= FALSE;  
404    
405    do_push(p);    do_push(p);
406  }  }
# Line 633  void html_text::check_emit_text (tag_def Line 644  void html_text::check_emit_text (tag_def
644  void html_text::do_emittext (const char *s, int length)  void html_text::do_emittext (const char *s, int length)
645  {  {
646    if ((! is_present(P_TAG)) && (! is_present(PRE_TAG)))    if ((! is_present(P_TAG)) && (! is_present(PRE_TAG)))
647      do_para("");      do_para("", FALSE);
648    
649    if (is_present(BREAK_TAG)) {    if (is_present(BREAK_TAG)) {
650      int text = remove_break();      int text = remove_break();
# Line 656  void html_text::do_emittext (const char Line 667  void html_text::do_emittext (const char
667   *  do_para - starts a new paragraph   *  do_para - starts a new paragraph
668   */   */
669    
670  void html_text::do_para (const char *arg, html_indent *in)  void html_text::do_para (const char *arg, html_indent *in, int space)
671  {  {
672    if (! is_present(P_TAG)) {    if (! is_present(P_TAG)) {
673      if (is_present(PRE_TAG)) {      if (is_present(PRE_TAG)) {
# Line 670  void html_text::do_para (const char *arg Line 681  void html_text::do_para (const char *arg
681      }      }
682      remove_sub_sup();      remove_sub_sup();
683      push_para(P_TAG, (void *)arg, in);      push_para(P_TAG, (void *)arg, in);
684        start_space = space;
685    }    }
686  }  }
687    
688  void html_text::do_para (const char *arg)  void html_text::do_para (const char *arg, int space)
689  {  {
690    do_para(arg, NULL);    do_para(arg, NULL, space);
691  }  }
692    
693  void html_text::do_para (simple_output *op, const char *arg1,  void html_text::do_para (simple_output *op, const char *arg1,
694                           int indentation_value, int page_offset,                           int indentation_value, int page_offset,
695                           int line_length)                           int line_length, int space)
696  {  {
697    html_indent *ind;    html_indent *ind;
698    
# Line 688  void html_text::do_para (simple_output * Line 700  void html_text::do_para (simple_output *
700      ind = NULL;      ind = NULL;
701    else    else
702      ind = new html_indent(op, indentation_value, page_offset, line_length);      ind = new html_indent(op, indentation_value, page_offset, line_length);
703    do_para(arg1, ind);    do_para(arg1, ind, space);
704  }  }
705    
706  /*  /*
# Line 723  html_indent *html_text::remove_indent (H Line 735  html_indent *html_text::remove_indent (H
735    
736  /*  /*
737   *  remove_para_space - removes the leading space to a paragraph   *  remove_para_space - removes the leading space to a paragraph
738   *                      (effectively this trims off the <p> and </p>   *                      (effectively this trims off a leading `.sp' tag).
  *                      tags.  
739   */   */
740    
741  void html_text::remove_para_space (void)  void html_text::remove_para_space (void)
# Line 739  void html_text::remove_para_space (void) Line 750  void html_text::remove_para_space (void)
750  void html_text::do_space (void)  void html_text::do_space (void)
751  {  {
752    if (is_in_pre()) {    if (is_in_pre()) {
753  #if 0      do_emittext("", 0);
754      if (blank_para)      out->force_nl();
755        start_space = TRUE;      space_emitted = TRUE;
     else {  
 #endif  
       do_emittext("", 0);  
       out->force_nl();  
       space_emitted = TRUE;  
 #if 0  
     }  
 #endif  
756    } else {    } else {
757      html_indent *i = remove_indent(P_TAG);      html_indent *i = remove_indent(P_TAG);
758    
759      do_para(done_para(), i);      do_para(done_para(), i, TRUE);
760      space_emitted = TRUE;      space_emitted = TRUE;
     start_space = TRUE;  
761    }    }
762  }  }
763    
# Line 765  void html_text::do_space (void) Line 767  void html_text::do_space (void)
767    
768  void html_text::do_break (void)  void html_text::do_break (void)
769  {  {
770    if (! is_present(PRE_TAG)) {    if (! is_present(PRE_TAG))
771      if (emitted_text()) {      if (emitted_text())
772        if (! is_present(BREAK_TAG)) {        if (! is_present(BREAK_TAG))
773          push_para(BREAK_TAG);          push_para(BREAK_TAG);
774        }  
     }  
   }  
775    space_emitted = TRUE;    space_emitted = TRUE;
776  }  }
777    
# Line 797  int html_text::emitted_text (void) Line 797  int html_text::emitted_text (void)
797  }  }
798    
799  /*  /*
800   *  ever_emitted_text - returns TRUE if we have ever emitted text in this paragraph.   *  ever_emitted_text - returns TRUE if we have ever emitted text in this
801     *                      paragraph.
802   */   */
803    
804  int html_text::ever_emitted_text (void)  int html_text::ever_emitted_text (void)
# Line 815  int html_text::starts_with_space (void) Line 816  int html_text::starts_with_space (void)
816  }  }
817    
818  /*  /*
819     *  retrieve_para_space - returns TRUE, if the paragraph starts with
820     *                        a space and text has not yet been emitted.
821     *                        If TRUE is returned, then the, start_space,
822     *                        variable is set to FALSE.
823     */
824    
825    int html_text::retrieve_para_space (void)
826    {
827      if (start_space && blank_para) {
828        start_space = FALSE;
829        return TRUE;
830      }
831      else
832        return FALSE;
833    }
834    
835    /*
836   *  emit_space - writes a space providing that text was written beforehand.   *  emit_space - writes a space providing that text was written beforehand.
837   */   */
838    
# Line 951  void html_text::remove_para_align (void) Line 969  void html_text::remove_para_align (void)
969        if (p->type == P_TAG && p->arg1 != NULL) {        if (p->type == P_TAG && p->arg1 != NULL) {
970          html_indent *i = remove_indent(P_TAG);          html_indent *i = remove_indent(P_TAG);
971          done_para();          done_para();
972          do_para("", i);          do_para("", i, space_emitted);
973          return;          return;
974        }        }
975        p = p->next;        p = p->next;
# Line 1021  void html_text::do_sub (void) Line 1039  void html_text::do_sub (void)
1039  {  {
1040    push_para(SUB_TAG);    push_para(SUB_TAG);
1041  }  }
   

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26