%%
%% This is file `tikz-imagelabels.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tikz-imagelabels.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2019 by Tobias Plüss <tpluess@ieee.org>
%% 
%% This work 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 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{tikz-imagelabels}
  [2019/01/29 v0.1 put labels on images using TikZ]
\RequirePackage{tikz}
\RequirePackage{xifthen}
\usetikzlibrary{
  arrows.meta,
  calc,
  positioning,
  decorations,
  decorations.markings,
  math,
}
\pgfkeys{
  /imagelabels/.is family,
  /imagelabels/.search also={/tikz},
}

\def\imagelabelset{\pgfqkeys{/imagelabels}}
\imagelabelset{
  coarse grid color/.store in = \maingridcolor,
  fine grid color/.store in = \finegridcolor,
}

\imagelabelset{
  image label font/.store in = \imagelabelfont,
  image label distance/.store in = \imagelabelsep,
  image label back/.store in = \imagelabelback,
  image label text/.store in = \imagelabeltext,
}

\imagelabelset{
  annotation font/.store in = \annotationfont,
  arrow distance/.store in = \arrowdistance,
  arrow thickness/.store in = \arrowthickness,
  tip size/.store in = \tipsize,
  border thickness/.store in = \borderthickness,
  outer dist/.store in = \labeloutersep,
}
\imagelabelset{
  coarse grid color = red,
  fine grid color = gray,
  image label font = \sffamily\bfseries\small,
  image label distance = 2mm,
  image label back = black,
  image label text = white,
  annotation font = \normalfont\small,
  arrow distance = 1.5mm,
  border thickness = 0.6pt,
  arrow thickness = 0.4pt,
  tip size = 1.2mm,
  outer dist = 0.5cm,
}
\newenvironment{annotationimage}[3][]{
\let\tikzset\imagelabelset
  \begin{tikzpicture}
  \node[anchor=south west, inner sep=0]
    (image) at (0,0) {\includegraphics[#2]{#3}};
  \begin{scope}[x={(image.south east)},y={(image.north west)}]
  \ifthenelse{\equal{#1}{grid}}{%
    \draw[very thin, draw=\finegridcolor, step=0.02]
      (0,0) grid (1,1);
    \draw[thin, draw=\maingridcolor, xstep=0.1, ystep=0.1]
      (0,0) grid (1,1);
    \foreach \x in {0,1,...,9} {
      \node [anchor=north] at (\x/10,0) {\tiny 0.\x};
    }
    \node [anchor=north] at (1,0) {\tiny 1};

    \foreach \y in {0,1,...,9} {
      \node [anchor=east] at (0,\y/10) {\tiny 0.\y};
    }
    \node [anchor=east] at (0,1) {\tiny 1};
  }{}
}
{
 \end{scope}
 \end{tikzpicture}}
\imagelabelset{
  annotation arrow/.style =
  {
    preaction =
    {
      draw,
      -{Circle[fill=white, length=\tipsize+2*\borderthickness,
        width=\tipsize+2*\borderthickness]},
      line width = 2*\borderthickness + \arrowthickness,
      white,
      shorten >= \arrowdistance,
    },
    draw,
    -{Circle[fill=black, length=\tipsize, width=\tipsize]},
    black,
    line width = \arrowthickness,
    shorten >= \borderthickness + \arrowdistance,
  },
  annotation node/.style =
  {
    font=\annotationfont,
    inner sep = 0.5ex,
  },
  annotation below/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (#2,0) ++ (0,-\labeloutersep)
        node[anchor = north, annotation node] {#1\strut}
    }
  },
  annotation above/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (#2,1.0) ++ (0,\labeloutersep)
        node[anchor = south, annotation node] {#1\strut}
    }
  },
  annotation left/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (0,#2) ++ (-\labeloutersep,0)
        node[anchor = east, annotation node] {#1}
    }
  },
  annotation right/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (1.0,#2) ++ (\labeloutersep,0)
        node[anchor = west, annotation node] {#1}
    }
  },
}
\imagelabelset{
  image label style/.style = {
    rectangle,
    minimum width = 5mm,
    minimum height = 5mm,
    fill = \imagelabelback,
    text = \imagelabeltext,
    font = \imagelabelfont,
  },
  image label/.style args = {#1 at #2}{
    insert path = {
      (image.#2) node[outer sep = \imagelabelsep,
        anchor=#2, image label style] {#1}
    }
  },
}
\endinput
%%
%% End of file `tikz-imagelabels.sty'.
