summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/graphicxpsd/graphicxpsd.sty
blob: 3f170d9c2fffa299f88b696c92c55d22a11e83d6 (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
% #!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.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{graphicxpsd}
  [2018/01/30 v1.1  Adobe Photoshop Data format (PSD) support for graphicx package
                    with sips (Darwin/macOS)/magick (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 commands: 
%% sips (Darwin/macOS), magick/convert (ImageMagick)
\newif\if@gfxpsd@imagemagick \@gfxpsd@imagemagickfalse
\def\@gfxpsd@psdtopdf{sips}%% as default
\DeclareOption{sips}{%
  \@gfxpsd@imagemagickfalse\gdef\@gfxpsd@psdtopdf{sips}}
\DeclareOption{imagemagick}{%
  \@gfxpsd@imagemagicktrue\gdef\@gfxpsd@psdtopdf{magick}}
\DeclareOption{magick}{%
  \@gfxpsd@imagemagicktrue\gdef\@gfxpsd@psdtopdf{magick}}
\DeclareOption{convert}{%
  \@gfxpsd@imagemagicktrue\gdef\@gfxpsd@psdtopdf{convert}}

\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
  \gfxpsd@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
\@ifundefined{Ginclude@pdf}{\gfxpsd@error{%
  Please load 'graphicxpsd' package after loading 'graphicx' package.}}\relax
\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}%
  \if@gfxpsd@imagemagick
    \ShellEscape{\@gfxpsd@psdtopdf\GPT@space\Gin@base\Gin@ext\GPT@space\Gin@base4gfxpsd.pdf}%
  \else
    \ShellEscape{sips -s format pdf \Gin@base\Gin@ext\GPT@space --out \Gin@base4gfxpsd.pdf}%
  \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'.