2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
2014-05-04 17:55:54 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
|
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-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Value in pixels
|
|
|
|
|
* @return double Value in EMU
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function pixelsToEMU($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
return round($pValue * 9525);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert EMU to pixels
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Value in EMU
|
|
|
|
|
* @return integer Value in pixels
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function EMUToPixels($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
if ($pValue != 0) {
|
|
|
|
|
return round($pValue / 9525);
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert pixels to points
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Value in pixels
|
|
|
|
|
* @return double Value in points
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function pixelsToPoints($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
return $pValue * 0.67777777;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert points width to pixels
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Value in points
|
|
|
|
|
* @return integer Value in pixels
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function pointsToPixels($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
if ($pValue != 0) {
|
|
|
|
|
return $pValue * 1.333333333;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert degrees to angle
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Degrees
|
|
|
|
|
* @return integer Angle
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function degreesToAngle($pValue = 0)
|
|
|
|
|
{
|
2014-04-04 00:29:57 +07:00
|
|
|
return (integer)round($pValue * 60000);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert angle to degrees
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Angle
|
|
|
|
|
* @return integer Degrees
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function angleToDegrees($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
if ($pValue != 0) {
|
|
|
|
|
return round($pValue / 60000);
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert pixels to centimeters
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Value in pixels
|
|
|
|
|
* @return double Value in centimeters
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function pixelsToCentimeters($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
return $pValue * 0.028;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert centimeters width to pixels
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param integer $pValue Value in centimeters
|
|
|
|
|
* @return integer Value in pixels
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function centimetersToPixels($pValue = 0)
|
|
|
|
|
{
|
|
|
|
|
if ($pValue != 0) {
|
|
|
|
|
return $pValue / 0.028;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert HTML hexadecimal to RGB
|
|
|
|
|
*
|
2014-04-04 00:29:57 +07:00
|
|
|
* @param string $pValue HTML Color in hexadecimal
|
|
|
|
|
* @return array Value in RGB
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public static function htmlToRGB($pValue)
|
|
|
|
|
{
|
|
|
|
|
if ($pValue[0] == '#') {
|
|
|
|
|
$pValue = substr($pValue, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen($pValue) == 6) {
|
|
|
|
|
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
|
|
|
|
|
} elseif (strlen($pValue) == 3) {
|
|
|
|
|
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$color_R = hexdec($color_R);
|
|
|
|
|
$color_G = hexdec($color_G);
|
|
|
|
|
$color_B = hexdec($color_B);
|
|
|
|
|
|
|
|
|
|
return array($color_R, $color_G, $color_B);
|
|
|
|
|
}
|
|
|
|
|
}
|