From 334989a3b87eba4882bd6b67b84c443816b361c3 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 27 Jul 2012 17:40:39 +0200 Subject: Related: fdo#36089 improve import of EQ field in writerfilter This moves the FIELD_EQ parsing where it belongs + improves it, so a custom "lower by" value is handled on import. Change-Id: I0459042d7a610c397ce90ec3dba5ff49ce9ef60f --- sw/qa/extras/rtfimport/data/fdo36089.rtf | 9 +++++++ sw/qa/extras/rtfimport/rtfimport.cxx | 8 ++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 33 +++++++++++++++++++++++ writerfilter/source/dmapper/FieldTypes.hxx | 1 + writerfilter/source/rtftok/rtfdocumentimpl.cxx | 22 +++------------ writerfilter/source/rtftok/rtfdocumentimpl.hxx | 2 -- 6 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 sw/qa/extras/rtfimport/data/fdo36089.rtf diff --git a/sw/qa/extras/rtfimport/data/fdo36089.rtf b/sw/qa/extras/rtfimport/data/fdo36089.rtf new file mode 100644 index 000000000000..035d74f6cec6 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/fdo36089.rtf @@ -0,0 +1,9 @@ +{\rtf1 +{\fonttbl{\f0\fnil\fcharset0 Times New Roman;} +} +{\stylesheet +{\s0\fs20 Normal ;} +} +{\pard\plain\s0 Subscript{{\field{\*\fldinst{ EQ \\s\\do5({\fs16 1})}}{\fldrslt }} +}\par +}} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 229dec870ff6..753505e514c8 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -100,6 +100,7 @@ public: void testFdo46966(); void testFdo52066(); void testFdo48033(); + void testFdo36089(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -142,6 +143,7 @@ public: CPPUNIT_TEST(testFdo46966); CPPUNIT_TEST(testFdo52066); CPPUNIT_TEST(testFdo48033); + CPPUNIT_TEST(testFdo36089); #endif CPPUNIT_TEST_SUITE_END(); @@ -854,6 +856,12 @@ void Test::testFdo48033() CPPUNIT_ASSERT_EQUAL(OUString("Frame"), getProperty(getRun(xPara, 1), "TextPortionType")); } +void Test::testFdo36089() +{ + load("fdo36089.rtf"); + CPPUNIT_ASSERT_EQUAL(sal_Int16(-50), getProperty(getRun(getParagraph(1), 2), "CharEscapement")); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 2d8c584e6baf..73a084a2e24c 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -2092,6 +2092,7 @@ if(!bFilled) {OUString("DOCPROPERTY"), "", "", FIELD_DOCPROPERTY }, {OUString("DOCVARIABLE"), "User", "", FIELD_DOCVARIABLE }, {OUString("EDITTIME"), "DocInfo.EditTime", "", FIELD_EDITTIME }, + {OUString("EQ"), "", "", FIELD_EQ }, {OUString("FILLIN"), "Input", "", FIELD_FILLIN }, {OUString("FILENAME"), "FileName", "", FIELD_FILENAME }, // {OUString("FILESIZE"), "", "", FIELD_FILESIZE }, @@ -2639,6 +2640,7 @@ void DomainMapper_Impl::CloseFieldCommand() case FIELD_DOCPROPERTY: case FIELD_TOC: case FIELD_TC: + case FIELD_EQ: bCreateField = false; break; case FIELD_FORMCHECKBOX : @@ -2762,6 +2764,37 @@ void DomainMapper_Impl::CloseFieldCommand() case FIELD_EDITTIME : //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties ); break; + case FIELD_EQ: + { + OUString aCommand = pContext->GetCommand().trim(); + nSpaceIndex = aCommand.indexOf(' '); + if(nSpaceIndex > 0) + aCommand = aCommand.copy(nSpaceIndex).trim(); + if (aCommand.compareTo("\\s", 2) == 0) + { + aCommand = aCommand.copy(2); + if (aCommand.compareTo("\\do", 3) == 0) + { + aCommand = aCommand.copy(3); + sal_Int32 nStartIndex = aCommand.indexOf('('); + sal_Int32 nEndIndex = aCommand.indexOf(')'); + if (nStartIndex > 0 && nEndIndex > 0) + { + // nDown is the requested "lower by" value in points. + sal_Int32 nDown = aCommand.copy(0, nStartIndex).toInt32(); + OUString aContent = aCommand.copy(nStartIndex + 1, nEndIndex - nStartIndex - 1); + PropertyMapPtr pCharContext = GetTopContext(); + // dHeight is the font size of the current style. + double dHeight = 0; + if (GetPropertyFromStyleSheet(PROP_CHAR_HEIGHT) >>= dHeight) + // Character escapement should be given in negative percents for subscripts. + pCharContext->Insert(PROP_CHAR_ESCAPEMENT, true, uno::makeAny( sal_Int16(- 100 * nDown / dHeight) ) ); + appendTextPortion(aContent, pCharContext); + } + } + } + } + break; case FIELD_FILLIN : { sal_Int32 nIndex = 0; diff --git a/writerfilter/source/dmapper/FieldTypes.hxx b/writerfilter/source/dmapper/FieldTypes.hxx index 3f0a4608b55a..35effc319273 100644 --- a/writerfilter/source/dmapper/FieldTypes.hxx +++ b/writerfilter/source/dmapper/FieldTypes.hxx @@ -74,6 +74,7 @@ enum FieldId ww8filterimprovement: multiple languages now supported */ ,FIELD_EDITTIME + ,FIELD_EQ /* FILLIN "text to fill in" \d defaultanswer \o \* MERGEFORMAT -> Function-InputField */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index b03a7bc5d415..e6758f1f9610 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -260,7 +260,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference const& x m_nCurrentFontIndex(0), m_aStyleTableEntries(), m_nCurrentStyleIndex(0), - m_bEq(false), m_bFormField(false), m_bIsInFrame(false), m_aUnicodeBuffer(), @@ -989,10 +988,6 @@ void RTFDocumentImpl::text(OUString& rString) case DESTINATION_MGROW: m_aStates.top().aDestinationText.append(rString); break; - case DESTINATION_EQINSTRUCTION: - if ( rString.getLength() > 3 && rString.copy(0, 2) == "do" && rString.copy(2).toInt32() > 0 ) - dispatchFlag(RTF_SUB); - break; default: bRet = false; break; } if (bRet) @@ -1134,11 +1129,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) if (aBuf.toString().indexOf(OString("FORM")) != -1 ) m_bFormField = true; - // EQ fields are not really fields in fact. - if (aBuf.toString().equals("EQ")) - m_bEq = true; - else - singleChar(0x13); + singleChar(0x13); m_aStates.top().nDestinationState = DESTINATION_FIELDINSTRUCTION; } break; @@ -3160,7 +3151,6 @@ int RTFDocumentImpl::pushState() case DESTINATION_FIELDRESULT: case DESTINATION_SHAPETEXT: case DESTINATION_FORMFIELD: - case DESTINATION_EQINSTRUCTION: m_aStates.top().nDestinationState = DESTINATION_NORMAL; break; case DESTINATION_MNUM: @@ -3174,7 +3164,7 @@ int RTFDocumentImpl::pushState() m_aStates.top().nDestinationState = DESTINATION_MR; break; case DESTINATION_FIELDINSTRUCTION: - m_aStates.top().nDestinationState = !m_bEq ? DESTINATION_NORMAL : DESTINATION_EQINSTRUCTION; + m_aStates.top().nDestinationState = DESTINATION_NORMAL; break; case DESTINATION_REVISIONTABLE: m_aStates.top().nDestinationState = DESTINATION_REVISIONENTRY; break; case DESTINATION_MOMATH: m_aStates.top().nDestinationState = DESTINATION_MR; break; @@ -3285,14 +3275,10 @@ int RTFDocumentImpl::popState() m_aFormfieldAttributes.clear(); m_aFormfieldSprms.clear(); } - if (!m_bEq) - singleChar(0x14); + singleChar(0x14); break; case DESTINATION_FIELDRESULT: - if (!m_bEq) - singleChar(0x15); - else - m_bEq = false; + singleChar(0x15); break; case DESTINATION_LEVELTEXT: { diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index f2532e7e7a1a..1de7c6e36c39 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -65,7 +65,6 @@ namespace writerfilter { DESTINATION_COLORTABLE, DESTINATION_STYLESHEET, DESTINATION_STYLEENTRY, - DESTINATION_EQINSTRUCTION, DESTINATION_FIELD, DESTINATION_FIELDINSTRUCTION, DESTINATION_FIELDRESULT, @@ -563,7 +562,6 @@ namespace writerfilter { RTFReferenceTable::Entries_t m_aStyleTableEntries; int m_nCurrentStyleIndex; - bool m_bEq; bool m_bFormField; /// If a frame start token is already sent to dmapper (nesting them is not OK). bool m_bIsInFrame; -- cgit