editeng/source/editeng/eertfpar.cxx |   34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

New commits:
commit 1ed564ecb73f2cab3a921a5bde67b9db48ea04a3
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Mon Nov 18 14:13:05 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Wed Nov 20 21:29:59 2024 +0100

    tdf#163967 RTF: Pasting/loading hyperlink imports font color and underline
    
    Hyperlinks are typically colored and underlined. The RTF import
    - also used when pasting from clipbard - now evaluates font color
    and underline in the field result.
    
    Change-Id: I725fc3e94746c96d68379c021fb0c12cd3750096
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176714
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins

diff --git a/editeng/source/editeng/eertfpar.cxx 
b/editeng/source/editeng/eertfpar.cxx
index 615147f4c148..deacdfa5905a 100644
--- a/editeng/source/editeng/eertfpar.cxx
+++ b/editeng/source/editeng/eertfpar.cxx
@@ -28,6 +28,8 @@
 #include <editeng/fontitem.hxx>
 #include <editeng/flditem.hxx>
 #include <editeng/editeng.hxx>
+#include <editeng/udlnitem.hxx>
+#include <editeng/colritem.hxx>
 
 #include <svtools/rtftoken.h>
 #include <svtools/htmltokn.h>
@@ -517,12 +519,16 @@ void EditRTFParser::ReadField()
     int _nOpenBrackets = 1;      // the first was already detected earlier
     bool bFldInst = false;
     bool bFldRslt = false;
+    bool bUnderline = false;
+    Color aColor;
+    bool bColor = false;
     OUString aFldInst;
     OUString aFldRslt;
 
     while( _nOpenBrackets && IsParserWorking() )
     {
-        switch( GetNextToken() )
+        auto nNextToken = GetNextToken();
+        switch( nNextToken )
         {
             case '}':
             {
@@ -555,6 +561,21 @@ void EditRTFParser::ReadField()
                     aFldRslt += aToken;
             }
             break;
+            case RTF_CF:
+            {
+                if (bFldRslt)
+                {
+                    aColor = GetColor(sal_uInt16(nTokenValue));
+                    bColor = true;
+                }
+            }
+            break;
+            case RTF_UL:
+            {
+                if (bFldRslt)
+                    bUnderline = true;
+            }
+            break;
         }
     }
     if ( !aFldInst.isEmpty() )
@@ -572,6 +593,17 @@ void EditRTFParser::ReadField()
 
             SvxFieldItem aField( SvxURLField( aFldInst, aFldRslt, 
SvxURLFormat::Repr ), EE_FEATURE_FIELD  );
             aCurSel = mpEditEngine->InsertField(aCurSel, aField);
+            if (bUnderline || bColor )
+            {
+                SfxItemSet aAttribs( mpEditEngine->GetEmptyItemSet() );
+                if (bUnderline)
+                   aAttribs.Put(SvxUnderlineItem(LINESTYLE_SINGLE, 
EE_CHAR_UNDERLINE));
+                if (bColor)
+                   aAttribs.Put(SvxColorItem(aColor, EE_CHAR_COLOR));
+                EditSelection aAttribSelection(aCurSel.Min(), aCurSel.Max());
+                
aAttribSelection.Min().SetIndex(aAttribSelection.Min().GetIndex() - 1);
+                mpEditEngine->SetAttribs(aAttribSelection, aAttribs, 
SetAttribsMode::Edge);
+            }
             mpEditEngine->UpdateFieldsOnly();
             bLastActionInsertParaBreak = false;
         }

Reply via email to