%%
%% Copyright (C) 2008 by:
%% Josef Kleber
%% <josef.kleber@gmx.de>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3 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.3 or later is part of all distributions of LaTeX version
%% 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "author-maintained".
%% 
%% This Current Maintainer of this work is Josef Kleber.
%%
%% This work consists of all files listed in manifest.txt.
%%
%
\ProvidesPackage{pdfcomment}[2008/12/07 pdfcomment.sty v1.0 - Josef Kleber (C) 2008]%
%
\RequirePackage{xkeyval}%
%
% default values for global package options
\gdef\pc@goptd@subject{}%
\gdef\pc@goptd@color{0 0 1}%
\gdef\pc@goptd@author{}%
\gdef\pc@goptd@icon{Comment}%
\gdef\pc@goptd@open{false}%
\gdef\pc@goptd@hspace{15pt}%
%
% values for global package options
\gdef\pc@gopt@subject{}%
\gdef\pc@gopt@color{}%
\gdef\pc@gopt@author{}%
\gdef\pc@gopt@icon{}%
\gdef\pc@gopt@open{}%
\gdef\pc@gopt@hspace{}%
%
% values for local command options
\gdef\pc@lopt@subject{}%
\gdef\pc@lopt@color{}%
\gdef\pc@lopt@author{}%
\gdef\pc@lopt@icon{}%
\gdef\pc@lopt@open{}%
\gdef\pc@lopt@hspace{}%
%
% define global style option subject for setting the subject of pdf annotations
\define@key{pdfcomment.sty}{subject}[\pc@goptd@subject]%
{%
  \gdef\pc@gopt@subject{#1}%
}%
%
% define global style option color for setting the color of pdf annotations
\define@key{pdfcomment.sty}{color}[\pc@goptd@color]%
{%
  \gdef\pc@gopt@color{#1}%
}%
%
% define global style option author for setting the author of pdf annotations
\define@key{pdfcomment.sty}{author}[\pc@goptd@author]%
{%
  \gdef\pc@gopt@author{#1}%
}%
%
% define global style option icon for setting the icon of pdf annotations
\define@key{pdfcomment.sty}{icon}[\pc@goptd@icon]%
{%
  \gdef\pc@gopt@icon{#1}%
}%
%
% define global style option open for setting the open status (true,false) of pdf annotations
\define@key{pdfcomment.sty}{open}[\pc@goptd@open]%
{%
  \gdef\pc@gopt@open{#1}%
}%
%
% define global style option hspace for setting the space after the pdf annotations
\define@key{pdfcomment.sty}{hspace}[\pc@goptd@hspace]%
{%
  \gdef\pc@gopt@hspace{#1}%
}%
%
% define local command option subject for setting the subject of pdf annotations
\define@key{pdfcomment}{subject}[\pc@gopt@subject]%
{%
  \gdef\pc@lopt@subject{#1}%
}%
%
% define local command option color for setting the color of pdf annotations
\define@key{pdfcomment}{color}[\pc@gopt@color]%
{%
  \gdef\pc@lopt@color{#1}%
}%
%
% define local command option author for setting the author of pdf annotations
\define@key{pdfcomment}{author}[\pc@gopt@author]%
{%
  \gdef\pc@lopt@author{#1}%
}%
%
% define local command option icon for setting the icon of pdf annotations
\define@key{pdfcomment}{icon}[\pc@gopt@icon]%
{%
  \gdef\pc@lopt@icon{#1}%
}%
%
% define local command option open for setting the open status (true,false) of pdf annotations
\define@key{pdfcomment}{open}[\pc@gopt@open]%
{%
  \gdef\pc@lopt@open{#1}%
}%
%
% define local command option hspace for setting the space after the pdf annotations
\define@key{pdfcomment}{hspace}[\pc@gopt@hspace]%
{%
  \gdef\pc@lopt@hspace{#1}%
}%
%
% define local command option subject for setting the subject of pdf annotations
\define@key{pdfmargincomment}{subject}[\pc@gopt@subject]%
{%
  \gdef\pc@lopt@subject{#1}%
}%
%
% define local command option color for setting the color of pdf annotations
\define@key{pdfmargincomment}{color}[\pc@gopt@color]%
{%
  \gdef\pc@lopt@color{#1}%
}%
%
% define local command option author for setting the author of pdf annotations
\define@key{pdfmargincomment}{author}[\pc@gopt@author]%
{%
  \gdef\pc@lopt@author{#1}%
}%
%
% define local command option icon for setting the icon of pdf annotations
\define@key{pdfmargincomment}{icon}[\pc@gopt@icon]%
{%
  \gdef\pc@lopt@icon{#1}%
}%
%
% define local command option open for setting the open status (true,false) of pdf annotations
\define@key{pdfmargincomment}{open}[\pc@gopt@open]%
{%
  \gdef\pc@lopt@open{#1}%
}%
%
% define local command option hspace for setting the space after the pdf annotations
\define@key{pdfmargincomment}{hspace}[\pc@gopt@hspace]%
{%
  \gdef\pc@lopt@hspace{#1}%
}%
%
\ExecuteOptionsX{subject,color,author,icon,open,hspace}%
%
\ProcessOptionsX\relax%
%
\RequirePackage{marginnote}%
\RequirePackage{hyperref}%
\RequirePackage{ifpdf}%
%
\ifpdf%
\else%
  \PackageError{pdfcomment}%
  {pdfcomment works only with pdflatex in PDF mode!}%
  {Not running pdfLaTeX in PDF mode; pdfcomment makes use of pdflatex primitive \pdfannot! Please run pdflatex!}%
\fi%
%
\newcommand{\pdfcomment}[2][subject={\pc@gopt@subject},color={\pc@gopt@color},author={\pc@gopt@author},icon={\pc@gopt@icon},open={\pc@gopt@open},hspace={\pc@gopt@hspace}]%
{%
  % Copy all global option to local options
  \gdef\pc@lopt@subject{\pc@gopt@subject}%
  \gdef\pc@lopt@color{\pc@gopt@color}%
  \gdef\pc@lopt@author{\pc@gopt@author}%
  \gdef\pc@lopt@icon{\pc@gopt@icon}%
  \gdef\pc@lopt@open{\pc@gopt@open}%
  \gdef\pc@lopt@hspace{\pc@gopt@hspace}%
  % Change local options if specified
  \setkeys{pdfcomment}{#1}%
  % Encode Contents, Author and Subject to pdf encodings (PD or PU) with hyperref's \pdfstringdef
  \def\pc@pdfenc@contents{}%
  \pdfstringdef\pc@pdfenc@contents{#2}%
  \def\pc@pdfenc@author{}%
  \pdfstringdef\pc@pdfenc@author{\pc@lopt@author}%
  \def\pc@pdfenc@subject{}%
  \pdfstringdef\pc@pdfenc@subject{\pc@lopt@subject}%
  % transform color input to pdf color
  \HyColor@XZeroOneThreeFour{\pc@lopt@color}{\pc@hyenc@color}{pdfcomment}{color}%
  % typeset text annotation (see: PDF Reference)
  \pdfannot width 0pt height \baselineskip depth 0pt%
  {%
    /Subtype /Text%
	/C [\pc@hyenc@color]%
	/T (\pc@pdfenc@author)%
	/Subj (\pc@pdfenc@subject)%
	/Name /\pc@lopt@icon%
	/Contents (\pc@pdfenc@contents)%
	/Open \pc@lopt@open%
  }
  \hspace{\pc@lopt@hspace}%
}%
%
\newcommand{\pdfmargincomment}[2][subject={\pc@gopt@subject},color={\pc@gopt@color},author={\pc@gopt@author},icon={\pc@gopt@icon},open={\pc@gopt@open},hspace={\pc@gopt@hspace}]%
{%
  % Copy all global option to local options
  \gdef\pc@lopt@subject{\pc@gopt@subject}%
  \gdef\pc@lopt@color{\pc@gopt@color}%
  \gdef\pc@lopt@author{\pc@gopt@author}%
  \gdef\pc@lopt@icon{\pc@gopt@icon}%
  \gdef\pc@lopt@open{\pc@gopt@open}%
  \gdef\pc@lopt@hspace{\pc@gopt@hspace}%
  % Change local options if specified
  \setkeys{pdfmargincomment}{#1}%
  % Encode Contents, Author and Subject to pdf encodings (PD or PU) with hyperref's \pdfstringdef
  \def\pc@pdfenc@contents{}%
  \pdfstringdef\pc@pdfenc@contents{#2}%
  \def\pc@pdfenc@author{}%
  \pdfstringdef\pc@pdfenc@author{\pc@lopt@author}%
  \def\pc@pdfenc@subject{}%
  \pdfstringdef\pc@pdfenc@subject{\pc@lopt@subject}%
  % transform color input to pdf color
  \HyColor@XZeroOneThreeFour{\pc@lopt@color}{\pc@hyenc@color}{pdfcomment}{color}%
  \begingroup
  % center marginnotes!
    \renewcommand*{\raggedleftmarginnote}{\centering}%
    \renewcommand*{\raggedrightmarginnote}{\centering}%
    % typeset text annotation (see: PDF Reference)
    \marginnote%
    {%
      \pdfannot width 0pt height \baselineskip depth 0pt%
      {%
        /Subtype /Text%
	    /C [\pc@hyenc@color]%
	    /T (\pc@pdfenc@author)%
	    /Subj (\pc@pdfenc@subject)%
	    /Name /\pc@lopt@icon%
	    /Contents (\pc@pdfenc@contents)%
	    /Open \pc@lopt@open%
      }
      \hspace{\pc@lopt@hspace}%
    }%
  \endgroup
}%
%
\newcommand{\pdfcommentsetup}[1]%
{%
  % Change global options if specified
  \setkeys{pdfcomment.sty}{#1}%
}%
%
%
%
\endinput%