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 |   17 +++++++++++++----
 5 files changed, 49 insertions(+), 8 deletions(-)

New commits:
commit d280a38913d37d5b58cd72ff3798ca4a89028197
Author: Vasily Melenchuk <vasily.melenc...@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
    
    Reviewed-on: https://gerrit.libreoffice.org/41784
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>
    (cherry picked from commit eaa9cf6a3069fba3d82c046f0041bfb537d9e648)
    
    Conflicts:
            sw/qa/extras/ooxmlimport/ooxmlimport.cxx
            writerfilter/source/dmapper/DomainMapper_Impl.hxx
    
    Change-Id: I1a228992eb7c1e259a6a811aa7f959debaae4f35

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 b55b17c05053..a9be7f45cb75 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -3286,6 +3286,17 @@ DECLARE_OOXMLIMPORT_TEST(testTdf96218, "tdf96218.docx")
     CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), "IsFollowingTextFlow"));
 }
 
+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 46aef6bf81c7..eec33d46246f 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2155,11 +2155,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 19d6f1a82985..c5ca29a02510 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1283,7 +1283,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 );
@@ -3572,6 +3583,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;
@@ -4547,6 +4560,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 ad96d4c77ef9..49b61d261b61 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -137,19 +137,21 @@ public:
  * --------------------------------------------------*/
 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_sHyperlinkStyle;
     FFDataHandler::Pointer_t                                                   
     m_pFFDataHandler;
     FormControlHelper::Pointer_t                                               
     m_pFormControlHelper;
     /// (Character) properties of the field itself.
@@ -164,6 +166,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; }
 
@@ -188,6 +193,8 @@ public:
 
     void    SetHyperlinkURL( const OUString& rURL ) { m_sHyperlinkURL = rURL; }
     const OUString&                                                      
GetHyperlinkURL() { return m_sHyperlinkURL; }
+    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; }
@@ -204,7 +211,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)
@@ -679,6 +686,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; }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to