uint32_t FileWriterI::open(string filepath) { GError * err = NULL; // open file GsfOutput * output = gsf_output_stdio_new (filepath.c_str(), &err); if (output == NULL) { ERROR << "ops::msole::FileWriterI::open() : can't open " + filepath + " : " + err->message; g_error_free (err); return RET_ERR; } baseOutfile = gsf_outfile_msole_new (output); g_object_unref (G_OBJECT (output)); if (baseOutfile == NULL) { ERROR << "ops::msole::FileWriterI::open() : can't create OLE file :" + filepath + " : " + err->message; g_error_free (err); return RET_ERR; } // create map for keeping open directories openDirList["/"] = GSF_OUTPUT(baseOutfile); DEBUG << "ops::msole::FileWriterI::open() : " + filepath + " opened"; return RET_OK; }
static int test (char *argv[]) { GsfInfile *infile; GsfOutfile *outfile; GsfOutput *output; GError *err = NULL; fprintf (stderr, "%s\n", argv [1]); infile = gsf_infile_stdio_new (argv[1], &err); if (infile == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s", argv[1], err->message); g_error_free (err); return 1; } output = gsf_output_stdio_new (argv[2], &err); if (output == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s", argv[2], err->message); g_error_free (err); g_object_unref (G_OBJECT (infile)); return 1; } outfile = gsf_outfile_msole_new (output); g_object_unref (G_OBJECT (output)); clone (GSF_INPUT (infile), GSF_OUTPUT (outfile)); return 0; }
/* Decompress infile in dest_dir. */ static void decompress_infile (GsfInfile *infile, gchar *dest_dir) { GError *err = (GError *) NULL; int j = 0; for (j = 0; j < gsf_infile_num_children (infile); j++) { GsfInput *child = gsf_infile_child_by_index (infile, j); char const* filename = gsf_input_name (child); gboolean is_dir = gsf_infile_num_children (GSF_INFILE (child)) >= 0; if (is_dir) { gchar *dir_path = g_build_filename (dest_dir, filename, (gchar *) 0); decompress_infile (GSF_INFILE (child), dir_path); g_free (dir_path); } else { gchar *file_path = g_build_filename (dest_dir, filename, (gchar *) 0); GsfOutput *output = GSF_OUTPUT (gsf_output_stdio_new (file_path, &err)); gsf_input_copy (child, output); gsf_output_close (output); g_object_unref (output); g_free (file_path); } g_object_unref (G_OBJECT (child)); } }
static int test (char *argv[]) { GsfInput *input; GsfOutput *output; GError *err = NULL; int rval = 0; input = gsf_input_stdio_new (argv[1], &err); if (input == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s\n", argv[1], err->message); g_error_free (err); return 1; } output = gsf_output_stdio_new (argv[2], &err); if (output == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s\n", argv[2], err->message); g_error_free (err); g_object_unref (G_OBJECT (input)); return 1; } if (gsf_input_copy (input, output) == FALSE) { rval = 1; err = (GError*) gsf_output_error (output); if (err != NULL) { g_warning ("'%s' error: %s\n", argv[2], err->message); } } g_object_unref (G_OBJECT (input)); gsf_output_close (output); g_object_unref (G_OBJECT (output)); return rval; }
HRESULT STDMETHODCALLTYPE OMGSFIStorage::StgCreateStorageEx( const TCHAR FAR* in_filename, OMFile::OMAccessMode in_accessMode, void **out_storage, ULONG in_sectorSize) { TRACE("OMGSFIStorage::StgCreateStorageEx"); PRECONDITION("Valid access mode", in_accessMode == OMFile::writeOnlyMode); GsfStorage *storage = 0; *out_storage = 0; char storageName[FILENAME_MAX]; #ifndef OM_UNICODE_APIS strncpy (storageName, in_filename, sizeof(storageName) -1); storageName[sizeof(storageName) -1] = '\0'; #else convertWideStringToString (storageName, in_filename, FILENAME_MAX); #endif int status = GSTG_OK; GError *err; GsfOutput *output = GSF_OUTPUT (gsf_output_stdio_new (storageName, &err)); if (output != NULL) { storage = GSF_OUTFILE (gsf_outfile_msole_new_full ( output, in_sectorSize, // sector size - 512 or 4096 bytes 64)); // mini-sector size always 64 bytes g_object_unref (G_OBJECT (output)); } else status = GSTG_ERROR; if (status == GSTG_OK) { OMGSFIStorage *newStorage = new OMGSFIStorage (storage, GSF_WRITE, storageName); *out_storage = newStorage; } return makeStatus(status); }
/* Create the iwb file. */ static void create_iwb (gchar *zip_filename, gchar *working_dir, gchar *images_folder, gchar *content_filename) { GError *err = (GError *) NULL; GsfOutfile *gst_outfile = (GsfOutfile *) NULL; GsfOutput *gst_output = (GsfOutput *) NULL; gsf_init (); gst_output = gsf_output_stdio_new (zip_filename, &err); if (gst_output == NULL) { g_warning ("Error saving iwb: %s\n", err->message); g_error_free (err); return; } gst_outfile = gsf_outfile_zip_new (gst_output, &err); if (gst_outfile == NULL) { g_warning ("Error in gsf_outfile_zip_new: %s\n", err->message); g_error_free (err); return; } g_object_unref (G_OBJECT (gst_output)); add_folder_to_gst_outfile (gst_outfile, working_dir, images_folder); add_file_to_gst_outfile (gst_outfile, working_dir, content_filename); gsf_output_close ((GsfOutput *) gst_outfile); g_object_unref (G_OBJECT (gst_outfile)); gsf_shutdown (); }
virtual UT_Error _loadFile(GsfInput * input) { UT_Error rval = UT_ERROR; UT_String pdf_on_disk, abw_on_disk; // create temporary file names rval = temp_name (pdf_on_disk); if (rval != UT_OK) return rval; rval = temp_name (abw_on_disk); if (rval != UT_OK) return rval; GsfOutput * output = gsf_output_stdio_new (pdf_on_disk.c_str (), NULL); if (output) { // copy input to disk gboolean copy_res = gsf_input_copy (input, output); gsf_output_close (output); g_object_unref (G_OBJECT (output)); if (copy_res) { for (size_t i = 0; i < G_N_ELEMENTS(pdf_conversion_programs); i++) { if ((rval = _runConversion(pdf_on_disk, abw_on_disk, i)) == UT_OK) break; } } } // remove temporary files remove(pdf_on_disk.c_str ()); remove(abw_on_disk.c_str ()); return rval; }
/** * be sure to unref the result if it is non-NULL * * TODO : this is really overkill for now. * only wmf/emf will require regenerating the pixbuf for different scale * factors. And even then we should cache them. */ static GdkPixbuf * soi_get_pixbuf (SheetObjectImage *soi, double scale) { GError *err = NULL; guint8 *data; guint32 data_len; GdkPixbufLoader *loader = NULL; GdkPixbuf *pixbuf = NULL; gboolean ret; g_return_val_if_fail (IS_SHEET_OBJECT_IMAGE (soi), NULL); data = soi->bytes.data; data_len = soi->bytes.len; if (data == NULL || data_len == 0) return pixbuf; if (soi->type != NULL && !strcmp (soi->type, "wmf")) loader = gdk_pixbuf_loader_new_with_type (soi->type, &err); else loader = gdk_pixbuf_loader_new (); if (soi->type == NULL || strlen (soi->type) == 0) g_signal_connect (loader, "size-prepared", G_CALLBACK (soi_info_cb), soi); if (loader) { ret = gdk_pixbuf_loader_write (loader, soi->bytes.data, soi->bytes.len, &err); /* Close in any case. But don't let error during closing * shadow error from loader_write. */ gdk_pixbuf_loader_close (loader, ret ? &err : NULL); if (ret) pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) { g_object_ref (G_OBJECT (pixbuf)); d (printf ("pixbuf width=%d, height=%d\n", gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf))); if (soi->crop_top != 0.0 || soi->crop_bottom != 0.0 || soi->crop_left != 0.0 || soi->crop_right != 0.0) { d (printf ("crop rect top=%g, bottom=%g, " "left=%g, right=%g\n", soi->crop_top, soi->crop_bottom, soi->crop_left, soi->crop_right)); pixbuf = soi_get_cropped_pixbuf (soi, pixbuf); } } g_object_unref (G_OBJECT (loader)); } if (!pixbuf) { if (!soi->dumped) { static int count = 0; char *filename = g_strdup_printf ("unknown%d.%s", count++, soi->type); #if 0 GsfOutput *file = gsf_output_stdio_new (filename, NULL); if (file) { gsf_output_write (GSF_OUTPUT (file), soi->bytes.len, soi->bytes.data); gsf_output_close (GSF_OUTPUT (file)); g_object_unref (file); } #endif g_free (filename); soi->dumped = TRUE; } if (err != NULL) { g_warning ("%s", err->message); g_error_free (err); err = NULL; } else { g_warning ("Unable to display image"); } } return pixbuf; }
/*! * This method copies the selection defined by pDocRange to ODT format * placed in the ByteBuf bufODT */ UT_Error IE_Exp_OpenDocument::copyToBuffer(PD_DocumentRange * pDocRange,UT_ByteBuf * bufODT) { // // First export selected range to a tempory document // PD_Document * outDoc = new PD_Document(); outDoc->createRawDocument(); IE_Exp_DocRangeListener * pRangeListener = new IE_Exp_DocRangeListener(pDocRange,outDoc); UT_DEBUGMSG(("DocumentRange low %d High %d \n",pDocRange->m_pos1,pDocRange->m_pos2)); PL_ListenerCoupleCloser* pCloser = new PL_ListenerCoupleCloser(); pDocRange->m_pDoc->tellListenerSubset(pRangeListener,pDocRange,pCloser); if( pCloser) delete pCloser; // // Grab the RDF triples while we are copying... // if( PD_DocumentRDFHandle outrdf = outDoc->getDocumentRDF() ) { std::set< std::string > xmlids; PD_DocumentRDFHandle inrdf = pDocRange->m_pDoc->getDocumentRDF(); inrdf->addRelevantIDsForRange( xmlids, pDocRange ); if( !xmlids.empty() ) { UT_DEBUGMSG(("MIQ: ODF export creating restricted RDF model xmlids.sz:%ld \n",(long)xmlids.size())); PD_RDFModelHandle subm = inrdf->createRestrictedModelForXMLIDs( xmlids ); PD_DocumentRDFMutationHandle m = outrdf->createMutation(); m->add( subm ); m->commit(); subm->dumpModel("copied rdf triples subm"); outrdf->dumpModel("copied rdf triples result"); } // PD_DocumentRDFMutationHandle m = outrdf->createMutation(); // m->add( PD_URI("http://www.example.com/foo"), // PD_URI("http://www.example.com/bar"), // PD_Literal("copyToBuffer path") ); // m->commit(); } outDoc->finishRawCreation(); // // OK now we have a complete and valid document containing our selected // content. We export this to an in memory GSF buffer // IE_Exp * pNewExp = NULL; char *szTempFileName = NULL; GError *err = NULL; g_file_open_tmp ("XXXXXX", &szTempFileName, &err); GsfOutput * outBuf = gsf_output_stdio_new (szTempFileName,&err); IEFileType ftODT = IE_Exp::fileTypeForMimetype("application/vnd.oasis.opendocument.text"); UT_Error aerr = IE_Exp::constructExporter(outDoc,outBuf, ftODT,&pNewExp); if(pNewExp == NULL) { return aerr; } aerr = pNewExp->writeFile(szTempFileName); if(aerr != UT_OK) { delete pNewExp; delete pRangeListener; UNREFP( outDoc); g_remove(szTempFileName); g_free (szTempFileName); return aerr; } // // File is closed at the end of the export. Open it again. // GsfInput * fData = gsf_input_stdio_new(szTempFileName,&err); UT_DebugOnly<UT_sint32> siz = gsf_input_size(fData); const UT_Byte * pData = gsf_input_read(fData,gsf_input_size(fData),NULL); UT_DEBUGMSG(("Writing %d bytes to clipboard \n", (UT_sint32)siz)); bufODT->append( pData, gsf_input_size(fData)); delete pNewExp; delete pRangeListener; UNREFP( outDoc); g_remove(szTempFileName); g_free (szTempFileName); return aerr; }