summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfit.code.tex
blob: 1181dabea5fc5fb71b89acc959d2930b0e689fbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
% Copyright 2007 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfit.code.tex,v 1.2 2008/02/06 22:18:29 tantau Exp $

\pgfkeys{/tikz/fit/.code=\tikz@lib@fit{#1}}

\def\tikz@lib@fit#1{%
  \pgf@xb=-16000pt\relax%
  \pgf@xa=16000pt\relax%
  \pgf@yb=-16000pt\relax%
  \pgf@ya=16000pt\relax%
  % Now iterate over the coordinates
  \tikz@lib@fit@scan#1\pgf@stop%
  % Now, let's see what has happend
  \ifdim\pgf@xa>\pgf@xa%
    % Nothing... Ok, let's just ignore this.
  \else%
    % Ok, compute center and width and height
    \pgf@x=\pgf@xb%
    \advance\pgf@x by-\pgf@xa%
    \pgf@y=\pgf@yb%
    \advance\pgf@y by-\pgf@ya%
    \advance\pgf@xa by.5\pgf@x%
    \advance\pgf@ya by.5\pgf@y%
    \edef\tikz@node@at{\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}%
    \pgfkeysalso{/tikz/anchor=center,/tikz/text centered}%
    \pgfkeysalso{/tikz/text width/.expanded=\the\pgf@x}%
    \pgf@x=\pgf@y%
    \pgf@y=.5\pgf@y%
    \pgfkeysalso{
      /tikz/text height/.expanded=\the\pgf@y-.5\dp\pgfnodeparttextbox,
      /tikz/text depth/.expanded=\the\pgf@x-\noexpand\the\ht\pgfnodeparttextbox}%
    \pgfkeysalso{every fit/.try}%
  \fi%
}

\def\tikz@lib@fit@scan{%
  \pgfutil@ifnextchar\pgf@stop{\pgfutil@gobble}
  {\tikz@scan@one@point\tikz@lib@fit@scan@handle}}

\def\tikz@lib@fit@scan@handle#1{%
  \iftikz@shapeborder%
    % Ok, fit all four external anchors, if they exist
    \tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{west}}%
    \tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{east}}%
    \tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{north}}%
    \tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{south}}%
  \else%
    \tikz@lib@fit@adjust{#1}%
  \fi%
  \tikz@lib@fit@scan%
}

\def\tikz@lib@fit@adjust#1{%
  \pgf@process{#1}%
  \ifdim\pgf@x<\pgf@xa%
    \pgf@xa=\pgf@x%
  \fi%
  \ifdim\pgf@y<\pgf@ya%
    \pgf@ya=\pgf@y%
  \fi%
  \ifdim\pgf@x>\pgf@xb%
    \pgf@xb=\pgf@x%
  \fi%
  \ifdim\pgf@y>\pgf@yb%
    \pgf@yb=\pgf@y%
  \fi%
}

\endinput