aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref
diff options
context:
space:
mode:
authorFelix E. Klee2019-07-15 17:07:56 +0200
committerLars Ingebrigtsen2019-07-15 17:07:56 +0200
commitd6bc55ae2dc98c83e58a28e380ce4bcf2ed00bb3 (patch)
tree47e633d687d0bda97e8613c57bed4ab816e55d44 /doc/lispref
parent3b6992118501d0a17b6817a91011f8e8dcdf8164 (diff)
downloademacs-d6bc55ae2dc98c83e58a28e380ce4bcf2ed00bb3.tar.gz
emacs-d6bc55ae2dc98c83e58a28e380ce4bcf2ed00bb3.zip
Add support for paths to svg.el
* doc/lispref/display.texi (SVG Images): Document svg-path, svg-clip-path and svg-node (bug#32359). * doc/lispref/display.texi (SVG Path Commands): New node. * lisp/svg.el (svg--plist-delete, svg--path-command-symbol) (svg--elliptical-arc-coordinates, svg--elliptical-arc-command) (svg--moveto-command, svg--closepath-command) (svg--lineto-command, svg--horizontal-lineto-command) (svg--vertical-lineto-command, svg--curveto-command) (svg--smooth-curveto-command) (svg--quadratic-bezier-curveto-command) (svg--smooth-quadratic-bezier-curveto-command) (svg--eval-path-command, svg-path, svg-clip-path, svg-node): New functions.
Diffstat (limited to 'doc/lispref')
-rw-r--r--doc/lispref/display.texi237
1 files changed, 237 insertions, 0 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index a38569f7263..ecaf2e054e0 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -5587,6 +5587,9 @@ The identified of the shape.
5587@item :gradient 5587@item :gradient
5588If given, this should be the identifier of a previously defined 5588If given, this should be the identifier of a previously defined
5589gradient object. 5589gradient object.
5590
5591@item :clip-path
5592Identifier of a clip path.
5590@end table 5593@end table
5591 5594
5592@defun svg-rectangle svg x y width height &rest args 5595@defun svg-rectangle svg x y width height &rest args
@@ -5634,6 +5637,29 @@ that describe the outer circumference of the polygon.
5634@end lisp 5637@end lisp
5635@end defun 5638@end defun
5636 5639
5640@defun svg-path svg commands &rest args
5641Add the outline of a shape to @var{svg} according to @var{commands},
5642see @ref{SVG Path Commands}.
5643
5644Coordinates by default are absolute. To use coordinates relative to
5645the last position, or -- initially -- to the origin, set the attribute
5646@var{:relative} to @code{t}. This attribute can be specified for the
5647function or for individual commands. If specified for the function,
5648then all commands use relative coordinates by default. To make an
5649individual command use absolute coordinates, set @var{:relative} to
5650@code{nil}.
5651
5652@lisp
5653(svg-path svg
5654 '((moveto ((100 . 100)))
5655 (lineto ((200 . 0) (0 . 200) (-200 . 0)))
5656 (lineto ((100 . 100)) :relative nil))
5657 :stroke-color "blue"
5658 :fill-color "lightblue"
5659 :relative t)
5660@end lisp
5661@end defun
5662
5637@defun svg-text svg text &rest args 5663@defun svg-text svg text &rest args
5638Add the specified @var{text} to @var{svg}. 5664Add the specified @var{text} to @var{svg}.
5639 5665
@@ -5665,6 +5691,30 @@ string containing the image data as raw bytes. @var{image-type} should be a
5665@end lisp 5691@end lisp
5666@end defun 5692@end defun
5667 5693
5694@defun svg-clip-path svg &rest args
5695Add a clipping path to @var{svg}. If applied to a shape via the
5696@var{:clip-path} property, parts of that shape which lie outside of
5697the clipping path are not drawn.
5698
5699@lisp
5700(let ((clip-path (svg-clip-path svg :id "foo")))
5701 (svg-circle clip-path 200 200 175))
5702(svg-rectangle svg 50 50 300 300
5703 :fill-color "red"
5704 :clip-path "url(#foo)")
5705@end lisp
5706@end defun
5707
5708@defun svg-node svg tag &rest args
5709Add the custom node @var{tag} to @var{svg}.
5710
5711@lisp
5712(svg-node svg
5713 'rect
5714 :width 300 :height 200 :x 50 :y 100 :fill-color "green")
5715@end lisp
5716@end defun
5717
5668@defun svg-remove svg id 5718@defun svg-remove svg id
5669Remove the element with identifier @code{id} from the @code{svg}. 5719Remove the element with identifier @code{id} from the @code{svg}.
5670@end defun 5720@end defun
@@ -5687,6 +5737,193 @@ circle:
5687@end lisp 5737@end lisp
5688 5738
5689 5739
5740@node SVG Path Commands
5741@subsubsection SVG Path Commands
5742
5743@deffn Command moveto points
5744Move the pen to the first point in @var{points}. Additional points
5745are connected with lines. @var{points} is a list of X/Y coordinate
5746pairs. Subsequent @command{moveto} commands represent the start of a
5747new @dfn{subpath}.
5748
5749@lisp
5750(svg-path svg '((moveto ((200 . 100) (100 . 200) (0 . 100))))
5751 :fill "white" :stroke "black")
5752@end lisp
5753@end deffn
5754
5755@deffn Command closepath
5756End the current subpath by connecting it back to its initial point. A
5757line is drawn along the connection.
5758
5759@lisp
5760(svg-path svg '((moveto ((200 . 100) (100 . 200) (0 . 100)))
5761 (closepath)
5762 (moveto ((75 . 125) (100 . 150) (125 . 125)))
5763 (closepath))
5764 :fill "red" :stroke "black")
5765@end lisp
5766@end deffn
5767
5768@deffn Command lineto points
5769Draw a line from the current point to the first element in
5770@var{points}, a list of X/Y position pairs. If more than one point is
5771specified, draw a polyline.
5772@lisp
5773(svg-path svg '((moveto ((200 . 100)))
5774 (lineto ((100 . 200) (0 . 100))))
5775 :fill "yellow" :stroke "red")
5776@end lisp
5777@end deffn
5778
5779@deffn Command horizontal-lineto x-coordinates
5780Draw a horizontal line from the current point to the first element in
5781@var{x-coordinates}. Specifying multiple coordinates is possible,
5782although usually this doesn’t make sense.
5783
5784@lisp
5785(svg-path svg '((moveto ((100 . 200)))
5786 (horizontal-lineto (300)))
5787 :stroke "green")
5788@end lisp
5789@end deffn
5790
5791@deffn Command vertical-lineto y-coordinates
5792Draw vertical lines.
5793
5794@lisp
5795(svg-path svg '((moveto ((200 . 100)))
5796 (vertical-lineto (300)))
5797 :stroke "green")
5798@end lisp
5799@end deffn
5800
5801@deffn Command curveto coordinate-sets
5802Using the first element in @var{coordinate-sets}, draw a cubic Bézier
5803curve from the current point. If there are multiple coordinate sets,
5804draw a polybézier. Each coordinate set is a list of the form
5805@code{(@var{x1} @var{y1} @var{x2} @var{y2} @var{x} @var{y})}, where
5806@w{(@var{x}, @var{y})} is the curve’s end point. @w{(@var{x1},
5807@var{y1})} and @w{(@var{x2}, @var{y2})} are control points at the
5808beginning and at the end, respectively.
5809
5810@lisp
5811(svg-path svg '((moveto ((100 . 100)))
5812 (curveto ((200 100 100 200 200 200)
5813 (300 200 0 100 100 100))))
5814 :fill "transparent" :stroke "red")
5815@end lisp
5816@end deffn
5817
5818@deffn Command smooth-curveto coordinate-sets
5819Using the first element in @var{coordinate-sets}, draw a cubic Bézier
5820curve from the current point. If there are multiple coordinate sets,
5821draw a polybézier. Each coordinate set is a list of the form
5822@code{(@var{x2} @var{y2} @var{x} @var{y})}, where @w{(@var{x},
5823@var{y})} is the curve’s end point and @w{(@var{x2}, @var{y2})} is the
5824corresponding control point. The first control point is the
5825reflection of the second control point of the previous command
5826relative to the current point, if that command was @command{curveto}
5827or @command{smooth-curveto}. Otherwise the first control point
5828coincides with the current point.
5829
5830@lisp
5831(svg-path svg '((moveto ((100 . 100)))
5832 (curveto ((200 100 100 200 200 200)))
5833 (smooth-curveto ((0 100 100 100))))
5834 :fill "transparent" :stroke "blue")
5835@end lisp
5836@end deffn
5837
5838@deffn Command quadratic-bezier-curveto coordinate-sets
5839Using the first element in @var{coordinate-sets}, draw a quadratic
5840Bézier curve from the current point. If there are multiple coordinate
5841sets, draw a polybézier. Each coordinate set is a list of the form
5842@code{(@var{x1} @var{y1} @var{x} @var{y})}, where @w{(@var{x},
5843@var{y})} is the curve’s end point and @w{(@var{x1}, @var{y1})} is the
5844control point.
5845
5846@lisp
5847(svg-path svg '((moveto ((200 . 100)))
5848 (quadratic-bezier-curveto ((300 100 300 200)))
5849 (quadratic-bezier-curveto ((300 300 200 300)))
5850 (quadratic-bezier-curveto ((100 300 100 200)))
5851 (quadratic-bezier-curveto ((100 100 200 100))))
5852 :fill "transparent" :stroke "pink")
5853@end lisp
5854@end deffn
5855
5856@deffn Command smooth-quadratic-bezier-curveto coordinate-sets
5857Using the first element in @var{coordinate-sets}, draw a quadratic
5858Bézier curve from the current point. If there are multiple coordinate
5859sets, draw a polybézier. Each coordinate set is a list of the form
5860@code{(@var{x} @var{y})}, where @w{(@var{x}, @var{y})} is the curve’s
5861end point. The control point is the reflection of the control point
5862of the previous command relative to the current point, if that command
5863was @command{quadratic-bezier-curveto} or
5864@command{smooth-quadratic-bezier-curveto}. Otherwise the control
5865point coincides with the current point.
5866
5867@lisp
5868(svg-path svg '((moveto ((200 . 100)))
5869 (quadratic-bezier-curveto ((300 100 300 200)))
5870 (smooth-quadratic-bezier-curveto ((200 300)))
5871 (smooth-quadratic-bezier-curveto ((100 200)))
5872 (smooth-quadratic-bezier-curveto ((200 100))))
5873 :fill "transparent" :stroke "lightblue")
5874@end lisp
5875@end deffn
5876
5877@deffn Command elliptical-arc coordinate-sets
5878Using the first element in @var{coordinate-sets}, draw an elliptical
5879arc from the current point. If there are multiple coordinate sets,
5880draw a sequence of elliptical arcs. Each coordinate set is a list of
5881the form @code{(@var{rx} @var{ry} @var{x} @var{y})}, where
5882@w{(@var{x}, @var{y})} is the end point of the ellipse, and
5883@w{(@var{rx}, @var{ry})} are its radii. Attributes may be appended to
5884the list:
5885
5886@table @code
5887@item :x-axis-rotation
5888The angle in degrees by which the x-axis of the ellipse is rotated
5889relative to the x-axis of the current coordinate system.
5890
5891@item :large-arc
5892If set to @code{t}, draw an arc sweep greater than or equal to 180
5893degrees. Otherwise, draw an arc sweep smaller than or equal to 180
5894degrees.
5895
5896@item :sweep
5897If set to @code{t}, draw an arc in @dfn{positive angle direction}.
5898Otherwise, draw it in @dfn{negative angle direction}.
5899@end table
5900
5901@lisp
5902(svg-path svg '((moveto ((200 . 250)))
5903 (elliptical-arc ((75 75 200 350))))
5904 :fill "transparent" :stroke "red")
5905(svg-path svg '((moveto ((200 . 250)))
5906 (elliptical-arc ((75 75 200 350 :large-arc t))))
5907 :fill "transparent" :stroke "green")
5908(svg-path svg '((moveto ((200 . 250)))
5909 (elliptical-arc ((75 75 200 350 :sweep t))))
5910 :fill "transparent" :stroke "blue")
5911(svg-path svg '((moveto ((200 . 250)))
5912 (elliptical-arc ((75 75 200 350 :large-arc t
5913 :sweep t))))
5914 :fill "transparent" :stroke "gray")
5915(svg-path svg '((moveto ((160 . 100)))
5916 (elliptical-arc ((40 100 80 0)))
5917 (elliptical-arc ((40 100 -40 -70
5918 :x-axis-rotation -120)))
5919 (elliptical-arc ((40 100 -40 70
5920 :x-axis-rotation -240))))
5921 :stroke "pink" :fill "lightblue"
5922 :relative t)
5923@end lisp
5924@end deffn
5925
5926
5690@node Other Image Types 5927@node Other Image Types
5691@subsection Other Image Types 5928@subsection Other Image Types
5692@cindex PBM 5929@cindex PBM