sw/qa/extras/rtfexport/data/tdf108505_fieldCharFormat2.rtf |   37 +++++++++++++
 sw/qa/extras/rtfexport/rtfexport6.cxx                      |   21 +++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx          |   28 +++------
 3 files changed, 68 insertions(+), 18 deletions(-)

New commits:
commit caecfff1adbe9715260ef9e2009333e523d61123
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Dec 1 14:16:14 2023 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Dec 5 08:48:38 2023 +0100

    tdf#108505 writerfilter: fix field direct char settings
    
    Instead of adding characters properties one at a time,
    lets take care of everything all at once.
    
    The results seem to be good so far.
    There is even some similarity between
    how MS Word has these properties on the
    "in-between" pseudo end character, where
    placing the cursor after the field gets these properties.
    I don't see it happening in MS Word
    at the pseudo start character, but it does in LO now...
    
    Hopefully that doesn't end up doing bad things.
    
    In the unit test, replacing the content ends up
    in red, italic. However, I see the same thing in MSO
    when testing with my second FORMTEXT example,
    so I think everything is "working as expected".
    
    I tried to see if I could limit doing this
    for only certain types of fields or conditions.
    However, pContext->GetResult() doesn't have a \fldrslt
    yet at the time this is happening. Also, TextField.is()
    happens less than I expected. I'm sure I could limit it
    to just certain pContext->GetFieldId(),
    but so far no problems are noticed for all field types.
    
    make CppunitTest_sw_rtfexport6 \
        CPPUNIT_TEST_NAME=testTdf108505_fieldCharFormat
    
    make CppunitTest_sw_rtfexport6 \
        CPPUNIT_TEST_NAME=testTdf108505_fieldCharFormat2
    
    Change-Id: I3223437fd0d694f5e5733a9f7323f10f03d7802f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160232
    Tested-by: Jenkins
    Tested-by: Gabor Kelemen <kelem...@ubuntu.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/rtfexport/data/tdf108505_fieldCharFormat2.rtf 
b/sw/qa/extras/rtfexport/data/tdf108505_fieldCharFormat2.rtf
new file mode 100644
index 000000000000..bb45e3052011
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf108505_fieldCharFormat2.rtf
@@ -0,0 +1,37 @@
+{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang2057\deflangfe2057\themelang3079\themelangfe0\themelangcs0
+
+\noqfpromote {\stylesheet{\ql 
\li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0
 \rtlch\fcs1 
+\af0\afs20\alang1025 \ltrch\fcs0 
\fs26\lang1031\langfe3079\cgrid\langnp1031\langfenp3079 \snext0 \sqformat 
\spriority0 Normal;}{\s17\ql \li0\ri0\widctlpar
+\tqc\tx4819\tqr\tx9071\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0
 \rtlch\fcs1 \af0\afs20\alang1025 \ltrch\fcs0 
\fs26\lang1031\langfe3079\cgrid\langnp1031\langfenp3079 \sbasedon0 \snext17 
\slink18 header;}
+}
+\paperw16834\paperh11913\margl1134\margr1418\margt1418\margb567\gutter0\ltrsect
 
+\deftab708\widowctrl\ftnbj\aenddoc\hyphhotz425\trackmoves0\trackformatting1\donotembedsysfont0\relyonvml0\donotembedlingdata0\grfdocevents0\validatexml1\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0
+\showxmlerrors1\noextrasprl\prcolbl\cvmme\sprsspbf\brkfrm\swpbdr\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\lytprtmet\hyphcaps0\formshade\horzdoc\fracwidth\dghspace180\dgvspace180\dghorigin1701\dgvorigin1984\dghshow0\dgvshow0
+\jexpand\viewkind1\viewscale70\pgbrdrhead\pgbrdrfoot\nolnhtadjtbl\nojkernpunct\rsidroot3825670
 \fet0
+
+\ltrrow\trowd \irow0\irowband0\lastrow \ltrrow
+\ts11\trgaph70\trleft-70\trkeep\trftsWidth3\trwWidth8931\trftsWidthB3\trftsWidthA3\trpaddl70\trpaddr70\trpaddfl3\trpaddfr3\tblrsid16408416\tblind0\tblindtype3
 \clvertalc\clbrdrt\brdrtbl \clbrdrl\brdrtbl \clbrdrb\brdrtbl \clbrdrr\brdrtbl 
+\cltxlrtb\clftsWidth3\clwWidth1276\clshdrawnil 
\cellx1206\clvertalc\clbrdrt\brdrtbl \clbrdrl\brdrtbl \clbrdrb\brdrtbl 
\clbrdrr\brdrs\brdrw30 \cltxlrtb\clftsWidth3\clwWidth3969\clshdrawnil 
\cellx5175\clvertalt\clbrdrt\brdrs\brdrw30 \clbrdrl\brdrs\brdrw30 
+\clbrdrb\brdrs\brdrw30 \clbrdrr\brdrs\brdrw30 
\cltxlrtb\clftsWidth3\clwWidth2126\clshdrawnil 
\cellx7301\clvertalt\clbrdrt\brdrtbl \clbrdrl\brdrs\brdrw30 \clbrdrb\brdrtbl 
\clbrdrr\brdrs\brdrw30 \cltxlrtb\clftsWidth3\clwWidth1560\clshdrawnil \cellx8861
+\pard\plain \ltrpar\s17\ql 
\li72\ri0\sb120\sa120\widctlpar\intbl\tqr\tx1561\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin72\pararsid8918882
 \rtlch\fcs1 \af0\afs20\alang1025 \ltrch\fcs0 
\fs26\lang1031\langfe3079\cgrid\langnp1031\langfenp3079
+
+{\fonttbl{\f0\froman\fprq2\fcharset0 Times New 
Roman;}{\f5\fnil\fprq2\fcharset128 Linux Biolinum Keyboard O;}}
+
+{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}
+
+{\rtlch\fcs1 \af0 \ltrch\fcs0 \f5\fs32\chcbpat7\insrsid16408416 
Header}{\rtlch\fcs1 \af0 \ltrch\fcs0 \fs32\insrsid16408416\charrsid8918882 
\cell }\pard\plain \ltrpar\ql 
\li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\pararsid5246913
 
+\rtlch\fcs1 \af0\afs20\alang1025 \ltrch\fcs0 
\fs26\lang1031\langfe3079\cgrid\langnp1031\langfenp3079 {\rtlch\fcs1 \af0 
\ltrch\fcs0 \insrsid16408416\charrsid8918882 Normal\cell }\pard \ltrpar
+\qc 
\li0\ri0\sb120\sa120\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0
 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5701682\charrsid5701682 {\*\bkmkstart 
Dropdown1}x}
+
+{\field{\*\fldinst {\ltrch\fcs0 \i\fs40\cf6  FORMTEXT }{{\*\datafield 0abcd}
+{\*\formfield{\fftype0\fftypetxt0{\*\ffname Text1}
+{\*\ffdeftext {placeholder}}}}}}
+{\fldrslt \fs48\b xyz}}
+
+\sectd \ltrsect
+\lndscpsxn\binfsxn4\binsxn4\linex0\headery851\sectlinegrid354\sectdefaultcl\sectrsid1197700\sftnbj
 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5701682\charrsid5701682 {\*\bkmkend 
Dropdown1}y}{ 
+\cell }{\rtlch\fcs1 \af0 \ltrch\fcs0 \b\fs32\insrsid16408416\charrsid4871016 
bold16\cell }\pard \ltrpar\ql 
\li0\ri0\sa200\sl276\slmult1\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0
 {\trowd \irow0\irowband0\lastrow 
\ltrrow\ts11\trgaph70\trleft-70\trkeep\trftsWidth3\trwWidth8931\trftsWidthB3\trftsWidthA3\trpaddl70\trpaddr70\trpaddfl3\trpaddfr3\tblrsid16408416\tblind0\tblindtype3
 \clvertalc\clbrdrt\brdrtbl 
+\clbrdrl\brdrtbl \clbrdrb\brdrtbl \clbrdrr\brdrtbl 
\cltxlrtb\clftsWidth3\clwWidth1276\clshdrawnil 
\cellx1206\clvertalc\clbrdrt\brdrtbl \clbrdrl\brdrtbl \clbrdrb\brdrtbl 
\clbrdrr\brdrs\brdrw30 \cltxlrtb\clftsWidth3\clwWidth3969\clshdrawnil \cellx5175
+\clvertalt\clbrdrt\brdrs\brdrw30 \clbrdrl\brdrs\brdrw30 \clbrdrb\brdrs\brdrw30 
\clbrdrr\brdrs\brdrw30 \cltxlrtb\clftsWidth3\clwWidth2126\clshdrawnil 
\cellx7301\clvertalt\clbrdrt\brdrtbl \clbrdrl\brdrs\brdrw30 \clbrdrb\brdrtbl 
\clbrdrr\brdrs\brdrw30 
+\cltxlrtb\clftsWidth3\clwWidth1560\clshdrawnil \cellx8861\row }\pard
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport6.cxx 
b/sw/qa/extras/rtfexport/rtfexport6.cxx
index 42419fb2ed00..f4ff562c37e8 100644
--- a/sw/qa/extras/rtfexport/rtfexport6.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport6.cxx
@@ -171,7 +171,26 @@ DECLARE_RTFEXPORT_TEST(testTdf108505_fieldCharFormat, 
"tdf108505_fieldCharFormat
     uno::Reference<text::XTextRange> xRun = getRun(xPara, 3, u"MZ"_ustr);
     CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xRun, 
"CharWeight"));
     CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, 
getProperty<awt::FontSlant>(xRun, "CharPosture"));
-    // CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, getProperty<Color>(xRun, 
"CharColor"));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, getProperty<Color>(xRun, 
"CharColor"));
+}
+
+DECLARE_RTFEXPORT_TEST(testTdf108505_fieldCharFormat2, 
"tdf108505_fieldCharFormat2.rtf")
+{
+    // not exported properly. Currrently xyz exports as run 6, red, italic.
+    if (isExported())
+        return;
+
+    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), 
uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("C1"), 
uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xPara = getParagraphOfText(1, 
xCell->getText());
+
+    // Preemptive test: nothing found wrong/fixed by the accompanying patch
+    // Character formatting should only be defined by the \fldrslt, and not by 
prior formatting.
+    // Prior formatting is italic, red, 20pt.
+    uno::Reference<text::XTextRange> xRun = getRun(xPara, 5, u"xyz"_ustr);
+    CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xRun, 
"CharWeight"));
+    CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, 
getProperty<awt::FontSlant>(xRun, "CharPosture"));
+    CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xRun, "CharColor"));
 }
 
 /** Make sure that the document variable "Unused", which is not referenced in 
the document,
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 18560a89eb84..183d71d5833a 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -7169,11 +7169,8 @@ void DomainMapper_Impl::CloseFieldCommand()
         (void)vSwitches;
         OUString const sFirstParam(vArguments.empty() ? OUString() : 
vArguments.front());
 
-        // apply font size to the form control
-        if (!m_aTextAppendStack.empty() && m_pLastCharacterContext
-            && (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT)
-                || m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME)
-                || m_pLastCharacterContext->isSet(PROP_CHAR_WEIGHT)))
+        // apply character properties to the form control
+        if (!m_aTextAppendStack.empty() && m_pLastCharacterContext)
         {
             uno::Reference< text::XTextAppend >  xTextAppend = 
m_aTextAppendStack.top().xTextAppend;
             if (xTextAppend.is())
@@ -7183,20 +7180,17 @@ void DomainMapper_Impl::CloseFieldCommand()
                 {
                     xCrsr->gotoEnd(false);
                     uno::Reference< beans::XPropertySet > xProp( xCrsr, 
uno::UNO_QUERY );
-                    if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT))
+                    for (auto& rPropValue : 
m_pLastCharacterContext->GetPropertyValues(false))
                     {
-                        
xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT), 
m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT)->second);
-                        if 
(m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT_COMPLEX))
-                            
xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT_COMPLEX), 
m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT_COMPLEX)->second);
-                    }
-                    if (m_pLastCharacterContext->isSet(PROP_CHAR_WEIGHT))
-                    {
-                        
xProp->setPropertyValue(getPropertyName(PROP_CHAR_WEIGHT), 
m_pLastCharacterContext->getProperty(PROP_CHAR_WEIGHT)->second);
-                        if 
(m_pLastCharacterContext->isSet(PROP_CHAR_WEIGHT_COMPLEX))
-                            
xProp->setPropertyValue(getPropertyName(PROP_CHAR_WEIGHT_COMPLEX), 
m_pLastCharacterContext->getProperty(PROP_CHAR_WEIGHT_COMPLEX)->second);
+                        try
+                        {
+                            xProp->setPropertyValue(rPropValue.Name, 
rPropValue.Value);
+                        }
+                        catch(uno::Exception&)
+                        {
+                            TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", 
"Unknown Field PropVal");
+                        }
                     }
-                    if (m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME))
-                        
xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), 
m_pLastCharacterContext->getProperty(PROP_CHAR_FONT_NAME)->second);
                 }
             }
         }

Reply via email to