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