/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Convert the twips values ...
SetCalcValue(true);
SetChkStyleAttr(mpEditEngine->IsImportRTFStyleSheetsSet());
SetNewDoc(false); // So that the Pool-Defaults are not overwritten...
aEditMapMode = MapMode(mpEditEngine->GetRefDevice()->GetMapMode().GetMapUnit());
}
EditRTFParser::~EditRTFParser()
{
}
SvParserState EditRTFParser::CallParser()
{
DBG_ASSERT( !aCurSel.HasRange(), "Selection for CallParser!" ); // Separate the part that is imported from the rest. // This expression should be used for all imports. // aStart1PaM: Last position before the imported content // aEnd1PaM: First position after the imported content // aStart2PaM: First position of the imported content // aEnd2PaM: Last position of the imported content
EditPaM aStart1PaM( aCurSel.Min().GetNode(), aCurSel.Min().GetIndex() );
aCurSel = mpEditEngine->InsertParaBreak(aCurSel);
EditPaM aStart2PaM = aCurSel.Min(); // Useful or not?
aStart2PaM.GetNode()->GetContentAttribs().GetItems().ClearItem();
AddRTFDefaultValues( aStart2PaM, aStart2PaM );
EditPaM aEnd1PaM = mpEditEngine->InsertParaBreak(EditSelection(aCurSel.Max())); // aCurCel now points to the gap
if (mpEditEngine->IsRtfImportHandlerSet())
{
RtfImportInfo aImportInfo(RtfImportState::Start, this, mpEditEngine->CreateESelection(aCurSel));
mpEditEngine->CallRtfImportHandler(aImportInfo);
}
void EditRTFParser::NextToken( int nToken )
{ switch( nToken )
{ case RTF_DEFF:
{
nDefFont = sal_uInt16(nTokenValue);
} break; case RTF_DEFTAB: break; case RTF_CELL:
{
aCurSel = mpEditEngine->InsertParaBreak(aCurSel);
} break; case RTF_LINE:
{
aCurSel = mpEditEngine->InsertLineBreak(aCurSel);
} break; case RTF_FIELD:
{
ReadField();
} break; case RTF_SHPINST: // fdo#76776 process contents of shpinst break; case RTF_SP: // fdo#76776 but skip SP groups
{
SkipGroup();
} break; case RTF_LISTTEXT:
{
SkipGroup();
} break; default:
{
SvxRTFParser::NextToken( nToken ); if ( nToken == RTF_STYLESHEET )
CreateStyleSheets();
} break;
} if (mpEditEngine->IsRtfImportHandlerSet())
{
RtfImportInfo aImportInfo(RtfImportState::NextToken, this, mpEditEngine->CreateESelection(aCurSel));
aImportInfo.nToken = nToken;
aImportInfo.nTokenValue = short(nTokenValue);
mpEditEngine->CallRtfImportHandler(aImportInfo);
}
}
void EditRTFParser::UnknownAttrToken( int nToken )
{ // for Tokens which are not evaluated in ReadAttr // Actually, only for Calc (RTFTokenHdl), so that RTF_INTBL if (mpEditEngine->IsRtfImportHandlerSet())
{
RtfImportInfo aImportInfo(RtfImportState::UnknownAttr, this, mpEditEngine->CreateESelection(aCurSel));
aImportInfo.nToken = nToken;
aImportInfo.nTokenValue = short(nTokenValue);
mpEditEngine->CallRtfImportHandler(aImportInfo);
}
}
void EditRTFParser::SetEndPrevPara( std::optional<EditNodeIdx>& rpNodePos,
sal_Int32& rCntPos )
{ // The Intention is to: determine the current insert position of the // previous paragraph and set the end from this. // This "\pard" always apply on the right paragraph.
if (rSet.StyleNo() && mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet())
{
SvxRTFStyleTbl::iterator it = GetStyleTbl().find( rSet.StyleNo() );
DBG_ASSERT( it != GetStyleTbl().end(), "Template not defined in RTF!" ); if ( it != GetStyleTbl().end() )
{ autoconst& pS = it->second;
mpEditEngine->SetStyleSheet(
EditSelection(aStartPaM, aEndPaM), static_cast<SfxStyleSheet*>(mpEditEngine->GetStyleSheetPool()->Find(pS.sName, SfxStyleFamily::All)));
nOutlLevel = pS.nOutlineNo;
}
}
// When an Attribute goes from 0 to the current paragraph length, // it should be a paragraph attribute!
// Note: Selection can reach over several paragraphs. // All Complete paragraphs are paragraph attributes ... for ( sal_Int32 z = nStartNode+1; z < nEndNode; z++ )
{
DBG_ASSERT(mpEditEngine->GetEditDoc().GetObject(z), "Node does not exist yet(RTF)");
mpEditEngine->SetParaAttribsOnly(z, rSet.GetAttrSet());
}
if ( aStartPaM.GetNode() != aEndPaM.GetNode() )
{ // The rest of the StartNodes... if ( aStartPaM.GetIndex() == 0 )
mpEditEngine->SetParaAttribsOnly(nStartNode, rSet.GetAttrSet()); else
mpEditEngine->SetAttribs(
EditSelection(aStartPaM, EditPaM(aStartPaM.GetNode(), aStartPaM.GetNode()->Len())), rSet.GetAttrSet());
// the beginning of the EndNodes... if ( aEndPaM.GetIndex() == aEndPaM.GetNode()->Len() )
mpEditEngine->SetParaAttribsOnly(nEndNode, rSet.GetAttrSet()); else
mpEditEngine->SetAttribs(
EditSelection(EditPaM(aEndPaM.GetNode(), 0), aEndPaM), rSet.GetAttrSet());
} else
{ if ( ( aStartPaM.GetIndex() == 0 ) && ( aEndPaM.GetIndex() == aEndPaM.GetNode()->Len() ) )
{ // When settings char attribs as para attribs, we must merge with existing attribs, not overwrite the ItemSet!
SfxItemSet aAttrs = mpEditEngine->GetBaseParaAttribs(nStartNode);
aAttrs.Put( rSet.GetAttrSet() );
mpEditEngine->SetParaAttribsOnly(nStartNode, aAttrs);
} else
{
mpEditEngine->SetAttribs(
EditSelection(aStartPaM, aEndPaM), rSet.GetAttrSet());
}
}
// OutlLevel... if ( nOutlLevel != 0xff )
{ for ( sal_Int32 n = nStartNode; n <= nEndNode; n++ )
{
ContentNode* pNode = mpEditEngine->GetEditDoc().GetObject( n );
pNode->GetContentAttribs().GetItems().Put( SfxInt16Item( EE_PARA_OUTLLEVEL, nOutlLevel ) );
}
}
}
SvxRTFStyleType* EditRTFParser::FindStyleSheet( std::u16string_view rName )
{
SvxRTFStyleTbl& rTable = GetStyleTbl(); for (auto & iter : rTable)
{ if (iter.second.sName == rName) return &iter.second;
} return nullptr;
}
SfxStyleSheet* EditRTFParser::CreateStyleSheet( SvxRTFStyleType const * pRTFStyle )
{ // Check if a template exists, then it will not be changed!
SfxStyleSheet* pStyle = static_cast<SfxStyleSheet*>(mpEditEngine->GetStyleSheetPool()->Find( pRTFStyle->sName, SfxStyleFamily::All )); if ( pStyle ) return pStyle;
OUString aName( pRTFStyle->sName );
OUString aParent; if ( pRTFStyle->nBasedOn )
{
SvxRTFStyleTbl::iterator it = GetStyleTbl().find( pRTFStyle->nBasedOn ); if ( it != GetStyleTbl().end())
{
SvxRTFStyleType const& rS = it->second; if ( &rS != pRTFStyle )
aParent = rS.sName;
}
}
// 1) convert and take over Items ...
ConvertAndPutItems( pStyle->GetItemSet(), pRTFStyle->aAttrSet );
// 2) As long as Parent is not in the pool, also create this ... if ( !aParent.isEmpty() && ( aParent != aName ) )
{
SfxStyleSheet* pS = static_cast<SfxStyleSheet*>(mpEditEngine->GetStyleSheetPool()->Find( aParent, SfxStyleFamily::All )); if ( !pS )
{ // If not found anywhere, create from RTF ...
SvxRTFStyleType* _pRTFStyle = FindStyleSheet( aParent ); if ( _pRTFStyle )
pS = CreateStyleSheet( _pRTFStyle );
} // 2b) Link Itemset with Parent ... if ( pS )
pStyle->GetItemSet().SetParent( &pS->GetItemSet() );
} return pStyle;
}
void EditRTFParser::CreateStyleSheets()
{ // the SvxRTFParser has now created the template... if (mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet())
{ for (auto & elem : GetStyleTbl())
{
SvxRTFStyleType& rRTFStyle = elem.second;
CreateStyleSheet( &rRTFStyle );
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.