LibreOffice Module sw (master)  1
htmlctxt.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/text/HoriOrientation.hpp>
21 #include <com/sun/star/text/VertOrientation.hpp>
22 
23 #include <hintids.hxx>
24 #include <svl/itemiter.hxx>
25 #include <editeng/lrspitem.hxx>
26 #include <editeng/ulspitem.hxx>
27 #include <editeng/brushitem.hxx>
28 #include <editeng/fhgtitem.hxx>
29 #include <svtools/htmltokn.h>
30 #include <editeng/boxitem.hxx>
31 #include <osl/diagnose.h>
32 
33 #include <doc.hxx>
34 #include <pam.hxx>
35 #include <shellio.hxx>
36 #include <paratr.hxx>
37 #include "htmlnum.hxx"
38 #include "swcss1.hxx"
39 #include "swhtml.hxx"
40 
41 #include <memory>
42 
43 using namespace ::com::sun::star;
44 
46 {
47  SwHTMLNumRuleInfo aNumRuleInfo; // Numbering for this environment
48  std::unique_ptr<SwPosition>
49  pPos; // Jump back to here when leaving context
50  std::shared_ptr<HTMLAttrTable>
51  xAttrTab; // Valid attributes for the environment,
52  // if attributes shouldn't be preserved
53 
54  size_t nContextStMin; // Stack lower bound for the environment
55  // if stack needs to be protected
56  size_t nContextStAttrMin; // Stack lower bound for the environment
57  // if the attributes shouldn't be preserved
59  bool bKeepNumRules : 1;
60  bool bFixHeaderDist : 1;
61  bool bFixFooterDist : 1;
62 
63 public:
64 
66  nContextStMin( SIZE_MAX ), nContextStAttrMin( SIZE_MAX ),
67  bStripTrailingPara( false ), bKeepNumRules( false ),
68  bFixHeaderDist( false ), bFixFooterDist( false )
69  {}
70 
71  // The position is ours, so we need to create and delete it
72  void SetPos( const SwPosition& rPos ) { pPos.reset( new SwPosition(rPos) ); }
73  const SwPosition *GetPos() const { return pPos.get(); }
74 
75  // The index isn't ours. So no creation or deletion
76  void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); }
77  const SwHTMLNumRuleInfo& GetNumInfo() const { return aNumRuleInfo; }
78 
79  std::shared_ptr<HTMLAttrTable> const & GetAttrTab(bool bCreate = false);
80 
81  void SetContextStMin( size_t nMin ) { nContextStMin = nMin; }
82  size_t GetContextStMin() const { return nContextStMin; }
83 
84  void SetContextStAttrMin( size_t nMin ) { nContextStAttrMin = nMin; }
85  size_t GetContextStAttrMin() const { return nContextStAttrMin; }
86 
87  void SetStripTrailingPara( bool bSet ) { bStripTrailingPara = bSet; }
88  bool GetStripTrailingPara() const { return bStripTrailingPara; }
89 
90  void SetKeepNumRules( bool bSet ) { bKeepNumRules = bSet; }
91  bool GetKeepNumRules() const { return bKeepNumRules; }
92 
93  void SetFixHeaderDist( bool bSet ) { bFixHeaderDist = bSet; }
94  bool GetFixHeaderDist() const { return bFixHeaderDist; }
95 
96  void SetFixFooterDist( bool bSet ) { bFixFooterDist = bSet; }
97  bool GetFixFooterDist() const { return bFixFooterDist; }
98 };
99 
100 std::shared_ptr<HTMLAttrTable> const & HTMLAttrContext_SaveDoc::GetAttrTab( bool bCreate )
101 {
102  if (!xAttrTab && bCreate)
103  {
104  xAttrTab = std::make_shared<HTMLAttrTable>();
105  memset(xAttrTab.get(), 0, sizeof(HTMLAttrTable));
106  }
107  return xAttrTab;
108 }
109 
111 {
112  if( !m_pSaveDocContext && bCreate )
114 
115  return m_pSaveDocContext.get();
116 }
117 
118 HTMLAttrContext::HTMLAttrContext( HtmlTokenId nTokn, sal_uInt16 nPoolId, const OUString& rClass,
119  bool bDfltColl ) :
120  m_aClass( rClass ),
121  m_nToken( nTokn ),
122  m_nTextFormatColl( nPoolId ),
123  m_nLeftMargin( 0 ),
124  m_nRightMargin( 0 ),
125  m_nFirstLineIndent( 0 ),
126  m_nUpperSpace( 0 ),
127  m_nLowerSpace( 0 ),
128  m_eAppend( AM_NONE ),
129  m_bLRSpaceChanged( false ),
130  m_bULSpaceChanged( false ),
131  m_bDefaultTextFormatColl( bDfltColl ),
132  m_bSpansSection( false ),
133  m_bPopStack( false ),
134  m_bFinishPREListingXMP( false ),
135  m_bRestartPRE( false ),
136  m_bRestartXMP( false ),
137  m_bRestartListing( false ),
138  m_bHeaderOrFooter( false )
139 {}
140 
142  m_nToken( nTokn ),
143  m_nTextFormatColl( 0 ),
144  m_nLeftMargin( 0 ),
145  m_nRightMargin( 0 ),
146  m_nFirstLineIndent( 0 ),
147  m_nUpperSpace( 0 ),
148  m_nLowerSpace( 0 ),
149  m_eAppend( AM_NONE ),
150  m_bLRSpaceChanged( false ),
151  m_bULSpaceChanged( false ),
152  m_bDefaultTextFormatColl( false ),
153  m_bSpansSection( false ),
154  m_bPopStack( false ),
155  m_bFinishPREListingXMP( false ),
156  m_bRestartPRE( false ),
157  m_bRestartXMP( false ),
158  m_bRestartListing( false ),
159  m_bHeaderOrFooter( false )
160 {}
161 
163 {
164  m_pSaveDocContext.reset();
165 }
166 
168 {
169  m_pSaveDocContext.reset();
170 }
171 
173 {
174  // preliminary paragraph attributes are not allowed here, they could
175  // be set here and then the pointers become invalid!
176  OSL_ENSURE(m_aParaAttrs.empty(),
177  "Danger: there are non-final paragraph attributes");
178  m_aParaAttrs.clear();
179 
180  const SwNodeIndex* pOldEndPara = &m_pPam->GetPoint()->nNode;
181 #ifndef NDEBUG
182  auto const nOld(pOldEndPara->GetIndex());
183 #endif
184  sal_Int32 nOldEndCnt = m_pPam->GetPoint()->nContent.GetIndex();
185 
186  const SwNodeIndex& rNewSttPara = rNewPos.nNode;
187  sal_Int32 nNewSttCnt = rNewPos.nContent.GetIndex();
188 
189  bool bMoveBack = false;
190 
191  // close all open attributes and re-open them after the table
192  HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get());
193  for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes)
194  {
195  HTMLAttr *pAttr = *pHTMLAttributes;
196  while( pAttr )
197  {
198  HTMLAttr *pNext = pAttr->GetNext();
199  HTMLAttr *pPrev = pAttr->GetPrev();
200 
201  sal_uInt16 nWhich = pAttr->m_pItem->Which();
202  if( !nOldEndCnt && RES_PARATR_BEGIN <= nWhich &&
203  pAttr->GetSttParaIdx() < pOldEndPara->GetIndex() )
204  {
205  // The attribute needs to be closed one content position beforehand
206  if( !bMoveBack )
207  {
208  bMoveBack = m_pPam->Move( fnMoveBackward );
209  nOldEndCnt = m_pPam->GetPoint()->nContent.GetIndex();
210  }
211  }
212  else if( bMoveBack )
213  {
215  nOldEndCnt = m_pPam->GetPoint()->nContent.GetIndex();
216  bMoveBack = false;
217  }
218 
219  if( (RES_PARATR_BEGIN <= nWhich && bMoveBack) ||
220  pAttr->GetSttParaIdx() < pOldEndPara->GetIndex() ||
221  (pAttr->GetSttPara() == *pOldEndPara &&
222  pAttr->GetSttCnt() != nOldEndCnt) )
223  {
224  // The attribute needs to be set. Because we still need the original, since
225  // pointers to the attribute still exists in the contexts, we need to clone it.
226  // The next-list gets lost but the previous-list is preserved
227  HTMLAttr *pSetAttr = pAttr->Clone( *pOldEndPara, nOldEndCnt );
228 
229  if( pNext )
230  pNext->InsertPrev( pSetAttr );
231  else
232  {
233  if (pSetAttr->m_bInsAtStart)
234  m_aSetAttrTab.push_front( pSetAttr );
235  else
236  m_aSetAttrTab.push_back( pSetAttr );
237  }
238  }
239  else if( pPrev )
240  {
241  // The previous attributes still need to be set, even if the current attribute
242  // doesn't need to be set before the table
243  if( pNext )
244  pNext->InsertPrev( pPrev );
245  else
246  {
247  if (pPrev->m_bInsAtStart)
248  m_aSetAttrTab.push_front( pPrev );
249  else
250  m_aSetAttrTab.push_back( pPrev );
251  }
252  }
253 
254  // Set the start of the attribute
255  pAttr->m_nStartPara = rNewSttPara;
256  pAttr->m_nEndPara = rNewSttPara;
257  pAttr->m_nStartContent = nNewSttCnt;
258  pAttr->m_nEndContent = nNewSttCnt;
259  pAttr->m_pPrev = nullptr;
260 
261  pAttr = pNext;
262  }
263  }
264 
265  if( bMoveBack )
267 
268  assert(m_pPam->GetPoint()->nNode.GetIndex() == nOld);
269 }
270 
272  HtmlContextFlags nFlags,
273  const SwPosition *pNewPos )
274 {
275  HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext( true );
276  pSave->SetStripTrailingPara( bool(HtmlContextFlags::StripPara & nFlags) );
277  pSave->SetKeepNumRules( bool(HtmlContextFlags::KeepNumrule & nFlags) );
278  pSave->SetFixHeaderDist( bool(HtmlContextFlags::HeaderDist & nFlags) );
279  pSave->SetFixFooterDist( bool(HtmlContextFlags::FooterDist & nFlags) );
280 
281  if( pNewPos )
282  {
283  // If the PaM needs to be set to a different position, we need to preserve numbering
284  if( !pSave->GetKeepNumRules() )
285  {
286  // Numbering shall not be preserved. So we need to preserve the current state
287  // and turn off numbering afterwards
288  pSave->SetNumInfo( GetNumInfo() );
289  GetNumInfo().Clear();
290  }
291 
292  if( HtmlContextFlags::KeepAttrs & nFlags )
293  {
294  // Close attribute on current position and start on new one
295  SplitAttrTab( *pNewPos );
296  }
297  else
298  {
299  std::shared_ptr<HTMLAttrTable> xSaveAttrTab = pSave->GetAttrTab(true);
300  SaveAttrTab(xSaveAttrTab);
301  }
302 
303  pSave->SetPos( *m_pPam->GetPoint() );
304  *m_pPam->GetPoint() = *pNewPos;
305  }
306 
307  // Settings nContextStMin automatically means, that no
308  // currently open lists (DL/OL/UL) can be closed
309  if( HtmlContextFlags::ProtectStack & nFlags )
310  {
312  m_nContextStMin = m_aContexts.size();
313 
314  if( HtmlContextFlags::KeepAttrs & nFlags )
315  {
318  }
319  }
320 }
321 
323 {
324  HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext();
325  if( !pSave )
326  return;
327 
328  if( pSave->GetStripTrailingPara() )
330 
331  if( pSave->GetPos() )
332  {
333  if( pSave->GetFixHeaderDist() || pSave->GetFixFooterDist() )
335  pSave->GetPos() );
336 
337  std::shared_ptr<HTMLAttrTable> xSaveAttrTab = pSave->GetAttrTab();
338  if (!xSaveAttrTab)
339  {
340  // Close attribute on current position and start on the old one
341  SplitAttrTab( *pSave->GetPos() );
342  }
343  else
344  {
345  RestoreAttrTab(xSaveAttrTab);
346  }
347 
348  *m_pPam->GetPoint() = *pSave->GetPos();
349 
350  // We can already set the attributes so far
351  SetAttr();
352  }
353 
354  if( SIZE_MAX != pSave->GetContextStMin() )
355  {
356  m_nContextStMin = pSave->GetContextStMin();
357  if( SIZE_MAX != pSave->GetContextStAttrMin() )
359  }
360 
361  if( !pSave->GetKeepNumRules() )
362  {
363  // Set the preserved numbering back
364  GetNumInfo().Set( pSave->GetNumInfo() );
365  }
366 
367  pCntxt->ClearSaveDocContext();
368 }
369 
371 {
372  if( pContext->GetPopStack() )
373  {
374  // Close all still open contexts. Our own context needs to be deleted already!
375  while( m_aContexts.size() > m_nContextStMin )
376  {
377  std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
378  OSL_ENSURE(xCntxt.get() != pContext,
379  "Context still on the stack" );
380  if (xCntxt.get() == pContext)
381  break;
382 
383  EndContext(xCntxt.get());
384  }
385  }
386 
387  // Close all still open attributes
388  if( pContext->HasAttrs() )
389  EndContextAttrs( pContext );
390 
391  // If a section has been opened, end it. Since sections can be part of absolute-positioned
392  // objects, this needs to be done before restoring document context
393  if( pContext->GetSpansSection() )
394  EndSection();
395 
396  // Leave borders and other special sections
397  if( pContext->HasSaveDocContext() )
398  RestoreDocContext( pContext );
399 
400  // Add a paragraph break if needed
401  if( AM_NONE != pContext->GetAppendMode() &&
403  AppendTextNode( pContext->GetAppendMode() );
404 
405  // Restart PRE, LISTING and XMP environments
406  if( pContext->IsFinishPREListingXMP() )
407  FinishPREListingXMP();
408 
409  if( pContext->IsRestartPRE() )
410  StartPRE();
411 
412  if( pContext->IsRestartXMP() )
413  StartXMP();
414 
415  if( pContext->IsRestartListing() )
416  StartListing();
417 }
418 
420 {
421  HTMLAttrs &rAttrs = pContext->GetAttrs();
422  for( auto pAttr : rAttrs )
423  {
424  // Simple deletion doesn't to the job, since the attribute
425  // needs to be deregistered with its list.
426  // In theory, you could delete the list and its attributes separately
427  // but if you get that wrong, quite a lot is messed up
428  DeleteAttr( pAttr );
429  }
430  rAttrs.clear();
431 
432  OSL_ENSURE( !pContext->GetSpansSection(),
433  "Area can no longer be exited" );
434 
435  OSL_ENSURE( !pContext->HasSaveDocContext(),
436  "Frame can no longer be exited" );
437 
438  // like RestoreDocContext reset enough of this to not catastrophically
439  // fail if we still have a SaveDocContext here
440  if (HTMLAttrContext_SaveDoc *pSave = pContext->GetSaveDocContext())
441  {
442  if (SIZE_MAX != pSave->GetContextStMin())
443  {
444  m_nContextStMin = pSave->GetContextStMin();
445  if (SIZE_MAX != pSave->GetContextStAttrMin())
446  m_nContextStAttrMin = pSave->GetContextStAttrMin();
447  }
448 
449  pContext->ClearSaveDocContext();
450  }
451 
452  // Restart PRE/LISTING/XMP environments
453  if( pContext->IsFinishPREListingXMP() )
454  FinishPREListingXMP();
455 
456  if( pContext->IsRestartPRE() )
457  StartPRE();
458 
459  if( pContext->IsRestartXMP() )
460  StartXMP();
461 
462  if( pContext->IsRestartListing() )
463  StartListing();
464 }
465 
467  SvxCSS1PropertyInfo &rPropInfo,
468  HTMLAttrContext *pContext )
469 {
470  bool bRet = false;
471 
472  // A border is opened on the following conditions
473  // - the tag is absolute-positioned AND left/top are both known AND don't contain a % property
474  // OR
475  // - the tag should be floating AND
476  // - there's a given width
477  if( SwCSS1Parser::MayBePositioned( rPropInfo ) )
478  {
479  SfxItemSet aFrameItemSet( m_xDoc->GetAttrPool(),
481  if( !IsNewDoc() )
482  Reader::ResetFrameFormatAttrs(aFrameItemSet );
483 
485  aFrameItemSet );
486 
487  SetVarSize( rPropInfo, aFrameItemSet );
488 
489  SetSpace( Size(0,0), rItemSet, rPropInfo, aFrameItemSet );
490 
491  SetFrameFormatAttrs( rItemSet,
493  aFrameItemSet );
494 
495  InsertFlyFrame(aFrameItemSet, pContext, rPropInfo.m_aId);
496  pContext->SetPopStack( true );
497  rPropInfo.m_aId.clear();
498  bRet = true;
499  }
500 
501  return bRet;
502 }
503 
504 bool SwHTMLParser::CreateContainer( const OUString& rClass,
505  SfxItemSet &rItemSet,
506  SvxCSS1PropertyInfo &rPropInfo,
507  HTMLAttrContext *pContext )
508 {
509  bool bRet = false;
510  if( rClass.equalsIgnoreAsciiCase( "sd-abs-pos" ) &&
511  SwCSS1Parser::MayBePositioned( rPropInfo ) )
512  {
513  // Container class
514  SfxItemSet *pFrameItemSet = pContext->GetFrameItemSet( m_xDoc.get() );
515  if( !IsNewDoc() )
516  Reader::ResetFrameFormatAttrs( *pFrameItemSet );
517 
519  rPropInfo, *pFrameItemSet );
520  Size aDummy(0,0);
521  SetFixSize( aDummy, aDummy, false, false, rPropInfo, *pFrameItemSet );
522  SetSpace( aDummy, rItemSet, rPropInfo, *pFrameItemSet );
524  *pFrameItemSet );
525 
526  bRet = true;
527  }
528 
529  return bRet;
530 }
531 
533  SvxCSS1PropertyInfo const &rPropInfo,
534  HTMLAttrContext *pContext,
535  bool bCharLvl )
536 {
537  // Put together a DropCap attribute, if a "float:left" is before the first character
538  if( bCharLvl && !m_pPam->GetPoint()->nContent.GetIndex() &&
539  SvxAdjust::Left == rPropInfo.m_eFloat )
540  {
541  SwFormatDrop aDrop;
542  aDrop.GetChars() = 1;
543 
544  m_pCSS1Parser->FillDropCap( aDrop, rItemSet );
545 
546  // We only set the DropCap attribute if the initial spans multiple lines
547  if( aDrop.GetLines() > 1 )
548  {
549  NewAttr(m_xAttrTab, &m_xAttrTab->pDropCap, aDrop);
550 
551  HTMLAttrs &rAttrs = pContext->GetAttrs();
552  rAttrs.push_back( m_xAttrTab->pDropCap );
553 
554  return;
555  }
556  }
557 
558  if( !bCharLvl )
559  m_pCSS1Parser->SetFormatBreak( rItemSet, rPropInfo );
560 
561  OSL_ENSURE(m_aContexts.size() <= m_nContextStAttrMin ||
562  m_aContexts.back().get() != pContext,
563  "SwHTMLParser::InsertAttrs: Context already on the Stack");
564 
565  SfxItemIter aIter( rItemSet );
566 
567  for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
568  {
569  HTMLAttr **ppAttr = nullptr;
570 
571  switch( pItem->Which() )
572  {
573  case RES_LR_SPACE:
574  {
575  // Paragraph indents need to be added and are generated for each paragraphs
576  // (here for the first paragraph only, all the following in SetTextCollAttrs)
577  const SvxLRSpaceItem *pLRItem =
578  static_cast<const SvxLRSpaceItem *>(pItem);
579 
580  // Get old paragraph indents without the top context (that's the one we're editing)
581  sal_uInt16 nOldLeft = 0, nOldRight = 0;
582  short nOldIndent = 0;
583  bool bIgnoreTop = m_aContexts.size() > m_nContextStMin &&
584  m_aContexts.back().get() == pContext;
585  GetMarginsFromContext( nOldLeft, nOldRight, nOldIndent,
586  bIgnoreTop );
587 
588  // ... and the currently valid ones
589  sal_uInt16 nLeft = nOldLeft, nRight = nOldRight;
590  short nIndent = nOldIndent;
591  pContext->GetMargins( nLeft, nRight, nIndent );
592 
593  // ... and add the new indents to the old ones
594  // Here, we don't get the ones from the item but the separately remembered ones,
595  // since they could be negative. Accessing those via the item still works, since
596  // the item (with value 0) will be added
597  if( rPropInfo.m_bLeftMargin )
598  {
599  OSL_ENSURE( rPropInfo.m_nLeftMargin < 0 ||
600  rPropInfo.m_nLeftMargin == pLRItem->GetTextLeft(),
601  "left margin does not match with item" );
602  if( rPropInfo.m_nLeftMargin < 0 &&
603  -rPropInfo.m_nLeftMargin > nOldLeft )
604  nLeft = 0;
605  else
606  nLeft = nOldLeft + static_cast< sal_uInt16 >(rPropInfo.m_nLeftMargin);
607  }
608  if( rPropInfo.m_bRightMargin )
609  {
610  OSL_ENSURE( rPropInfo.m_nRightMargin < 0 ||
611  rPropInfo.m_nRightMargin == pLRItem->GetRight(),
612  "right margin does not match with item" );
613  if( rPropInfo.m_nRightMargin < 0 &&
614  -rPropInfo.m_nRightMargin > nOldRight )
615  nRight = 0;
616  else
617  nRight = nOldRight + static_cast< sal_uInt16 >(rPropInfo.m_nRightMargin);
618  }
619  if( rPropInfo.m_bTextIndent )
620  nIndent = pLRItem->GetTextFirstLineOffset();
621 
622  // Remember the value for the following paragraphs
623  pContext->SetMargins( nLeft, nRight, nIndent );
624 
625  // Set the attribute on the current paragraph
626  SvxLRSpaceItem aLRItem( *pLRItem );
627  aLRItem.SetTextFirstLineOffset( nIndent );
628  aLRItem.SetTextLeft( nLeft );
629  aLRItem.SetRight( nRight );
630  NewAttr(m_xAttrTab, &m_xAttrTab->pLRSpace, aLRItem);
631  EndAttr( m_xAttrTab->pLRSpace, false );
632  }
633  break;
634 
635  case RES_UL_SPACE:
636  if( !rPropInfo.m_bTopMargin || !rPropInfo.m_bBottomMargin )
637  {
638  sal_uInt16 nUpper = 0, nLower = 0;
639  GetULSpaceFromContext( nUpper, nLower );
640  SvxULSpaceItem aULSpace( *static_cast<const SvxULSpaceItem *>(pItem) );
641  if( !rPropInfo.m_bTopMargin )
642  aULSpace.SetUpper( nUpper );
643  if( !rPropInfo.m_bBottomMargin )
644  aULSpace.SetLower( nLower );
645 
646  NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, aULSpace);
647 
648  // save context information
649  HTMLAttrs &rAttrs = pContext->GetAttrs();
650  rAttrs.push_back( m_xAttrTab->pULSpace );
651 
652  pContext->SetULSpace( aULSpace.GetUpper(), aULSpace.GetLower() );
653  }
654  else
655  {
656  ppAttr = &m_xAttrTab->pULSpace;
657  }
658  break;
659  case RES_CHRATR_FONTSIZE:
660  // don't set attributes with a % property
661  if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
662  ppAttr = &m_xAttrTab->pFontHeight;
663  break;
665  // don't set attributes with a % property
666  if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
667  ppAttr = &m_xAttrTab->pFontHeightCJK;
668  break;
670  // don't set attributes with a % property
671  if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
672  ppAttr = &m_xAttrTab->pFontHeightCTL;
673  break;
674 
675  case RES_BACKGROUND:
676  if( bCharLvl )
677  {
678  // Convert the Frame attribute to a Char attribute (if needed)
679  SvxBrushItem aBrushItem( *static_cast<const SvxBrushItem *>(pItem) );
680  aBrushItem.SetWhich( RES_CHRATR_BACKGROUND );
681 
682  // Set the attribute
683  NewAttr(m_xAttrTab, &m_xAttrTab->pCharBrush, aBrushItem);
684 
685  // and save context information
686  HTMLAttrs &rAttrs = pContext->GetAttrs();
687  rAttrs.push_back( m_xAttrTab->pCharBrush );
688  }
689  else if( pContext->GetToken() != HtmlTokenId::TABLEHEADER_ON &&
690  pContext->GetToken() != HtmlTokenId::TABLEDATA_ON )
691  {
692  ppAttr = &m_xAttrTab->pBrush;
693  }
694  break;
695 
696  case RES_BOX:
697  if( bCharLvl )
698  {
699  SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem *>(pItem) );
700  aBoxItem.SetWhich( RES_CHRATR_BOX );
701 
702  NewAttr(m_xAttrTab, &m_xAttrTab->pCharBox, aBoxItem);
703 
704  HTMLAttrs &rAttrs = pContext->GetAttrs();
705  rAttrs.push_back( m_xAttrTab->pCharBox );
706  }
707  else
708  {
709  ppAttr = &m_xAttrTab->pBox;
710  }
711  break;
712 
713  default:
714  ppAttr = GetAttrTabEntry( pItem->Which() );
715  break;
716  }
717 
718  if( ppAttr )
719  {
720  // Set the attribute
721  NewAttr(m_xAttrTab, ppAttr, *pItem);
722 
723  // and save context information
724  HTMLAttrs &rAttrs = pContext->GetAttrs();
725  rAttrs.push_back( *ppAttr );
726  }
727  }
728 
729  if( !rPropInfo.m_aId.isEmpty() )
730  InsertBookmark( rPropInfo.m_aId );
731 }
732 
733 void SwHTMLParser::InsertAttr( HTMLAttr **ppAttr, const SfxPoolItem & rItem,
734  HTMLAttrContext *pCntxt )
735 {
736  if( !ppAttr )
737  {
738  ppAttr = GetAttrTabEntry( rItem.Which() );
739  if( !ppAttr )
740  return;
741  }
742 
743  // Set the attribute
744  NewAttr(m_xAttrTab, ppAttr, rItem);
745 
746  // save context information
747  HTMLAttrs &rAttrs = pCntxt->GetAttrs();
748  rAttrs.push_back( *ppAttr );
749 }
750 
752 {
753  // PRE/Listing/XMP need to be finished when finishing context
754  pCntxt->SetFinishPREListingXMP( true );
755 
756  // And set all now valid flags
757  if( IsReadPRE() )
758  pCntxt->SetRestartPRE( true );
759  if( IsReadXMP() )
760  pCntxt->SetRestartXMP( true );
761  if( IsReadListing() )
762  pCntxt->SetRestartListing( true );
763 
764  FinishPREListingXMP();
765 }
766 
768 {
769  if( !m_pFrameItemSet && pCreateDoc )
770  m_pFrameItemSet = std::make_unique<SfxItemSet>( pCreateDoc->GetAttrPool(),
772  return m_pFrameItemSet.get();
773 }
774 
775 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool EndSection(bool bLFStripped=false)
Definition: htmlsect.cxx:503
static void SetSpace(const Size &rPixSpace, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:241
void SetAnchorAndAdjustment(sal_Int16 eVertOri, sal_Int16 eHoriOri, const SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFrameSet)
Definition: htmlgrin.cxx:149
bool GetKeepNumRules() const
Definition: htmlctxt.cxx:91
void SplitPREListingXMP(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:751
bool IsFinishPREListingXMP() const
Definition: swhtml.hxx:278
size_t GetContextStAttrMin() const
Definition: htmlctxt.cxx:85
bool HasSaveDocContext() const
Definition: swhtml.hxx:271
Marks a position in the document model.
Definition: pam.hxx:35
std::unique_ptr< HTMLAttrContext_SaveDoc > m_pSaveDocContext
Definition: swhtml.hxx:209
void SetAttr(bool bChkEnd=true, bool bBeforeTable=false, std::deque< std::unique_ptr< HTMLAttr >> *pPostIts=nullptr)
Definition: swhtml.hxx:489
sal_Int32 GetSttCnt() const
Definition: swhtml.hxx:164
sal_uInt16 GetLower() const
HTMLAttrs m_aSetAttrTab
Definition: swhtml.hxx:360
void SetContextStAttrMin(size_t nMin)
Definition: htmlctxt.cxx:84
void FixHeaderFooterDistance(bool bHeader, const SwPosition *pOldPos)
Definition: htmlsect.cxx:413
bool m_bInsAtStart
Definition: swhtml.hxx:133
SwNodeIndex nNode
Definition: pam.hxx:37
void SaveAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3269
void InsertBookmark(const OUString &rName)
Definition: htmlgrin.cxx:1350
void Set(const SwHTMLNumRuleInfo &rInf)
Definition: htmlnum.hxx:93
sal_uInt8 GetLines() const
Definition: paratr.hxx:86
std::unique_ptr< SfxItemSet > m_pFrameItemSet
Definition: swhtml.hxx:210
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
HTMLAttr * GetNext() const
Definition: swhtml.hxx:173
void NewAttr(const std::shared_ptr< HTMLAttrTable > &rAttrTab, HTMLAttr **ppAttr, const SfxPoolItem &rItem)
Definition: swhtml.cxx:3033
void SetRestartListing(bool bSet)
Definition: swhtml.hxx:286
Definition: doc.hxx:186
HTMLAttrContexts m_aContexts
Definition: swhtml.hxx:363
const SfxItemSet * GetFrameItemSet() const
Definition: swhtml.hxx:274
void SetTextLeft(const long nL, const sal_uInt16 nProp=100)
const SwNodeIndex & GetSttPara() const
Definition: swhtml.hxx:161
constexpr TypedWhichId< SvxBoxItem > RES_CHRATR_BOX(40)
bool HasAttrs() const
Definition: swhtml.hxx:261
void SplitAttrTab(const SwPosition &rNewPos)
Definition: htmlctxt.cxx:172
SwNodeIndex m_nStartPara
Definition: swhtml.hxx:131
void SetULSpace(sal_uInt16 nUpper, sal_uInt16 nLower)
Definition: swhtml.hxx:980
void SetMargins(sal_uInt16 nLeft, sal_uInt16 nRight, short nIndent)
Definition: swhtml.hxx:959
static void ResetFrameFormatAttrs(SfxItemSet &rFrameSet)
Definition: shellio.cxx:612
void RestoreDocContext(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:322
constexpr sal_uInt16 RES_PARATR_BEGIN(RES_TXTATR_END)
std::shared_ptr< HTMLAttrTable > const & GetAttrTab(bool bCreate=false)
Definition: htmlctxt.cxx:100
void GetMarginsFromContext(sal_uInt16 &nLeft, sal_uInt16 &nRight, short &nIndent, bool bIgnoreCurrent=false) const
Definition: htmlcss1.cxx:2149
SwIndex nContent
Definition: pam.hxx:38
void InsertAttrs(std::deque< std::unique_ptr< HTMLAttr >> rAttrs)
Definition: swhtml.cxx:3434
const HTMLAttrs & GetAttrs() const
Definition: swhtml.hxx:262
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
const SwPosition * GetPos() const
Definition: htmlctxt.cxx:73
HtmlContextFlags
Definition: swhtml.hxx:304
bool IsRestartListing() const
Definition: swhtml.hxx:287
SwPaM * m_pPam
Definition: swhtml.hxx:377
bool CreateContainer(const OUString &rClass, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:504
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
void InsertAttr(const SfxPoolItem &rItem, bool bInsAtStart)
Definition: swhtml.cxx:3425
sal_Int32 m_nEndContent
Definition: swhtml.hxx:132
static void SetFrameFormatAttrs(SfxItemSet &rItemSet, HtmlFrameFormatFlags nFlags, SfxItemSet &rFrameItemSet)
Definition: htmlcss1.cxx:2072
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:501
SwNodeIndex m_nEndPara
Definition: swhtml.hxx:131
void SetRight(const long nR, const sal_uInt16 nProp=100)
void DeleteAttr(HTMLAttr *pAttr)
Definition: swhtml.cxx:3211
std::deque< HTMLAttr * > HTMLAttrs
Definition: swhtml.hxx:72
HTMLAttr * GetPrev() const
Definition: swhtml.hxx:176
void SetKeepNumRules(bool bSet)
Definition: htmlctxt.cxx:90
void EndContextAttrs(HTMLAttrContext *pContext)
Definition: htmlcss1.cxx:2223
const SwPosition * GetPoint() const
Definition: pam.hxx:207
sal_Int32 m_nStartContent
Definition: swhtml.hxx:132
std::shared_ptr< HTMLAttrTable > xAttrTab
Definition: htmlctxt.cxx:51
std::unique_ptr< SwCSS1Parser > m_pCSS1Parser
Definition: swhtml.hxx:372
void SetContextStMin(size_t nMin)
Definition: htmlctxt.cxx:81
HTMLAttrContext(HtmlTokenId nTokn, sal_uInt16 nPoolId, const OUString &rClass, bool bDfltColl=false)
Definition: htmlctxt.cxx:118
void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp=100)
HTMLAttr * m_pPrev
Definition: swhtml.hxx:140
void EndContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:370
std::unique_ptr< SwPosition > pPos
Definition: htmlctxt.cxx:49
std::unique_ptr< HTMLAttrContext > PopContext(HtmlTokenId nToken=HtmlTokenId::NONE)
Definition: htmlcss1.cxx:2109
size_t GetContextStMin() const
Definition: htmlctxt.cxx:82
bool GetPopStack() const
Definition: swhtml.hxx:269
void StripTrailingPara()
Definition: htmlgrin.cxx:1405
bool DoPositioning(SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:466
void SetStripTrailingPara(bool bSet)
Definition: htmlctxt.cxx:87
short GetTextFirstLineOffset() const
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwHTMLNumRuleInfo & GetNumInfo() const
Definition: htmlctxt.cxx:77
HTMLAttr * Clone(const SwNodeIndex &rEndPara, sal_Int32 nEndCnt) const
Definition: swhtml.cxx:5487
sal_uInt8 GetChars() const
Definition: paratr.hxx:89
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
bool IsRestartPRE() const
Definition: swhtml.hxx:281
void InsertFlyFrame(const SfxItemSet &rItemSet, HTMLAttrContext *pCntxt, const OUString &rId)
Definition: htmlsect.cxx:761
void GetMargins(sal_uInt16 &nLeft, sal_uInt16 &nRight, short &nIndent) const
Definition: swhtml.hxx:968
HTMLAttrContext_SaveDoc * GetSaveDocContext(bool bCreate=false)
Definition: htmlctxt.cxx:110
bool IsRestartXMP() const
Definition: swhtml.hxx:284
size_t m_nContextStMin
Definition: swhtml.hxx:402
HtmlTokenId
constexpr sal_uInt16 RES_FRMATR_END(131)
void SetFixFooterDist(bool bSet)
Definition: htmlctxt.cxx:96
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_BACKGROUND(21)
SwHTMLNumRuleInfo aNumRuleInfo
Definition: htmlctxt.cxx:47
HTMLAttrs m_aParaAttrs
Definition: swhtml.hxx:361
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
void SetNumInfo(const SwHTMLNumRuleInfo &rInf)
Definition: htmlctxt.cxx:76
void SetPopStack(bool bSet)
Definition: swhtml.hxx:268
bool GetStripTrailingPara() const
Definition: htmlctxt.cxx:88
HtmlTokenId GetToken() const
Definition: swhtml.hxx:244
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
void GetULSpaceFromContext(sal_uInt16 &rUpper, sal_uInt16 &rLower) const
Definition: htmlcss1.cxx:2190
void ClearContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:419
sal_Int32 GetIndex() const
Definition: index.hxx:95
SwHTMLNumRuleInfo & GetNumInfo()
Definition: swhtml.hxx:539
void SetPos(const SwPosition &rPos)
Definition: htmlctxt.cxx:72
bool EndAttr(HTMLAttr *pAttr, bool bChkEmpty=true)
Definition: swhtml.cxx:3049
HTMLAttr ** GetAttrTabEntry(sal_uInt16 nWhich)
Definition: htmlcss1.cxx:1535
bool GetFixHeaderDist() const
Definition: htmlctxt.cxx:94
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
static void SetVarSize(SvxCSS1PropertyInfo const &rPropInfo, SfxItemSet &rFlyItemSet, SwTwips nDfltWidth=MINLAY, sal_uInt8 nDefaultPercentWidth=0)
Definition: htmlcss1.cxx:2033
void SetFinishPREListingXMP(bool bSet)
Definition: swhtml.hxx:277
void SetRestartXMP(bool bSet)
Definition: swhtml.hxx:283
size_t m_nContextStAttrMin
Definition: swhtml.hxx:403
void RestoreAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3395
constexpr TypedWhichId< SvxBoxItem > RES_BOX(106)
long GetRight() const
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
bool GetFixFooterDist() const
Definition: htmlctxt.cxx:97
void SetRestartPRE(bool bSet)
Definition: swhtml.hxx:280
std::shared_ptr< HTMLAttrTable > m_xAttrTab
Definition: swhtml.hxx:362
void ClearSaveDocContext()
Definition: htmlctxt.cxx:167
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps...
Definition: paratr.hxx:50
bool AppendTextNode(SwHTMLAppendMode eMode=AM_NORMAL, bool bUpdateNum=true)
Definition: swhtml.cxx:2155
SwHTMLAppendMode GetAppendMode() const
Definition: swhtml.hxx:293
long GetTextLeft() const
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
rtl::Reference< SwDoc > m_xDoc
Definition: swhtml.hxx:376
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
void SaveDocContext(HTMLAttrContext *pCntxt, HtmlContextFlags nFlags, const SwPosition *pNewPos)
Definition: htmlctxt.cxx:271
constexpr sal_uInt16 RES_FRMATR_BEGIN(RES_PARATR_LIST_END)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(92)
void SetFixHeaderDist(bool bSet)
Definition: htmlctxt.cxx:93
std::unique_ptr< SfxPoolItem > m_pItem
Definition: swhtml.hxx:137
sal_uInt32 GetSttParaIdx() const
Definition: swhtml.hxx:158
void InsertPrev(HTMLAttr *pPrv)
Definition: swhtml.cxx:5514
sal_uInt16 Which() const
bool GetSpansSection() const
Definition: swhtml.hxx:266
static void SetFixSize(const Size &rPixSize, const Size &rTwipDfltSize, bool bPercentWidth, bool bPercentHeight, SvxCSS1PropertyInfo const &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:163
static bool MayBePositioned(const SvxCSS1PropertyInfo &rPropInfo, bool bAutoWidth=false)
Definition: htmlcss1.cxx:1425
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1317
sal_uInt16 GetUpper() const