%#!pdflatex --synctex=1 test
\documentclass{article}\listfiles\pagestyle{empty}

\usepackage[table]{xcolor}%requires colortbl, array
\usepackage{tikz}%requires xcolor
\usetikzlibrary{calc, patterns, patterns.meta, fadings}
\usepackage{tcolorbox}%requires tikz, xcolor
\tcbuselibrary{xparse,hooks,skins}

\usepackage{spotxcolor}
\definespotcolor{DIC161s}{DIC 161s*}{0, 0.64, 1, 0}
\definespotcolor{DIC256s}{DIC 256s*}{0.9, 0, 0.4, 0}   % Green
\definespotcolor{DIC200s}{DIC 200s*}{0.5, 0.8, 0, 0}   % Purple

% PANTONE Metallic Coated (true spot color — Lab→CMYK via ML model)
\definespotcolor{PANTONE876C}{PANTONE 876 C}{0.4467, 0.7463, 0.9732, 0.0}

% \NewSpotColorSpace{DIC}
% \AddSpotColor{DIC}{DIC161s}{DIC\SpotSpace 161s*}{0 0.64 1 0}
% \SetPageColorSpace{DIC}

\newcommand\onelineskip{\par\vspace{\baselineskip}\par}

\begin{document}
\IfFileExists{test_version}{
\expandafter\title\expandafter{\input{test_version}}
\author{}
\maketitle
}\relax

\sffamily\bfseries

\section{Basic Command Tests}

DIC 161

\begingroup
\color{DIC161s}DIC 161
\endgroup

\begingroup
\color{DIC161s!50}DIC 161
\endgroup

\begingroup
\color{DIC161s!25}DIC 161
\endgroup

\textcolor{DIC161s}{DIC 161}

\textcolor{DIC161s!50}{DIC 161}

\textcolor{DIC161s!25}{DIC 161}


\SpotColor{DIC161s}{1.0}
DIC 161

\SpotColor{DIC161s}{0.5}
DIC 161

\SpotColor{DIC161s}{0.25}
DIC 161

\clearpage
\pagecolor{DIC161s}

DIC 161

\clearpage
\pagecolor{DIC161s!50}

50\% DIC 161

\clearpage
\nopagecolor

DIC 161

\clearpage
\section{TikZ Environment Tests}

% 1-a. 簡単な図形
% v0.14 NG: xetex, dvipdfmx
% v0.15 OK: xetex, dvipdfmx
% NG: colorspace 2019/03/25 v1.3
\subsection*{Simple Shapes}
\begin{tikzpicture}
  \fill[DIC161s] (0,0) circle (1.5);
  \fill[DIC161s!50] (2,-1.5) rectangle (5,1.5);
  \draw[DIC161s, ultra thick, rounded corners] (6,-1.5) rectangle (9,1.5);
  \fill[DIC161s!20] (6,-1.5) rectangle (9,1.5);
%% v1.4 NOTE:
%% CMYK値: 0 0.512 0.8 0.2
%% 色: DIC161s!80!black
%% 理由: 非比例混色（K成分0.2が追加）→ 正しいフォールバック
  \node[DIC161s!80!black] at (7.5, 0) {100\%, 50\%, 20\%};
\end{tikzpicture}

\onelineskip

% 1-b. 初等関数のグラフ (正弦波)
\subsection*{Elementary Function Graph}
\begin{tikzpicture}[domain=0:2*pi, scale=1.5, samples=100]
  % 軸
  \draw[->, thick, DIC161s!70] (-0.2,0) -- (6.8,0) node[right] {$x$};
  \draw[->, thick, DIC161s!70] (0,-1.2) -- (0,1.2) node[above] {$f(x)$};
  % グラフ本体
  \draw[color=DIC161s, ultra thick] plot (\x,{sin(\x r)}) node[right] {$\sin x$};
  % 補助線
  \draw[color=DIC161s!30, dashed] (0,1) -- (2*pi,1);
  \draw[color=DIC161s!30, dashed] (0,-1) -- (2*pi,-1);
\end{tikzpicture}

\onelineskip

% 1-c. 別行立て数式 (TikZノードを使った装飾付き)
\subsection*{Riemann Zeta Function}
\begin{tikzpicture}
  \node[
    draw=DIC161s,
    line width=1.5pt,
    fill=DIC161s!5,
    rounded corners=2ex,
    inner sep=1.5em
  ] {
%% v1.4 NOTE:
%% CMYK値: 0 0.512 0.8 0.2
%% 色: DIC161s!80!black
%% 理由: 非比例混色（K成分0.2が追加）→ 正しいフォールバック
    \color{DIC161s!80!black}
    $\displaystyle
      \zeta(s)
      = \sum_{n=1}^\infty \frac{1}{n^s}
      = \frac{1}{\Gamma(s)} \int_0^\infty \frac{x^{s-1}}{e^x - 1} \, dx
      \quad (\Re(s) > 1)
    $
  };
\end{tikzpicture}

\clearpage
% 1-d. PGF/TikZ Stroke and Fill Tests
% v0.1x: Test separation of stroke (CS/SC) and fill (cs/sc) operators
\subsection*{Stroke and Fill Separation}

\begin{tikzpicture}
  % Test 1: Fill with spot color, stroke with black
  \draw[ultra thick, fill=DIC161s!40] (0,0) circle (1.2) node[black, align=center] {Fill:\\40\% DIC161s};

  % Test 2: Stroke with spot color, fill with gray
  \draw[DIC161s, ultra thick, fill=gray!20] (3.5, -1.2) rectangle (6.5, 1.2) node[pos=0.5, black, align=center] {Stroke:\\100\% DIC161s};

  % Test 3: Stroke and Fill with DIFFERENT spot color tints
%% v1.4 NOTE:
%% CMYK値: 0 0.512 0.8 0.2
%% 色: DIC161s!80!black
%% 理由: 非比例混色（K成分0.2が追加）→ 正しいフォールバック
  \draw[DIC161s, line width=3pt, fill=DIC161s!15, rounded corners] (7.5, -1.2) rectangle (10.5, 1.2) node[pos=0.5, DIC161s!80!black, align=center] {Stroke: 100\%\\Fill: 15\%};
\end{tikzpicture}

\onelineskip

% 1-e. Low-level PGF commands test (Checking pgfsys integration)
\subsection*{Low-level PGF Color Commands}
% Directly calling PGF commands to ensure the driver macros (\pgfsys@color@...) are hooked correctly.
\begin{pgfpicture}
  % Set fill color to 60% tint, stroke color to 100%
  \pgfsetfillcolor{DIC161s!60}
  \pgfsetstrokecolor{DIC161s}
  \pgfsetlinewidth{4pt}

  \pgfpathcircle{\pgfpoint{2cm}{0cm}}{1.5cm}
  \pgfusepath{fill,stroke}

  \pgftext[x=2cm, y=0cm]{\sffamily\color{white} PGF Native}
\end{pgfpicture}

\onelineskip

% 1-f. Pattern Fill Tests (Hatching)
\subsection*{Pattern Fill Tests (Hatching)}

% v0.15:
% * (u)platex+dvipdfmx, xelatex: OK
% * pdflatex, lualatex: NG
% v0.16: all engines OK
% v0.17: Test 1: all engines OK, Test 2,3: NG
%% v1.4 NOTE:
%% CMYK値: 0 0.512 0.8 0.2
%% 色: DIC161s!80!black
%% 理由: 非比例混色（K成分0.2が追加）→ 正しいフォールバック
\begin{tikzpicture}
  % Test 1: 古い patterns ライブラリを使った標準的な斜線ハッチ
  \draw[DIC161s, ultra thick, pattern=north east lines, pattern color=DIC161s]
    (0,0) rectangle (3, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC161s!80!black] {Basic Hatch};

  % Test 2: patterns.meta ライブラリを使ったカスタマイズ斜線 (60% tint)
  \draw[DIC161s, ultra thick, pattern={Lines[angle=45, distance=6pt, line width=1.5pt]}, pattern color=DIC161s!60]
    (4,0) rectangle (7, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC161s!80!black] {Meta Lines (60\%)};

  % Test 3: patterns.meta ライブラリを使ったドットパターン (40% tint)
  \draw[DIC161s, ultra thick, pattern={Dots[distance=3mm, radius=1mm]}, pattern color=DIC161s!40]
    (8,0) rectangle (11, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC161s!80!black] {Meta Dots (40\%)};
\end{tikzpicture}

\clearpage

% 1-g. Fading Tests (Transparency Masks)
\subsection*{Fading Tests (Transparency Masks)}

\begin{tikzpicture}
  % 背景として特色の網点を敷く
  \fill[DIC161s!20] (-1,-1) rectangle (10, 2);

  % Test 1: 左から右へ透明になるフェーディング
  \fill[DIC161s, path fading=east] (0, 0) rectangle (4, 1.5)
    node[pos=0.5, text=white, font=\sffamily\small] {Fading East};

  % Test 2: 中心から外側へ透明になる円形フェーディング
  \fill[DIC161s, path fading=circle with fuzzy edge 20 percent] (7, 0.5) circle (1.2)
    node[text=white, font=\sffamily\small] {Fuzzy Circle};
\end{tikzpicture}

\onelineskip

% 1-h. Shading Tests (Gradients)
\subsection*{Shading Tests (Gradients)}
% Note: Standard PGF shadings might fallback to RGB natively depending on the driver.
% This tests if xcolor's CMYK definition survives the gradient creation.
\begin{tikzpicture}
  % Test 1: 特色100%から特色10%への線形グラデーション (left to right)
  \shade[left color=DIC161s, right color=DIC161s!10] (0,0) rectangle (4, 1.5)
    node[pos=0.5, font=\sffamily\small, text=white] {Linear Shading};

  % Test 2: 中心が白、外側が特色の放射状グラデーション
  \shade[inner color=white, outer color=DIC161s] (7, 0.5) circle (1.2)
    node[font=\sffamily\small, text=white] {Radial Shading};
\end{tikzpicture}

\clearpage

\onelineskip

% 1-i. Opacity and Blend Modes
\subsection*{Opacity and Blend Modes}
\begin{tikzpicture}
  % 背景
  \fill[gray!20] (0,0) rectangle (8,3);

  % Test 1: Tint (網点) + Opacity (アルファチャンネル透過) の複合
  % !80 で色を薄くしつつ、さらに opacity=0.5 で透かすという、PDFオペレータ的には全く異なる2つの処理の同時適用
  \fill[DIC161s!80, opacity=0.5] (1.5, 1.5) circle (1.2)
    node[black, opacity=1, font=\sffamily\small, align=center] {Tint: 80\%\\Opacity: 0.5};

  % Test 2: ブレンドモード (乗算 / Multiply)
  % 特色とプロセスカラー(Cyan, Yellow)を乗算モードで重ねる
  \begin{scope}[blend mode=multiply]
    \fill[DIC161s] (5.5, 1.8) circle (1);
    \fill[cyan] (5.0, 1.0) circle (1);
    \fill[yellow] (6.0, 1.0) circle (1);
  \end{scope}
  \node[font=\sffamily\small] at (5.5, 3.2) {Multiply Blend: DIC161s + Cyan + Yellow};
\end{tikzpicture}

\onelineskip

% 1-j. Mixed Color Space Shading
\subsection*{Mixed Color Space Shading}
% 異なるカラーモデル(RGBの赤 と CMYK/特色のDIC161)を両端に指定したグラデーション。
% PGFが内部でこれをどう補間し、どのカラースペース(おそらくRGBかCMYKに強制フォールバック)で出力するか。エラーでクラッシュしないかが重要。
\begin{tikzpicture}
  \shade[left color=red, right color=DIC161s] (0,0) rectangle (8, 1.5)
    node[pos=0.5, font=\sffamily\small, text=white] {Red (RGB) to DIC161s (CMYK)};
\end{tikzpicture}

\clearpage

% ==========================================
\section{Zebra-striped Table Test}

% 行の偶奇で背景色を変える (colortbl の機能)
\rowcolors{2}{DIC161s!10}{white}
\begin{center}
  \renewcommand{\arraystretch}{1.5}
  \begin{tabular}{p{3cm} p{5cm} c}
    % ヘッダー行
    \rowcolor{DIC161s}
    \textcolor{white}{\textbf{Parameter}} & \textcolor{white}{\textbf{Description}} & \textcolor{white}{\textbf{Value}} \\
    Alpha   & First coefficient used in calc & 0.98 \\
    Beta    & Secondary alignment offset     & 1.24 \\
    Gamma   & Spot color tint percentage     & 50\% \\
    Delta   & Base margin parameter          & 4.00 \\
    Epsilon & Threshold for error correction & 0.01 \\
  \end{tabular}
\end{center}

\onelineskip

% ==========================================
\section{tcolorbox Test}

\begin{tcolorbox}[
  enhanced, % skinsライブラリの機能
  colframe=DIC161s,       % 枠線の色
  colback=DIC161s!5,      % 背景色 (5% tint)
  coltitle=white,        % タイトル文字色
  colbacktitle=DIC161s!80,% タイトル背景色 (80% tint)
  fonttitle=\sffamily\bfseries\Large,
  title={spotxcolor $\times$ tcolorbox},
  drop fuzzy shadow=DIC161s!30 % 影の色にも特色を指定
]
This is an example of \textbf{tcolorbox} seamlessly integrating with the \textsf{spotxcolor} package.

\onelineskip

\begin{itemize}
  \item The outer frame is drawn in \textcolor{DIC161s}{100\% DIC161}.
  \item The title background uses \textcolor{DIC161s!80}{80\% DIC161}.
  \item The content background uses a subtle \textcolor{DIC161s!10}{10\% DIC161} tint.
  \item Even the drop shadow is rendered using a \textcolor{DIC161s!30}{30\% DIC161} tint!
\end{itemize}
\end{tcolorbox}

\clearpage

% ==========================================
\section{PANTONE Spot Color Test}

% v1.5: Test PANTONE Metallic Coated (true spot color)
% PDF Name "PANTONE 876 C" must appear as /PANTONE#20876#20C in QDF
\subsection*{PANTONE 876 C (Metallic Gold)}

\textcolor{PANTONE876C}{PANTONE 876 C at 100\% tint.}

\textcolor{PANTONE876C!50}{PANTONE 876 C at 50\% tint.}

\textcolor{PANTONE876C!25}{PANTONE 876 C at 25\% tint.}

{\color{PANTONE876C}\rule{\linewidth}{4pt}}
\vskip2pt
{\color{PANTONE876C!50}\rule{\linewidth}{4pt}}
\vskip2pt
{\color{PANTONE876C!25}\rule{\linewidth}{4pt}}

\onelineskip

% Tint series
\noindent
{\color{PANTONE876C!10}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!20}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!30}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!40}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!50}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!60}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!70}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!80}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C!90}\rule{0.1\linewidth}{10pt}}%
{\color{PANTONE876C}\rule{0.1\linewidth}{10pt}}

\onelineskip

\subsection*{TikZ with PANTONE Metallic}

\begin{tikzpicture}
  % DIC + PANTONE coexistence
  \fill[PANTONE876C] (0,0) rectangle (3,2)
    node[pos=0.5, white, font=\sffamily\small] {PANTONE 876 C};
  \fill[DIC161s] (3.5,0) rectangle (6.5,2)
    node[pos=0.5, white, font=\sffamily\small] {DIC 161s*};
  \fill[PANTONE876C!40] (7,0) rectangle (10,2)
    node[pos=0.5, font=\sffamily\small] {876 C (40\%)};
\end{tikzpicture}

\clearpage

% ==========================================
\section{Backward Compatibility Tests}

\subsection*{\textsf{colorspace} package macros}

This page tests the dummy backward compatibility macros for the \textsf{colorspace} package.
They should produce no visible output and cause no compilation errors.
\onelineskip

Testing \verb|\pagecolorspace|...
\pagecolorspace{DIC161s} % Should silently do nothing
\onelineskip

Testing \verb|\resetpagecolorspace|...
\resetpagecolorspace % Should silently do nothing
\onelineskip

If the document compiles successfully and this page renders without errors, the backward compatibility wrappers are working perfectly.

\clearpage

% ==========================================
\section{Multiple Spot Color Tests}
% ==========================================
% v1.5: Three distinct spot colors used simultaneously.
% Verify that each color registers its own Separation CS, Pattern CS,
% and resource dictionary entries without collision.

\subsection*{Three Spot Colors: Basic}

\textcolor{DIC161s}{DIC 161s (Vermilion) --- 100\%}\par
\textcolor{DIC256s}{DIC 256s (Green) --- 100\%}\par
\textcolor{DIC200s}{DIC 200s (Purple) --- 100\%}

\onelineskip

\textcolor{DIC161s!50}{DIC 161s --- 50\%}\par
\textcolor{DIC256s!50}{DIC 256s --- 50\%}\par
\textcolor{DIC200s!50}{DIC 200s --- 50\%}

\onelineskip

\subsection*{Three Spot Colors: TikZ Fill and Stroke}

\begin{tikzpicture}
  % Vermilion circle
  \fill[DIC161s] (0,0) circle (1.2);
  \fill[DIC161s!30] (0,-1.8) rectangle (2.4,1.8);
  \fill[DIC161s] (0,0) circle (1.2);

  % Green rectangle
  \draw[DIC256s, ultra thick, fill=DIC256s!20, rounded corners]
    (3,-1.2) rectangle (6,1.2);
  \node[DIC256s] at (4.5,0) {\textsf{DIC 256s}};

  % Purple diamond
  \fill[DIC200s!60] (8.5,0) -- (9.5,1.2) -- (10.5,0) -- (9.5,-1.2) -- cycle;
  \draw[DIC200s, ultra thick] (8.5,0) -- (9.5,1.2) -- (10.5,0) -- (9.5,-1.2) -- cycle;
  \node[white, font=\sffamily\small] at (9.5,0) {DIC 200s};
\end{tikzpicture}

\onelineskip

\subsection*{Three Spot Colors: Multiply Blend Mode}

\begin{tikzpicture}
  \fill[gray!10] (-1.5,-2) rectangle (4.5,3);
  \begin{scope}[blend mode=multiply]
    \fill[DIC161s] (90:1) circle (1.3);
    \fill[DIC256s] (210:1) circle (1.3);
    \fill[DIC200s] (330:1) circle (1.3);
  \end{scope}
  \node[font=\sffamily\small] at (1.5, 2.8) {Multiply: DIC161s + DIC256s + DIC200s};
\end{tikzpicture}

\onelineskip

\subsection*{Three Spot Colors: Pattern Fills}

\begin{tikzpicture}
  % DIC161s pattern
  \draw[DIC161s, ultra thick,
    pattern={Lines[angle=45, distance=6pt, line width=1.5pt]},
    pattern color=DIC161s!60]
    (0,0) rectangle (3, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC161s] {161s Lines};

  % DIC256s pattern
  \draw[DIC256s, ultra thick,
    pattern={Lines[angle=-45, distance=6pt, line width=1.5pt]},
    pattern color=DIC256s!60]
    (4,0) rectangle (7, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC256s] {256s Lines};

  % DIC200s dots
  \draw[DIC200s, ultra thick,
    pattern={Dots[distance=3mm, radius=1mm]},
    pattern color=DIC200s!50]
    (8,0) rectangle (11, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC200s] {200s Dots};
\end{tikzpicture}

\onelineskip

\subsection*{Three Spot Colors: Zebra-striped Table}

\rowcolors{2}{DIC256s!8}{white}
\begin{center}
  \renewcommand{\arraystretch}{1.5}
  \begin{tabular}{p{3cm} p{5cm} c}
    \rowcolor{DIC200s}
    \textcolor{white}{\textbf{Color}} & \textcolor{white}{\textbf{PDF Name}} & \textcolor{white}{\textbf{Base CMYK}} \\
    \textcolor{DIC161s}{DIC 161s}  & DIC 161s* (Vermilion) & (0, 0.64, 1, 0) \\
    \textcolor{DIC256s}{DIC 256s}  & DIC 256s* (Green)     & (0.9, 0, 0.4, 0) \\
    \textcolor{DIC200s}{DIC 200s}  & DIC 200s* (Purple)    & (0.5, 0.8, 0, 0) \\
  \end{tabular}
\end{center}

\onelineskip

\subsection*{Three Spot Colors: tcolorbox}

\begin{tcolorbox}[
  enhanced,
  colframe=DIC256s,
  colback=DIC256s!5,
  coltitle=white,
  colbacktitle=DIC256s!80,
  fonttitle=\sffamily\bfseries\Large,
  title={Three-Color Harmony},
  drop fuzzy shadow=DIC256s!30
]
This box frame uses \textcolor{DIC256s}{\textbf{DIC 256s}} (Green).

Inside, we can mix all three spot colors freely:
\textcolor{DIC161s}{\textbf{Vermilion (DIC 161s)}},
\textcolor{DIC256s}{\textbf{Green (DIC 256s)}}, and
\textcolor{DIC200s}{\textbf{Purple (DIC 200s)}}.

\onelineskip

Tints also work for each:
\textcolor{DIC161s!50}{161s @ 50\%},
\textcolor{DIC256s!50}{256s @ 50\%},
\textcolor{DIC200s!50}{200s @ 50\%}.
\end{tcolorbox}

\clearpage

% ==========================================
\section{pdfmanagement Compatibility Test}
% ==========================================
% v1.5: This section tests basic compilation when pdfmanagement is NOT active.
% The actual pdfmanagement interaction test requires \DocumentMetadata{} before
% \documentclass, which makes it a separate test file (test-pdfmanagement.tex).
%
% Here we verify that spotxcolor's resource management works correctly in the
% traditional (non-pdfmanagement) mode, i.e., via \pgfutil@addpdfresource@colorspaces
% and direct \pdfpageresources manipulation.

\subsection*{Resource Registration Verification}

This page verifies that all three spot color resources are registered correctly
in the traditional (non-pdfmanagement) mode:

\begin{itemize}
  \item \textcolor{DIC161s}{\textbf{DIC161s}}: Separation CS + Pattern CS registered
  \item \textcolor{DIC256s}{\textbf{DIC256s}}: Separation CS + Pattern CS registered
  \item \textcolor{DIC200s}{\textbf{DIC200s}}: Separation CS + Pattern CS registered
\end{itemize}

\onelineskip

To confirm correct PDF structure, inspect the compiled PDF with a tool such as
\texttt{qpdf --json} or Adobe Preflight. Each page should contain
\texttt{/ColorSpace} entries for all three spot colors.

\onelineskip

\subsection*{Note on pdfmanagement Testing}

A dedicated test file \texttt{test-pdfmanagement.tex} should be used to test the
\verb|\DocumentMetadata{}| pathway (Issue \#2). That file places
\verb|\DocumentMetadata{}| \emph{before} \verb|\documentclass| and exercises the
same spot color commands to verify that \textsf{spotxcolor} correctly switches to
the \verb|\pdfmanagement_add:nnn| API when pdfmanagement is active.

\end{document}
