-
Notifications
You must be signed in to change notification settings - Fork 17
Update ASCIIToSVG.php #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this, more information in a later comment. |
||
| } | ||
|
|
||
| public function getGroup($groupName) { | ||
| return $this->groups[$groupName]; | ||
| } | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this whitespace change. |
||
| 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. | ||
| */ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please make this comment block follow the style of other comment blocks in this file? For example: Please remove your github username from the comment. It isn't informative to the code or the comment and this ends up being distracting when reading the code. Please only use one instance of If you intend on solving this problem, please feel free to change the Please also fix the contents of this comment based on the discussion about indexing below. |
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this line, to follow style with other comments on class methods in this code. |
||
| public function addObject($o) { | ||
| $this->groups[$this->curGroup][] = $o; | ||
| if ($this->curGroup == "boxes") { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this is probably only useful for layering boxes, I'd recommend removing this conditional such that it may be possible to annotate lines and text in the future, and have those layered appropriately. |
||
| $layer = 'a'; | ||
| if ($o->getOption('a2s:layer')) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend renaming this to |
||
| $layer = $o->getOption('a2s:layer'); | ||
| } | ||
| $i = $layer . $this->index++; | ||
| $this->groups[$this->curGroup][$i] = $o; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code above ends up calling Another thing worth thinking about: if you do not layer all of your objects, you start to need to come up with creative names for layers since they are sorted lexicographically. If I want to stack my boxes below the default layer, I need to use uppercase names, some kinds of punctuation, or numbers for the start of the layer name. If I want to stack my boxes above the default layer, I can't use those things for layer names. I would recommend that we use a deterministic ordering, hence switching to This can all be expressed in a single line of code which can replace most of this change. |
||
| } | ||
| else { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this else clause based on the above comments. |
||
| $this->groups[$this->curGroup][] = $o; | ||
| } | ||
| } | ||
|
|
||
| public function rearrangeBoxes() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs to be a public method. In particular, you can perform the sort just-in-time before you render the group. Please move the layer sorting logic into the render method of this class. |
||
| $newboxes = array(); | ||
| ksort($this->groups["boxes"], SORT_NATURAL); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the PHP manual, array sorting functions are in-place. As such, the loop and re-assignment below are not necessary. Since this will be moving into
|
||
| 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(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this line as the logic performed by this call should instead just be performed by |
||
| } | ||
|
|
||
| /* | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this, more information in a later comment.