Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / lsolesen / pel / src / PelEntryVersion.php
1 <?php
2
3 /**
4  * PEL: PHP Exif Library.
5  * A library with support for reading and
6  * writing all Exif headers in JPEG and TIFF images using PHP.
7  *
8  * Copyright (C) 2004, 2005 Martin Geisler.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program in the file COPYING; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301 USA
24  */
25 namespace lsolesen\pel;
26
27 /**
28  * Classes used to hold data for Exif tags of format undefined.
29  *
30  * This file contains the base class {@link PelEntryUndefined} and
31  * the subclasses {@link PelEntryUserComment} which should be used
32  * to manage the {@link PelTag::USER_COMMENT} tag, and {@link
33  * PelEntryVersion} which is used to manage entries with version
34  * information.
35  *
36  * @author Martin Geisler <mgeisler@users.sourceforge.net>
37  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
38  *          License (GPL)
39  * @package PEL
40  */
41
42 /**
43  * Class to hold version information.
44  *
45  * There are three Exif entries that hold version information: the
46  * {@link PelTag::EXIF_VERSION}, {@link
47  * PelTag::FLASH_PIX_VERSION}, and {@link
48  * PelTag::INTEROPERABILITY_VERSION} tags. This class manages
49  * those tags.
50  *
51  * The class is used in a very straight-forward way:
52  * <code>
53  * $entry = new PelEntryVersion(PelTag::EXIF_VERSION, 2.2);
54  * </code>
55  * This creates an entry for an file complying to the Exif 2.2
56  * standard. It is easy to test for standards level of an unknown
57  * entry:
58  * <code>
59  * if ($entry->getTag() == PelTag::EXIF_VERSION &&
60  * $entry->getValue() > 2.0) {
61  * echo 'Recent Exif version.';
62  * }
63  * </code>
64  *
65  * @author Martin Geisler <mgeisler@users.sourceforge.net>
66  * @package PEL
67  */
68 class PelEntryVersion extends PelEntry
69 {
70
71     /**
72      * The version held by this entry.
73      *
74      * @var float
75      */
76     private $version;
77
78     /**
79      * Make a new entry for holding a version.
80      *
81      * @param integer $tag
82      *            This should be one of {@link
83      *            PelTag::EXIF_VERSION}, {@link PelTag::FLASH_PIX_VERSION},
84      *            or {@link PelTag::INTEROPERABILITY_VERSION}.
85      *
86      * @param float $version
87      *            The size of the entries leave room for
88      *            exactly four digits: two digits on either side of the decimal
89      *            point.
90      */
91     public function __construct($tag, $version = 0.0)
92     {
93         $this->tag = $tag;
94         $this->format = PelFormat::UNDEFINED;
95         $this->setValue($version);
96     }
97
98     /**
99      * Set the version held by this entry.
100      *
101      * @param float $version
102      *            The size of the entries leave room for
103      *            exactly four digits: two digits on either side of the decimal
104      *            point.
105      */
106     public function setValue($version = 0.0)
107     {
108         $this->version = $version;
109         $major = floor($version);
110         $minor = ($version - $major) * 100;
111         $strValue = sprintf('%02.0f%02.0f', $major, $minor);
112         $this->components = strlen($strValue);
113         $this->bytes = $strValue;
114     }
115
116     /**
117      * Return the version held by this entry.
118      *
119      * @return float This will be the same as the value
120      *         given to {@link setValue} or {@link __construct the
121      *         constructor}.
122      */
123     public function getValue()
124     {
125         return $this->version;
126     }
127
128     /**
129      * Return a text string with the version.
130      *
131      * @param boolean $brief
132      *            controls if the output should be brief. Brief
133      *            output omits the word 'Version' so the result is just 'Exif x.y'
134      *            instead of 'Exif Version x.y' if the entry holds information
135      *            about the Exif version --- the output for FlashPix is similar.
136      *
137      * @return string the version number with the type of the tag,
138      *         either 'Exif' or 'FlashPix'.
139      */
140     public function getText($brief = false)
141     {
142         $v = $this->version;
143
144         /*
145          * Versions numbers like 2.0 would be output as just 2 if we don't
146          * add the '.0' ourselves.
147          */
148         if (floor($this->version) == $this->version) {
149             $v .= '.0';
150         }
151
152         switch ($this->tag) {
153             case PelTag::EXIF_VERSION:
154                 if ($brief) {
155                     return Pel::fmt('Exif %s', $v);
156                 } else {
157                     return Pel::fmt('Exif Version %s', $v);
158                 }
159                 break;
160             case PelTag::FLASH_PIX_VERSION:
161                 if ($brief) {
162                     return Pel::fmt('FlashPix %s', $v);
163                 } else {
164                     return Pel::fmt('FlashPix Version %s', $v);
165                 }
166                 break;
167             case PelTag::INTEROPERABILITY_VERSION:
168                 if ($brief) {
169                     return Pel::fmt('Interoperability %s', $v);
170                 } else {
171                     return Pel::fmt('Interoperability Version %s', $v);
172                 }
173                 break;
174         }
175
176         if ($brief) {
177             return $v;
178         } else {
179             return Pel::fmt('Version %s', $v);
180         }
181     }
182 }