/***************************************************************************
                   html32generator.cpp  -  description
                             -------------------
    copyright            : (C) 2007 by Andre Simon
    email                : andre.simon1@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <sstream>

#include "version.h"
#include "html32generator.h"

using namespace std;

namespace ansifilter {

Html32Generator::Html32Generator ():
  CodeGenerator(HTML32)
{
  newLineTag = "\n";
  spacer = " ";
  styleCommentOpen="/*";
  styleCommentClose="*/";
}


string  Html32Generator::getOpenTag() {
    ostringstream s;
  s << "<font color=\""<<"#"
	   << elementStyle.getFgColour().getRed(HTML)
	<< elementStyle.getFgColour().getGreen(HTML)
	<< elementStyle.getFgColour().getBlue(HTML)
    << "\">";
  if (elementStyle.isBold()) s << "<b>";
  if (elementStyle.isItalic()) s << "<i>";
  if (elementStyle.isUnderline()) s << "<u>";
  return  s.str();
}

string  Html32Generator::getCloseTag() {
  ostringstream s;
  if (elementStyle.isUnderline()) s << "</u>";
  if (elementStyle.isItalic()) s << "</i>";
  if (elementStyle.isBold()) s << "</b>";
  s << "</font>";
  return  s.str();
}

string Html32Generator::getHeader()
{
  ostringstream os;
  os << "<html>\n<body bgcolor=\"#"
	<< elementStyle.getBgColour().getRed(HTML) 
	<< elementStyle.getBgColour().getGreen(HTML)
	<< elementStyle.getBgColour().getBlue(HTML)
     << "\" text=\"#"
	   << elementStyle.getFgColour().getRed(HTML)
	<< elementStyle.getFgColour().getGreen(HTML)
	<< elementStyle.getFgColour().getBlue(HTML)
     << "\">\n<pre><font face=\""<< font<<"\">";
  return os.str();
}

string Html32Generator::getFooter()
{
 ostringstream s;
 s <<"</font></pre>\n</body>\n</html>\n<!--HTML 3.2 generated by ansifilter "
   << ANSIFILTER_VERSION << ", " <<  ANSIFILTER_URL <<"-->\n";
 return s.str();
}

void Html32Generator::printBody()
{
  processRootState();
}

string Html32Generator::maskCharacter(unsigned char c)
{
  switch (c) {
    case '<' :
      return "&lt;";
      break;
    case '>' :
      return "&gt;";
      break;
    case '&' :
      return "&amp;";
      break;
    case '\"' :
      return "&quot;";
      break;

    //case '@' :
      //return "&#64;";
      //break;

    default :
      string m;
      return m += c;
    }
}

}
