/* * This code is based in the HTML output generated by Dev-C++ */ #include "HTMLExporter.h" #include #include #include #include #include #include using std::ofstream; using std::ostringstream; using std::hex; using std::setw; using std::setfill; using std::uppercase; using std::size_t; namespace { // Helper function to convert i to a string inline string to_string(int i) { ostringstream ostr; ostr << i; return ostr.str(); } }; const char *HTMLExporter::HTMLHeaderBEG = "\n" "\n" "\n" "\n"; const char *HTMLExporter::HTMLMeta = "\n" "\n"; const char *HTMLExporter::HTMLStyleBEG = ""; const char *HTMLExporter::HTMLHeaderEND = "\n"; const char *HTMLExporter::HTMLBodyBEG = "\n" "
\n";

string HTMLExporter::HTMLBody(const wxMemoryBuffer &styled_text)
{
  string html_body("");
  const char *buffer = reinterpret_cast(styled_text.GetData());
  const size_t buffer_size = styled_text.GetDataLen();

  wxString fontstring = ConfigManager::Get()->Read(_T("/editor/font"), wxEmptyString);

  if (!fontstring.IsEmpty())
  {
    wxFont tmpFont;
    wxNativeFontInfo nfi;
    nfi.FromString(fontstring);
    tmpFont.SetNativeFontInfo(nfi);

    int pt = tmpFont.GetPointSize();
    wxString faceName = tmpFont.GetFaceName();

    if (!faceName.IsEmpty())
    {
      html_body = string("");
    }
  }

  if (buffer_size == 0)
  {
    return html_body;
  }

  // Get the current style from the first character
  char current_style = buffer[1];

  // If the first style happen to be the body style...
  if (current_style == 0)
  {
    html_body += string("");
  }
  else
  {
    html_body += string("";
  }

  for (size_t i = 0; i < buffer_size; i += 2)
  {
    if (buffer[i + 1] != current_style)
    {
      if (!isspace(buffer[i]))
      {
        html_body += "";
        current_style = buffer[i + 1];
        html_body += string("";
      }
    }

    switch (buffer[i])
    {
      case '<':
        html_body += "<";
        break;

      case '>':
        html_body += ">";
        break;

      case '&':
        html_body += "&";
        break;

      case '\r':
        break;

      default:
        html_body += buffer[i];
        break;
    }
  }

  html_body += "";

  return html_body;
}

const char *HTMLExporter::HTMLBodyEND =
  "\n"
  "
\n" "\n" "\n"; void HTMLExporter::Export(const wxString &filename, const wxString &title, const wxMemoryBuffer &styled_text, const EditorColorSet *color_set) { string html_code; HighlightLanguage lang = const_cast(color_set)->GetLanguageForFilename(title); html_code += HTMLHeaderBEG; html_code += string("") + string(reinterpret_cast<const char *>(title.c_str())) + string("\n"); html_code += HTMLMeta; html_code += HTMLStyleBEG; html_code += HTMLStyle(color_set, lang); html_code += HTMLStyleEND; html_code += HTMLHeaderEND; html_code += HTMLBodyBEG; html_code += HTMLBody(styled_text); html_code += HTMLBodyEND; ofstream file(filename.c_str()); file << html_code; }