UT_UTF8String::UT_UTF8String (const char *str, const char *encoding) { UT_uint32 iRead, iWritten; char *pUTF8Buf = UT_convert(str, strlen(str), encoding, "UTF-8", &iRead, &iWritten); pimpl = new UT_UTF8Stringbuf(pUTF8Buf); FREEP(pUTF8Buf); }
UT_Error IE_Imp_Hancom::_loadFile(GsfInput * input) { mDoc = GSF_INFILE(gsf_infile_msole_new (input, NULL)); if (!mDoc) return UT_IE_BOGUSDOCUMENT; GsfInput *textStream = gsf_infile_child_by_name(mDoc, "/PrvText"); if (!textStream) return UT_IE_BOGUSDOCUMENT; size_t len = gsf_input_size(textStream); UT_DEBUGMSG(("HANCOM: Text length = %zd bytes\n", len)); unsigned char* buf = new unsigned char[len]; if (!buf) { g_object_unref (G_OBJECT (textStream)); return UT_IE_NOMEMORY; } gsf_input_read(textStream, len, buf); g_object_unref (G_OBJECT (textStream)); UT_uint32 length; UT_UCS4Char* text = reinterpret_cast<UT_UCS4Char*>(UT_convert((const char *)buf, len, "UCS-2LE", UCS_INTERNAL, NULL, &length)); delete[] buf; if (!text) return UT_IE_NOMEMORY; UT_DEBUGMSG(("HANCOM: Text successfully converted.\n")); if (!appendStrux(PTX_Section, NULL)) { FREEP(text); return UT_IE_NOMEMORY; } if (!appendStrux(PTX_Block, NULL)) { FREEP(text); return UT_IE_NOMEMORY; } if (!appendSpan(text, length/4)) { FREEP(text); return UT_IE_NOMEMORY; } FREEP(text); return UT_OK; }
/* From UCS4 To WinLocale */ UT_String AP_Win32App::s_fromUCS4ToWinLocale(const UT_UCS4Char * szIn) { UT_UCS4String sUCS4(szIn); UT_String sRslt; char *pText = UT_convert ((char *)sUCS4.ucs4_str(), sUCS4.length()*sizeof(UT_UCS4Char), ucs4Internal(), XAP_App::getApp()->getDefaultEncoding(), NULL, NULL); sRslt = pText; g_free(pText); return sRslt; }
/*! * Translate the stylename in UCS2 to a sanitized UTF8 string. * * The input is a psiconv UCS2 string; the output an Abiword UTF8 string. * Special characters are filtered away. * \return NULL if input is NULL or something went horribly wrong, the * UTF8 string otherwise. */ static gchar *prepare_style_name(const psiconv_string_t input) { psiconv_string_t input_copy; gchar *result; int i; UT_uint32 read,written; if (!(input_copy = psiconv_unicode_strdup(input))) return NULL; for (i = 0; i < psiconv_unicode_strlen(input_copy);i++) if ((input[i] < 0x20) || (input[i] == ';') || (input[i] == ':')) input[i] = '?'; read=written=0; result = UT_convert((char *)input, psiconv_unicode_strlen(input) * sizeof(*input), "UCS-2","UTF-8",&read,&written); free(input_copy); return result; }
/*! paste from the system clipboard using the best-for-us format that is present. try to get the content in the order listed. \todo currently i have this set so that a ^v or Menu[Edit/Paste] will use the CLIPBOARD property and a MiddleMouseClick will use the PRIMARY property -- this seems to be the "X11 way" (sigh). consider having a preferences switch to allow ^v and Menu[Edit/Paste] to use the most recent property... this might be a nice way of unifying things -- or it might not -- this is probably an area for investigation or some usability testing. */ void AP_UnixApp::pasteFromClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard, bool bHonorFormatting) { XAP_UnixClipboard::T_AllowGet tFrom = ((bUseClipboard) ? XAP_UnixClipboard::TAG_ClipboardOnly : XAP_UnixClipboard::TAG_PrimaryOnly); const char * szFormatFound = NULL; const unsigned char * pData = NULL; UT_uint32 iLen = 0; bool bFoundOne = false; bool bSuccess = false; if ( bHonorFormatting ) bFoundOne = m_pClipboard->getSupportedData(tFrom,reinterpret_cast<const void **>(&pData),&iLen,&szFormatFound); else bFoundOne = m_pClipboard->getTextData(tFrom,reinterpret_cast<const void **>(&pData),&iLen, &szFormatFound); #ifdef DUMP_CLIPBOARD_PASTE if (bFoundOne) { std::ofstream oss("/tmp/clips"); oss.write( (const char*)pData, iLen ); oss.close(); } #endif if (!bFoundOne) { UT_DEBUGMSG(("PasteFromClipboard: did not find anything to paste.\n")); return; } if (AP_UnixClipboard::isDynamicTag (szFormatFound)) { UT_DEBUGMSG(("Dynamic Format Found = %s \n",szFormatFound)); } if (AP_UnixClipboard::isRichTextTag(szFormatFound)) { IE_Imp_RTF * pImpRTF = new IE_Imp_RTF(pDocRange->m_pDoc); bSuccess = pImpRTF->pasteFromBuffer(pDocRange,pData,iLen); DELETEP(pImpRTF); } else if (AP_UnixClipboard::isHTMLTag (szFormatFound)) { IE_Imp_Text_Sniffer SniffBuf; const char * szRes = SniffBuf.recognizeContentsType(reinterpret_cast<const char *>(pData),iLen); if(szRes && strcmp(szRes,"none") != 0) { UT_uint32 iread,iwritten = 0; const char * szutf8= static_cast<const char *>(UT_convert(reinterpret_cast<const char *>(pData),iLen,szRes,"UTF-8",&iread,&iwritten)); IE_Imp_XHTML * pImpHTML = new IE_Imp_XHTML(pDocRange->m_pDoc); bSuccess = pImpHTML->pasteFromBuffer(pDocRange,reinterpret_cast<const unsigned char *>(szutf8),iwritten,"UTF-8"); g_free(const_cast<char *>(szutf8)); DELETEP(pImpHTML); } else { IE_Imp_XHTML * pImpHTML = new IE_Imp_XHTML(pDocRange->m_pDoc); bSuccess = pImpHTML->pasteFromBuffer(pDocRange,reinterpret_cast<const unsigned char *>(pData),iLen); DELETEP(pImpHTML); } } else if (AP_UnixClipboard::isDynamicTag (szFormatFound)) { UT_DEBUGMSG(("Format Found = %s \n",szFormatFound)); IE_Imp * pImp = NULL; IEFileType ieft = IE_Imp::fileTypeForMimetype(szFormatFound); UT_DEBUGMSG(("found file type %d\n",ieft)); IE_Imp::constructImporter(pDocRange->m_pDoc,ieft,&pImp); if(pImp == NULL) goto retry_text; bSuccess = pImp->pasteFromBuffer(pDocRange,pData,iLen); DELETEP(pImp); } else if (AP_UnixClipboard::isImageTag(szFormatFound)) { UT_DEBUGMSG(("Format Found = %s \n",szFormatFound)); if(strncmp(szFormatFound,"application",11) == 0) // embedded object { IE_Imp * pImp = NULL; IEGraphicFileType iegft = IE_Imp::fileTypeForMimetype(szFormatFound); IE_Imp::constructImporter(pDocRange->m_pDoc,iegft,&pImp); if(pImp == NULL) { goto retry_text; } /*bool b = */ pImp->pasteFromBuffer(pDocRange,pData,iLen); DELETEP(pImp); return; } FG_Graphic * pFG = NULL; IEGraphicFileType iegft = IEGFT_Unknown; UT_Error error = UT_OK; UT_ByteBuf bytes( iLen ); bytes.append (pData, iLen); error = IE_ImpGraphic::loadGraphic(bytes, iegft, &pFG); if(!pFG || error) { UT_DEBUGMSG(("DOM: could not import graphic (%d)\n", error)); goto retry_text; } // at this point, 'bytes' is owned by pFG FV_View * pView = static_cast<FV_View*>(getLastFocussedFrame ()->getCurrentView()); error = pView->cmdInsertGraphic(pFG); DELETEP(pFG); if (!error) bSuccess = true; } else // ( AP_UnixClipboard::isTextTag(szFormatFound) ) { IE_Imp_Text * pImpText = new IE_Imp_Text(pDocRange->m_pDoc,"UTF-8"); bSuccess = pImpText->pasteFromBuffer(pDocRange,pData,iLen); DELETEP(pImpText); } retry_text: // we failed to paste *anything.* try plaintext as a last-ditch effort if(!bSuccess && m_pClipboard->getTextData(tFrom,reinterpret_cast<const void **>(&pData),&iLen, &szFormatFound)) { UT_DEBUGMSG(("DOM: pasting text as an absolute fallback (bug 7666)\n")); IE_Imp_Text * pImpText = new IE_Imp_Text(pDocRange->m_pDoc,"UTF-8"); bSuccess = pImpText->pasteFromBuffer(pDocRange,pData,iLen); DELETEP(pImpText); } }