void IE_Imp_WordPerfect::openFootnote(const librevenge::RVNGPropertyList & /*propList*/) { if (m_bHdrFtrOpenCount) return; // HACK if (!m_bInSection) { X_CheckDocumentError(appendStrux(PTX_Section, PP_NOPROPS)); X_CheckDocumentError(appendStrux(PTX_Block,PP_NOPROPS)); m_bInSection = true; } std::string footnoteId = UT_std_string_sprintf("%i", UT_rand()); PP_PropertyVector propsArray = { "type", "footnote_ref", "footnote-id", footnoteId }; X_CheckDocumentError(appendObject(PTO_Field, propsArray)); const PP_PropertyVector attribs = { "footnote-id", footnoteId }; X_CheckDocumentError(appendStrux(PTX_SectionFootnote, attribs)); X_CheckDocumentError(appendStrux(PTX_Block, PP_NOPROPS)); m_bRequireBlock = false; // just change the type. propsArray[1] = "footnote_anchor"; X_CheckDocumentError(appendObject(PTO_Field, propsArray)); }
void IE_Imp_WordPerfect::openEndnote(const WPXPropertyList & /*propList*/) { if (m_bHdrFtrOpenCount) return; // HACK const gchar** propsArray = NULL; UT_String endnoteId; UT_String_sprintf(endnoteId,"%i",UT_rand()); propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *))); propsArray [0] = "type"; propsArray [1] = "endnote_ref"; propsArray [2] = "endnote-id"; propsArray [3] = endnoteId.c_str(); propsArray [4] = NULL; propsArray [5] = NULL; propsArray [6] = NULL; X_CheckDocumentError(appendObject(PTO_Field, propsArray)); const gchar * attribs[3] ={"endnote-id", endnoteId.c_str(), NULL}; X_CheckDocumentError(appendStrux(PTX_SectionEndnote,attribs)); X_CheckDocumentError(appendStrux(PTX_Block,NULL)); m_bRequireBlock = false; propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *))); propsArray [0] = "type"; propsArray [1] = "endnote_anchor"; propsArray [2] = "endnote-id"; propsArray [3] = endnoteId.c_str(); propsArray [4] = NULL; propsArray [5] = NULL; propsArray [6] = NULL; X_CheckDocumentError(appendObject(PTO_Field, propsArray)); }
void IE_Imp_WordPerfect::defineUnorderedListLevel(const WPXPropertyList &propList) { if (m_bHdrFtrOpenCount) return; // HACK UT_DEBUGMSG(("AbiWordPerfect: defineUnorderedListLevel\n")); int listID = 0, level = 1; WPXString textBeforeNumber, textAfterNumber; float listLeftOffset = 0.0f; float listMinLabelWidth = 0.0f; if (propList["libwpd:id"]) listID = propList["libwpd:id"]->getInt(); if (propList["libwpd:level"]) level = propList["libwpd:level"]->getInt(); if (propList["text:space-before"]) listLeftOffset = propList["text:space-before"]->getDouble(); if (propList["text:min-label-width"]) listMinLabelWidth = propList["text:min-label-width"]->getDouble(); if (!m_pCurrentListDefinition || m_pCurrentListDefinition->getOutlineHash() != listID) { if (m_pCurrentListDefinition) delete (m_pCurrentListDefinition); m_pCurrentListDefinition = new ABI_ListDefinition(listID); } if (!m_pCurrentListDefinition->getListID(level)) { m_pCurrentListDefinition->setListID(level, UT_rand()); m_pCurrentListDefinition->setListLeftOffset(level, listLeftOffset); m_pCurrentListDefinition->setListMinLabelWidth(level, listMinLabelWidth); _updateDocumentUnorderedListDefinition(m_pCurrentListDefinition, level); } }
void IE_Imp_WordPerfect::openOrderedListLevel(const librevenge::RVNGPropertyList &propList) { if (m_bHdrFtrOpenCount) return; // HACK UT_DEBUGMSG(("AbiWordPerfect: openOrderedListLevel\n")); int listID = 0, startingNumber = 0, level = 1; char listType = '1'; UT_UTF8String textBeforeNumber, textAfterNumber; float listLeftOffset = 0.0f; float listMinLabelWidth = 0.0f; if (propList["librevenge:id"]) listID = propList["librevenge:id"]->getInt(); if (propList["text:start-value"]) startingNumber = propList["text:start-value"]->getInt(); if (propList["librevenge:level"]) level = propList["librevenge:level"]->getInt(); if (propList["style:num-prefix"]) textBeforeNumber += propList["style:num-prefix"]->getStr().cstr(); if (propList["style:num-suffix"]) textAfterNumber += propList["style:num-suffix"]->getStr().cstr(); if (propList["style:num-format"]) listType = propList["style:num-format"]->getStr().cstr()[0]; if (propList["text:space-before"]) listLeftOffset = propList["text:space-before"]->getDouble(); if (propList["text:min-label-width"]) listMinLabelWidth = propList["text:min-label-width"]->getDouble(); if (!m_pCurrentListDefinition || m_pCurrentListDefinition->getOutlineHash() != listID || (m_pCurrentListDefinition->getLevelNumber(level) != startingNumber && level == 1)) { if (m_pCurrentListDefinition) delete (m_pCurrentListDefinition); m_pCurrentListDefinition = new ABI_ListDefinition(listID); } if (!m_pCurrentListDefinition->getListID(level)) { m_pCurrentListDefinition->setListType(level, listType); m_pCurrentListDefinition->setListID(level, UT_rand()); m_pCurrentListDefinition->setListLeftOffset(level, listLeftOffset); m_pCurrentListDefinition->setListMinLabelWidth(level, listMinLabelWidth); _updateDocumentOrderedListDefinition(m_pCurrentListDefinition, level, listType, textBeforeNumber, textAfterNumber, startingNumber); } m_iCurrentListLevel++; }
std::string UT_createTmpFile(const std::string& prefix, const std::string& extension) { const gchar *filename = g_build_filename (g_get_tmp_dir (), prefix.c_str(), NULL); UT_return_val_if_fail(filename, ""); std::string sName = filename; FREEP(filename); UT_UTF8String rand = UT_UTF8String_sprintf("%X", UT_rand() * 0xFFFFFF); sName += rand.utf8_str(); sName += extension; FILE* f = fopen (sName.c_str(), "w+b"); if (!f) return ""; fclose(f); return sName; }
void UT_UUIDGenerator__test(UT_UUIDGenerator* self) { // test hashes ... UT_DEBUGMSG(("------------------------- Testing uuid hash() ---------------------------\n")); std::vector<test_record> v; const UT_uint32 iMax = 512000; const UT_uint32 iMsg = 5000; const UT_uint32 iTest = 10; UT_uint32 iColHTotal = 0; UT_uint32 iDeltaMinH = 0xffffffff; // create a dummy uuid instance ... if(!self->m_pUUID) self->m_pUUID = new UT_UUID; for (UT_uint32 k = 0; k < iTest; ++k) { UT_uint32 j; UT_uint32 iColH = 0; UT_uint32 iDMinH = 0xffffffff; TF_Test::pulse(); for(j = 0; j < iMax; ++j) { //makeUUID(); // on similar strings, the glib hash performs much better; // let's test it on random strings UT_uint32 * p = (UT_uint32 *)&(self->m_pUUID->m_uuid); for(UT_uint32 n = 0; n < 4; n++) p[n] = UT_rand(); test_record t; t.val = self->m_pUUID->hash32(); t.indx = j; v.push_back(t); // if(0 == j % iMsg) // UT_DEBUGMSG(("Round %d: Generating rand %d of %d\n", k, j, iMax)); } TF_Test::pulse(); std::sort(v.begin(), v.end(), s_cmp_hash); for(j = 0; j < iMax - 1; ++j) { const test_record &t1 = v.at(j); const test_record &t2 = v.at(j+1); if(t1.val == t2.val) { UT_DEBUGMSG(("Round %04d: uuid hash() collision (value: %u)\n", k, t1.val)); UT_uint32 i1 = t1.indx > t2.indx ? t1.indx : t2.indx; UT_uint32 i2 = t1.indx < t2.indx ? t1.indx : t2.indx; iDMinH = iDMinH < (UT_uint32)(i1-i2) ? iDMinH : (UT_uint32)i1-i2; iColH++; } // if(0 == j % iMsg) // UT_DEBUGMSG(("Round %04d: testing %d of %d\n", k, j, iMax)); } UT_DEBUGMSG(("RESULTS: round %04u: %u hash collisions (min distance %u)\n", k, iColH, iDMinH)); iColHTotal += iColH; iDeltaMinH = iDeltaMinH < iDMinH ? iDeltaMinH : iDMinH; v.clear(); } UT_DEBUGMSG(("CUMULATIVE RESULTS (of %d): %d hash collisions (min distance %d)\n", iMax*iTest, iColHTotal, iDeltaMinH)); // delete the dummy uuid instance so that any genuine calls to the // hash functions allocate a proper derived instance if(self->m_pUUID) { delete self->m_pUUID; self->m_pUUID = NULL; } UT_DEBUGMSG(("---------------------- Testing uuid hash END --------------------------\n")); }