summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-01-28 22:44:16 +0000
committerKarl Berry <karl@freefriends.org>2014-01-28 22:44:16 +0000
commita2be3e804efcd0ae25349c50199baddb24b5c343 (patch)
tree4daa73e0add0c223a15e43056a02d5cc3e0a168d /Master/texmf-dist/tex/generic
parent6558684eddf81be5903af36a77fad398f63bd9c5 (diff)
pdf-trans (28jan14)
git-svn-id: svn://tug.org/texlive/trunk@32809 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic')
-rw-r--r--Master/texmf-dist/tex/generic/pdf-trans/pdf-trans.tex92
1 files changed, 62 insertions, 30 deletions
diff --git a/Master/texmf-dist/tex/generic/pdf-trans/pdf-trans.tex b/Master/texmf-dist/tex/generic/pdf-trans/pdf-trans.tex
index 4326d3187d3..870e1dacb99 100644
--- a/Master/texmf-dist/tex/generic/pdf-trans/pdf-trans.tex
+++ b/Master/texmf-dist/tex/generic/pdf-trans/pdf-trans.tex
@@ -1,8 +1,8 @@
%%% A set of macros for various transformations of TeX boxes.
-%%% (bases on plain and pdfeTeX primitives)
+%%% (bases on plain and pdf(e)TeX primitives)
%
-% Version: 2.3
-% Author: Pawe/l Jackowski (P.Jackowski@gust.org.pl)
+% Version: 2.4
+% Author: Pawe{\l} Jackowski (P.Jackowski@gust.org.pl)
% Public Domain
%
% The macro provides a bunch of TeX box transformations. It was initially
@@ -38,6 +38,18 @@
% (minus sign remains)
% * \roundbponce renamed to \round:bp:once
%
+% 01.2014, v2.4
+% * some rework on pdf unit related macros
+% - \t@bp renamed to \asbp as pretty useful converter to big points (with no rounding)
+% - new macro \roundbpto{0..4}{<dimexpr>} rounds #2 to #1 digits
+% - \roundbp now always rounds to \pdfdecimaldigits
+% - \enablebpround, \disablebpround and \setbpround now redefine \tobp:
+% - \enablebpround makes \tobp equivalent to \roundbp
+% - \disablebpround makes \tobp equivalent to \asbp
+% - \setbpround{0..4} makes \tobp equivalent to \roundbpto{#1}
+% - removed \romannumeral from csnames, decimal digits used instead
+% - removed \big:p@ints
+
\def\starttrans{%
\xdef\endtrans{%
@@ -1041,42 +1053,68 @@
\endgroup
\def\withoutpt{\expandafter\with@ut:pt}
-\def\big:p@ints#1#2{#1\the\dimexpr#2*\pt:f@ctor/\bp:f@ctor\relax}
\def\negbp#1{\withoutpt\the\dimexpr-#1pt\relax}
+\def\asbp#1{\withoutpt\the\dimexpr#1*\pt:f@ctor/\bp:f@ctor\relax}
% If we assume that \pdfdecimaldigits never exceeds possible range (0..4),
% we can implement PDF dimens rounding in the following way:
-\def\t@bp{\big:p@ints\withoutpt}
-
+% \def\roundbp#1{%
+% \expandafter\expandafter
+% \csname r@und:bp:\the\pdfdecimaldigits\expandafter\endcsname
+% \expandafter\with@ut:pt\the\dimexpr(#1)*\pt:f@ctor/\bp:f@ctor\relax0000\relax}
+% or with less \expandafters
\def\roundbp#1{%
- \expandafter\expandafter
- \csname r@und:bp:\romannumeral\pdfdecimaldigits\expandafter\endcsname
- \expandafter\with@ut:pt\the\dimexpr(#1)*\pt:f@ctor/\bp:f@ctor\relax0000\relax}
-
-\def\r@und:bp: #1.#2#3\relax{\number\numexpr#1#2/10\relax}
-\def\r@und:bp:i #1.#2#3#4\relax{\round:bp:once{#1}{#2#3}\relax}
-\def\r@und:bp:ii #1.#2#3#4#5\relax{\round:bp:once{#1}{#2#3#4}\relax}
-\def\r@und:bp:iii #1.#2#3#4#5#6\relax{\round:bp:once{#1}{#2#3#4#5}\relax}
-\def\r@und:bp:iv #1.#2#3#4#5#6#7\relax{\round:bp:once{#1}{#2#3#4#5#6}\relax}
+ \expandafter\r@undbp\the\dimexpr(#1)*\pt:f@ctor/\bp:f@ctor\relax0000\relax}
+\def\r@undbp{%
+ \csname r@und:bp:\the\pdfdecimaldigits\expandafter\endcsname
+ \with@ut:pt}
-% To speed-up things one may say
-
-\def\setbpround#1{% 0..4
- \edef\roundbp##1{%
- \unexpanded{\expandafter\expandafter\expandafter}\expandafter\noexpand
- \csname r@und:bp:\romannumeral#1\endcsname
- \unexpanded{\expandafter\with@ut:pt\the}%
- \dimexpr(##1)*\unexpanded{\pt:f@ctor/\bp:f@ctor}\relax0000\relax}}
+\expandafter\def\csname r@und:bp:0\endcsname #1.#2#3\relax{\number\numexpr#1#2/10\relax}
+\expandafter\def\csname r@und:bp:1\endcsname #1.#2#3#4\relax{\round:bp:once{#1}{#2#3}\relax}
+\expandafter\def\csname r@und:bp:2\endcsname #1.#2#3#4#5\relax{\round:bp:once{#1}{#2#3#4}\relax}
+\expandafter\def\csname r@und:bp:3\endcsname #1.#2#3#4#5#6\relax{\round:bp:once{#1}{#2#3#4#5}\relax}
+\expandafter\def\csname r@und:bp:4\endcsname #1.#2#3#4#5#6#7\relax{\round:bp:once{#1}{#2#3#4#5#6}\relax}
\def\round:bp:once#1#2{%
- %\number\numexpr#1\ifnum#1<0-\else+\fi % 15.10.2013: wrong! that drops minus sign in case -0.xxxx
+ % 15.10.2013: that is wrong! that drops minus sign in case -0.xxxx
+ %\number\numexpr#1\ifnum#1<0-\else+\fi
%(\m@ne+\expandafter\r@und:bp:once\number\numexpr1#2/10\relax}
+ % that works but may produce -0.0
\ifnum#11<0-\number\numexpr-\else\number\numexpr\fi
#1+(\m@ne+\expandafter\r@und:bp:once\number\numexpr1#2/10\relax}
+ % 21.01.2014: but both rounds 0.9995bp to 0.999, while they should to 1.0,
+ % but this is a cost of bp<->pt conversion
\def\r@und:bp:once#1#2\relax{#1)\relax\ifnum#2>0.#2\fi}
+% To change rounding digits and speed-up a little one may say \setbpround 0..4
+
+\def\set:bp:rounder#1#2{% 0..4
+ \expandafter\edef\csname #1:\the\numexpr#2\relax\endcsname##1{%
+ \unexpanded{\expandafter\expandafter\expandafter}\expandafter\noexpand
+ \csname r@und:bp:\the\numexpr#2\relax\endcsname
+ \unexpanded{\expandafter\with@ut:pt\the}%
+ \dimexpr(##1)*\unexpanded{\pt:f@ctor/\bp:f@ctor}\relax0000\relax}}
+
+\set:bp:rounder{roundbpto}{0}
+\set:bp:rounder{roundbpto}{1}
+\set:bp:rounder{roundbpto}{2}
+\set:bp:rounder{roundbpto}{3}
+\set:bp:rounder{roundbpto}{4}
+
+\def\roundbpto#1{\csname roundbpto:#1\endcsname}
+
+\def\enablebpround{\let\tobp\roundbp}
+\def\disablebpround{\let\tobp\asbp}
+\def\setbpround#1{\expandafter\let\expandafter\tobp\csname roundbpto:\the\numexpr#1\relax\endcsname}
+
+% By default, \tobp respects \pdfdecimaldigits
+
+\enablebpround
+
+% save rounded to macro
+
\def\savebp#1{%
\def\s@vebp{%
\edef#1{\tobp{\bp:dim@n}}}%
@@ -1084,12 +1122,6 @@
\newdimen\bp:dim@n
-\def\disablebpround{\let\tobp\t@bp}
-\def\enablebpround{\let\tobp\roundbp}
-
-%\disablebpround
-\enablebpround
-
% Lets play with basic arithmetic operations. To make things consistent, each
% function expands to \numexpr|\dimexpr, even if could be easily expanded to
% digits. This approach ensures predictable behaviour whenever a \function is