You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

617 lines
21 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. /** @noinspection MultiAssignmentUsageInspection */
  3. namespace Shuchkin;
  4. use SimpleXMLElement;
  5. class SimpleXLSXEx
  6. {
  7. public static $IC = [
  8. 0 => '000000',
  9. 1 => 'FFFFFF',
  10. 2 => 'FF0000',
  11. 3 => '00FF00',
  12. 4 => '0000FF',
  13. 5 => 'FFFF00',
  14. 6 => 'FF00FF',
  15. 7 => '00FFFF',
  16. 8 => '000000',
  17. 9 => 'FFFFFF',
  18. 10 => 'FF0000',
  19. 11 => '00FF00',
  20. 12 => '0000FF',
  21. 13 => 'FFFF00',
  22. 14 => 'FF00FF',
  23. 15 => '00FFFF',
  24. 16 => '800000',
  25. 17 => '008000',
  26. 18 => '000080',
  27. 19 => '808000',
  28. 20 => '800080',
  29. 21 => '008080',
  30. 22 => 'C0C0C0',
  31. 23 => '808080',
  32. 24 => '9999FF',
  33. 25 => '993366',
  34. 26 => 'FFFFCC',
  35. 27 => 'CCFFFF',
  36. 28 => '660066',
  37. 29 => 'FF8080',
  38. 30 => '0066CC',
  39. 31 => 'CCCCFF',
  40. 32 => '000080',
  41. 33 => 'FF00FF',
  42. 34 => 'FFFF00',
  43. 35 => '00FFFF',
  44. 36 => '800080',
  45. 37 => '800000',
  46. 38 => '008080',
  47. 39 => '0000FF',
  48. 40 => '00CCFF',
  49. 41 => 'CCFFFF',
  50. 42 => 'CCFFCC',
  51. 43 => 'FFFF99',
  52. 44 => '99CCFF',
  53. 45 => 'FF99CC',
  54. 46 => 'CC99FF',
  55. 47 => 'FFCC99',
  56. 48 => '3366FF',
  57. 49 => '33CCCC',
  58. 50 => '99CC00',
  59. 51 => 'FFCC00',
  60. 52 => 'FF9900',
  61. 53 => 'FF6600',
  62. 54 => '666699',
  63. 55 => '969696',
  64. 56 => '003366',
  65. 57 => '339966',
  66. 58 => '003300',
  67. 59 => '333300',
  68. 60 => '993300',
  69. 61 => '993366',
  70. 62 => '333399',
  71. 63 => '333333',
  72. 64 => '000000', // System Foreground
  73. 65 => 'FFFFFF', // System Background'
  74. ];
  75. public static $CH = [
  76. 0 => 'ANSI_CHARSET',
  77. 1 => 'DEFAULT_CHARSET',
  78. 2 => 'SYMBOL_CHARSET',
  79. 77 => 'MAC_CHARSET',
  80. 128 => 'SHIFTJIS_CHARSET',
  81. //129 => 'HANGEUL_CHARSET',
  82. 129 => 'HANGUL_CHARSET',
  83. 130 => 'JOHAB_CHARSET',
  84. 134 => 'GB2312_CHARSET',
  85. 136 => 'CHINESEBIG5_CHARSET',
  86. 161 => 'GREEK_CHARSET',
  87. 162 => 'TURKISH_CHARSET',
  88. 163 => 'VIETNAMESE_CHARSET',
  89. 177 => 'HEBREW_CHARSET',
  90. 178 => 'ARABIC_CHARSET',
  91. 186 => 'BALTIC_CHARSET',
  92. 204 => 'RUSSIAN_CHARSET',
  93. 222 => 'THAI_CHARSET',
  94. 238 => 'EASTEUROPE_CHARSET',
  95. 255 => 'OEM_CHARSET'
  96. ];
  97. public $xlsx;
  98. public $themeColors;
  99. public $fonts;
  100. public $fills;
  101. public $borders;
  102. public $cellStyles;
  103. public $css;
  104. public function __construct(SimpleXLSX $xlsx)
  105. {
  106. $this->xlsx = $xlsx;
  107. $this->readThemeColors();
  108. $this->readFonts();
  109. $this->readFills();
  110. $this->readBorders();
  111. $this->readXfs();
  112. }
  113. public function readThemeColors()
  114. {
  115. $this->themeColors = [];
  116. if (isset($this->xlsx->theme->themeElements->clrScheme)) {
  117. $colors12 = ['lt1', 'dk1', 'lt2', 'dk2','accent1','accent2','accent3','accent4','accent5',
  118. 'accent6','hlink','folHlink'];
  119. foreach ($colors12 as $c) {
  120. $v = $this->xlsx->theme->themeElements->clrScheme->{$c};
  121. if (isset($v->sysClr)) {
  122. $this->themeColors[] = (string) $v->sysClr['lastClr'];
  123. } elseif (isset($v->srgbClr)) {
  124. $this->themeColors[] = (string) $v->srgbClr['val'];
  125. } else {
  126. $this->themeColors[] = null;
  127. }
  128. }
  129. }
  130. }
  131. public function readFonts()
  132. {
  133. // fonts
  134. $this->fonts = [];
  135. if (isset($this->xlsx->styles->fonts->font)) {
  136. foreach ($this->xlsx->styles->fonts->font as $v) {
  137. $u = '';
  138. if (isset($v->u)) {
  139. $u = isset($v->u['val']) ? (string) $v->u['val'] : 'single';
  140. }
  141. $f = [
  142. 'b' => isset($v->b) && ($v->b['val'] === null || $v->b['val']),
  143. 'i' => isset($v->i) && ($v->i['val'] === null || $v->i['val']),
  144. 'u' => $u,
  145. 'strike' => isset($v->strike) && ($v->strike['val'] === null || $v->strike['val']),
  146. 'sz' => isset($v->sz['val']) ? (int) $v->sz['val'] : 11,
  147. 'color' => $this->getColorValue($v->color),
  148. 'name' => isset($v->name['val']) ? (string) $v->name['val'] : 'Calibri',
  149. 'family' => isset($v->family['val']) ? (int) $v->family['val'] : 2,
  150. 'charset' => isset($v->charset['val']) ? (int) $v->charset['val'] : 1,
  151. 'scheme' => isset($v->scheme['val']) ? (string) $v->scheme['val'] : 'minor'
  152. ];
  153. $this->fonts[] = $f;
  154. }
  155. }
  156. }
  157. public function readFills()
  158. {
  159. // fills
  160. $this->fills = [];
  161. if (isset($this->xlsx->styles->fills->fill)) {
  162. foreach ($this->xlsx->styles->fills->fill as $v) {
  163. if (isset($v->patternFill)) {
  164. $this->fills[] = [
  165. 'pattern' => isset($v->patternFill['patternType']) ? (string) $v->patternFill['patternType'] : 'none',
  166. 'fgcolor' => $this->getColorValue($v->patternFill->fgColor),
  167. 'bgcolor' => $this->getColorValue($v->patternFill->bgColor)
  168. ];
  169. }
  170. }
  171. }
  172. }
  173. public function readBorders()
  174. {
  175. $this->borders = [];
  176. if (isset($this->xlsx->styles->borders->border)) {
  177. foreach ($this->xlsx->styles->borders->border as $v) {
  178. $this->borders[] = [
  179. 'left' => [
  180. 'style' => (string) $v->left['style'],
  181. 'color' => $this->getColorValue($v->left->color)
  182. ],
  183. 'right' => [
  184. 'style' => (string) $v->right['style'],
  185. 'color' => $this->getColorValue($v->right->color)
  186. ],
  187. 'top' => [
  188. 'style' => (string) $v->top['style'],
  189. 'color' => $this->getColorValue($v->top->color)
  190. ],
  191. 'bottom' => [
  192. 'style' => (string) $v->bottom['style'],
  193. 'color' => $this->getColorValue($v->bottom->color)
  194. ],
  195. 'diagonal' => [
  196. 'style' => (string) $v->diagonal['style'],
  197. 'color' => $this->getColorValue($v->diagonal->color)
  198. ],
  199. 'horizontal' => [
  200. 'style' => (string) $v->horizontal['style'],
  201. 'color' => $this->getColorValue($v->horizontal->color)
  202. ],
  203. 'vertical' => [
  204. 'style' => (string) $v->vertical['style'],
  205. 'color' => $this->getColorValue($v->vertical->color)
  206. ],
  207. 'diagonalUp' => (bool) $v['diagonalUp'],
  208. 'diagonalDown' => (bool) $v['diagonalDown'],
  209. 'outline' => !(isset($v['outline'])) || $v['outline']
  210. ];
  211. }
  212. }
  213. }
  214. public function readXfs()
  215. {
  216. // cellStyles
  217. $this->cellStyles = [];
  218. if (isset($this->xlsx->styles->cellStyleXfs->xf)) {
  219. foreach ($this->xlsx->styles->cellStyleXfs->xf as $v) {
  220. $x = [];
  221. foreach ($v->attributes() as $k1 => $v1) {
  222. $x[ $k1 ] = (int) $v1;
  223. }
  224. if (isset($v->alignment)) {
  225. foreach ($v->alignment->attributes() as $k1 => $v1) {
  226. $x['alignment'][$k1] = (string) $v1;
  227. }
  228. }
  229. $this->cellStyles[] = $x;
  230. }
  231. }
  232. // css
  233. $this->css = [];
  234. // xf
  235. if (isset($this->xlsx->styles->cellXfs->xf)) {
  236. $k = 0;
  237. foreach ($this->xlsx->styles->cellXfs->xf as $v) {
  238. $cf = &$this->xlsx->cellFormats[$k];
  239. // alignment
  240. $alignment = [];
  241. if (isset($v->alignment)) {
  242. foreach ($v->alignment->attributes() as $k1 => $v1) {
  243. $alignment[$k1] = (string)$v1;
  244. }
  245. }
  246. if (isset($cf['xfId'], $this->cellStyles[ $cf['xfId'] ])) {
  247. $s = $this->cellStyles[$cf['xfId']];
  248. if (!empty($s['applyNumberFormat'])) {
  249. $cf['numFmtId'] = $s['numFmtId'];
  250. }
  251. if (!empty($s['applyFont'])) {
  252. $cf['fontId'] = $s['fontId'];
  253. }
  254. if (!empty($s['applyBorder'])) {
  255. $cf['borderId'] = $s['borderId'];
  256. }
  257. if (!empty($s['applyAlignment'])) {
  258. $alignment = $s['alignment'];
  259. }
  260. }
  261. $cf['alignment'] = $alignment;
  262. $align = null;
  263. if (isset($alignment['horizontal'])) {
  264. $align = $alignment['horizontal'];
  265. if ($align === 'centerContinuous') {
  266. $align = 'center';
  267. }
  268. if ($align === 'distributed') {
  269. $align = 'justify';
  270. }
  271. if ($align === 'general') {
  272. $align = null;
  273. }
  274. }
  275. $cf['align'] = $align;
  276. $valign = null;
  277. if (isset($alignment['vertical'])) {
  278. $valign = $alignment['vertical'];
  279. if ($valign === 'center' || $valign === 'distributed' || $valign === 'justify') {
  280. $valign = 'middle';
  281. }
  282. }
  283. $cf['valign'] = $valign;
  284. // font
  285. if (isset($cf['fontId'])) {
  286. $cf['font'] = $this->fonts[$cf['fontId']]['name'];
  287. $cf['color'] = $this->fonts[$cf['fontId']]['color'];
  288. $cf['f-size'] = $this->fonts[$cf['fontId']]['sz'];
  289. $cf['f-b'] = $this->fonts[$cf['fontId']]['b'];
  290. $cf['f-i'] = $this->fonts[$cf['fontId']]['i'];
  291. $cf['f-u'] = $this->fonts[$cf['fontId']]['u'];
  292. $cf['f-strike'] = $this->fonts[$cf['fontId']]['strike'];
  293. } else {
  294. $cf['font'] = null;
  295. $cf['color'] = null;
  296. $cf['f-size'] = null;
  297. $cf['f-b'] = null;
  298. $cf['f-i'] = null;
  299. $cf['f-u'] = null;
  300. $cf['f-strike'] = null;
  301. }
  302. // fill
  303. $cf['bgcolor'] = isset($cf['fillId']) ? $this->fills[ $cf['fillId'] ]['fgcolor'] : null;
  304. // borders
  305. if (isset($cf['borderId'], $this->borders[ $cf['borderId'] ])) {
  306. $border = $this->borders[ $cf['borderId'] ];
  307. $borders = ['left', 'right', 'top', 'bottom'];
  308. foreach ($borders as $b) {
  309. $cf['b-' . $b.'-color'] = $border[$b]['color'];
  310. if ($border[$b]['style'] === '' || $border[$b]['style'] === 'none') {
  311. $cf['b-' . $b.'-style'] = '';
  312. $cf['b-' . $b.'-color'] = '';
  313. } elseif ($border[$b]['style'] === 'dashDot'
  314. || $border[$b]['style'] === 'dashDotDot'
  315. || $border[$b]['style'] === 'dashed'
  316. ) {
  317. $cf['b-' . $b.'-style'] = 'dashed';
  318. } else {
  319. $cf['b-' . $b.'-style'] = 'solid';
  320. }
  321. }
  322. } else {
  323. $cf['b-top-style'] = null;
  324. $cf['b-right-style'] = null;
  325. $cf['b-bottom-style'] = null;
  326. $cf['b-left-style'] = null;
  327. }
  328. $css = '';
  329. if ($cf['color']) {
  330. $css .= 'color: #'.$cf['color'].';';
  331. }
  332. if ($cf['font']) {
  333. $css .= 'font-family: '.$cf['font'].';';
  334. }
  335. if ($cf['f-size']) {
  336. // $css .= 'font-size: '.($cf['f-size'] * 0.352806).'mm;';
  337. $css .= 'font-size: '.(round($cf['f-size'] * 1.3333) + 2).'px;';
  338. }
  339. if ($cf['f-b']) {
  340. $css .= 'font-weight: bold;';
  341. }
  342. if ($cf['f-i']) {
  343. $css .= 'font-style: italic;';
  344. }
  345. if ($cf['f-u']) {
  346. $css .= 'text-decoration: underline;';
  347. }
  348. if ($cf['f-strike']) {
  349. $css .= 'text-decoration: line-through;';
  350. }
  351. if ($cf['bgcolor']) {
  352. $css .= 'background-color: #' . $cf['bgcolor'] . ';';
  353. }
  354. if ($cf['align']) {
  355. $css .= 'text-align: '.$cf['align'].';';
  356. }
  357. if ($cf['valign']) {
  358. $css .= 'vertical-align: '.$cf['valign'].';';
  359. }
  360. if ($cf['b-top-style']) {
  361. $css .= 'border-top-style: '.$cf['b-top-style'].';';
  362. $css .= 'border-top-color: #'.$cf['b-top-color'].';';
  363. $css .= 'border-top-width: thin;';
  364. }
  365. if ($cf['b-right-style']) {
  366. $css .= 'border-right-style: '.$cf['b-right-style'].';';
  367. $css .= 'border-right-color: #'.$cf['b-right-color'].';';
  368. $css .= 'border-right-width: thin;';
  369. }
  370. if ($cf['b-bottom-style']) {
  371. $css .= 'border-bottom-style: '.$cf['b-bottom-style'].';';
  372. $css .= 'border-bottom-color: #'.$cf['b-bottom-color'].';';
  373. $css .= 'border-bottom-width: thin;';
  374. }
  375. if ($cf['b-left-style']) {
  376. $css .= 'border-left-style: '.$cf['b-left-style'].';';
  377. $css .= 'border-left-color: #'.$cf['b-left-color'].';';
  378. $css .= 'border-left-width: thin;';
  379. }
  380. $this->css[$k] = $css;
  381. $k++;
  382. }
  383. }
  384. }
  385. public function readRowsEx($worksheetIndex = 0, $limit = 0)
  386. {
  387. if (($ws = $this->xlsx->worksheet($worksheetIndex)) === false) {
  388. return;
  389. }
  390. $dim = $this->xlsx->dimension($worksheetIndex);
  391. $numCols = $dim[0];
  392. $numRows = $dim[1];
  393. /*$emptyRow = array();
  394. for ($i = 0; $i < $numCols; $i++) {
  395. $emptyRow[] = null;
  396. }
  397. */
  398. $cols = [];
  399. for ($i = 0; $i < $numCols; $i++) {
  400. $cols[] = ['s' => 0, 'hidden' => false, 'width' => 0];
  401. }
  402. // $hiddenCols = [];
  403. /* @var SimpleXMLElement $ws */
  404. if (isset($ws->cols)) {
  405. foreach ($ws->cols->col as $col) {
  406. $min = (int)$col['min'];
  407. $max = (int)$col['max'];
  408. if (($max-$min) > 100) {
  409. $max = $min;
  410. }
  411. for ($i = $min; $i <= $max; $i++) {
  412. $cols[$i-1] = [
  413. 's' => (int)$col['style'],
  414. 'hidden' => (bool)$col['hidden'],
  415. 'width' => $col['customWidth'] ? (float) $col['width'] : 0
  416. ];
  417. }
  418. }
  419. }
  420. $curR = 0;
  421. $_limit = $limit;
  422. foreach ($ws->sheetData->row as $row) {
  423. $curC = 0;
  424. $r_idx = (int)$row['r'];
  425. $r_style = ['s' => 0, 'hidden' => (bool)$row['hidden'], 'height' => 0];
  426. if ($row['customFormat']) {
  427. $r_style['s'] = (int)$row['s'];
  428. }
  429. if ($row['customHeight']) {
  430. $r_style['height'] = (int)$row['ht'];
  431. }
  432. $cells = [];
  433. for ($i = 0; $i < $numCols; $i++) {
  434. $cells[] = null;
  435. }
  436. foreach ($row->c as $c) {
  437. $r = (string)$c['r'];
  438. $t = (string)$c['t'];
  439. $s = (int)$c['s'];
  440. $idx = $this->xlsx->getIndex($r);
  441. $x = $idx[0];
  442. $y = $idx[1];
  443. if ($x > -1) {
  444. $curC = $x;
  445. if ($curC >= $numCols) {
  446. $numCols = $curC + 1;
  447. }
  448. while ($curR < $y) {
  449. $emptyRow = [];
  450. for ($i = 0; $i < $numCols; $i++) {
  451. $emptyRow[] = $this->valueEx($cols[$i], $i, $curR);
  452. }
  453. yield $emptyRow;
  454. $curR++;
  455. $_limit--;
  456. if ($_limit === 0) {
  457. return;
  458. }
  459. }
  460. }
  461. $data = [
  462. 'type' => $t,
  463. 'name' => $r,
  464. 'value' => $this->xlsx->value($c),
  465. 'href' => $this->xlsx->href($worksheetIndex, $c),
  466. 'f' => (string)$c->f,
  467. 'r' => $r_idx,
  468. 's' => ($s > 0) ? $s : $cols[$curC]['s'],
  469. 'hidden' => $r_style['hidden'] || $cols[$curC]['hidden'],
  470. 'width' => $cols[$curC]['width'],
  471. 'height' => $r_style['height']
  472. ];
  473. $cells[$curC] = $this->valueEx($data, $curC, $curR);
  474. $curC++;
  475. }
  476. // check empty cells
  477. for ($i = 0; $i < $numCols; $i++) {
  478. if ($cells[$i] === null) {
  479. if ($r_style['s'] > 0) {
  480. $data = $r_style;
  481. } else {
  482. $data = $cols[$i];
  483. }
  484. $data['width'] = $cols[$i]['width'];
  485. $data['height'] = $r_style['height'];
  486. $cells[$i] = $this->valueEx($data, $i, $curR);
  487. }
  488. }
  489. yield $cells;
  490. $curR++;
  491. $_limit--;
  492. if ($_limit === 0) {
  493. break;
  494. }
  495. }
  496. while ($curR < $numRows) {
  497. $emptyRow = [];
  498. for ($i = 0; $i < $numCols; $i++) {
  499. $data = $cols[$i];
  500. $emptyRow[] = $this->valueEx($data, $i, $curR);
  501. }
  502. yield $emptyRow;
  503. $curR++;
  504. $_limit--;
  505. if ($_limit === 0) {
  506. return;
  507. }
  508. }
  509. }
  510. protected function valueEx($data, $x = null, $y = null)
  511. {
  512. $r = [
  513. 'type' => '',
  514. 'name' => '',
  515. 'value' => '',
  516. 'href' => '',
  517. 'f' => '',
  518. 'format' => '',
  519. 's' => 0,
  520. 'css' => '',
  521. 'r' => '',
  522. 'hidden' => false,
  523. 'width' => 0,
  524. 'height' => 0
  525. ];
  526. foreach ($data as $k => $v) {
  527. if (isset($r[$k])) {
  528. $r[$k] = $v;
  529. }
  530. }
  531. $st = &$this->xlsx->cellFormats[$r['s']];
  532. $r['format'] = $st['format'];
  533. $r['css'] = &$this->css[ $r['s'] ];
  534. if ($r['value'] !== '' && !$st['align'] && !in_array($r['type'], ['s','str','inlineStr','e'], true)) {
  535. $r['css'] .= 'text-align: right;';
  536. }
  537. if (!$r['name']) {
  538. $c = '';
  539. for ($k = $x; $k >= 0; $k = (int)($k / 26) - 1) {
  540. $c = chr($k % 26 + 65) . $c;
  541. }
  542. $r['name'] = $c . ($y + 1);
  543. $r['r'] = $y+1;
  544. }
  545. return $r;
  546. }
  547. public function getColorValue(SimpleXMLElement $a = null, $default = '')
  548. {
  549. if ($a === null) {
  550. return $default;
  551. }
  552. $c = $default; // auto
  553. if ($a['rgb'] !== null) {
  554. $c = substr((string) $a['rgb'], 2); // FFCCBBAA -> CCBBAA
  555. } elseif ($a['indexed'] !== null && isset(static::$IC[ (int) $a['indexed'] ])) {
  556. $c = static::$IC[ (int) $a['indexed'] ];
  557. } elseif ($a['theme'] !== null && isset($this->themeColors[ (int) $a['theme'] ])) {
  558. $c = $this->themeColors[ (int) $a['theme'] ];
  559. }
  560. if ($a['tint'] !== null) {
  561. list($r,$g,$b) = array_map('hexdec', str_split($c, 2));
  562. $tint = (float) $a['tint'];
  563. if ($tint > 0) {
  564. $r += (255 - $r) * $tint;
  565. $g += (255 - $g) * $tint;
  566. $b += (255 - $b) * $tint;
  567. } else {
  568. $r += $r * $tint;
  569. $g += $g * $tint;
  570. $b += $b * $tint;
  571. }
  572. $c = strtoupper(
  573. str_pad(dechex((int) $r), 2, '0', 0) .
  574. str_pad(dechex((int) $g), 2, '0', 0) .
  575. str_pad(dechex((int) $b), 2, '0', 0)
  576. );
  577. }
  578. return $c;
  579. }
  580. }