# -*- CPERL -*-
# /=====================================================================\ #
# |  graphics                                                           | #
# | 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=/ #
# (See  LaTeXML::Post::Graphics for suggested postprocessing)
#**********************************************************************
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
#**********************************************************************
# Package options: draft, final, hiderotate, hidescale, hiresbb

DefParameterType('GraphixDimension',  sub{
  my($gullet)=@_;
  if($gullet->ifNext(T_OTHER('!'))){
    $gullet->readToken();
    Dimension(0); }		# !!!
  else {
    $gullet->readDimension; }});

# Unimplemented, for now: What should be the result?
# Would seem to require different treatment if the content was ONLY \includegraphic,
# or more general text.
DefConstructor('\scalebox{}[]{}','#3',
	       mode=>'text');
DefConstructor('\resizebox OptionalMatch:* {GraphixDimension}{GraphixDimension}{}','#4',
	       mode=>'text');
DefConstructor('\rotatebox{Number}{}','#2',
	       mode=>'text');
DefConstructor('\reflectbox{}','#1',
	       mode=>'text');

DefConstructor('\graphicspath Semiverbatim',"<?latexml graphicspath='#1'?>");

# Basically, we're transforming the graphics options into graphicx format.
DefMacro('\includegraphics OptionalMatch:* [][] Semiverbatim',
	 '\@includegraphics#1[#2][#3]{#4}');

DefConstructor('\@includegraphics OptionalMatch:* [][] Semiverbatim', sub {
  my($document,$starred,$op1,$op2,$graphic)=@_;
  my $bb = ($op2 ? ToString($op1)." ".ToString($op2) : ($op1 ? "0 0 ".ToString($op1) : ''));
  $bb=~ s/,/ /g;
  my $options=($starred ? ($bb ? "viewport=$bb, clip" : "clip") : '');
  $document->insertElement('ltx:graphics',undef,graphic=>$graphic,options=>$options); },
	       alias=>'\includegraphics');

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

