2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2012-05-06 18:25:40 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
namespace PhpOffice\PhpWord;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Style\Font;
|
2014-03-30 18:51:25 +07:00
|
|
|
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Table of contents
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
class TOC
|
|
|
|
|
{
|
2013-12-11 14:45:44 -05:00
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Title elements
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
private static $_titles = array();
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* TOC style
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-03-30 18:51:25 +07:00
|
|
|
* @var TOCStyle
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
private static $_styleTOC;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Font style
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-03-30 18:51:25 +07:00
|
|
|
* @var Font|array|string
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
private static $_styleFont;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Title anchor
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-03-28 13:50:53 +07:00
|
|
|
* @var int
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
private static $_anchor = 252634154;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Title bookmark
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-03-28 13:50:53 +07:00
|
|
|
* @var int
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
private static $_bookmarkId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new Table-of-Contents Element
|
|
|
|
|
*
|
2014-03-28 13:50:53 +07:00
|
|
|
* @param mixed $styleFont
|
2013-12-11 14:45:44 -05:00
|
|
|
* @param array $styleTOC
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($styleFont = null, $styleTOC = null)
|
|
|
|
|
{
|
2014-03-30 18:51:25 +07:00
|
|
|
self::$_styleTOC = new TOCStyle();
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
if (!is_null($styleTOC) && is_array($styleTOC)) {
|
|
|
|
|
foreach ($styleTOC as $key => $value) {
|
|
|
|
|
if (substr($key, 0, 1) != '_') {
|
|
|
|
|
$key = '_' . $key;
|
|
|
|
|
}
|
|
|
|
|
self::$_styleTOC->setStyleValue($key, $value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_null($styleFont)) {
|
|
|
|
|
if (is_array($styleFont)) {
|
2014-03-22 10:06:08 +04:00
|
|
|
self::$_styleFont = new Font();
|
2013-12-11 14:45:44 -05:00
|
|
|
foreach ($styleFont as $key => $value) {
|
|
|
|
|
if (substr($key, 0, 1) != '_') {
|
|
|
|
|
$key = '_' . $key;
|
|
|
|
|
}
|
|
|
|
|
self::$_styleFont->setStyleValue($key, $value);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
self::$_styleFont = $styleFont;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a Title
|
|
|
|
|
*
|
2014-03-17 07:26:25 +07:00
|
|
|
* @param string $text
|
|
|
|
|
* @param int $depth
|
2013-12-11 14:45:44 -05:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function addTitle($text, $depth = 0)
|
|
|
|
|
{
|
|
|
|
|
$anchor = '_Toc' . ++self::$_anchor;
|
|
|
|
|
$bookmarkId = self::$_bookmarkId++;
|
|
|
|
|
|
|
|
|
|
$title = array();
|
|
|
|
|
$title['text'] = $text;
|
|
|
|
|
$title['depth'] = $depth;
|
|
|
|
|
$title['anchor'] = $anchor;
|
|
|
|
|
$title['bookmarkId'] = $bookmarkId;
|
|
|
|
|
|
|
|
|
|
self::$_titles[] = $title;
|
|
|
|
|
|
|
|
|
|
return array($anchor, $bookmarkId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all titles
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getTitles()
|
|
|
|
|
{
|
|
|
|
|
return self::$_titles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get TOC Style
|
|
|
|
|
*
|
2014-03-30 18:51:25 +07:00
|
|
|
* @return TOCStyle
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
public static function getStyleTOC()
|
|
|
|
|
{
|
|
|
|
|
return self::$_styleTOC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Font Style
|
|
|
|
|
*
|
2014-03-30 18:51:25 +07:00
|
|
|
* @return Font
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
public static function getStyleFont()
|
|
|
|
|
{
|
|
|
|
|
return self::$_styleFont;
|
|
|
|
|
}
|
2014-03-11 19:26:56 +07:00
|
|
|
}
|