Expand ADocList interface with an element type to get implicit client access.
This commit is contained in:
parent
686f837d62
commit
815da3b16c
|
@ -1 +1 @@
|
|||
Subproject commit 784ca10a530e629885236e9df7fdf5647ddffa7c
|
||||
Subproject commit bce8069895429f19b76fae6c740cb8426b125fa9
|
|
@ -5,7 +5,7 @@ namespace LAview {
|
|||
/**
|
||||
* List of {@link AddSpace}-s.
|
||||
*/
|
||||
public class AddSpaces : ADocList {
|
||||
public class AddSpaces : ADocList<AddSpace> {
|
||||
|
||||
/**
|
||||
* Style of the {@link AddSpace}/{@link Subtable}.
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace LAview {
|
|||
/**
|
||||
* List of Column Parameters.
|
||||
*/
|
||||
public class ColParams : ADocList {
|
||||
public class ColParams : ADocList<ColParam> {
|
||||
|
||||
protected override ADocList create_default_instance () { return new ColParams (); }
|
||||
|
||||
|
|
|
@ -39,14 +39,14 @@ namespace LAview {
|
|||
/**
|
||||
* Any iterable LaTeX Document.
|
||||
*/
|
||||
public abstract class ADocList : Gee.ArrayList<IDoc>, IDoc {
|
||||
public abstract class ADocList<T> : Gee.ArrayList<T>, IDoc {
|
||||
|
||||
protected ADocList () {}
|
||||
|
||||
/**
|
||||
* Object.new (this.get_type ()) doesn't work for me for ArrayList.
|
||||
*/
|
||||
protected abstract ADocList create_default_instance ();
|
||||
protected abstract ADocList<T> create_default_instance ();
|
||||
|
||||
/**
|
||||
* Gets a copy of the ``ADocList``.
|
||||
|
@ -54,8 +54,8 @@ namespace LAview {
|
|||
public virtual IDoc copy () {
|
||||
var clone = create_default_instance ();
|
||||
|
||||
foreach (IDoc dociface in this)
|
||||
clone.add (dociface.copy () as IDoc);
|
||||
foreach (T dociface in this)
|
||||
clone.add ((dociface as IDoc).copy ());
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ namespace LAview {
|
|||
public virtual string generate () {
|
||||
var result = new StringBuilder ();
|
||||
|
||||
foreach (IDoc dociface in this)
|
||||
result.append (dociface.generate ());
|
||||
foreach (T dociface in this)
|
||||
result.append ((dociface as IDoc).generate ());
|
||||
|
||||
return result.str;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace LAview {
|
|||
/**
|
||||
* List of any LaTeX documents except Glob documents.
|
||||
*/
|
||||
public class Glob : ADocList {
|
||||
public class Glob : ADocList<IDoc> {
|
||||
|
||||
protected override ADocList create_default_instance () { return new Glob (); }
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace LAview {
|
|||
col_param.nrlines = wlen - 1 - nrlines;
|
||||
|
||||
// Bug #94: Parse Multiple defined columns in the tabular/longtable.
|
||||
while (count-- > 0) col_params.insert (0, col_param.copy ());
|
||||
while (count-- > 0) col_params.insert (0, col_param.copy () as ColParam);
|
||||
|
||||
match_info.next ();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace LAview {
|
|||
/**
|
||||
* Row in the {@link Subtable}.
|
||||
*/
|
||||
public class Row : ADocList {
|
||||
public class Row : ADocList<Cell> {
|
||||
|
||||
/**
|
||||
* Expands {@link AddSpaces.Style}.
|
||||
|
@ -162,7 +162,7 @@ namespace LAview {
|
|||
while (lines_type != LinesType.NONE) {
|
||||
lines_type = LinesType.NONE;
|
||||
|
||||
foreach (var cell in lcount_row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in lcount_row) {
|
||||
if (overline && cell.noverlines != 0
|
||||
|| !overline && cell.nunderlines != 0) {
|
||||
if (lines_type == LinesType.NONE) {
|
||||
|
@ -208,7 +208,7 @@ namespace LAview {
|
|||
uint cline_begin = 0, cline_end = 0;
|
||||
var where = Where.SEARCH_BEGIN;
|
||||
for (var idx = 0, max_idx = lcount_row.size; idx < max_idx; ++idx) {
|
||||
var cell = lcount_row[idx] as Cell;
|
||||
var cell = lcount_row[idx];
|
||||
|
||||
switch (where) {
|
||||
case Where.SEARCH_BEGIN:
|
||||
|
@ -216,8 +216,8 @@ namespace LAview {
|
|||
|| !overline && cell.nunderlines != 0) {
|
||||
|
||||
if (idx + 1 < max_idx
|
||||
&& (overline && (lcount_row[idx + 1] as Cell).noverlines != 0
|
||||
|| !overline && (lcount_row[idx + 1] as Cell).nunderlines != 0)) {
|
||||
&& (overline && lcount_row[idx + 1].noverlines != 0
|
||||
|| !overline && lcount_row[idx + 1].nunderlines != 0)) {
|
||||
cline_end = cline_begin + cell.ncells;
|
||||
where = Where.SEARCH_END;
|
||||
} else {
|
||||
|
@ -236,8 +236,8 @@ namespace LAview {
|
|||
break;
|
||||
case Where.SEARCH_END:
|
||||
if (idx + 1 >= max_idx
|
||||
|| overline && (lcount_row[idx + 1] as Cell).noverlines == 0
|
||||
|| !overline && (lcount_row[idx + 1] as Cell).nunderlines == 0) {
|
||||
|| overline && lcount_row[idx + 1].noverlines == 0
|
||||
|| !overline && lcount_row[idx + 1].nunderlines == 0) {
|
||||
if (clines_added)
|
||||
s.append_c (' ');
|
||||
s.append_printf (lcount_row.style != Style.DEFAULT ?
|
||||
|
@ -258,7 +258,7 @@ namespace LAview {
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var cell in lcount_row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in lcount_row) {
|
||||
if (overline && cell.noverlines != 0
|
||||
|| !overline && cell.nunderlines != 0) {
|
||||
if (overline)
|
||||
|
@ -279,14 +279,14 @@ namespace LAview {
|
|||
|
||||
if ((line_style & OpLineStyle.VBORDER) != 0) {
|
||||
if (index < 0 || index >= size) {
|
||||
var last_cell = get (size - 1) as Cell;
|
||||
var last_cell = this[size - 1];
|
||||
if (last_cell.multitype == Cell.Multitype.MULTICOL
|
||||
|| last_cell.multitype == Cell.Multitype.MULTICOLROW)
|
||||
cell.nrlines = last_cell.nrlines;
|
||||
} else if (index == 0) {
|
||||
if ((get (index) as Cell).multitype == Cell.Multitype.MULTICOL
|
||||
|| (get (index) as Cell).multitype == Cell.Multitype.MULTICOLROW)
|
||||
cell.nllines = (get (index) as Cell).nllines;
|
||||
if (this[index].multitype == Cell.Multitype.MULTICOL
|
||||
|| this[index].multitype == Cell.Multitype.MULTICOLROW)
|
||||
cell.nllines = this[index].nllines;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,7 +294,7 @@ namespace LAview {
|
|||
var prev_index = index - 1;
|
||||
|
||||
if (index >= 0 && index < size) { // next == [index]
|
||||
var idx_cell = get (index) as Cell;
|
||||
var idx_cell = this[index];
|
||||
if (idx_cell.multitype == Cell.Multitype.MULTICOL
|
||||
|| idx_cell.multitype == Cell.Multitype.MULTICOLROW ) {
|
||||
idx_cell.nllines = cell.nrlines != 0 || idx_cell.nllines != 0 ? 1 : 0;
|
||||
|
@ -307,7 +307,7 @@ namespace LAview {
|
|||
if (prev_index >= 0 && prev_index < size
|
||||
&& (cell.multitype == Cell.Multitype.MULTICOL
|
||||
|| cell.multitype == Cell.Multitype.MULTICOLROW)) {
|
||||
var idx_cell = get (prev_index) as Cell;
|
||||
var idx_cell = this[prev_index];
|
||||
cell.nllines = idx_cell.nrlines != 0 || cell.nllines != 0 ? 1 : 0;
|
||||
idx_cell.nrlines = 0;
|
||||
}
|
||||
|
@ -334,21 +334,21 @@ namespace LAview {
|
|||
* @param line_style {@link Row.OpLineStyle} of the operation.
|
||||
*/
|
||||
public new Cell remove_at (int index, Row.OpLineStyle line_style = Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
var cell = get (index) as Cell;
|
||||
var cell = this[index];
|
||||
if ((line_style & OpLineStyle.VBORDER) != 0
|
||||
&& (cell.multitype == Cell.Multitype.MULTICOL
|
||||
|| cell.multitype == Cell.Multitype.MULTICOLROW)) {
|
||||
if (size > 1) {
|
||||
if (index == 0)
|
||||
(get (1) as Cell).nllines = cell.nllines;
|
||||
this[1].nllines = cell.nllines;
|
||||
else if (index == size - 1)
|
||||
(get (size - 2) as Cell).nrlines = cell.nrlines;
|
||||
this[size - 2].nrlines = cell.nrlines;
|
||||
}
|
||||
|
||||
if ((line_style & OpLineStyle.VDBLLINES) != 0) {
|
||||
if (index > 0 && index + 1 < size) {
|
||||
var prev = get (index - 1) as Cell,
|
||||
next = get (index + 1) as Cell;
|
||||
var prev = this[index - 1],
|
||||
next = this[index + 1];
|
||||
if (next.multitype == Cell.Multitype.MULTICOL
|
||||
|| next.multitype == Cell.Multitype.MULTICOLROW) {
|
||||
next.nllines = prev.nrlines != 0 || next.nllines != 0 ? 1 : 0;
|
||||
|
@ -358,7 +358,7 @@ namespace LAview {
|
|||
}
|
||||
}
|
||||
|
||||
return base.remove_at (index) as Cell;
|
||||
return base.remove_at (index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace LAview {
|
|||
/**
|
||||
* Subtable in the {@link ATable}.
|
||||
*/
|
||||
public class Subtable : ADocList {
|
||||
public class Subtable : ADocList<Row> {
|
||||
|
||||
/**
|
||||
* Caption of the table.
|
||||
|
@ -51,8 +51,8 @@ namespace LAview {
|
|||
uint dncells = 0, sncells = 0;
|
||||
|
||||
while (si < max_si && di < max_di) {
|
||||
var scell = src_row.get (si) as Cell;
|
||||
var dcell = dest_row.get (di) as Cell;
|
||||
var scell = src_row[si];
|
||||
var dcell = dest_row[di];
|
||||
|
||||
dncells = dncells != 0 ? dncells
|
||||
: uint.max (1, dcell.multitype == Cell.Multitype.MULTICOL ?
|
||||
|
@ -76,8 +76,8 @@ namespace LAview {
|
|||
uint tncells = 0, bncells = 0;
|
||||
|
||||
while (ti < max_ti && bi < max_bi) {
|
||||
var tcell = top_row.get (ti) as Cell;
|
||||
var bcell = bottom_row.get (bi) as Cell;
|
||||
var tcell = top_row[ti];
|
||||
var bcell = bottom_row[bi];
|
||||
|
||||
tncells = tncells != 0 ? tncells
|
||||
: uint.max (1, tcell.multitype == Cell.Multitype.MULTICOL ?
|
||||
|
@ -99,7 +99,7 @@ namespace LAview {
|
|||
|
||||
if ((line_style & Row.OpLineStyle.HBORDER) != 0) {
|
||||
if (row2 == null)
|
||||
process_border_lines (row, get (size - 1) as Row, false);
|
||||
process_border_lines (row, this[size - 1], false);
|
||||
else if (index_of (row2) == 0)
|
||||
process_border_lines (row, row2, true);
|
||||
}
|
||||
|
@ -108,10 +108,10 @@ namespace LAview {
|
|||
Row prev = null;
|
||||
|
||||
if (row2 != null) { // next == iter
|
||||
prev = get (index_of (row2) - 1) as Row;
|
||||
prev = this[index_of (row2) - 1];
|
||||
process_double_lines (row, row2);
|
||||
} else {
|
||||
prev = get (size - 1) as Row;
|
||||
prev = this[size - 1];
|
||||
}
|
||||
|
||||
if (prev != null)
|
||||
|
@ -126,10 +126,10 @@ namespace LAview {
|
|||
* @param line_style {@link Row.OpLineStyle} of the operation.
|
||||
*/
|
||||
public void remove_col (uint index, Row.OpLineStyle line_style = Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
foreach (Row row in this as Gee.ArrayList<Row>) {
|
||||
foreach (Row row in this) {
|
||||
uint mindx = 0;
|
||||
|
||||
foreach (var cell in row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in row) {
|
||||
uint ncells = 1;
|
||||
|
||||
if (cell.multitype == Cell.Multitype.MULTICOL)
|
||||
|
@ -158,12 +158,12 @@ namespace LAview {
|
|||
*/
|
||||
public void clone_col (uint src_index, uint dest_index,
|
||||
bool multicol, Row.OpLineStyle line_style = Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
foreach (var row in this as Gee.ArrayList<Row>) {
|
||||
foreach (var row in this) {
|
||||
uint mindx = 0;
|
||||
var sidx = -1;
|
||||
var didx = -1;
|
||||
|
||||
foreach (var cell in row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in row) {
|
||||
uint ncells = 1;
|
||||
|
||||
if (cell.multitype == Cell.Multitype.MULTICOL)
|
||||
|
@ -176,7 +176,7 @@ namespace LAview {
|
|||
didx = row.index_of (cell);
|
||||
|
||||
if (sidx != -1 && didx != -1) {
|
||||
var cell2 = row.get (sidx).copy () as Cell;
|
||||
var cell2 = row[sidx].copy () as Cell;
|
||||
if (!multicol && cell2.multitype == Cell.Multitype.MULTICOL)
|
||||
cell2.ncells = 1;
|
||||
row.insert (didx, cell2, line_style);
|
||||
|
@ -193,15 +193,14 @@ namespace LAview {
|
|||
Cell cell;
|
||||
|
||||
while (mindx < dest_index) {
|
||||
var row_size = row.size;
|
||||
cell = row.get (row_size - 1).copy () as Cell;
|
||||
cell = row[row.size - 1].copy () as Cell;
|
||||
cell.contents = empty_global_doc;
|
||||
cell.ncells = 1;
|
||||
row.add (cell, line_style);
|
||||
mindx++;
|
||||
}
|
||||
|
||||
cell = row.get (sidx).copy () as Cell;
|
||||
cell = row[sidx].copy () as Cell;
|
||||
if (!multicol && cell.multitype == Cell.Multitype.MULTICOL)
|
||||
cell.ncells = 1;
|
||||
row.add (cell, line_style);
|
||||
|
@ -231,17 +230,17 @@ namespace LAview {
|
|||
public new Row remove_at (int index, Row.OpLineStyle line_style = Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
if (size > 1 && 0 != line_style & Row.OpLineStyle.HBORDER) {
|
||||
if (index == 0)
|
||||
process_border_lines (get (1) as Row, get (index) as Row, true);
|
||||
process_border_lines (this[1], this[index], true);
|
||||
else if (index == size - 1)
|
||||
process_border_lines (get (size - 2) as Row, get (index) as Row, false);
|
||||
process_border_lines (this[size - 2], this[index], false);
|
||||
}
|
||||
|
||||
if ((line_style & Row.OpLineStyle.HDBLLINES) != 0)
|
||||
if (index > 0 && index + 1 < size)
|
||||
process_double_lines (get (index + 1) as Row,
|
||||
get (index - 1) as Row);
|
||||
process_double_lines (this[index + 1],
|
||||
this[index - 1]);
|
||||
|
||||
return base.remove_at (index) as Row;
|
||||
return base.remove_at (index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +251,7 @@ namespace LAview {
|
|||
* @param line_style {@link Row.OpLineStyle} of the operation.
|
||||
*/
|
||||
public new void insert (int index, Row row, Row.OpLineStyle line_style = Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
process_opline_insert (row, get (index) as Row, line_style);
|
||||
process_opline_insert (row, this[index], line_style);
|
||||
base.insert (index, row);
|
||||
}
|
||||
|
||||
|
@ -283,12 +282,12 @@ namespace LAview {
|
|||
|
||||
uint min_olines = 0, min_ulines = 0;
|
||||
|
||||
foreach (var cell in row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in row) {
|
||||
min_olines = uint.min (min_olines, cell.noverlines);
|
||||
min_ulines = uint.min (min_ulines, cell.nunderlines);
|
||||
}
|
||||
|
||||
foreach (var cell in row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in row) {
|
||||
switch (row_pos) {
|
||||
case RowPos.FIRST:
|
||||
cell.noverlines = uint.min (min_olines + 1, cell.noverlines);
|
||||
|
@ -323,7 +322,7 @@ namespace LAview {
|
|||
s.append ("\\tabularnewline");
|
||||
}
|
||||
|
||||
foreach (var row in this as Gee.ArrayList<Row>) {
|
||||
foreach (var row in this) {
|
||||
var row_style = Row.Style.DEFAULT;
|
||||
|
||||
if (style != AddSpaces.Style.DEFAULT) {
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace LAview {
|
|||
public ColParams params { get; set; default = new ColParams (); }
|
||||
|
||||
/**
|
||||
* Main sutable.
|
||||
* Main subtable.
|
||||
*/
|
||||
public Subtable table { get; set; default = new Subtable (); }
|
||||
|
||||
|
@ -111,21 +111,21 @@ namespace LAview {
|
|||
= Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
if (index >= params.size) return;
|
||||
|
||||
var param = params.get (index) as ColParam;
|
||||
var param = params[index];
|
||||
|
||||
if ((line_style & Row.OpLineStyle.VBORDER) != 0 && param.align != "") {
|
||||
if (params.size > 1) {
|
||||
if (index == 0)
|
||||
(params.get (1) as ColParam).nllines = param.nllines;
|
||||
params[1].nllines = param.nllines;
|
||||
else if (index == params.size - 1)
|
||||
(params.get (params.size - 2) as ColParam).nrlines = param.nrlines;
|
||||
params[params.size - 2].nrlines = param.nrlines;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_style & Row.OpLineStyle.VDBLLINES) != 0) {
|
||||
if (index > 0 && index < params.size - 1) {
|
||||
var prev = params.get (index - 1) as ColParam,
|
||||
next = params.get (index + 1) as ColParam;
|
||||
var prev = params[index - 1],
|
||||
next = params[index + 1];
|
||||
next.nllines = prev.nrlines != 0 || next.nllines != 0 ? 1 : 0;
|
||||
prev.nrlines = 0;
|
||||
}
|
||||
|
@ -153,15 +153,15 @@ namespace LAview {
|
|||
= Row.OpLineStyle.BORDER_DBLLINES) {
|
||||
if (src_index >= params.size || dest_index > params.size) return;
|
||||
|
||||
var param = params.get (src_index).copy () as ColParam;
|
||||
var param = params[src_index].copy () as ColParam;
|
||||
|
||||
if ((Row.OpLineStyle.VBORDER & line_style) != 0) {
|
||||
if (dest_index >= params.size) {
|
||||
var last_param = params.get (params.size - 1) as ColParam;
|
||||
var last_param = params[params.size - 1];
|
||||
if (last_param.align != "")
|
||||
param.nrlines = last_param.nrlines;
|
||||
} else {
|
||||
var first_param = params.get (0) as ColParam;
|
||||
var first_param = params[0];
|
||||
if (dest_index == 0 && first_param.align != "")
|
||||
param.nllines = first_param.nllines;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ namespace LAview {
|
|||
if (dest_index < params.size) {
|
||||
prev_index = dest_index > 0 ? dest_index - 1 : 0;
|
||||
if (prev_index > 0) prev_edit = true;
|
||||
var dest_param = params.get (dest_index) as ColParam;
|
||||
var dest_param = params[dest_index];
|
||||
dest_param.nllines = param.nrlines != 0 || dest_param.nllines != 0 ? 1 : 0;
|
||||
param.nrlines = 0;
|
||||
} else {
|
||||
|
@ -183,7 +183,7 @@ namespace LAview {
|
|||
}
|
||||
|
||||
if (prev_edit) {
|
||||
var prev_param = params.get (prev_index) as ColParam;
|
||||
var prev_param = params[prev_index];
|
||||
param.nllines = prev_param.nrlines != 0 || param.nllines != 0 ? 1 : 0;
|
||||
prev_param.nrlines = 0;
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ namespace LAview {
|
|||
var subdoc = subparserGlobal.parse (cell_contents, subdoc_start.line, subdoc_start.pos);
|
||||
|
||||
unowned List<int> clines_p = clines.first ();
|
||||
foreach (var cell in row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in row) {
|
||||
if (clines_p == null) break;
|
||||
|
||||
for (var i = 0, max_i = cell.ncells; i < max_i; ++i) {
|
||||
|
@ -258,7 +258,7 @@ namespace LAview {
|
|||
switch (lines_type) {
|
||||
case Row.LinesType.HLINE:
|
||||
if (subtable.size != 0) {
|
||||
foreach (var cell in subtable.get (subtable.size - 1) as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in subtable[subtable.size - 1]) {
|
||||
cell.nunderlines += nhlines;
|
||||
clear_lines = true;
|
||||
}
|
||||
|
@ -268,9 +268,9 @@ namespace LAview {
|
|||
/* #85 Assert in LINE_CLINES case */
|
||||
if (row.size == 0 && subtable.size == 0)
|
||||
break;
|
||||
var tmp_row = row.size != 0 ? row : subtable.get (subtable.size - 1) as Row;
|
||||
var tmp_row = row.size != 0 ? row : subtable[subtable.size - 1];
|
||||
unowned List<int> clines_p = clines.first ();
|
||||
foreach (var cell in tmp_row as Gee.ArrayList<Cell>) {
|
||||
foreach (var cell in tmp_row) {
|
||||
if (clines_p == null) break;
|
||||
|
||||
if (clines_p != null && clines_p.data != 0)
|
||||
|
@ -313,7 +313,7 @@ namespace LAview {
|
|||
|
||||
Row last_row;
|
||||
if (subtable.size != 0)
|
||||
last_row = subtable.get(subtable.size-1) as Row;
|
||||
last_row = subtable[subtable.size-1];
|
||||
else
|
||||
last_row = new Row ();
|
||||
|
||||
|
@ -322,7 +322,7 @@ namespace LAview {
|
|||
} else if (row.top.size == 0 || subtable.size == 0) {
|
||||
row.top.add (add_space);
|
||||
} else if (row.top.size == 1 && subtable.size != 0) {
|
||||
last_row.between.add (row.top.get (0) as AddSpace);
|
||||
last_row.between.add (row.top[0]);
|
||||
row.top.remove_at (0);
|
||||
row.top.add (add_space);
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ namespace LAview {
|
|||
protected void spaces_to_last_row () {
|
||||
var top = row.top;
|
||||
if (top.size == 1 && subtable.size != 0) {
|
||||
(subtable.get (subtable.size - 1) as Row).between.add (top.get (0) as AddSpace);
|
||||
subtable[subtable.size - 1].between.add (top[0]);
|
||||
top.remove_at (0);
|
||||
}
|
||||
}
|
||||
|
@ -522,11 +522,9 @@ namespace LAview {
|
|||
case TableTagType.DBLBACKSLASHES:
|
||||
case TableTagType.TABULARNEWLINE:
|
||||
if (tag == TableTagType.DBLBACKSLASHES) {
|
||||
var row_length = row.size;
|
||||
|
||||
var col_param = "";
|
||||
if (row_length < table.params.size)
|
||||
col_param = (table.params.get (row_length) as ColParam).align;
|
||||
if (row.size < table.params.size)
|
||||
col_param = table.params[row.size].align;
|
||||
if (col_param != ""
|
||||
&& (col_param.index_of_char ('p') != -1
|
||||
|| col_param.index_of_char ('b') != -1
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace LAview {
|
|||
col_param.nrlines = wlen - 1 - nrlines;
|
||||
|
||||
// Bug #94: Parse Multiple defined columns in the tabular/longtable.
|
||||
while (count-- > 0) col_params.insert (0, col_param.copy ());
|
||||
while (count-- > 0) col_params.insert (0, col_param.copy () as ColParam);
|
||||
|
||||
match_info.next ();
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class Main : Object {
|
|||
ltable.clone_col (1000, 0, true);
|
||||
} else if (args[3] == "append_row0") {
|
||||
var table = ltable.table;
|
||||
table.add (table.get (0).copy () as Table.Row);
|
||||
table.add (table[0].copy () as Table.Row);
|
||||
} else {
|
||||
stdout.printf ("Incorrect operation '%s' specified.\n", args[3]);
|
||||
return -1;
|
||||
|
@ -84,7 +84,7 @@ public class Main : Object {
|
|||
if (args[3] == "append_row0") {
|
||||
var tabular = subdoc as Table.Tabular;
|
||||
var table = tabular.table;
|
||||
table.add (table.get (0).copy () as Table.Row);
|
||||
table.add (table[0].copy () as Table.Row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,22 +60,21 @@ public class Main : Object {
|
|||
foreach (var subdoc in doc) {
|
||||
stdout.printf ("%s\n", subdoc.get_type ().name ());
|
||||
|
||||
if (subdoc.get_type ().name () == "LAviewTableTabular"
|
||||
|| subdoc.get_type ().name () == "LAviewTableLongtable") {
|
||||
if (subdoc is Table.Tabular || subdoc is Table.Longtable) {
|
||||
|
||||
unowned Table.Subtable subtable = null;
|
||||
|
||||
if (subdoc.get_type ().name () == "LAviewTableTabular")
|
||||
if (subdoc is Table.Tabular)
|
||||
subtable = (subdoc as Table.Tabular).table;
|
||||
else
|
||||
subtable = (subdoc as Table.Longtable).table;
|
||||
|
||||
foreach (var row in subtable) {
|
||||
foreach (var cell in (row as Table.Row)) {
|
||||
var glob = (cell as Table.Cell).contents;
|
||||
foreach (var cell in row) {
|
||||
var glob = cell.contents;
|
||||
|
||||
foreach (var glob_subdoc in glob) {
|
||||
if (glob_subdoc.get_type ().name () != "LAviewText") {
|
||||
if (!( glob_subdoc is LAview.Text )) {
|
||||
stdout.printf (" %s\n", glob_subdoc.get_type ().name ());
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +89,7 @@ public class Main : Object {
|
|||
foreach (var subdoc in doc) {
|
||||
stdout.printf ("%s\n", subdoc.get_type ().name ());
|
||||
|
||||
if (subdoc.get_type ().name () == "LAviewGraphics") {
|
||||
if (subdoc is LAview.Graphics) {
|
||||
var graphics = subdoc as Graphics;
|
||||
stdout.printf (" width=%f%s, height=%f%s, path=%s,\n gen()=%s\n",
|
||||
graphics.width, graphics.width_unit, graphics.height, graphics.height_unit,
|
||||
|
|
|
@ -1,386 +0,0 @@
|
|||
FIND_PACKAGE (PkgConfig REQUIRED)
|
||||
PKG_CHECK_MODULES (GLIB2 REQUIRED glib-2.0)
|
||||
PKG_CHECK_MODULES (GOBJECT2 REQUIRED gobject-2.0)
|
||||
|
||||
INCLUDE_DIRECTORIES (${GLIB2_INCLUDE_DIRS} ${GOBJECT2_INCLUDE_DIRS})
|
||||
LINK_DIRECTORIES (${GLIB2_LIBRARY_DIRS} ${GOBJECT2_LIBRARY_DIRS})
|
||||
|
||||
IF (CMAKE_COMPILER_IS_GNUCC)
|
||||
ADD_DEFINITIONS (${GLIB2_CFLAGS_OTHER} ${GOBJECT2_CFLAGS_OTHER})
|
||||
ENDIF ()
|
||||
|
||||
# add the executable
|
||||
ADD_EXECUTABLE (txr_parse_test txr_parse_test.c)
|
||||
TARGET_LINK_LIBRARIES (txr_parse_test txr-texparser ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})
|
||||
|
||||
# add ltable_test executable
|
||||
ADD_EXECUTABLE (ltable_test ltable_test.c)
|
||||
TARGET_LINK_LIBRARIES (ltable_test txr-texparser ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})
|
||||
|
||||
# add the install targets and files
|
||||
# INSTALL (TARGETS txr_parse_test ltable_test DESTINATION bin)
|
||||
|
||||
# parsing test macro
|
||||
MACRO (do_parse_test testname table_path etalon_path regexp)
|
||||
IF ("${etalon_path}" STREQUAL "")
|
||||
SET (extra_args "")
|
||||
ELSE ()
|
||||
SET (extra_args --etalon ${etalon_path})
|
||||
ENDIF ()
|
||||
ADD_TEST (txr_parse_test-${testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/txr_parse_test --table ${table_path} ${extra_args})
|
||||
SET_TESTS_PROPERTIES (txr_parse_test-${testname}
|
||||
PROPERTIES PASS_REGULAR_EXPRESSION ${regexp}
|
||||
FAIL_REGULAR_EXPRESSION "CRITICAL;WARNING")
|
||||
ENDMACRO (do_parse_test)
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleList ${PROJECT_SOURCE_DIR}/test/throttle.tex ""
|
||||
"list all objects
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRGraphics
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleWalk ${PROJECT_SOURCE_DIR}/test/throttle.tex ""
|
||||
"Walk through all objects
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRGraphics
|
||||
width=0.000000.null., height=0.000000.null., path=174,
|
||||
gen..=.includegraphics., angle=25, scale=3,angle=70 , , .{174}
|
||||
resized gen.. = .includegraphics.angle=25,scale=3.{174}
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleCmp ${PROJECT_SOURCE_DIR}/test/throttle.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleErr1 ${PROJECT_SOURCE_DIR}/test/throttle_err1.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:33:15: : Unexpected stop tag sequence '..end{longtable}' without start tag pair.
|
||||
.end{longtable}
|
||||
.")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleErr2 ${PROJECT_SOURCE_DIR}/test/throttle_err2.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:33:1: Start tag sequence '..begin{longtable}' without stop tag pair.
|
||||
.begin{longtable}
|
||||
.
|
||||
")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleErr3 ${PROJECT_SOURCE_DIR}/test/throttle_err3.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:34:1: Error parsing subdoc.
|
||||
.begin{longtable}
|
||||
.
|
||||
TXRLongtableScanner:55:46: Stop external tag sequence '..end{longtable}' without start tag pair.
|
||||
.multicolumn{2}{|l|}{ЗМГ} & & .end{longtable} & & & & .tabularnewline
|
||||
.
|
||||
")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleErr4 ${PROJECT_SOURCE_DIR}/test/throttle_err4.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:33:13: : Unexpected stop tag sequence '..end{tabular}' without start tag pair.
|
||||
.end{tabular}
|
||||
.")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleErr5 ${PROJECT_SOURCE_DIR}/test/throttle_err5.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:33:1: Start tag sequence '..begin{tabular}' without stop tag pair.
|
||||
.begin{tabular}
|
||||
.
|
||||
")
|
||||
|
||||
# test throttle.tex
|
||||
do_parse_test (throttleErr6 ${PROJECT_SOURCE_DIR}/test/throttle_err6.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:34:1: Error parsing subdoc.
|
||||
.begin{tabular}
|
||||
.
|
||||
TXRTabularScanner:55:46: Stop external tag sequence '..end{tabular}' without start tag pair.
|
||||
.multicolumn{2}{|l|}{ЗМГ} & & .end{tabular} & & & & .tabularnewline
|
||||
.
|
||||
")
|
||||
|
||||
# test formular.tex
|
||||
do_parse_test (formularList ${PROJECT_SOURCE_DIR}/test/formular.tex ""
|
||||
"list all objects
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRGraphics
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
")
|
||||
|
||||
# test formular.tex
|
||||
do_parse_test (formularWalk ${PROJECT_SOURCE_DIR}/test/formular.tex ""
|
||||
"Walk through all objects
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRGraphics
|
||||
width=12.000000cm, height=25.000000cm, path=151,
|
||||
gen..=.includegraphics.width=12cm,height=25cm.{151}
|
||||
resized gen.. = .includegraphics.width=6.000000pt,height=50.000000dd.{151}
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
")
|
||||
|
||||
# test formular.tex
|
||||
do_parse_test (formularCmp ${PROJECT_SOURCE_DIR}/test/formular.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test formular.tex
|
||||
do_parse_test (formularErr1 ${PROJECT_SOURCE_DIR}/test/formular_err1.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:192:15: : Unexpected stop tag sequence '..end{longtable}' without start tag pair.
|
||||
.end{longtable}
|
||||
.")
|
||||
|
||||
# test formular.tex
|
||||
do_parse_test (formularErr2 ${PROJECT_SOURCE_DIR}/test/formular_err2.tex ""
|
||||
"Error parsing TeX document: TXRGlobScanner:44:1: Start tag sequence '..begin{longtable}' without stop tag pair.
|
||||
.begin{longtable}
|
||||
.
|
||||
")
|
||||
|
||||
# test for caption in all_subtables.tex
|
||||
do_parse_test (captionTest ${PROJECT_SOURCE_DIR}/test/all_subtables.tex ""
|
||||
".begin{document}
|
||||
.begin{longtable}{.c.c.}
|
||||
.caption{Caption of the table}
|
||||
")
|
||||
|
||||
# test all_subtables.tex
|
||||
do_parse_test (all_subtablesCmp ${PROJECT_SOURCE_DIR}/test/all_subtables.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test all_subtables.tex
|
||||
do_parse_test (linesCmp ${PROJECT_SOURCE_DIR}/test/lines.tex ${PROJECT_SOURCE_DIR}/test/lines.etalon.tex
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test ltable_embedded.tex
|
||||
do_parse_test (ltable_embedded ${PROJECT_SOURCE_DIR}/test/ltable_embedded.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test ltable_double_embedded.tex
|
||||
do_parse_test (ltable_double_embedded ${PROJECT_SOURCE_DIR}/test/ltable_double_embedded.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test throttle_VK2500.tex
|
||||
do_parse_test (throttle_VK2500Cmp ${PROJECT_SOURCE_DIR}/test/throttle_VK2500.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test throttle_VK2500.tex
|
||||
do_parse_test (throttle_VK2500PSCmp ${PROJECT_SOURCE_DIR}/test/throttle_VK2500PS.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test throttle_VK2500_dos_newlines_.tex
|
||||
do_parse_test (throttle_VK2500PS_dos_newlines_ListWalk ${PROJECT_SOURCE_DIR}/test/throttle_VK2500PS_dos_newlines.tex ""
|
||||
"list all objects
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
Walk through all objects
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
end of objects
|
||||
")
|
||||
|
||||
# test graph_in_ltable.tex
|
||||
do_parse_test (graph_in_ltable ${PROJECT_SOURCE_DIR}/test/graph_in_ltable.tex ""
|
||||
"
|
||||
list all objects
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRGraphics
|
||||
TXRLongtable
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
Walk through all objects
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
TXRLongtable
|
||||
TXRText
|
||||
end of objects
|
||||
")
|
||||
|
||||
# test ltable_square_arg.tex
|
||||
do_parse_test (ltable_square_arg ${PROJECT_SOURCE_DIR}/test/ltable_square_arg.tex ""
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
# test table_in_table.tex
|
||||
do_parse_test (table_in_table ${PROJECT_SOURCE_DIR}/test/table_in_table.tex ""
|
||||
"
|
||||
list all objects
|
||||
")
|
||||
|
||||
# test unary_quotes.tex
|
||||
do_parse_test (unary_quotes ${PROJECT_SOURCE_DIR}/test/unary_quotes.tex ""
|
||||
"
|
||||
list all objects
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
end of objects
|
||||
|
||||
Walk through all objects
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
TXRTabular
|
||||
TXRText
|
||||
end of objects
|
||||
")
|
||||
|
||||
# test back_slashes_in_a_table.tex
|
||||
do_parse_test (back_slashes_in_a_table ${PROJECT_SOURCE_DIR}/test/back_slashes_in_a_table.tex ${PROJECT_SOURCE_DIR}/test/back_slashes_in_a_table.etalon.tex
|
||||
"Original and generated text are EQUAL .-.")
|
||||
|
||||
|
||||
# ltable_test macro
|
||||
macro (ltable_test testname tex_path1 tex_path2 operation regexp)
|
||||
add_test (ltable_test-${testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ltable_test ${tex_path1} ${tex_path2} ${operation})
|
||||
set_tests_properties (ltable_test-${testname}
|
||||
PROPERTIES PASS_REGULAR_EXPRESSION ${regexp}
|
||||
FAIL_REGULAR_EXPRESSION "CRITICAL;WARNING")
|
||||
endmacro (ltable_test)
|
||||
|
||||
# ltable_test rm0row
|
||||
ltable_test (rm0row ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_rm0row.tex rm0row
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test rm1row
|
||||
ltable_test (rm1row ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_rm1row.tex rm1row
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test rm1000row
|
||||
ltable_test (rm1000row ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_rm1000row.tex rm1000row
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test rm_last_row
|
||||
ltable_test (rm_last_row ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_rm_last_row.tex rm_last_row
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_0_0
|
||||
ltable_test (clone_0_0 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_0_0.tex clone_0_0
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_0_1
|
||||
ltable_test (clone_0_1 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_0_1.tex clone_0_1
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_1_0
|
||||
ltable_test (clone_1_0 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_1_0.tex clone_1_0
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_0_last
|
||||
ltable_test (clone_0_last ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_0_last.tex clone_0_last
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_last_0
|
||||
ltable_test (clone_last_0 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_last_0.tex clone_last_0
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_0_lastp1
|
||||
ltable_test (clone_0_lastp1 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_0_lastp1.tex clone_0_lastp1
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_lastp1_0
|
||||
ltable_test (clone_lastp1_0 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_lastp1_0.tex clone_lastp1_0
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_0_1000
|
||||
ltable_test (clone_0_1000 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_0_1000.tex clone_0_1000
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test clone_1000_0
|
||||
ltable_test (clone_1000_0 ${PROJECT_SOURCE_DIR}/test/formular.tex ${PROJECT_SOURCE_DIR}/test/ltable_clone_1000_0.tex clone_1000_0
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# ltable_test append_row0
|
||||
ltable_test (append_row0 ${PROJECT_SOURCE_DIR}/test/table_rows.tex ${PROJECT_SOURCE_DIR}/test/table_rows.etalon.tex append_row0
|
||||
"Etalon and generated text are EQUAL .-.")
|
||||
|
||||
# enable testing
|
||||
ENABLE_TESTING ()
|
|
@ -1,219 +0,0 @@
|
|||
///@cond INTERNAL
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gprintf.h>
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#include "txr-texparser.h"
|
||||
|
||||
static gchar *fnameTable = NULL;
|
||||
static gchar *fnameEtalon = NULL;
|
||||
static gchar *fnameWrite = NULL;
|
||||
|
||||
static GOptionEntry entries[] =
|
||||
{
|
||||
{ "table", 't', 0, G_OPTION_ARG_FILENAME, &fnameTable, "File with a table", NULL },
|
||||
{ "etalon", 'e', 0, G_OPTION_ARG_FILENAME, &fnameEtalon, "File with etalon table", NULL },
|
||||
{ "write", 'w', 0, G_OPTION_ARG_FILENAME, &fnameWrite, "File to write", NULL },
|
||||
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GOptionContext *context;
|
||||
GError *error = NULL;
|
||||
|
||||
GError *parse_error = NULL;
|
||||
gchar *contents = NULL,
|
||||
*generated = NULL,
|
||||
*gentext;
|
||||
TXRGlob *doc = NULL;
|
||||
TXRGlobIter it;
|
||||
|
||||
//MamanBar *bar;
|
||||
//MamanBar *bar1;
|
||||
|
||||
//#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
// g_type_init ();
|
||||
//#endif
|
||||
|
||||
//bar = g_object_new (MAMAN_BAR_TYPE, NULL);
|
||||
//g_printf ("type = %s\n", G_OBJECT_TYPE_NAME (bar));
|
||||
//g_object_unref (bar);
|
||||
//bar1 = g_object_new (MAMAN_BAR_TYPE, NULL);
|
||||
//g_object_unref (bar1);
|
||||
//(void) bar1;
|
||||
//return 0;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
g_type_init ();
|
||||
#endif
|
||||
|
||||
/* commandline arguments processing */
|
||||
context = g_option_context_new ("- tests LaTeX parser");
|
||||
g_option_context_add_main_entries (context, entries, NULL);//GETTEXT_PACKAGE);
|
||||
// g_option_context_add_group (context, gtk_get_option_group (TRUE));
|
||||
if (!g_option_context_parse (context, &argc, &argv, &error))
|
||||
{
|
||||
fprintf (stderr, "option parsing failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
g_option_context_free (context);
|
||||
|
||||
/* read table */
|
||||
if (!fnameTable)
|
||||
{
|
||||
fprintf (stderr, "Specify file with a table");
|
||||
goto err;
|
||||
}
|
||||
/* load file contents
|
||||
*/
|
||||
if (!g_file_get_contents (fnameTable, &contents, NULL, &error))
|
||||
{
|
||||
g_printf ("Unable to read file: %s\n", error->message);
|
||||
goto err;
|
||||
}
|
||||
g_free (fnameTable);
|
||||
|
||||
g_assert ((contents == NULL && error != NULL)
|
||||
|| (contents != NULL && error == NULL));
|
||||
|
||||
/* parse TeX */
|
||||
doc = txr_parse (contents, &parse_error);
|
||||
|
||||
if (parse_error)
|
||||
{
|
||||
g_print ("Error parsing TeX document: %s\n", parse_error->message);
|
||||
goto err;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
puts ("TeX document successfully parsed\n");
|
||||
}
|
||||
|
||||
/* list all objects */
|
||||
g_printf ("list all objects\n");
|
||||
for (it = txr_glob_first (doc); it; it = txr_glob_iter_next (it))
|
||||
{
|
||||
g_printf ("%s\n", G_OBJECT_TYPE_NAME (*it));
|
||||
|
||||
if ( !g_strcmp0 ("TXRTabular", G_OBJECT_TYPE_NAME (*it))
|
||||
|| !g_strcmp0 ("TXRLongtable", G_OBJECT_TYPE_NAME (*it)))
|
||||
{
|
||||
TXRSubtable *subtable;
|
||||
TXRSubtableIter st_it;
|
||||
|
||||
if (!g_strcmp0 ("TXRTabular", G_OBJECT_TYPE_NAME (*it)))
|
||||
subtable = txr_tabular_get_table (TXR_TABULAR (*it));
|
||||
else
|
||||
subtable = txr_longtable_get_table (TXR_LONGTABLE (*it));
|
||||
|
||||
for (st_it = txr_subtable_first (subtable); st_it; st_it = txr_subtable_iter_next (st_it))
|
||||
{
|
||||
TXRRow *row = TXR_ROW (*st_it);
|
||||
TXRRowIter row_it;
|
||||
|
||||
for (row_it = txr_row_first (row); row_it; row_it = txr_row_iter_next (row_it))
|
||||
{
|
||||
TXRCell *cell = TXR_CELL (*row_it);
|
||||
TXRGlob *glob = txr_cell_get_contents (cell);
|
||||
TXRGlobIter glob_it;
|
||||
|
||||
for (glob_it = txr_glob_first (glob); glob_it; glob_it = txr_glob_iter_next (glob_it))
|
||||
{
|
||||
if (g_strcmp0 ("TXRText", G_OBJECT_TYPE_NAME (*glob_it)))
|
||||
g_printf (" %s\n", G_OBJECT_TYPE_NAME (*glob_it));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_printf ("end of objects\n\n");
|
||||
|
||||
/* walk through all objects */
|
||||
g_printf ("Walk through all objects\n");
|
||||
for (it = txr_glob_first (doc); it; it = txr_glob_iter_next (it))
|
||||
{
|
||||
g_printf ("%s\n", G_OBJECT_TYPE_NAME (*it));
|
||||
|
||||
if (!g_strcmp0 ("TXRGraphics", G_OBJECT_TYPE_NAME (*it)))
|
||||
{
|
||||
gdouble width = 0,
|
||||
height = 0;
|
||||
gchar *w_unit = NULL,
|
||||
*h_unit = NULL;
|
||||
TXRGraphics *graphics = txr_graphics_clone (TXR_GRAPHICS (*it));
|
||||
txr_graphics_get_size (graphics, &width, &w_unit, &height, &h_unit);
|
||||
gentext = txr_glob_gen ((TXRGlob *) graphics);
|
||||
g_printf (" width=%f%s, height=%f%s, path=%s,\n gen()=%s\n",
|
||||
width, w_unit, height, h_unit,
|
||||
txr_graphics_get_path (graphics),
|
||||
gentext);
|
||||
g_free (gentext);
|
||||
/* test txr_graphics_set_size () */
|
||||
txr_graphics_set_size (graphics, width / 2, "pt", height * 2, "dd");
|
||||
gentext = txr_glob_gen ((TXRGlob *) graphics);
|
||||
g_printf ("resized gen() = %s\n", gentext);
|
||||
g_free (gentext);
|
||||
txr_graphics_unref (graphics);
|
||||
g_free (w_unit);
|
||||
g_free (h_unit);
|
||||
}
|
||||
}
|
||||
g_printf ("end of objects\n\n");
|
||||
|
||||
/* generate plain-TeX document */
|
||||
generated = txr_glob_gen (doc);
|
||||
|
||||
/* load etalon file
|
||||
*/
|
||||
if (fnameEtalon)
|
||||
{
|
||||
g_free (contents);
|
||||
if (!g_file_get_contents (fnameEtalon, &contents, NULL, &error))
|
||||
{
|
||||
g_printf ("Unable to read file: %s\n", error->message);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
g_free (fnameEtalon);
|
||||
|
||||
if (!g_strcmp0 (contents, generated))
|
||||
g_printf ("Original and generated text are EQUAL ;-)\n");
|
||||
else
|
||||
g_printf ("Original and generated text are NOT EQUAL ;-(\n");
|
||||
|
||||
g_printf ("--- Generated plain-TeX (generated) ---\n%s", generated);
|
||||
|
||||
/* write to file */
|
||||
if (fnameWrite)
|
||||
g_file_set_contents (fnameWrite, generated, -1, NULL);
|
||||
g_free (fnameWrite);
|
||||
|
||||
err:
|
||||
//end:
|
||||
g_free (contents);
|
||||
g_free (generated);
|
||||
|
||||
if (parse_error)
|
||||
{
|
||||
g_error_free (parse_error);
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
txr_glob_unref (doc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
///@endcond
|
Loading…
Reference in New Issue