-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlpod_test
executable file
·385 lines (326 loc) · 10.9 KB
/
lpod_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/perl
#=============================================================================
# lpod_test lpOD-Perl installation test 2014-05-28T13:27:57
#=============================================================================
=head1 NAME
lpod_test - ODF::lpOD installation test
=head1 USAGE
lpod_test <filename>
=head1 SYNOPSIS
Sample script that displays a basic information about the current ODF::lpOD
installation.
A sample ODF text document is generated if a filename is provided as argument.
=cut
use 5.010_001;
use strict;
use warnings;
use ODF::lpOD;
#--- announcement ------------------------------------------------------------
say sprintf(
"ODF::lpOD %s (build %s) %s",
$ODF::lpOD::VERSION,
ODF::lpOD->PACKAGE_DATE,
lpod->installation_path
);
our $filename = $ARGV[0] or exit;
$filename .= '.odt' unless $filename =~ /\.odt$/;
say "Generating test document $filename";
#--- test parameters ---------------------------------------------------------
our $title = "lpOD test";
our $subject = "lpOD generated test document";
our %desc = (
"lpOD version" => $ODF::lpOD::VERSION,
"lpOD build date" => ODF::lpOD->PACKAGE_DATE,
"lpOD installation path" => lpod->installation_path,
"XML::Twig version" => $XML::Twig::VERSION,
"Archive::Zip version" => $Archive::Zip::VERSION,
"Perl version" => $],
"Platform" => $^O
);
our $announce =
"This document has been generated by the lpOD-Perl installation " .
"test program. The main characteristics of your environment are " .
"listed below.";
lpod->debug(TRUE);
my $elt;
#--- document initialization -------------------------------------------------
# Document creation check
my $doc = odf_document->create('text')
or die "# Document initialisation failure. Stopped";
# Main context access
my $context = $doc->body;
# Metadata access
my $meta = $doc->meta;
# Styles context access
my $styles = $doc->styles;
#--- metadata settings -------------------------------------------------------
$meta->set_generator(scalar lpod->info);
$meta->set_title($title);
$meta->set_subject($subject);
$meta->set_user_field("Project name", "lpOD", "string");
$meta->set_keywords("ODF", "Perl");
#--- paragraph style definitions ---------------------------------------------
# Default paragraph style creation
$elt = $doc->insert_style(
odf_create_style(
'paragraph',
align => 'justify',
margin_top => '2mm',
margin_bottom => '2mm',
orphans => 2,
widows => 2
),
default => TRUE
);
$elt->set_properties(
area => 'text',
language => 'none',
country => 'none'
);
# Basic paragraph style creation
$elt = $doc->insert_style(
odf_create_style(
'paragraph',
name => "Basic",
margin_top => "0mm",
margin_left => "0mm"
)
);
# Level 2 Heading style creation
my $heading_style = $doc->insert_style(
odf_create_style(
'paragraph',
name => "Level 2 Heading",
keep_with_next => 'always',
margin_top => '1cm',
margin_bottom => '4mm'
)
);
$heading_style->set_properties(
area => 'text',
size => '16pt',
weight => 'bold',
style => 'italic',
color => 'navy blue'
);
# top title style
$doc->insert_style(
odf_create_style(
'paragraph',
name => "Top title",
align => 'center',
margin_top => '0cm',
margin_bottom => '1cm'
)
)->set_properties(
area => 'text',
size => '200%',
weight => 'bold',
color => 'navy blue'
);
# middle title style
$doc->insert_style(
odf_create_style(
'paragraph',
name => "Middle title",
parent => "Top title",
margin_top => '1cm',
margin_bottom => '8mm',
master_page => 'StdMaster'
)
)->set_background(color => 'light blue');
# style for the labels in the left column
$doc->insert_style(
odf_create_style(
'paragraph',
name => "Label",
margin_left => "3mm"
)
)->set_properties(
area => 'text',
style => 'italic'
);
# style for the values in the right column
$doc->insert_style(
odf_create_style(
'paragraph',
name => "Content",
margin_left => "3mm"
)
)->set_properties(
area => 'text',
weight => 'bold'
);
# footer paragraph style
$doc->insert_style(
odf_create_style(
'paragraph',
name => "SmallCentered",
margin_top => "1mm",
margin_bottom => "0mm",
margin_left => "0mm",
margin_right => "0mm",
align => 'center'
)
)->set_properties(
area => 'text',
size => '70%'
);
# header subtitle style
$doc->insert_style(
odf_create_style(
'paragraph',
name => "LargeCentered",
align => 'center'
)
)->set_properties(
area => 'text',
size => '120%',
style => 'italic'
);
#--- table style definition --------------------------------------------------
# Table style creation
$elt = $doc->insert_style(
odf_create_style(
'table',
name => "Environment",
width => '90%',
align => 'center',
margin_top => '8mm'
)
);
$doc->insert_style(
odf_create_style(
'table column',
name => "C0",
width => "400*"
)
);
$doc->insert_style(
odf_create_style(
'table column',
name => "C1",
width => "600*"
)
);
$doc->insert_style(
odf_create_style(
'table cell',
name => "Sky"
)
)->set_background(color => '#E6F9FF');
#--- page style definition ---------------------------------------------------
# Page layout creation
$elt = $doc->insert_style(
odf_create_style(
'page layout',
name => "StdLayout",
size => "21cm, 29.7cm",
margin => "16mm"
)
);
# define the master page using the layout
# Master page creation
my $mp = $doc->insert_style(
odf_create_style(
'master page',
name => "StdMaster",
layout => "StdLayout"
)
);
# define a header and a footer for the master page
my $header = $mp->set_header;
my $footer = $mp->set_footer;
# Table creation in the page header
my $ht = $header->append_element(
odf_create_table("HeaderTable", size => "1, 2")
);
# Image frame creation
my $img_path = lpod->installation_path() . '/data/oasis_odf_logo.png';
my ($img, $size) = $doc->add_image_file($img_path);
my $fr = $ht->get_cell("A1")
->append_element(odf_create_paragraph(style => "Basic"))
->append_element(
odf_create_image_frame(
$img,
name => "Logo",
size => $size,
title => "OASIS ODF logo"
)
);
$fr->set_hyperlink(url => 'http://opendocument.xml.org');
# put 2 text paragraphs in the right cell of the table
$ht->get_cell("B1")->append_element(
odf_create_paragraph(
text => "The lpOD Project",
style => "Top title"
)
);
$ht->get_cell("B1")->append_element(
odf_create_paragraph(
text => "Open Document processing\nwith Perl",
style => "LargeCentered"
)
);
# put 2 centered paragraphs in the footer
$footer->append_element(
odf_create_paragraph(
text => "Generated with lpOD",
style => "SmallCentered"
)
);
$footer->append_element(
odf_create_paragraph(
text => scalar localtime,
style => "SmallCentered"
)
);
#--- document content providing ----------------------------------------------
# make sure that the document body is empty
$context->clear;
# put the main title
$context->append_element(
odf_create_heading(
level => 1,
text => "Installation test",
style => "Middle title"
)
);
# Paragraph creation in document body
$elt = $context->append_element(odf_create_paragraph(text => $announce));
# put a bookmark in the paragraph
$elt->set_bookmark("Announce");
# Table creation in the document body
my $tbl = $context->append_element(
odf_create_table(
"Environment",
length => scalar keys %desc,
width => 2,
style => "Environment"
)
);
# apply the appropriate style for each column
$tbl->get_column($_)->set_style("C$_") for (0..1);
$_->set_style("Sky") for $tbl->get_column('B')->get_cells;
# fill the table with the environment description
my $i = 0;
foreach my $k (sort keys %desc) {
$tbl->get_cell($i, 0)->append_element(
odf_create_paragraph(
text => $k,
style => "Label"
)
);
$tbl->get_cell($i, 1)->append_element(
odf_create_paragraph(
text => $desc{$k},
style => "Content"
)
);
$i++;
}
#=== COMMIT THE RESULT
# save the generated document and quit
$doc->save(target => $filename, pretty => TRUE);
exit;
#=== END