~begerega/ihris-chw-sl/trunk

« back to all changes in this revision

Viewing changes to tools/PHPExcel/PHPExcel/Worksheet/HeaderFooterDrawing.php

  • Committer: Ese Egerega
  • Date: 2018-05-03 14:17:04 UTC
  • Revision ID: egerega@gmail.com-20180503141704-3br8dto013rgx65x
Initial import of Sierra Leone  CHW registry

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * PHPExcel_Worksheet_HeaderFooterDrawing
 
5
 *
 
6
 * Copyright (c) 2006 - 2015 PHPExcel
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2.1 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this library; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 * @category   PHPExcel
 
23
 * @package    PHPExcel_Worksheet
 
24
 * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
 
25
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 
26
 * @version    ##VERSION##, ##DATE##
 
27
 */
 
28
class PHPExcel_Worksheet_HeaderFooterDrawing extends PHPExcel_Worksheet_Drawing implements PHPExcel_IComparable
 
29
{
 
30
    /**
 
31
     * Path
 
32
     *
 
33
     * @var string
 
34
     */
 
35
    private $path;
 
36
 
 
37
    /**
 
38
     * Name
 
39
     *
 
40
     * @var string
 
41
     */
 
42
    protected $name;
 
43
 
 
44
    /**
 
45
     * Offset X
 
46
     *
 
47
     * @var int
 
48
     */
 
49
    protected $offsetX;
 
50
 
 
51
    /**
 
52
     * Offset Y
 
53
     *
 
54
     * @var int
 
55
     */
 
56
    protected $offsetY;
 
57
 
 
58
    /**
 
59
     * Width
 
60
     *
 
61
     * @var int
 
62
     */
 
63
    protected $width;
 
64
 
 
65
    /**
 
66
     * Height
 
67
     *
 
68
     * @var int
 
69
     */
 
70
    protected $height;
 
71
 
 
72
    /**
 
73
     * Proportional resize
 
74
     *
 
75
     * @var boolean
 
76
     */
 
77
    protected $resizeProportional;
 
78
 
 
79
    /**
 
80
     * Create a new PHPExcel_Worksheet_HeaderFooterDrawing
 
81
     */
 
82
    public function __construct()
 
83
    {
 
84
        // Initialise values
 
85
        $this->path                = '';
 
86
        $this->name                = '';
 
87
        $this->offsetX             = 0;
 
88
        $this->offsetY             = 0;
 
89
        $this->width               = 0;
 
90
        $this->height              = 0;
 
91
        $this->resizeProportional  = true;
 
92
    }
 
93
 
 
94
    /**
 
95
     * Get Name
 
96
     *
 
97
     * @return string
 
98
     */
 
99
    public function getName()
 
100
    {
 
101
        return $this->name;
 
102
    }
 
103
 
 
104
    /**
 
105
     * Set Name
 
106
     *
 
107
     * @param string $pValue
 
108
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
109
     */
 
110
    public function setName($pValue = '')
 
111
    {
 
112
        $this->name = $pValue;
 
113
        return $this;
 
114
    }
 
115
 
 
116
    /**
 
117
     * Get OffsetX
 
118
     *
 
119
     * @return int
 
120
     */
 
121
    public function getOffsetX()
 
122
    {
 
123
        return $this->offsetX;
 
124
    }
 
125
 
 
126
    /**
 
127
     * Set OffsetX
 
128
     *
 
129
     * @param int $pValue
 
130
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
131
     */
 
132
    public function setOffsetX($pValue = 0)
 
133
    {
 
134
        $this->offsetX = $pValue;
 
135
        return $this;
 
136
    }
 
137
 
 
138
    /**
 
139
     * Get OffsetY
 
140
     *
 
141
     * @return int
 
142
     */
 
143
    public function getOffsetY()
 
144
    {
 
145
        return $this->offsetY;
 
146
    }
 
147
 
 
148
    /**
 
149
     * Set OffsetY
 
150
     *
 
151
     * @param int $pValue
 
152
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
153
     */
 
154
    public function setOffsetY($pValue = 0)
 
155
    {
 
156
        $this->offsetY = $pValue;
 
157
        return $this;
 
158
    }
 
159
 
 
160
    /**
 
161
     * Get Width
 
162
     *
 
163
     * @return int
 
164
     */
 
165
    public function getWidth()
 
166
    {
 
167
        return $this->width;
 
168
    }
 
169
 
 
170
    /**
 
171
     * Set Width
 
172
     *
 
173
     * @param int $pValue
 
174
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
175
     */
 
176
    public function setWidth($pValue = 0)
 
177
    {
 
178
        // Resize proportional?
 
179
        if ($this->resizeProportional && $pValue != 0) {
 
180
            $ratio = $this->width / $this->height;
 
181
            $this->height = round($ratio * $pValue);
 
182
        }
 
183
 
 
184
        // Set width
 
185
        $this->width = $pValue;
 
186
 
 
187
        return $this;
 
188
    }
 
189
 
 
190
    /**
 
191
     * Get Height
 
192
     *
 
193
     * @return int
 
194
     */
 
195
    public function getHeight()
 
196
    {
 
197
        return $this->height;
 
198
    }
 
199
 
 
200
    /**
 
201
     * Set Height
 
202
     *
 
203
     * @param int $pValue
 
204
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
205
     */
 
206
    public function setHeight($pValue = 0)
 
207
    {
 
208
        // Resize proportional?
 
209
        if ($this->resizeProportional && $pValue != 0) {
 
210
            $ratio = $this->width / $this->height;
 
211
            $this->width = round($ratio * $pValue);
 
212
        }
 
213
 
 
214
        // Set height
 
215
        $this->height = $pValue;
 
216
 
 
217
        return $this;
 
218
    }
 
219
 
 
220
    /**
 
221
     * Set width and height with proportional resize
 
222
     * Example:
 
223
     * <code>
 
224
     * $objDrawing->setResizeProportional(true);
 
225
     * $objDrawing->setWidthAndHeight(160,120);
 
226
     * </code>
 
227
     *
 
228
     * @author Vincent@luo MSN:kele_100@hotmail.com
 
229
     * @param int $width
 
230
     * @param int $height
 
231
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
232
     */
 
233
    public function setWidthAndHeight($width = 0, $height = 0)
 
234
    {
 
235
        $xratio = $width / $this->width;
 
236
        $yratio = $height / $this->height;
 
237
        if ($this->resizeProportional && !($width == 0 || $height == 0)) {
 
238
            if (($xratio * $this->height) < $height) {
 
239
                $this->height = ceil($xratio * $this->height);
 
240
                $this->width  = $width;
 
241
            } else {
 
242
                $this->width    = ceil($yratio * $this->width);
 
243
                $this->height    = $height;
 
244
            }
 
245
        }
 
246
        return $this;
 
247
    }
 
248
 
 
249
    /**
 
250
     * Get ResizeProportional
 
251
     *
 
252
     * @return boolean
 
253
     */
 
254
    public function getResizeProportional()
 
255
    {
 
256
        return $this->resizeProportional;
 
257
    }
 
258
 
 
259
    /**
 
260
     * Set ResizeProportional
 
261
     *
 
262
     * @param boolean $pValue
 
263
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
264
     */
 
265
    public function setResizeProportional($pValue = true)
 
266
    {
 
267
        $this->resizeProportional = $pValue;
 
268
        return $this;
 
269
    }
 
270
 
 
271
    /**
 
272
     * Get Filename
 
273
     *
 
274
     * @return string
 
275
     */
 
276
    public function getFilename()
 
277
    {
 
278
        return basename($this->path);
 
279
    }
 
280
 
 
281
    /**
 
282
     * Get Extension
 
283
     *
 
284
     * @return string
 
285
     */
 
286
    public function getExtension()
 
287
    {
 
288
        $parts = explode(".", basename($this->path));
 
289
        return end($parts);
 
290
    }
 
291
 
 
292
    /**
 
293
     * Get Path
 
294
     *
 
295
     * @return string
 
296
     */
 
297
    public function getPath()
 
298
    {
 
299
        return $this->path;
 
300
    }
 
301
 
 
302
    /**
 
303
     * Set Path
 
304
     *
 
305
     * @param     string         $pValue            File path
 
306
     * @param     boolean        $pVerifyFile    Verify file
 
307
     * @throws     PHPExcel_Exception
 
308
     * @return PHPExcel_Worksheet_HeaderFooterDrawing
 
309
     */
 
310
    public function setPath($pValue = '', $pVerifyFile = true)
 
311
    {
 
312
        if ($pVerifyFile) {
 
313
            if (file_exists($pValue)) {
 
314
                $this->path = $pValue;
 
315
 
 
316
                if ($this->width == 0 && $this->height == 0) {
 
317
                    // Get width/height
 
318
                    list($this->width, $this->height) = getimagesize($pValue);
 
319
                }
 
320
            } else {
 
321
                throw new PHPExcel_Exception("File $pValue not found!");
 
322
            }
 
323
        } else {
 
324
            $this->path = $pValue;
 
325
        }
 
326
        return $this;
 
327
    }
 
328
 
 
329
    /**
 
330
     * Get hash code
 
331
     *
 
332
     * @return string    Hash code
 
333
     */
 
334
    public function getHashCode()
 
335
    {
 
336
        return md5(
 
337
            $this->path .
 
338
            $this->name .
 
339
            $this->offsetX .
 
340
            $this->offsetY .
 
341
            $this->width .
 
342
            $this->height .
 
343
            __CLASS__
 
344
        );
 
345
    }
 
346
 
 
347
    /**
 
348
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
 
349
     */
 
350
    public function __clone()
 
351
    {
 
352
        $vars = get_object_vars($this);
 
353
        foreach ($vars as $key => $value) {
 
354
            if (is_object($value)) {
 
355
                $this->$key = clone $value;
 
356
            } else {
 
357
                $this->$key = $value;
 
358
            }
 
359
        }
 
360
    }
 
361
}