Document.java

1
/*
2
 * $Id: Document.java 4106 2009-11-27 12:59:39Z blowagie $
3
 *
4
 * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
50
package com.lowagie.text;
51
52
import com.lowagie.text.error_messages.MessageLocalization;
53
54
import java.text.SimpleDateFormat;
55
import java.util.ArrayList;
56
import java.util.Date;
57
import java.util.List;
58
59
60
/**
61
 * A generic Document class.
62
 * <P>
63
 * All kinds of Text-elements can be added to a <CODE>HTMLDocument</CODE>.
64
 * The <CODE>Document</CODE> signals all the listeners when an element has
65
 * been added.
66
 * <P>
67
 * Remark:
68
 * <OL>
69
 *     <LI>Once a document is created you can add some meta information.
70
 *     <LI>You can also set the headers/footers.
71
 *     <LI>You have to open the document before you can write content.
72
 * <LI>You can only write content (no more meta-formation!) once a document is
73
 * opened.
74
 * <LI>When you change the header/footer on a certain page, this will be
75
 * effective starting on the next page.
76
 * <LI>After closing the document, every listener (as well as its <CODE>
77
 * OutputStream</CODE>) is closed too.
78
 * </OL>
79
 * Example: <BLOCKQUOTE>
80
 *
81
 * <PRE>// creation of the document with a certain size and certain margins
82
 * <STRONG>Document document = new Document(PageSize.A4, 50, 50, 50, 50);
83
 * </STRONG> try { 
84
 *   // creation of the different writers 
85
 *   HtmlWriter.getInstance(<STRONG>document </STRONG>, System.out);
86
 *   PdfWriter.getInstance(<STRONG>document </STRONG>, new FileOutputStream("text.pdf"));
87
 *   // we add some meta information to the document
88
 *   <STRONG>document.addAuthor("Bruno Lowagie"); </STRONG>
89
 *   <STRONG>document.addSubject("This is the result of a Test."); </STRONG>
90
 *   // we open the document for writing
91
 *   <STRONG>document.open(); </STRONG>
92
 *   <STRONG>document.add(new Paragraph("Hello world"));</STRONG>
93
 *  } catch(DocumentException de) {
94
 *   System.err.println(de.getMessage());
95
 *  }
96
 *  <STRONG>document.close();</STRONG>
97
 * </PRE>
98
 * 
99
 * </BLOCKQUOTE>
100
 */
101
102
public class Document implements AutoCloseable, DocListener {
103
    
104
    // membervariables
105
    /**
106
     * @since    2.1.6
107
     */
108
    private static final String OPENPDF = "OpenPDF";
109
    /**
110
     * @since    2.1.6
111
     */
112
    private static final String RELEASE = VersionBean.VERSION.getImplementationVersion();
113
    private static final String OPENPDF_VERSION = OPENPDF + " " + RELEASE;
114
    
115
    /**
116
     * Allows the pdf documents to be produced without compression for debugging
117
     * purposes.
118
     */
119
    public static boolean compress = true; 
120
    
121
    /**
122
     * When true the file access is not done through a memory mapped file. Use it if the file
123
     * is too big to be mapped in your address space.
124
     */
125
    public static boolean plainRandomAccess = false; 
126
 
127
    /** Scales the WMF font size. The default value is 0.86. */
128
    public static float wmfFontCorrection = 0.86f;
129
    
130
    /** The DocListener. */
131
    private List<DocListener> listeners = new ArrayList<>();
132
    
133
    /** Is the document open or not? */
134
    protected boolean open;
135
    
136
    /** Has the document already been closed? */
137
    protected boolean close;
138
    
139
    // membervariables concerning the layout
140
    
141
    /** The size of the page. */
142
    protected Rectangle pageSize;
143
    
144
    /** margin in x direction starting from the left */
145
    protected float marginLeft = 0;
146
    
147
    /** margin in x direction starting from the right */
148
    protected float marginRight = 0;
149
    
150
    /** margin in y direction starting from the top */
151
    protected float marginTop = 0;
152
    
153
    /** margin in y direction starting from the bottom */
154
    protected float marginBottom = 0;
155
    
156
    /** mirroring of the left/right margins */
157
    protected boolean marginMirroring = false;
158
    
159
    /**
160
     * mirroring of the top/bottom margins
161
     * @since    2.1.6
162
     */
163
    protected boolean marginMirroringTopBottom = false;
164
    
165
    /** Content of JavaScript onLoad function */
166
    protected String javaScript_onLoad = null;
167
168
    /** Content of JavaScript onUnLoad function */
169
    protected String javaScript_onUnLoad = null;
170
171
    /** Style class in HTML body tag */
172
    protected String htmlStyleClass = null;
173
174
    // headers, footers
175
    
176
    /** Current pagenumber */
177
    protected int pageN = 0;
178
    
179
    /** This is the textual part of a Page; it can contain a header */
180
    protected HeaderFooter header = null;
181
    
182
    /** This is the textual part of the footer */
183
    protected HeaderFooter footer = null;
184
    
185
    /** This is a chapter number in case ChapterAutoNumber is used. */
186
    protected int chapternumber = 0;
187
    
188
    // constructor
189
190
    /**
191
     * Constructs a new <CODE>Document</CODE> -object.
192
     */
193
    public Document() {
194
        this(PageSize.A4);
195
    }
196
197
    /**
198
     * Constructs a new <CODE>Document</CODE> -object.
199
     *
200
     * @param pageSize
201
     *            the pageSize
202
     */
203
    public Document(Rectangle pageSize) {
204
        this(pageSize, 36, 36, 36, 36);
205
    }
206
207
    /**
208
     * Constructs a new <CODE>Document</CODE> -object.
209
     *
210
     * @param pageSize
211
     *            the pageSize
212
     * @param marginLeft
213
     *            the margin on the left
214
     * @param marginRight
215
     *            the margin on the right
216
     * @param marginTop
217
     *            the margin on the top
218
     * @param marginBottom
219
     *            the margin on the bottom
220
     */
221
    public Document(Rectangle pageSize, float marginLeft, float marginRight,
222
            float marginTop, float marginBottom) {
223
        this.pageSize = pageSize;
224
        this.marginLeft = marginLeft;
225
        this.marginRight = marginRight;
226
        this.marginTop = marginTop;
227
        this.marginBottom = marginBottom;
228
    }
229
    
230
    // listener methods
231
232
    /**
233
     * Adds a <CODE>DocListener</CODE> to the <CODE>Document</CODE>.
234
     *
235
     * @param listener
236
     *            the new DocListener.
237
     */
238
    public void addDocListener(DocListener listener) {
239
        listeners.add(listener);
240
    }
241
242
    /**
243
     * Removes a <CODE>DocListener</CODE> from the <CODE>Document</CODE>.
244
     *
245
     * @param listener
246
     *            the DocListener that has to be removed.
247
     */
248
    public void removeDocListener(DocListener listener) {
249
        listeners.remove(listener);
250
    }
251
    
252
    // methods implementing the DocListener interface
253
254
    /**
255
     * Adds an <CODE>Element</CODE> to the <CODE>Document</CODE>.
256
     *
257
     * @param element
258
     *            the <CODE>Element</CODE> to add
259
     * @return <CODE>true</CODE> if the element was added, <CODE>false
260
     *         </CODE> if not
261
     * @throws DocumentException
262
     *             when a document isn't open yet, or has been closed
263
     */
264
    public boolean add(Element element) throws DocumentException {
265 1 1. add : negated conditional → KILLED
        if (close) {
266
            throw new DocumentException(MessageLocalization.getComposedMessage("the.document.has.been.closed.you.can.t.add.any.elements"));
267
        }
268 2 1. add : negated conditional → SURVIVED
2. add : negated conditional → KILLED
        if (!open && element.isContent()) {
269
            throw new DocumentException(MessageLocalization.getComposedMessage("the.document.is.not.open.yet.you.can.only.add.meta.information"));
270
        }
271
        boolean success = false;
272 1 1. add : negated conditional → KILLED
        if (element instanceof ChapterAutoNumber) {
273
            chapternumber = ((ChapterAutoNumber)element).setAutomaticNumber(chapternumber);
274
        }
275
        for (DocListener listener : listeners) {
276 1 1. add : Replaced bitwise OR with AND → NO_COVERAGE
            success |= listener.add(element);
277
        }
278 1 1. add : negated conditional → SURVIVED
        if (element instanceof LargeElement) {
279
            LargeElement e = (LargeElement)element;
280 1 1. add : negated conditional → SURVIVED
            if (!e.isComplete())
281 1 1. add : removed call to com/lowagie/text/LargeElement::flushContent → NO_COVERAGE
                e.flushContent();
282
        }
283 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED
        return success;
284
    }
285
286
    /**
287
     * Opens the document.
288
     * <P>
289
     * Once the document is opened, you can't write any Header- or
290
     * Meta-information anymore. You have to open the document before you can
291
     * begin to add content to the body of the document.
292
     */
293
    public void open() {
294 1 1. open : negated conditional → KILLED
        if (!close) {
295
            open = true;
296
        }
297
        for (DocListener listener : listeners) {
298
            listener.setPageSize(pageSize);
299
            listener.setMargins(marginLeft, marginRight, marginTop,
300
                    marginBottom);
301 1 1. open : removed call to com/lowagie/text/DocListener::open → NO_COVERAGE
            listener.open();
302
        }
303
    }
304
    
305
    /**
306
 * Sets the pagesize.
307
 *
308
     * @param pageSize
309
     *            the new pagesize
310
 * @return    a <CODE>boolean</CODE>
311
 */
312
    public boolean setPageSize(Rectangle pageSize) {
313
        this.pageSize = pageSize;
314
        for (DocListener listener : listeners) {
315
            listener.setPageSize(pageSize);
316
        }
317 1 1. setPageSize : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return true;
318
    }
319
    
320
    /**
321
 * Sets the margins.
322
 *
323
     * @param marginLeft
324
     *            the margin on the left
325
     * @param marginRight
326
     *            the margin on the right
327
     * @param marginTop
328
     *            the margin on the top
329
     * @param marginBottom
330
     *            the margin on the bottom
331
 * @return    a <CODE>boolean</CODE>
332
 */
333
    public boolean setMargins(float marginLeft, float marginRight,
334
            float marginTop, float marginBottom) {
335
        this.marginLeft = marginLeft;
336
        this.marginRight = marginRight;
337
        this.marginTop = marginTop;
338
        this.marginBottom = marginBottom;
339
        for (DocListener listener : listeners) {
340
            listener.setMargins(marginLeft, marginRight, marginTop,
341
                    marginBottom);
342
        }
343 1 1. setMargins : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return true;
344
    }
345
    
346
    /**
347
 * Signals that an new page has to be started.
348
 *
349
     * @return <CODE>true</CODE> if the page was added, <CODE>false</CODE>
350
     *         if not.
351
 */
352
    public boolean newPage() {
353 2 1. newPage : negated conditional → NO_COVERAGE
2. newPage : negated conditional → NO_COVERAGE
        if (!open || close) {
354 1 1. newPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return false;
355
        }
356
        for (DocListener listener : listeners) {
357
            listener.newPage();
358
        }
359 1 1. newPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return true;
360
    }
361
    
362
    /**
363
 * Changes the header of this document.
364
 *
365
     * @param header
366
     *            the new header
367
 */
368
    public void setHeader(HeaderFooter header) {
369
        this.header = header;
370
        for (DocListener listener : listeners) {
371 1 1. setHeader : removed call to com/lowagie/text/DocListener::setHeader → NO_COVERAGE
            listener.setHeader(header);
372
        }
373
    }
374
    
375
    /**
376
 * Resets the header of this document.
377
 */
378
    public void resetHeader() {
379
        this.header = null;
380
        for (DocListener listener : listeners) {
381 1 1. resetHeader : removed call to com/lowagie/text/DocListener::resetHeader → NO_COVERAGE
            listener.resetHeader();
382
        }
383
    }
384
    
385
    /**
386
 * Changes the footer of this document.
387
 *
388
     * @param footer
389
     *            the new footer
390
 */
391
    public void setFooter(HeaderFooter footer) {
392
        this.footer = footer;
393
        for (DocListener listener : listeners) {
394 1 1. setFooter : removed call to com/lowagie/text/DocListener::setFooter → NO_COVERAGE
            listener.setFooter(footer);
395
        }
396
    }
397
398
    /**
399
     * Resets the footer of this document.
400
     */
401
    public void resetFooter() {
402
        this.footer = null;
403
        for (DocListener listener : listeners) {
404 1 1. resetFooter : removed call to com/lowagie/text/DocListener::resetFooter → NO_COVERAGE
            listener.resetFooter();
405
        }
406
    }
407
408
    /**
409
     * Sets the page number to 0.
410
     */
411
    public void resetPageCount() {
412
        pageN = 0;
413
        for (DocListener listener : listeners) {
414 1 1. resetPageCount : removed call to com/lowagie/text/DocListener::resetPageCount → NO_COVERAGE
            listener.resetPageCount();
415
        }
416
    }
417
418
    /**
419
     * Sets the page number.
420
     *
421
     * @param pageN the new page number
422
     */
423
    public void setPageCount(int pageN) {
424
        this.pageN = pageN;
425
        for (DocListener listener : listeners) {
426 1 1. setPageCount : removed call to com/lowagie/text/DocListener::setPageCount → NO_COVERAGE
            listener.setPageCount(pageN);
427
        }
428
    }
429
430
    /**
431
     * Returns the current page number.
432
     *
433
     * @return the current page number
434
     */
435
    public int getPageNumber() {
436
        return this.pageN;
437
    }
438
439
    /**
440
     * Closes the document.
441
     * <p>
442
     * Once all the content has been written in the body, you have to close the
443
     * body. After that nothing can be written to the body anymore.
444
     */
445
    @Override
446
    public void close() {
447 1 1. close : negated conditional → NO_COVERAGE
        if (!close) {
448
            open = false;
449
            close = true;
450
        }
451
        for (DocListener listener : listeners) {
452 1 1. close : removed call to com/lowagie/text/DocListener::close → NO_COVERAGE
            listener.close();
453
        }
454
    }
455
456
    // methods concerning the header or some meta information
457
    
458
    /**
459
 * Adds a user defined header to the document.
460
 *
461
     * @param name
462
     *            the name of the header
463
     * @param content
464
     *            the content of the header
465
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
466
 */
467
    
468
    public boolean addHeader(String name, String content) {
469
        try {
470 1 1. addHeader : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Header(name, content));
471
        } catch (DocumentException de) {
472
            throw new ExceptionConverter(de);
473
        }
474
    }
475
    
476
    /**
477
 * Adds the title to a Document.
478
 *
479
     * @param title
480
     *            the title
481
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
482
 */
483
    
484
    public boolean addTitle(String title) {
485
        try {
486 1 1. addTitle : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Meta(Element.TITLE, title));
487
        } catch (DocumentException de) {
488
            throw new ExceptionConverter(de);
489
        }
490
    }
491
    
492
    /**
493
 * Adds the subject to a Document.
494
 *
495
     * @param subject
496
     *            the subject
497
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
498
 */
499
    
500
    public boolean addSubject(String subject) {
501
        try {
502 1 1. addSubject : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Meta(Element.SUBJECT, subject));
503
        } catch (DocumentException de) {
504
            throw new ExceptionConverter(de);
505
        }
506
    }
507
    
508
    /**
509
 * Adds the keywords to a Document.
510
 *
511
     * @param keywords
512
     *            adds the keywords to the document
513
 * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
514
 */
515
    
516
    public boolean addKeywords(String keywords) {
517
        try {
518 1 1. addKeywords : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Meta(Element.KEYWORDS, keywords));
519
        } catch (DocumentException de) {
520
            throw new ExceptionConverter(de);
521
        }
522
    }
523
    
524
    /**
525
 * Adds the author to a Document.
526
 *
527
     * @param author
528
     *            the name of the author
529
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
530
 */
531
    
532
    public boolean addAuthor(String author) {
533
        try {
534 1 1. addAuthor : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Meta(Element.AUTHOR, author));
535
        } catch (DocumentException de) {
536
            throw new ExceptionConverter(de);
537
        }
538
    }
539
    
540
    /**
541
 * Adds the creator to a Document.
542
 *
543
     * @param creator
544
     *            the name of the creator
545
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
546
 */
547
    
548
    public boolean addCreator(String creator) {
549
        try {
550 1 1. addCreator : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Meta(Element.CREATOR, creator));
551
        } catch (DocumentException de) {
552
            throw new ExceptionConverter(de);
553
        }
554
    }
555
    
556
    /**
557
 * Adds the producer to a Document.
558
 *
559
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
560
 */
561
    
562
    public boolean addProducer() {
563 1 1. addProducer : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return this.addProducer(getVersion());
564
    }
565
566
    /**
567
     * Adds the provided value as the producer to a Document.
568
     *
569
     * @param producer new producer line value
570
     * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
571
     */
572
    public boolean addProducer(final String producer) {
573 1 1. addProducer : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return add(new Meta(Element.PRODUCER, producer));
574
    }
575
    
576
    /**
577
 * Adds the current date and time to a Document.
578
 *
579
 * @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
580
 */
581
    
582
    public boolean addCreationDate() {
583
        try {
584
            /* bugfix by 'taqua' (Thomas) */
585
            final SimpleDateFormat sdf = new SimpleDateFormat(
586
                    "EEE MMM dd HH:mm:ss zzz yyyy");
587 1 1. addCreationDate : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return add(new Meta(Element.CREATIONDATE, sdf.format(new Date())));
588
        } catch (DocumentException de) {
589
            throw new ExceptionConverter(de);
590
        }
591
    }
592
    
593
    // methods to get the layout of the document.
594
    
595
    /**
596
 * Returns the left margin.
597
 *
598
 * @return    the left margin
599
 */
600
    
601
    public float leftMargin() {
602
        return marginLeft;
603
    }
604
    
605
    /**
606
 * Return the right margin.
607
 *
608
 * @return    the right margin
609
 */
610
    
611
    public float rightMargin() {
612
        return marginRight;
613
    }
614
    
615
    /**
616
 * Returns the top margin.
617
 *
618
 * @return    the top margin
619
 */
620
    
621
    public float topMargin() {
622
        return marginTop;
623
    }
624
    
625
    /**
626
 * Returns the bottom margin.
627
 *
628
 * @return    the bottom margin
629
 */
630
    
631
    public float bottomMargin() {
632
        return marginBottom;
633
    }
634
    
635
    /**
636
 * Returns the lower left x-coordinate.
637
 *
638
 * @return    the lower left x-coordinate
639
 */
640
    
641
    public float left() {
642 1 1. left : replaced return of float value with -(x + 1) for com/lowagie/text/Document::left → NO_COVERAGE
        return pageSize.getLeft(marginLeft);
643
    }
644
    
645
    /**
646
 * Returns the upper right x-coordinate.
647
 *
648
 * @return    the upper right x-coordinate
649
 */
650
    
651
    public float right() {
652 1 1. right : replaced return of float value with -(x + 1) for com/lowagie/text/Document::right → NO_COVERAGE
        return pageSize.getRight(marginRight);
653
    }
654
    
655
    /**
656
 * Returns the upper right y-coordinate.
657
 *
658
 * @return    the upper right y-coordinate
659
 */
660
    
661
    public float top() {
662 1 1. top : replaced return of float value with -(x + 1) for com/lowagie/text/Document::top → NO_COVERAGE
        return pageSize.getTop(marginTop);
663
    }
664
    
665
    /**
666
 * Returns the lower left y-coordinate.
667
 *
668
 * @return    the lower left y-coordinate
669
 */
670
    
671
    public float bottom() {
672 1 1. bottom : replaced return of float value with -(x + 1) for com/lowagie/text/Document::bottom → NO_COVERAGE
        return pageSize.getBottom(marginBottom);
673
    }
674
    
675
    /**
676
 * Returns the lower left x-coordinate considering a given margin.
677
 *
678
     * @param margin
679
     *            a margin
680
 * @return    the lower left x-coordinate
681
 */
682
    
683
    public float left(float margin) {
684 2 1. left : Replaced float addition with subtraction → NO_COVERAGE
2. left : replaced return of float value with -(x + 1) for com/lowagie/text/Document::left → NO_COVERAGE
        return pageSize.getLeft(marginLeft + margin);
685
    }
686
    
687
    /**
688
 * Returns the upper right x-coordinate, considering a given margin.
689
 *
690
     * @param margin
691
     *            a margin
692
 * @return    the upper right x-coordinate
693
 */
694
    
695
    public float right(float margin) {
696 2 1. right : Replaced float addition with subtraction → NO_COVERAGE
2. right : replaced return of float value with -(x + 1) for com/lowagie/text/Document::right → NO_COVERAGE
        return pageSize.getRight(marginRight + margin);
697
    }
698
    
699
    /**
700
 * Returns the upper right y-coordinate, considering a given margin.
701
 *
702
     * @param margin
703
     *            a margin
704
 * @return    the upper right y-coordinate
705
 */
706
    
707
    public float top(float margin) {
708 2 1. top : Replaced float addition with subtraction → NO_COVERAGE
2. top : replaced return of float value with -(x + 1) for com/lowagie/text/Document::top → NO_COVERAGE
        return pageSize.getTop(marginTop + margin);
709
    }
710
    
711
    /**
712
 * Returns the lower left y-coordinate, considering a given margin.
713
 *
714
     * @param margin
715
     *            a margin
716
 * @return    the lower left y-coordinate
717
 */
718
    
719
    public float bottom(float margin) {
720 2 1. bottom : Replaced float addition with subtraction → NO_COVERAGE
2. bottom : replaced return of float value with -(x + 1) for com/lowagie/text/Document::bottom → NO_COVERAGE
        return pageSize.getBottom(marginBottom + margin);
721
    }
722
    
723
    /**
724
 * Gets the pagesize.
725
     * 
726
 * @return the page size
727
 */
728
    
729
    public Rectangle getPageSize() {
730
        return this.pageSize;
731
    }
732
    
733
    /**
734
     * Checks if the document is open.
735
     * 
736
     * @return <CODE>true</CODE> if the document is open
737
     */    
738
    public boolean isOpen() {
739
        return open;
740
    }
741
742
    /**
743
     * Gets the product name.
744
     *
745
     * @return the product name
746
     * @since 2.1.6
747
     */
748
    public static String getProduct() {
749
        return OPENPDF;
750
    }
751
752
    /**
753
     * Gets the release number.
754
     *
755
     * @return the product name
756
     * @since 2.1.6
757
     */
758
    public static String getRelease() {
759
        return RELEASE;
760
    }
761
762
    /**
763
     * Gets the iText version.
764
     *
765
     * @return iText version
766
     */
767
    public static String getVersion() {
768
        return OPENPDF_VERSION;
769
    }
770
771
    /**
772
 * Adds a JavaScript onLoad function to the HTML body tag
773
 *
774
     * @param code
775
     *            the JavaScript code to be executed on load of the HTML page
776
 */
777
    
778
    public void setJavaScript_onLoad(String code) {
779
        this.javaScript_onLoad = code;
780
    }
781
782
    /**
783
 * Gets the JavaScript onLoad command.
784
     * 
785
 * @return the JavaScript onLoad command
786
 */
787
788
    public String getJavaScript_onLoad() {
789
        return this.javaScript_onLoad;
790
    }
791
792
    /**
793
 * Adds a JavaScript onUnLoad function to the HTML body tag
794
 *
795
     * @param code
796
     *            the JavaScript code to be executed on unload of the HTML page
797
 */
798
    
799
    public void setJavaScript_onUnLoad(String code) {
800
        this.javaScript_onUnLoad = code;
801
    }
802
803
    /**
804
 * Gets the JavaScript onUnLoad command.
805
     * 
806
 * @return the JavaScript onUnLoad command
807
 */
808
809
    public String getJavaScript_onUnLoad() {
810
        return this.javaScript_onUnLoad;
811
    }
812
813
    /**
814
 * Adds a style class to the HTML body tag
815
 *
816
     * @param htmlStyleClass
817
     *            the style class for the HTML body tag
818
 */
819
    
820
    public void setHtmlStyleClass(String htmlStyleClass) {
821
        this.htmlStyleClass = htmlStyleClass;
822
    }
823
824
    /**
825
 * Gets the style class of the HTML body tag
826
 *
827
 * @return        the style class of the HTML body tag
828
 */
829
    
830
    public String getHtmlStyleClass() {
831
        return this.htmlStyleClass;
832
    }
833
    
834
    /**
835
     * Set the margin mirroring. It will mirror right/left margins for odd/even pages.
836
     * <p>
837
     * Note: it will not work with {@link Table}.
838
     * 
839
     * @param marginMirroring
840
     *            <CODE>true</CODE> to mirror the margins
841
     * @return always <CODE>true</CODE>
842
     */    
843
    public boolean setMarginMirroring(boolean marginMirroring) {
844
        this.marginMirroring = marginMirroring;
845
        for (DocListener listener : listeners) {
846
            listener.setMarginMirroring(marginMirroring);
847
        }
848 1 1. setMarginMirroring : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return true;
849
    }
850
    
851
    /**
852
     * Set the margin mirroring. It will mirror top/bottom margins for odd/even pages.
853
     * <p>
854
     * Note: it will not work with {@link Table}.
855
     * 
856
     * @param marginMirroringTopBottom
857
     *            <CODE>true</CODE> to mirror the margins
858
     * @return always <CODE>true</CODE>
859
     * @since    2.1.6
860
     */    
861
    public boolean setMarginMirroringTopBottom(boolean marginMirroringTopBottom) {
862
        this.marginMirroringTopBottom = marginMirroringTopBottom;
863
        for (DocListener listener : listeners) {
864
            listener.setMarginMirroringTopBottom(marginMirroringTopBottom);
865
        }
866 1 1. setMarginMirroringTopBottom : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return true;
867
    }
868
    
869
    /**
870
     * Gets the margin mirroring flag.
871
     * 
872
     * @return the margin mirroring flag
873
     */    
874
    public boolean isMarginMirroring() {
875
        return marginMirroring;
876
    }
877
}

Mutations

265

1.1
Location : add
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

268

1.1
Location : add
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

2.2
Location : add
Killed by : none
negated conditional → SURVIVED

272

1.1
Location : add
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

276

1.1
Location : add
Killed by : none
Replaced bitwise OR with AND → NO_COVERAGE

278

1.1
Location : add
Killed by : none
negated conditional → SURVIVED

280

1.1
Location : add
Killed by : none
negated conditional → SURVIVED

281

1.1
Location : add
Killed by : none
removed call to com/lowagie/text/LargeElement::flushContent → NO_COVERAGE

283

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED

294

1.1
Location : open
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

301

1.1
Location : open
Killed by : none
removed call to com/lowagie/text/DocListener::open → NO_COVERAGE

317

1.1
Location : setPageSize
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

343

1.1
Location : setMargins
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

353

1.1
Location : newPage
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : newPage
Killed by : none
negated conditional → NO_COVERAGE

354

1.1
Location : newPage
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

359

1.1
Location : newPage
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

371

1.1
Location : setHeader
Killed by : none
removed call to com/lowagie/text/DocListener::setHeader → NO_COVERAGE

381

1.1
Location : resetHeader
Killed by : none
removed call to com/lowagie/text/DocListener::resetHeader → NO_COVERAGE

394

1.1
Location : setFooter
Killed by : none
removed call to com/lowagie/text/DocListener::setFooter → NO_COVERAGE

404

1.1
Location : resetFooter
Killed by : none
removed call to com/lowagie/text/DocListener::resetFooter → NO_COVERAGE

414

1.1
Location : resetPageCount
Killed by : none
removed call to com/lowagie/text/DocListener::resetPageCount → NO_COVERAGE

426

1.1
Location : setPageCount
Killed by : none
removed call to com/lowagie/text/DocListener::setPageCount → NO_COVERAGE

447

1.1
Location : close
Killed by : none
negated conditional → NO_COVERAGE

452

1.1
Location : close
Killed by : none
removed call to com/lowagie/text/DocListener::close → NO_COVERAGE

470

1.1
Location : addHeader
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

486

1.1
Location : addTitle
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

502

1.1
Location : addSubject
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

518

1.1
Location : addKeywords
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

534

1.1
Location : addAuthor
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

550

1.1
Location : addCreator
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

563

1.1
Location : addProducer
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

573

1.1
Location : addProducer
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

587

1.1
Location : addCreationDate
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

642

1.1
Location : left
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::left → NO_COVERAGE

652

1.1
Location : right
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::right → NO_COVERAGE

662

1.1
Location : top
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::top → NO_COVERAGE

672

1.1
Location : bottom
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::bottom → NO_COVERAGE

684

1.1
Location : left
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

2.2
Location : left
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::left → NO_COVERAGE

696

1.1
Location : right
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

2.2
Location : right
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::right → NO_COVERAGE

708

1.1
Location : top
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

2.2
Location : top
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::top → NO_COVERAGE

720

1.1
Location : bottom
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

2.2
Location : bottom
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Document::bottom → NO_COVERAGE

848

1.1
Location : setMarginMirroring
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

866

1.1
Location : setMarginMirroringTopBottom
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2