diff options
author | Karl Berry <karl@freefriends.org> | 2009-12-31 01:40:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-12-31 01:40:09 +0000 |
commit | f84374dfd46b282099b639296e3b952f4d52746f (patch) | |
tree | 5494a9c99e49aad4e33ed49bc04f36b78bb03b6e /Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex | |
parent | e70f23cf27d400ee9d1cd7afa8fa7de6896c1b69 (diff) |
tikz-qtree update (26dec09)
git-svn-id: svn://tug.org/texlive/trunk@16546 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex | 116 |
1 files changed, 98 insertions, 18 deletions
diff --git a/Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex b/Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex index 928ae336e95..4acd7d57b28 100644 --- a/Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex +++ b/Master/texmf-dist/tex/latex/tikz-qtree/pgfsubpic.tex @@ -1,5 +1,5 @@ % pgfsubpic.tex -% Version 1, 22 Dec 2009 +% Version 1.1, 25 Dec 2009 % Copyright 2009 by David Chiang @@ -17,6 +17,14 @@ % with this program; if not, write to the Free Software Foundation, Inc., % 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +% New in version 1.1: +% - the ability to save a subpicture in local variables +% - nodes in subpictures are tracked if the subpicture is placed with arbitrary transforms +% - new \pgffitsubpicture macro to transform a subpicture (preserving aspect) to fit in a desired box + +% To do: +% - speed up interpictureshift hook by promoting subsubpictures + \newdimen\pgf@subpicminx \newdimen\pgf@subpicminy \newdimen\pgf@subpicmaxx @@ -28,14 +36,15 @@ \def\southwest{\pgfqpoint{\pgf@subpicminx}{\pgf@subpicminy}}% \def\northeast{\pgfqpoint{\pgf@subpicmaxx}{\pgf@subpicmaxy}}% } -\expandafter\def\csname pgf@sh@nt@current subpicture\endcsname{{1}{0}{0}{1}{0pt}{0pt}} +\expandafter\def\csname pgf@sh@nt@current subpicture\endcsname{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}} % the transformation at invocation time \expandafter\def\csname pgf@sh@pi@current subpicture\endcsname{\pgfpictureid} % Create a pgfpicture inside an hbox for delayed placement \def\pgfsubpicture{% -\global\setbox\pgf@hbox=\hbox\bgroup -\pgfinterruptpicture% -\pgfpicture% +\expandafter\global\expandafter\setbox\pgf@hbox=\hbox\bgroup +\pgfinterruptpicture +\pgfpicture +\relax % not sure why. otherwise a curly brace immediately after causes an error } \def\endpgfsubpicture{ @@ -50,19 +59,51 @@ \egroup } +% Allocate registers for saving a subpicture. #1 is text, not a control sequence. +\def\pgfnewsubpicture#1{% +\expandafter\newbox\csname pgf@subpic@hbox@#1\endcsname +\expandafter\newdimen\csname pgf@subpic@minx@#1\endcsname +\expandafter\newdimen\csname pgf@subpic@miny@#1\endcsname +\expandafter\newdimen\csname pgf@subpic@maxx@#1\endcsname +\expandafter\newdimen\csname pgf@subpic@maxy@#1\endcsname +} + +% saved subpictures are local to the current group +\def\pgfsavesubpicture#1{% +\expandafter\setbox\csname pgf@subpic@hbox@#1\endcsname\copy\pgf@hbox +\csname pgf@subpic@minx@#1\endcsname\pgf@subpicminx +\csname pgf@subpic@miny@#1\endcsname\pgf@subpicminy +\csname pgf@subpic@maxx@#1\endcsname\pgf@subpicmaxx +\csname pgf@subpic@maxy@#1\endcsname\pgf@subpicmaxy +\expandafter\edef\csname pgf@subpic@id@#1\endcsname{\subpictureid} +} + +\def\pgfrestoresubpicture#1{% +\edef\act{\global\noexpand\setbox\pgf@hbox\noexpand\copy\csname pgf@subpic@hbox@#1\endcsname}\act +\expandafter\global\expandafter\pgf@subpicminx\csname pgf@subpic@minx@#1\endcsname +\expandafter\global\expandafter\pgf@subpicminy\csname pgf@subpic@miny@#1\endcsname +\expandafter\global\expandafter\pgf@subpicmaxx\csname pgf@subpic@maxx@#1\endcsname +\expandafter\global\expandafter\pgf@subpicmaxy\csname pgf@subpic@maxy@#1\endcsname +\xdef\subpictureid{\csname pgf@subpic@id@#1\endcsname} +} + % Place a previously-created subpicture, lining up its origin with the current origin \def\pgfplacesubpicture{ \pgfscope % expand current bounding box to accommodate subpicture -\pgfpathmoveto{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}% -\pgfpathlineto{\pgfpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}% +\pgfpathrectanglecorners{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}{\pgfpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}% \pgfusepath{use as bounding box}% -% save relative position of subpicture inside containing picture -\pgfpointorigin -\pgf@pos@transform{\pgf@x}{\pgf@y}% -\expandafter\xdef\csname pgf@subpic@\subpictureid @x\endcsname{\the\pgf@x}% -\expandafter\xdef\csname pgf@subpic@\subpictureid @y\endcsname{\the\pgf@y}% -\expandafter\xdef\csname pgf@subpic@\subpictureid @p\endcsname{\pgfpictureid}% +% +% make the subpicture a node in the containing picture +\expandafter\gdef\csname pgf@sh@ns@\subpictureid\endcsname{rectangle} +\expandafter\xdef\csname pgf@sh@np@\subpictureid\endcsname{% + \noexpand\def\noexpand\southwest{\noexpand\pgfqpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}% + \noexpand\def\noexpand\northeast{\noexpand\pgfqpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}% +}% +\pgfgettransform\pgf@temp +\expandafter\xdef\csname pgf@sh@nt@\subpictureid\endcsname{\pgf@temp}% +\expandafter\xdef\csname pgf@sh@pi@\subpictureid\endcsname{\pgfpictureid}% +% % align origin of subpicture with origin \pgftransformshift{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}% \pgfqboxsynced{\pgf@hbox}% @@ -73,6 +114,13 @@ % This is called whenever we look up an anchor of a node. % This hook recursively checks to see if the node's picture % is a subpicture of another, and if so, adjusts its position accordingly. + +% This is slow. It makes drawing trees O(n^2) in the depth of the tree. +% The alternative is to store, for each picture, a list of the nodes +% inside it. But this way doesn't require us to hijack \pgfnode, and +% is robust to re-placement of a subpicture. A compromise would be +% to store, for each picture, a list of the *subpictures* inside it. + \let\orig@pgf@shape@interpictureshift\pgf@shape@interpictureshift \def\unwind@subpic#1{% % is #1 the current picture? @@ -81,14 +129,18 @@ % yes, we're done \else % does #1 have a parent picture? -\expandafter\ifx\csname pgf@subpic@#1@p\endcsname\relax +\expandafter\ifx\csname pgf@sh@pi@#1\endcsname\relax % no, the original node was not inside the current picture \fallback \else -% yes, apply shift and move up to parent picture -\global\advance\pgf@x by \csname pgf@subpic@#1@x\endcsname -\global\advance\pgf@y by \csname pgf@subpic@#1@y\endcsname -\unwind@subpic{\csname pgf@subpic@#1@p\endcsname}% +% yes, apply transform and move up to parent picture +{% + \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}% + \pgf@pos@transform{\pgf@x}{\pgf@y}% + \global\pgf@x=\pgf@x + \global\pgf@y=\pgf@y +}% +\unwind@subpic{\csname pgf@sh@pi@#1\endcsname}% \fi \fi } @@ -97,6 +149,33 @@ \unwind@subpic{\csname pgf@sh@pi@#1\endcsname}% } +% \pgffitsubpicture{sw}{ne} +% Make the subpicture fit in the rectangle from sw to ne, preserving its aspect ratio. +\def\pgffitsubpicture#1#2{% +% current size +\pgfpointdiff{\pgfpointanchor{current subpicture}{south west}}{\pgfpointanchor{current subpicture}{north east}}% +\pgf@xa=\pgf@x \pgf@ya=\pgf@y +% desired size +\pgf@process{\pgfpointdiff{#1}{#2}}% +\pgf@xb=\pgf@x \pgf@yb=\pgf@y +\pgfmathparse{min(\pgf@xb/\pgf@xa,\pgf@yb/\pgf@ya)}% +\pgfmathparse{min(1,\pgfmathresult)}% +\pgftransformscale{\pgfmathresult}% +% +% current position +\pgfpointanchor{current subpicture}{center}% +\pgf@xa=\pgf@x \pgf@ya=\pgf@y +% desired position +% we scaled transform, so apply reverse scaling to argument +\pgfmathparse{1/\pgfmathresult}% +\pgf@process{\pgfpointscale{\pgfmathresult}{\pgfpointlineattime{0.5}{#1}{#2}}}% +\pgf@xb=\pgf@x \pgf@yb=\pgf@y +\pgfpointdiff{\pgfpoint{\pgf@xa}{\pgf@ya}}{\pgfpoint{\pgf@xb}{\pgf@yb}}% +\pgftransformshift{\pgfpoint{\pgf@x}{\pgf@y}}% +} + +% utility functions -- not currently used + \def\pgfnodedelete#1{% \expandafter\global\expandafter\let\csname pgf@sh@ns@#1\endcsname\relax \expandafter\global\expandafter\let\csname pgf@sh@np@#1\endcsname\relax @@ -108,3 +187,4 @@ \def\pgfnodeifexists#1#2#3{% \expandafter\ifx\csname pgf@sh@ns@#1\endcsname\relax#3\else#2\fi } + |