Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
PagedTiffInfoParserState | |
0.00% |
0 / 37 |
|
0.00% |
0 / 12 |
600 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
finish | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |||
resetPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
finishPage | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
setPageProperty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasPageProperty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
setFileProperty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasFileProperty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
addError | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addWarning | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMetadata | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasErrors | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Copyright © Wikimedia Deutschland, 2009 |
4 | * Authors Hallo Welt! Medienwerkstatt GmbH |
5 | * Authors Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; if not, write to the Free Software Foundation, Inc., |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * http://www.gnu.org/copyleft/gpl.html |
21 | */ |
22 | |
23 | namespace MediaWiki\Extension\PagedTiffHandler; |
24 | |
25 | class PagedTiffInfoParserState { |
26 | /** @var array All data */ |
27 | public $metadata; |
28 | |
29 | /** @var array Current page */ |
30 | public $page; |
31 | |
32 | /** @var int */ |
33 | public $prevPage; |
34 | |
35 | public function __construct() { |
36 | $this->metadata = []; |
37 | $this->page = []; |
38 | $this->prevPage = 0; |
39 | |
40 | $this->metadata['page_data'] = []; |
41 | } |
42 | |
43 | public function finish( $finishPage = true ) { |
44 | if ( $finishPage ) { |
45 | $this->finishPage(); |
46 | } |
47 | |
48 | if ( !$this->metadata['page_data'] ) { |
49 | $this->metadata['errors'][] = 'no page data found in tiff directory!'; |
50 | return; |
51 | } |
52 | |
53 | if ( !isset( $this->metadata['page_count'] ) ) { |
54 | $this->metadata['page_count'] = count( $this->metadata['page_data'] ); |
55 | } |
56 | |
57 | if ( !isset( $this->metadata['first_page'] ) ) { |
58 | $this->metadata['first_page'] = min( array_keys( $this->metadata['page_data'] ) ); |
59 | } |
60 | |
61 | if ( !isset( $this->metadata['last_page'] ) ) { |
62 | $this->metadata['last_page'] = max( array_keys( $this->metadata['page_data'] ) ); |
63 | } |
64 | } |
65 | |
66 | public function resetPage() { |
67 | $this->page = []; |
68 | } |
69 | |
70 | public function finishPage() { |
71 | if ( !isset( $this->page['page'] ) ) { |
72 | $this->page['page'] = $this->prevPage + 1; |
73 | } else { |
74 | if ( $this->prevPage >= $this->page['page'] ) { |
75 | $this->metadata['errors'][] = "inconsistent page numbering in TIFF directory"; |
76 | return false; |
77 | } |
78 | } |
79 | |
80 | if ( isset( $this->page['width'] ) && isset( $this->page['height'] ) ) { |
81 | $this->prevPage = max( $this->prevPage, $this->page['page'] ); |
82 | |
83 | if ( !isset( $this->page['alpha'] ) ) { |
84 | $this->page['alpha'] = 'false'; |
85 | } |
86 | |
87 | $this->page['pixels'] = $this->page['height'] * $this->page['width']; |
88 | $this->metadata['page_data'][$this->page['page']] = $this->page; |
89 | } |
90 | |
91 | $this->page = []; |
92 | return true; |
93 | } |
94 | |
95 | public function setPageProperty( $key, $value ) { |
96 | $this->page[$key] = $value; |
97 | } |
98 | |
99 | public function hasPageProperty( $key ) { |
100 | return isset( $this->page[$key] ) && $this->page[$key] !== null; |
101 | } |
102 | |
103 | public function setFileProperty( $key, $value ) { |
104 | $this->metadata[$key] = $value; |
105 | } |
106 | |
107 | public function hasFileProperty( $key, $value ) { |
108 | return isset( $this->metadata[$key] ) && $this->metadata[$key] !== null; |
109 | } |
110 | |
111 | public function addError( $message ) { |
112 | $this->metadata['errors'][] = $message; |
113 | } |
114 | |
115 | public function addWarning( $message ) { |
116 | $this->metadata['warnings'][] = $message; |
117 | } |
118 | |
119 | public function getMetadata() { |
120 | return $this->metadata; |
121 | } |
122 | |
123 | public function hasErrors() { |
124 | return !empty( $this->metadata['errors'] ); |
125 | } |
126 | } |