\NeedsTeXFormat{LaTeX2e}%
\def\PackageName{bclogo}%
\def\fileversion{v3.0}%
\def\filedate{2011/10/01}%
\ProvidesPackage{bclogo}[\filedate\space\fileversion]%
%
% Extensions a charger
\RequirePackage{xkeyval,ifthen}%
\RequirePackage{graphicx}%
\RequirePackage{mdframed}%
\ifdef{\ifmdf@nobreak}{\relax}{\define@key{mdf}{nobreak}[]{}}%%l'option nobreak de mdframed vient avec la version 0.9
%
%% Les options globales du package sont au nombre de 2: tikz ou pstricks
\newif\ifbclogotikz%
\newif\ifbclogoblur%
\define@key{bclogo.sty}{tikz}[]{\bclogotikztrue}%
\define@key{bclogo.sty}{pstricks}[]{\bclogotikzfalse}%
\define@key{bclogo.sty}{blur}[]{\bclogoblurtrue}%
%
% quelques dimensions
\newlength{\bc@invboxh}\newlength{\bc@invboxd}%
\newlength{\bc@titleLength}%
\newlength{\logowidth}%
\newlength{\bc@mdfboxwidth}%
\newlength{\bc@mdfboxheight}%
%\newlength{\bc@mdf@ymargin@length}
%
\setlength{\logowidth}{17pt}%
\ProcessOptionsX%
%
\ifbclogotikz%
        \RequirePackage{tikz}%
        \usetikzlibrary{shadows}% pour l'ombre
        \usetikzlibrary{decorations.pathmorphing}% pour la barre ondulee
        \def\bc@mdf@style{1}%
        \input{bclogoMdframedTikz}%
\else%
        \RequirePackage{pstricks}%
        \RequirePackage{pst-grad}%
        \RequirePackage{pst-coil}% pour la barre ondulee
        \ifbclogoblur%
                \RequirePackage{pst-blur}%
                \let\pagecolorOLD\pagecolor% modification pour sauvegarde de la couleur du fond
                \def\pagecolor#1{\gdef\psx@blurbg{#1}\pagecolorOLD{#1}}%suppose l'utilisation: \pagecolor{couleur}
        \fi%
        \def\bc@mdf@style{3}%
        \input{bclogoMdframedPst}%
\fi%
\edef\Gin@extensions{.mps,\Gin@extensions}%
\RequirePackage{ifpdf}%
\ifpdf\relax\else\DeclareGraphicsRule{mps}{eps}{*}{}\fi%
%
% les symboles
% ==============================================================================
% la fleur
\newcommand\bcfleur{\includegraphics[width=\logowidth]{bc-fleur}}%
% une note (Thomas Labarussias)
\newcommand\bcnote{\includegraphics[width=\logowidth]{bc-note}}%
% panneau chantier (Jean-Michel Sarlat)
\newcommand\bcpanchant{\includegraphics[width=\logowidth]{bc-aux-301}}%
% ours
%\newcommand\bcours{\begingroup\input{bc-ours.tex}\endgroup}
\newcommand\bcours{\includegraphics[width=\logowidth]{bc-ours}}%
% etoile
%\newcommand\bcetoile{\begingroup\input{bc-etoile.tex}\endgroup}
\newcommand\bcetoile{\includegraphics[width=\logowidth]{bc-etoile}}%
% attention
%\newcommand\bcattention{\begingroup\input{bc-attention.tex}\endgroup}
\newcommand\bcattention{\includegraphics[width=\logowidth]{bc-attention}}%
% attention P.Fradin
\newcommand\bctakecare{\includegraphics[width=\logowidth]{bc-takecare}}%
% lampe P.Fradin
\newcommand\bclampe{\includegraphics[width=\logowidth]{bc-lampe}}%
% coeur
\newcommand\bccoeur{\includegraphics[width=\logowidth]{bc-coeur}}%
% ornement (tire du site http://openclipart.org )
\newcommand\bcorne{\includegraphics[width=\logowidth]{bc-orne}}%
% danger (Francois)
\newcommand\bcdanger{\includegraphics[width=\logowidth]{bc-danger}}%
% smiley bonne humeur (Francois)
\newcommand\bcsmbh{\includegraphics[width=\logowidth]{bc-smiley-bonnehumeur}}%
% smiley bonne humeur (Francois)
\newcommand\bcsmmh{\includegraphics[width=\logowidth]{bc-smiley-mauvaisehumeur}}%
% le trefle
\newcommand\bctrefle{\includegraphics[width=\logowidth]{bc-trefle}}%
% le livre
\newcommand\bcbook{\includegraphics[width=\logowidth]{bc-book}}%
% point d'interrogation
\newcommand\bcquestion{\includegraphics[width=\logowidth]{bc-inter}}%
% crayon anne-sophie philippe
\newcommand\bccrayon{\includegraphics[width=\logowidth]{bc-crayon}}%
% info (thomas labarrussias)
\newcommand\bcinfo{\includegraphics[width=\logowidth]{bc-info}}%
% plume
\newcommand\bcplume{\includegraphics[width=\logowidth]{bc-plume}}%
% le pic LaTeX
\newcommand\bcspadesuit{{\centering \huge $\spadesuit$}}%
% logos Alphonse Capriani
\newcommand\bcbombe{\includegraphics[width=\logowidth]{bc-bombe}}%
\newcommand\bccube{\includegraphics[width=\logowidth]{bc-cube}}%
\newcommand\bcdallemagne{\includegraphics[width=\logowidth]{bc-dallemagne}}%
\newcommand\bcdautriche{\includegraphics[width=\logowidth]{bc-dautriche}}%
\newcommand\bcdbelgique{\includegraphics[width=\logowidth]{bc-dbelgique}}%
\newcommand\bcdbulgarie{\includegraphics[width=\logowidth]{bc-dbulgarie}}%
\newcommand\bcdfrance{\includegraphics[width=\logowidth]{bc-dfrance}}%
\newcommand\bcditalie{\includegraphics[width=\logowidth]{bc-ditalie}}%
\newcommand\bcdluxembourg{\includegraphics[width=\logowidth]{bc-dluxembourg}}%
\newcommand\bcdpaysbas{\includegraphics[width=\logowidth]{bc-dpaysbas}}%
\newcommand\bcdodecaedre{\includegraphics[width=\logowidth]{bc-dodecaedre}}%
\newcommand\bceclaircie{\includegraphics[width=\logowidth]{bc-eclaircie}}%
\newcommand\bcicosaedre{\includegraphics[width=\logowidth]{bc-icosaedre}}%
\newcommand\bcinterdit{\includegraphics[width=\logowidth]{bc-interdit}}%
\newcommand\bcneige{\includegraphics[width=\logowidth]{bc-neige}}%
\newcommand\bcoctaedre{\includegraphics[width=\logowidth]{bc-octaedre}}%
\newcommand\bcpluie{\includegraphics[width=\logowidth]{bc-pluie}}%
\newcommand\bcpoisson{\includegraphics[width=\logowidth]{bc-poisson}}%
\newcommand\bcsoleil{\includegraphics[width=\logowidth]{bc-soleil}}%
\newcommand\bcstop{\includegraphics[width=\logowidth]{bc-stop}}%
\newcommand\bctetraedre{\includegraphics[width=\logowidth]{bc-tetraedre}}%
\newcommand\bccalendrier{\includegraphics[width=\logowidth]{bc-calendrier}}%
\newcommand\bchorloge{\includegraphics[width=\logowidth]{bc-horloge}}%
\newcommand\bcyin{\includegraphics[width=\logowidth]{bc-yin}}%
\newcommand\bcrosevents{\includegraphics[width=\logowidth]{bc-rosevents}}%
% fin alphonse
% Vincent Pantaloni route glissante
\newcommand\bcdz{\includegraphics[width=\logowidth]{bc-dz}}%
% François Pétiard
\newcommand\bcvelo{\includegraphics[width=\logowidth]{bc-velo}}%
\newcommand\bcoeil{\includegraphics[width=\logowidth]{bc-oeil}}%
\newcommand\bcpeaceandlove{\includegraphics[width=\logowidth]{bc-peaceandlove}}%
\newcommand\bcnucleaire{\includegraphics[width=\logowidth]{bc-nucleaire}}%
\newcommand\bcfemme{\includegraphics[width=\logowidth]{bc-femme}}%
\newcommand\bchomme{\includegraphics[width=\logowidth]{bc-homme}}%
\newcommand\bcloupe{\includegraphics[width=\logowidth]{bc-loupe}}%
\newcommand\bcrecyclage{\includegraphics[width=\logowidth]{bc-recyclage}}%
\newcommand\bcvaletcoeur{\includegraphics[width=\logowidth]{bc-valetcoeur}}%
\newcommand\bccle{\includegraphics[width=\logowidth]{bc-cle}}%
\newcommand\bcclefa{\includegraphics[width=\logowidth]{bc-clefa}}%
\newcommand\bcclesol{\includegraphics[width=\logowidth]{bc-clesol}}%
\newcommand\bcfeujaune{\includegraphics[width=\logowidth]{bc-feujaune}}%
\newcommand\bcfeurouge{\includegraphics[width=\logowidth]{bc-feurouge}}%
\newcommand\bcfeutricolore{\includegraphics[width=\logowidth]{bc-feutricolore}}%
\newcommand\bcfeuvert{\includegraphics[width=\logowidth]{bc-feuvert}}%
\newcommand\bcoutil{\includegraphics[width=\logowidth]{bc-outil}}%
\newcommand\bctrombone{\includegraphics[width=\logowidth]{bc-trombone}}%
% fin François
% =========================== La fonction listable =============================
%
\newcommand{\titrebclogo}{Liste des \texttt{bclogo}}%
\newcommand\bccaption[1]{\addcontentsline{bcl}{bclogo}{#1}}%
\newcommand\listofbclogo{\section*{\titrebclogo}\@starttoc{bcl}}%
\newcommand\l@bclogo[2]{\par\noindent #1,~\textit{page~#2}}%
\newcounter{bclogocompteur} % idee de Francois Petiard
%
% ======================================= les keys =============================
%
\newlength{\bcval@epBarre}% on definit une longueur : l'epaisseur de la barre en point
\newlength{\bcval@framesep}% on definit une longueur : l'epaisseur de la marge en point
\newlength{\bcval@tailleOndu}% on definit une longueur : taille d'une ondulation
\newlength{\bcval@borderWidth}% on definit une longueur : epaisseur du bord
\newlength{\bcval@margeG}% on definit une longueur : marge gauche avant la boîte
\newlength{\bcval@margeD}% on definit une longueur : marge droite après la boîte
\define@key{bclogo}{logo}[\bcfleur]{\def\bcval@logo{#1}}%
\define@key{bclogo}{couleur}[white]{\def\bcval@couleur{#1}}%
\define@key{bclogo}{arrondi}[0]{\def\bcval@arrondi{#1}}%
\define@key{bclogo}{epOmbre}[0.125]{\def\bcval@epOmbre{#1}}%
\define@key{bclogo}{arrondi}[0]{\def\bcval@arrondi{#1}}%
\define@key{bclogo}{couleurOmbre}[black]{\def\bcval@couleurOmbre{#1}}%
\define@key{bclogo}{couleurBarre}[black]{\def\bcval@couleurBarre{#1}}%
\define@key{bclogo}{couleurBord}[black]{\def\bcval@couleurBord{#1}}% modification Philippe Fortemps
\define@key{bclogo}{couleurTexte}[black]{\def\bcval@couleurTexte{#1}}%
\define@key{bclogo}{imageBarre}[]{\def\bcval@imageBarre{#1}}%
\define@key{bclogo}{motifBarre}[*]{\def\bcval@motifBarre{#1}}%
\define@key{bclogo}{marge}[4]{\setlength{\bcval@framesep}{#1 pt}}%
\define@key{bclogo}{margeG}[0]{\setlength{\bcval@margeG}{#1 cm}}%
\define@key{bclogo}{margeD}[0]{\setlength{\bcval@margeD}{#1 cm}}%
\define@key{bclogo}{sousTitre}[]{\def\bcval@sousTitre{#1}}%
\define@key{bclogo}{epBarre}[1.5]{\setlength{\bcval@epBarre}{#1 pt}}%
\define@key{bclogo}{epBord}[0.8]{\setlength{\bcval@borderWidth}{#1 pt}%
        \ifdimgreater{\bcval@borderWidth}{\z@}{\KV@bclogo@noborderfalse}{\KV@bclogo@nobordertrue}%
        }%
\define@key{bclogo}{tailleOndu}[2.5]{\setlength{\bcval@tailleOndu}{#1 pt}}%
\define@boolkey{bclogo}{cadreTitre}[true]{}%
\define@boolkey{bclogo}{noborder}[true]{\ifKV@bclogo@noborder\setlength{\bcval@borderWidth}{\z@}\fi}%
\define@boolkey{bclogo}{ombre}[true]{}%
\define@boolkey{bclogo}{avecBarre}[true]{}%
\define@boolkey{bclogo}{nobreak}[true]{}%
\define@boolkey{bclogo}{blur}[true]{\ifKV@bclogo@blur\KV@bclogo@ombretrue\fi}%
\define@choicekey{bclogo}{barre}{none,line,snake,motif,zigzag,imageExt,imageClip, wave}[line]{%
\ifthenelse{\equal{#1}{none}}{\KV@bclogo@avecBarrefalse\gdef\bc@barre{}}%
{\gdef\bc@barre{\ifKV@bclogo@avecBarre\@nameuse{bc@barre#1}\fi}}%
}%
%
% selection par defaut
\presetkeys{bclogo}{logo,barre,couleur,arrondi,couleurOmbre,couleurTexte,couleurBarre,epOmbre,epBarre,epBord,tailleOndu,ombre=false,cadreTitre=false,%
avecBarre=true,noborder=false,marge,sousTitre, couleurBord,blur=false, nobreak=false}{}%
%
%les differentes commandes de barre verticale a gauche
%
\newcommand{\bc@barreline}{%
\begin{minipage}{\logowidth}\centering%
\ifbclogotikz%
\begin{tikzpicture}%
\draw[line width=\bcval@epBarre,line cap=butt,color=\bcval@couleurBarre](0,\bc@invboxh)--(0,0);\end{tikzpicture}%
\else%
\psset{unit=1pt}%
\begin{pspicture}(0,0)(0,\bc@invboxh)%
\psline[linewidth=\bcval@epBarre,linecolor=\bcval@couleurBarre](0,\bc@invboxh)(0,0)%
\end{pspicture}%
\fi%
\end{minipage}}%
%
\newcommand{\bc@barremotif}{%
\begin{minipage}{\logowidth}\color{\bcval@couleurBarre}\centering%
\vbox to \bc@invboxh{\cleaders\vbox{\vss \bcval@motifBarre \vss}\vfill}%
\end{minipage}}%
%
\newcommand{\bc@barrewave}{%
\begin{minipage}{\logowidth}\color{\bcval@couleurBarre}\centering%
\vbox to \bc@invboxh{\cleaders\vbox{\vss $\leftwave\right.$ \vss}\vfill}%
\end{minipage}}%
%
\newcommand{\bc@barresnake}{%
\begin{minipage}{\logowidth}\centering%
\ifbclogotikz%
\begin{tikzpicture}[decoration={snake,segment length=2.66\bcval@tailleOndu, amplitude=\bcval@tailleOndu}]%
\draw[decorate,line width=1pt, color=\bcval@couleurBarre](0,\bc@invboxh)--(0,0);\end{tikzpicture}%
\else%
\psset{unit=1pt}%
\begin{pspicture}(0,0)(0,\bc@invboxh)%
\pszigzag[coilarm=0pt,coilwidth=2\bcval@tailleOndu,linewidth=1pt,linearc=1pt,coilheight=1.33,linecolor=\bcval@couleurBarre](0,\bc@invboxh)(0,0)%
\end{pspicture}%
\fi%
\end{minipage}}%
%
\newcommand{\bc@barrezigzag}{%
\begin{minipage}{\logowidth}\centering%
\ifbclogotikz%
\begin{tikzpicture}[decoration={zigzag,segment length=2.66\bcval@tailleOndu, amplitude=\bcval@tailleOndu}]%
\draw[decorate,line width=1pt,color=\bcval@couleurBarre](0,\bc@invboxh)--(0,0);\end{tikzpicture}%
\else%
\psset{unit=1pt}%
\begin{pspicture}(0,0)(0,\bc@invboxh)%
\pszigzag[coilarm=0pt,coilwidth=2\bcval@tailleOndu,linewidth=1pt,linearc=0pt,coilheight=1.33,linecolor=\bcval@couleurBarre](0,\bc@invboxh)(0,0)%
\end{pspicture}%
\fi%
\end{minipage}}%
%
\newcommand{\bc@barreimageExt}{% l'image est deformee
\begin{minipage}{\logowidth}\centering%
\includegraphics[width=\logowidth,height=\bc@invboxh]{\bcval@imageBarre}%
\end{minipage}}%
%
\newcommand{\bc@barreimageClip}{%
\begin{minipage}{\logowidth}\centering%
\includegraphics[viewport=0 0 \logowidth~ \bc@invboxh,%
clip=true]{\bcval@imageBarre}%
\end{minipage}}%
%
%======================= Quelques definitions===================================
% boite titre
\newsavebox{\bc@envbox}%
%%% precaution JCC
\newcommand*\bclogotitre{}%
\newcommand\bcStyleSousTitre[1]{\normalsize \textit{#1}}%
\newcommand\styleSousTitre[1]{\bcStyleSousTitre{#1}}% pour la compatibilit
\newcommand\bcStyleTitre[1]{\large \textbf{#1}}%
%======================= L'environnement =======================================
%
\newenvironment*{bclogo}[2][]{%
   \setkeys{bclogo}{#1}%options
   \renewcommand*\bclogotitre{#2}%
  % deux types de titres
   \ifKV@bclogo@cadreTitre% si cadreTitre = true
       \def\bc@structitre{%
            \hfil%
            \ifbclogotikz% cadreTitre tikz
            \begin{tikzpicture}%
                \node[rectangle, thick, top color=red!60!green!40, bottom color=white,draw]{\large #2};%
            \end{tikzpicture}%
            \else% cadreTitre pstricks
            \psframebox[fillstyle=gradient,gradmidpoint=0.2, gradangle=0,gradbegin=red!60!green!40, gradend=white]{\large  #2}%
            \fi%
            \hfil%
        }%
  \else%sinon cadreTitre = false
      \def\bc@structitre{\bcStyleTitre{#2} \bcStyleSousTitre{\bcval@sousTitre}}%
  \fi%
%boite logo+titre
\setlength{\bc@titleLength}{%
\dimexpr\linewidth-\bcval@margeD-\bcval@margeG-1.5\bcval@framesep-\ifKV@bclogo@noborder\z@\else2\bcval@borderWidth\fi-%
\logowidth-\ifKV@bclogo@ombre\bcval@epOmbre cm\else\z@\fi\relax}%
%
   \begin{lrbox}{\bc@envbox}% boite titre
     \begin{tabular}{@{}c@{}p{\bc@titleLength}@{}}%
       \begin{minipage}{\logowidth}%
                \refstepcounter{bclogocompteur}\bccaption{\bclogotitre}\bcval@logo%
       \end{minipage}%
     &%
       \ifKV@bclogo@cadreTitre%
         \begin{minipage}{\bc@titleLength}%
                \bc@structitre%
         \end{minipage}%
       \else\bc@structitre\fi%
   \end{tabular}%
  \end{lrbox}%
% affichage
%\smallskip% ressort %% Pourquoi ?
\def\bcval@nobreak{\ifKV@bclogo@nobreak true\else false\fi}% gestion nobreak
\mdframed[%
 innerleftmargin={\dimexpr\ifKV@bclogo@avecBarre\logowidth\else\z@\fi+\bcval@framesep\relax},%
 innertopmargin={\dimexpr\ht\bc@envbox+\dp\bc@envbox+\bcval@framesep\relax},%hauteur titre+framesep
 innerrightmargin=\bcval@framesep,%
 innerbottommargin=\bcval@framesep,%
 rightmargin=\dimexpr\bcval@margeD+\ifKV@bclogo@ombre\bcval@epOmbre cm\else\z@\fi,%
 leftmargin=\bcval@margeG,%
 backgroundcolor=\bcval@couleur,%
 fontcolor=\bcval@couleurTexte,%
 linewidth=\bcval@borderWidth,%
 roundcorner={\bcval@arrondi cm},%
 nobreak=\bcval@nobreak%%l'option nobreak de mdframed vient avec la version 0.9
]%
}%
{%
\endmdframed\par%
\ifKV@bclogo@ombre\vspace*{\bcval@epOmbre cm}\else\smallskip\fi%
\goodbreak%
}%
\setkeys{bclogo}{barre=none}%% en cas d'utlisation de l'environnement mdframed 
