2014-04-09 17:43:14 +04:00
|
|
|
namespace LAview {
|
|
|
|
|
|
|
|
namespace Table {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cell of any table.
|
|
|
|
*/
|
|
|
|
public class Cell : ADoc {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of occupied cells.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public uint ncells { get; set; default = 1; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cell's alignment.
|
|
|
|
*
|
|
|
|
* Possible values: "c", "r", "l", ">{\centering}p{0.07\paperwidth}", etc.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public string align { get; set; default = ""; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of left lines.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public uint nllines { get; set; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of right lines.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public uint nrlines { get; set; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of top lines.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public uint noverlines { get; set; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of bottom lines.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public uint nunderlines { get; set; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Contents of the cell.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public Glob contents { get; set; default = new Glob (); }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Any text before the cell.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public string before { get; set; default = ""; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Any text after the cell.
|
|
|
|
*/
|
2014-10-30 16:58:23 +03:00
|
|
|
public string after { get; set; default = ""; }
|
2014-04-09 17:43:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of a cell indicates how much columns/rows does it occupy.
|
|
|
|
*/
|
|
|
|
public enum Multitype {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard cell.
|
|
|
|
*/
|
|
|
|
SIMPLE = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cell occupies several columns.
|
|
|
|
*/
|
|
|
|
MULTICOL,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cell occupies several rows.
|
|
|
|
*/
|
|
|
|
MULTIROW,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cell occupies several columns and rows.
|
|
|
|
*/
|
|
|
|
MULTICOLROW
|
|
|
|
}
|
|
|
|
|
|
|
|
Multitype _multitype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of a cell indicates how much columns/rows does it occupy.
|
|
|
|
*/
|
|
|
|
public Multitype multitype {
|
|
|
|
set {
|
|
|
|
if (value != Multitype.MULTICOL && value != Multitype.MULTICOLROW)
|
|
|
|
nllines = nrlines = 0;
|
|
|
|
_multitype = value;
|
|
|
|
}
|
|
|
|
get {
|
|
|
|
return _multitype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-25 18:30:55 +04:00
|
|
|
* Constructs a new ``Cell`` based on it's properties.
|
2014-04-09 17:43:14 +04:00
|
|
|
*/
|
|
|
|
public Cell.with_params (Multitype multitype, uint ncells, uint nllines, string align,
|
|
|
|
uint nrlines, uint noverlines, uint nunderlines,
|
|
|
|
Glob contents, string before, string after) {
|
|
|
|
this.ncells = ncells;
|
|
|
|
this.nllines = nllines;
|
|
|
|
this.align = align;
|
|
|
|
this.nrlines = nrlines;
|
|
|
|
this.noverlines = noverlines;
|
|
|
|
this.nunderlines = nunderlines;
|
|
|
|
this.contents = contents.copy () as Glob;
|
|
|
|
this.before = before;
|
|
|
|
this.after = after;
|
|
|
|
this.multitype = multitype;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Cell () {}
|
|
|
|
|
|
|
|
/**
|
2014-07-25 18:30:55 +04:00
|
|
|
* Gets a copy of the ``Cell``.
|
2014-04-09 17:43:14 +04:00
|
|
|
*/
|
|
|
|
public override IDoc copy () {
|
|
|
|
return new Cell.with_params (multitype, ncells, nllines, align, nrlines,
|
|
|
|
noverlines, nunderlines, contents, before, after);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-25 18:30:55 +04:00
|
|
|
* Generates LaTeX string for the ``Cell``.
|
2014-04-09 17:43:14 +04:00
|
|
|
*/
|
|
|
|
public override string generate () {
|
|
|
|
var result = new StringBuilder (before),
|
|
|
|
params = new StringBuilder (),
|
|
|
|
contents = this.contents.generate ();
|
|
|
|
|
|
|
|
if (align != "") {
|
|
|
|
for (uint i = 0; i < nllines; ++i) params.append_c ('|');
|
|
|
|
params.append (align);
|
|
|
|
for (uint i = 0; i < nrlines; ++i) params.append_c ('|');
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (multitype) {
|
|
|
|
case Multitype.SIMPLE:
|
|
|
|
result.append (contents);
|
|
|
|
break;
|
|
|
|
case Multitype.MULTICOL:
|
|
|
|
result.append_printf ("\\multicolumn{%u}{%s}{%s}",
|
|
|
|
ncells, params.str, contents);
|
|
|
|
break;
|
|
|
|
case Multitype.MULTIROW:
|
|
|
|
result.append_printf ("\\multirow{%u}{%s}{%s}",
|
|
|
|
ncells, params.str, contents);
|
|
|
|
break;
|
|
|
|
case Multitype.MULTICOLROW:
|
|
|
|
result.append_printf ("\\multicolumn{1}{%s}{\\multirow{%u}{*}{%s}}",
|
|
|
|
params.str, ncells, contents);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert (multitype == Multitype.SIMPLE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.append (after);
|
|
|
|
|
|
|
|
return result.str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|