[Libreoffice-commits] core.git: sw/qa writerfilter/source

Vasily Melenchuk Vasily.Melenchuk at cib.de
Fri Nov 10 01:02:29 UTC 2017


 sw/qa/extras/ooxmlimport/data/tdf43017.docx       |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx          |   11 ++++++++
 writerfilter/source/dmapper/DomainMapper.cxx      |    8 +++---
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   21 +++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |   29 +++++++++++++++-------
 5 files changed, 56 insertions(+), 13 deletions(-)

New commits:
commit eaa9cf6a3069fba3d82c046f0041bfb537d9e648
Author: Vasily Melenchuk <Vasily.Melenchuk at cib.de>
Date:   Fri Aug 18 22:14:08 2017 +0300

    tdf#43017: Support for DOCX hyperlinks character properties
    
    Here goes a bunch of related changes:
    
    1. Create new character style based on current character properties
    
    2. Apply created style to hyperlink object
    
    3. Fixes to predefined style names usage in w:rPr
    
    4. Disable style usage for hyperlinks in TOC: they will receive later
    anoter styles
    
    Change-Id: I1a228992eb7c1e259a6a811aa7f959debaae4f35
    Reviewed-on: https://gerrit.libreoffice.org/41784
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sw/qa/extras/ooxmlimport/data/tdf43017.docx b/sw/qa/extras/ooxmlimport/data/tdf43017.docx
new file mode 100644
index 000000000000..c3372e11a0c8
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf43017.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 29e008b4d147..cafef1d2ee53 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1548,6 +1548,17 @@ DECLARE_OOXMLIMPORT_TEST(testTdf111550, "tdf111550.docx")
     getCell(innerTable, "A1", "[outer:A2]\n[inner:A1]");
 }
 
+
+DECLARE_OOXMLIMPORT_TEST(testTdf43017, "tdf43017.docx")
+{
+    uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
+    uno::Reference<text::XTextRange> xText = getRun(xParagraph, 2, "kick the bucket");
+
+    // Ensure that hyperlink text color is not blue (0x0000ff), but default (-1)
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Hyperlink color should be black!",
+        sal_Int32(-1), getProperty<sal_Int32>(xText, "CharColor"));
+}
+
 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 4d034cab669a..a8eff5e63165 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2207,11 +2207,11 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
         {
             OUString sConvertedName( m_pImpl->GetStyleSheetTable()->ConvertStyleName( sStringValue, true ) );
             // First check if the style exists in the document.
-            StyleSheetEntryPtr pEntry = m_pImpl->GetStyleSheetTable( )->FindStyleSheetByStyleName( sConvertedName );
+            StyleSheetEntryPtr pEntry = m_pImpl->GetStyleSheetTable( )->FindStyleSheetByConvertedStyleName( sConvertedName );
             bool bExists = pEntry.get( ) && ( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR );
-
-            // Add the property if the style exists
-            if ( bExists && m_pImpl->GetTopContext() )
+            // Add the property if the style exists, but do not add it elements in TOC:
+            // they will receive later another style references from TOC
+            if ( bExists && m_pImpl->GetTopContext() && !m_pImpl->IsInTOC())
                 m_pImpl->GetTopContext()->Insert( PROP_CHAR_STYLE_NAME, uno::makeAny( sConvertedName ) );
         }
     break;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 823450f2aab8..9bc53f2f4b90 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1383,7 +1383,18 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, const Proper
                     }
                 }
                 else
+                {
+                    if (IsOpenField() && GetTopFieldContext()->GetFieldId() == FIELD_HYPERLINK)
+                    {
+                        // It is content of hyperlink field. We need to create and remember
+                        // character style for later applying to hyperlink
+                        PropertyValueVector_t aProps = comphelper::sequenceToContainer< PropertyValueVector_t >(GetTopContext()->GetPropertyValues());
+                        OUString sHyperlinkStyleName = GetStyleSheetTable()->getOrCreateCharStyle(aProps, /*bAlwaysCreate=*/false);
+                        GetTopFieldContext()->SetHyperlinkStyle(sHyperlinkStyleName);
+                    }
+
                     xTextRange = xTextAppend->appendTextPortion(rString, aValues);
+                }
             }
 
             CheckRedline( xTextRange );
@@ -3708,6 +3719,8 @@ void DomainMapper_Impl::CloseFieldCommand()
                 aFieldConversionMap.find(std::get<0>(field));
             if(aIt != aFieldConversionMap.end())
             {
+                pContext->SetFieldId(aIt->second.eFieldId);
+
                 bool bCreateEnhancedField = false;
                 uno::Reference< beans::XPropertySet > xFieldProperties;
                 bool bCreateField = true;
@@ -4753,6 +4766,14 @@ void DomainMapper_Impl::PopFieldContext()
                                 xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::makeAny(sDisplayName));
                                 xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::makeAny(sDisplayName));
                             }
+                            else
+                            {
+                                if (!pContext->GetHyperlinkStyle().isEmpty())
+                                {
+                                    xCrsrProperties->setPropertyValue("VisitedCharStyleName", uno::makeAny(pContext->GetHyperlinkStyle()));
+                                    xCrsrProperties->setPropertyValue("UnvisitedCharStyleName", uno::makeAny(pContext->GetHyperlinkStyle()));
+                                }
+                            }
                         }
                         else if(m_bStartGenericField)
                         {
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index df22413a8cbd..bf5c2644e182 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -132,23 +132,27 @@ public:
 /// field stack element
 class FieldContext
 {
-    bool                                                                            m_bFieldCommandCompleted;
+    bool m_bFieldCommandCompleted;
     css::uno::Reference<css::text::XTextRange> m_xStartRange;
 
-    OUString                                                                 m_sCommand;
+    OUString m_sCommand;
     OUString m_sResult;
+    boost::optional<FieldId> m_eFieldId;
     bool m_bFieldLocked;
 
     css::uno::Reference<css::text::XTextField> m_xTextField;
-    css::uno::Reference<css::text::XFormField>  m_xFormField;
+    css::uno::Reference<css::text::XFormField> m_xFormField;
     css::uno::Reference<css::beans::XPropertySet> m_xTOC;
     css::uno::Reference<css::beans::XPropertySet> m_xTC; // TOX entry
     css::uno::Reference<css::beans::XPropertySet> m_xCustomField;
-    OUString                                                                 m_sHyperlinkURL;
+
+    OUString m_sHyperlinkURL;
     /// A frame for the hyperlink when one exists.
     OUString m_sHyperlinkTarget;
-    FFDataHandler::Pointer_t                                                        m_pFFDataHandler;
-    FormControlHelper::Pointer_t                                                    m_pFormControlHelper;
+    OUString m_sHyperlinkStyle;
+
+    FFDataHandler::Pointer_t m_pFFDataHandler;
+    FormControlHelper::Pointer_t m_pFormControlHelper;
     /// (Character) properties of the field itself.
     PropertyMapPtr m_pProperties;
 
@@ -161,6 +165,9 @@ public:
     void                    AppendCommand(const OUString& rPart);
     const OUString&  GetCommand() const {return m_sCommand; }
 
+    void SetFieldId(FieldId eFieldId ) { m_eFieldId = eFieldId; }
+    boost::optional<FieldId> GetFieldId() const { return m_eFieldId; }
+
     void AppendResult(OUString const& rResult) { m_sResult += rResult; }
     const OUString&  GetResult() const { return m_sResult; }
 
@@ -183,10 +190,12 @@ public:
     void SetTC(css::uno::Reference<css::beans::XPropertySet> const& xTC) { m_xTC = xTC; }
     const css::uno::Reference<css::beans::XPropertySet>& GetTC() { return m_xTC; }
 
-    void    SetHyperlinkURL( const OUString& rURL ) { m_sHyperlinkURL = rURL; }
-    const OUString&                                                      GetHyperlinkURL() { return m_sHyperlinkURL; }
+    void  SetHyperlinkURL( const OUString& rURL ) { m_sHyperlinkURL = rURL; }
+    const OUString& GetHyperlinkURL() { return m_sHyperlinkURL; }
     void SetHyperlinkTarget(const OUString& rTarget) { m_sHyperlinkTarget = rTarget; }
     const OUString& GetHyperlinkTarget() { return m_sHyperlinkTarget; }
+    void  SetHyperlinkStyle(const OUString& rStyle) { m_sHyperlinkStyle = rStyle; }
+    const OUString& GetHyperlinkStyle() { return m_sHyperlinkStyle; }
 
     void setFFDataHandler(FFDataHandler::Pointer_t pFFDataHandler) { m_pFFDataHandler = pFFDataHandler; }
     const FFDataHandler::Pointer_t& getFFDataHandler() const { return m_pFFDataHandler; }
@@ -203,7 +212,7 @@ struct TextAppendContext
     css::uno::Reference<css::text::XTextAppend> xTextAppend;
     css::uno::Reference<css::text::XTextRange> xInsertPosition;
     css::uno::Reference<css::text::XParagraphCursor> xCursor;
-    ParagraphPropertiesPtr                                                        pLastParagraphProperties;
+    ParagraphPropertiesPtr pLastParagraphProperties;
 
     TextAppendContext(const css::uno::Reference<css::text::XTextAppend>& xAppend, const css::uno::Reference<css::text::XTextCursor>& xCur)
         : xTextAppend(xAppend)
@@ -687,6 +696,8 @@ public:
     void PopPageHeaderFooter();
     bool IsInHeaderFooter() const { return m_bInHeaderFooterImport; }
 
+    bool IsInTOC() const { return m_bStartTOC; }
+
     void PushFootOrEndnote( bool bIsFootnote );
     void PopFootOrEndnote();
     bool IsInFootOrEndnote() const { return m_bInFootOrEndnote; }


More information about the Libreoffice-commits mailing list