Re: Bold and Formatting within a Table

Subject: Re: Bold and Formatting within a Table
From: Norman Walsh <norm@xxxxxxxxxxxxx>
Date: Fri, 20 Mar 1998 07:23:55 -0500
/ "Jordi Mulet" <jmulet@xxxxxxxxxx> was heard to say:
| We have modified our custom layer for formatting cells with different sizes
| and colors with the new rules you have sent yesterday.
| The new style-sheet can output markup as
|     <entry><para>some info<emphasis>Here the
| italics</emphasis></para><entry>
| correctly with the text inside emphasis in bold and italics.
| 
| bu if we markup with pi instructions as :
| <para><?size 18pt><?color red-color>some information</para>
| the output doesnt work correctly.

My code is below.  A few things had to be changed.  First, the
(current-node) when a table-cell is being processed is actually
the TBODY, so the entry had to be passed to the $pi-* functions.
Second, since the PIs are embedded in the PARAs in ENTRYs, I had
to add the PI tests to the PARA as well.  You'll have to do the
same thing for other block markup that can appear in an ENTRY if
it has to have color PIs.  Alternatively, you could make the
pi-value function search the descendants of the entry, but then
you might get unexpected results if you wanted to have different
parts be different colors.  And pi-value could have really
unexpected results if you called it from somewhere else (like
chapter or book).

<!DOCTYPE style-sheet PUBLIC "-//nwalsh//DTD Annotated DSSSL Style Sheet V1.0//EN" [
<!ENTITY plain.dsl SYSTEM "/share/dsssl/docbook/print/plain.dsl" CDATA DSSSL>
]>

<style-sheet>
<title>DocBook V3.0 Document (Plain)</title>
<doctype pubid="-//Davenport//DTD DocBook V3.0//EN">
<backend name="rtf" default="true" fragid="print">
<backend name="sgml" supported="no">

<style-specification id="print" use="plain">
<style-specification-body>

(define colorspace (color-space 
		    "ISO/IEC 10179:1996//Color-Space Family::Device RGB"))
(define color-red   (color colorspace 1 0 0))
(define color-green (color colorspace 0 1 0))
(define color-blue  (color colorspace 0 0 1))
(define color-black (color colorspace 0 0 0))

;; Returns the value of the (?piname value) PI (if one exists)
;; as a child of component, otherwise returns #f
;;
(define (pi-value component piname)
  (let loop ((nl (children component)))
    (if (node-list-empty? nl)
	#f
	(if (and (equal? (node-property 'class-name (node-list-first nl)) 'pi)
		 (> (string-length (node-property 'system-data 
						  (node-list-first nl))) 
		    (string-length piname))
		 (equal? piname
			 (substring (node-property 'system-data 
						   (node-list-first nl)) 
				    0 (string-length piname))))
	    (substring (node-property 'system-data (node-list-first nl)) 
		       (+ (string-length piname) 1)
		       (string-length 
			(node-property 'system-data (node-list-first nl))))
	    (loop (node-list-rest nl))))))

(define (inherited-pi-value component piname)
  (let loop ((value #f) (nd component))
    (if (or value (node-list-empty? nd))
	value
	(loop (pi-value nd piname) (parent nd)))))

(define ($pi-font-size$ entry)
  (let ((fontsize (pi-value entry "size")))
    (if fontsize
	(measurement-to-length fontsize)
	#f)))

(define ($pi-font-color$ entry)
  (let* ((picolor (pi-value entry "color"))
	 (color   (case picolor
		    (("red-color") color-red)
		    (("blue-color") color-blue)
		    (("green-color") color-green)
		    (else #f))))
    color))

(element (ENTRY PARA)
  (let ((color ($pi-font-color$ (current-node)))
	(size  ($pi-font-size$ (current-node))))
    (make paragraph
      quadding: (inherited-quadding)
      color: (if color color (inherited-color))
      font-size: (if size size (inherited-font-size))
      (process-children))))

(define ($process-cell-contents$ entry colnum)
  (let ((font-name (if (have-ancestor? "THEAD" entry)
		       %title-font-family%
		       %body-font-family%))
	(weight    (if (have-ancestor? "THEAD" entry)
		       'bold
		       'medium))
	(align     (cell-align entry colnum))
	(fontsize  ($pi-font-size$ entry))
	(fontcolor ($pi-font-color$ entry)))
    (make sequence
      font-family-name: font-name
      font-weight: weight
      font-size: (if fontsize fontsize (inherited-font-size))
      color: (if fontcolor fontcolor (inherited-color))
      quadding: align
      (process-node-list (children entry)))))

</style-specification-body>
</style-specification>

<external-specification id="plain" document="plain.dsl">

</style-sheet>

And here's my test case:

<!doctype chapter public "-//Davenport//DTD DocBook V3.0//EN">
<chapter><title>colored text</title>
<informaltable>
<tgroup cols=2>
<tbody>
<row>
<entry><para>normal</para></entry>
<entry><para><?size 18pt><?color red-color>some information</para></entry>
</row>
<row>
<entry><para>normal</para></entry>
<entry><?size 18pt><?color red-color><para>some information</para></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</chapter>


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread
  • Bold and Formatting within a Table
    • Chuck Darney - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id JAA19672Thu, 19 Mar 1998 09:54:32 -0500 (EST)
      • Norman Walsh - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id KAA20817Thu, 19 Mar 1998 10:28:45 -0500 (EST)
      • <Possible follow-ups>
      • Jordi Mulet - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id DAA08750Fri, 20 Mar 1998 03:42:04 -0500 (EST)
        • Norman Walsh - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id HAA10429Fri, 20 Mar 1998 07:26:19 -0500 (EST) <=
      • Jordi Mulet - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id LAA12801Fri, 20 Mar 1998 11:26:41 -0500 (EST)