-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Hello!
As the mPDF won't support marker as they said at the mPDF Manual.
I'd like to do something like the codes below, to refuse the marker but use some more paths.
But, my php is only at a beginner level. And I am not very sure if there need four branch in each draw function.
Could you have a look at this and found some way to make the dw2pdf usefull?
--- ASCIIToSVG.php.orig 2020-04-21 11:45:31.105630518 +0800
+++ ASCIIToSVG.php 2020-04-21 16:34:30.261628449 +0800
@@ -2474,6 +2474,92 @@
}
}
+ public function drawIArrow($fx, $fy, $tx, $ty) {
+ $l = 8;
+ // <
+ if($fx < $tx) {
+ $ax0 = $fx - $l/2;
+ $ay0 = $fy;
+ $ax1 = $fx + $l;
+ $ay1 = $fy - $l;
+ $ax2 = $fx + $l;
+ $ay2 = $fy + $l;
+ }
+ // >
+ else if($fx > $tx) {
+ $ax0 = $fx + $l/2;
+ $ay0 = $fy;
+ $ax1 = $fx - $l;
+ $ay1 = $fy - $l;
+ $ax2 = $fx - $l;
+ $ay2 = $fy + $l;
+ }
+ // ^
+ if($fy < $ty) {
+ $ax0 = $fx;
+ $ay0 = $fy - $l/2;
+ $ax1 = $fx - $l;
+ $ay1 = $fy + $l;
+ $ax2 = $fx + $l;
+ $ay2 = $fy + $l;
+ }
+ // v
+ else if($fy > $ty) {
+ $ax0 = $fx;
+ $ay0 = $fy + $l/2;
+ $ax1 = $fx - $l;
+ $ay1 = $fy - $l;
+ $ax2 = $fx + $l;
+ $ay2 = $fy - $l;
+ }
+
+ //return "M {$ax0} {$ay0} L {$ax1} {$ay1} L {$ax2} {$ay2} Z ";
+ return "M {$ax0} {$ay0} L {$fx} {$fy} M {$ax0} {$ay0} L {$ax1} {$ay1} M {$ax0} {$ay0} {$ax2} {$ay2} ";
+ }
+
+ public function drawArrow($fx, $fy, $tx, $ty) {
+ $l = 8;
+ // <
+ if($fx > $tx) {
+ $ax0 = $tx - $l/2;
+ $ay0 = $ty;
+ $ax1 = $tx + $l;
+ $ay1 = $ty - $l;
+ $ax2 = $tx + $l;
+ $ay2 = $ty + $l;
+ }
+ // >
+ else if($fx < $tx) {
+ $ax0 = $tx + $l/2;
+ $ay0 = $ty;
+ $ax1 = $tx - $l;
+ $ay1 = $ty - $l;
+ $ax2 = $tx - $l;
+ $ay2 = $ty + $l;
+ }
+ // ^
+ if($fy > $ty) {
+ $ax0 = $tx;
+ $ay0 = $ty - $l/2;
+ $ax1 = $tx - $l;
+ $ay1 = $ty + $l;
+ $ax2 = $tx + $l;
+ $ay2 = $ty + $l;
+ }
+ // v
+ else if($fy < $ty) {
+ $ax0 = $tx;
+ $ay0 = $ty + $l/2;
+ $ax1 = $tx - $l;
+ $ay1 = $ty - $l;
+ $ax2 = $tx + $l;
+ $ay2 = $ty - $l;
+ }
+
+ // return "M {$ax0} {$ay0} L {$ax1} {$ay1} L {$ax2} {$ay2} Z ";
+ return "M {$ax0} {$ay0} L {$tx} {$ty} M {$ax0} {$ay0} L {$ax1} {$ay1} M {$ax0} {$ay0} {$ax2} {$ay2} ";
+ }
+
public function render() {
$startPoint = array_shift($this->points);
$endPoint = $this->points[count($this->points) - 1];
@@ -2589,6 +2675,8 @@
$path = "M {$startPoint->x} {$startPoint->y} ";
}
+
+
$prevP = $startPoint;
$bound = count($this->points);
for ($i = 0; $i < $bound; $i++) {
@@ -2666,15 +2754,26 @@
/* Add markers if necessary. */
if ($startPoint->flags & Point::SMARKER) {
- $this->options["marker-start"] = "url(#Pointer)";
+ //$this->options["marker-start"] = "url(#Pointer)";
+ $path .= $this->drawArrow($startPoint->x, $startPoint->y, $this->points[0]->x, $this->points[0]->y);
} elseif ($startPoint->flags & Point::IMARKER) {
- $this->options["marker-start"] = "url(#iPointer)";
+ //$this->options["marker-start"] = "url(#iPointer)";
+ $path .= $this->drawIArrow($startPoint->x, $startPoint->y, $this->points[0]->x, $this->points[0]->y);
}
if ($endPoint->flags & Point::SMARKER) {
- $this->options["marker-end"] = "url(#Pointer)";
+ //$this->options["marker-end"] = "url(#Pointer)";
+ if($bound == 1) {
+ $path .= $this->drawArrow($startPoint->x, $startPoint->y, $endPoint->x, $endPoint->y);
+ }
+ else {
+ $j = count($this->points) - 2;
+ $path .= $this->drawArrow($this->points[$j]->x, $this->points[$j]->y, $endPoint->x, $endPoint->y);
+ }
} elseif ($endPoint->flags & Point::IMARKER) {
- $this->options["marker-end"] = "url(#iPointer)";
+ //$this->options["marker-end"] = "url(#iPointer)";
+ $j = count($this->points) - 2;
+ $path .= $this->drawIArrow($endPoint->x, $endPoint->y, $this->points[$j]->x, $this->points[$j]->y);
}
/*I tested this with the codes below, seems it work.
<a2s>
---> <--- | ^
| |
| ^ +--> --+
| |
v | +-- |<--+
| | |
===> <=== v |
--- ---
: ^ | ^
: : | | |
v : +-->| --+
</a2s>
Metadata
Metadata
Assignees
Labels
No labels