bug-groff
[Top][All Lists]
Advanced

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

[bug #66187] [troff] permit control over flushing of output file state


From: G. Branden Robinson
Subject: [bug #66187] [troff] permit control over flushing of output file state
Date: Wed, 11 Sep 2024 11:02:54 -0400 (EDT)

Update of bug #66187 (group groff):

                  Status:                    None => In Progress            
             Assigned to:                    None => gbranden               

    _______________________________________________________

Follow-up Comment #4:

This is one stubborn son of a gun.

I'm kicking the formatter pretty hard, and it's just not letting go of the
"DFr".  It's holding tight onto it and keeping the black page background.

This may be an unfortunate consequence of its design.  The font, fill color,
and stroke color all belong to _things_.  Glyphs or geometric objects.

I'll keep banging my head on this.  Failing that, the best alternative I have
is to make `BOXSTART` use the escape hatch and blast a 'DFr' command to the
output itself.  Really really gross.  Also there's the problem of retrieving
the RGB color channel values of the selected color so as to write them out. 
SUPER gross.

Here's the current state of my hackery for dark amusement.


diff --git a/contrib/sboxes/sboxes.tmac b/contrib/sboxes/sboxes.tmac
index 63c92636a..54636756e 100644
--- a/contrib/sboxes/sboxes.tmac
+++ b/contrib/sboxes/sboxes.tmac
@@ -75,7 +75,7 @@ .  de pdfbackground
 ..
 .
 .de BOXSTART
-.  fl
+.  nop \c \" Force the document to start.
 .  nr bx*stack \\n[bx*stack]+1u
 .  nr bx*shad 0
 .  nr bx*outl 0
@@ -85,6 +85,10 @@ .de BOXSTART
 .  while \\n[.$] \{\
 .    ie 'SHADED'\\$1' \{\
 .       nop \\M[\\$2]\c
+.\" We want to force a fill color setting command ("D F") onto the
+.\" output; the formatter cannot tell that we're using it, because it is
+.\" associated with no glyph or geometric object.
+'       fl 1
 .       nr bx*shad 1
 .       as bx*type "fill\"
 .       shift 2
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 0f97c52fa..bed40e027 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -923,12 +923,16 @@ void output_saved_vertical_space()
 
 static void flush_request()
 {
-  while (!tok.is_newline() && !tok.is_eof())
-    tok.next();
+  bool flush_fill_color = false;
+  int n = 0;
+  if (has_arg() && get_integer(&n))
+    flush_fill_color = (n > 0);
   if (want_break)
     curenv->do_break();
-  if (the_output != 0 /* nullptr */)
-    the_output->flush();
+  if (the_output != 0 /* nullptr */) {
+    debug("GBR: the_output->flush(%1)", flush_fill_color);
+    the_output->flush(flush_fill_color);
+  }
   tok.next();
 }
 
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 74b66672a..f60826017 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -738,6 +738,7 @@ public:
   real_output_file();
   ~real_output_file();
   void flush();
+  void flush(bool);
   void transparent_char(unsigned char);
   void print_line(hunits x, vunits y, node *n, vunits before, vunits after,
hunits width);
   void begin_page(int pageno, vunits page_length);
@@ -755,6 +756,8 @@ public:
   void really_transparent_char(unsigned char);
   void really_print_line(hunits x, vunits y, node *n, vunits, vunits, hunits
width);
   void really_begin_page(int pageno, vunits page_length);
+  // XXX: Should a flush of the fill color work even while output is
+  // suppressed?
 };
 
 class ascii_output_file : public real_output_file {
@@ -819,14 +822,14 @@ public:
   troff_output_file();
   ~troff_output_file();
   void flush();
+  void flush(bool);
   void trailer(vunits page_length);
   void put_char(charinfo *, tfont *, color *, color *);
   void put_char_width(charinfo *, tfont *, color *, color *, hunits,
hunits);
   void right(hunits);
   void down(vunits);
   void moveto(hunits, vunits);
-  void start_device_extension(color * /* fcol */,
-                             bool /* omit_command_prefix */ = false);
+  void start_device_extension(bool /* omit_command_prefix */);
   void start_device_extension();
   void write_device_extension_char(unsigned char c);
   void end_device_extension();
@@ -842,7 +845,7 @@ public:
   void determine_line_limits (char code, hvpair *point, int npoints);
   void check_charinfo(tfont *tf, charinfo *ci);
   void stroke_color(color *c);
-  void fill_color(color *c);
+  void fill_color(color * /* c */, bool /* forcing */ = false);
   int get_hpos() { return hpos; }
   int get_vpos() { return vpos; }
   void add_to_tag_list(string s);
@@ -885,16 +888,13 @@ inline void troff_output_file::put(unsigned int i)
   put_string(ui_to_a(i), fp);
 }
 
-void troff_output_file::start_device_extension(color *fcol,
-                                              bool omit_command_prefix)
+void troff_output_file::start_device_extension(bool omit_command_prefix)
 {
   flush_tbuf();
 #if 0
   set_font(tf);
   stroke_color(gcol);
-#endif
-  fill_color(fcol);
-#if 0
+  fill_color(current_fill_color);
   do_motion();
 #endif
   if (!omit_command_prefix)
@@ -1266,10 +1266,19 @@ void troff_output_file::set_font(tfont *tf)
 
 // fill_color calls 'flush_tbuf' and 'do_motion' if necessary.
 
-void troff_output_file::fill_color(color *col)
+void troff_output_file::fill_color(color *col, bool forcing)
 {
-  if ((0 /* nullptr */ == col) || current_fill_color == col)
+  debug("GBR: troff_output_file::fill_color(ptr, %1)", forcing);
+  if (0 /* nullptr */ == col)
     return;
+  debug("GBR: color is not nullptr");
+  if (current_fill_color == col) {
+    debug("GBR: ...redundantly");
+    if (forcing)
+      debug("GBR: ...but FORCING IT");
+    else
+      return;
+  }
   current_fill_color = col;
   if (!want_color_output)
     return;
@@ -1633,10 +1642,22 @@ troff_output_file::troff_output_file()
 
 void troff_output_file::flush()
 {
+  debug("GBR: troff_output_file::flush()");
   flush_tbuf();
   real_output_file::flush();
 }
 
+void troff_output_file::flush(bool force_fill_color)
+{
+  debug("GBR: troff_output_file::flush(%1)", force_fill_color);
+  flush_tbuf();
+  if (force_fill_color) {
+    fill_color(current_fill_color, true /* forcing */);
+    put("# GBR WAS HERE\n");
+  }
+  real_output_file::flush();
+}
+
 /* output_file */
 
 output_file *the_output = 0 /* nullptr */;
@@ -3970,7 +3991,7 @@ node *device_extension_node::copy()
 
 void device_extension_node::tprint_start(troff_output_file *out)
 {
-  out->start_device_extension(fcol, lacks_command_prefix);
+  out->start_device_extension(lacks_command_prefix);
 }
 
 void device_extension_node::tprint_char(troff_output_file *out,
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 078bf37bf..62bfa80a8 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -542,6 +542,7 @@ public:
 
 class device_extension_node : public node {
   macro mac;
+  // Should a device extension node _have_ the next 3 properties?  --GBR
   tfont *tf;
   color *gcol;
   color *fcol;
@@ -564,6 +565,8 @@ public:
   bool is_tag();
   int ends_sentence();
   tfont *get_tfont();
+  void mark_fcol_dirty();
+  // TODO: mark_gcol_dirty, mark_tf_dirty, mark_pos_dirty
 };
 
 class suppress_node : public node {
@@ -667,7 +670,8 @@ public:
   bool is_dying;
   virtual ~output_file();
   virtual void trailer(vunits);
-  virtual void flush() = 0;
+  void flush() {};
+  void flush(bool) {};
   virtual void transparent_char(unsigned char) = 0;
   virtual void print_line(hunits x, vunits y, node *n,
                          vunits before, vunits after,




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?66187>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature


reply via email to

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