void ODTExporter::ODTCreateDirectoryStructure(wxZipOutputStream &zout) { zout.PutNextEntry(_T("META-INF/")); zout.PutNextEntry(_T("Thumbnails/")); zout.PutNextEntry(_T("Pictures/")); zout.PutNextEntry(_T("Configurations2/")); }
bool CompressRecursively(const wxString &path, wxZipOutputStream &zipStream, const wxString &topDir) { wxFileName destPath(path); destPath.MakeRelativeTo(topDir); if (wxFileExists(path)) { zipStream.PutNextEntry(destPath.GetFullPath()); wxFFileInputStream inStream(path); zipStream.Write(inStream); } else if (wxDirExists(path)) { zipStream.PutNextDirEntry(destPath.GetFullPath()); wxDir dir(path); wxString subpath; if (dir.GetFirst(&subpath)) { do { if (!CompressRecursively(Path::Combine(path, subpath), zipStream, topDir)) return false; } while (dir.GetNext(&subpath)); } } return true; }
string ODTExporter::ODTStylesFileMID(wxZipOutputStream &zout) { static const char *t1 = "<office:font-face-decls>\n" " <style:font-face style:name=\""; // FontName static const char *t2 = "\" svg:font-family=\""; // FontName static const char *t3 = "\"/>\n" "</office:font-face-decls>\n" "<office:styles>\n" "<style:style style:family=\"paragraph\"\n" " style:name=\"Default\"\n" " style:display-name=\"Default\"\n" " style:parent-style-name=\"Standard\"\n" " style:class=\"text\">\n" " <style:text-properties style:font-name=\""; // FontName static const char *t4 = "\" fo:font-size=\""; // Pt static const char *t5 = "pt\"/>\n" "</style:style>\n"; string theFont("Courier New"); string thePt("8"); wxString fontstring = Manager::Get()->GetConfigManager(_T("editor"))->Read(_T("/font"), wxEmptyString); if (!fontstring.IsEmpty()) { wxFont tmpFont; wxNativeFontInfo nfi; nfi.FromString(fontstring); tmpFont.SetNativeFontInfo(nfi); thePt = to_string(tmpFont.GetPointSize()); wxString faceName = tmpFont.GetFaceName(); if (!faceName.IsEmpty()) { theFont = string(faceName.mb_str()); } } zout.Write(t1, strlen(t1)); zout.Write(theFont.c_str(), theFont.size()); zout.Write(t2, strlen(t2)); zout.Write(theFont.c_str(), theFont.size()); zout.Write(t3, strlen(t3)); zout.Write(theFont.c_str(), theFont.size()); zout.Write(t4, strlen(t4)); zout.Write(thePt.c_str(), thePt.size()); zout.Write(t5, strlen(t5)); return theFont; }
void TransferZipArchive(wxInputStream &stream, wxZipOutputStream &out) { wxZipInputStream zipStream(stream); std::auto_ptr<wxZipEntry> entry; while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL) { if (entry->IsDir()) continue; wxString name = entry->GetName(); out.PutNextEntry(name); out.Write(zipStream); } }
void ZipTestCase::OnCreateEntry(wxZipOutputStream& zip, TestEntry& testEntry, wxZipEntry *entry) { zip.SetLevel((m_id + m_count) % 10); if (entry) { switch ((m_id + m_count) % 5) { case 0: { wxString comment = wxT("Comment for ") + entry->GetName(); entry->SetComment(comment); // lowercase the expected result, and the notifier should do // the same for the zip entries when ModifyArchive() runs testEntry.SetComment(comment.Lower()); break; } case 2: entry->SetMethod(wxZIP_METHOD_STORE); break; case 4: entry->SetMethod(wxZIP_METHOD_DEFLATE); break; } entry->SetIsText(testEntry.IsText()); } m_count++; }
void ODTExporter::ODTCreateCommonFiles(wxZipOutputStream &zout) { zout.PutNextEntry(_T("META-INF/manifest.xml")); zout.Write(ODTManifestFile, strlen(ODTManifestFile)); zout.PutNextEntry(_T("meta.xml")); zout.Write(ODTMetaFile, strlen(ODTMetaFile)); zout.PutNextEntry(_T("mimetype")); zout.Write(ODTMIMETypeFile, strlen(ODTMIMETypeFile)); zout.PutNextEntry(_T("settings.xml")); zout.Write(ODTSettingsFile, strlen(ODTSettingsFile)); }
void ODTExporter::ODTCreateContentFile(wxZipOutputStream &zout, const wxMemoryBuffer &styled_text, int lineCount, int tabWidth) { const char *buffer = reinterpret_cast<char *>(styled_text.GetData()); const size_t buffer_size = styled_text.GetDataLen(); int lineno = 1; int width = calcWidth(lineCount); zout.PutNextEntry(_T("content.xml")); zout.Write(ODTContentFileBEG, strlen(ODTContentFileBEG)); if (buffer_size) { char current_style = buffer[1]; string content("<text:h text:style-name=\"Default\">"); if (lineCount != -1) { int difWidth = width - calcWidth(lineno); if (difWidth > 0) { content += string("<text:s text:c=\"") + to_string(difWidth) + string("\"/>"); } content += to_string(lineno); ++lineno; content += "<text:s text:c=\"2\"/>"; } size_t first = 0; if (buffer_size > 0 && buffer[0] == ' ') { content += fix_spaces(buffer, &first, buffer_size, true); } if (current_style != 0) { content += string("<text:span text:style-name=\"style") + to_string(current_style) + string("\">"); } int charLinePos = 0; for (size_t i = first; i < buffer_size; i += 2, ++charLinePos) { if (buffer[i + 1] != current_style) { if (!isspace(buffer[i])) { if (current_style != 0) { content += string("</text:span>"); } current_style = buffer[i + 1]; if (current_style != 0) { content += string("<text:span text:style-name=\"style") + to_string(current_style) + string("\">"); } } } switch (buffer[i]) { case '<': content += "<"; break; case '>': content += ">"; break; case '&': content += "&"; break; case '\'': content += "'"; break; case '"': content += """; break; case ' ': content += fix_spaces(buffer, &i, buffer_size); break; case '\t': { const int extraSpaces = tabWidth - charLinePos % tabWidth; size_t dummy = 0; const std::string extraSpacesStr(extraSpaces * 2, ' '); // imitates buffer (char + style) content += fix_spaces(extraSpacesStr.c_str(), &dummy, extraSpacesStr.size()); charLinePos += extraSpaces - 1; // account for auto-increment } break; case '\r': --charLinePos; // account for auto-increment break; case '\n': if (current_style != 0) { content += string("</text:span>"); current_style = 0; } content += "</text:h>\n"; content += "<text:h text:style-name=\"Default\">"; if (lineCount != -1) { int difWidth = width - calcWidth(lineno); if (difWidth > 0) { content += string("<text:s text:c=\"") + to_string(difWidth) + string("\"/>"); } content += to_string(lineno); ++lineno; content += "<text:s text:c=\"2\"/>"; } if (i + 2 < buffer_size && buffer[i + 2] == ' ') { i += 2; content += fix_spaces(buffer, &i, buffer_size, true); } charLinePos = -1; // account for auto-increment break; default: content += buffer[i]; break; } } if (current_style != 0) { content += string("</text:span>"); } content += "</text:h>\n"; zout.Write(content.c_str(), content.size()); } zout.Write(ODTContentFileEND, strlen(ODTContentFileEND)); }
void ODTExporter::ODTCreateStylesFile(wxZipOutputStream &zout, const EditorColourSet *color_set, HighlightLanguage lang) { zout.PutNextEntry(_T("styles.xml")); zout.Write(ODTStylesFileBEG, strlen(ODTStylesFileBEG)); string fontName = ODTStylesFileMID(zout); if (lang != HL_NONE) { const int count = const_cast<EditorColourSet *>(color_set)->GetOptionCount(lang); for (int i = 0; i < count; ++i) { OptionColour *optc = const_cast<EditorColourSet *>(color_set)->GetOptionByIndex(lang, i); if (!optc->isStyle) { continue; } ostringstream ostr; ostr << "<style:style style:name=\"style" << optc->value << "\" style:family=\"text\">\n" << " <style:text-properties\n" << " style:font-name=\"" << fontName << "\"\n" << " fo:color=\"#" << hex << setfill('0') << setw(2) << static_cast<unsigned int>(optc->fore.Red()) << setw(2) << static_cast<unsigned int>(optc->fore.Green()) << setw(2) << static_cast<unsigned int>(optc->fore.Blue()) << "\""; if (optc->back.Ok()) { ostr << "\n fo:background-color=\"#" << setw(2) << static_cast<unsigned int>(optc->back.Red()) << setw(2) << static_cast<unsigned int>(optc->back.Green()) << setw(2) << static_cast<unsigned int>(optc->back.Blue()) << "\""; } if (optc->bold) { ostr << "\n fo:font-weight=\"bold\""; } if (optc->italics) { ostr << "\n fo:font-style=\"italic\""; } if (optc->underlined) { ostr << "\n style:text-underline-style=\"solid\"" << "\n style:text-underline-width=\"normal\"" << "\n style:text-underline-color=\"font-color\"" << "\n style:text-underline-mode=\"skip-white-space\""; } ostr << " />\n" << "</style:style>\n"; zout.Write(ostr.str().c_str(), ostr.str().size()); } } zout.Write(ODTStylesFileEND, strlen(ODTStylesFileEND)); }
void ZipTestCase::OnCreateArchive(wxZipOutputStream& zip) { m_comment << wxT("Comment for test ") << m_id; zip.SetComment(m_comment); }