/* Return a GsfOutput for writing to a path. Paths are object name first, then * path components with least-specific first, NULL-terminated. For example: * * GsfOutput *obj = vips_gsf_path( tree, "fred.jpg", "a", "b", NULL ); * * Returns an obj you can use to write to a/b/fred.jpg. * * You must write, close and unref obj. */ static GsfOutput * vips_gsf_path( VipsGsfDirectory *tree, const char *name, ... ) { va_list ap; VipsGsfDirectory *dir; VipsGsfDirectory *child; char *dir_name; GsfOutput *obj; dir = tree; va_start( ap, name ); while( (dir_name = va_arg( ap, char * )) ) if( (child = vips_gsf_child_by_name( dir, dir_name )) ) dir = child; else dir = vips_gsf_dir_new( dir, dir_name ); va_end( ap ); if( dir->no_compression ) obj = gsf_outfile_new_child_full( (GsfOutfile *) dir->out, name, FALSE, "compression-level", 0, NULL ); else obj = gsf_outfile_new_child( (GsfOutfile *) dir->out, name, FALSE ); return( obj ); }
/* Make a new directory. */ static VipsGsfDirectory * vips_gsf_dir_new( VipsGsfDirectory *parent, const char *name ) { VipsGsfDirectory *dir = g_new( VipsGsfDirectory, 1 ); g_assert( !vips_gsf_child_by_name( parent, name ) ); dir->parent = parent; dir->name = g_strdup( name ); dir->children = NULL; dir->no_compression = parent->no_compression; dir->container = NULL; if( dir->no_compression ) dir->out = gsf_outfile_new_child_full( (GsfOutfile *) parent->out, name, TRUE, "compression-level", 0, NULL ); else dir->out = gsf_outfile_new_child( (GsfOutfile *) parent->out, name, TRUE ); parent->children = g_slist_prepend( parent->children, dir ); return( dir ); }
static char const * xlsx_write_pivot_cache_definition (XLSXWriteState *state, GsfOutfile *wb_part, GODataCache const *cache, unsigned int cache_def_num) { GsfXMLOut *xml; int i, n; char const *record_id; char *name = g_strdup_printf ("pivotCacheDefinition%u.xml", cache_def_num); GsfOutput *cache_def_part = gsf_outfile_new_child_full (state->pivotCache.dir, name, FALSE, "content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml", NULL); char const *cache_def_id = gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (cache_def_part), GSF_OUTFILE_OPEN_PKG (wb_part), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"); record_id = xlsx_write_pivot_cache_records (state, cache, cache_def_part, cache_def_num); xml = gsf_xml_out_new (cache_def_part); gsf_xml_out_start_element (xml, "pivotCacheDefinition"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss); gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel); gsf_xml_out_add_cstr (xml, "r:id", record_id); if (cache->refreshed_by) gsf_xml_out_add_cstr (xml, "refreshedBy", cache->refreshed_by); if (cache->refreshed_on) { if (state->version == ECMA_376_2006) gsf_xml_out_add_float (xml, "refreshedDate", go_val_as_float (cache->refreshed_on), -1); else { GOFormat const *format = go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss"); gchar *date = format_value (format, cache->refreshed_on, NULL, -1, NULL); gsf_xml_out_add_cstr_unchecked (xml, "refreshedDateIso", date); g_free (date); go_format_unref (format); } } gsf_xml_out_add_int (xml, "createdVersion", cache->XL_created_ver); gsf_xml_out_add_int (xml, "refreshedVersion", cache->XL_refresh_ver); gsf_xml_out_add_uint (xml, "recordCount", go_data_cache_num_items (cache)); xlsx_add_bool (xml, "upgradeOnRefresh", cache->refresh_upgrades); xlsx_write_pivot_cache_source (state, xml, cache); gsf_xml_out_start_element (xml, "cacheFields"); n = go_data_cache_num_fields (cache); gsf_xml_out_add_uint (xml, "count", n); for (i = 0 ; i < n ; i++) xlsx_write_pivot_cache_field (state, xml, go_data_cache_get_field (cache, i)); gsf_xml_out_end_element (xml); /* </cacheFields> */ gsf_xml_out_end_element (xml); /* </pivotCacheDefinition> */ g_object_unref (xml); gsf_output_close (cache_def_part); g_object_unref (cache_def_part); g_free (name); return cache_def_id; }
static char const * xlsx_write_pivot_cache_records (XLSXWriteState *state, GODataCache const *cache, GsfOutput *cache_def_part, unsigned int cache_records_num) { unsigned int i, j; GsfXMLOut *xml; char *name = g_strdup_printf ("pivotCacheRecords%u.xml", cache_records_num); GsfOutput *record_part = gsf_outfile_new_child_full (state->pivotCache.dir, name, FALSE, "content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml", NULL); char const *record_id = gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (record_part), GSF_OUTFILE_OPEN_PKG (cache_def_part), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords"); xml = gsf_xml_out_new (record_part); gsf_xml_out_start_element (xml, "pivotCacheRecords"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss); gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel); gsf_xml_out_add_int (xml, "count", go_data_cache_num_items (cache)); for (j = 0 ; j < go_data_cache_num_items (cache); j++) { gsf_xml_out_start_element (xml, "r"); for (i = 0 ; i < go_data_cache_num_fields (cache); i++) { GODataCacheField *field = go_data_cache_get_field (cache, i); switch (go_data_cache_field_ref_type (field)) { case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I8 : case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I16 : /* fallthrough */ case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I32 : /* fallthrough */ gsf_xml_out_start_element (xml, "x"); gsf_xml_out_add_int (xml, "v", go_data_cache_get_index (cache, field, j)); gsf_xml_out_end_element (xml); break; case GO_DATA_CACHE_FIELD_TYPE_INLINE : xlsx_write_pivot_val (state, xml, go_data_cache_field_get_val (field, j)); break; case GO_DATA_CACHE_FIELD_TYPE_NONE : continue; } } gsf_xml_out_end_element (xml); /* </r> */ } gsf_xml_out_end_element (xml); /* </pivotCacheRecords> */ g_object_unref (xml); gsf_output_close (record_part); g_object_unref (record_part); g_free (name); return record_id; }
/** * gsf_outfile_open_pkg_add_rel: * @dir: #GsfOutfile * @name: target name * @content_type: non-%NULL content type * @parent: #GsfOutfile * @type: target type * * A convenience wrapper to create a child in @dir of @content_type then create * a @type relation to @parent * * Returns: (transfer full): the new part. **/ GsfOutput * gsf_outfile_open_pkg_add_rel (GsfOutfile *dir, char const *name, char const *content_type, GsfOutfile *parent, char const *type) { GsfOutput *part = gsf_outfile_new_child_full (dir, name, FALSE, "content-type", content_type, NULL); (void) gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (part), GSF_OUTFILE_OPEN_PKG (parent), type); return part; }
/** * This writes out our AbiWord file as an OpenOffice * compound document */ UT_Error IE_Exp_OpenDocument::_writeDocument(void) { ODe_DocumentData docData(getDoc()); ODe_AuxiliaryData auxData; ODe_AbiDocListener* pAbiDocListener = NULL; ODe_AbiDocListenerImpl* pAbiDocListenerImpl = NULL; UT_return_val_if_fail (getFp(), UT_ERROR); PD_DocumentRDFHandle rdf = getDoc()->getDocumentRDF(); auxData.m_additionalRDF = rdf->createScratchModel(); const std::string & prop = getProperty ("uncompressed"); if (!prop.empty() && UT_parseBool (prop.c_str (), false)) { m_odt = GSF_OUTFILE(g_object_ref(G_OBJECT(getFp()))); } else { GError* error = NULL; m_odt = GSF_OUTFILE (gsf_outfile_zip_new (getFp(), &error)); if (error) { UT_DEBUGMSG(("Error writing odt file: %s\n", error->message)); UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); } } UT_return_val_if_fail(m_odt, UT_ERROR); // Needed to ensure that all *printf writes numbers correctly, // like "45.56mm" instead of "45,56mm". UT_LocaleTransactor numericLocale (LC_NUMERIC, "C"); { GsfOutput * mimetype = gsf_outfile_new_child_full (m_odt, "mimetype", FALSE, "compression-level", 0, (void*)0); if (!mimetype) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } ODe_gsf_output_write(mimetype, 39 /*39 == strlen("application/vnd.oasis.opendocument.text")*/, (const guint8 *)"application/vnd.oasis.opendocument.text"); ODe_gsf_output_close(mimetype); } if (!ODe_MetaDataWriter::writeMetaData(getDoc(), m_odt)) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } if (!ODe_SettingsWriter::writeSettings(getDoc(), m_odt)) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } if (!ODe_PicturesWriter::writePictures(getDoc(), m_odt)) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } if (!ODe_ManifestWriter::writeManifest(getDoc(), m_odt)) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } // Gather all paragraph style names used by heading paragraphs // (ie. all paragraph styles that are used to build up TOCs). pAbiDocListenerImpl = new ODe_HeadingSearcher_Listener(docData.m_styles, auxData); pAbiDocListener = new ODe_AbiDocListener(getDoc(), pAbiDocListenerImpl, false); if (!getDoc()->tellListener(static_cast<PL_Listener *>(pAbiDocListener))) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } pAbiDocListener->finished(); DELETEP(pAbiDocListener); DELETEP(pAbiDocListenerImpl); // Now that we have all paragraph styles that build up the TOCs in the // document (if any), we can build up the TOC bodies. We do this because // OpenOffice.org requires the TOC bodies to be present and filled // when initially opening the document. Without it, it will show // an empty TOC until the user regenerates it, which is not that pretty. // Annoyingly we have to build up the TOC ourselves during export, as // it doesn't exist within AbiWord's PieceTable. Until that changes, this // is the best we can do. if (auxData.m_pTOCContents) { pAbiDocListenerImpl = new ODe_TOC_Listener(auxData); pAbiDocListener = new ODe_AbiDocListener(getDoc(), pAbiDocListenerImpl, false); if (!getDoc()->tellListener(static_cast<PL_Listener *>(pAbiDocListener))) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } pAbiDocListener->finished(); DELETEP(pAbiDocListener); DELETEP(pAbiDocListenerImpl); } // Gather document content and styles if (!docData.doPreListeningWork()) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } pAbiDocListenerImpl = new ODe_Main_Listener(docData, auxData); pAbiDocListener = new ODe_AbiDocListener(getDoc(), pAbiDocListenerImpl, false); if (!getDoc()->tellListener(static_cast<PL_Listener *>(pAbiDocListener))) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } pAbiDocListener->finished(); DELETEP(pAbiDocListener); DELETEP(pAbiDocListenerImpl); if (!docData.doPostListeningWork()) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } // Write RDF. if (!ODe_RDFWriter::writeRDF(getDoc(), m_odt, auxData.m_additionalRDF )) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } // Write content and styles if (!docData.writeStylesXML(m_odt)) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } if (!docData.writeContentXML(m_odt)) { ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_ERROR; } ODe_gsf_output_close(GSF_OUTPUT(m_odt)); return UT_OK; }
UT_Error IE_Exp_EPUB::_writeDocument() { UT_Error errOptions = doOptions(); if (errOptions == UT_SAVE_CANCELLED) //see Bug 10840 { return UT_SAVE_CANCELLED; } else if (errOptions != UT_OK) { return UT_ERROR; } m_root = gsf_outfile_zip_new(getFp(), NULL); if (m_root == NULL) { UT_DEBUGMSG(("ZIP output is null\n")); return UT_ERROR; } m_oebps = gsf_outfile_new_child(m_root, "OEBPS", TRUE); if (m_oebps == NULL) { UT_DEBUGMSG(("Can`t create oebps output object\n")); return UT_ERROR; } // mimetype must a first file in archive GsfOutput *mimetype = gsf_outfile_new_child_full(m_root, "mimetype", FALSE, "compression-level", 0, NULL); gsf_output_write(mimetype, strlen(EPUB_MIMETYPE), (const guint8*) EPUB_MIMETYPE); gsf_output_close(mimetype); // We need to create temporary directory to which // HTML plugin will export our document m_baseTempDir = UT_go_filename_to_uri(g_get_tmp_dir()); m_baseTempDir += G_DIR_SEPARATOR_S; // To generate unique directory name we`ll use document UUID m_baseTempDir += getDoc()->getDocUUIDString(); // We should delete any previous temporary data for this document to prevent // odd files appearing in the container UT_go_file_remove(m_baseTempDir.c_str(), NULL); UT_go_directory_create(m_baseTempDir.c_str(), NULL); if (writeContainer() != UT_OK) { UT_DEBUGMSG(("Failed to write container\n")); return UT_ERROR; } if (writeStructure() != UT_OK) { UT_DEBUGMSG(("Failed to write document structure\n")); return UT_ERROR; } if (writeNavigation() != UT_OK) { UT_DEBUGMSG(("Failed to write navigation\n")); return UT_ERROR; } if (package() != UT_OK) { UT_DEBUGMSG(("Failed to package document\n")); return UT_ERROR; } gsf_output_close(m_oebps); gsf_output_close(GSF_OUTPUT(m_root)); // After doing all job we should delete temporary files UT_go_file_remove(m_baseTempDir.c_str(), NULL); return UT_OK; }
static void clone_ (GsfInfile *in, GsfOutfile *out) { GsfInput *input = GSF_INPUT (in); GsfOutput *output = GSF_OUTPUT (out); if (gsf_input_size (input) > 0) { size_t len; while ((len = gsf_input_remaining (input)) > 0) { guint8 const *data; /* copy in odd sized chunks to exercise system */ if (len > 314) len = 314; if (NULL == (data = gsf_input_read (input, len, NULL))) { g_warning ("error reading ?"); break; } if (!gsf_output_write (output, len, data)) { g_warning ("error writing ?"); break; } } } else { int i, n = gsf_infile_num_children (in); for (i = 0 ; i < n; i++) { int level; gboolean is_dir; char const *name = gsf_infile_name_by_index (in, i); char *display_name = name ? g_filename_display_name (name) : NULL; input = gsf_infile_child_by_index (in, i); if (NULL == input) { g_print ("Error opening '%s, index = %d\n", display_name ? display_name : "?", i); g_free (display_name); continue; } is_dir = gsf_infile_num_children (GSF_INFILE (input)) >= 0; g_object_get (G_OBJECT (input), "compression-level", &level, NULL); g_print ("%s: size=%ld, level=%d, %s\n", display_name ? display_name : "?", (long)gsf_input_size (input), level, is_dir ? "directory" : "file"); g_free (display_name); output = gsf_outfile_new_child_full (out, name, is_dir, "compression-level", level, NULL); clone_ (GSF_INFILE (input), GSF_OUTFILE (output)); } } gsf_output_close (GSF_OUTPUT (out)); g_object_unref (G_OBJECT (out)); g_object_unref (G_OBJECT (in)); }