source-class-Com.Tecnick.Pdf.Graph.Draw

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Draw.php
  4:  *
  5:  * @since       2011-05-23
  6:  * @category    Library
  7:  * @package     PdfGraph
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-pdf-graph
 12:  *
 13:  * This file is part of tc-lib-pdf-graph software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Pdf\Graph;
 17: 
 18: use \Com\Tecnick\Pdf\Graph\Exception as GraphException;
 19: 
 20: /**
 21:  * Com\Tecnick\Pdf\Graph\Draw
 22:  *
 23:  * @since       2011-05-23
 24:  * @category    Library
 25:  * @package     PdfGraph
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-pdf-graph
 30:  */
 31: class Draw extends \Com\Tecnick\Pdf\Graph\Gradient
 32: {
 33:     /**
 34:      * Draws a line between two points.
 35:      *
 36:      * @param float $posx1 Abscissa of first point.
 37:      * @param float $posy1 Ordinate of first point.
 38:      * @param float $posx2 Abscissa of second point.
 39:      * @param float $posy2 Ordinate of second point.
 40:      * @param array $style Line style to apply.
 41:      *
 42:      * @return string PDF command
 43:      */
 44:     public function getLine($posx1, $posy1, $posx2, $posy2, array $style = array())
 45:     {
 46:         return $this->getStyleCmd($style)
 47:             .$this->getRawPoint($posx1, $posy1)
 48:             .$this->getRawLine($posx2, $posy2)
 49:             .$this->getPathPaintOp('S');
 50:     }
 51: 
 52:     /**
 53:      * Draws a Bezier curve.
 54:      * The Bezier curve is a tangent to the line between the control points at either end of the curve.
 55:      *
 56:      * @param float  $posx0 Abscissa of start point.
 57:      * @param float  $posy0 Ordinate of start point.
 58:      * @param float  $posx1 Abscissa of control point 1.
 59:      * @param float  $posy1 Ordinate of control point 1.
 60:      * @param float  $posx2 Abscissa of control point 2.
 61:      * @param float  $posy2 Ordinate of control point 2.
 62:      * @param float  $posx3 Abscissa of end point.
 63:      * @param float  $posy3 Ordinate of end point.
 64:      * @param string $mode  Mode of rendering. @see getPathPaintOp()
 65:      * @param array  $style Style.
 66:      *
 67:      * @return string PDF command
 68:      *
 69:      * @SuppressWarnings(PHPMD.ExcessiveParameterList)
 70:      */
 71:     public function getCurve(
 72:         $posx0,
 73:         $posy0,
 74:         $posx1,
 75:         $posy1,
 76:         $posx2,
 77:         $posy2,
 78:         $posx3,
 79:         $posy3,
 80:         $mode = 'S',
 81:         array $style = array()
 82:     ) {
 83:         return $this->getStyleCmd($style)
 84:             .$this->getRawPoint($posx0, $posy0)
 85:             .$this->getRawCurve($posx1, $posy1, $posx2, $posy2, $posx3, $posy3)
 86:             .$this->getPathPaintOp($mode);
 87:     }
 88: 
 89:     /**
 90:      * Draws a poly-Bezier curve.
 91:      * Each Bezier curve segment is a tangent to the line between the control points at either end of the curve.
 92:      *
 93:      * @param float  $posx0    Abscissa of start point.
 94:      * @param float  $posy0    Ordinate of start point.
 95:      * @param float  $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
 96:      * @param string $mode     Mode of rendering. @see getPathPaintOp()
 97:      * @param array  $style    Style.
 98:      *
 99:      * @return string PDF command
100:      */
101:     public function getPolycurve($posx0, $posy0, $segments, $mode = 'S', array $style = array())
102:     {
103:         $out = $this->getStyleCmd($style)
104:             .$this->getRawPoint($posx0, $posy0);
105:         foreach ($segments as $seg) {
106:             list($posx1, $posy1, $posx2, $posy2, $posx3, $posy3) = $seg;
107:             $out .= $this->getRawCurve($posx1, $posy1, $posx2, $posy2, $posx3, $posy3);
108:         }
109:         $out .= $this->getPathPaintOp($mode);
110:         return $out;
111:     }
112: 
113:     /**
114:      * Draws an ellipse.
115:      * An ellipse is formed from n Bezier curves.
116:      *
117:      * @param float  $posx   Abscissa of center point.
118:      * @param float  $posy   Ordinate of center point.
119:      * @param float  $hrad   Horizontal radius.
120:      * @param float  $vrad   Vertical radius.
121:      * @param float  $angle  Angle oriented (anti-clockwise). Default value: 0.
122:      * @param float  $angs   Angle in degrees at which starting drawing.
123:      * @param float  $angf   Angle in degrees at which stop drawing.
124:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
125:      * @param array  $style  Style.
126:      * @param int    $ncv    Number of curves used to draw a 90 degrees portion of ellipse.
127:      *
128:      * @return string PDF command
129:      *
130:      * @SuppressWarnings(PHPMD.ExcessiveParameterList)
131:      */
132:     public function getEllipse(
133:         $posx,
134:         $posy,
135:         $hrad,
136:         $vrad = 0,
137:         $angle = 0,
138:         $angs = 0,
139:         $angf = 360,
140:         $mode = 'S',
141:         array $style = array(),
142:         $ncv = 2
143:     ) {
144:         if (empty($vrad)) {
145:             $vrad = $hrad;
146:         }
147:         return $this->getStyleCmd($style)
148:             .$this->getRawEllipticalArc(
149:                 $posx,
150:                 $posy,
151:                 $hrad,
152:                 $vrad,
153:                 $angle,
154:                 $angs,
155:                 $angf,
156:                 false,
157:                 $ncv,
158:                 true,
159:                 true,
160:                 false
161:             )
162:             .$this->getPathPaintOp($mode);
163:     }
164: 
165:     /**
166:      * Draws a circle.
167:      * A circle is formed from n Bezier curves.
168:      *
169:      * @param float  $posx   Abscissa of center point.
170:      * @param float  $posy   Ordinate of center point.
171:      * @param float  $rad    Radius.
172:      * @param float  $angs   Angle in degrees at which starting drawing.
173:      * @param float  $angf   Angle in degrees at which stop drawing.
174:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
175:      * @param array  $style  Style.
176:      * @param int    $ncv    Number of curves used to draw a 90 degrees portion of ellipse.
177:      *
178:      * @return string PDF command
179:      */
180:     public function getCircle(
181:         $posx,
182:         $posy,
183:         $rad,
184:         $angs = 0,
185:         $angf = 360,
186:         $mode = 'S',
187:         array $style = array(),
188:         $ncv = 2
189:     ) {
190:         return $this->getEllipse($posx, $posy, $rad, $rad, 0, $angs, $angf, $mode, $style, $ncv);
191:     }
192: 
193:     /**
194:      * Draws a circle pie sector.
195:      *
196:      * @param float  $posx   Abscissa of center point.
197:      * @param float  $posy   Ordinate of center point.
198:      * @param float  $rad    Radius.
199:      * @param float  $angs   Angle in degrees at which starting drawing.
200:      * @param float  $angf   Angle in degrees at which stop drawing.
201:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
202:      * @param array  $style  Style.
203:      * @param int    $ncv    Number of curves used to draw a 90 degrees portion of ellipse.
204:      *
205:      * @return string PDF command
206:      */
207:     public function getPieSector(
208:         $posx,
209:         $posy,
210:         $rad,
211:         $angs = 0,
212:         $angf = 360,
213:         $mode = 'FD',
214:         array $style = array(),
215:         $ncv = 2
216:     ) {
217:         return $this->getStyleCmd($style)
218:             .$this->getRawEllipticalArc(
219:                 $posx,
220:                 $posy,
221:                 $rad,
222:                 $rad,
223:                 0,
224:                 $angs,
225:                 $angf,
226:                 true,
227:                 $ncv,
228:                 true,
229:                 true,
230:                 false
231:             )
232:             .$this->getPathPaintOp($mode);
233:     }
234: 
235:     /**
236:      * Draws a basic polygon.
237:      *
238:      * @param array  $points Points - array containing 4 points for each segment: (x0, y0, x1, y1, x2, y2, ...)
239:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
240:      * @param array  $style  Style.
241:      *
242:      * @return string PDF command
243:      */
244:     public function getBasicPolygon($points, $mode = 'S', array $style = array())
245:     {
246:         $nco = count($points); // number of coordinates
247:         $out = $this->getStyleCmd($style)
248:             .$this->getRawPoint($points[0], $points[1]);
249:         for ($idx = 2; $idx < $nco; $idx += 2) {
250:             $out .= $this->getRawLine($points[$idx], $points[($idx + 1)]);
251:         }
252:         $out .= $this->getPathPaintOp($mode);
253:         return $out;
254:     }
255: 
256:     /**
257:      * Returns the polygon default style command and initialize the first segment style if missing.
258:      *
259:      * @param array  $styles  Array of styles - one style entry for each polygon segment and/or one global "all" entry.
260:      *
261:      * @return string PDF command
262:      */
263:     protected function getDefaultSegStyle(array &$styles = array())
264:     {
265:         $out = '';
266:         if (!empty($styles['all'])) {
267:             $out .= $this->getStyleCmd($styles['all']);
268:         }
269:         if (empty($styles[0])) {
270:             $styles[0] = array();
271:         }
272:         return $out;
273:     }
274: 
275:     /**
276:      * Draws a polygon with a different style for each segment.
277:      *
278:      * @param array  $points  Points - array with values (x0, y0, x1, y1,..., x(n-1), y(n-1))
279:      * @param string $mode    Mode of rendering. @see getPathPaintOp()
280:      * @param array  $styles  Array of styles - one style entry for each polygon segment and/or one global "all" entry.
281:      *
282:      * @return string PDF command
283:      */
284:     public function getPolygon($points, $mode = 'S', array $styles = array())
285:     {
286:         $nco = count($points); // number of points
287:         if ($nco < 6) {
288:             return ''; // we need at least 3 points
289:         }
290:         $nseg = (int) ($nco / 2); // number of segments (including the closing one)
291: 
292:         $out = $this->getDefaultSegStyle($styles);
293: 
294:         // paint the filling
295:         if ($this->isFillingMode($mode)) {
296:             $out .= $this->getBasicPolygon($points, $this->getModeWithoutStroke($mode));
297:         }
298: 
299:         if ($this->isClosingMode($mode)
300:             && (($points[($nco - 2)] != $points[0]) || ($points[($nco - 1)] != $points[1]))
301:         ) {
302:             // close polygon by adding the first point (x, y) at the end
303:             $points[$nco++] = $points[0];
304:             $points[$nco++] = $points[1];
305:             // copy style for the last segment
306:             $styles[($nseg - 1)] = $styles[0];
307:         }
308: 
309:         $nco -= 3;
310:         for ($idx = 0; $idx < $nco; $idx += 2) {
311:             $segid = (int) ($idx / 2);
312:             if (!isset($styles[$segid])) {
313:                 $styles[$segid] = array();
314:             }
315:             $out .=$this->getLine(
316:                 $points[$idx],
317:                 $points[($idx + 1)],
318:                 $points[($idx + 2)],
319:                 $points[($idx + 3)],
320:                 $styles[$segid]
321:             );
322:         }
323: 
324:         return $out;
325:     }
326: 
327:     /**
328:      * Draws a regular polygon.
329:      *
330:      * @param float  $posx     Abscissa of center point.
331:      * @param float  $posy     Ordinate of center point.
332:      * @param float  $radius   Radius of inscribed circle.
333:      * @param int    $sides    Number of sides.
334:      * @param float  $angle    Angle of the orientation (anti-clockwise).
335:      * @param string $mode     Mode of rendering. @see getPathPaintOp()
336:      * @param array  $styles   Array of styles - one style entry for each polygon segment and/or one global "all" entry.
337:      * @param string $cirmode  Mode of rendering of the inscribed circle (if any). @see getPathPaintOp()
338:      * @param array  $cirstyle Style of inscribed circle.
339:      *
340:      * @return string PDF command
341:      */
342:     public function getRegularPolygon(
343:         $posx,
344:         $posy,
345:         $radius,
346:         $sides,
347:         $angle = 0,
348:         $mode = 'S',
349:         array $styles = array(),
350:         $cirmode = '',
351:         $cirstyle = array()
352:     ) {
353:         if ($sides < 3) { // triangle is the minimum polygon
354:             return '';
355:         }
356:         $out = '';
357:         if (!empty($cirmode)) {
358:             $out .= $this->getCircle($posx, $posy, $radius, 0, 360, $cirmode, $cirstyle);
359:         }
360:         $points = array();
361:         for ($idx = 0; $idx < $sides; ++$idx) {
362:             $angrad = $this->degToRad((float) ($angle + ($idx * 360 / $sides)));
363:             $points[] = ($posx + ($radius * sin($angrad)));
364:             $points[] = ($posy + ($radius * cos($angrad)));
365:         }
366:         $out .= $this->getPolygon($points, $mode, $styles);
367:         return $out;
368:     }
369: 
370: 
371:     /**
372:      * Draws a star polygon.
373:      *
374:      * @param float  $posx     Abscissa of center point.
375:      * @param float  $posy     Ordinate of center point.
376:      * @param float  $radius   Radius of inscribed circle.
377:      * @param int    $nvert    Number of vertices.
378:      * @param int    $ngaps    Number of gaps (if ($ngaps % $nvert = 1) then is a regular polygon).
379:      * @param float  $angle    Angle oriented (anti-clockwise).
380:      * @param string $mode     Mode of rendering. @see getPathPaintOp()
381:      * @param array  $styles   Array of styles - one style entry for each polygon segment and/or one global "all" entry.
382:      * @param string $cirmode  Mode of rendering of the inscribed circle (if any). @see getPathPaintOp()
383:      * @param array  $cirstyle Style of inscribed circle.
384:      *
385:      * @return string PDF command
386:      *
387:      * @SuppressWarnings(PHPMD.ExcessiveParameterList)
388:      */
389:     public function getStarPolygon(
390:         $posx,
391:         $posy,
392:         $radius,
393:         $nvert,
394:         $ngaps,
395:         $angle = 0,
396:         $mode = 'S',
397:         array $styles = array(),
398:         $cirmode = '',
399:         $cirstyle = array()
400:     ) {
401:         if ($nvert < 2) {
402:             return '';
403:         }
404:         $out = '';
405:         if (!empty($cirmode)) {
406:             $out .= $this->getCircle($posx, $posy, $radius, 0, 360, $cirmode, $cirstyle);
407:         }
408:         
409:         $points2 = array();
410:         $visited = array();
411:         for ($idx = 0; $idx < $nvert; ++$idx) {
412:             $angrad = $this->degToRad((float) ($angle + ($idx * 360 / $nvert)));
413:             $points2[] = $posx + ($radius * sin($angrad));
414:             $points2[] = $posy + ($radius * cos($angrad));
415:             $visited[] = false;
416:         }
417:         
418:         $points = array();
419:         $idx = 0;
420:         do {
421:             $points[] = $points2[($idx * 2)];
422:             $points[] = $points2[(($idx * 2) + 1)];
423:             $visited[$idx] = true;
424:             $idx += $ngaps;
425:             $idx %= $nvert;
426:         } while (!$visited[$idx]);
427: 
428:         $out .= $this->getPolygon($points, $mode, $styles);
429:         return $out;
430:     }
431: 
432:     /**
433:      * Draws a basic rectangle
434:      *
435:      * @param float  $posx   Abscissa of upper-left corner.
436:      * @param float  $posy   Ordinate of upper-left corner.
437:      * @param float  $width  Width.
438:      * @param float  $height Height.
439:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
440:      * @param array  $style  Style.
441:      *
442:      * @return string PDF command
443:      */
444:     public function getBasicRect($posx, $posy, $width, $height, $mode = 'S', array $style = array())
445:     {
446:         return $this->getStyleCmd($style)
447:             .$this->getRawRect($posx, $posy, $width, $height)
448:             .$this->getPathPaintOp($mode);
449:     }
450: 
451:     /**
452:      * Draws a rectangle with a different style for each segment.
453:      *
454:      * @param float  $posx   Abscissa of upper-left corner.
455:      * @param float  $posy   Ordinate of upper-left corner.
456:      * @param float  $width  Width.
457:      * @param float  $height Height.
458:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
459:      * @param array  $styles Array of styles - one style entry for each side (T,R,B,L) and/or one global "all" entry.
460: 
461:      * @return string PDF command
462:      */
463:     public function getRect($posx, $posy, $width, $height, $mode = 'S', array $styles = array())
464:     {
465:         $points = array(
466:             $posx,
467:             $posy,
468:             $posx + $width,
469:             $posy,
470:             $posx + $width,
471:             $posy + $height,
472:             $posx,
473:             $posy + $height,
474:             $posx,
475:             $posy
476:         );
477:         return $this->getPolygon($points, $mode, $styles);
478:     }
479:     
480:     /**
481:      * Draws a rounded rectangle.
482:      *
483:      * @param float  $posx   Abscissa of upper-left corner.
484:      * @param float  $posy   Ordinate of upper-left corner.
485:      * @param float  $width  Width.
486:      * @param float  $height Height.
487:      * @param float  $hrad   X-axis radius of the ellipse used to round off the corners of the rectangle.
488:      * @param float  $vrad   Y-axis radius of the ellipse used to round off the corners of the rectangle.
489:      * @param string $corner Round corners to draw: 0 (square i-corner) or 1 (rounded i-corner) in i-position.
490:      *                       Positions are int the following order: top right, bottom right, bottom left and top left.
491:      * @param string $mode   Mode of rendering. @see getPathPaintOp()
492:      * @param array  $style  Style.
493:      *
494:      * @return string PDF command
495:      */
496:     public function getRoundedRect(
497:         $posx,
498:         $posy,
499:         $width,
500:         $height,
501:         $hrad,
502:         $vrad,
503:         $corner = '1111',
504:         $mode = 'S',
505:         array $style = array()
506:     ) {
507:         if (($corner === '0000') || (empty($hrad) && empty($vrad))) {
508:             // basic rectangle with straight corners
509:             return $this->getBasicRect($posx, $posy, $width, $height, $mode, $style);
510:         }
511: 
512:         $out = $this->getStyleCmd($style);
513:         if ($corner[3]) {
514:             $out .= $this->getRawPoint(($posx + $hrad), $posy);
515:         } else {
516:             $out .= $this->getRawPoint($posx, $posy);
517:         }
518:         $posxc = ($posx + $width - $hrad);
519:         $posyc = ($posy + $vrad);
520:         $out .= $this->getRawLine($posxc, $posy);
521:         $arc = (4 / 3 * (sqrt(2) - 1));
522:         $harc = ($hrad * $arc);
523:         $varc = ($vrad * $arc);
524:         
525:         if ($corner[0]) {
526:             $out .= $this->getRawCurve(
527:                 ($posxc + $harc),
528:                 ($posyc - $vrad),
529:                 ($posxc + $hrad),
530:                 ($posyc - $varc),
531:                 ($posxc + $hrad),
532:                 $posyc
533:             );
534:         } else {
535:             $out .= $this->getRawLine(($posx + $width), $posy);
536:         }
537:         $posxc = ($posx + $width - $hrad);
538:         $posyc = ($posy + $height - $vrad);
539:         $out .= $this->getRawLine(($posx + $width), $posyc);
540: 
541:         if ($corner[1]) {
542:             $out .= $this->getRawCurve(
543:                 ($posxc + $hrad),
544:                 ($posyc + $varc),
545:                 ($posxc + $harc),
546:                 ($posyc + $vrad),
547:                 $posxc,
548:                 ($posyc + $vrad)
549:             );
550:         } else {
551:             $out .= $this->getRawLine(($posx + $width), ($posy + $height));
552:         }
553:         $posxc = ($posx + $hrad);
554:         $posyc = ($posy + $height - $vrad);
555:         $out .= $this->getRawLine($posxc, ($posy + $height));
556: 
557:         if ($corner[2]) {
558:             $out .= $this->getRawCurve(
559:                 ($posxc - $harc),
560:                 ($posyc + $vrad),
561:                 ($posxc - $hrad),
562:                 ($posyc + $varc),
563:                 ($posxc - $hrad),
564:                 $posyc
565:             );
566:         } else {
567:             $out .= $this->getRawLine($posx, ($posy + $height));
568:         }
569:         $posxc = ($posx + $hrad);
570:         $posyc = ($posy + $vrad);
571:         $out .= $this->getRawLine($posx, $posyc);
572: 
573:         if ($corner[3]) {
574:             $out .= $this->getRawCurve(
575:                 ($posxc - $hrad),
576:                 ($posyc - $varc),
577:                 ($posxc - $harc),
578:                 ($posyc - $vrad),
579:                 $posxc,
580:                 ($posyc - $vrad)
581:             );
582:         } else {
583:             $out .= $this->getRawLine($posx, $posy);
584:         }
585: 
586:         $out .= $this->getPathPaintOp($mode);
587: 
588:         return $out;
589:     }
590: 
591:     /**
592:      * Draws an arrow.
593:      *
594:      * @param float $posx0    Abscissa of first point.
595:      * @param float $posy0    Ordinate of first point.
596:      * @param float $posx1    Abscissa of second point (head side).
597:      * @param float $posy1    Ordinate of second point (head side)
598:      * @param int   $headmode Arrow head mode:
599:      *                        0 = draw only head arms;
600:      *                        1 = draw closed head without filling;
601:      *                        2 = closed and filled head;
602:      *                        3 = filled head.
603:      * @param float $armsize  Length of head arms.
604:      * @param int   $armangle Angle between an head arm and the arrow shaft.
605:      * @param array $style    Line style to apply.
606:      *
607:      * @return string PDF command
608:      */
609:     public function getArrow(
610:         $posx0,
611:         $posy0,
612:         $posx1,
613:         $posy1,
614:         $headmode = 0,
615:         $armsize = 5,
616:         $armangle = 15,
617:         array $style = array()
618:     ) {
619:         // getting arrow direction angle; 0 deg angle is when both arms go along X axis; angle grows clockwise.
620:         $dir_angle = atan2(($posy0 - $posy1), ($posx0 - $posx1));
621:         if ($dir_angle < 0) {
622:             $dir_angle += (2 * self::MPI);
623:         }
624:         $armangle = $this->degToRad($armangle);
625:         $sx1 = $posx1;
626:         $sy1 = $posy1;
627:         if ($headmode > 0) {
628:             // calculate the stopping point for the arrow shaft
629:             $linewidth = 0;
630:             if (isset($style['lineWidth'])) {
631:                 $linewidth = $style['lineWidth'];
632:             } else {
633:                 $linewidth = $this->getLastStyleProperty('lineWidth', $linewidth);
634:             }
635:             $sx1 = ($posx1 + (($armsize - $linewidth) * cos($dir_angle)));
636:             $sy1 = ($posy1 + (($armsize - $linewidth) * sin($dir_angle)));
637:         }
638:         $out = $this->getStyleCmd($style);
639:         // main arrow line / shaft
640:         $out .= $this->getLine($posx0, $posy0, $sx1, $sy1);
641:         // left arrowhead arm tip
642:         $hxl = ($posx1 + ($armsize * cos($dir_angle + $armangle)));
643:         $hyl = ($posy1 + ($armsize * sin($dir_angle + $armangle)));
644:         // right arrowhead arm tip
645:         $hxr = ($posx1 + ($armsize * cos($dir_angle - $armangle)));
646:         $hyr = ($posy1 + ($armsize * sin($dir_angle - $armangle)));
647:         $modemap = array(0 => 'S', 1 => 's', 2 => 'b', 3 => 'f', );
648:         $points = array($hxl, $hyl, $posx1, $posy1, $hxr, $hyr);
649:         $out .= $this->getBasicPolygon($points, $modemap[$headmode], $style);
650:         return $out;
651:     }
652: 
653:     /**
654:      * Get a registration mark.
655:      *
656:      * @param float   $posx   Abscissa of center point.
657:      * @param float   $posy   Ordinate of center point.
658:      * @param float   $rad    Radius.
659:      * @param boolean $double If true prints two concentric crop marks.
660:      * @param array   $color  Color.
661:      *
662:      * @return string PDF command
663:      */
664:     public function getRegistrationMark($posx, $posy, $rad, $double = false, $color = 'all')
665:     {
666:         $style = array(
667:             'lineWidth'  => max((0.5 / $this->kunit), ($rad / 30)),
668:             'lineCap'    => 'butt',
669:             'lineJoin'   => 'miter',
670:             'miterLimit' => (10.0 / $this->kunit),
671:             'dashArray'  => array(),
672:             'dashPhase'  => 0,
673:             'lineColor'  => $color,
674:             'fillColor'  => $color,
675:         );
676:         $out = $this->col->getColorObject($color)->getPdfColor()
677:             .$this->getPieSector($posx, $posy, $rad, 90, 180, 'F')
678:             .$this->getPieSector($posx, $posy, $rad, 270, 360, 'F')
679:             .$this->getCircle($posx, $posy, $rad, 0, 360, 'S', array(), 8);
680:         if ($double) {
681:             $radi = ($rad * 0.5);
682:             $out .= $this->col->getColorObject($color)->invertColor()->getPdfColor()
683:             .$this->getPieSector($posx, $posy, $radi, 90, 180, 'F')
684:             .$this->getPieSector($posx, $posy, $radi, 270, 360, 'F')
685:             .$this->getCircle($posx, $posy, $radi, 0, 360, 'S', array(), 8)
686:             .$this->col->getColorObject($color)->getPdfColor()
687:             .$this->getPieSector($posx, $posy, $radi, 0, 90, 'F')
688:             .$this->getPieSector($posx, $posy, $radi, 180, 270, 'F')
689:             .$this->getCircle($posx, $posy, $radi, 0, 360, 'S', array(), 8);
690:         }
691:         return $this->getStartTransform()
692:             .$this->getStyleCmd($style)
693:             .$out
694:             .$this->getStopTransform();
695:     }
696: 
697:     /**
698:      * Get a CMYK registration mark.
699:      *
700:      * @param float   $posx   Abscissa of center point.
701:      * @param float   $posy   Ordinate of center point.
702:      * @param float   $rad    Radius.
703:      *
704:      * @return string PDF command
705:      */
706:     public function getCmykRegistrationMark($posx, $posy, $rad)
707:     {
708:         // internal radius
709:         $radi = ($rad * 0.6);
710:         // external radius
711:         $rade = ($rad * 1.3);
712:         // line style for external circle
713:         $style = array(
714:             'lineWidth'  => max((0.5 / $this->kunit), ($rad / 30)),
715:             'lineCap'    => 'butt',
716:             'lineJoin'   => 'miter',
717:             'miterLimit' => (10.0 / $this->kunit),
718:             'dashArray'  => array(),
719:             'dashPhase'  => 0,
720:             'lineColor'  => 'All',
721:             'fillColor'  => '',
722:         );
723:         return $this->getStartTransform()
724:             .$this->col->getColorObject('Cyan')->getPdfColor()
725:             .$this->getPieSector($posx, $posy, $radi, 270, 360, 'F')
726:             .$this->col->getColorObject('Magenta')->getPdfColor()
727:             .$this->getPieSector($posx, $posy, $radi, 0, 90, 'F')
728:             .$this->col->getColorObject('Yellow')->getPdfColor()
729:             .$this->getPieSector($posx, $posy, $radi, 90, 180, 'F')
730:             .$this->col->getColorObject('Key')->getPdfColor()
731:             .$this->getPieSector($posx, $posy, $radi, 180, 270, 'F')
732:             .$this->getStyleCmd($style)
733:             .$this->getCircle($posx, $posy, $rad, 0, 360, 'S', array(), 8)
734:             .$this->getLine($posx, ($posy - $rade), $posx, ($posy - $radi))
735:             .$this->getLine($posx, ($posy + $radi), $posx, ($posy + $rade))
736:             .$this->getLine(($posx - $rade), $posy, ($posx - $radi), $posy)
737:             .$this->getLine(($posx + $radi), $posy, ($posx + $rade), $posy)
738:             .$this->getStopTransform();
739:     }
740: }
741: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy