App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/SocialCalcServersideUtilities.pm view on Meta::CPAN
my $sheet = shift @_;
my $context = {
sheet => $sheet,
hideRowsCols => 0, # pay attention to row/col hide settings (currently ignored)
cellIDprefix => "", # if non-null, each cell will render with an ID starting with this
defaultcolwidth => 80,
defaultlayout => "padding:2px 2px 1px 2px;vertical-align:top;",
globaldefaultfontstyle => "normal normal",
globaldefaultfontsize => "small",
globaldefaultfontfamily => "Verdana,Arial,Helvetica,sans-serif",
explicitStyles => {
skippedcell => "font-size:small;background-color:#CCC",
comment => "background-repeat:no-repeat;background-position:top right;background-image:url(images/sc-commentbg.gif);"
},
classnames => {
skippedcell => "",
comment => ""
},
# initialize calculated values to be filled in later:
cellskip => {}, # this-cell => coord of cell covering this cell (only for covered cells)
colwidth => [], # column widths, taking into account defaults
totalwidth => 0, # total table width
maxcol => 0, # max col to display, adding long spans, etc.
maxrow => 0, # max row to display, adding long spans, etc.
defaultfontstyle => "",
defaultfontsize => "",
defaultfontfamily => "",
fonts => [], # for each fontnum, {style: fs, weight: fw, size: fs, family: ff}
layouts => [], # for each layout, "padding:Tpx Rpx Bpx Lpx;vertical-align:va;"
};
}
#
# $outstr = RenderSheet($context, $options)
#
# Returns HTML for table rendering the sheet in that context.
#
# The options (passed to cell rendering code) are:
#
# newwinlinks => t/f (default is true) - whether text-link has target="_blank" by default or not
#
sub RenderSheet {
my ($context, $options) = @_;
my $sheet = $context->{sheet};
CalculateCellSkipData($context, $options);
PrecomputeSheetFontsAndLayouts($context, $options);
CalculateColWidthData($context, $options);
# Make a reasonable guess about the size of our rendered sheet, then
# pre-extend that SV. This is *critical* for mod_perl performance,
# as malloc there is much slower there than the command line.
my $outstr = ("\x00" x ($context->{maxrow} * $context->{maxcol} * 100));
$outstr = '';
$outstr .= RenderTableTag($context, $options); # start with table tag
$outstr .= RenderColGroup($context, $options); # then colgroup section
$outstr .= RenderSizingRow($context, $options); # add tiny row so all cols have something despite spans
$outstr .= "<tbody>";
my $id_prefix = $context->{cellIDprefix} || 'cell_';
for (my $row=1; $row <= $context->{maxrow}; $row++) {
$outstr .= qq!<tr><th height="1"><span>$row</span></th>!;
for (my $col=1; $col <= $context->{maxcol}; $col++) {
my $coord = (ColToCoord()->[$col]).$row;
# Skip if within a span masked by merged cells
next if $context->{cellskip}{$coord};
my $cell = $context->{sheet}{cells}{$coord};
$outstr .= qq{<td id="$id_prefix$coord"\n} . (
$context->{_render_cache_cell_html}{$cell->{_cache_key}}
||= RenderCell($context, $row, $col, $options, $coord, $cell || { datatype => 'b' })
);
}
$outstr .= "</tr>";
}
$outstr .= "</tbody>";
$outstr .= "</table>";
my $stylestr = "<style><!--\n";
while (my ($short_class, $long_class) = each %{ $context->{_render_cache_cell_style_short} }) {
my $style = delete $context->{_render_cache_cell_style_long}{$long_class};
# Here the ", td.$long_class" is not strictly neccessary, but contained
# for the case of possible e.g. concating two stylesheet renderings.
$stylestr .= "td.$short_class, td.$long_class {\n$style}\n";
}
while (my ($long_class, $style) = each %{ $context->{_render_cache_cell_style_long} }) {
$stylestr .= "td.$long_class {\n$style}\n";
}
$stylestr .= "--></style>";
delete $context->{_render_cache_cell_style_long};
delete $context->{_render_cache_cell_style_short};
delete $context->{_render_cache_cell_html};
return $stylestr . $outstr;
}
#
# CalculateCellSkipData($context, $options)
#
( run in 1.542 second using v1.01-cache-2.11-cpan-99c4e6809bf )