[latex3-commits] [git/LaTeX3-latex3-latex3] master: Lots of additional drawing examples [ci skip] (23c2c96)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Feb 23 22:44:56 CET 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/23c2c96f9da2e6d7c8e3305dca368f7b4d7968b3

>---------------------------------------------------------------

commit 23c2c96f9da2e6d7c8e3305dca368f7b4d7968b3
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Feb 23 21:44:56 2018 +0000

    Lots of additional drawing examples [ci skip]
    
    As close as possible to the pgf ones on the same functions.


>---------------------------------------------------------------

23c2c96f9da2e6d7c8e3305dca368f7b4d7968b3
 l3experimental/l3draw/l3draw.dtx |  225 ++++++++++++++++++++++++++++++++------
 1 file changed, 189 insertions(+), 36 deletions(-)

diff --git a/l3experimental/l3draw/l3draw.dtx b/l3experimental/l3draw/l3draw.dtx
index 7dbd340..57de250 100644
--- a/l3experimental/l3draw/l3draw.dtx
+++ b/l3experimental/l3draw/l3draw.dtx
@@ -50,13 +50,14 @@
     {%
        basicstyle   = \small\ttfamily,
        basewidth    = 0.51em,
-       gobble       = 3,
+       gobble       = 5,
        language     = [LaTeX]{TeX},
     }%
 }
 \newcommand*\demo at input{%
   \ExplSyntaxOn
   \catcode`\^^M = 10\relax
+  \catcode`\% = 14\relax
   \input{\jobname.tmp}%
   \ExplSyntaxOff
 }
@@ -145,6 +146,17 @@
 %   The drawing created within the environment will be inserted into
 %   the typesetting stream by the \cs{draw_end:} function, which will
 %   switch out of vertical mode if required.
+%   \begin{demo}
+%     \dim_new:N \l_mypos_dim
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , \l_mypos_dim }
+%       \draw_path_lineto:n { 1cm , \l_mypos_dim }
+%       \dim_set:Nn \l_mypos_dim { 1cm }
+%       \draw_path_lineto:n { 1cm , \l_mypos_dim }
+%       \draw_path_close:
+%       \draw_path_use_clear:n { stroke }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % Within a drawing, there are different ways of referring to a position.
@@ -156,18 +168,6 @@
 % axes at the driver level: this is then \enquote{transparent} to the
 % \pkg{draw} level, and so should be used only when strictly required.)
 %
-% \begin{demo}
-%   \dim_new:N \l_mypos_dim
-%   \draw_begin:
-%     \draw_path_moveto:n { 0cm , \l_mypos_dim }
-%     \draw_path_lineto:n { 1cm , \l_mypos_dim }
-%     \dim_set:Nn \l_mypos_dim { 1cm }
-%     \draw_path_lineto:n { 1cm , \l_mypos_dim }
-%     \draw_path_close:
-%     \draw_path_use:n { stroke }
-%   \draw_end:
-% \end{demo}
-%
 % \subsection{Graphics state}
 %
 % Within the drawing environment, a number of functions control how drawings
@@ -184,23 +184,22 @@
 %   A scope forms a \TeX{} group but will also localise global state
 %   variables (such as \cs{g_draw_linewidth_default_dim}), and driver-level
 %   concepts such as the termination of lines.
-% \end{function}
-%
-% \begin{demo}
-%   \draw_begin:
-%     \draw_scope_begin:
-%       \group_begin:
-%         \draw_linewidth:n { 2pt }
-%         \draw_path_rectangle:nn { 0 , 0 } { 2ex , 2ex }
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_scope_begin:
+%         \group_begin:
+%           \draw_linewidth:n { 2pt }
+%           \draw_path_rectangle:nn { 0 , 0 } { 2ex , 2ex }
+%           \draw_path_use:n  { stroke }
+%         \group_end:
+%         \draw_path_rectangle:nn { 3ex , 0ex } { 2ex , 2ex }
 %         \draw_path_use:n  { stroke }
-%       \group_end:
-%       \draw_path_rectangle:nn { 3ex , 0ex } { 2ex , 2ex }
-%       \draw_path_use:n  { stroke }
-%     \draw_scope_end:
-%     \draw_path_rectangle:nn { 6ex , 0ex } { 2ex , 2ex }
-%     \draw_path_use:n  { stroke }
-%   \draw_end:
-% \end{demo}
+%       \draw_scope_end:
+%       \draw_path_rectangle:nn { 6ex , 0ex } { 2ex , 2ex }
+%       \draw_path_use_clear:n  { stroke }
+%     \draw_end:
+%   \end{demo}
+% \end{function}
 %
 % \begin{function}{\g_draw_linewidth_default_dim}
 %   The default value of the linewidth for stokes, set at the start
@@ -523,6 +522,32 @@
 %     \cs{draw_path_lineto:n} \Arg{point}
 %   \end{syntax}
 %   Joins the current path to the \meta{point} with a straight line.
+%   In general, for reliable treatment by viewers, a \cs{draw_path_moveto:n}
+%   operation should precede the first use of a \cs{draw_path_lineto:n}
+%   on a path.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_lineto:n { 1cm , 1cm }
+%       \draw_path_lineto:n { 2cm , 1cm }
+%       \draw_path_lineto:n { 3cm , 0.5cm }
+%       \draw_path_lineto:n { 3cm , 0cm }
+%       \draw_color_fill:n {  yellow!80!black }
+%       \draw_path_use_clear:n { fill , stroke }
+%     \draw_end:
+%   \end{demo}
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_lineto:n { 1cm , 1cm }
+%       \draw_path_lineto:n { 2cm , 1cm }
+%       \draw_path_moveto:n { 2cm , 1cm }  % Begins a new part
+%       \draw_path_lineto:n { 3cm , 0.5cm }
+%       \draw_path_lineto:n { 3cm , 0cm }
+%       \draw_color_fill:n {  yellow!80!black }
+%       \draw_path_use_clear:n { fill , stroke }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % \begin{function}{\draw_path_curveto:nnn}
@@ -530,7 +555,21 @@
 %     \cs{draw_path_curveto:nnn} \Arg{control1} \Arg{control2} \Arg{end}
 %   \end{syntax}
 %   Joins the current path to the \meta{end} with a curved line defined by
-%   cubic Bézier points \meta{control1} and \meta{control2}.
+%   cubic Bézier points \meta{control1} and \meta{control2}. The bounding box
+%   of the path (and image) will fully-contain the curve and control points,
+%   \emph{i.e.}~it may be bigger than strictly necessary to contain the curve
+%   \emph{alone}.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_curveto:nnn
+%         { 1cm , 1cm }
+%         { 2cm , 1cm }
+%         { 3cm , 0cm }
+%       \draw_color_fill:n {  yellow!80!black }
+%       \draw_path_use_clear:n { fill , stroke }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % \begin{function}{\draw_path_curveto:nn}
@@ -538,7 +577,20 @@
 %     \cs{draw_path_curveto:nn} \Arg{control} \Arg{end}
 %   \end{syntax}
 %   Joins the current path to the \meta{end} with a curved line defined by
-%   quadratic Bézier point \meta{control}.
+%   quadratic Bézier point \meta{control}. The bounding box
+%   of the path (and image) will fully-contain the curve and computed (cubic)
+%   control points, \emph{i.e.}~it may be bigger than strictly necessary to
+%   contain the curve \emph{alone}.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_curveto:nn
+%         { 1cm , 1cm }
+%         { 2cm , 0cm }
+%       \draw_color_fill:n {  yellow!80!black }
+%       \draw_path_use_clear:n { fill , stroke }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % \begin{function}{\draw_path_arc:nnn, \draw_path_arc:nnnn}
@@ -549,9 +601,26 @@
 %   Joins the current path with an arc between \meta{angle1} and \meta{angle2}
 %   and of \meta{radius}. The four-argument version accepts two radii of
 %   different lengths.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_lineto:n { 0cm , 1cm }
+%       \draw_path_arc:nnn { 180 } { 90 } { 0.5cm }
+%       \draw_path_lineto:n { 3cm , 1.5cm }
+%       \draw_path_arc:nnn { 90 } { -45 } { 0.5cm }
+%       \draw_path_use_clear:n { fill }
+%     \draw_end:
+%   \end{demo}
 %
 %   Note the interface here has a different argument ordering from that in
 %   \pkg{pgf}, which has the two centers then the two radii.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_arc:nnnn { 180 } { 45 } { 2cm } { 1cm }
+%       \draw_path_use_clear:n { stroke }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % \begin{function}{\draw_path_arc_axes:nnnn}
@@ -559,15 +628,49 @@
 %     \cs{draw_path_arc_axes:nnn} \Arg{angle1} \Arg{angle2} \Arg{vector1} \Arg{vector2}
 %   \end{syntax}
 %   Appends the portion of an ellipse from \meta{angle1} to \meta{angle2} of an
-%   ellipse with axes along \meta{vector1} and \meta{vector2} to the current path. 
-% \end{function}
-%
-% \begin{function}{\draw_path_ellipse:nnnn}
+%   ellipse with axes along \meta{vector1} and \meta{vector2} to the current
+%   path.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_lineto:n { 2cm , 5mm }
+%       \draw_path_moveto:n { 0cm , 0cm }
+%       \draw_path_lineto:n { 0cm , 1cm }
+%       \draw_path_moveto:n { 2cm , 5mm }
+%       \draw_path_arc_axes:nnnn { 0 } { 90 }
+%         { 2cm , 5mm } { 0cm , 1cm }
+%       \draw_path_use_clear:n { stroke }
+%     \draw_end:
+%   \end{demo}
+% \end{function}
+%
+% \begin{function}{\draw_path_ellipse:nnn}
 %   \begin{syntax}
 %     \cs{draw_path_ellipse:nnn} \Arg{center} \Arg{vector1} \Arg{vector2}
 %   \end{syntax}
 %   Appends an ellipse at \meta{center} with axes along \meta{vector1} and
-%   \meta{vector2} to the current path. 
+%   \meta{vector2} to the current path. A new part is started if the path
+%   is already non-empty. Notice that the underlying drawing is constructed
+%   from arcs with appropriate moves: the interfaces is a more efficient
+%   convenience.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_ellipse:nnn
+%         { 1cm , 0cm }
+%         { 1.5cm , 0cm }
+%         { 0cm , 1cm }
+%       \draw_path_use_clear:n { stroke }
+%       \draw_color:n { red }
+%       \draw_path_ellipse:nnn
+%         { 1cm , 0cm }
+%         { 1cm , 1cm }
+%         { -0.5cm , 0.5cm }
+%       \draw_path_use_clear:n { stroke }
+%     \draw_end:
+%   \end{demo}
+%
+%   Note that any transformation is applied to the completed ellipse rather than
+%   to the axes.
 % \end{function}
 %
 % \begin{function}{\draw_path_circle:nn}
@@ -575,6 +678,7 @@
 %     \cs{draw_path_circle:nn} \Arg{center} \Arg{radius}
 %   \end{syntax}
 %   Appends a circle of \meta{radius} at \meta{center} to the current path. 
+%   This is a shortcut for \cs{draw_path_ellipse:nnn}.
 % \end{function}
 %
 % \begin{function}{\draw_path_rectangle:nn, \draw_path_rectangle_corners:nn}
@@ -585,6 +689,28 @@
 %   Appends a rectangle starting at \meta{lower-left} to the current path,
 %   with the size of the rectangle determined either by a \meta{displacement}
 %   or the position of the \meta{top-right}.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_rectangle:nn
+%         { 1cm , 0cm }
+%         { 1.5cm , 1cm }
+%       \draw_path_rectangle:nn
+%         { 1.5cm , 0.25cm }
+%         { 1.5cm , 1cm }
+%       \draw_path_rectangle:nn
+%         { 2cm , 0.5cm }
+%         { 1.5cm , 1cm }
+%       \draw_path_use_clear:n { draw }
+%     \draw_end:
+%   \end{demo}
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_path_rectangle_corners:nn
+%         { 1cm , 0cm }
+%         { 1.5cm , 1cm }
+%       \draw_path_use_clear:n { draw }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % \begin{function}{\draw_path_grid:nnnn}
@@ -594,6 +720,33 @@
 %   Constructs a grid of \meta{xspace} and \meta{yspace} from the
 %   \meta{lower-left} to the \meta{upper-right}, and appends this to the
 %   current path.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_linewidth:n { 0.8pt }
+%       \draw_path_grid:nnnn
+%         { 1cm } { 1cm }
+%         { -3mm , -3mm }
+%         { 33mm , 23mm }
+%       \draw_linewidth:n { 0.4pt }
+%       \draw_path_grid:nnnn
+%         { 1mm } { 1mm }
+%         { -1.5mm , -1.5mm }
+%         { 31.5mm , 21.5mm }
+%       \draw_path_use_clear:n { stroke }
+%     \draw_end:
+%   \end{demo}
+%
+%   Any transformation is applied to the finished grid.
+%   \begin{demo}
+%     \draw_begin:
+%       \draw_transform_rotate:n { 10 }
+%       \draw_path_grid:nnnn
+%         { 1mm } { 2mm }
+%         { 0mm , 0mm }
+%         { 30mm , 30mm }
+%       \draw_path_use_clear:n { stroke }
+%     \draw_end:
+%   \end{demo}
 % \end{function}
 %
 % \subsubsection{Path operations on canvas axes}





More information about the latex3-commits mailing list