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.behrens@allotropia.de> Tested-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de> Tested-by: Jenkins
This commit is contained in:
committed by
Thorsten Behrens
parent
2bb92e0a9d
commit
1ed564ecb7
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user