# -*- mode: Perl -*-
# /=====================================================================\ #
# |  epsfig                                                             | #
# | Implementation for LaTeXML                                          | #
# |=====================================================================| #
# | Part of LaTeXML:                                                    | #
# |  Public domain software, produced as part of work done by the       | #
# |  United States Government & not subject to copyright in the US.     | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;
use LaTeXML::Util::Image;

#**********************************************************************
# (See  LaTeXML::Post::Graphics for suggested postprocessing)

RequirePackage('graphicx');
AssignValue(epsfclip => 0);
DefKeyVal('epsGin', 'width',           'Dimension');
DefKeyVal('epsGin', 'height',          'Dimension');
DefKeyVal('epsGin', 'keepaspectratio', '', 'true');
DefKeyVal('epsGin', 'clip',            '', 'true');

DefKeyVal('epsGin', 'figure', 'Semiverbatim');
DefKeyVal('epsGin', 'file',   'Semiverbatim');

DefKeyVal('epsGin', 'prolog', 'Semiverbatim');
DefKeyVal('epsGin', 'silent', '');

DefConstructor('\psfig RequiredKeyVals:epsGin',
  "<ltx:graphics graphic='#graphic' candidates='#candidates' options='#options'/>",
  sizer      => \&image_graphicx_sizer,
  properties => sub {
    my ($stomach, $kv) = @_;
    my $file = $kv->getValue('file') || $kv->getValue('figure');
    $file = ToString($file); $file =~ s/^\s+//; $file =~ s/\s+$//;
    $kv->setValue(file   => undef);
    $kv->setValue(figure => undef);
    $kv->setValue(clip   => 'true') if LookupValue('epsfclip');
    my @candidates = pathname_findall($file, types => ['*'], paths => LookupValue('GRAPHICSPATHS'));
    if (my $base = LookupValue('SOURCEDIRECTORY')) {
      @candidates = map { pathname_relative($_, $base) } @candidates; }
    my $options = ToString($kv);
    (graphic => $file,
      candidates => join(',', @candidates),
      options => $options); });

Let('\epsfig', '\psfig');

# Also unimplemented... probably nothing useful to pass thru anyway?
DefConstructor('\DeclareGraphicsExtensions{}',          '');
DefConstructor('\DeclareGraphicsRule{}{}{} Undigested', '');
# Nothing done about the keyval package...

# Ignorable
DefPrimitive('\psdraft',       undef);
DefPrimitive('\psfull',        undef);
DefPrimitive('\pssilent',      undef);
DefPrimitive('\psnoisy',       undef);
DefPrimitive('\psfigdriver{}', undef);
# \epsfsize ?
# Probably not ignorable, but don't have time to figure out just now...
DefPrimitive('\epsfbox[]{}', undef);
Let('\epsffile', '\epsfbox');
DefPrimitive('\epsfclipon',  sub { AssignValue(epsfclip => 1); });
DefPrimitive('\epsfclipoff', sub { AssignValue(epsfclip => 0); });

DefPrimitive('\epsfverbosetrue',  undef);
DefPrimitive('\epsfverbosefalse', undef);

# Ignored!
DefRegister('\epsfxsize' => Dimension(0));
DefRegister('\epsfysize' => Dimension(0));
DefPrimitive('\epsfsize{}{}', undef);
#**********************************************************************
1;