From 99f9c5b4ba01860b348ef4b0b22c0c87ff818313 Mon Sep 17 00:00:00 2001 From: aavzz Date: Thu, 5 Apr 2018 12:46:02 +0400 Subject: [PATCH] Update ASCIIToSVG.php Add more fine-grained control over which box is rendered above and which one is rendered below. --- ASCIIToSVG.php | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/ASCIIToSVG.php b/ASCIIToSVG.php index 10e7e65..d99d8c6 100644 --- a/ASCIIToSVG.php +++ b/ASCIIToSVG.php @@ -273,17 +273,19 @@ class SVGGroup { private $curGroup; private $groupStack; private $options; + private $index; public function __construct() { $this->groups = array(); $this->groupStack = array(); $this->options = array(); + $this->index = 0; } public function getGroup($groupName) { return $this->groups[$groupName]; } - + public function pushGroup($groupName) { if (!isset($this->groups[$groupName])) { $this->groups[$groupName] = array(); @@ -304,10 +306,44 @@ public function popGroup() { $this->curGroup = array_pop($this->groupStack); } + /* + AAVZZ + Since SVG has no notion of layers, we emulate them by changing the order + of boxes. This involves tagging and reordering. Tagging is done in `addObject', + reordering in `rearrangeBoxes'. We tag a box with a layer prefix, like `a' (default), + `b', `c' and so on. So, the sequence numbers will be something like + a0, a1, b2, a3, a4, b5, c6 ... + Once all the boxes are parsed, we need to rearrange them like + a0, a1, a3, a4, b2, b5, c6 ... + and change the indices to be numeic (we rely on them being numeric!!) + XXX Some text lines belonging to overlying box are placed in underlying box + XXX and do not show up. Further investigation is necessary to place them correctly. + XXX This issue is not introduced with this patch. + */ + public function addObject($o) { - $this->groups[$this->curGroup][] = $o; + if ($this->curGroup == "boxes") { + $layer = 'a'; + if ($o->getOption('a2s:layer')) { + $layer = $o->getOption('a2s:layer'); + } + $i = $layer . $this->index++; + $this->groups[$this->curGroup][$i] = $o; + } + else { + $this->groups[$this->curGroup][] = $o; + } } + public function rearrangeBoxes() { + $newboxes = array(); + ksort($this->groups["boxes"], SORT_NATURAL); + foreach($this->groups["boxes"] as $index => $value) { + $newboxes[] = $value; + } + $this->groups["boxes"]=$newboxes; + } + public function setOption($opt, $val) { $this->options[$this->curGroup][$opt] = $val; } @@ -1480,6 +1516,7 @@ private function parseBoxes() { /* Anything after this is not a subgroup */ $this->svgObjects->popGroup(); + $this->svgObjects->rearrangeBoxes(); } /*