summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/graphicxpsd/graphicxpsd.sty
blob: b4d4b9dcab68a6769034a64e7e5c1651a9a15ccb (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
% #!rm -f tigerpsdfmt4* && ptex2pdf -l -u -ot '-shell-escape' -od '-v' test-gin-rule-psd
% #!rm -f tigerpsdfmt4* && xelatex -shell-escape test-gin-rule-psd
% #!rm -f tigerpsdfmt4* && pdflatex -shell-escape test-gin-rule-psd
%#!rm -f tigerpsdfmt4* && lualatex -shell-escape test-gin-rule-psd
%%
%% This is file 'graphicxpsd.sty'.
%%
%% Copyright (c) 2017, 2018 Munehiro Yamamoto
%% 
%%   * e-mail:   munepixyz@gmail.com, munepi@greencherry.jp
%%   * GitHub:   https://github.com/munepi
%%   * Twitter:  @munepixyz
%% 
%% This package is licensed under the terms of the MIT License.
%%
\ProvidesPackage{graphicxpsd}
  [2018/01/26 v1.0  Adobe Photoshop Data format (PSD) support for graphicx package
                    with sips (Darwin/macOS)/convert (ImageMagick) command]

%% declare package errors
\def\gfxpsd@error{\PackageError{graphicxpsd}}
\def\gfxpsd@warning{\PackageWarning{graphicxpsd}}
\def\gfxpsd@warningnoline{\PackageWarningNoLine{graphicxpsd}}
\def\gfxpsd@info{\PackageInfo{graphicxpsd}}

%% support major graphicx drivers
\newif\if@gfxpsd@dvipdfmx \@gfxpsd@dvipdfmxfalse
\newif\if@gfxpsd@pdftex \@gfxpsd@pdftexfalse
\DeclareOption{dvipdfmx}{\@gfxpsd@dvipdfmxtrue\@gfxpsd@pdftexfalse}
\DeclareOption{xetex}{\@gfxpsd@dvipdfmxtrue\@gfxpsd@pdftexfalse}
\DeclareOption{luatex}{\@gfxpsd@dvipdfmxfalse\@gfxpsd@pdftextrue}
\DeclareOption{pdftex}{\@gfxpsd@dvipdfmxfalse\@gfxpsd@pdftextrue}

%% support two psd-to-pdf command: sips (Darwin/macOS), convert (ImageMagick)
\def\@gfxpsd@psdtopdf{sips}%% as default
\DeclareOption{imagemagick}{\gdef\@gfxpsd@psdtopdf{convert}}
\DeclareOption{sips}{\gdef\@gfxpsd@psdtopdf{sips}}

\ProcessOptions\relax

%% support the extension .psd (psdtopdf)
\if@gfxpsd@dvipdfmx
  \@namedef{Gin@rule@.PSD}#1{{psdtopdf}{.xbb}{#1}}
  \@namedef{Gin@rule@.psd}#1{{psdtopdf}{.xbb}{#1}}
\else\if@gfxpsd@pdftex
  \@namedef{Gin@rule@.PSD}#1{{psdtopdf}{.pdf}{#1}}
  \@namedef{Gin@rule@.psd}#1{{psdtopdf}{.pdf}{#1}}
\else
  \grnchry@error{Please choice specific dviware driver from the following list
    and set the one as a documentclass option.^^J
    available dviware drivers: dvipdfmx, xetex, luatex, pdftex}%
\fi\fi

%% then, include .psd file as converted PDF
\let\Ginclude@psdtopdf\Ginclude@pdf

%% compatibility for TL16 or lower version
\@ifundefined{GPT@space}{%
  \def\GPT@space{ }%
}{}

%% check shell escape trigger
\IfFileExists{shellesc.sty}{%%is bundled in TL15 or higher release version
\RequirePackage{shellesc}}{%%otherwise, such TL has no luatex.
  \protected\def\ShellEscape{\immediate\write18 }%%compatibility for TL14 or lower version
}

%% read .psd file
\let\clone@Gread@pdf\Gread@pdf
\def\Gread@psdtopdf#1{%
  \typeout{converting: \Gin@base\Gin@ext\GPT@space -> \Gin@base4gfxpsd.pdf}%
  \def\gfxpsd@tmp{sips}\ifx\@gfxpsd@psdtopdf\gfxpsd@tmp
    \ShellEscape{sips -s format pdf \Gin@base\Gin@ext\GPT@space --out \Gin@base4gfxpsd.pdf}%
  \else\def\gfxpsd@tmp{convert}\ifx\@gfxpsd@psdtopdf\gfxpsd@tmp
    \ShellEscape{convert \Gin@base\Gin@ext\GPT@space\Gin@base4gfxpsd.pdf}%
  \fi\fi
  %% renamed inside: foo.psd -> foo4gfxpsd.pdf
  \let\clone@Gin@base\Gin@base
  \def\Gin@base{\clone@Gin@base4gfxpsd}%
  \def\Gin@ext{.pdf}%
% \typeout{!!! #1}%%=> tigerpsdfmt4gfxpsd.xbb
% \typeout{!!! \Gin@base\Gin@ext}%%=> tigerpsdfmt4gfxpsd.pdf
  \clone@Gread@pdf{#1}}

\endinput
%%
%% End of file `graphicxpsd.sty'.