1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
/* -*- 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 .
*/
#ifndef INCLUDED_EDITENG_SVXRTF_HXX
#define INCLUDED_EDITENG_SVXRTF_HXX
#include <svl/itemset.hxx>
#include <svtools/parrtf.hxx>
#include <rtl/ustring.hxx>
#include <editeng/editengdllapi.h>
#include <deque>
#include <utility>
#include <vector>
#include <boost/ptr_container/ptr_map.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
class Font;
class Color;
class Graphic;
class DateTime;
struct SvxRTFStyleType;
class SvxRTFItemStackType;
class SvxRTFItemStackList : public boost::ptr_vector<SvxRTFItemStackType> {};
namespace com { namespace sun { namespace star {
namespace document {
class XDocumentProperties;
}
namespace util {
struct DateTime;
}
} } }
// Mapper-Classes for the various requirements on Document positions
// Swg - NodePosition is a SwIndex, which is used internally
// EditEngine - ULONG to list of paragraphs
class SvxNodeIdx
{
public:
virtual ~SvxNodeIdx() {}
virtual sal_Int32 GetIdx() const = 0;
virtual SvxNodeIdx* Clone() const = 0; // Cloning itself
};
class SvxPosition
{
public:
virtual ~SvxPosition() {}
virtual sal_Int32 GetNodeIdx() const = 0;
virtual sal_Int32 GetCntIdx() const = 0;
virtual SvxPosition* Clone() const = 0; // Cloning itself
virtual SvxNodeIdx* MakeNodeIdx() const = 0; // Cloning NodeIndex
};
typedef Color* ColorPtr;
typedef std::deque< ColorPtr > SvxRTFColorTbl;
typedef boost::ptr_map<short, Font> SvxRTFFontTbl;
typedef boost::ptr_map<sal_uInt16, SvxRTFStyleType> SvxRTFStyleTbl;
// SvxRTFItemStack can't be "std::stack< SvxRTFItemStackType* >" type, because
// the methods are using operator[] in sw/source/filter/rtf/rtftbl.cxx file
typedef std::deque< SvxRTFItemStackType* > SvxRTFItemStack;
// own helper classes for the RTF Parser
struct SvxRTFStyleType
{
SfxItemSet aAttrSet; // the attributes of Style (+ derivate!)
OUString sName;
sal_uInt16 nBasedOn, nNext;
bool bBasedOnIsSet;
sal_uInt8 nOutlineNo;
bool bIsCharFmt;
SvxRTFStyleType( SfxItemPool& rPool, const sal_uInt16* pWhichRange );
};
// Here are the IDs for all character attributes, which can be detected by
// SvxParser and can be set in a SfxItemSet. The IDs are set correctly throught
// the SlotIds from POOL.
struct RTFPlainAttrMapIds
{
sal_uInt16 nCaseMap,
nBgColor,
nColor,
nContour,
nCrossedOut,
nEscapement,
nFont,
nFontHeight,
nKering,
nLanguage,
nPosture,
nShadowed,
nUnderline,
nOverline,
nWeight,
nWordlineMode,
nAutoKerning,
nCJKFont,
nCJKFontHeight,
nCJKLanguage,
nCJKPosture,
nCJKWeight,
nCTLFont,
nCTLFontHeight,
nCTLLanguage,
nCTLPosture,
nCTLWeight,
nEmphasis,
nTwoLines,
nCharScaleX,
nHorzVert,
nRuby,
nRelief,
nHidden
;
RTFPlainAttrMapIds( const SfxItemPool& rPool );
};
// Here are the IDs for all paragraph attributes, which can be detected by
// SvxParser and can be set in a SfxItemSet. The IDs are set correctly throught
// the SlotIds from POOL.
struct RTFPardAttrMapIds
{
sal_uInt16 nLinespacing,
nAdjust,
nTabStop,
nHyphenzone,
nLRSpace,
nULSpace,
nBrush,
nBox,
nShadow,
nOutlineLvl,
nSplit,
nKeep,
nFontAlign,
nScriptSpace,
nHangPunct,
nForbRule,
nDirection
;
RTFPardAttrMapIds( const SfxItemPool& rPool );
};
class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser
{
SvStream &rStrm;
SvxRTFColorTbl aColorTbl;
SvxRTFFontTbl aFontTbl;
SvxRTFStyleTbl aStyleTbl;
SvxRTFItemStack aAttrStack;
SvxRTFItemStackList aAttrSetList;
std::vector<sal_uInt16> aPlainMap;
std::vector<sal_uInt16> aPardMap;
std::vector<sal_uInt16> aWhichMap;
OUString sBaseURL;
SvxPosition* pInsPos;
SfxItemPool* pAttrPool;
Color* pDfltColor;
Font* pDfltFont;
::com::sun::star::uno::Reference<
::com::sun::star::document::XDocumentProperties> m_xDocProps;
SfxItemSet *pRTFDefaults;
long nVersionNo;
int nDfltFont;
bool bNewDoc : 1; // sal_False - Reading in an existing
bool bNewGroup : 1; // sal_True - there was an opening parenthesis
bool bIsSetDfltTab : 1; // sal_True - DefTab was loaded
bool bChkStyleAttr : 1; // sal_True - StyleSheets are evaluated
bool bCalcValue : 1; // sal_True - Twip values adapt to App
bool bPardTokenRead : 1; // sal_True - Token \pard was detected
bool bReadDocInfo : 1; // sal_True - DocInfo to read
bool bIsLeftToRightDef : 1; // sal_True - in LeftToRight char run def.
// sal_False - in RightToLeft char run def.
bool bIsInReadStyleTab : 1; // sal_True - in ReadStyleTable
void ClearColorTbl();
void ClearFontTbl();
void ClearStyleTbl();
void ClearAttrStack();
SvxRTFItemStackType* _GetAttrSet( int bCopyAttr=sal_False ); // Create new ItemStackType:s
void _ClearStyleAttr( SvxRTFItemStackType& rStkType );
// Sets all the attributes that are different from the current
void SetAttrSet( SfxItemSet& rAttrSet, SvxPosition& rSttPos );
void SetAttrSet( SvxRTFItemStackType &rSet );
void SetDefault( int nToken, int nValue );
// Excecute pard / plain
void RTFPardPlain( int bPard, SfxItemSet** ppSet );
void BuildWhichTbl();
enum RTF_CharTypeDef
{
NOTDEF_CHARTYPE,
LOW_CHARTYPE,
HIGH_CHARTYPE,
DOUBLEBYTE_CHARTYPE
};
// set latin/asian/complex character attributes
void SetScriptAttr(
RTF_CharTypeDef eType, SfxItemSet& rSet, SfxPoolItem& rItem );
protected:
virtual void EnterEnvironment();
virtual void LeaveEnvironment();
virtual void ResetPard();
virtual void InsertPara() = 0;
OUString& DelCharAtEnd( OUString& rStr, const sal_Unicode cDel );
// is called for each token that is recognized in CallParser
virtual void NextToken( int nToken ) SAL_OVERRIDE;
virtual void ReadBitmapData() SAL_OVERRIDE;
virtual void ReadOLEData() SAL_OVERRIDE;
void ReadStyleTable();
void ReadColorTable();
void ReadFontTable();
void ReadAttr( int nToken, SfxItemSet* pSet );
void ReadTabAttr( int nToken, SfxItemSet& rSet );
// Read Document-Info
::com::sun::star::util::DateTime GetDateTimeStamp( );
OUString& GetTextToEndGroup( OUString& rStr );
virtual void ReadInfo( const sal_Char* pChkForVerNo = 0 );
inline SfxItemSet& GetAttrSet();
// no text yet inserted? (SttPos from the top stack entry!)
bool IsAttrSttPos();
void AttrGroupEnd(); // edit the current, delete from stack
void SetAllAttrOfStk(); // end all Attr. and set it into doc
virtual void InsertText() = 0;
virtual void MovePos( int bForward = sal_True ) = 0;
virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos,
sal_Int32& rCntPos )=0;
virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
// for Tokens, which are not evaluated in ReadAttr
virtual void UnknownAttrToken( int nToken, SfxItemSet* pSet );
// if no-one would like to have any twips
virtual void CalcValue();
SvxRTFParser( SfxItemPool& rAttrPool,
SvStream& rIn,
::com::sun::star::uno::Reference<
::com::sun::star::document::XDocumentProperties> i_xDocProps,
int bReadNewDoc = sal_True );
virtual ~SvxRTFParser();
bool IsNewDoc() const { return bNewDoc; }
void SetNewDoc( bool bFlag ) { bNewDoc = bFlag; }
bool IsNewGroup() const { return bNewGroup; }
void SetNewGroup( bool bFlag ) { bNewGroup = bFlag; }
bool IsChkStyleAttr() const { return bChkStyleAttr; }
void SetChkStyleAttr( bool bFlag ) { bChkStyleAttr = bFlag; }
bool IsCalcValue() const { return bCalcValue; }
void SetCalcValue( bool bFlag ) { bCalcValue = bFlag; }
bool IsPardTokenRead() const { return bPardTokenRead; }
void SetPardTokenRead( bool bFlag ) { bPardTokenRead = bFlag; }
bool IsReadDocInfo() const { return bReadDocInfo; }
void SetReadDocInfo( bool bFlag ) { bReadDocInfo = bFlag; }
// Query/Set the current insert position
SvxPosition& GetInsPos() const { return *pInsPos; }
void SetInsPos( const SvxPosition& rNew );
long GetVersionNo() const { return nVersionNo; }
// Query/Set the mapping IDs for the Pard/Plain attributes
//(Set: It is noted in the pointers, which thus does not create a copy)
void AddPardAttr( sal_uInt16 nWhich ) { aPardMap.push_back( nWhich ); }
void AddPlainAttr( sal_uInt16 nWhich ) { aPlainMap.push_back( nWhich ); }
SvxRTFStyleTbl& GetStyleTbl() { return aStyleTbl; }
SvxRTFItemStack& GetAttrStack() { return aAttrStack; }
SvxRTFColorTbl& GetColorTbl() { return aColorTbl; }
SvxRTFFontTbl& GetFontTbl() { return aFontTbl; }
const OUString& GetBaseURL() const { return sBaseURL; }
public:
virtual SvParserState CallParser() SAL_OVERRIDE;
inline const Color& GetColor( size_t nId ) const;
const Font& GetFont( sal_uInt16 nId ); // Changes the default Font
virtual bool IsEndPara( SvxNodeIdx* pNd, sal_Int32 nCnt ) const = 0;
// to det a different attribute pool. May only be done prior to CallParser!
// The maps are not generated anew!
void SetAttrPool( SfxItemPool* pNewPool ) { pAttrPool = pNewPool; }
// to set different WhichIds for a different pool.
RTFPardAttrMapIds& GetPardMap()
{ return (RTFPardAttrMapIds&)*aPardMap.begin(); }
RTFPlainAttrMapIds& GetPlainMap()
{ return (RTFPlainAttrMapIds&)*aPlainMap.begin(); }
// to be able to assign them from the outside as for example table cells
void ReadBorderAttr( int nToken, SfxItemSet& rSet, int bTableDef=sal_False );
void ReadBackgroundAttr( int nToken, SfxItemSet& rSet, int bTableDef=sal_False );
// for asynchronous read from the SvStream
virtual void Continue( int nToken ) SAL_OVERRIDE;
// get RTF default ItemSets. Must be used by pard/plain tokens or in
// reset of Style-Items
const SfxItemSet& GetRTFDefaults();
virtual bool UncompressableStackEntry(const SvxRTFItemStackType &rSet) const;
};
// The stack for the attributes:
// this class may only be used by SvxRTFParser!
class EDITENG_DLLPUBLIC SvxRTFItemStackType
{
friend class SvxRTFParser;
SfxItemSet aAttrSet;
SvxNodeIdx *pSttNd, *pEndNd;
sal_Int32 nSttCnt, nEndCnt;
SvxRTFItemStackList* pChildList;
sal_uInt16 nStyleNo;
SvxRTFItemStackType( SfxItemPool&, const sal_uInt16* pWhichRange,
const SvxPosition& );
void Add( SvxRTFItemStackType* );
void Compress( const SvxRTFParser& );
public:
SvxRTFItemStackType( const SvxRTFItemStackType&, const SvxPosition&,
int bCopyAttr = sal_False );
~SvxRTFItemStackType();
//cmc, I'm very suspicios about SetStartPos, it doesn't change
//its children's starting position, and the implementation looks
//bad, consider this deprecated.
void SetStartPos( const SvxPosition& rPos );
void MoveFullNode(const SvxNodeIdx &rOldNode,
const SvxNodeIdx &rNewNode);
sal_Int32 GetSttNodeIdx() const { return pSttNd->GetIdx(); }
sal_Int32 GetEndNodeIdx() const { return pEndNd->GetIdx(); }
const SvxNodeIdx& GetSttNode() const { return *pSttNd; }
const SvxNodeIdx& GetEndNode() const { return *pEndNd; }
sal_Int32 GetSttCnt() const { return nSttCnt; }
sal_Int32 GetEndCnt() const { return nEndCnt; }
SfxItemSet& GetAttrSet() { return aAttrSet; }
const SfxItemSet& GetAttrSet() const { return aAttrSet; }
sal_uInt16 StyleNo() const { return nStyleNo; }
void SetRTFDefaults( const SfxItemSet& rDefaults );
};
// ----------- Inline Implementations --------------
inline const Color& SvxRTFParser::GetColor( size_t nId ) const
{
ColorPtr pColor = (ColorPtr)pDfltColor;
if( nId < aColorTbl.size() )
pColor = aColorTbl[ nId ];
return *pColor;
}
inline SfxItemSet& SvxRTFParser::GetAttrSet()
{
SvxRTFItemStackType* pTmp;
if( bNewGroup || 0 == ( pTmp = aAttrStack.empty() ? 0 : aAttrStack.back()) )
pTmp = _GetAttrSet();
return pTmp->aAttrSet;
}
#endif
// INCLUDED_EDITENG_SVXRTF_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|