summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/sttools/boundbox.sty
blob: 1799613f736d8b79cbc93cd0a658acd9460eeb2f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
%%
%% This is file `boundbox.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% boundbox.dtx  (with options: `package')
%% 
%% Copyright (C) 1997-2012 by Sigitas Tolu\v{s}is <sigitas@vtex.lt>
%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
%% http://www.vtex.lt/tex/download/macros/
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% PURPOSE: Calculate TeX bounding box in rounded points (LaTeX2e)
%%          from left top corner of the paper
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{boundbox}
    [2012/05/29 v1.3 Calculate TeX bounding box in points]
%%
\newif\if@withfoot \@withfoottrue
\newif\if@output@bbox@special \@output@bbox@specialtrue
\DeclareOption{nofoot}{\global\@withfootfalse}
\DeclareOption{nospec}{\global\@output@bbox@specialfalse}
\ProcessOptions
%%
\def\special@bbox@odd@prefix{mt:TeXBBox:odd}
\def\special@bbox@even@prefix{mt:TeXBBox:even}
%%
\def\roundtexdim#1#{\round@tex@dim{#1}}
\def\round@tex@dim#1#2#3{%
  \expandafter\expandafter\csname get@#1@pt@data\endcsname\the#2\to#3\relax
  }
\def\get@floor@pt@data#1.#2#3\to#4{%
  \bgroup
    \@tempcnta=#1\relax
    \xdef#4{\the\@tempcnta}%
  \egroup
  }
\def\get@round@pt@data#1.#2#3\to#4{%
  \bgroup
    \@tempcnta=#1\relax
    \ifnum#2>4\relax
      \advance\@tempcnta by\@ne
    \fi
    \xdef#4{\the\@tempcnta}%
  \egroup
  }
\let\get@@pt@data\get@round@pt@data
\def\get@ceil@pt@data#1.#2#3\to#4{%
  \bgroup
    \@tempcnta=#1\relax
    \afterassignment\@gobbletwo
    \@tempcntb=#2#3\relax
    \ifnum\@tempcntb>0\relax
      \advance\@tempcnta by\@ne
    \fi
    \xdef#4{\the\@tempcnta}%
  \egroup
  }
\def\@calculate@bbox{%
  \bgroup
    \@tempdima=1in\relax
    \advance\@tempdima by\hoffset
    \advance\@tempdima by\oddsidemargin
    \roundtexdim floor{\@tempdima}\bbox@odd@left@pt
    \advance\@tempdima\textwidth
    \roundtexdim ceil{\@tempdima}\bbox@odd@right@pt
    \@tempdima=1in\relax
    \advance\@tempdima by\hoffset
    \advance\@tempdima by\evensidemargin
    \roundtexdim floor{\@tempdima}\bbox@even@left@pt
    \advance\@tempdima\textwidth
    \roundtexdim ceil{\@tempdima}\bbox@even@right@pt
    \@tempdima=1in\relax
    \advance\@tempdima by\voffset
    \advance\@tempdima by\topmargin
    \roundtexdim floor{\@tempdima}\bbox@odd@top@pt
    \global\let\bbox@even@top@pt\bbox@odd@top@pt
    \advance\@tempdima by\headheight
    \advance\@tempdima by\headsep
    \advance\@tempdima\textheight
    \if@withfoot
      \advance\@tempdima\footskip
    \fi
    \roundtexdim ceil{\@tempdima}\bbox@odd@bottom@pt
    \global\let\bbox@even@bottom@pt\bbox@odd@bottom@pt
  \egroup
  }
%%
\AtBeginDocument{%
  \@calculate@bbox
  \if@output@bbox@special
    \special{\special@bbox@odd@prefix\space
           left=\csname bbox@odd@left@pt\endcsname\space
           top=\csname bbox@odd@top@pt\endcsname\space
           right=\csname bbox@odd@right@pt\endcsname\space
           bottom=\csname bbox@odd@bottom@pt\endcsname
           }%
    \special{\special@bbox@even@prefix\space
           left=\csname bbox@even@left@pt\endcsname\space
           top=\csname bbox@even@top@pt\endcsname\space
           right=\csname bbox@even@right@pt\endcsname\space
           bottom=\csname bbox@even@bottom@pt\endcsname
           }%
  \fi
  }
\endinput
%%
%% End of file `boundbox.sty'.