Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Commit

Permalink
Improve documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nstdio committed Sep 1, 2016
1 parent 93a7032 commit b957507
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 36 deletions.
6 changes: 4 additions & 2 deletions src/svg/ElementInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace nstdio\svg;

use DOMDocument;
use DOMElement;
use nstdio\svg\container\ContainerInterface;

/**
Expand All @@ -14,7 +16,7 @@ interface ElementInterface
/**
* Returns the parent element.
*
* @return \DOMElement | ContainerInterface
* @return ContainerInterface|DOMDocument
*/
public function getRoot();

Expand All @@ -28,7 +30,7 @@ public function getName();
/**
* Returns the element itself.
*
* @return \DOMElement | ContainerInterface | XMLDocumentInterface
* @return ContainerInterface|XMLDocumentInterface|DOMElement
*/
public function getElement();

Expand Down
2 changes: 0 additions & 2 deletions src/svg/container/ContainerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function hasChild();

/**
* @param ElementInterface $child
*
* @return void
*/
public function removeChild(ElementInterface $child);
}
84 changes: 76 additions & 8 deletions src/svg/container/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* shall be filled or stroked with the referenced pattern.
*
* @link https://www.w3.org/TR/SVG/pservers.html#Patterns
* @property string patternUnits "userSpaceOnUse | objectBoundingBox" Defines the coordinate system for
* @property string $patternUnits "userSpaceOnUse | objectBoundingBox" Defines the coordinate system for
* attributes 'x',
* 'y', 'width' and 'height'. If patternUnits="userSpaceOnUse", 'x', 'y', 'width' and 'height' represent
* values in the coordinate system that results from taking the current user coordinate system in place at
Expand All @@ -29,7 +29,7 @@
* which the pattern is applied (see Object bounding box units) and then applying the transform specified by
* attribute 'patternTransform'. If attribute 'patternUnits' is not specified, then the effect is as if a
* value of 'objectBoundingBox' were specified.
* @property string patternContentUnits = "userSpaceOnUse | objectBoundingBox" Defines the coordinate system for the
* @property string $patternContentUnits = "userSpaceOnUse | objectBoundingBox" Defines the coordinate system for the
* contents of the ‘pattern’. Note that this attribute has no effect if attribute ‘viewBox’ is specified. If
* patternContentUnits="userSpaceOnUse", the user coordinate system for the contents of the ‘pattern’ element
* is the coordinate system that results from taking the current user coordinate system in place at the time
Expand All @@ -40,26 +40,26 @@
* pattern is applied (see Object bounding box units) and then applying the transform specified by attribute
* ‘patternTransform’. If attribute ‘patternContentUnits’ is not specified, then the effect is as if a value
* of 'userSpaceOnUse' were specified.
* @property string patternTransform = "<transform-list>" Contains the definition of an optional additional
* @property string $patternTransform = "<transform-list>" Contains the definition of an optional additional
* transformation from the pattern coordinate system onto the target coordinate system (i.e.,
* 'userSpaceOnUse' or 'objectBoundingBox'). This allows for things such as skewing the pattern tiles. This
* additional transformation matrix is post-multiplied to (i.e., inserted to the right of) any previously
* defined transformations, including the implicit transformation necessary to convert from object bounding
* box units to user space. If attribute ‘patternTransform’ is not specified, then the effect is as if an
* identity transform were specified.
* @property float x = "<coordinate>" ‘x’, ‘y’, ‘width’ and ‘height’ indicate how the pattern tiles
* @property float $x = "<coordinate>" ‘x’, ‘y’, ‘width’ and ‘height’ indicate how the pattern tiles
* are placed and spaced. These attributes represent coordinates and values in the coordinate space specified
* by the combination of attributes ‘patternUnits’ and ‘patternTransform’. If the attribute is not specified,
* the effect is as if a value of zero were specified.
* @property float y = "<coordinate>" See ‘x’. If the attribute is not specified, the effect is as
* @property float $y = "<coordinate>" See ‘x’. If the attribute is not specified, the effect is as
* if a value of zero were specified.
* @property float width = "<length>" See ‘x’. A negative value is an error (see Error processing). A
* @property float $width = "<length>" See ‘x’. A negative value is an error (see Error processing). A
* value of zero disables rendering of the element (i.e., no paint is applied). If the attribute is not
* specified, the effect is as if a value of zero were specified.
* @property float height = "<length>" See ‘x’. A negative value is an error (see Error processing). A
* @property float $height = "<length>" See ‘x’. A negative value is an error (see Error processing). A
* value of zero disables rendering of the element (i.e., no paint is applied). If the attribute is not
* specified, the effect is as if a value of zero were specified.
* @property float xlink :href = "<iri>" An IRI reference to a different ‘pattern’ element within the
* @property float $xlinkHref = "<iri>" An IRI reference to a different ‘pattern’ element within the
* current SVG document fragment. Any attributes which are defined on the referenced element which are not
* defined on this element are inherited by this element. If this element has no children, and the referenced
* element does (possibly due to its own ‘xlink:href’ attribute), then this element inherits the children
Expand All @@ -73,6 +73,12 @@ class Pattern extends Container implements TransformInterface, Transformable
{
use TransformTrait;

/**
* Pattern constructor.
*
* @param ElementInterface $parent
* @param null|string $id
*/
public function __construct(ElementInterface $parent, $id = null)
{
if ($parent instanceof SVG) {
Expand All @@ -85,11 +91,22 @@ public function __construct(ElementInterface $parent, $id = null)
$this->id = $id;
}

/**
* @inheritdoc
*/
public function getName()
{
return 'pattern';
}

/**
* @param ContainerInterface $container
* @param Shape $shape
* @param array $patternConfig
* @param null $id
*
* @return $this
*/
public static function withShape(ContainerInterface $container, Shape $shape, array $patternConfig = [], $id = null)
{
$patternConfig = array_merge(self::getDefaultConfig(), $patternConfig);
Expand All @@ -105,21 +122,53 @@ public static function withShape(ContainerInterface $container, Shape $shape, ar
return $pattern;
}

/**
* @param ContainerInterface $container
* @param array $patternConfig
* @param array $lineConfig
* @param null|string $id
*
* @return $this
*/
public static function verticalHatch(ContainerInterface $container, array $patternConfig = [], array $lineConfig = [], $id = null)
{
return self::hatch($container, $patternConfig, $lineConfig, $id);
}

/**
* @param ContainerInterface $container
* @param array $patternConfig
* @param array $lineConfig
* @param null|string $id
*
* @return $this
*/
public static function horizontalHatch(ContainerInterface $container, array $patternConfig = [], array $lineConfig = [], $id = null)
{
return self::hatch($container, $patternConfig, $lineConfig, $id)->rotate(90);
}

/**
* @param ContainerInterface $container
* @param array $patternConfig
* @param array $lineConfig
* @param null|string $id
*
* @return $this
*/
public static function diagonalHatch(ContainerInterface $container, array $patternConfig = [], array $lineConfig = [], $id = null)
{
return self::hatch($container, $patternConfig, $lineConfig, $id)->rotate(45);
}

/**
* @param ContainerInterface $container
* @param array $patternConfig
* @param array $lineConfig
* @param null|string $id
*
* @return $this
*/
public static function crossHatch(ContainerInterface $container, array $patternConfig = [], array $lineConfig = [], $id = null)
{
if (isset($patternConfig['width'])) {
Expand Down Expand Up @@ -148,11 +197,27 @@ public static function crossHatch(ContainerInterface $container, array $patternC
return $pattern;
}

/**
* @param ContainerInterface $container
* @param array $patternConfig
* @param array $lineConfig
* @param null|string $id
*
* @return $this
*/
public static function straightCrossHatch(ContainerInterface $container, array $patternConfig = [], array $lineConfig = [], $id = null)
{
return self::crossHatch($container, $patternConfig, $lineConfig, $id)->rotate(90);
}

/**
* @param ContainerInterface $container
* @param array $patternConfig
* @param array $lineConfig
* @param null|string $id
*
* @return $this
*/
protected static function hatch(ContainerInterface $container, array $patternConfig = [], array $lineConfig = [], $id = null)
{
$patternConfig = array_merge(self::getDefaultConfig(), $patternConfig);
Expand All @@ -166,6 +231,9 @@ protected static function hatch(ContainerInterface $container, array $patternCon
return $pattern;
}

/**
* @return array
*/
protected static function getDefaultConfig()
{
return ['x' => 0, 'y' => 0, 'height' => 4, 'width' => 4, 'patternUnits' => 'userSpaceOnUse'];
Expand Down
4 changes: 2 additions & 2 deletions src/svg/container/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function asFile($name, $prettyPrint = false, $override = false)
public function asImageFile($name, $format = IOFormat::PNG, $override = false)
{
return $this->outputImpl->imageFile(
$this->domImpl->saveXML(),
$this->domImpl->saveXML(false),
$name,
$format,
$override
Expand All @@ -189,7 +189,7 @@ public function asImageFile($name, $format = IOFormat::PNG, $override = false)
public function asImage($format = IOFormat::PNG, $sendHeader = false)
{
return $this->outputImpl->image(
$this->domImpl->saveXML(),
$this->domImpl->saveXML(false),
$format,
$sendHeader
);
Expand Down
12 changes: 6 additions & 6 deletions src/svg/filter/BaseFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
/**
* Class BaseFilter
*
* @property float x = "<coordinate>" The minimum x coordinate for the subregion which restricts
* @property float $x = "<coordinate>" The minimum x coordinate for the subregion which restricts
* calculation and rendering of the given filter primitive.
* @property float y = "<coordinate>" The minimum y coordinate for the subregion which restricts
* @property float $y = "<coordinate>" The minimum y coordinate for the subregion which restricts
* calculation and rendering of the given filter primitive.
* @property float width = "<length>" The width of the subregion which restricts calculation and
* @property float $width = "<length>" The width of the subregion which restricts calculation and
* rendering of the given filter primitive. See filter primitive subregion. A negative value is an error. A
* value of zero disables the effect of the given filter primitive (i.e., the result is a transparent black
* image).
* @property float height = "<length>" The height of the subregion which restricts calculation and rendering of
* @property float $height = "<length>" The height of the subregion which restricts calculation and rendering of
* the given filter primitive. See filter primitive subregion. A negative value is an error (see Error
* processing). A value of zero disables the effect of the given filter primitive (i.e., the result is a
* transparent black image).
* @property string result = "<filter-primitive-reference>" Assigned name for this filter primitive. If supplied,
* @property string $result = "<filter-primitive-reference>" Assigned name for this filter primitive. If supplied,
* then graphics that result from processing this filter primitive can be referenced by an 'in' attribute on
* a subsequent filter primitive within the same 'filter' element. If no value is provided, the output will
* only be available for re-use as the implicit input into the next filter primitive if that filter primitive
Expand All @@ -29,7 +29,7 @@
* only local scope. It is legal for the same <filter-primitive-reference> to appear multiple times within
* the same 'filter' element. When referenced, the <filter-primitive-reference> will use the closest
* preceding filter primitive with the given result.
* @property string in = "SourceGraphic | SourceAlpha | BackgroundImage | BackgroundAlpha | FillPaint |
* @property string $in = "SourceGraphic | SourceAlpha | BackgroundImage | BackgroundAlpha | FillPaint |
* StrokePaint | <filter-primitive-reference>" Identifies input for the given filter primitive. The value can
* be either one of six keywords or can be a string which matches a previous 'result' attribute value within
* the same 'filter' element. If no value is provided and this is the first filter primitive, then this
Expand Down
6 changes: 3 additions & 3 deletions src/svg/filter/DiffuseLighting.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
* light color is specified by property ‘lighting-color’.
*
* @link https://www.w3.org/TR/SVG11/filters.html#feDiffuseLightingElement
* @property float surfaceScale = "<number>" height of surface when Ain = 1. If the attribute is not specified,
* @property float $surfaceScale = "<number>" height of surface when Ain = 1. If the attribute is not specified,
* then
* the effect is as if a value of 1 were specified.
* @property float diffuseConstant = "<number>" kd in Phong lighting model. In SVG, this can be any non-negative
* @property float $diffuseConstant = "<number>" kd in Phong lighting model. In SVG, this can be any non-negative
* number. If the attribute is not specified, then the effect is as if a value of 1 were specified.
* @property float kernelUnitLength = "<number-optional-number>" The first number is the <dx> value. The second number
* @property float $kernelUnitLength = "<number-optional-number>" The first number is the <dx> value. The second number
* is the <dy> value. If the <dy> value is not specified, it defaults to the same value as <dx>. Indicates
* the intended distance in current filter units (i.e., units as determined by the value of attribute
* ‘primitiveUnits’) for dx and dy, respectively, in the surface normal calculation formulas. By specifying
Expand Down
6 changes: 3 additions & 3 deletions src/svg/gradient/Gradient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __construct(ElementInterface $parent, $id = null)
*/
public function appendStop(Stop $stop)
{
$stops = func_get_args();
foreach ($stops as $stop) {
$this->append($stop);
$stop = func_get_args();
foreach ($stop as $item) {
$this->append($item);
}
}
}
25 changes: 15 additions & 10 deletions src/svg/traits/ChildTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ trait ChildTrait
protected $child;

/**
* @inheritdoc
* @param string $name
*
* @return ContainerInterface[]
*/
public function getChild($name)
{
Expand All @@ -41,7 +43,9 @@ public function getChild($name)
}

/**
* @inheritdoc
* @param $id
*
* @return ContainerInterface
*/
public function getChildById($id)
{
Expand All @@ -64,8 +68,7 @@ public function getChildById($id)
}

/**
* @inheritdoc
* @return ElementInterface
* @return ContainerInterface|null
*/
public function getFirstChild()
{
Expand All @@ -77,41 +80,43 @@ public function getFirstChild()
}

/**
* @inheritdoc
* @return bool
*/
public function hasChild()
{
return count($this->child) > 0;
}

/**
* @inheritdoc
* @return ContainerInterface[]|ElementStorage
*/
public function getChildren()
{
return $this->child;
}

/**
* @inheritdoc
* @param $index
*
* @return ContainerInterface|SVGElement|null
*/
public function getChildAtIndex($index)
{
return $this->child[$index];
}

/**
* @inheritdoc
* @param ElementInterface $child
*/
public function removeChild(ElementInterface $child)
{
$this->child->remove($child);
/** @var XMLDocumentInterface $element */
$element = $this->getElement();
if ($element instanceof \DOMNode) {
return $element->removeChild($child->getElement()->getElement());
$element->removeChild($child->getElement()->getElement());
} else {
return $element->removeNode($child->getElement());
$element->removeNode($child->getElement());
}
}
}

0 comments on commit b957507

Please sign in to comment.