]> git.lyx.org Git - features.git/blobdiff - lib/reLyX/RelyxTable.pm
Whitespace, only whitespace. Part II.
[features.git] / lib / reLyX / RelyxTable.pm
index 4b3aaaccc15c2eb9329b39a3d8b87abf202c627d..a77af824eb6adb6e73679f443157cb5a1e1e2458 100644 (file)
@@ -68,7 +68,7 @@ sub parse_cols {
     while (@group) {
 
        $tok = shift(@group);
-       # Each $tok will consist of /^[clr|]*[p*@]?$/
+       # Each $tok will consist of /^[clr|]*[mp*@]?$/
        # (Except first may have | and/or @ expressions before it)
        # p*@ will end the $tok since after it comes a group in braces
        # @ will be a TT::Token, everything else will be in TT::Text
@@ -86,15 +86,14 @@ sub parse_cols {
        @new_cols = ($description =~ /[clr]\|*/g);
        push @cols, @new_cols;
 
-       # parse a p or * or @ if necessary
+       # parse a 'p', an 'm', a '*' or a '@' as necessary
        # use exact_print in case there's weird stuff in the @ descriptions
        $description = substr($description,-1);
-#      if ($description eq 'p') {
        # The m and p descriptors have identical form.
-       if ($description =~ /^[mp]$/) {
+       if ($description eq 'p' || $description eq 'm') {
            $tok = shift(@group);
-           my $pdes = $description . $tok->exact_print; # "p{foo}"
-           push @cols, $pdes;
+           my $des = $description . $tok->exact_print; # 'p{foo}' or 'm{foo}'
+           push @cols, $des;
 
        } elsif ($description eq '@') {
            $tok = shift(@group);
@@ -123,30 +122,6 @@ sub parse_cols {
     return @cols;
 } # end sub parse_cols
 
-sub write_string {
-    my ($name, $s) = @_;
-    if (!$s) {
-       return '';
-    }
-    return ' ' . $name . '="' . $s . '"';
-}
-
-sub write_bool {
-    my ($name, $b) = @_;
-    if (!$b) {
-       return '';
-    }
-    write_string $name, "true";
-}
-
-sub write_int {
-    my ($name, $i) = @_;
-    if (!$i) {
-       return '';
-    }
-    write_string $name, $i;
-}
-
 ################################################################################
 # This package handles tables for reLyX
 
@@ -201,7 +176,7 @@ sub write_int {
        push @RelyxTable::table_array, $thistable;
 
 
-       # Now that it's blessed, put the 0th row into the table 
+       # Now that it's blessed, put the 0th row into the table
        $thistable->addrow;
 
        return $thistable;
@@ -309,60 +284,8 @@ sub write_int {
        }
     } # end sub done_reading
 
+# Subroutines to print out the table once it's created
     sub print_info {
-    # Subroutine to print out the table once it's created
-       &print_info_215(@_);
-    }
-
-    sub print_info_221 {
-    # Subroutine to print out the table in \lyxformat 221
-       my $thistable = shift;
-        my $to_print = '';
-        # header line
-       $to_print .= "\n<lyxtabular" .
-           RelyxTable::write_int("version", 3) .
-           RelyxTable::write_int("rows", $thistable->numrows) .
-           RelyxTable::write_int("columns", $thistable->numcols) .
-           ">\n";
-       # global longtable options
-       $to_print .= "<features" .
-          RelyxTable::write_int ("rotate", $thistable->{"rotate"}) .
-          RelyxTable::write_bool("islongtable", $thistable->{"is_long_table"}) .
-          RelyxTable::write_int ("firstHeadTopDL", 0) .
-          RelyxTable::write_int ("firstHeadBottomDL", 0) .
-          RelyxTable::write_bool("firstHeadEmpty", 0) .
-          RelyxTable::write_int ("headTopDL", 0) .
-          RelyxTable::write_int ("headBottomDL", 0) .
-          RelyxTable::write_int ("footTopDL", 0) .
-          RelyxTable::write_int ("footBottomDL", 0) .
-          RelyxTable::write_int ("lastFootTopDL", 0) .
-          RelyxTable::write_int ("lastFootBottomDL", 0) .
-          RelyxTable::write_bool("lastFootEmpty", 0) .
-          ">\n";
-       # column info
-       my $col;
-       foreach $col (@{$thistable->{"columns"}}) {
-           $to_print .= $col->print_info_221;
-       }
-       # row info
-       my $row;
-       my $cell;
-       foreach $row (@{$thistable->{"rows"}}) {
-           $to_print .= $row->print_info_221;
-           my $count = 0;
-           foreach $col (@{$thistable->{"columns"}}) {
-               $cell = $row->{"cells"}[$count];
-               $count++;
-               $to_print .= $cell->print_info_221;
-           }
-           $to_print .= "</row>\n";
-       }
-       $to_print .= "</lyxtabular>\n";
-       return $to_print;
-    } # end sub print_info_221
-
-    sub print_info_215 {
-    # Subroutine to print out the table in \lyxformat 215
         # print the header information for this table
        my $thistable = shift;
         my $to_print = "";
@@ -390,7 +313,7 @@ sub write_int {
        foreach $col (@{$thistable->{"columns"}}) {
            $to_print .= $col->print_info;
        }
-                  
+
        # Print cell info
        my $cell;
        foreach $row (@{$thistable->{"rows"}}) {
@@ -405,7 +328,7 @@ sub write_int {
        $to_print .= "\n";
 
        return $to_print;
-    } # end sub print_info_215
+    } # end sub print_info
 
 # Convenient subroutines
     sub numrows {
@@ -446,7 +369,7 @@ package RelyxTable::Column;
        my $description = shift;
        my $col;
 
-       # Initially zero everything, since we set different 
+       # Initially zero everything, since we set different
        # fields for @ and non-@ columns
        $col->{"alignment"} = "c";  # default
        $col->{"left_line"} = 0;
@@ -454,25 +377,25 @@ package RelyxTable::Column;
        $col->{"pwidth"} = "";
        $col->{"special"} = "";
 
-       # Any special (@) column should be handled differently
+       # LyX does not know about '@' or 'm' column descriptors so, to
+       # ensure that the LaTeX -> LyX -> LaTeX cycle is invariant,
+       # these descriptors are placed in the 'special' field.
        if ($description =~ /\@/ || $description =~ /^m/ ) {
-          # Just put the whole description in "special" field --- this
-          # corresponds the the "extra" field in LyX table popup
-          # Note that LyX ignores alignment, r/l lines for a special column
-          $col->{"special"} = $description;
-          print "\n'$description' column won't display WYSIWYG in LyX\n"
-                                                           if $debug_on;
-
-       # It's not a special @ column
-       } else {
+           $col->{"special"} = $description;
+           print "\n'$description' column won't display WYSIWYG in LyX\n"
+                                                            if $debug_on;
+       }
 
+       # '@' columns really can't be displayed WYSIWYG in LyX,
+       # but we can get visual feedback on 'm' columns.
+       if (!($description =~ /\@/)) {
            # left line?
            $description =~ s/^\|*//;
            $col->{"left_line"} = length($&);
 
            # main column description
-           $description =~ s/^[clrp]//;
-           if ($& eq "p") {
+           $description =~ s/^[clrpm]//;
+           if ($& eq 'p' || $& eq 'm') {
                $description =~ s/^\{(.+)\}//; # eat the width
                $col->{"pwidth"} = $1; # width without braces
                # note: alignment is not applicable for 'p' columns
@@ -501,26 +424,9 @@ package RelyxTable::Column;
                    );
        $to_print .= join(" ",@arr);
        $to_print .= "\n";
-                  
-       return $to_print;
-    }
 
-    sub print_info_221 {
-    # print out header information for this column
-       my $col = shift;
-       my $to_print = '';
-
-       $to_print = "<column" .
-#          RelyxTable::write_attribute("alignment", $TableAlignments{$col->{"alignment"}) .
-#          RelyxTable::write_attribute("valignment", 0) .
-#          RelyxTable::write_attribute("leftline",  $col->{"left_line"}) .
-#          RelyxTable::write_attribute("rightline", $col->{"right_line"} .
-#          RelyxTable::write_length("width", $col->{"pwidth"}) .
-           RelyxTable::write_string("special", $col->{"special"}) .
-#          ">\n";
        return $to_print;
     }
-
 } # end package RelyxTable::Column
 
 ################################################################################
@@ -613,26 +519,10 @@ package RelyxTable::Row;
                    );
        $to_print .= join(" ",@arr);
        $to_print .= "\n";
-                  
+
        return $to_print;
     } # end sub print_info
 
-    sub print_info_221 {
-    # print out header information for this column
-       my $row = shift;
-       my $to_print = '';
-
-       $to_print = "<row" .
-#          RelyxTable::write_attribute("topline", $row->{"top_line"}) .
-#          RelyxTable::write_attribute("bottomline", $row->{"bottom_line"}) .
-#          RelyxTable::write_attribute("endhead", $row->{"endhead"}) .
-#          RelyxTable::write_attribute("endfirsthead", $row->{"endfirsthead"}) .
-#          RelyxTable::write_attribute("endfoot", $row->{"endfoot"}) .
-#          RelyxTable::write_attribute("endlastfoot", $row->{"endlastfoot"}) .
-#          RelyxTable::write_attribute("newpage", $row->{"newpage"}) .
-           ">\n";
-       return $to_print;
-    }
 } # end package RelyxTable::Row
 
 ################################################################################
@@ -644,7 +534,7 @@ package RelyxTable::Cell;
 #    alignment   - alignment of this cell
 #    top_line    - does the cell have a line on the top?
 #    bottom_line - does the cell have a line on the bottom?
-#    has_cont_row- 
+#    has_cont_row-
 #    rotate      - rotate cell?
 #    line_breaks - cell has line breaks in it (???)
 #    special     - does this multicol have a special description (@ commands?)
@@ -705,26 +595,7 @@ package RelyxTable::Cell;
                    );
        $to_print .= join(" ",@arr);
        $to_print .= "\n";
-                  
-       return $to_print;
-    }
-    sub print_info_221 {
-    # print out header information for this column
-       my $cell = shift;
-       my $to_print = '';
-
-       $to_print = "<cell" .
-#          RelyxTable::write_attribute("topline", $row->{"top_line"}) .
-#          RelyxTable::write_attribute("bottomline", $row->{"bottom_line"}) .
-#          RelyxTable::write_attribute("endhead", $row->{"endhead"}) .
-#          RelyxTable::write_attribute("endfirsthead", $row->{"endfirsthead"}) .
-#          RelyxTable::write_attribute("endfoot", $row->{"endfoot"}) .
-#          RelyxTable::write_attribute("endlastfoot", $row->{"endlastfoot"}) .
-#          RelyxTable::write_attribute("newpage", $row->{"newpage"}) .
-           ">\n" .
-           "\\begin_inset " .
-           "\n\\end_inset \n" .
-           "</cell>\n";
+
        return $to_print;
     }
 } # end package RelyxTable::Cell