|
220 | 220 | \RequirePackage{ifplatform} |
221 | 221 | \RequirePackage{pdftexcmds} |
222 | 222 | \RequirePackage{ltxcmds} |
| 223 | +\RequirePackage{xfp} |
| 224 | +\RequirePackage{etoolbox} |
223 | 225 | \newif\ifgraphicscache@render |
224 | 226 | \newif\ifgraphicscache@disable |
225 | 227 | \newif\ifgraphicscache@compress |
|
229 | 231 | \newif\ifgraphicscache@dorender |
230 | 232 | \newif\ifgraphicscache@trim |
231 | 233 | \newif\ifgraphicscache@clip |
| 234 | +\newif\ifgraphicscache@fullclip |
232 | 235 | \def\graphicscache@graphicsargs{} |
233 | 236 | \newlength\graphicscache@tmplen |
234 | 237 | \newcommand{\graphicscache@addarg}[1]{% |
|
239 | 242 | \fi |
240 | 243 | } |
241 | 244 | \def\graphicscache@parsetrim#1 #2 #3 #4 #5\\{% |
242 | | - \Gin@defaultbp\graphicscache@trim@left{#1}% |
243 | | - \Gin@defaultbp\graphicscache@trim@bottom{#2}% |
244 | | - \Gin@defaultbp\graphicscache@trim@right{#3}% |
245 | | - \Gin@defaultbp\graphicscache@trim@top{#4}% |
| 245 | + \Gin@defaultbp\graphicscache@trim@l{#1}% |
| 246 | + \Gin@defaultbp\graphicscache@trim@b{#2}% |
| 247 | + \Gin@defaultbp\graphicscache@trim@r{#3}% |
| 248 | + \Gin@defaultbp\graphicscache@trim@t{#4}% |
246 | 249 | \graphicscache@trimtrue |
247 | 250 | } |
248 | 251 | \pgfkeys{ |
|
277 | 280 | hashshortnames/.is if=graphicscache@hashshortnames, |
278 | 281 | hashshortnames=false, |
279 | 282 | % \end{macrocode} |
| 283 | +% \begin{macrocode} |
| 284 | + fullclip/.is if=graphicscache@fullclip, |
| 285 | +% \end{macrocode} |
280 | 286 | % We now define the list of supported graphicx arguments: |
281 | 287 | % \begin{macrocode} |
282 | 288 | width/.code={% |
|
345 | 351 | \directlua{os.execute("\luaescapestring{#1}")}} |
346 | 352 | \fi |
347 | 353 | % \end{macrocode} |
| 354 | +% \begin{macrocode} |
| 355 | +\newcommand{\graphicscache@isbitmap}[1]{% |
| 356 | + \fullexpandarg |
| 357 | + \IfSubStr*{,png,PNG,jpg,JPG,jpeg,JPEG,}{,#1,}% |
| 358 | +} |
| 359 | +\def\graphicscache@trunc#1.#2\@empty{#1}% |
| 360 | +\newcommand{\graphicscache@pix}[2]{% |
| 361 | + % Compute trim amount in pixels |
| 362 | + \edef\graphicscache@trimtmp{\fpeval{#2 * \graphicscache@fdpi}}% |
| 363 | + % Now truncate & compute remainder |
| 364 | + \edef#1{\expandafter\graphicscache@trunc\graphicscache@trimtmp.\@empty}% |
| 365 | + \edef#2{\fpeval{(\graphicscache@trimtmp - #1) / \graphicscache@fdpi}}% |
| 366 | +} |
| 367 | +% \end{macrocode} |
348 | 368 | % |
349 | 369 | % \begin{macro}{\graphicscache@callgswithname} |
350 | 370 | % This macro calls ghostscript using the name specified in the first argument. |
|
431 | 451 | % Here, we actually perform the rendering. Sadly, this is quite complex due |
432 | 452 | % to cross-platform support. |
433 | 453 | % \begin{macrocode} |
434 | | -\newcommand{\graphicscache@isbitmap}[1]{% |
435 | | - \fullexpandarg |
436 | | - \IfSubStr*{,png,PNG,jpg,JPG,jpeg,JPEG,}{,#1,}% |
437 | | -} |
438 | 454 | \newcommand{\graphicscache@dorender}{% |
439 | 455 | \PackageInfo{graphicscache}{Rendering \graphicscache@outputhash: \graphicscache@fname\space with args: \graphicscache@graphicsargs\space (master file)}% |
440 | 456 | \ifwindows |
|
444 | 460 | \fi |
445 | 461 | \ifgraphicscache@trim |
446 | 462 | \ifgraphicscache@clip |
447 | | - \PackageInfo{graphicscache}{Trim: \graphicscache@trim@left, \graphicscache@trim@bottom, \graphicscache@trim@right, \graphicscache@trim@top}% |
448 | | - \filename@parse{\graphicscache@fname}% |
449 | | - \PackageInfo{graphicscache}{Ext: |\filename@ext|}% |
450 | | - \graphicscache@isbitmap{\filename@ext}{% |
451 | | - \PackageInfo{graphicscache}{is bitmap!}% |
452 | | - \graphicscache@ShellEscape{identify -units PixelsPerInch -format '\@percentchar[fx:int(resolution.x)]' "\graphicscache@fname" > \graphicscache@output.dpi}% |
453 | | - \CatchFileDef{\graphicscache@fdpi}{\graphicscache@output.dpi}{}% |
454 | | -% \input{\graphicscache@output.dpi} |
455 | | - \PackageInfo{graphicscache}{Detected DPI: \graphicscache@fdpi}% |
456 | | - \edef\graphicscache@trim@left@pix{\strip@pt\dimexpr1bp*\graphicscache@trim@left*\graphicscache@fdpi*65535/\dimexpr 1in\relax\relax}% |
457 | | - \edef\graphicscache@trim@bottom@pix{\strip@pt\dimexpr1bp*\graphicscache@trim@bottom*\graphicscache@fdpi*65535/\dimexpr 1in\relax\relax}% |
458 | | - \edef\graphicscache@trim@right@pix{\strip@pt\dimexpr1bp*\graphicscache@trim@right*\graphicscache@fdpi*65535/\dimexpr 1in\relax\relax}% |
459 | | - \edef\graphicscache@trim@top@pix{\strip@pt\dimexpr1bp*\graphicscache@trim@top*\graphicscache@fdpi*65535/\dimexpr 1in\relax\relax}% |
460 | | - \PackageInfo{graphicscache}{Detected left: \graphicscache@trim@left@pix}% |
461 | | - }{% |
462 | | - \PackageInfo{graphicscache}{no bitmap!}% |
463 | | - }% |
464 | | - % Compute pixels |
465 | | - % \setlength{\dimen@}{ |
466 | | - % \setlength{\graphicscache@trim@pixel@left}{\graphicscache@trim@left bp} |
| 463 | + \ifgraphicscache@fullclip |
| 464 | + \PackageInfo{graphicscache}{Trim: \graphicscache@trim@l, \graphicscache@trim@b, \graphicscache@trim@r, \graphicscache@trim@t}% |
| 465 | + \filename@parse{\graphicscache@fname}% |
| 466 | + \PackageInfo{graphicscache}{Ext: |\filename@ext|}% |
| 467 | + \graphicscache@isbitmap{\filename@ext}{% |
| 468 | + \PackageInfo{graphicscache}{is bitmap!}% |
| 469 | + \graphicscache@ShellEscape{identify -units PixelsPerInch -format '\@percentchar[fx:int(resolution.x)]' "\graphicscache@fname" > \graphicscache@output.dpi}% |
| 470 | + \CatchFileDef{\graphicscache@fdpi}{\graphicscache@output.dpi}{}% |
| 471 | + \PackageInfo{graphicscache}{Detected DPI: \graphicscache@fdpi (default 71)}% |
| 472 | + \ifnumequal{\graphicscache@fdpi}{0}{\edef\graphicscache@fdpi{71}}{}% |
| 473 | + \edef\graphicscache@fdpi{\fpeval{0.01389 * \graphicscache@fdpi}}% |
| 474 | + \graphicscache@pix{\graphicscache@trim@l@pix}{\graphicscache@trim@l}% |
| 475 | + \graphicscache@pix{\graphicscache@trim@b@pix}{\graphicscache@trim@b}% |
| 476 | + \graphicscache@pix{\graphicscache@trim@r@pix}{\graphicscache@trim@r}% |
| 477 | + \graphicscache@pix{\graphicscache@trim@t@pix}{\graphicscache@trim@t}% |
| 478 | + \PackageInfo{graphicscache}{Pixel trims: |
| 479 | + \graphicscache@trim@l@pix +\graphicscache@trim@l bp, |
| 480 | + \graphicscache@trim@b@pix +\graphicscache@trim@b bp, |
| 481 | + \graphicscache@trim@r@pix +\graphicscache@trim@r bp, |
| 482 | + \graphicscache@trim@t@pix +\graphicscache@trim@t bp |
| 483 | + }% |
| 484 | + \graphicscache@ShellEscape{convert "\graphicscache@fname" -gravity Northwest -chop \graphicscache@trim@l@pix x\graphicscache@trim@t@pix\space -gravity Southeast -chop \graphicscache@trim@r@pix x\graphicscache@trim@b@pix\space \graphicscache@output.crop.\filename@ext}% |
| 485 | + \edef\graphicscache@fname{\graphicscache@output.crop.\filename@ext}% |
| 486 | + \graphicscache@addarg{trim=\graphicscache@trim@l\space\graphicscache@trim@b\space\graphicscache@trim@r\space\graphicscache@trim@t}% |
| 487 | + }{% |
| 488 | + \PackageInfo{graphicscache}{no bitmap!}% |
| 489 | + }% |
| 490 | + \fi |
467 | 491 | \fi |
468 | 492 | \fi |
469 | 493 | % \end{macrocode} |
|
687 | 711 | \else |
688 | 712 | \edef\graphicscache@hashedname{\graphicscache@fname}% |
689 | 713 | \fi |
690 | | - \edef\graphicscache@outputhash{\pdf@mdfivesum{\graphicscache@options\graphicscache@graphicsargs\graphicscache@hashedname}}% |
| 714 | + \ifgraphicscache@fullclip |
| 715 | + \def\graphicscache@clipmode{fullclip}% |
| 716 | + \else |
| 717 | + \def\graphicscache@clipmode{nclip}% |
| 718 | + \fi |
| 719 | + \edef\graphicscache@outputhash{\pdf@mdfivesum{\graphicscache@options\graphicscache@graphicsargs\graphicscache@clipmode\graphicscache@hashedname}}% |
691 | 720 | \edef\graphicscache@output{\graphicscache@cachedir/\graphicscache@outputhash.pdf}% |
692 | 721 | \ifgraphicscache@listing |
693 | 722 | \PackageInfo{graphicscache}{graphicscache: includegraphics\{#2\} => \graphicscache@output}% |
|
0 commit comments