Created
August 8, 2016 12:39
-
-
Save zr-tex8r/e48ceb66eab8d605b58f2c3130c89a87 to your computer and use it in GitHub Desktop.
LaTeX: graphics パッケージをドライバ非依存にする(☃使用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% tcgraphicss.sty | |
%% package declaration | |
\NeedsTeXFormat{LaTeX2e} | |
\ProvidesPackage{tcgraphicss}[2016/08/08 v0.2] | |
%% preparation | |
\def\tcqgs@pkgname{tcgraphicss} | |
\def\tcqgs@error{\PackageError\tcqgs@pkgname} | |
\providecommand\bxDebug[1]{} | |
%% \tcqgs@default@size | |
\def\tcqgs@default@size{50} | |
%--------------------------------------- helpers | |
\@ifpackageloaded{graphics}{}{%else | |
\ifx\Gin@driver\relax\let\Gin@driver\@undefined\fi | |
\ifx\Gin@driver\@undefined\else | |
\def\@tempa#1.#2\relax{\PassOptionsToPackage{#1}{graphics}}% | |
\expandafter\@tempa\Gin@driver\relax | |
\fi} | |
\RequirePackage{graphicx} | |
%--------------------------------------- the snowman symbol | |
%% \tcqgs@put@snowman | |
\DeclareFontFamily{U}{tcqgs}{} | |
\DeclareFontShape{U}{tcqgs}{m}{n}{<->ipxm-r-u26}{} | |
\def\tcqgs@put@snowman#1{% | |
\begingroup \dimen@=#1\relax | |
\fontsize{\dimen@}{\z@}\usefont{U}{tcqgs}{m}{n}% | |
\raise0.12#1\hbox{\char3}% | |
\endgroup} | |
%--------------------------------------- includegraphics stuffs | |
%% variables | |
\let\tcqgs@wd\@ovxx \let\tcqgs@ht\@ovyy \let\tcqgs@dp\@ovro | |
\let\tcqgs@da\@ovdx \let\tcqgs@db\@ovdy \let\tcqgs@dd\@ovri | |
\let\tcqgs@dx\@xdim \let\tcqgs@dy\@ydim | |
\let\tcqgs@th\relax | |
%% \tcqgs@snowman@box{<width>}{<height>}{<depth>}{<angle>} | |
\def\tcqgs@snowman@box#1#2#3#4{% | |
\begingroup | |
\tcqgs@wd=#1\relax \tcqgs@ht=#2\relax \tcqgs@dp=#3\relax | |
\edef\tcqgs@th{#4}% | |
\bxDebug{\the\tcqgs@wd(\the\tcqgs@ht+\the\tcqgs@dp)@\tcqgs@th}% | |
% | |
\ifdim\tcqgs@ht<\z@ \tcqgs@ht\z@ \fi \ifdim\tcqgs@dp<\z@ \tcqgs@dp\z@ \fi | |
\advance\tcqgs@ht\tcqgs@dp \ifdim\tcqgs@wd<\z@ \tcqgs@wd\z@ \fi | |
\ifdim\tcqgs@ht>\tcqgs@wd % tall | |
\@tempswatrue \tcqgs@da\tcqgs@wd \tcqgs@wd\tcqgs@ht \tcqgs@ht\tcqgs@da | |
\else \@tempswafalse | |
\fi | |
\ifdim\tcqgs@ht<\p@ \@tempcnta\m@ne | |
\else | |
\Gscale@div\@tempa\tcqgs@wd\tcqgs@ht \tcqgs@da\@tempa\p@ | |
\advance\tcqgs@da-.98\p@ \divide\tcqgs@da\p@ \@tempcnta\tcqgs@da | |
\tcqgs@dd\tcqgs@wd \advance\tcqgs@dd-\tcqgs@ht | |
\ifnum\@tempcnta>\z@ \tcqgs@db\z@ \divide\tcqgs@dd\@tempcnta | |
\else \tcqgs@db.5\tcqgs@dd \tcqgs@dd\z@ | |
\fi | |
\fi | |
% | |
\ifdim\tcqgs@th\p@=\z@\else | |
\CalculateSin\tcqgs@th \edef\tcqgs@sin{\UseSin\tcqgs@th}% | |
\CalculateCos\tcqgs@th \edef\tcqgs@cos{\UseCos\tcqgs@th}% | |
\fi | |
\@whilenum{\@tempcnta>\m@ne}\do{% | |
\if@tempswa \tcqgs@dx\z@ \tcqgs@dy\tcqgs@db \advance\tcqgs@dy-\tcqgs@dp | |
\else \tcqgs@dx\tcqgs@db \tcqgs@dy-\tcqgs@dp | |
\fi | |
\ifdim\tcqgs@th\p@=\z@\else | |
\advance\tcqgs@dx.5\tcqgs@ht \advance\tcqgs@dy.5\tcqgs@ht | |
\tcqgs@da\tcqgs@cos\tcqgs@dx \advance\tcqgs@da-\tcqgs@sin\tcqgs@dy | |
\edef\@tempa{\tcqgs@dx\the\tcqgs@da}% | |
\tcqgs@da\tcqgs@sin\tcqgs@dx \advance\tcqgs@da\tcqgs@cos\tcqgs@dy | |
\@tempa \tcqgs@dy\tcqgs@da | |
\advance\tcqgs@dx-.5\tcqgs@ht \advance\tcqgs@dy-.5\tcqgs@ht | |
\fi | |
\bxDebug{(\the\tcqgs@dx,\the\tcqgs@dy)}% | |
\raise\tcqgs@dy\hb@xt@\z@{\kern\tcqgs@dx\tcqgs@put@snowman\tcqgs@ht\hss}% | |
\advance\@tempcnta\m@ne \advance\tcqgs@db\tcqgs@dd | |
}% | |
\endgroup} | |
%--------------------------------------- fix \scalebox & \rotatebox | |
%% \tcqgs@Gscale@box | |
\def\tcqgs@Gscale@box{% | |
\tcqgs@snowman@box{\Gscale@x\wd\z@}{\Gscale@y\ht\z@}% | |
{\Gscale@y\dp\z@}{0}} | |
%% \tcqgs@Grotate@box | |
\def\tcqgs@Grotate@box{% | |
\tcqgs@snowman@box{\wd\z@}{\ht\z@}{\dp\z@}{\Grot@angle}} | |
%% prepend \tcqgs@patch@scalrot | |
\begingroup | |
\toks@\expandafter{\Gscale@box{#1}[#2]{#3}}% | |
\edef\@tempa{% | |
\long\gdef\noexpand\Gscale@box##1[##2]##3{% | |
\noexpand\tcqgs@patch@scalrot \the\toks@}% | |
}\@tempa | |
\toks@\expandafter{\Grot@box}% | |
\edef\@tempa{% | |
\long\gdef\noexpand\Grot@box{% | |
\noexpand\tcqgs@patch@scalrot \the\toks@}% | |
}\@tempa | |
\endgroup | |
%% \tcqgs@fix@scalebox@rotatebox | |
\@onlypreamble\tcqgs@fix@scalebox@rotatebox | |
\def\tcqgs@fix@scalebox@rotatebox{% | |
\def\tcqgs@patch@scalrot{% | |
\global\let\tcqgs@patch@scalrot\relax | |
\gdef\Gscale@start{\tcqgs@Gscale@box | |
\begingroup\setbox\z@\hbox\bgroup}% | |
\gdef\Gscale@end{\egroup\endgroup}% | |
\gdef\Grot@start{\tcqgs@Grotate@box | |
\begingroup\setbox\z@\hbox\bgroup}% | |
\gdef\Grot@end{\egroup\endgroup}}} | |
%% fix internal of '\scalebox' & '\rotatebox' | |
\tcqgs@fix@scalebox@rotatebox | |
\AtBeginDocument{\tcqgs@fix@scalebox@rotatebox} | |
%--------------------------------------- fix \includegraphics | |
%% \tcqgs@Ginclude@box | |
\def\tcqgs@Ginclude@box{% | |
\tcqgs@snowman@box{\Gin@req@width}{\Gin@req@height}{\z@}{0}} | |
%% \tcqgs@Ginclude@graphics | |
\def\tcqgs@Ginclude@graphics{% | |
\ifGin@bbox\else | |
\let\Gin@urx\tcqgs@default@size | |
\let\Gin@ury\tcqgs@default@size | |
\fi | |
\Gin@viewport@code | |
\Gin@nat@height\Gin@ury bp% | |
\advance\Gin@nat@height-\Gin@lly bp% | |
\Gin@nat@width\Gin@urx bp% | |
\advance\Gin@nat@width-\Gin@llx bp% | |
\Gin@req@sizes | |
\leavevmode | |
\setbox\z@\hbox{\tcqgs@Ginclude@box}% | |
\dp\z@\z@ \ht\z@\Gin@req@height \wd\z@\Gin@req@width | |
\box\z@} | |
%% \tcqgs@fix@Ginclude@graphics | |
\@onlypreamble\tcqgs@fix@Ginclude@graphics | |
\def\tcqgs@fix@Ginclude@graphics{% | |
\def\Ginclude@graphics##1{\tcqgs@Ginclude@graphics}% | |
\def\Gin@setfile##1##2##3{\tcqgs@Ginclude@graphics}% | |
\let\GPT@fix\relax} | |
%% fix internal of '\includegraphics' | |
\tcqgs@fix@Ginclude@graphics | |
\AtBeginDocument{\tcqgs@fix@Ginclude@graphics} | |
%--------------------------------------- all done | |
\endinput | |
%% EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment