2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Shared;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Common drawing functions
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
class Drawing
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Convert pixels to EMU
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Value in pixels
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return double Value in EMU
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function pixelsToEMU($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
return round($value * 9525);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert EMU to pixels
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Value in EMU
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return integer Value in pixels
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function emuToPixels($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($value != 0) {
|
|
|
|
|
return round($value / 9525);
|
2014-03-22 10:06:08 +04:00
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert pixels to points
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Value in pixels
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return double Value in points
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function pixelsToPoints($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-11 09:16:36 +02:00
|
|
|
return $value * 0.75;
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert points width to pixels
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Value in points
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return integer Value in pixels
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function pointsToPixels($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($value != 0) {
|
|
|
|
|
return $value * 1.333333333;
|
2014-03-22 10:06:08 +04:00
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert degrees to angle
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Degrees
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return integer Angle
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function degreesToAngle($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
return (integer)round($value * 60000);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert angle to degrees
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Angle
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return integer Degrees
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function angleToDegrees($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($value != 0) {
|
|
|
|
|
return round($value / 60000);
|
2014-03-22 10:06:08 +04:00
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert pixels to centimeters
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Value in pixels
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return double Value in centimeters
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function pixelsToCentimeters($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-10 23:52:10 +02:00
|
|
|
return $value * 0.026458333;
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert centimeters width to pixels
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param integer $value Value in centimeters
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return integer Value in pixels
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function centimetersToPixels($value = 0)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($value != 0) {
|
2014-05-10 23:52:10 +02:00
|
|
|
return $value / 0.026458333;
|
2014-03-22 10:06:08 +04:00
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert HTML hexadecimal to RGB
|
|
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @param string $value HTML Color in hexadecimal
|
2014-04-04 00:29:57 +07:00
|
|
|
* @return array Value in RGB
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function htmlToRGB($value)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($value[0] == '#') {
|
|
|
|
|
$value = substr($value, 1);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
2014-05-04 15:13:31 +07:00
|
|
|
if (strlen($value) == 6) {
|
|
|
|
|
list($red, $green, $blue) = array($value[0] . $value[1], $value[2] . $value[3], $value[4] . $value[5]);
|
|
|
|
|
} elseif (strlen($value) == 3) {
|
|
|
|
|
list($red, $green, $blue) = array($value[0] . $value[0], $value[1] . $value[1], $value[2] . $value[2]);
|
2014-03-22 10:06:08 +04:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-04 15:13:31 +07:00
|
|
|
$red = hexdec($red);
|
|
|
|
|
$green = hexdec($green);
|
|
|
|
|
$blue = hexdec($blue);
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-05-04 15:13:31 +07:00
|
|
|
return array($red, $green, $blue);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
}
|