HTML problem reproduction

Shannon Weyrick <weyrick-UWl7u1r57vBWk0Htik3J/[email protected]> Sat, 14 May 2005 11:38:44 -0400
Newsgroups gmane.text.rlib.user
Message-ID <[email protected]>
Greets,

I worked on tracking the HTML problems down more. I found where the 
problem is, but couldn't muster the skill to eradicate it.

The first problem was the one I mentioned in the last email - if 
trim_links is turned on, it's not closing <span> tags for bgcolor in 
some cases. The fix I had for that is attached.

The next problem is related and again specific to trim_links and 
bgcolor. The problem appears to be in 
rlib_layout_find_common_properties_in_a_line(), which also gets my 
nomination for Longest Function name.

The second part of the function loops through extra_data looking for 
where to start and stop link flags. But if trim links is on there is a 
bgcolor for that Line then in some situations it gets out of sync and 
again ends up with mismatched <span> tags. This all happens around lines 
637-662 in layout.c

I've attached a sample php script and xml report file that demonstrates 
the problem in various ways (including a work around). Also it 
demonstrates the fact that trim_links only works if the link text is 
left aligned and doesn't work if it's center or right aligned.

Bob, regarding the new Doc Wiki - I think it's a great idea. I'd love to 
contribute but unfortunately I'm one of the one's in the dark about most 
of the functionality that's not documented in the current docs :)

Thanks,
Shannon
layout.c.patch (text/plain, 744 B)
--- rlib-1.3.4/libsrc/layout.c	2005-05-02 13:29:47.000000000 -0400
+++ rlib-1.3.4-weyrick/libsrc/layout.c	2005-05-14 11:29:16.344516759 -0400
@@ -278,7 +278,13 @@
 		OUTPUT(r)->end_boxurl(r, backwards);
 		if(OUTPUT(r)->trim_links) {
 			rlib_layout_output_extras_start(r, part, backwards, 0, 0, extra_data, TRUE);
-			rlib_layout_text_from_extra_data(r, backwards, 0, 0, extra_data, TEXT_RIGHT);		
+			rlib_layout_text_from_extra_data(r, backwards, 0, 0, extra_data, TEXT_RIGHT);
+	               	if(extra_data->running_bgcolor_status & STATUS_STOP)
+           	  	    	OUTPUT(r)->end_draw_cell_background(r);
+			if(extra_data->is_italics)
+				OUTPUT(r)->end_italics(r);
+			if(extra_data->is_bold)
+				OUTPUT(r)->end_bold(r);
 		}
 	}
trimBgColorProb.xml (text/xml, 8.1 KB)
<!DOCTYPE report >

<Part layout="'flow'" fontSize="14" orientation="landscape">


  <pr>
    <pd width="98">


      <Report fontSize="9" orientation="landscape">

        <ReportHeader>
            <Output>
                <Line>
                  <literal>This report has no links so it works</literal>
                </Line>
            </Output>
        </ReportHeader>

        <Detail>

          <FieldHeaders>
            <Output>
              <Line  bgcolor="'0xe5e5e5'">
                <literal width="10" col="1">ID</literal>
                <literal width="1"/>
                <literal width="15" col="2">First Name</literal>
                <literal width="1"/>
                <literal width="15" col="3">Last Name</literal>
                <literal width="1"/>
                <literal width="9" col="4" align="left">Ethnicity</literal>
                <literal width="1"/>
              </Line>
            </Output>
          </FieldHeaders>

          <FieldDetails>
            <Output>
              <Line bgcolor="iif(r.detailcnt%2,'0xe5e5e5','white')">
                <literal width="1"/>
                <field value="id" width="10" align="left" col="1" />
                <literal width="1"/>
                <field value="firstName" width="15" align="left" col="2" />
                <literal width="1"/>
                <field value="lastName" width="15" align="left" col="3" />
                <literal width="1"/>
                <field value="color" width="9" align="left" col="4" />
              </Line>
            </Output>
          </FieldDetails>
        </Detail>

      </Report>

    </pd>
  </pr>

  <pr>
    <pd width="98">


      <Report fontSize="9" orientation="landscape">

        <ReportHeader>
            <Output>
                <Line>
                  <literal>This report starts with a column that is linked and trim links is on so bg colors are broken</literal>
                </Line>
            </Output>
        </ReportHeader>

        <Detail>

          <FieldHeaders>
            <Output>
              <Line  bgcolor="'0xe5e5e5'">
                <literal width="10" col="1">ID</literal>
                <literal width="1"/>
                <literal width="15" col="2">First Name</literal>
                <literal width="1"/>
                <literal width="15" col="3">Last Name</literal>
                <literal width="1"/>
                <literal width="9" col="4" align="left">Ethnicity</literal>
                <literal width="1"/>
              </Line>
            </Output>
          </FieldHeaders>

          <FieldDetails>
            <Output>
              <Line bgcolor="iif(r.detailcnt%2,'0xe5e5e5','white')">
                <field value="id" width="10" align="left" col="1" link="'foo'"/>
                <literal width="1"/>
                <field value="firstName" width="15" align="left" col="2" />
                <literal width="1"/>
                <field value="lastName" width="15" align="left" col="3"  link="'foo'"/>
                <literal width="1"/>
                <field value="color" width="9" align="left" col="4" />
              </Line>
            </Output>
          </FieldDetails>
        </Detail>

      </Report>

    </pd>
  </pr>

  <pr>
    <pd width="98">


      <Report fontSize="9" orientation="landscape">

        <ReportHeader>
            <Output>
                <Line>
                  <literal>This is the same but starts with a literl with no link so it works</literal>
                </Line>
            </Output>
        </ReportHeader>

        <Detail>

          <FieldHeaders>
            <Output>
              <Line  bgcolor="'0xe5e5e5'">
                <literal width="1"/>
                <literal width="10" col="1">ID</literal>
                <literal width="1"/>
                <literal width="15" col="2">First Name</literal>
                <literal width="1"/>
                <literal width="15" col="3">Last Name</literal>
                <literal width="1"/>
                <literal width="9" col="4" align="left">Ethnicity</literal>
                <literal width="1"/>
              </Line>
            </Output>
          </FieldHeaders>

          <FieldDetails>
            <Output>
              <Line bgcolor="iif(r.detailcnt%2,'0xe5e5e5','white')">
                <!-- this makes it work, sometimes -->
                <literal width="1"/>
                <field value="id" width="10" align="left" col="1" link="'foo'"/>
                <literal width="1"/>
                <field value="firstName" width="15" align="left" col="2" />
                <literal width="1"/>
                <field value="lastName" width="15" align="left" col="3"  link="'foo'"/>
                <literal width="1"/>
                <field value="color" width="9" align="left" col="4" />
              </Line>
            </Output>
          </FieldDetails>
        </Detail>

      </Report>

    </pd>
  </pr>

  <pr>
    <pd width="98">


      <Report fontSize="9" orientation="landscape">

        <ReportHeader>
            <Output>
                <Line>
                  <literal>This has header fields linked which breaks bg color up here</literal>
                </Line>
            </Output>
        </ReportHeader>

        <Detail>

          <FieldHeaders>
            <Output>
              <Line  bgcolor="'0xe5e5e5'">
                <literal width="10" col="1" link="'foo'">ID</literal>
                <literal width="1"/>
                <literal width="15" col="2">First Name</literal>
                <literal width="1"/>
                <literal width="15" col="3">Last Name</literal>
                <literal width="1"/>
                <literal width="9" col="4" align="left">Ethnicity</literal>
                <literal width="1"/>
              </Line>
            </Output>
          </FieldHeaders>

          <FieldDetails>
            <Output>
              <Line bgcolor="iif(r.detailcnt%2,'0xe5e5e5','white')">
                <field value="id" width="10" align="left" col="1" link="'foo'"/>
                <literal width="1"/>
                <field value="firstName" width="15" align="left" col="2" />
                <literal width="1"/>
                <field value="lastName" width="15" align="left" col="3"  link="'foo'"/>
                <literal width="1"/>
                <field value="color" width="9" align="left" col="4" />
              </Line>
            </Output>
          </FieldDetails>
        </Detail>

      </Report>

    </pd>
  </pr>
                                                                          
  <pr>
    <pd width="98">


      <Report fontSize="9" orientation="landscape">

        <ReportHeader>
            <Output>
                <Line>
                  <literal>This shows the problem of trim links and center and right aligned items</literal>
                </Line>
            </Output>
        </ReportHeader>

        <Detail>

          <FieldHeaders>
            <Output>
              <Line  bgcolor="'0xe5e5e5'">
                <literal width="10" col="1" link="'foo'" align="right">ID</literal>
                <literal width="1"/>
                <literal width="15" col="2">First Name</literal>
                <literal width="1"/>
                <literal width="15" col="3">Last Name</literal>
                <literal width="1"/>
                <literal width="9" col="4" align="left">Ethnicity</literal>
                <literal width="1"/>
              </Line>
            </Output>
          </FieldHeaders>

          <FieldDetails>
            <Output>
              <Line bgcolor="iif(r.detailcnt%2,'0xe5e5e5','white')">
                <field value="id" width="10" col="1" link="'foo'" align="center"/>
                <literal width="1"/>
                <field value="firstName" width="15" align="left" col="2" />
                <literal width="1"/>
                <field value="lastName" width="15" align="center" col="3"  link="'foo'"/>
                <literal width="1"/>
                <field value="color" width="9" align="left" col="4" />
              </Line>
            </Output>
          </FieldDetails>
        </Detail>

      </Report>

    </pd>
  </pr>
                                                                                
 
</Part>
adriver.php (application/x-httpd-php, 948 B)
<? dl ("rlib.so");

	$data[0][0] = "firstName";
	$data[0][1] = "lastName";
	$data[0][2] = "color";
	$data[0][3] = "id";

	$data[1][0] = "Bob";
	$data[1][1] = "Doan";
	$data[1][2] = "blue";
	$data[1][3] = "1";

	$data[2][0] = "Eric";
	$data[2][1] = "Eburuschkin";
	$data[2][2] = "orange";
	$data[2][3] = "1";

	$data[3][0] = "Mike";
	$data[3][1] = "Roth";
	$data[3][2] = "yellow";
	$data[3][3] = "2";

	$data[4][0] = "Bob";
	$data[4][1] = "Kratz";
	$data[4][2] = "pink";
	$data[4][3] = "2";

	$data[5][0] = "Steve";
	$data[5][1] = "Tilden";
	$data[5][2] = "purple";
	$data[5][3] = "2";

	$rlib =	rlib_init();
	rlib_version();
	rlib_add_datasource_array($rlib, "local_array");
	rlib_add_query_as($rlib, "local_array", "data", "data");
	rlib_add_report($rlib, "report.xml");
    rlib_set_output_parameter($rlib, 'trim_links', '1');
    rlib_set_output_format_from_text($rlib, "html");
	rlib_execute($rlib);
	rlib_spool($rlib);
	rlib_free($rlib);
	
?>