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 #include <o3tl/string_view.hxx>
33 
34 #include <doc.hxx>
35 #include <pam.hxx>
36 #include <shellio.hxx>
37 #include <paratr.hxx>
38 #include "htmlnum.hxx"
39 #include "swcss1.hxx"
40 #include "swhtml.hxx"
41 
42 #include <memory>
43 
44 using namespace ::com::sun::star;
45 
47 {
48  SwHTMLNumRuleInfo m_aNumRuleInfo; // Numbering for this environment
49  std::unique_ptr<SwPosition>
50  m_pPos; // Jump back to here when leaving context
51  std::shared_ptr<HTMLAttrTable>
52  m_xAttrTab; // Valid attributes for the environment,
53  // if attributes shouldn't be preserved
54 
55  size_t m_nContextStMin; // Stack lower bound for the environment
56  // if stack needs to be protected
57  size_t m_nContextStAttrMin; // Stack lower bound for the environment
58  // if the attributes shouldn't be preserved
60  bool m_bKeepNumRules : 1;
61  bool m_bFixHeaderDist : 1;
62  bool m_bFixFooterDist : 1;
63 
64 public:
65 
67  m_nContextStMin( SIZE_MAX ), m_nContextStAttrMin( SIZE_MAX ),
70  {}
71 
72  // The position is ours, so we need to create and delete it
73  void SetPos( const SwPosition& rPos ) { m_pPos.reset( new SwPosition(rPos) ); }
74  const SwPosition *GetPos() const { return m_pPos.get(); }
75 
76  // The index isn't ours. So no creation or deletion
77  void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { m_aNumRuleInfo.Set(rInf); }
78  const SwHTMLNumRuleInfo& GetNumInfo() const { return m_aNumRuleInfo; }
79 
80  std::shared_ptr<HTMLAttrTable> const & GetAttrTab(bool bCreate = false);
81 
82  void SetContextStMin( size_t nMin ) { m_nContextStMin = nMin; }
83  size_t GetContextStMin() const { return m_nContextStMin; }
84 
85  void SetContextStAttrMin( size_t nMin ) { m_nContextStAttrMin = nMin; }
86  size_t GetContextStAttrMin() const { return m_nContextStAttrMin; }
87 
88  void SetStripTrailingPara( bool bSet ) { m_bStripTrailingPara = bSet; }
89  bool GetStripTrailingPara() const { return m_bStripTrailingPara; }
90 
91  void SetKeepNumRules( bool bSet ) { m_bKeepNumRules = bSet; }
92  bool GetKeepNumRules() const { return m_bKeepNumRules; }
93 
94  void SetFixHeaderDist( bool bSet ) { m_bFixHeaderDist = bSet; }
95  bool GetFixHeaderDist() const { return m_bFixHeaderDist; }
96 
97  void SetFixFooterDist( bool bSet ) { m_bFixFooterDist = bSet; }
98  bool GetFixFooterDist() const { return m_bFixFooterDist; }
99 };
100 
101 std::shared_ptr<HTMLAttrTable> const & HTMLAttrContext_SaveDoc::GetAttrTab( bool bCreate )
102 {
103  if (!m_xAttrTab && bCreate)
104  {
105  m_xAttrTab = std::make_shared<HTMLAttrTable>();
106  memset(m_xAttrTab.get(), 0, sizeof(HTMLAttrTable));
107  }
108  return m_xAttrTab;
109 }
110 
112 {
113  if( !m_pSaveDocContext && bCreate )
115 
116  return m_pSaveDocContext.get();
117 }
118 
119 HTMLAttrContext::HTMLAttrContext( HtmlTokenId nTokn, sal_uInt16 nPoolId, const OUString& rClass,
120  bool bDfltColl ) :
121  m_aClass( rClass ),
122  m_nToken( nTokn ),
123  m_nTextFormatColl( nPoolId ),
124  m_nLeftMargin( 0 ),
125  m_nRightMargin( 0 ),
126  m_nFirstLineIndent( 0 ),
127  m_nUpperSpace( 0 ),
128  m_nLowerSpace( 0 ),
129  m_eAppend( AM_NONE ),
130  m_bLRSpaceChanged( false ),
131  m_bULSpaceChanged( false ),
132  m_bDefaultTextFormatColl( bDfltColl ),
133  m_bSpansSection( false ),
134  m_bPopStack( false ),
135  m_bFinishPREListingXMP( false ),
136  m_bRestartPRE( false ),
137  m_bRestartXMP( false ),
138  m_bRestartListing( false ),
139  m_bHeaderOrFooter( false )
140 {}
141 
143  m_nToken( nTokn ),
144  m_nTextFormatColl( 0 ),
145  m_nLeftMargin( 0 ),
146  m_nRightMargin( 0 ),
147  m_nFirstLineIndent( 0 ),
148  m_nUpperSpace( 0 ),
149  m_nLowerSpace( 0 ),
150  m_eAppend( AM_NONE ),
151  m_bLRSpaceChanged( false ),
152  m_bULSpaceChanged( false ),
153  m_bDefaultTextFormatColl( false ),
154  m_bSpansSection( false ),
155  m_bPopStack( false ),
156  m_bFinishPREListingXMP( false ),
157  m_bRestartPRE( false ),
158  m_bRestartXMP( false ),
159  m_bRestartListing( false ),
160  m_bHeaderOrFooter( false )
161 {}
162 
164 {
165  m_pSaveDocContext.reset();
166 }
167 
169 {
170  m_pSaveDocContext.reset();
171 }
172 
174 {
175  // preliminary paragraph attributes are not allowed here, they could
176  // be set here and then the pointers become invalid!
177  OSL_ENSURE(m_aParaAttrs.empty(),
178  "Danger: there are non-final paragraph attributes");
179  m_aParaAttrs.clear();
180 
181  const SwNodeIndex* pOldEndPara = &m_pPam->GetPoint()->nNode;
182 #ifndef NDEBUG
183  auto const nOld(pOldEndPara->GetIndex());
184 #endif
185  sal_Int32 nOldEndCnt = m_pPam->GetPoint()->nContent.GetIndex();
186 
187  const SwNodeIndex& rNewSttPara = rNewPos.nNode;
188  sal_Int32 nNewSttCnt = rNewPos.nContent.GetIndex();
189 
190  bool bMoveBack = false;
191 
192  // close all open attributes and re-open them after the table
193  HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get());
194  for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes)
195  {
196  HTMLAttr *pAttr = *pHTMLAttributes;
197  while( pAttr )
198  {
199  HTMLAttr *pNext = pAttr->GetNext();
200  HTMLAttr *pPrev = pAttr->GetPrev();
201 
202  sal_uInt16 nWhich = pAttr->m_pItem->Which();
203  if( !nOldEndCnt && RES_PARATR_BEGIN <= nWhich &&
204  pAttr->GetStartParagraphIdx() < pOldEndPara->GetIndex() )
205  {
206  // The attribute needs to be closed one content position beforehand
207  if( !bMoveBack )
208  {
209  bMoveBack = m_pPam->Move( fnMoveBackward );
210  nOldEndCnt = m_pPam->GetPoint()->nContent.GetIndex();
211  }
212  }
213  else if( bMoveBack )
214  {
216  nOldEndCnt = m_pPam->GetPoint()->nContent.GetIndex();
217  bMoveBack = false;
218  }
219 
220  if( (RES_PARATR_BEGIN <= nWhich && bMoveBack) ||
221  pAttr->GetStartParagraphIdx() < pOldEndPara->GetIndex() ||
222  (pAttr->GetStartParagraph() == *pOldEndPara &&
223  pAttr->GetStartContent() != nOldEndCnt) )
224  {
225  // The attribute needs to be set. Because we still need the original, since
226  // pointers to the attribute still exists in the contexts, we need to clone it.
227  // The next-list gets lost but the previous-list is preserved
228  HTMLAttr *pSetAttr = pAttr->Clone( *pOldEndPara, nOldEndCnt );
229 
230  if( pNext )
231  pNext->InsertPrev( pSetAttr );
232  else
233  {
234  if (pSetAttr->m_bInsAtStart)
235  m_aSetAttrTab.push_front( pSetAttr );
236  else
237  m_aSetAttrTab.push_back( pSetAttr );
238  }
239  }
240  else if( pPrev )
241  {
242  // The previous attributes still need to be set, even if the current attribute
243  // doesn't need to be set before the table
244  if( pNext )
245  pNext->InsertPrev( pPrev );
246  else
247  {
248  if (pPrev->m_bInsAtStart)
249  m_aSetAttrTab.push_front( pPrev );
250  else
251  m_aSetAttrTab.push_back( pPrev );
252  }
253  }
254 
255  // Set the start of the attribute
256  pAttr->m_nStartPara = rNewSttPara;
257  pAttr->m_nEndPara = rNewSttPara;
258  pAttr->m_nStartContent = nNewSttCnt;
259  pAttr->m_nEndContent = nNewSttCnt;
260  pAttr->m_pPrev = nullptr;
261 
262  pAttr = pNext;
263  }
264  }
265 
266  if( bMoveBack )
268 
269  assert(m_pPam->GetPoint()->nNode.GetIndex() == nOld);
270 }
271 
273  HtmlContextFlags nFlags,
274  const SwPosition *pNewPos )
275 {
276  HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext( true );
277  pSave->SetStripTrailingPara( bool(HtmlContextFlags::StripPara & nFlags) );
278  pSave->SetKeepNumRules( bool(HtmlContextFlags::KeepNumrule & nFlags) );
279  pSave->SetFixHeaderDist( bool(HtmlContextFlags::HeaderDist & nFlags) );
280  pSave->SetFixFooterDist( bool(HtmlContextFlags::FooterDist & nFlags) );
281 
282  if( pNewPos )
283  {
284  // If the PaM needs to be set to a different position, we need to preserve numbering
285  if( !pSave->GetKeepNumRules() )
286  {
287  // Numbering shall not be preserved. So we need to preserve the current state
288  // and turn off numbering afterwards
289  pSave->SetNumInfo( GetNumInfo() );
290  GetNumInfo().Clear();
291  }
292 
293  if( HtmlContextFlags::KeepAttrs & nFlags )
294  {
295  // Close attribute on current position and start on new one
296  SplitAttrTab( *pNewPos );
297  }
298  else
299  {
300  std::shared_ptr<HTMLAttrTable> xSaveAttrTab = pSave->GetAttrTab(true);
301  SaveAttrTab(xSaveAttrTab);
302  }
303 
304  pSave->SetPos( *m_pPam->GetPoint() );
305  *m_pPam->GetPoint() = *pNewPos;
306  }
307 
308  // Settings nContextStMin automatically means, that no
309  // currently open lists (DL/OL/UL) can be closed
310  if( HtmlContextFlags::ProtectStack & nFlags )
311  {
313  m_nContextStMin = m_aContexts.size();
314 
315  if( HtmlContextFlags::KeepAttrs & nFlags )
316  {
319  }
320  }
321 }
322 
324 {
325  HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext();
326  if( !pSave )
327  return;
328 
329  if( pSave->GetStripTrailingPara() )
331 
332  if( pSave->GetPos() )
333  {
334  if( pSave->GetFixHeaderDist() || pSave->GetFixFooterDist() )
336  pSave->GetPos() );
337 
338  std::shared_ptr<HTMLAttrTable> xSaveAttrTab = pSave->GetAttrTab();
339  if (!xSaveAttrTab)
340  {
341  // Close attribute on current position and start on the old one
342  SplitAttrTab( *pSave->GetPos() );
343  }
344  else
345  {
346  RestoreAttrTab(xSaveAttrTab);
347  }
348 
349  *m_pPam->GetPoint() = *pSave->GetPos();
350 
351  // We can already set the attributes so far
352  SetAttr();
353  }
354 
355  if( SIZE_MAX != pSave->GetContextStMin() )
356  {
357  m_nContextStMin = pSave->GetContextStMin();
358  if( SIZE_MAX != pSave->GetContextStAttrMin() )
360  }
361 
362  if( !pSave->GetKeepNumRules() )
363  {
364  // Set the preserved numbering back
365  GetNumInfo().Set( pSave->GetNumInfo() );
366  }
367 
368  pCntxt->ClearSaveDocContext();
369 }
370 
372 {
373  if( pContext->GetPopStack() )
374  {
375  // Close all still open contexts. Our own context needs to be deleted already!
376  while( m_aContexts.size() > m_nContextStMin )
377  {
378  std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
379  OSL_ENSURE(xCntxt.get() != pContext,
380  "Context still on the stack" );
381  if (xCntxt.get() == pContext)
382  break;
383 
384  EndContext(xCntxt.get());
385  }
386  }
387 
388  // Close all still open attributes
389  if( pContext->HasAttrs() )
390  EndContextAttrs( pContext );
391 
392  // If a section has been opened, end it. Since sections can be part of absolute-positioned
393  // objects, this needs to be done before restoring document context
394  if( pContext->GetSpansSection() )
395  EndSection();
396 
397  // Leave borders and other special sections
398  if( pContext->HasSaveDocContext() )
399  RestoreDocContext( pContext );
400 
401  // Add a paragraph break if needed
402  if( AM_NONE != pContext->GetAppendMode() &&
404  AppendTextNode( pContext->GetAppendMode() );
405 
406  // Restart PRE, LISTING and XMP environments
407  if( pContext->IsFinishPREListingXMP() )
408  FinishPREListingXMP();
409 
410  if( pContext->IsRestartPRE() )
411  StartPRE();
412 
413  if( pContext->IsRestartXMP() )
414  StartXMP();
415 
416  if( pContext->IsRestartListing() )
417  StartListing();
418 }
419 
421 {
422  HTMLAttrs &rAttrs = pContext->GetAttrs();
423  for( auto pAttr : rAttrs )
424  {
425  // Simple deletion doesn't to the job, since the attribute
426  // needs to be deregistered with its list.
427  // In theory, you could delete the list and its attributes separately
428  // but if you get that wrong, quite a lot is messed up
429  DeleteAttr( pAttr );
430  }
431  rAttrs.clear();
432 
433  OSL_ENSURE( !pContext->GetSpansSection(),
434  "Area can no longer be exited" );
435 
436  OSL_ENSURE( !pContext->HasSaveDocContext(),
437  "Frame can no longer be exited" );
438 
439  // like RestoreDocContext reset enough of this to not catastrophically
440  // fail if we still have a SaveDocContext here
441  if (HTMLAttrContext_SaveDoc *pSave = pContext->GetSaveDocContext())
442  {
443  if (SIZE_MAX != pSave->GetContextStMin())
444  {
445  m_nContextStMin = pSave->GetContextStMin();
446  if (SIZE_MAX != pSave->GetContextStAttrMin())
447  m_nContextStAttrMin = pSave->GetContextStAttrMin();
448  }
449 
450  pContext->ClearSaveDocContext();
451  }
452 
453  // Restart PRE/LISTING/XMP environments
454  if( pContext->IsFinishPREListingXMP() )
455  FinishPREListingXMP();
456 
457  if( pContext->IsRestartPRE() )
458  StartPRE();
459 
460  if( pContext->IsRestartXMP() )
461  StartXMP();
462 
463  if( pContext->IsRestartListing() )
464  StartListing();
465 }
466 
468  SvxCSS1PropertyInfo &rPropInfo,
469  HTMLAttrContext *pContext )
470 {
471  bool bRet = false;
472 
473  // A border is opened on the following conditions
474  // - the tag is absolute-positioned AND left/top are both known AND don't contain a % property
475  // OR
476  // - the tag should be floating AND
477  // - there's a given width
478  if( SwCSS1Parser::MayBePositioned( rPropInfo ) )
479  {
480  SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END-1> 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( std::u16string_view rClass,
505  SfxItemSet &rItemSet,
506  SvxCSS1PropertyInfo &rPropInfo,
507  HTMLAttrContext *pContext )
508 {
509  bool bRet = false;
510  if( o3tl::equalsIgnoreAsciiCase( rClass, u"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 )
771  ( 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:512
static void SetSpace(const Size &rPixSpace, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:243
void SetAnchorAndAdjustment(sal_Int16 eVertOri, sal_Int16 eHoriOri, const SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFrameSet)
Definition: htmlgrin.cxx:151
bool GetKeepNumRules() const
Definition: htmlctxt.cxx:92
void SplitPREListingXMP(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:751
bool IsFinishPREListingXMP() const
Definition: swhtml.hxx:282
void SetRight(const tools::Long nR, const sal_uInt16 nProp=100)
size_t GetContextStAttrMin() const
Definition: htmlctxt.cxx:86
bool HasSaveDocContext() const
Definition: swhtml.hxx:275
Marks a position in the document model.
Definition: pam.hxx:36
std::unique_ptr< HTMLAttrContext_SaveDoc > m_pSaveDocContext
Definition: swhtml.hxx:211
void SetAttr(bool bChkEnd=true, bool bBeforeTable=false, std::deque< std::unique_ptr< HTMLAttr >> *pPostIts=nullptr)
Definition: swhtml.hxx:508
sal_uInt16 GetLower() const
HTMLAttrs m_aSetAttrTab
Definition: swhtml.hxx:376
void SetContextStAttrMin(size_t nMin)
Definition: htmlctxt.cxx:85
void FixHeaderFooterDistance(bool bHeader, const SwPosition *pOldPos)
Definition: htmlsect.cxx:424
bool m_bInsAtStart
Definition: swhtml.hxx:135
SwNodeIndex nNode
Definition: pam.hxx:38
bool CreateContainer(std::u16string_view rClass, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:504
void SaveAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3321
void InsertBookmark(const OUString &rName)
Definition: htmlgrin.cxx:1353
void Set(const SwHTMLNumRuleInfo &rInf)
Definition: htmlnum.hxx:93
sal_uInt8 GetLines() const
Definition: paratr.hxx:101
tools::Long GetRight() const
std::unique_ptr< SfxItemSet > m_pFrameItemSet
Definition: swhtml.hxx:212
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
HTMLAttr * GetNext() const
Definition: swhtml.hxx:175
void NewAttr(const std::shared_ptr< HTMLAttrTable > &rAttrTab, HTMLAttr **ppAttr, const SfxPoolItem &rItem)
Definition: swhtml.cxx:3085
void SetRestartListing(bool bSet)
Definition: swhtml.hxx:290
Definition: doc.hxx:187
constexpr sal_uInt16 RES_FRMATR_END(133)
HTMLAttrContexts m_aContexts
Definition: swhtml.hxx:379
const SfxItemSet * GetFrameItemSet() const
Definition: swhtml.hxx:278
constexpr TypedWhichId< SvxBoxItem > RES_CHRATR_BOX(40)
bool HasAttrs() const
Definition: swhtml.hxx:265
void SplitAttrTab(const SwPosition &rNewPos)
Definition: htmlctxt.cxx:173
SwNodeIndex m_nStartPara
Definition: swhtml.hxx:131
void SetULSpace(sal_uInt16 nUpper, sal_uInt16 nLower)
Definition: swhtml.hxx:997
void SetMargins(sal_uInt16 nLeft, sal_uInt16 nRight, short nIndent)
Definition: swhtml.hxx:976
static void ResetFrameFormatAttrs(SfxItemSet &rFrameSet)
Definition: shellio.cxx:613
void SetTextLeft(const tools::Long nL, const sal_uInt16 nProp=100)
void RestoreDocContext(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:323
constexpr sal_uInt16 RES_PARATR_BEGIN(RES_TXTATR_END)
std::shared_ptr< HTMLAttrTable > const & GetAttrTab(bool bCreate=false)
Definition: htmlctxt.cxx:101
void GetMarginsFromContext(sal_uInt16 &nLeft, sal_uInt16 &nRight, short &nIndent, bool bIgnoreCurrent=false) const
Definition: htmlcss1.cxx:2140
SwIndex nContent
Definition: pam.hxx:39
void InsertAttrs(std::deque< std::unique_ptr< HTMLAttr >> rAttrs)
Definition: swhtml.cxx:3486
sal_Int32 GetStartContent() const
Definition: swhtml.hxx:166
const HTMLAttrs & GetAttrs() const
Definition: swhtml.hxx:266
const SwPosition * GetPos() const
Definition: htmlctxt.cxx:74
HtmlContextFlags
Definition: swhtml.hxx:311
bool IsRestartListing() const
Definition: swhtml.hxx:291
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:161
SwPaM * m_pPam
Definition: swhtml.hxx:393
SwHTMLNumRuleInfo m_aNumRuleInfo
Definition: htmlctxt.cxx:48
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
std::unique_ptr< SwPosition > m_pPos
Definition: htmlctxt.cxx:50
void InsertAttr(const SfxPoolItem &rItem, bool bInsAtStart)
Definition: swhtml.cxx:3477
sal_Int32 m_nEndContent
Definition: swhtml.hxx:134
static void SetFrameFormatAttrs(SfxItemSet &rItemSet, HtmlFrameFormatFlags nFlags, SfxItemSet &rFrameItemSet)
Definition: htmlcss1.cxx:2061
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:502
SwNodeIndex m_nEndPara
Definition: swhtml.hxx:132
tools::Long GetTextLeft() const
void DeleteAttr(HTMLAttr *pAttr)
Definition: swhtml.cxx:3263
std::deque< HTMLAttr * > HTMLAttrs
Definition: swhtml.hxx:74
HTMLAttr * GetPrev() const
Definition: swhtml.hxx:178
void SetKeepNumRules(bool bSet)
Definition: htmlctxt.cxx:91
void EndContextAttrs(HTMLAttrContext *pContext)
Definition: htmlcss1.cxx:2214
const SwPosition * GetPoint() const
Definition: pam.hxx:208
sal_Int32 m_nStartContent
Definition: swhtml.hxx:133
std::unique_ptr< SwCSS1Parser > m_pCSS1Parser
Definition: swhtml.hxx:388
SwNodeOffset GetStartParagraphIdx() const
Definition: swhtml.hxx:160
void SetContextStMin(size_t nMin)
Definition: htmlctxt.cxx:82
HTMLAttrContext(HtmlTokenId nTokn, sal_uInt16 nPoolId, const OUString &rClass, bool bDfltColl=false)
Definition: htmlctxt.cxx:119
void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp=100)
HTMLAttr * m_pPrev
Definition: swhtml.hxx:142
void EndContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:371
float u
std::unique_ptr< HTMLAttrContext > PopContext(HtmlTokenId nToken=HtmlTokenId::NONE)
Definition: htmlcss1.cxx:2100
tools::Long m_nRightMargin
Definition: svxcss1.hxx:135
size_t GetContextStMin() const
Definition: htmlctxt.cxx:83
std::shared_ptr< HTMLAttrTable > m_xAttrTab
Definition: htmlctxt.cxx:52
bool GetPopStack() const
Definition: swhtml.hxx:273
void StripTrailingPara()
Definition: htmlgrin.cxx:1408
bool DoPositioning(SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:467
void SetStripTrailingPara(bool bSet)
Definition: htmlctxt.cxx:88
short GetTextFirstLineOffset() const
Marks a node in the document model.
Definition: ndindex.hxx:30
const SwHTMLNumRuleInfo & GetNumInfo() const
Definition: htmlctxt.cxx:78
HTMLAttr * Clone(const SwNodeIndex &rEndPara, sal_Int32 nEndCnt) const
Definition: swhtml.cxx:5483
sal_uInt8 GetChars() const
Definition: paratr.hxx:104
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
bool IsRestartPRE() const
Definition: swhtml.hxx:285
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:985
HTMLAttrContext_SaveDoc * GetSaveDocContext(bool bCreate=false)
Definition: htmlctxt.cxx:111
bool IsRestartXMP() const
Definition: swhtml.hxx:288
size_t m_nContextStMin
Definition: swhtml.hxx:418
HtmlTokenId
void SetFixFooterDist(bool bSet)
Definition: htmlctxt.cxx:97
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_BACKGROUND(21)
tools::Long m_nLeftMargin
Definition: svxcss1.hxx:135
HTMLAttrs m_aParaAttrs
Definition: swhtml.hxx:377
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
void SetNumInfo(const SwHTMLNumRuleInfo &rInf)
Definition: htmlctxt.cxx:77
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
void SetPopStack(bool bSet)
Definition: swhtml.hxx:272
bool GetStripTrailingPara() const
Definition: htmlctxt.cxx:89
HtmlTokenId GetToken() const
Definition: swhtml.hxx:248
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
void GetULSpaceFromContext(sal_uInt16 &rUpper, sal_uInt16 &rLower) const
Definition: htmlcss1.cxx:2181
void ClearContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:420
sal_Int32 GetIndex() const
Definition: index.hxx:91
SwHTMLNumRuleInfo & GetNumInfo()
Definition: swhtml.hxx:558
void SetPos(const SwPosition &rPos)
Definition: htmlctxt.cxx:73
bool EndAttr(HTMLAttr *pAttr, bool bChkEmpty=true)
Definition: swhtml.cxx:3101
HTMLAttr ** GetAttrTabEntry(sal_uInt16 nWhich)
Definition: htmlcss1.cxx:1524
bool GetFixHeaderDist() const
Definition: htmlctxt.cxx:95
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:2022
void SetFinishPREListingXMP(bool bSet)
Definition: swhtml.hxx:281
void SetRestartXMP(bool bSet)
Definition: swhtml.hxx:287
size_t m_nContextStAttrMin
Definition: swhtml.hxx:419
void RestoreAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3447
constexpr TypedWhichId< SvxBoxItem > RES_BOX(106)
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
bool GetFixFooterDist() const
Definition: htmlctxt.cxx:98
void SetRestartPRE(bool bSet)
Definition: swhtml.hxx:284
std::shared_ptr< HTMLAttrTable > m_xAttrTab
Definition: swhtml.hxx:378
void ClearSaveDocContext()
Definition: htmlctxt.cxx:168
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps...
Definition: paratr.hxx:62
bool AppendTextNode(SwHTMLAppendMode eMode=AM_NORMAL, bool bUpdateNum=true)
Definition: swhtml.cxx:2188
SwHTMLAppendMode GetAppendMode() const
Definition: swhtml.hxx:297
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:392
const SwNodeIndex & GetStartParagraph() const
Definition: swhtml.hxx:163
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
void SaveDocContext(HTMLAttrContext *pCntxt, HtmlContextFlags nFlags, const SwPosition *pNewPos)
Definition: htmlctxt.cxx:272
constexpr sal_uInt16 RES_FRMATR_BEGIN(RES_PARATR_LIST_END)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(92)
void SetFixHeaderDist(bool bSet)
Definition: htmlctxt.cxx:94
std::unique_ptr< SfxPoolItem > m_pItem
Definition: swhtml.hxx:139
void InsertPrev(HTMLAttr *pPrv)
Definition: swhtml.cxx:5510
sal_uInt16 Which() const
bool GetSpansSection() const
Definition: swhtml.hxx:270
static void SetFixSize(const Size &rPixSize, const Size &rTwipDfltSize, bool bPercentWidth, bool bPercentHeight, SvxCSS1PropertyInfo const &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:165
static bool MayBePositioned(const SvxCSS1PropertyInfo &rPropInfo, bool bAutoWidth=false)
Definition: htmlcss1.cxx:1409
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1318
sal_uInt16 GetUpper() const
bool m_bDetectedRangeSegmentation false