static void _write_png( png_structp png_ptr, png_bytep data, png_size_t length ) { UT_ByteBuf* bb = static_cast<UT_ByteBuf*>(png_get_io_ptr(png_ptr)); bb->append(data, length); }
/*! Write data to the PNG stream * * This is a callback function for the PNG library. It is called when * some data needs to writting to the PNG file. We have implemented it as * writing to a ByteBuf. */ static void write_png_data(png_structp png_ptr, png_bytep data, png_size_t length) { UT_ByteBuf* bb = (UT_ByteBuf*) (png_get_io_ptr(png_ptr)); UT_DEBUGMSG(("PSION: write_png_data: %d bytes\n",length)); bb->append(data,length); }
/** * Code from Dom Lachowicz and/or Robert Staudinger. */ UT_Error ODi_Abi_Data::_loadStream (GsfInfile* oo, const char* stream, UT_ByteBuf& buf ) { guint8 const *data = NULL; size_t len = 0; static const size_t BUF_SZ = 4096; buf.truncate (0); GsfInput * input = gsf_infile_child_by_name(oo, stream); if (!input) return UT_ERROR; if (gsf_input_size (input) > 0) { while ((len = gsf_input_remaining (input)) > 0) { len = UT_MIN (len, BUF_SZ); if (NULL == (data = gsf_input_read (input, len, NULL))) { g_object_unref (G_OBJECT (input)); return UT_ERROR; } buf.append ((const UT_Byte *)data, len); } } g_object_unref (G_OBJECT (input)); return UT_OK; }
UT_Error OXML_Element_Math::addToPT(PD_Document * pDocument) { UT_uint32 id; id = pDocument->getUID(UT_UniqueId::Math); std::string mID = UT_std_string_sprintf("MathLatex%d", id); std::string lID = UT_std_string_sprintf("LatexMath%d", id); UT_ByteBuf mathBuf; UT_ByteBuf latexBuf; mathBuf.ins(0,reinterpret_cast<const UT_Byte *>(m_MathML.c_str()),static_cast<UT_uint32>(m_MathML.length())); UT_UTF8String sMathml; // TO DO : use std::string after enabling it in ie_math_convert UT_UTF8String sLatex,sitex; sMathml.assign(m_MathML.c_str()); pDocument->createDataItem(mID.c_str(),false,&mathBuf, "", NULL); if(convertMathMLtoLaTeX(sMathml, sLatex) && convertLaTeXtoEqn(sLatex,sitex)) { // Conversion of MathML to LaTeX and the Equation Form suceeds latexBuf.ins(0,reinterpret_cast<const UT_Byte *>(sitex.utf8_str()),static_cast<UT_uint32>(sitex.size())); pDocument->createDataItem(lID.c_str(), false, &latexBuf, "", NULL); } const gchar *atts[5] = { NULL, NULL, NULL, NULL, NULL }; atts[0] = PT_IMAGE_DATAID; atts[1] = static_cast<const gchar *>(mID.c_str()); atts[2] = static_cast<const gchar *>("latexid"); atts[3] = static_cast<const gchar *>(lID.c_str()); if(!pDocument->appendObject(PTO_Math, atts)) return UT_ERROR; return UT_OK; }
static gboolean convCallback(const gchar *buf, gsize count, GError ** /*error*/, gpointer byteBuf) { UT_ByteBuf * pBB = reinterpret_cast<UT_ByteBuf *>(byteBuf); pBB->append(reinterpret_cast<const UT_Byte *>(buf),count); return TRUE; }
void UT_UTF8String::appendBuf (const UT_ByteBuf & buf, UT_UCS4_mbtowc & converter) { UT_uint32 i; UT_UCS4Char wc; const UT_Byte *ptr = buf.getPointer(0); for (i = 0; i < buf.getLength(); i++) { if (converter.mbtowc(wc, static_cast<char>(ptr[i]))) pimpl->appendUCS4(&wc, 1); } }
bool GR_VectorImage::convertToBuffer(UT_ByteBuf** ppBB) const { UT_ByteBuf* pBB = new UT_ByteBuf; bool bCopied = pBB->append(m_pBB_Image->getPointer(0), m_pBB_Image->getLength()); if (!bCopied) DELETEP(pBB); *ppBB = pBB; return bCopied; }
bool AP_Win32App::_cacheClipboardDoc(PD_DocumentRange *pDocRange) { UT_return_val_if_fail(m_pClipboard && pDocRange, false); UT_ByteBuf buf; UT_Error status;; UT_Byte b = 0; IE_Exp_RTF * pExpRtf = new IE_Exp_RTF(pDocRange->m_pDoc); if (pExpRtf) { status = pExpRtf->copyToBuffer(pDocRange,&buf); if(status != UT_OK) return false; buf.append(&b,1); // NULL terminate the string DELETEP(pExpRtf); } else { return false; } // now create a subdocument ... PD_Document * pDoc = new PD_Document(); if(!pDoc) return false; pDoc->newDocument(); PD_DocumentRange DocRange(pDoc, 2, 2); IE_Imp * pImp = 0; IE_Imp::constructImporter(pDoc, IE_Imp::fileTypeForSuffix(".rtf"),&pImp,0); if(pImp) { pImp->pasteFromBuffer(&DocRange,buf.getPointer(0),buf.getLength(),NULL); delete pImp; } else { return false; } m_pClipboard->setClipboardDoc(pDoc); return true; }
/*! Output text buffer to stream \param data Buffer to output \param length Size of buffer */ void Text_Listener::_outputData(const UT_UCSChar * data, UT_uint32 length) { UT_ByteBuf bBuf; const UT_UCSChar * pData; int mbLen; char pC[MY_MB_LEN_MAX]; if (m_bFirstWrite) { if (m_szEncoding) m_wctomb.setOutCharset(m_szEncoding); _genLineBreak(); if (m_bUseBOM) { _genBOM(); m_pie->write(static_cast<const char *>(m_mbBOM),m_iBOMLen); } m_bFirstWrite = false; } for (pData=data; (pData<data+length); ++pData) { // We let any UCS_LF's (forced line breaks) go out as is. if (*pData==UCS_LF) bBuf.append(reinterpret_cast<UT_Byte *>(m_mbLineBreak),m_iLineBreakLen); else { if (!_wctomb(pC,mbLen,*pData)) { UT_ASSERT_HARMLESS(!m_bIs16Bit); mbLen=1; pC[0]='?'; m_wctomb.initialize(); } UT_ASSERT_HARMLESS(mbLen>=1); bBuf.append(reinterpret_cast<const UT_Byte *>(pC),mbLen); } } m_pie->write(reinterpret_cast<const char *>(bBuf.getPointer(0)),bBuf.getLength()); }
// // Creates a BITMAP file from a handle // static void CreateBMPFile(HWND hwnd, UT_ByteBuf & pBB, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC) { BITMAPFILEHEADER hdr; // bitmap file-header PBITMAPINFOHEADER pbih; // bitmap info-header LPBYTE lpBits; // memory pointer if (!hBMP) return; pbih = (PBITMAPINFOHEADER) pbi; lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage); if (!lpBits) return; // Retrieve the color table (RGBQUAD array) and the bits // (array of palette indices) from the DIB. if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, DIB_RGB_COLORS)) return; hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M" // Compute the size of the entire file. hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; // Compute the offset to the array of color indices. hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD); pBB.truncate (0); // Copy the BITMAPFILEHEADER into the .BMP file. pBB.append ((const UT_Byte *)&hdr, sizeof(BITMAPFILEHEADER)); pBB.append ((const UT_Byte *)pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD)); // Copy the array of color indices into the .BMP file. pBB.append ((const UT_Byte *)lpBits, (int) pbih->biSizeImage); GlobalFree((HGLOBAL)lpBits); }
/** * Parses the image stream and returns the image data */ UT_ByteBuf* OXMLi_PackageManager::parseImageStream(const char * id) { GsfInput * parent = _getDocumentStream(); GsfInput * stream = getChildById(parent, id); //First, we check if this stream has already been parsed before std::string part_name = gsf_input_name(stream); //TODO: determine if part names are truly unique std::map<std::string, bool>::iterator it; it = m_parsedParts.find(part_name); if (it != m_parsedParts.end() && it->second) { //this stream has already been parsed successfully return NULL; } UT_ByteBuf* buffer = new UT_ByteBuf(); buffer->insertFromInput(0, stream); g_object_unref (G_OBJECT (stream)); m_parsedParts[part_name] = true; return buffer; }
gint XAP_UnixDialog_FileOpenSaveAs::previewPicture (void) { UT_ASSERT (m_FC && m_preview); UT_ASSERT(XAP_App::getApp()); const XAP_StringSet * pSS = m_pApp->getStringSet(); UT_return_val_if_fail( pSS, 0 ); // attach and clear the area immediately GR_UnixCairoAllocInfo ai(m_preview); GR_CairoGraphics* pGr = (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai); const gchar * file_name = gtk_file_chooser_get_uri (m_FC); GR_Font * fnt = pGr->findFont("Times New Roman", "normal", "", "normal", "", "12pt", pSS->getLanguageName()); pGr->setFont(fnt); UT_UTF8String str; pSS->getValueUTF8(XAP_STRING_ID_DLG_IP_No_Picture_Label, str); int answer = 0; FG_Graphic * pGraphic = 0; GR_Image *pImage = NULL; double scale_factor = 0.0; UT_sint32 scaled_width,scaled_height; UT_sint32 iImageWidth,iImageHeight; { GR_Painter painter(pGr); painter.clearArea(0, 0, pGr->tlu(m_preview->allocation.width), pGr->tlu(m_preview->allocation.height)); if (!file_name) { painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2); goto Cleanup; } // are we dealing with a file or directory here? struct stat st; if (!stat (file_name, &st)) { if (!S_ISREG(st.st_mode)) { painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2); goto Cleanup; } } GsfInput * input = NULL; UT_DEBUGMSG(("file_name %s \n",file_name)); input = UT_go_file_open (file_name, NULL); if (!input) goto Cleanup; char Buf[4097] = ""; // 4096+nul ought to be enough UT_uint32 iNumbytes = UT_MIN(4096, gsf_input_size(input)); gsf_input_read(input, iNumbytes, (guint8 *)(Buf)); Buf[iNumbytes] = '\0'; IEGraphicFileType ief = IE_ImpGraphic::fileTypeForContents(Buf,4096); if((ief == IEGFT_Unknown) || (ief == IEGFT_Bogus)) { painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2); g_object_unref (G_OBJECT (input)); goto Cleanup; } g_object_unref (G_OBJECT (input)); input = UT_go_file_open (file_name, NULL); size_t num_bytes = gsf_input_size(input); UT_Byte * bytes = (UT_Byte *) gsf_input_read(input, num_bytes,NULL ); if(bytes == NULL) { painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2); g_object_unref (G_OBJECT (input)); goto Cleanup; } UT_ByteBuf * pBB = new UT_ByteBuf(); pBB->append(bytes,num_bytes); g_object_unref (G_OBJECT (input)); // // OK load the data into a GdkPixbuf // bool bLoadFailed = false; // GdkPixbuf * pixbuf = pixbufForByteBuf ( pBB); delete pBB; if(pixbuf == NULL) { // // Try a fallback loader here. // painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2); bLoadFailed = true; goto Cleanup; } pImage = new GR_UnixImage(NULL,pixbuf); iImageWidth = gdk_pixbuf_get_width (pixbuf); iImageHeight = gdk_pixbuf_get_height (pixbuf); if (m_preview->allocation.width >= iImageWidth && m_preview->allocation.height >= iImageHeight) scale_factor = 1.0; else scale_factor = MIN( static_cast<double>(m_preview->allocation.width)/iImageWidth, static_cast<double>(m_preview->allocation.height)/iImageHeight); scaled_width = static_cast<int>(scale_factor * iImageWidth); scaled_height = static_cast<int>(scale_factor * iImageHeight); static_cast<GR_UnixImage *>(pImage)->scale(scaled_width,scaled_height); painter.drawImage(pImage, pGr->tlu(static_cast<int>((m_preview->allocation.width - scaled_width ) / 2)), pGr->tlu(static_cast<int>((m_preview->allocation.height - scaled_height) / 2))); answer = 1; } Cleanup: FREEP(file_name); DELETEP(pImage); DELETEP(pGr); DELETEP(pGraphic); return answer; }
/*! Load the picture data \param format the Picture Format. \param image_name the name of the image. Must be unique. \param imgProps the RTF properties for the image. \return true if success, otherwise false. \desc Load the picture data from the flow. Will move the file position and assume proper RTF file structure. It will take care of inserting the picture into the document. \todo TODO: We assume the data comes in hex. Check this assumption as we might have to handle binary data as well \see IE_Imp_RTF::HandlePicture */ bool IE_Imp_RTF::LoadPictData(PictFormat format, const char * image_name, struct RTFProps_ImageProps & imgProps, bool isBinary, long binaryLen) { // first, we load the actual data into a buffer bool ok; bool retval = true; const UT_uint16 chars_per_byte = 2; const UT_uint16 BITS_PER_BYTE = 8; const UT_uint16 bits_per_char = BITS_PER_BYTE / chars_per_byte; UT_ByteBuf pictData; UT_uint16 chLeft = chars_per_byte; UT_Byte pic_byte = 0; FG_Graphic* pFG = NULL; UT_Error error = UT_OK; unsigned char ch; if (!isBinary) { if (!ReadCharFromFile(&ch)) { retval = false; goto cleanup; } while (ch != '}') { int digit; if (!hexVal(ch, digit)) { retval = false; goto cleanup; } pic_byte = (pic_byte << bits_per_char) + digit; // if we have a complete byte, we put it in the buffer if (--chLeft == 0) { pictData.append(&pic_byte, 1); chLeft = chars_per_byte; pic_byte = 0; } if (!ReadCharFromFile(&ch)) { retval = false; goto cleanup; } } } else { UT_ASSERT_HARMLESS(binaryLen); UT_DEBUGMSG(("Loading binary data image of %ld bytes\n", binaryLen)); for (long i = 0; i < binaryLen; i++) { if (!ReadCharFromFileWithCRLF(&ch)) { retval = false; goto cleanup; } pictData.append(&ch, 1); } } // We let the caller handle this SkipBackChar(ch); error = IE_ImpGraphic::loadGraphic(pictData, iegftForRTF(format), &pFG); if ((error == UT_OK) && pFG) { imgProps.width = static_cast<UT_uint32>(pFG->getWidth ()); imgProps.height = static_cast<UT_uint32>(pFG->getHeight ()); // Not sure whether this is the right way, but first, we should // insert any pending chars if (!FlushStoredChars(true)) { UT_DEBUGMSG(("Error flushing stored chars just before inserting a picture\n")); DELETEP(pFG); return false; } ok = InsertImage (pFG, image_name, imgProps); DELETEP(pFG); if (!ok) { return false; } } else { // if we're not inserting a graphic, we should destroy the buffer UT_DEBUGMSG (("no translator found: %d\n", error)); } cleanup: return retval; }
void FV_Selection::pasteRowOrCol(void) { pf_Frag_Strux* cellSDH, *tableSDH; PT_DocPosition pos = m_pView->getPoint(); if(m_iPrevSelectionMode == FV_SelectionMode_TableColumn) { // // GLOB stuff together so it undo's in one go. // getDoc()->beginUserAtomicGlob(); // // Insert a column after the current column // m_pView->cmdInsertCol(m_pView->getPoint(),false); // // Now do all the encapsulating stuff for piecetable manipulations. // // Signal PieceTable Change m_pView->_saveAndNotifyPieceTableChange(); // Turn off list updates getDoc()->disableListUpdates(); if (!m_pView->isSelectionEmpty()) { m_pView->_clearSelection(); } getDoc()->setDontImmediatelyLayout(true); pos = m_pView->getPoint(); PT_DocPosition posTable,posCell; UT_sint32 iLeft,iRight,iTop,iBot; posCell = 0; m_pView->getCellParams(pos, &iLeft, &iRight,&iTop,&iBot); bool bRes = getDoc()->getStruxOfTypeFromPosition(pos,PTX_SectionCell,&cellSDH); bRes = getDoc()->getStruxOfTypeFromPosition(pos,PTX_SectionTable,&tableSDH); UT_return_if_fail(bRes); posTable = getDoc()->getStruxPosition(tableSDH) + 1; UT_sint32 numRows = 0; UT_sint32 numCols = 0; UT_sint32 i = 0; getDoc()-> getRowsColsFromTableSDH(tableSDH, m_pView->isShowRevisions(), m_pView->getRevisionLevel(), &numRows, &numCols); PD_DocumentRange DocRange(getDoc(),posCell,posCell); for(i=0; i<getNumSelections(); i++) { posCell = m_pView->findCellPosAt(posTable,i,iLeft)+2; m_pView->setPoint(posCell); PD_DocumentRange * pR = getNthSelection(i); if(pR->m_pos1 == pR->m_pos2) { // // Dont paste empty cells // continue; } UT_ByteBuf * pBuf = m_vecSelRTFBuffers.getNthItem(i); const unsigned char * pData = pBuf->getPointer(0); UT_uint32 iLen = pBuf->getLength(); DocRange.m_pos1 = posCell; DocRange.m_pos2 = posCell; IE_Imp_RTF * pImpRTF = new IE_Imp_RTF(getDoc()); pImpRTF->pasteFromBuffer(&DocRange,pData,iLen); DELETEP(pImpRTF); fl_SectionLayout * pSL = m_pView->getCurrentBlock()->getSectionLayout(); pSL->checkAndAdjustCellSize(); } getDoc()->endUserAtomicGlob(); getDoc()->setDontImmediatelyLayout(false); m_pView->_generalUpdate(); // restore updates and clean up dirty lists getDoc()->enableListUpdates(); getDoc()->updateDirtyLists(); // Signal PieceTable Changes have finished m_pView->_restorePieceTableState(); // Put the insertion point in a legal position // m_pView->notifyListeners(AV_CHG_MOTION); m_pView->_fixInsertionPointCoords(); m_pView->_ensureInsertionPointOnScreen(); } else { } }
/*! copy the given subset of the given document to the system clipboard in a variety of formats. to minimize the effects of race-conditions, we create all of the buffers we need and then post them to the server (well sorta) all at one time. \param pDocRange a range of the document to be copied */ void AP_UnixApp::copyToClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard) { UT_ByteBuf bufRTF; UT_ByteBuf bufHTML4; UT_ByteBuf bufXHTML; UT_ByteBuf bufTEXT; UT_ByteBuf bufODT; // create RTF buffer to put on the clipboard IE_Exp_RTF * pExpRtf = new IE_Exp_RTF(pDocRange->m_pDoc); if (pExpRtf) { pExpRtf->copyToBuffer(pDocRange,&bufRTF); DELETEP(pExpRtf); } // create XHTML buffer to put on the clipboard IE_Exp_HTML * pExpHtml = new IE_Exp_HTML(pDocRange->m_pDoc); if (pExpHtml) { pExpHtml->set_HTML4 (false); pExpHtml->copyToBuffer (pDocRange, &bufXHTML); DELETEP(pExpHtml); } // create HTML4 buffer to put on the clipboard pExpHtml = new IE_Exp_HTML(pDocRange->m_pDoc); if (pExpHtml) { pExpHtml->set_HTML4 (true); pExpHtml->copyToBuffer(pDocRange, &bufHTML4); DELETEP(pExpHtml); } // Look to see if the ODT plugin is loaded IEFileType ftODT = IE_Exp::fileTypeForMimetype("application/vnd.oasis.opendocument.text"); bool bExpODT = false; if(ftODT != IEFT_Unknown) { // ODT plugin is present construct an exporter // IE_Exp * pODT = NULL; IEFileType genIEFT = IEFT_Unknown; GsfOutput * outBuf = gsf_output_memory_new(); UT_Error err = IE_Exp::constructExporter(pDocRange->m_pDoc,outBuf, ftODT,&pODT,& genIEFT); if(pODT && (genIEFT == ftODT)) { // // Copy to the buffer // err = pODT->copyToBuffer(pDocRange, &bufODT); bExpODT = (err == UT_OK); UT_DEBUGMSG(("Putting ODF on the clipboard...e:%d bExpODT:%d\n", err, bExpODT )); #ifdef DUMP_CLIPBOARD_COPY std::ofstream oss("/tmp/abiword-clipboard-copy.odt"); oss.write( (const char*)bufODT.getPointer (0), bufODT.getLength () ); oss.close(); #endif } } // create UTF-8 text buffer to put on the clipboard IE_Exp_Text * pExpText = new IE_Exp_Text(pDocRange->m_pDoc, "UTF-8"); if (pExpText) { pExpText->copyToBuffer(pDocRange,&bufTEXT); DELETEP(pExpText); } // NOTE: this clearData() will actually release our ownership of // NOTE: the CLIPBOARD property in addition to clearing any // NOTE: stored buffers. I'm omitting it since we seem to get // NOTE: clr callback after we have done some other processing // NOTE: (like adding the new stuff). // m_pClipboard->clearData(true,false); // TODO: handle CLIPBOARD vs PRIMARY XAP_UnixClipboard::T_AllowGet target = ((bUseClipboard) ? XAP_UnixClipboard::TAG_ClipboardOnly : XAP_UnixClipboard::TAG_PrimaryOnly); if (bufRTF.getLength () > 0) m_pClipboard->addRichTextData (target, bufRTF.getPointer (0), bufRTF.getLength ()); if (bufXHTML.getLength () > 0) m_pClipboard->addHtmlData (target, bufXHTML.getPointer (0), bufXHTML.getLength (), true); if (bufHTML4.getLength () > 0) m_pClipboard->addHtmlData (target, bufHTML4.getPointer (0), bufHTML4.getLength (), false); if (bExpODT && bufODT.getLength () > 0) m_pClipboard->addODTData (target, bufODT.getPointer (0), bufODT.getLength ()); if (bufTEXT.getLength () > 0) m_pClipboard->addTextData (target, bufTEXT.getPointer (0), bufTEXT.getLength ()); { // TODO: we have to make a good way to tell if the current selection is just an image FV_View * pView = NULL; if(getLastFocussedFrame()) pView = static_cast<FV_View*>(getLastFocussedFrame()->getCurrentView()); if (pView && !pView->isSelectionEmpty()) { // don't own, don't g_free const UT_ByteBuf * png = 0; pView->saveSelectedImage (&png); if (png && png->getLength() > 0) { m_pClipboard->addPNGData(target, static_cast<const UT_Byte*>(png->getPointer(0)), png->getLength()); } } } m_pClipboard->finishedAddingData(); return; }
UT_Error IE_ImpGraphic_WMF::convertGraphicToSVG(UT_ByteBuf* pBBwmf, UT_ByteBuf** ppBB) { int status = 0; unsigned int disp_width = 0; unsigned int disp_height = 0; float wmf_width; float wmf_height; float ratio_wmf; float ratio_bounds; unsigned long flags; unsigned int max_width = 768; unsigned int max_height = 512; unsigned long max_flags = 0; static const char* Default_Description = "wmf2svg"; wmf_error_t err; wmf_svg_t* ddata = 0; wmfAPI* API = 0; wmfD_Rect bbox; wmfAPI_Options api_options; bbuf_read_info read_info; char *stream = NULL; unsigned long stream_len = 0; *ppBB = 0; flags = 0; flags = WMF_OPT_IGNORE_NONFATAL | WMF_OPT_FUNCTION; api_options.function = wmf_svg_function; err = wmf_api_create (&API,flags,&api_options); status = explicit_wmf_error ("wmf_api_create",err); if (status) { if (API) wmf_api_destroy (API); return (UT_ERROR); } read_info.pByteBuf = pBBwmf; read_info.len = pBBwmf->getLength(); read_info.pos = 0; err = wmf_bbuf_input (API,AbiWord_WMF_read,AbiWord_WMF_seek,AbiWord_WMF_tell,(void *) &read_info); if (err != wmf_E_None) { UT_DEBUGMSG(("IE_ImpGraphic_WMF::convertGraphic Bad input set\n")); goto ErrorHandler; } err = wmf_scan (API,0,&(bbox)); status = explicit_wmf_error ("wmf_scan",err); if (status) { goto ErrorHandler; } /* Okay, got this far, everything seems cool. */ ddata = WMF_SVG_GetData (API); ddata->out = wmf_stream_create(API, NULL); ddata->Description = (char *)Default_Description; ddata->bbox = bbox; wmf_display_size (API,&disp_width,&disp_height,72,72); wmf_width = (float) disp_width; wmf_height = (float) disp_height; if ((wmf_width <= 0) || (wmf_height <= 0)) { fputs ("Bad image size - but this error shouldn't occur...\n",stderr); status = 1; wmf_api_destroy (API); return UT_ERROR; } if ((wmf_width > (float) max_width ) || (wmf_height > (float) max_height)) { if (max_flags == 0) max_flags = WMF2SVG_MAXPECT; } if (max_flags == WMF2SVG_MAXPECT) /* scale the image */ { ratio_wmf = wmf_height / wmf_width; ratio_bounds = (float) max_height / (float) max_width; if (ratio_wmf > ratio_bounds) { ddata->height = max_height; ddata->width = (unsigned int) ((float) ddata->height / ratio_wmf); } else { ddata->width = max_width; ddata->height = (unsigned int) ((float) ddata->width * ratio_wmf); } } else if (max_flags == WMF2SVG_MAXSIZE) /* bizarre option, really */ { ddata->width = max_width; ddata->height = max_height; } else { ddata->width = (unsigned int) ceil ((double) wmf_width ); ddata->height = (unsigned int) ceil ((double) wmf_height); } ddata->flags |= WMF_SVG_INLINE_IMAGES; ddata->flags |= WMF_GD_OUTPUT_MEMORY | WMF_GD_OWN_BUFFER; if (status == 0) { err = wmf_play (API,0,&(bbox)); status = explicit_wmf_error ("wmf_play",err); } wmf_stream_destroy(API, ddata->out, &stream, &stream_len); if (status == 0) { UT_ByteBuf* pBB = new UT_ByteBuf; pBB->append((const UT_Byte*)stream, (UT_uint32)stream_len); *ppBB = pBB; DELETEP(pBBwmf); wmf_free(API, stream); wmf_api_destroy (API); return UT_OK; } ErrorHandler: DELETEP(pBBwmf); if(API) { if(stream) { wmf_free(API, stream); } wmf_api_destroy (API); } return UT_ERROR; }
/*! copy data in required format to the clipboard */ bool AP_Win32App::_copyFmtToClipboard(PD_DocumentRange * pDocRange, const char * pszFmt) { UT_return_val_if_fail(m_pClipboard && pszFmt, false); UT_ByteBuf buf; UT_Error status;; UT_Byte b = 0; if(0 == strcmp(AP_CLIPBOARD_TEXTPLAIN_8BIT, pszFmt)) { IE_Exp_Text * pExpText = new IE_Exp_Text(pDocRange->m_pDoc); if (pExpText) { status = pExpText->copyToBuffer(pDocRange,&buf); if(status != UT_OK) return false; buf.append(&b,1); // NULL terminate the string m_pClipboard->addData(AP_CLIPBOARD_TEXTPLAIN_8BIT, (UT_Byte *)buf.getPointer(0),buf.getLength()); DELETEP(pExpText); UT_DEBUGMSG(("CopyToClipboard: copying %d bytes in TEXTPLAIN format.\n", buf.getLength())); } else { return false; } } else if(0 == strcmp(AP_CLIPBOARD_TEXTPLAIN_UCS2, pszFmt)) { const char *szEnc = XAP_EncodingManager::get_instance()->getNativeUnicodeEncodingName(); IE_Exp_Text * pExpUnicodeText = new IE_Exp_Text(pDocRange->m_pDoc,szEnc); if (pExpUnicodeText) { status = pExpUnicodeText->copyToBuffer(pDocRange,&buf); if(status != UT_OK) return false; UT_Byte b[2] = {0,0}; buf.append(b,2); // NULL terminate the string m_pClipboard->addData(AP_CLIPBOARD_TEXTPLAIN_UCS2, (UT_Byte *)buf.getPointer(0),buf.getLength()); DELETEP(pExpUnicodeText); UT_DEBUGMSG(("CopyToClipboard: copying %d bytes in TEXTPLAIN UNICODE format.\n", buf.getLength()*2)); } else { return false; } } else if(0 == strcmp(AP_CLIPBOARD_RTF, pszFmt)) { IE_Exp_RTF * pExpRtf = new IE_Exp_RTF(pDocRange->m_pDoc); if (pExpRtf) { status = pExpRtf->copyToBuffer(pDocRange,&buf); if(status != UT_OK) return false; buf.append(&b,1); // NULL terminate the string m_pClipboard->addData(AP_CLIPBOARD_RTF,(UT_Byte *)buf.getPointer(0),buf.getLength()); DELETEP(pExpRtf); UT_DEBUGMSG(("CopyFmtToClipboard: copying %d bytes in RTF format.\n", buf.getLength())); } else { return false; } } return true; }
static void _png_write(png_structp png_ptr, png_bytep data, png_size_t length) { UT_ByteBuf* pBB = (UT_ByteBuf*) png_get_io_ptr(png_ptr); pBB->ins(pBB->getLength(), data, length); }