biblicit 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,336 +0,0 @@
1
- package Omni::Omnitable;
2
-
3
- # Configuration
4
- use strict;
5
-
6
- # Local libraries
7
- use Omni::Config;
8
- use Omni::Omnicell;
9
-
10
- # Extern libraries
11
- use XML::Twig;
12
- use XML::Parser;
13
-
14
- # Global variables
15
- my $tag_list = $Omni::Config::tag_list;
16
- my $att_list = $Omni::Config::att_list;
17
- my $obj_list = $Omni::Config::obj_list;
18
-
19
- ###
20
- # A table object in Omnipage xml: a table contains cells with various objects
21
- #
22
- # Do Hoang Nhat Huy, 11 Feb 2011
23
- ###
24
- # Initialization
25
- sub new
26
- {
27
- my ($class) = @_;
28
-
29
- # Objs: a table can have many cells
30
- my @objs = ();
31
-
32
- # Grid coordinates
33
- my @grid_cols = ();
34
- my @grid_rows = ();
35
-
36
- # Content of all rows in the table
37
- my @rcontent = ();
38
-
39
- # Class members
40
- my $self = { '_self' => $obj_list->{ 'OMNITABLE' },
41
- '_raw' => undef,
42
- '_content' => undef,
43
- '_rcontent' => \@rcontent,
44
- '_bottom' => undef,
45
- '_top' => undef,
46
- '_left' => undef,
47
- '_right' => undef,
48
- '_alignment' => undef,
49
- '_grid_cols' => \@grid_cols,
50
- '_grid_rows' => \@grid_rows,
51
- '_objs' => \@objs };
52
-
53
- bless $self, $class;
54
- return $self;
55
- }
56
-
57
- #
58
- sub set_raw
59
- {
60
- my ($self, $raw) = @_;
61
-
62
- # Save the raw xml <table> ... </table>
63
- $self->{ '_raw' } = $raw;
64
-
65
- # Parse the raw string
66
- my $twig_roots = { $tag_list->{ 'TABLE' } => 1 };
67
- my $twig_handlers = { $tag_list->{ 'TABLE' } => sub { parse(@_, \$self); } };
68
-
69
- # XML::Twig
70
- my $twig = new XML::Twig( twig_roots => $twig_roots,
71
- twig_handlers => $twig_handlers,
72
- pretty_print => 'indented' );
73
-
74
- # Start the XML parsing
75
- $twig->parse($raw, \$self);
76
- $twig->purge;
77
- }
78
-
79
- sub get_raw
80
- {
81
- my ($self) = @_;
82
- return $self->{ '_raw' };
83
- }
84
-
85
- sub parse
86
- {
87
- my ($twig, $node, $self) = @_;
88
-
89
- # At first, content is blank
90
- my $tmp_content = "";
91
- my @tmp_rcontent = ();
92
- # because there's no object
93
- my @tmp_objs = ();
94
- # and no coordinate
95
- my @tmp_grid_cols = ();
96
- my @tmp_grid_rows = ();
97
-
98
- # Get <table> node attributes
99
- my $tmp_bottom = GetNodeAttr($node, $att_list->{ 'BOTTOM' });
100
- my $tmp_top = GetNodeAttr($node, $att_list->{ 'TOP' });
101
- my $tmp_left = GetNodeAttr($node, $att_list->{ 'LEFT' });
102
- my $tmp_right = GetNodeAttr($node, $att_list->{ 'RIGHT' });
103
- my $tmp_alignment = GetNodeAttr($node, $att_list->{ 'ALIGN' });
104
-
105
- # A table contains <cell> and <gridtable> tag
106
- my $cell_tag = $tag_list->{ 'CELL' };
107
- my $grid_tag = $tag_list->{ 'GRID' };
108
- my $grid_col_tag = $tag_list->{ 'GRID-COL' };
109
- my $grid_row_tag = $tag_list->{ 'GRID-ROW' };
110
-
111
- my $child = undef;
112
- # Get the first child which is tha <gridtable>
113
- $child = $node->first_child( $grid_tag );
114
-
115
- # Grid table found, a formatted table
116
- if (defined $child)
117
- {
118
- # Get the first grid coordinate
119
- $child = $child->first_child();
120
-
121
- # Extract the grid coodinates
122
- while (defined $child)
123
- {
124
- my $xpath = $child->path();
125
-
126
- # if this child is a <gridCol> tag
127
- if ($xpath =~ m/\/$grid_col_tag$/)
128
- {
129
- push @tmp_grid_cols, GetNodeText( $child );
130
- }
131
- # if this child is a <gridRow> tag
132
- elsif ($xpath =~ m/\/$grid_row_tag$/)
133
- {
134
- push @tmp_grid_rows, GetNodeText( $child );
135
- }
136
-
137
- # Little brother
138
- if ($child->is_last_child)
139
- {
140
- last;
141
- }
142
- else
143
- {
144
- $child = $child->next_sibling();
145
- }
146
- }
147
- }
148
-
149
- # All cells
150
- my @all_cells = $node->descendants( $cell_tag );
151
- foreach my $cell (@all_cells)
152
- {
153
- my $obj = new Omni::Omnicell();
154
-
155
- # Set raw content
156
- $obj->set_raw($cell->sprint());
157
-
158
- # Update cell list
159
- push @tmp_objs, $obj;
160
-
161
- }
162
-
163
- # Unformatted table
164
- if ((scalar(@tmp_grid_cols) == 0) || (scalar(@tmp_grid_rows) == 0))
165
- {
166
- # Just append cell content
167
- foreach my $cell (@tmp_objs) { $tmp_content = $tmp_content . $cell->get_content() . "\n"; }
168
- }
169
- # Formatted table
170
- else
171
- {
172
- # Table content
173
- my @content_matrix = ();
174
-
175
- # Matrix initialization
176
- for(my $i = 0; $i < scalar(@tmp_grid_rows); $i++)
177
- {
178
- # Empty row
179
- my @row = ();
180
- # Update the row
181
- for(my $j = 0; $j < scalar(@tmp_grid_cols); $j++) { push @row, ""; }
182
- # Save the row
183
- push @content_matrix, [ @row ];
184
- }
185
-
186
- # Update table content
187
- foreach my $cell (@tmp_objs)
188
- {
189
- my $row_index = $cell->get_grid_row_from();
190
- my $col_index = $cell->get_grid_col_from();
191
-
192
- # Check index and update
193
- if (($row_index < scalar(@content_matrix)) && ($col_index < scalar(@{ $content_matrix[ $row_index ] })))
194
- {
195
- my $cell_content = undef;
196
- # Get content
197
- $cell_content = $cell->get_content();
198
- # Trim
199
- $cell_content =~ s/^\s+|\s+$//g;
200
- # Remove blank line
201
- $cell_content =~ s/\n\s*\n/\n/g;
202
-
203
- $content_matrix[ $row_index ][ $col_index ] = $cell_content;
204
- }
205
- }
206
-
207
- # Save content
208
- foreach my $row (@content_matrix)
209
- {
210
- # This is used to handle the case in which a cell have multiple lines
211
- my @lines = ();
212
- # Foreach cell in the row, get its content
213
- foreach my $cell (@{ $row })
214
- {
215
- my @local_lines = split /\n/, $cell;
216
- for (my $i = 0; $i < scalar(@local_lines); $i++)
217
- {
218
- if ($i == scalar(@lines)) { push @lines, ""; }
219
- $lines[ $i ] = $lines[ $i ] . $local_lines[ $i ] . "\t";
220
- }
221
- }
222
-
223
- my $row_content = "";
224
- # Add a new row to the table content and the row content
225
- foreach my $line (@lines)
226
- {
227
- $row_content = $row_content . $line . "\n";
228
- $tmp_content = $tmp_content . $line . "\n";
229
- }
230
-
231
- # Save row content
232
- push @tmp_rcontent, $row_content;
233
- }
234
- }
235
-
236
- # Copy information from temporary variables to class members
237
- $$self->{ '_bottom' } = $tmp_bottom;
238
- $$self->{ '_top' } = $tmp_top;
239
- $$self->{ '_left' } = $tmp_left;
240
- $$self->{ '_right' } = $tmp_right;
241
- $$self->{ '_alignment' } = $tmp_alignment;
242
-
243
- # Copy all cells
244
- @{$$self->{ '_objs' } } = @tmp_objs;
245
-
246
- # Copy all grid columns
247
- @{$$self->{ '_grid_cols' } } = @tmp_grid_cols;
248
- # Copy all grid rows
249
- @{$$self->{ '_grid_rows' } } = @tmp_grid_rows;
250
-
251
- # Copy content
252
- $$self->{ '_content' } = $tmp_content;
253
- # Copy row content
254
- @{ $$self->{ '_rcontent' } } = @tmp_rcontent;
255
- }
256
-
257
- sub get_name
258
- {
259
- my ($self) = @_;
260
- return $self->{ '_self' };
261
- }
262
-
263
- sub get_objs_ref
264
- {
265
- my ($self) = @_;
266
- return $self->{ '_objs' };
267
- }
268
-
269
- sub get_content
270
- {
271
- my ($self) = @_;
272
- return $self->{ '_content' };
273
- }
274
-
275
- sub get_row_content
276
- {
277
- my ($self) = @_;
278
- return $self->{ '_rcontent' };
279
- }
280
-
281
- sub get_bottom_pos
282
- {
283
- my ($self) = @_;
284
- return $self->{ '_bottom' };
285
- }
286
-
287
- sub get_top_pos
288
- {
289
- my ($self) = @_;
290
- return $self->{ '_top' };
291
- }
292
-
293
- sub get_left_pos
294
- {
295
- my ($self) = @_;
296
- return $self->{ '_left' };
297
- }
298
-
299
- sub get_right_pos
300
- {
301
- my ($self) = @_;
302
- return $self->{ '_right' };
303
- }
304
-
305
- sub get_alignment
306
- {
307
- my ($self) = @_;
308
- return $self->{ '_alignment' };
309
- }
310
-
311
- # Support functions
312
- sub GetNodeAttr
313
- {
314
- my ($node, $attr) = @_;
315
- return ($node->att($attr) ? $node->att($attr) : "");
316
- }
317
-
318
- sub SetNodeAttr
319
- {
320
- my ($node, $attr, $value) = @_;
321
- $node->set_att($attr, $value);
322
- }
323
-
324
- sub GetNodeText
325
- {
326
- my ($node) = @_;
327
- return $node->text;
328
- }
329
-
330
- sub SetNodeText
331
- {
332
- my ($node, $value) = @_;
333
- $node->set_text($value);
334
- }
335
-
336
- 1;
@@ -1,162 +0,0 @@
1
- package Omni::Omniword;
2
-
3
- # Configuration
4
- use strict;
5
-
6
- # Local libraries
7
- use Omni::Config;
8
- use Omni::Omnirun;
9
-
10
- # Extern libraries
11
- use XML::Twig;
12
- use XML::Parser;
13
-
14
- # Global variables
15
- my $tag_list = $Omni::Config::tag_list;
16
- my $att_list = $Omni::Config::att_list;
17
- my $obj_list = $Omni::Config::obj_list;
18
-
19
- # Temporary variables
20
- my $tmp_content = undef;
21
- my $tmp_bottom = undef;
22
- my $tmp_top = undef;
23
- my $tmp_left = undef;
24
- my $tmp_right = undef;
25
-
26
- ###
27
- # A word object in Omnipage xml: basic blocks of the xml
28
- #
29
- # Do Hoang Nhat Huy, 07 Jan 2011
30
- ###
31
- # Initialization
32
- sub new
33
- {
34
- my ($class) = @_;
35
-
36
- # Class members
37
- my $self = { '_self' => $obj_list->{ 'OMNIWORD' },
38
- '_raw' => undef,
39
- '_content' => undef,
40
- '_bottom' => undef,
41
- '_top' => undef,
42
- '_left' => undef,
43
- '_right' => undef };
44
-
45
- bless $self, $class;
46
- return $self;
47
- }
48
-
49
- #
50
- sub set_raw
51
- {
52
- my ($self, $raw) = @_;
53
-
54
- # Save the raw xml <wd> ... </wd>
55
- $self->{ '_raw' } = $raw;
56
-
57
- # Parse the raw string
58
- my $twig_roots = { $tag_list->{ 'WORD' } => 1 };
59
- my $twig_handlers = { $tag_list->{ 'WORD' } => \&parse};
60
-
61
- # XML::Twig
62
- my $twig = new XML::Twig( twig_roots => $twig_roots,
63
- twig_handlers => $twig_handlers,
64
- pretty_print => 'indented' );
65
-
66
- # Start the XML parsing
67
- $twig->parse($raw);
68
- $twig->purge;
69
-
70
- # Copy information from temporary variables to class members
71
- $self->{ '_bottom' } = $tmp_bottom;
72
- $self->{ '_top' } = $tmp_top;
73
- $self->{ '_left' } = $tmp_left;
74
- $self->{ '_right' } = $tmp_right;
75
-
76
- # Copy content
77
- $self->{ '_content' } = $tmp_content;
78
- }
79
-
80
- sub get_raw
81
- {
82
- my ($self) = @_;
83
- return $self->{ '_raw' };
84
- }
85
-
86
- sub parse
87
- {
88
- my ($twig, $node) = @_;
89
-
90
- # Get <run> node attributes
91
- $tmp_bottom = GetNodeAttr($node, $att_list->{ 'BOTTOM' });
92
- $tmp_top = GetNodeAttr($node, $att_list->{ 'TOP' });
93
- $tmp_left = GetNodeAttr($node, $att_list->{ 'LEFT' });
94
- $tmp_right = GetNodeAttr($node, $att_list->{ 'RIGHT' });
95
-
96
- # Get the word's content
97
- $tmp_content = GetNodeText($node);
98
- $tmp_content =~ s/^\s+|\s+$//g;
99
- }
100
-
101
- sub get_name
102
- {
103
- my ($self) = @_;
104
- return $self->{ '_self' };
105
- }
106
-
107
- sub get_content
108
- {
109
- my ($self) = @_;
110
- return $self->{ '_content' };
111
- }
112
-
113
- sub get_bottom_pos
114
- {
115
- my ($self) = @_;
116
- return $self->{ '_bottom' };
117
- }
118
-
119
- sub get_top_pos
120
- {
121
- my ($self) = @_;
122
- return $self->{ '_top' };
123
- }
124
-
125
- sub get_left_pos
126
- {
127
- my ($self) = @_;
128
- return $self->{ '_left' };
129
- }
130
-
131
- sub get_right_pos
132
- {
133
- my ($self) = @_;
134
- return $self->{ '_right' };
135
- }
136
-
137
- # Support functions
138
- sub GetNodeAttr
139
- {
140
- my ($node, $attr) = @_;
141
- return ($node->att($attr) ? $node->att($attr) : "");
142
- }
143
-
144
- sub SetNodeAttr
145
- {
146
- my ($node, $attr, $value) = @_;
147
- $node->set_att($attr, $value);
148
- }
149
-
150
- sub GetNodeText
151
- {
152
- my ($node) = @_;
153
- return $node->text;
154
- }
155
-
156
- sub SetNodeText
157
- {
158
- my ($node, $value) = @_;
159
- $node->set_text($value);
160
- }
161
-
162
- 1;