%%
%% This is file `simplecd.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ./simplecd.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2010 by Daniel Majoros
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.2 of this license or (at your option) any later
%% version. The latest version of this license is in:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% and version 1.2 or later is part of all distributions of
%% LaTeX version 1999/12/01 or later.
%% 

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{simplecd}
    [2010/07/01 v1.0 simple cd, dvd covers]

\RequirePackage{rotating}
\RequirePackage{fix-cm}
\RequirePackage{array}
\RequirePackage{calc}

\DeclareOption{noalign}{
    \setlength{\sc@jfcalign}{0cm}
    \setlength{\sc@jbsalign}{0cm}
    \setlength{\sc@slalign}{0cm}
    \setlength{\sc@kcfalign}{0cm}
    \setlength{\sc@kcbalign}{0cm}
    \setlength{\sc@inalign}{0cm}
    \setlength{\sc@djewsalign}{0cm}
}
\DeclareOption{nofold}{
    \renewcommand{\sc@hfoldline}[1]{}
    \setlength{\sc@vfoldline}{0pt}
}

\newcommand{\sc@hfoldline}[1]{
    \cline{#1}
}

\newlength{\sc@vfoldline}
\setlength{\sc@vfoldline}{0.4pt}

\DeclareOption{spiner}{
    \renewcommand{\sc@spinerotone}{180}
    \renewcommand{\sc@spinerottwo}{90}
    \renewcommand{\sc@spinerotthree}{270}
}

\newcommand{\sc@spinerotone}{0}

\newcommand{\sc@spinerottwo}{270}

\newcommand{\sc@spinerotthree}{90}

%% CD jewelcase dimensions
\newlength{\sc@cdjccoverheight}
\setlength{\sc@cdjccoverheight}{120mm}
\newlength{\sc@cdjccoverwidth}
\setlength{\sc@cdjccoverwidth}{120mm}
\newlength{\sc@cdjcbackheight}
\setlength{\sc@cdjcbackheight}{117.5mm}
\newlength{\sc@cdjcbackwidth}
\setlength{\sc@cdjcbackwidth}{138mm}
\newlength{\sc@cdjcspinewidth}
\setlength{\sc@cdjcspinewidth}{6mm}

%% Jewelcase spine fixed text font size
\newcommand{\sc@cdjfontsize}{15}

%% Disk sleeve dimensions
\newlength{\sc@dsdim}
\setlength{\sc@dsdim}{125mm}

%% Slim DVD keepcase dimensions
\newlength{\sc@sdvdcoverwidth}
\setlength{\sc@sdvdcoverwidth}{128.5mm}
\newlength{\sc@sdvdspinewidth}
\setlength{\sc@sdvdspinewidth}{7mm}

%% DVD keepcase dimensions
\newlength{\sc@dvdkcheight}
\setlength{\sc@dvdkcheight}{183mm}
\newlength{\sc@dvdkccoverwidth}
\setlength{\sc@dvdkccoverwidth}{129.5mm}
\newlength{\sc@dvdkcspinewidth}
\setlength{\sc@dvdkcspinewidth}{14mm}
\newlength{\sc@dvdkcinletwidth}
\setlength{\sc@dvdkcinletwidth}{115mm}
\newlength{\sc@dvdkcinletheight}
\setlength{\sc@dvdkcinletheight}{175mm}

%% Blu-Ray case dimensions
\newlength{\sc@brcoverwidth}
\setlength{\sc@brcoverwidth}{128mm}
\newlength{\sc@brcoverheight}
\setlength{\sc@brcoverheight}{149mm}
\newlength{\sc@brspinewidth}
\setlength{\sc@brspinewidth}{14mm}
\newlength{\sc@brinletwidth}
\setlength{\sc@brinletwidth}{115mm}
\newlength{\sc@brinletheight}
\setlength{\sc@brinletheight}{140mm}

%% Width and correction of the invisible |\rule|'s column
\newlength{\sc@ircwidth}
\setlength{\sc@ircwidth}{0.1mm}
\newlength{\sc@ircorr}
\setlength{\sc@ircorr}{1mm}

%%Text aligning lengths
\newlength{\sc@jfcalign}
\setlength{\sc@jfcalign}{1.5cm}
\newlength{\sc@jbsalign}
\setlength{\sc@jbsalign}{3cm}
\newlength{\sc@slalign}
\setlength{\sc@slalign}{1.5cm}
\newlength{\sc@kcfalign}
\setlength{\sc@kcfalign}{4cm}
\newlength{\sc@kcbalign}
\setlength{\sc@kcbalign}{3cm}
\newlength{\sc@inalign}
\setlength{\sc@inalign}{3cm}
\newlength{\sc@djewsalign}
\setlength{\sc@djewsalign}{3cm}

\ProcessOptions\relax


\DeclareRobustCommand{\covers}[3][\ ]{
    \frontcover{#2}

    \vspace*{0.5cm}
    \backsheet[#1]{#3}
}

\DeclareRobustCommand{\frontcover}[1]{
    \sc@cell{#1}{\sc@cdjccoverwidth}{\sc@cdjccoverheight}%
    {\vspace{\sc@jfcalign}}
}

\DeclareRobustCommand{\backsheet}[2][\ ]{
    \begin{tabular}%
        {|@{\hspace{0.4mm}}m{\sc@cdjcspinewidth-0.4mm}@{}%
            !{\vrule width \sc@vfoldline}%
            @{}m{\sc@cdjcbackwidth}@{}%
            !{\vrule width \sc@vfoldline}@{}%
            m{\sc@cdjcspinewidth-0.4mm}@{\hspace{0.4mm}}%
            |m{\sc@ircwidth}}
        \cline{1-3}
        \centering%
        \begin{turn}{\sc@spinerotthree}%
            {\fontsize{\sc@cdjfontsize}{36}\selectfont #2 }%
        \end{turn} %
        & \parbox[c]{\sc@cdjcbackwidth}{\centering #1 \\
        \vspace{\sc@jbsalign}}%
        & \centering %
        \begin{turn}{\sc@spinerottwo}%
            {\fontsize{\sc@cdjfontsize}{36}\selectfont #2}%
        \end{turn} & \rule{0pt}{\sc@cdjcbackheight-\sc@ircorr} \\
        \cline{1-3}
    \end{tabular}
}

\DeclareRobustCommand{\jewelspine}[1]{
    \begin{tabular}{|@{}m{\sc@cdjcbackheight}@{}|m{\sc@ircwidth}}
        \cline{1-1} %
        \centering %
        {\fontsize{\sc@cdjfontsize}{36}\selectfont #1}& %
        \rule{0pt}{\sc@cdjcspinewidth-0.1cm} \\
        \cline{1-1}
    \end{tabular}
}

\DeclareRobustCommand{\sleeve}[1]{
    \begin{tabular}{m{10mm}|@{}m{\sc@dsdim}@{}|m{10mm}m{\sc@ircwidth}}
        \multicolumn{3}{c}{ \setlength{\unitlength}{0.5cm}
        \begin{picture}(0,0)%
            \put(-12.5,-0.25){\line(1,1){4}}
            \put(-8.5,3.75){\line(1,0){17}}
            \put(12.5,-0.25){\line(-1,1){4}}
        \end{picture} \rule{0pt}{3cm}} \\
        \cline{2-2}
        \centering \setlength{\unitlength}{0.5cm}
        \begin{picture}(0,0)%
            \put(1.45,-12.38){\line(-1,1){1.5}}%
            \put(-0.06,-10.9){\line(0,1){22.08}} %
            \put(-0.06,11.18){\line(1,1){1.5}}%
        \end{picture} & \parbox[c]{\sc@dsdim}%
            {\centering #1 \\ \vspace{\sc@slalign}} &%
        \setlength{\unitlength}{0.5cm} %
        \begin{picture}(0,0)%
            \put(-0.45,-12.38){\line(1,1){1.5}}%
            \put(1.04,-10.9){\line(0,1){22.08}} %
            \put(1.04,11.18){\line(-1,1){1.5}}%
        \end{picture} & \rule{0pt}{\sc@dsdim-\sc@ircorr}\\
        \sc@hfoldline{2-2}
        & & & \rule{0pt}{\sc@dsdim-0.1cm} \\
        \cline{2-2}
    \end{tabular}
}

\DeclareRobustCommand{\keepcase}[6][]{
    \begin{tabular}{|@{}m{#4}@{}|m{\sc@ircwidth}}
        \cline{1-1}
        \centering
        \begin{sideways} \parbox[c]{#5}{\centering #2 %
            \\ \vspace{\sc@kcfalign}} %
        \end{sideways} & \rule{0pt}{#5-\sc@ircorr} \\
        \sc@hfoldline{1-1} \centering %
        \begin{turn}{\sc@spinerotone}%
            #3 %
        \end{turn}%
        & \rule{0pt}{#6-\sc@ircorr} \\
        \sc@hfoldline{1-1}%
        \centering %
        \begin{sideways} \parbox[c]{#5}{\centering #1\ \\ %
        \vspace{\sc@kcbalign}} \end{sideways} & %
        \rule{0pt} {#5-\sc@ircorr}\\
        \cline{1-1}
    \end{tabular}
}

\DeclareRobustCommand{\slimdvd}[3][]{
    \keepcase[#1]{#2}{#3}{\sc@dvdkcheight}{\sc@sdvdcoverwidth}%
        {\sc@sdvdspinewidth}
}

\DeclareRobustCommand{\dvd}[3][]{
    \keepcase[#1]{#2}{#3}{\sc@dvdkcheight}{\sc@dvdkccoverwidth-1.5mm}%
        {\sc@dvdkcspinewidth}
}

\DeclareRobustCommand{\bluray}[3][]{
    \keepcase[#1]{#2}{#3}{\sc@brcoverheight}{\sc@brcoverwidth}%
        {\sc@brspinewidth}
}

\DeclareRobustCommand{\coverimg}[1]{
    \resizebox{\sc@cdjccoverwidth}{\sc@cdjccoverheight}{#1}
}

\DeclareRobustCommand{\backsheetimg}[1]{
    \resizebox{\sc@cdjcbackwidth+\sc@cdjcspinewidth*2}%
        {\sc@cdjcbackheight}{#1}
}

\DeclareRobustCommand{\slimdvdimg}[1]{
    \resizebox{\sc@dvdkcheight}%
        {\sc@sdvdcoverwidth*2+\sc@sdvdspinewidth}{#1}
}

\DeclareRobustCommand{\dvdimg}[1]{
    \resizebox{\sc@dvdkcheight}%
        {\sc@dvdkccoverwidth*2+\sc@dvdkcspinewidth}{#1}
}

\DeclareRobustCommand{\blurayimg}[1]{
    \resizebox{\sc@brcoverheight}%
        {\sc@brcoverwidth*2+\sc@brspinewidth}{#1}
}

\DeclareRobustCommand{\sc@cell}[4]{
    \begin{tabular}{|@{}m{#2}@{}|m{\sc@ircwidth}}
        \cline{1-1}%
        \centering %
        \parbox[c]{#2}{\centering #1 \\ #4} & \rule{0pt}{{#3}-\sc@ircorr}\\
        \cline{1-1}
    \end{tabular}
}

\DeclareRobustCommand{\inlay}[3]{
    \sc@cell{#1}{#2}{#3}{\vspace{\sc@inalign}}
}

\DeclareRobustCommand{\dvdinlay}[1]{
    \inlay{#1}{\sc@dvdkcinletwidth}{\sc@dvdkcinletheight}
}

\DeclareRobustCommand{\blurayinlay}[1]{
    \inlay{#1}{\sc@brinletwidth}{\sc@brinletheight}
}

\DeclareRobustCommand{\djewel}[2]{
    \begin{tabular}{|@{}m{\sc@cdjccoverheight}@{}|m{\sc@ircwidth}}
        \cline{1-1} %
        \centering%
        \begin{turn}{270}%
            \parbox[c]{\sc@cdjccoverwidth-\sc@ircorr}%
            {\centering #2 \\ \vspace{\sc@djewsalign}}%
        \end{turn}& \rule{0pt}{\sc@cdjccoverwidth-\sc@ircorr} \\
        \sc@hfoldline{1-1} %
        \centering%
        \begin{turn}{270}%
            \parbox[c]{\sc@cdjccoverwidth-\sc@ircorr}%
            {\centering #1 \\ \vspace{\sc@jfcalign}}%
        \end{turn} & \rule{0pt}{\sc@cdjccoverwidth-\sc@ircorr} \\
        \cline{1-1}
    \end{tabular}
}
\endinput
%%
%% End of file `simplecd.sty'.
