Skip to content

Commit f852623

Browse files
Always improve scaling iteratively, if necessary
1 parent 6b1671d commit f852623

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tikzscale.dtx

+15-5
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ and the derived files tikzscale.ins,
307307
%
308308
% \section{Further Ideas}
309309
% \begin{itemize}
310-
% \item Improve scaling iteratively until it is good enough if only either width or height has been given.
311310
% \item At least give a clear error message for unscalable plots.
312311
% \item the package can test if a pgfplot is used (needed due to keepAspectRatio in pgfplots) by changing the width and or height and measuring. If nothing changes, it must be a normal tikzpicture (the argument does not hold the other way round).
313312
% \item The final sizing parameters should be saved per figure in the aux file. The first rendering each run should be performed with the aux file's parameters into an sbox. The scaling algorithms should only be called, if the sizing requirements are not met.
@@ -655,10 +654,21 @@ and the derived files tikzscale.ins,
655654
\pgfmathsetmacro{\tikzscale@scale}{(\tikzsize - \fixedSize) / (\measuredFirst - \fixedSize)}%
656655
% \end{macrocode}
657656
% Additionally or alternatively the brute force approach to iteratively improve the solution can be used.
658-
%^^A \foreach \l in {1,...,3}{%
659-
%^^A \sbox{\tikzscale@measuredSize}{\BODY}%
660-
%^^A \pgfmathsetglobalmacro{\tikzscale@scale}{\tikzscale@scale*\tikzsize/#1\tikzscale@measuredSize}%
661-
%^^A }%
657+
% \begin{macrocode}
658+
\foreach \l in {1,...,\maxTestIterations}{%
659+
\tikzscale@measureSize{\measuredIntermediate}{#1}{#2}%
660+
%
661+
\tikzscale@ifSizeDifference{\measuredIntermediate-\tikzsize}{%
662+
% \end{macrocode}
663+
% First divide before multiply to avoid overflowing (at 16384).
664+
% \begin{macrocode}
665+
\pgfmathparsemacro{\errorRatio}{\measuredIntermediate/\tikzsize}%
666+
\pgfmathsetglobalmacro{\tikzscale@scale}{\tikzscale@scale/\errorRatio}%
667+
}{%
668+
\breakforeach%
669+
}%
670+
}%
671+
% \end{macrocode}
662672
% Finally, include the picture. Do it via a new measurement to be able to warn if it does not fit good enough.
663673
% \begin{macrocode}
664674
\tikzscale@measureSize{\measuredFinal}{#1}{#2}%

0 commit comments

Comments
 (0)