Re: [page] margin box header/footer

Grant, Melinda wrote:
> 
> Fantasai said:
>> Grant, Melinda wrote:
>>> I think we should add an explicit margin declaration to the rules 
>>> establishing test header and footer.
>>>     a) for consistent test output
>>>     b) some UA's may default to 0 margins.
>> What would you recommend as the default margin?
> 
> 7% should work pretty well across sizes...

Proposed patch attached: it should
   * use start/end <p> paragraphs with test ID if there are margin box rules
   * use the @page headers and footers with test ID if there are no margin box rules
       - use a 7% margin if the test contains no @page rule
       - not specify any margin declaration if the test does contain an @page rule

Let me know if this is ok.

~fantasai
Index: lib/format/xhtml1print.pm
===================================================================
RCS file: /sources/public/CSS/CSS2.1-test-suite/lib/format/xhtml1print.pm,v
retrieving revision 1.3
diff -u -r1.3 xhtml1print.pm
--- lib/format/xhtml1print.pm	19 Apr 2007 22:42:36 -0000	1.3
+++ lib/format/xhtml1print.pm	20 Nov 2007 03:55:26 -0000
@@ -8,11 +8,15 @@
     @page { counter-increment: page;
             font: italic 8pt sans-serif;
             color: gray;
+            %%MARGIN%%
             @top-left { content: "CSS 2.1 Conformance Test Suite"; }
             @top-right { content: "Test %%TESTID%%"; }
             @bottom-right { content: counter(page); }
           }
 ^;
+my $printMargin = 'margin: 7%;';
+my $printHTMLstart = '<p style="font: italic 8pt sans-serif; color: gray;">Start of CSS2.1 Conformance Test %%TESTID%%.</p>';
+my $printHTMLend = '<p style="font: italic 8pt sans-serif; color: gray;">End of CSS2.1 Conformance Test %%TESTID%%.</p>';
 
 sub output {
     my($tree,$id) = @_;
@@ -20,8 +24,29 @@
     $output .= "\n";
     $output .= xml::treeAsXML($tree);
 
-    $_ = $printCSS;
-    s/%%TESTID%%/$id/g;
-    $output =~ s/<\/title>/<\/title>\n  <style type="text\/css">$_  <\/style>/;
+    if ($output =~ /\@page\s*{[^}]*\@/) {
+      # Don't use headers and footers when page tests margin boxes
+      my $start = $printHTMLstart;
+      $start =~ s/%%TESTID%%/$id/g;
+      my $end = $printHTMLend;
+      $end =~ s/%%TESTID%%/$id/g;
+
+      $output =~ s/(<body[^>]*>)/$1\n$start/;
+      $output =~ s/(<\/body[^>]*>)/$end\n$1/;
+    }
+    else {
+      $_ = $printCSS;
+      s/%%TESTID%%/$id/g;
+
+      if ($output =~ /\@page/) {
+        s/%%MARGIN%%//; # skip margin rule when @page statement exists
+      }
+      else {
+        s/%%MARGIN%%/$printMargin/;
+      }
+
+      $output =~ s/<\/title>/<\/title>\n  <style type="text\/css">$_  <\/style>/;
+    }
+
     return $output;
 }

Received on Tuesday, 20 November 2007 03:59:33 UTC