Skip to content

Commit

Permalink
Add dash patterns to drawings
Browse files Browse the repository at this point in the history
This rounds out l3draw-scope, at least until inner
lines are sorted out.
  • Loading branch information
josephwright committed Mar 8, 2018
1 parent e14d3b3 commit c7a957f
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 24 deletions.
36 changes: 36 additions & 0 deletions l3experimental/l3draw/l3draw-state.dtx
Expand Up @@ -58,6 +58,15 @@
%<@@=draw>
% \end{macrocode}
%
% This sub-module covers more-or-less the same ideas as
% \texttt{pgfcoregraphicstate.code.tex}. At present, equivalents of the
% following are currently absent:
% \begin{itemize}
% \item \cs{pgfsetinnerlinewidth}, \cs{pgfinnerlinewidth},
% \cs{pgfsetinnerstrokecolor}, \cs{pgfsetinnerstrokecolor}: Likely to
% be added on further work is done on paths/stroking.
% \end{itemize}
%
% \begin{variable}{\g_@@_linewidth_dim}
% Linewidth for strokes: global as the scope for this relies on the graphics
% state. The inner line width is used for places where two lines are used.
Expand Down Expand Up @@ -86,6 +95,33 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\draw_dash_pattern:nn}
% \begin{variable}{\l_@@_tmp_clist}
% Evaluated all of the list and pass it to the driver layer.
% \begin{macrocode}
\cs_new_protected:Npn \draw_dash_pattern:nn #1#2
{
\group_begin:
\clist_clear:N \l_@@_tmp_clist
\clist_map_inline:nn {#1}
{
\clist_put_right:Nx \l_@@_tmp_clist
{ \fp_to_dim:n {##1} }
}
\clist_set:Nn \l_@@_tmp_clist {#1}
\use:x
{
\driver_draw_dash_pattern:nn
{ \clist_use:Nnnn \l_@@_tmp_clist { , } { , } { , } }
{ \fp_to_dim:n {#2} }
}
\group_end:
}
\clist_new:N \l_@@_tmp_clist
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\draw_miterlimit:n}
% Pass through to the driver layer.
% \begin{macrocode}
Expand Down
38 changes: 38 additions & 0 deletions l3experimental/l3draw/l3draw.dtx
Expand Up @@ -226,6 +226,44 @@
% \meta{fp expr}).
% \end{function}
%
% \begin{function}{\draw_dash_pattern:nn}
% \begin{syntax}
% \cs{draw_dash_pattern:nn} \Arg{pattern} \Arg{phase}
% \end{syntax}
% Specifies a dash pattern. The \meta{pattern} itself is a comma-separated
% list of entries which represent the \enquote{on} and \enquote{off}
% parts of the line. These are all \meta{fp expr} and repeat as required.
% Thus the \meta{pattern} may be of arbitrary length. The \meta{phase}
% specifies where during the first \enquote{on} line the pattern should
% start.
% \begin{demo}
% \draw_begin:
% \draw_dash_pattern:nn
% { 0.5cm , 0.5cm , 0.1cm , 0.2cm }
% { 0cm }
% \draw_path_moveto:n { 0cm , 0cm }
% \draw_path_lineto:n { 2cm , 0cm }
% \draw_path_use_clear:n { stroke }
% \draw_dash_pattern:nn
% { 0.5cm , 0.5cm , 0.1cm , 0.2cm }
% { 0.1cm }
% \draw_path_moveto:n { 0cm , 1mm }
% \draw_path_lineto:n { 2cm , 1mm }
% \draw_path_use_clear:n { stroke }
% \draw_dash_pattern:nn
% { 0.5cm , 0.5cm , 0.1cm , 0.2cm }
% { 0.2cm }
% \draw_path_moveto:n { 0cm , 2mm }
% \draw_path_lineto:n { 2cm , 2mm }
% \draw_path_use_clear:n { stroke }
% \draw_end:
% \end{demo}
% Setting an empty pattern will produce a solid line.
%
% Note the \meta{pattern} interface here is different from that in \pkg{pgf}:
% the list is comma-separated not given in brace groups.
% \end{function}
%
% \begin{function}{\draw_nonzero_rule:, \draw_evenodd_rule:}
% \begin{syntax}
% \cs{draw_nonzero_rule:}
Expand Down
6 changes: 6 additions & 0 deletions l3experimental/l3draw/testfiles/m3draw004.lvt
Expand Up @@ -44,6 +44,12 @@
\test:n { \draw_linewidth:n { 1pt } }
}

\TEST { \draw_dash_pattern:nn }
{
\test:n { \draw_dash_pattern:nn { } { 0 } }
\test:n { \draw_dash_pattern:nn { 0.2cm , 0.2cm } { 0 } }
\test:n { \draw_dash_pattern:nn { 0.2cm , 0.2cm } { 0.1cm } }
}

\TEST { \draw_cap_... }
{
Expand Down
70 changes: 64 additions & 6 deletions l3experimental/l3draw/testfiles/m3draw004.ptex.tlg
Expand Up @@ -61,7 +61,65 @@ TEST 2: \draw_linewidth:n
l. ... }
============================================================
============================================================
TEST 3: \draw_cap_ ...
TEST 3: \draw_dash_pattern:nn
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
.\hbox(284.92755+0.0)x57.30551
..\glue 0.2
..\hbox(0.0+0.0)x0.0, shifted -0.2
...\special{x:gsave}
...\special{pdf:literal 0.3985 w}
...\special{color push gray 0}
...\special{pdf:literal [] 0 d}
...\special{pdf:literal 0 0 m}
...\special{pdf:literal 28.34647 283.46457 l}
...\special{pdf:literal 56.69292 0 l}
...\special{pdf:literal S}
...\special{x:grestore}
...\special{color pop}
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(284.92755+0.0)x57.30551
.\hbox(284.92755+0.0)x57.30551
..\glue 0.2
..\hbox(0.0+0.0)x0.0, shifted -0.2
...\special{x:gsave}
...\special{pdf:literal 0.3985 w}
...\special{color push gray 0}
...\special{pdf:literal [5.6692 5.6692] 0 d}
...\special{pdf:literal 0 0 m}
...\special{pdf:literal 28.34647 283.46457 l}
...\special{pdf:literal 56.69292 0 l}
...\special{pdf:literal S}
...\special{x:grestore}
...\special{color pop}
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(284.92755+0.0)x57.30551
.\hbox(284.92755+0.0)x57.30551
..\glue 0.2
..\hbox(0.0+0.0)x0.0, shifted -0.2
...\special{x:gsave}
...\special{pdf:literal 0.3985 w}
...\special{color push gray 0}
...\special{pdf:literal [5.6692 5.6692] 2.83464 d}
...\special{pdf:literal 0 0 m}
...\special{pdf:literal 28.34647 283.46457 l}
...\special{pdf:literal 56.69292 0 l}
...\special{pdf:literal S}
...\special{x:grestore}
...\special{color pop}
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 4: \draw_cap_ ...
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -119,7 +177,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 4: \draw_join_ ...
TEST 5: \draw_join_ ...
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -177,7 +235,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 5: \draw_miterlimit:n
TEST 6: \draw_miterlimit:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -235,7 +293,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 6: \draw_color:n
TEST 7: \draw_color:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -285,7 +343,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 7: \draw_color_fill:n
TEST 8: \draw_color_fill:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -313,7 +371,7 @@ TEST 7: \draw_color_fill:n
l. ... }
============================================================
============================================================
TEST 8: \draw_color_stroke:n
TEST 9: \draw_color_stroke:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down
70 changes: 64 additions & 6 deletions l3experimental/l3draw/testfiles/m3draw004.tlg
Expand Up @@ -61,7 +61,65 @@ TEST 2: \draw_linewidth:n
l. ... }
============================================================
============================================================
TEST 3: \draw_cap_ ...
TEST 3: \draw_dash_pattern:nn
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
.\hbox(284.92755+0.0)x57.30551
..\glue 0.2
..\hbox(0.0+0.0)x0.0, shifted -0.2
...\pdfsave
...\pdfliteral{0.3985 w}
...\pdfcolorstack 0 push {0 g 0 G}
...\pdfliteral{[] 0 d}
...\pdfliteral{0 0 m}
...\pdfliteral{28.34647 283.46457 l}
...\pdfliteral{56.69292 0 l}
...\pdfliteral{S}
...\pdfrestore
...\pdfcolorstack 0 pop
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(284.92755+0.0)x57.30551
.\hbox(284.92755+0.0)x57.30551
..\glue 0.2
..\hbox(0.0+0.0)x0.0, shifted -0.2
...\pdfsave
...\pdfliteral{0.3985 w}
...\pdfcolorstack 0 push {0 g 0 G}
...\pdfliteral{[5.6692 5.6692] 0 d}
...\pdfliteral{0 0 m}
...\pdfliteral{28.34647 283.46457 l}
...\pdfliteral{56.69292 0 l}
...\pdfliteral{S}
...\pdfrestore
...\pdfcolorstack 0 pop
! OK.
<argument> \l_tmpa_box
l. ... }
> \box...=
\hbox(284.92755+0.0)x57.30551
.\hbox(284.92755+0.0)x57.30551
..\glue 0.2
..\hbox(0.0+0.0)x0.0, shifted -0.2
...\pdfsave
...\pdfliteral{0.3985 w}
...\pdfcolorstack 0 push {0 g 0 G}
...\pdfliteral{[5.6692 5.6692] 2.83464 d}
...\pdfliteral{0 0 m}
...\pdfliteral{28.34647 283.46457 l}
...\pdfliteral{56.69292 0 l}
...\pdfliteral{S}
...\pdfrestore
...\pdfcolorstack 0 pop
! OK.
<argument> \l_tmpa_box
l. ... }
============================================================
============================================================
TEST 4: \draw_cap_ ...
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -119,7 +177,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 4: \draw_join_ ...
TEST 5: \draw_join_ ...
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -177,7 +235,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 5: \draw_miterlimit:n
TEST 6: \draw_miterlimit:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -235,7 +293,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 6: \draw_color:n
TEST 7: \draw_color:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -285,7 +343,7 @@ l. ... }
l. ... }
============================================================
============================================================
TEST 7: \draw_color_fill:n
TEST 8: \draw_color_fill:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down Expand Up @@ -316,7 +374,7 @@ TEST 7: \draw_color_fill:n
l. ... }
============================================================
============================================================
TEST 8: \draw_color_stroke:n
TEST 9: \draw_color_stroke:n
============================================================
> \box...=
\hbox(284.92755+0.0)x57.30551
Expand Down

0 comments on commit c7a957f

Please sign in to comment.