2014-03-13 00:17:48 -06:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2014-03-13 00:17:48 -06: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-13 00:17:48 -06:00
|
|
|
*/
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
namespace PhpOffice\PhpWord;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
2014-04-17 16:19:23 +07:00
|
|
|
* PHPWord settings class
|
|
|
|
|
*
|
|
|
|
|
* @since 0.8.0
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
class Settings
|
2014-03-13 20:58:24 +07:00
|
|
|
{
|
2014-05-01 18:37:34 +07:00
|
|
|
/**
|
|
|
|
|
* Zip libraries
|
2014-05-02 01:15:28 +07:00
|
|
|
*
|
|
|
|
|
* @const string
|
2014-05-01 18:37:34 +07:00
|
|
|
*/
|
2014-03-28 19:41:33 +07:00
|
|
|
const PCLZIP = 'PhpOffice\\PhpWord\\Shared\\ZipArchive';
|
2014-03-16 11:57:48 -06:00
|
|
|
const ZIPARCHIVE = 'ZipArchive';
|
|
|
|
|
|
2014-05-01 18:37:34 +07:00
|
|
|
/**
|
|
|
|
|
* PDF rendering libraries
|
2014-05-02 01:15:28 +07:00
|
|
|
*
|
|
|
|
|
* @const string
|
2014-05-01 18:37:34 +07:00
|
|
|
*/
|
2014-04-13 23:17:39 +07:00
|
|
|
const PDF_RENDERER_DOMPDF = 'DomPDF';
|
|
|
|
|
|
2014-05-01 18:37:34 +07:00
|
|
|
/**
|
|
|
|
|
* Measurement units multiplication factor
|
|
|
|
|
*
|
|
|
|
|
* Applied to:
|
|
|
|
|
* - Section: margins, header/footer height, gutter, column spacing
|
|
|
|
|
* - Tab: position
|
2014-05-02 13:39:56 +07:00
|
|
|
* - Indentation: left, right, firstLine, hanging
|
|
|
|
|
* - Spacing: before, after
|
2014-05-01 18:37:34 +07:00
|
|
|
*
|
|
|
|
|
* @const int|float
|
|
|
|
|
*/
|
|
|
|
|
const UNIT_TWIP = 1; // = 1/20 point
|
|
|
|
|
const UNIT_CM = 567;
|
|
|
|
|
const UNIT_MM = 56.7;
|
|
|
|
|
const UNIT_INCH = 1440;
|
|
|
|
|
const UNIT_POINT = 20; // = 1/72 inch
|
|
|
|
|
const UNIT_PICA = 240; // = 1/6 inch = 12 points
|
|
|
|
|
|
2014-03-13 00:17:48 -06:00
|
|
|
/**
|
|
|
|
|
* Compatibility option for XMLWriter
|
|
|
|
|
*
|
2014-05-01 18:37:34 +07:00
|
|
|
* @var bool
|
2014-03-13 00:17:48 -06:00
|
|
|
*/
|
2014-04-05 00:57:50 +07:00
|
|
|
private static $xmlWriterCompatibility = true;
|
2014-03-13 00:17:48 -06:00
|
|
|
|
2014-03-16 11:57:48 -06:00
|
|
|
/**
|
|
|
|
|
* Name of the class used for Zip file management
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-04-05 00:57:50 +07:00
|
|
|
private static $zipClass = self::ZIPARCHIVE;
|
2014-03-16 11:57:48 -06:00
|
|
|
|
2014-04-13 23:17:39 +07:00
|
|
|
/**
|
|
|
|
|
* Name of the classes used for PDF renderer
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
private static $pdfRenderers = array(self::PDF_RENDERER_DOMPDF);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name of the external Library used for rendering PDF files
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private static $pdfRendererName = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Directory Path to the external Library used for rendering PDF files
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private static $pdfRendererPath = null;
|
|
|
|
|
|
2014-05-01 18:37:34 +07:00
|
|
|
/**
|
|
|
|
|
* Measurement unit
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private static $measurementUnit = self::UNIT_TWIP;
|
|
|
|
|
|
2014-05-04 15:13:31 +07:00
|
|
|
/**
|
|
|
|
|
* Return the compatibility option used by the XMLWriter
|
|
|
|
|
*
|
|
|
|
|
* @return bool Compatibility
|
|
|
|
|
*/
|
|
|
|
|
public static function hasCompatibility()
|
|
|
|
|
{
|
|
|
|
|
return self::$xmlWriterCompatibility;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 00:17:48 -06:00
|
|
|
/**
|
|
|
|
|
* Set the compatibility option used by the XMLWriter
|
|
|
|
|
*
|
2014-05-01 18:37:34 +07:00
|
|
|
* This sets the setIndent and setIndentString for better compatibility
|
|
|
|
|
*
|
|
|
|
|
* @param bool $compatibility
|
|
|
|
|
* @return bool
|
2014-03-13 00:17:48 -06:00
|
|
|
*/
|
2014-03-13 20:58:24 +07:00
|
|
|
public static function setCompatibility($compatibility)
|
|
|
|
|
{
|
2014-03-13 00:17:48 -06:00
|
|
|
if (is_bool($compatibility)) {
|
2014-04-05 00:57:50 +07:00
|
|
|
self::$xmlWriterCompatibility = $compatibility;
|
2014-03-13 20:58:24 +07:00
|
|
|
return true;
|
2014-03-13 00:17:48 -06:00
|
|
|
}
|
2014-05-01 18:37:34 +07:00
|
|
|
|
2014-03-13 20:58:24 +07:00
|
|
|
return false;
|
2014-03-15 09:27:48 -04:00
|
|
|
}
|
2014-03-13 00:17:48 -06:00
|
|
|
|
|
|
|
|
/**
|
2014-05-04 15:13:31 +07:00
|
|
|
* Get zip handler class
|
2014-03-13 00:17:48 -06:00
|
|
|
*
|
2014-05-04 15:13:31 +07:00
|
|
|
* @return string
|
2014-03-13 00:17:48 -06:00
|
|
|
*/
|
2014-05-04 15:13:31 +07:00
|
|
|
public static function getZipClass()
|
2014-03-13 20:58:24 +07:00
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
return self::$zipClass;
|
2014-03-15 09:27:48 -04:00
|
|
|
}
|
2014-03-16 11:57:48 -06:00
|
|
|
|
|
|
|
|
/**
|
2014-05-01 18:37:34 +07:00
|
|
|
* Set zip handler class
|
2014-03-16 11:57:48 -06:00
|
|
|
*
|
2014-05-01 18:37:34 +07:00
|
|
|
* @param string $zipClass
|
|
|
|
|
* @return bool
|
2014-03-16 11:57:48 -06:00
|
|
|
*/
|
|
|
|
|
public static function setZipClass($zipClass)
|
|
|
|
|
{
|
|
|
|
|
if (($zipClass === self::PCLZIP) ||
|
|
|
|
|
($zipClass === self::ZIPARCHIVE)) {
|
2014-04-05 00:57:50 +07:00
|
|
|
self::$zipClass = $zipClass;
|
2014-03-28 19:41:33 +07:00
|
|
|
return true;
|
2014-03-16 11:57:48 -06:00
|
|
|
}
|
2014-05-01 18:37:34 +07:00
|
|
|
|
2014-03-28 19:41:33 +07:00
|
|
|
return false;
|
2014-04-13 23:17:39 +07:00
|
|
|
}
|
2014-03-16 11:57:48 -06:00
|
|
|
|
2014-04-13 23:17:39 +07:00
|
|
|
/**
|
|
|
|
|
* Set details of the external library for rendering PDF files
|
|
|
|
|
*
|
|
|
|
|
* @param string $libraryName
|
|
|
|
|
* @param string $libraryBaseDir
|
2014-05-01 18:37:34 +07:00
|
|
|
* @return bool Success or failure
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
|
|
|
|
public static function setPdfRenderer($libraryName, $libraryBaseDir)
|
|
|
|
|
{
|
|
|
|
|
if (!self::setPdfRendererName($libraryName)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::setPdfRendererPath($libraryBaseDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the PDF Rendering Library
|
|
|
|
|
*/
|
|
|
|
|
public static function getPdfRendererName()
|
|
|
|
|
{
|
|
|
|
|
return self::$pdfRendererName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Identify the external library to use for rendering PDF files
|
|
|
|
|
*
|
|
|
|
|
* @param string $libraryName
|
2014-05-01 18:37:34 +07:00
|
|
|
* @return bool
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
|
|
|
|
public static function setPdfRendererName($libraryName)
|
|
|
|
|
{
|
|
|
|
|
if (!in_array($libraryName, self::$pdfRenderers)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
self::$pdfRendererName = $libraryName;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the directory path to the PDF Rendering Library
|
|
|
|
|
*/
|
|
|
|
|
public static function getPdfRendererPath()
|
|
|
|
|
{
|
|
|
|
|
return self::$pdfRendererPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Location of external library to use for rendering PDF files
|
|
|
|
|
*
|
|
|
|
|
* @param string $libraryBaseDir Directory path to the library's base folder
|
2014-05-01 18:37:34 +07:00
|
|
|
* @return bool Success or failure
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
|
|
|
|
public static function setPdfRendererPath($libraryBaseDir)
|
|
|
|
|
{
|
|
|
|
|
if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
self::$pdfRendererPath = $libraryBaseDir;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-05-01 18:37:34 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get measurement unit
|
|
|
|
|
*
|
|
|
|
|
* @return int|float
|
|
|
|
|
*/
|
|
|
|
|
public static function getMeasurementUnit()
|
|
|
|
|
{
|
|
|
|
|
return self::$measurementUnit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set measurement unit
|
|
|
|
|
*
|
|
|
|
|
* @param int|float $value
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function setMeasurementUnit($value)
|
|
|
|
|
{
|
|
|
|
|
$units = array(self::UNIT_TWIP, self::UNIT_CM, self::UNIT_MM, self::UNIT_INCH, self::UNIT_POINT, self::UNIT_PICA);
|
|
|
|
|
if (!in_array($value, $units)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
self::$measurementUnit = $value;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-05-04 15:13:31 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the compatibility option used by the XMLWriter
|
|
|
|
|
*
|
|
|
|
|
* @deprecated 0.10.0
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
|
|
|
|
public static function getCompatibility()
|
|
|
|
|
{
|
|
|
|
|
return self::hasCompatibility();
|
|
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|