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 | /** |
44 | * @param bool $finishPage |
45 | */ |
46 | public function finish( $finishPage = true ) { |
47 | if ( $finishPage ) { |
48 | $this->finishPage(); |
49 | } |
50 | |
51 | if ( !$this->metadata['page_data'] ) { |
52 | $this->metadata['errors'][] = 'no page data found in tiff directory!'; |
53 | return; |
54 | } |
55 | |
56 | if ( !isset( $this->metadata['page_count'] ) ) { |
57 | $this->metadata['page_count'] = count( $this->metadata['page_data'] ); |
58 | } |
59 | |
60 | if ( !isset( $this->metadata['first_page'] ) ) { |
61 | $this->metadata['first_page'] = min( array_keys( $this->metadata['page_data'] ) ); |
62 | } |
63 | |
64 | if ( !isset( $this->metadata['last_page'] ) ) { |
65 | $this->metadata['last_page'] = max( array_keys( $this->metadata['page_data'] ) ); |
66 | } |
67 | } |
68 | |
69 | public function resetPage() { |
70 | $this->page = []; |
71 | } |
72 | |
73 | public function finishPage() { |
74 | if ( !isset( $this->page['page'] ) ) { |
75 | $this->page['page'] = $this->prevPage + 1; |
76 | } else { |
77 | if ( $this->prevPage >= $this->page['page'] ) { |
78 | $this->metadata['errors'][] = "inconsistent page numbering in TIFF directory"; |
79 | return false; |
80 | } |
81 | } |
82 | |
83 | if ( isset( $this->page['width'] ) && isset( $this->page['height'] ) ) { |
84 | $this->prevPage = max( $this->prevPage, $this->page['page'] ); |
85 | |
86 | if ( !isset( $this->page['alpha'] ) ) { |
87 | $this->page['alpha'] = 'false'; |
88 | } |
89 | |
90 | $this->page['pixels'] = $this->page['height'] * $this->page['width']; |
91 | $this->metadata['page_data'][$this->page['page']] = $this->page; |
92 | } |
93 | |
94 | $this->page = []; |
95 | return true; |
96 | } |
97 | |
98 | /** |
99 | * @param string $key |
100 | * @param mixed $value |
101 | */ |
102 | public function setPageProperty( $key, $value ) { |
103 | $this->page[$key] = $value; |
104 | } |
105 | |
106 | /** |
107 | * @param string $key |
108 | * @return bool |
109 | */ |
110 | public function hasPageProperty( $key ) { |
111 | return isset( $this->page[$key] ) && $this->page[$key] !== null; |
112 | } |
113 | |
114 | /** |
115 | * @param string $key |
116 | * @param mixed $value |
117 | */ |
118 | public function setFileProperty( $key, $value ) { |
119 | $this->metadata[$key] = $value; |
120 | } |
121 | |
122 | /** |
123 | * @param string $key |
124 | * @param mixed $value |
125 | * @return bool |
126 | */ |
127 | public function hasFileProperty( $key, $value ) { |
128 | return isset( $this->metadata[$key] ) && $this->metadata[$key] !== null; |
129 | } |
130 | |
131 | /** |
132 | * @param string $message |
133 | */ |
134 | public function addError( $message ) { |
135 | $this->metadata['errors'][] = $message; |
136 | } |
137 | |
138 | /** |
139 | * @param string $message |
140 | */ |
141 | public function addWarning( $message ) { |
142 | $this->metadata['warnings'][] = $message; |
143 | } |
144 | |
145 | /** |
146 | * @return array |
147 | */ |
148 | public function getMetadata() { |
149 | return $this->metadata; |
150 | } |
151 | |
152 | /** |
153 | * @return bool |
154 | */ |
155 | public function hasErrors() { |
156 | return !empty( $this->metadata['errors'] ); |
157 | } |
158 | } |