[pstricks] Arbitrary dash patterns in pstricks.tex

i at tn-home.de i at tn-home.de
Sat Jul 17 15:51:40 CEST 2004


Hello,

@all:
I've implemented (almost) arbitrary dash patterns into pstricks and
would appreciate if someone could test it.

@Herbert: If it is evaluated to be worthy, then it would be nice if
you could take it over to the official pstricks version.

@all:
The changed pstricks.tex - file is:
http://www.tn-home.de/Tobias/Soft/TeX/PSTricks/pstricks040717.tex

The changed pstricks.pro - file is:
http://www.tn-home.de/Tobias/Soft/TeX/PSTricks/pstricks040717.pro

For testing, save the files pstricks040717.tex and pstricks040717.pro
(with these names) into your working directory and load
pstricks040717.tex via

\input{pstricks040717}

in your document preamble as a replacement for pstricks.tex.

One example for a test is:
http://www.tn-home.de/Tobias/Soft/TeX/PSTricks/test-dash040717.tex

@Herbert:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The changes in pstricks.tex:
(replacements for \psset at dash and \psls at dashed)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Begin patch TN; Date (YY-MM-DD): 04-07-17; first part
\def\psset at dash#1{%
\pst at expandafter\psset@@dash{#1}\@nil% Error handling for empty argument.
}
\def\psset@@dash#1\@nil{%
 \def\psk at dash{}%
 \def\next##1 ##2\relax{%
   \edef\@tempa{##1}%
   \ifx\@tempa\@empty\else% gobble leading spaces
   \pssetlength\pst at dimc{##1}%
   \edef\psk at dash{\psk at dash\space\pst at number\pst at dimc}%
   \fi%
   \edef\@tempa{##2}%
   \ifx\@tempa\@empty\else% detect end
   \ifx\@tempa\space\else% gobble trailing spaces
     \next##2\relax%
   \fi\fi%
 }%
\expandafter\next#1 \relax}
%% End patch TN; Date (YY-MM-DD): 04-07-17; 1st part
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\psset at dash{5pt 3pt}% black white black white 
%%------------------- end patch 15 HV 2004-05-15 -------------
\newif\ifpsdashadjust
\def\psset at dashadjust#1{\@nameuse{psdashadjust#1}}
\psset at dashadjust{true}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Begin patch TN; Date (YY-MM-DD): 04-07-17; 2nd part
\def\psls at dashed{%
  \ifpsdashadjust
    [ \psk at dash ] \pst at linetype\space \tx at DashLine
  \else
    [ \psk at dash ] 0 setdash stroke
  \fi}
%% End patch TN; Date (YY-MM-DD): 04-07-17; 2nd part
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





The changes in pstricks.pro:
(replacement for /DashLine ... def
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TN begin patch; Date (YY-MM-DD): 04-07-17;
/DashLine {
    dup 0 gt
    { /a .5 def PathLength exch div }
    { pop /a 1 def PathLength } ifelse
    /b ED % pattern should fit evenly in b
    dup /X ED % pattern array
    0 get /y ED % length of first black segment
    /z 0 X {add} forall def % length of the full pattern
    %% Computation of the scaling factor as described by van Zandt:
    b a .5 sub 2 mul y mul sub z Div round
    z mul a .5 sub 2 mul y mul add b exch Div
    %%%% scaling factor on stack.
    /z ED %% now, z is the scaling factor
    /X [ X { z mul } forall ] def
    %%% Checking whether at least one dash has positive length:
    false X {0 gt or} forall
    { X 1 a sub y mul }
    { [ 1 0 ] 0 }
    ifelse
    setdash stroke } def
%% TN end patch; Date (YY-MM-DD): 04-07-17;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




More information about the PSTricks mailing list