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  for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
570  {
571  HTMLAttr **ppAttr = nullptr;
572 
573  switch( pItem->Which() )
574  {
575  case RES_LR_SPACE:
576  {
577  // Paragraph indents need to be added and are generated for each paragraphs
578  // (here for the first paragraph only, all the following in SetTextCollAttrs)
579  const SvxLRSpaceItem *pLRItem =
580  static_cast<const SvxLRSpaceItem *>(pItem);
581 
582  // Get old paragraph indents without the top context (that's the one we're editing)
583  sal_uInt16 nOldLeft = 0, nOldRight = 0;
584  short nOldIndent = 0;
585  bool bIgnoreTop = m_aContexts.size() > m_nContextStMin &&
586  m_aContexts.back().get() == pContext;
587  GetMarginsFromContext( nOldLeft, nOldRight, nOldIndent,
588  bIgnoreTop );
589 
590  // ... and the currently valid ones
591  sal_uInt16 nLeft = nOldLeft, nRight = nOldRight;
592  short nIndent = nOldIndent;
593  pContext->GetMargins( nLeft, nRight, nIndent );
594 
595  // ... and add the new indents to the old ones
596  // Here, we don't get the ones from the item but the separately remembered ones,
597  // since they could be negative. Accessing those via the item still works, since
598  // the item (with value 0) will be added
599  if( rPropInfo.m_bLeftMargin )
600  {
601  OSL_ENSURE( rPropInfo.m_nLeftMargin < 0 ||
602  rPropInfo.m_nLeftMargin == pLRItem->GetTextLeft(),
603  "left margin does not match with item" );
604  if( rPropInfo.m_nLeftMargin < 0 &&
605  -rPropInfo.m_nLeftMargin > nOldLeft )
606  nLeft = 0;
607  else
608  nLeft = nOldLeft + static_cast< sal_uInt16 >(rPropInfo.m_nLeftMargin);
609  }
610  if( rPropInfo.m_bRightMargin )
611  {
612  OSL_ENSURE( rPropInfo.m_nRightMargin < 0 ||
613  rPropInfo.m_nRightMargin == pLRItem->GetRight(),
614  "right margin does not match with item" );
615  if( rPropInfo.m_nRightMargin < 0 &&
616  -rPropInfo.m_nRightMargin > nOldRight )
617  nRight = 0;
618  else
619  nRight = nOldRight + static_cast< sal_uInt16 >(rPropInfo.m_nRightMargin);
620  }
621  if( rPropInfo.m_bTextIndent )
622  nIndent = pLRItem->GetTextFirstLineOfst();
623 
624  // Remember the value for the following paragraphs
625  pContext->SetMargins( nLeft, nRight, nIndent );
626 
627  // Set the attribute on the current paragraph
628  SvxLRSpaceItem aLRItem( *pLRItem );
629  aLRItem.SetTextFirstLineOfst( nIndent );
630  aLRItem.SetTextLeft( nLeft );
631  aLRItem.SetRight( nRight );
632  NewAttr(m_xAttrTab, &m_xAttrTab->pLRSpace, aLRItem);
633  EndAttr( m_xAttrTab->pLRSpace, false );
634  }
635  break;
636 
637  case RES_UL_SPACE:
638  if( !rPropInfo.m_bTopMargin || !rPropInfo.m_bBottomMargin )
639  {
640  sal_uInt16 nUpper = 0, nLower = 0;
641  GetULSpaceFromContext( nUpper, nLower );
642  SvxULSpaceItem aULSpace( *static_cast<const SvxULSpaceItem *>(pItem) );
643  if( !rPropInfo.m_bTopMargin )
644  aULSpace.SetUpper( nUpper );
645  if( !rPropInfo.m_bBottomMargin )
646  aULSpace.SetLower( nLower );
647 
648  NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, aULSpace);
649 
650  // save context information
651  HTMLAttrs &rAttrs = pContext->GetAttrs();
652  rAttrs.push_back( m_xAttrTab->pULSpace );
653 
654  pContext->SetULSpace( aULSpace.GetUpper(), aULSpace.GetLower() );
655  }
656  else
657  {
658  ppAttr = &m_xAttrTab->pULSpace;
659  }
660  break;
661  case RES_CHRATR_FONTSIZE:
662  // don't set attributes with a % property
663  if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
664  ppAttr = &m_xAttrTab->pFontHeight;
665  break;
667  // don't set attributes with a % property
668  if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
669  ppAttr = &m_xAttrTab->pFontHeightCJK;
670  break;
672  // don't set attributes with a % property
673  if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
674  ppAttr = &m_xAttrTab->pFontHeightCTL;
675  break;
676 
677  case RES_BACKGROUND:
678  if( bCharLvl )
679  {
680  // Convert the Frame attribute to a Char attribute (if needed)
681  SvxBrushItem aBrushItem( *static_cast<const SvxBrushItem *>(pItem) );
682  aBrushItem.SetWhich( RES_CHRATR_BACKGROUND );
683 
684  // Set the attribute
685  NewAttr(m_xAttrTab, &m_xAttrTab->pCharBrush, aBrushItem);
686 
687  // and save context information
688  HTMLAttrs &rAttrs = pContext->GetAttrs();
689  rAttrs.push_back( m_xAttrTab->pCharBrush );
690  }
691  else if( pContext->GetToken() != HtmlTokenId::TABLEHEADER_ON &&
692  pContext->GetToken() != HtmlTokenId::TABLEDATA_ON )
693  {
694  ppAttr = &m_xAttrTab->pBrush;
695  }
696  break;
697 
698  case RES_BOX:
699  if( bCharLvl )
700  {
701  SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem *>(pItem) );
702  aBoxItem.SetWhich( RES_CHRATR_BOX );
703 
704  NewAttr(m_xAttrTab, &m_xAttrTab->pCharBox, aBoxItem);
705 
706  HTMLAttrs &rAttrs = pContext->GetAttrs();
707  rAttrs.push_back( m_xAttrTab->pCharBox );
708  }
709  else
710  {
711  ppAttr = &m_xAttrTab->pBox;
712  }
713  break;
714 
715  default:
716  ppAttr = GetAttrTabEntry( pItem->Which() );
717  break;
718  }
719 
720  if( ppAttr )
721  {
722  // Set the attribute
723  NewAttr(m_xAttrTab, ppAttr, *pItem);
724 
725  // and save context information
726  HTMLAttrs &rAttrs = pContext->GetAttrs();
727  rAttrs.push_back( *ppAttr );
728  }
729  }
730 
731  if( !rPropInfo.m_aId.isEmpty() )
732  InsertBookmark( rPropInfo.m_aId );
733 }
734 
735 void SwHTMLParser::InsertAttr( HTMLAttr **ppAttr, const SfxPoolItem & rItem,
736  HTMLAttrContext *pCntxt )
737 {
738  if( !ppAttr )
739  {
740  ppAttr = GetAttrTabEntry( rItem.Which() );
741  if( !ppAttr )
742  return;
743  }
744 
745  // Set the attribute
746  NewAttr(m_xAttrTab, ppAttr, rItem);
747 
748  // save context information
749  HTMLAttrs &rAttrs = pCntxt->GetAttrs();
750  rAttrs.push_back( *ppAttr );
751 }
752 
754 {
755  // PRE/Listing/XMP need to be finished when finishing context
756  pCntxt->SetFinishPREListingXMP( true );
757 
758  // And set all now valid flags
759  if( IsReadPRE() )
760  pCntxt->SetRestartPRE( true );
761  if( IsReadXMP() )
762  pCntxt->SetRestartXMP( true );
763  if( IsReadListing() )
764  pCntxt->SetRestartListing( true );
765 
766  FinishPREListingXMP();
767 }
768 
770 {
771  if( !m_pFrameItemSet && pCreateDoc )
772  m_pFrameItemSet = std::make_unique<SfxItemSet>( pCreateDoc->GetAttrPool(),
774  return m_pFrameItemSet.get();
775 }
776 
777 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool EndSection(bool bLFStripped=false)
Definition: htmlsect.cxx:506
static void SetSpace(const Size &rPixSpace, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:242
void SetAnchorAndAdjustment(sal_Int16 eVertOri, sal_Int16 eHoriOri, const SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFrameSet)
Definition: htmlgrin.cxx:153
bool GetKeepNumRules() const
Definition: htmlctxt.cxx:93
void SplitPREListingXMP(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:753
bool IsFinishPREListingXMP() const
Definition: swhtml.hxx:277
size_t GetContextStAttrMin() const
Definition: htmlctxt.cxx:87
bool HasSaveDocContext() const
Definition: swhtml.hxx:270
Marks a position in the document model.
Definition: pam.hxx:35
std::unique_ptr< HTMLAttrContext_SaveDoc > m_pSaveDocContext
Definition: swhtml.hxx:208
void SetAttr(bool bChkEnd=true, bool bBeforeTable=false, std::deque< std::unique_ptr< HTMLAttr >> *pPostIts=nullptr)
Definition: swhtml.hxx:486
sal_Int32 GetSttCnt() const
Definition: swhtml.hxx:163
sal_uInt16 GetLower() const
HTMLAttrs m_aSetAttrTab
Definition: swhtml.hxx:359
#define RES_CHRATR_FONTSIZE
Definition: hintids.hxx:77
void SetContextStAttrMin(size_t nMin)
Definition: htmlctxt.cxx:86
void FixHeaderFooterDistance(bool bHeader, const SwPosition *pOldPos)
Definition: htmlsect.cxx:416
bool m_bInsAtStart
Definition: swhtml.hxx:132
short GetTextFirstLineOfst() const
SwNodeIndex nNode
Definition: pam.hxx:37
void SaveAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3252
void InsertBookmark(const OUString &rName)
Definition: htmlgrin.cxx:1354
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:209
HTMLAttr * GetNext() const
Definition: swhtml.hxx:172
void NewAttr(const std::shared_ptr< HTMLAttrTable > &rAttrTab, HTMLAttr **ppAttr, const SfxPoolItem &rItem)
Definition: swhtml.cxx:3016
#define RES_FRMATR_END
Definition: hintids.hxx:238
void SetRestartListing(bool bSet)
Definition: swhtml.hxx:285
Definition: doc.hxx:185
HTMLAttrContexts m_aContexts
Definition: swhtml.hxx:362
const SfxItemSet * GetFrameItemSet() const
Definition: swhtml.hxx:273
void SetTextLeft(const long nL, const sal_uInt16 nProp=100)
const SwNodeIndex & GetSttPara() const
Definition: swhtml.hxx:160
#define RES_CHRATR_CJK_FONTSIZE
Definition: hintids.hxx:92
bool HasAttrs() const
Definition: swhtml.hxx:260
void SplitAttrTab(const SwPosition &rNewPos)
Definition: htmlctxt.cxx:174
SwNodeIndex m_nStartPara
Definition: swhtml.hxx:130
void SetULSpace(sal_uInt16 nUpper, sal_uInt16 nLower)
Definition: swhtml.hxx:976
void SetMargins(sal_uInt16 nLeft, sal_uInt16 nRight, short nIndent)
Definition: swhtml.hxx:955
static void ResetFrameFormatAttrs(SfxItemSet &rFrameSet)
Definition: shellio.cxx:608
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:2144
#define RES_CHRATR_CTL_FONTSIZE
Definition: hintids.hxx:97
SwIndex nContent
Definition: pam.hxx:38
void InsertAttrs(std::deque< std::unique_ptr< HTMLAttr >> rAttrs)
Definition: swhtml.cxx:3417
const HTMLAttrs & GetAttrs() const
Definition: swhtml.hxx:261
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
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:2028
HtmlContextFlags
Definition: swhtml.hxx:303
#define RES_UL_SPACE
Definition: hintids.hxx:199
bool IsRestartListing() const
Definition: swhtml.hxx:286
#define RES_PARATR_BEGIN
Definition: hintids.hxx:161
SwPaM * m_pPam
Definition: swhtml.hxx:376
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:3408
sal_Int32 m_nEndContent
Definition: swhtml.hxx:131
#define RES_BACKGROUND
Definition: hintids.hxx:212
static void SetFrameFormatAttrs(SfxItemSet &rItemSet, HtmlFrameFormatFlags nFlags, SfxItemSet &rFrameItemSet)
Definition: htmlcss1.cxx:2067
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:485
SwNodeIndex m_nEndPara
Definition: swhtml.hxx:130
void SetRight(const long nR, const sal_uInt16 nProp=100)
void DeleteAttr(HTMLAttr *pAttr)
Definition: swhtml.cxx:3194
std::deque< HTMLAttr * > HTMLAttrs
Definition: swhtml.hxx:71
#define RES_CHRATR_BACKGROUND
Definition: hintids.hxx:90
HTMLAttr * GetPrev() const
Definition: swhtml.hxx:175
void SetKeepNumRules(bool bSet)
Definition: htmlctxt.cxx:92
void EndContextAttrs(HTMLAttrContext *pContext)
Definition: htmlcss1.cxx:2218
const SwPosition * GetPoint() const
Definition: pam.hxx:207
#define RES_CHRATR_BOX
Definition: hintids.hxx:109
sal_Int32 m_nStartContent
Definition: swhtml.hxx:131
std::shared_ptr< HTMLAttrTable > xAttrTab
Definition: htmlctxt.cxx:53
std::unique_ptr< SwCSS1Parser > m_pCSS1Parser
Definition: swhtml.hxx:371
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:139
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:2104
size_t GetContextStMin() const
Definition: htmlctxt.cxx:84
bool GetPopStack() const
Definition: swhtml.hxx:268
void StripTrailingPara()
Definition: htmlgrin.cxx:1409
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:5470
sal_uInt8 GetChars() const
Definition: paratr.hxx:89
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
bool IsRestartPRE() const
Definition: swhtml.hxx:280
void InsertFlyFrame(const SfxItemSet &rItemSet, HTMLAttrContext *pCntxt, const OUString &rId)
Definition: htmlsect.cxx:764
void GetMargins(sal_uInt16 &nLeft, sal_uInt16 &nRight, short &nIndent) const
Definition: swhtml.hxx:964
HTMLAttrContext_SaveDoc * GetSaveDocContext(bool bCreate=false)
Definition: htmlctxt.cxx:112
bool IsRestartXMP() const
Definition: swhtml.hxx:283
#define RES_LR_SPACE
Definition: hintids.hxx:198
size_t m_nContextStMin
Definition: swhtml.hxx:401
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:360
void SetNumInfo(const SwHTMLNumRuleInfo &rInf)
Definition: htmlctxt.cxx:78
void SetPopStack(bool bSet)
Definition: swhtml.hxx:267
bool GetStripTrailingPara() const
Definition: htmlctxt.cxx:90
HtmlTokenId GetToken() const
Definition: swhtml.hxx:243
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
void GetULSpaceFromContext(sal_uInt16 &rUpper, sal_uInt16 &rLower) const
Definition: htmlcss1.cxx:2185
void ClearContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:421
sal_Int32 GetIndex() const
Definition: index.hxx:95
SwHTMLNumRuleInfo & GetNumInfo()
Definition: swhtml.hxx:536
void SetPos(const SwPosition &rPos)
Definition: htmlctxt.cxx:74
bool EndAttr(HTMLAttr *pAttr, bool bChkEmpty=true)
Definition: swhtml.cxx:3032
HTMLAttr ** GetAttrTabEntry(sal_uInt16 nWhich)
Definition: htmlcss1.cxx:1530
bool GetFixHeaderDist() const
Definition: htmlctxt.cxx:96
void SetFinishPREListingXMP(bool bSet)
Definition: swhtml.hxx:276
void SetRestartXMP(bool bSet)
Definition: swhtml.hxx:282
size_t m_nContextStAttrMin
Definition: swhtml.hxx:402
void RestoreAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3378
long GetRight() const
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
bool GetFixFooterDist() const
Definition: htmlctxt.cxx:99
#define RES_BOX
Definition: hintids.hxx:213
static void SetFixSize(const Size &rPixSize, const Size &rTwipDfltSize, bool bPrcWidth, bool bPrcHeight, SvxCSS1PropertyInfo const &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:164
void SetRestartPRE(bool bSet)
Definition: swhtml.hxx:279
std::shared_ptr< HTMLAttrTable > m_xAttrTab
Definition: swhtml.hxx:361
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:2138
SwHTMLAppendMode GetAppendMode() const
Definition: swhtml.hxx:292
long GetTextLeft() const
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
rtl::Reference< SwDoc > m_xDoc
Definition: swhtml.hxx:375
#define RES_FRMATR_BEGIN
Definition: hintids.hxx:194
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:136
sal_uInt32 GetSttParaIdx() const
Definition: swhtml.hxx:157
void InsertPrev(HTMLAttr *pPrv)
Definition: swhtml.cxx:5497
sal_uInt16 Which() const
bool GetSpansSection() const
Definition: swhtml.hxx:265
static bool MayBePositioned(const SvxCSS1PropertyInfo &rPropInfo, bool bAutoWidth=false)
Definition: htmlcss1.cxx:1420
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1309
sal_uInt16 GetUpper() const