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#include <utility>
44
45using namespace ::com::sun::star;
46
48{
49 SwHTMLNumRuleInfo m_aNumRuleInfo; // Numbering for this environment
50 std::unique_ptr<SwPosition>
51 m_pPos; // Jump back to here when leaving context
52 std::shared_ptr<HTMLAttrTable>
53 m_xAttrTab; // Valid attributes for the environment,
54 // if attributes shouldn't be preserved
55
56 size_t m_nContextStMin; // Stack lower bound for the environment
57 // if stack needs to be protected
58 size_t m_nContextStAttrMin; // Stack lower bound for the environment
59 // if the attributes shouldn't be preserved
64
65public:
66
68 m_nContextStMin( SIZE_MAX ), m_nContextStAttrMin( SIZE_MAX ),
69 m_bStripTrailingPara( false ), m_bKeepNumRules( false ),
70 m_bFixHeaderDist( false ), m_bFixFooterDist( false )
71 {}
72
73 // The position is ours, so we need to create and delete it
74 void SetPos( const SwPosition& rPos ) { m_pPos.reset( new SwPosition(rPos) ); }
75 const SwPosition *GetPos() const { return m_pPos.get(); }
76
77 // The index isn't ours. So no creation or deletion
78 void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { m_aNumRuleInfo.Set(rInf); }
79 const SwHTMLNumRuleInfo& GetNumInfo() const { return m_aNumRuleInfo; }
80
81 std::shared_ptr<HTMLAttrTable> const & GetAttrTab(bool bCreate = false);
82
83 void SetContextStMin( size_t nMin ) { m_nContextStMin = nMin; }
84 size_t GetContextStMin() const { return m_nContextStMin; }
85
86 void SetContextStAttrMin( size_t nMin ) { m_nContextStAttrMin = nMin; }
87 size_t GetContextStAttrMin() const { return m_nContextStAttrMin; }
88
89 void SetStripTrailingPara( bool bSet ) { m_bStripTrailingPara = bSet; }
91
92 void SetKeepNumRules( bool bSet ) { m_bKeepNumRules = bSet; }
93 bool GetKeepNumRules() const { return m_bKeepNumRules; }
94
95 void SetFixHeaderDist( bool bSet ) { m_bFixHeaderDist = bSet; }
96 bool GetFixHeaderDist() const { return m_bFixHeaderDist; }
97
98 void SetFixFooterDist( bool bSet ) { m_bFixFooterDist = bSet; }
99 bool GetFixFooterDist() const { return m_bFixFooterDist; }
100};
101
102std::shared_ptr<HTMLAttrTable> const & HTMLAttrContext_SaveDoc::GetAttrTab( bool bCreate )
103{
104 if (!m_xAttrTab && bCreate)
105 {
106 m_xAttrTab = std::make_shared<HTMLAttrTable>();
107 memset(m_xAttrTab.get(), 0, sizeof(HTMLAttrTable));
108 }
109 return m_xAttrTab;
110}
111
113{
114 if( !m_pSaveDocContext && bCreate )
116
117 return m_pSaveDocContext.get();
118}
119
120HTMLAttrContext::HTMLAttrContext( HtmlTokenId nTokn, sal_uInt16 nPoolId, OUString aClass,
121 bool bDfltColl ) :
122 m_aClass(std::move( aClass )),
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 SwPosition* pOldEndPara = m_pPam->GetPoint();
183#ifndef NDEBUG
184 auto const nOld(pOldEndPara->GetNodeIndex());
185#endif
186 sal_Int32 nOldEndCnt = m_pPam->GetPoint()->GetContentIndex();
187
188 const SwPosition& rNewSttPara = rNewPos;
189 sal_Int32 nNewSttCnt = rNewPos.GetContentIndex();
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->GetStartParagraphIdx() < pOldEndPara->GetNodeIndex() )
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()->GetContentIndex();
212 }
213 }
214 else if( bMoveBack )
215 {
217 nOldEndCnt = m_pPam->GetPoint()->GetContentIndex();
218 bMoveBack = false;
219 }
220
221 if( (RES_PARATR_BEGIN <= nWhich && bMoveBack) ||
222 pAttr->GetStartParagraphIdx() < pOldEndPara->GetNodeIndex() ||
223 (pAttr->GetStartParagraph() == pOldEndPara->GetNode() &&
224 pAttr->GetStartContent() != 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->GetNode(), 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.GetNode();
258 pAttr->m_nEndPara = rNewSttPara.GetNode();
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()->GetNodeIndex() == 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 {
315
316 if( HtmlContextFlags::KeepAttrs & nFlags )
317 {
320 }
321 }
322}
323
325{
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 {
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 SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END-1> aFrameItemSet( m_xDoc->GetAttrPool() );
482 if( !IsNewDoc() )
483 Reader::ResetFrameFormatAttrs(aFrameItemSet );
484
486 aFrameItemSet );
487
488 SetVarSize( rPropInfo, aFrameItemSet );
489
490 SetSpace( Size(0,0), rItemSet, rPropInfo, aFrameItemSet );
491
492 SetFrameFormatAttrs( rItemSet,
494 aFrameItemSet );
495
496 InsertFlyFrame(aFrameItemSet, pContext, rPropInfo.m_aId);
497 pContext->SetPopStack( true );
498 rPropInfo.m_aId.clear();
499 bRet = true;
500 }
501
502 return bRet;
503}
504
505bool SwHTMLParser::CreateContainer( std::u16string_view rClass,
506 SfxItemSet &rItemSet,
507 SvxCSS1PropertyInfo &rPropInfo,
508 HTMLAttrContext *pContext )
509{
510 bool bRet = false;
511 if( o3tl::equalsIgnoreAsciiCase( rClass, u"sd-abs-pos" ) &&
512 SwCSS1Parser::MayBePositioned( rPropInfo ) )
513 {
514 // Container class
515 SfxItemSet *pFrameItemSet = pContext->GetFrameItemSet( m_xDoc.get() );
516 if( !IsNewDoc() )
517 Reader::ResetFrameFormatAttrs( *pFrameItemSet );
518
520 rPropInfo, *pFrameItemSet );
521 Size aDummy(0,0);
522 SetFixSize( aDummy, aDummy, false, false, rPropInfo, *pFrameItemSet );
523 SetSpace( aDummy, rItemSet, rPropInfo, *pFrameItemSet );
525 *pFrameItemSet );
526
527 bRet = true;
528 }
529
530 return bRet;
531}
532
534 SvxCSS1PropertyInfo const &rPropInfo,
535 HTMLAttrContext *pContext,
536 bool bCharLvl )
537{
538 // Put together a DropCap attribute, if a "float:left" is before the first character
539 if( bCharLvl && !m_pPam->GetPoint()->GetContentIndex() &&
540 SvxAdjust::Left == rPropInfo.m_eFloat )
541 {
542 SwFormatDrop aDrop;
543 aDrop.GetChars() = 1;
544
545 m_pCSS1Parser->FillDropCap( aDrop, rItemSet );
546
547 // We only set the DropCap attribute if the initial spans multiple lines
548 if( aDrop.GetLines() > 1 )
549 {
550 NewAttr(m_xAttrTab, &m_xAttrTab->pDropCap, aDrop);
551
552 HTMLAttrs &rAttrs = pContext->GetAttrs();
553 rAttrs.push_back( m_xAttrTab->pDropCap );
554
555 return;
556 }
557 }
558
559 if( !bCharLvl )
560 m_pCSS1Parser->SetFormatBreak( rItemSet, rPropInfo );
561
562 OSL_ENSURE(m_aContexts.size() <= m_nContextStAttrMin ||
563 m_aContexts.back().get() != pContext,
564 "SwHTMLParser::InsertAttrs: Context already on the Stack");
565
566 SfxItemIter aIter( rItemSet );
567
568 const SvxFirstLineIndentItem * pFirstLineItem(nullptr);
569 const SvxTextLeftMarginItem * pTextLeftMargin(nullptr);
570 const SvxRightMarginItem * pRightMargin(nullptr);
571
572 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
573 {
574 switch( pItem->Which() )
575 {
577 {
578 pFirstLineItem = static_cast<const SvxFirstLineIndentItem*>(pItem);
579 }
580 break;
582 {
583 pTextLeftMargin = static_cast<const SvxTextLeftMarginItem*>(pItem);
584 }
585 break;
586 case RES_MARGIN_RIGHT:
587 {
588 pRightMargin = static_cast<const SvxRightMarginItem*>(pItem);
589 }
590 break;
591 }
592 }
593
594#if 1
595 {
596 // Paragraph indents need to be added and are generated for each paragraphs
597 // (here for the first paragraph only, all the following in SetTextCollAttrs)
598
599 // Get old paragraph indents without the top context (that's the one we're editing)
600 sal_uInt16 nOldLeft = 0, nOldRight = 0;
601 short nOldIndent = 0;
602 bool bIgnoreTop = m_aContexts.size() > m_nContextStMin &&
603 m_aContexts.back().get() == pContext;
604 GetMarginsFromContext( nOldLeft, nOldRight, nOldIndent,
605 bIgnoreTop );
606
607 // ... and the currently valid ones
608 sal_uInt16 nLeft = nOldLeft, nRight = nOldRight;
609 short nIndent = nOldIndent;
610 pContext->GetMargins( nLeft, nRight, nIndent );
611
612 // ... and add the new indents to the old ones
613 // Here, we don't get the ones from the item but the separately remembered ones,
614 // since they could be negative. Accessing those via the item still works, since
615 // the item (with value 0) will be added
616 if( rPropInfo.m_bLeftMargin )
617 {
618 OSL_ENSURE( rPropInfo.m_nLeftMargin < 0 ||
619 !pTextLeftMargin ||
620 rPropInfo.m_nLeftMargin == pTextLeftMargin->GetTextLeft(),
621 "left margin does not match with item" );
622 if( rPropInfo.m_nLeftMargin < 0 &&
623 -rPropInfo.m_nLeftMargin > nOldLeft )
624 nLeft = 0;
625 else
626 nLeft = nOldLeft + static_cast< sal_uInt16 >(rPropInfo.m_nLeftMargin);
627 }
628 if( rPropInfo.m_bRightMargin )
629 {
630 OSL_ENSURE( rPropInfo.m_nRightMargin < 0 ||
631 !pRightMargin ||
632 rPropInfo.m_nRightMargin == pRightMargin->GetRight(),
633 "right margin does not match with item" );
634 if( rPropInfo.m_nRightMargin < 0 &&
635 -rPropInfo.m_nRightMargin > nOldRight )
636 nRight = 0;
637 else
638 nRight = nOldRight + static_cast< sal_uInt16 >(rPropInfo.m_nRightMargin);
639 }
640 if (rPropInfo.m_bTextIndent && pFirstLineItem)
641 nIndent = pFirstLineItem->GetTextFirstLineOffset();
642
643 // Remember the value for the following paragraphs
644 pContext->SetMargins( nLeft, nRight, nIndent );
645
646 // Set the attribute on the current paragraph
647 SvxFirstLineIndentItem const firstLine(nIndent, RES_MARGIN_FIRSTLINE);
648 NewAttr(m_xAttrTab, &m_xAttrTab->pFirstLineIndent, firstLine);
649 EndAttr(m_xAttrTab->pFirstLineIndent, false);
650 SvxTextLeftMarginItem const leftMargin(nLeft, RES_MARGIN_TEXTLEFT);
651 NewAttr(m_xAttrTab, &m_xAttrTab->pTextLeftMargin, leftMargin);
652 EndAttr(m_xAttrTab->pTextLeftMargin, false);
653 SvxRightMarginItem const rightMargin(nRight, RES_MARGIN_RIGHT);
654 NewAttr(m_xAttrTab, &m_xAttrTab->pRightMargin, rightMargin);
655 EndAttr(m_xAttrTab->pRightMargin, false);
656 }
657#endif
658
659 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
660 {
661 HTMLAttr **ppAttr = nullptr;
662
663 switch( pItem->Which() )
664 {
665
666 case RES_UL_SPACE:
667 if( !rPropInfo.m_bTopMargin || !rPropInfo.m_bBottomMargin )
668 {
669 sal_uInt16 nUpper = 0, nLower = 0;
670 GetULSpaceFromContext( nUpper, nLower );
671 SvxULSpaceItem aULSpace( *static_cast<const SvxULSpaceItem *>(pItem) );
672 if( !rPropInfo.m_bTopMargin )
673 aULSpace.SetUpper( nUpper );
674 if( !rPropInfo.m_bBottomMargin )
675 aULSpace.SetLower( nLower );
676
677 NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, aULSpace);
678
679 // save context information
680 HTMLAttrs &rAttrs = pContext->GetAttrs();
681 rAttrs.push_back( m_xAttrTab->pULSpace );
682
683 pContext->SetULSpace( aULSpace.GetUpper(), aULSpace.GetLower() );
684 }
685 else
686 {
687 ppAttr = &m_xAttrTab->pULSpace;
688 }
689 break;
691 // don't set attributes with a % property
692 if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
693 ppAttr = &m_xAttrTab->pFontHeight;
694 break;
696 // don't set attributes with a % property
697 if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
698 ppAttr = &m_xAttrTab->pFontHeightCJK;
699 break;
701 // don't set attributes with a % property
702 if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 )
703 ppAttr = &m_xAttrTab->pFontHeightCTL;
704 break;
705
706 case RES_BACKGROUND:
707 if( bCharLvl )
708 {
709 // Convert the Frame attribute to a Char attribute (if needed)
710 SvxBrushItem aBrushItem( *static_cast<const SvxBrushItem *>(pItem) );
711 aBrushItem.SetWhich( RES_CHRATR_BACKGROUND );
712
713 // Set the attribute
714 NewAttr(m_xAttrTab, &m_xAttrTab->pCharBrush, aBrushItem);
715
716 // and save context information
717 HTMLAttrs &rAttrs = pContext->GetAttrs();
718 rAttrs.push_back( m_xAttrTab->pCharBrush );
719 }
720 else if( pContext->GetToken() != HtmlTokenId::TABLEHEADER_ON &&
721 pContext->GetToken() != HtmlTokenId::TABLEDATA_ON )
722 {
723 ppAttr = &m_xAttrTab->pBrush;
724 }
725 break;
726
727 case RES_BOX:
728 if( bCharLvl )
729 {
730 SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem *>(pItem) );
731 aBoxItem.SetWhich( RES_CHRATR_BOX );
732
733 NewAttr(m_xAttrTab, &m_xAttrTab->pCharBox, aBoxItem);
734
735 HTMLAttrs &rAttrs = pContext->GetAttrs();
736 rAttrs.push_back( m_xAttrTab->pCharBox );
737 }
738 else
739 {
740 ppAttr = &m_xAttrTab->pBox;
741 }
742 break;
743
744 default:
745 ppAttr = GetAttrTabEntry( pItem->Which() );
746 break;
747 }
748
749 if( ppAttr )
750 {
751 // Set the attribute
752 NewAttr(m_xAttrTab, ppAttr, *pItem);
753
754 // and save context information
755 HTMLAttrs &rAttrs = pContext->GetAttrs();
756 rAttrs.push_back( *ppAttr );
757 }
758 }
759
760 if( !rPropInfo.m_aId.isEmpty() )
761 InsertBookmark( rPropInfo.m_aId );
762}
763
764void SwHTMLParser::InsertAttr( HTMLAttr **ppAttr, const SfxPoolItem & rItem,
765 HTMLAttrContext *pCntxt )
766{
767 if( !ppAttr )
768 {
769 ppAttr = GetAttrTabEntry( rItem.Which() );
770 if( !ppAttr )
771 return;
772 }
773
774 // Set the attribute
775 NewAttr(m_xAttrTab, ppAttr, rItem);
776
777 // save context information
778 HTMLAttrs &rAttrs = pCntxt->GetAttrs();
779 rAttrs.push_back( *ppAttr );
780}
781
783{
784 // PRE/Listing/XMP need to be finished when finishing context
785 pCntxt->SetFinishPREListingXMP( true );
786
787 // And set all now valid flags
788 if( IsReadPRE() )
789 pCntxt->SetRestartPRE( true );
790 if( IsReadXMP() )
791 pCntxt->SetRestartXMP( true );
792 if( IsReadListing() )
793 pCntxt->SetRestartListing( true );
794
795 FinishPREListingXMP();
796}
797
799{
800 if( !m_pFrameItemSet && pCreateDoc )
802 ( pCreateDoc->GetAttrPool() );
803 return m_pFrameItemSet.get();
804}
805
806/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetContextStMin(size_t nMin)
Definition: htmlctxt.cxx:83
std::shared_ptr< HTMLAttrTable > m_xAttrTab
Definition: htmlctxt.cxx:53
bool GetStripTrailingPara() const
Definition: htmlctxt.cxx:90
void SetContextStAttrMin(size_t nMin)
Definition: htmlctxt.cxx:86
SwHTMLNumRuleInfo m_aNumRuleInfo
Definition: htmlctxt.cxx:49
size_t GetContextStMin() const
Definition: htmlctxt.cxx:84
void SetKeepNumRules(bool bSet)
Definition: htmlctxt.cxx:92
void SetPos(const SwPosition &rPos)
Definition: htmlctxt.cxx:74
const SwPosition * GetPos() const
Definition: htmlctxt.cxx:75
void SetFixFooterDist(bool bSet)
Definition: htmlctxt.cxx:98
bool GetFixHeaderDist() const
Definition: htmlctxt.cxx:96
void SetFixHeaderDist(bool bSet)
Definition: htmlctxt.cxx:95
std::shared_ptr< HTMLAttrTable > const & GetAttrTab(bool bCreate=false)
Definition: htmlctxt.cxx:102
void SetNumInfo(const SwHTMLNumRuleInfo &rInf)
Definition: htmlctxt.cxx:78
const SwHTMLNumRuleInfo & GetNumInfo() const
Definition: htmlctxt.cxx:79
void SetStripTrailingPara(bool bSet)
Definition: htmlctxt.cxx:89
size_t GetContextStAttrMin() const
Definition: htmlctxt.cxx:87
std::unique_ptr< SwPosition > m_pPos
Definition: htmlctxt.cxx:51
bool GetFixFooterDist() const
Definition: htmlctxt.cxx:99
bool GetKeepNumRules() const
Definition: htmlctxt.cxx:93
void ClearSaveDocContext()
Definition: htmlctxt.cxx:169
void SetULSpace(sal_uInt16 nUpper, sal_uInt16 nLower)
Definition: swhtml.hxx:1003
HTMLAttrContext_SaveDoc * GetSaveDocContext(bool bCreate=false)
Definition: htmlctxt.cxx:112
bool GetSpansSection() const
Definition: swhtml.hxx:276
void SetPopStack(bool bSet)
Definition: swhtml.hxx:278
const HTMLAttrs & GetAttrs() const
Definition: swhtml.hxx:272
SwHTMLAppendMode GetAppendMode() const
Definition: swhtml.hxx:303
bool IsRestartXMP() const
Definition: swhtml.hxx:294
void SetRestartXMP(bool bSet)
Definition: swhtml.hxx:293
void SetMargins(sal_uInt16 nLeft, sal_uInt16 nRight, short nIndent)
Definition: swhtml.hxx:982
void SetRestartPRE(bool bSet)
Definition: swhtml.hxx:290
bool GetPopStack() const
Definition: swhtml.hxx:279
HtmlTokenId GetToken() const
Definition: swhtml.hxx:254
std::unique_ptr< HTMLAttrContext_SaveDoc > m_pSaveDocContext
Definition: swhtml.hxx:217
bool IsFinishPREListingXMP() const
Definition: swhtml.hxx:288
bool IsRestartPRE() const
Definition: swhtml.hxx:291
void SetRestartListing(bool bSet)
Definition: swhtml.hxx:296
const SfxItemSet * GetFrameItemSet() const
Definition: swhtml.hxx:284
void SetFinishPREListingXMP(bool bSet)
Definition: swhtml.hxx:287
bool IsRestartListing() const
Definition: swhtml.hxx:297
HTMLAttrContext(HtmlTokenId nTokn, sal_uInt16 nPoolId, OUString aClass, bool bDfltColl=false)
Definition: htmlctxt.cxx:120
bool HasAttrs() const
Definition: swhtml.hxx:271
bool HasSaveDocContext() const
Definition: swhtml.hxx:281
std::unique_ptr< SfxItemSet > m_pFrameItemSet
Definition: swhtml.hxx:218
void GetMargins(sal_uInt16 &nLeft, sal_uInt16 &nRight, short &nIndent) const
Definition: swhtml.hxx:991
sal_Int32 m_nStartContent
Definition: swhtml.hxx:139
HTMLAttr * GetPrev() const
Definition: swhtml.hxx:184
sal_Int32 m_nEndContent
Definition: swhtml.hxx:140
SwNodeIndex m_nEndPara
Definition: swhtml.hxx:138
HTMLAttr * GetNext() const
Definition: swhtml.hxx:181
SwNodeOffset GetStartParagraphIdx() const
Definition: swhtml.hxx:166
HTMLAttr * m_pPrev
Definition: swhtml.hxx:148
bool m_bInsAtStart
Definition: swhtml.hxx:141
std::unique_ptr< SfxPoolItem > m_pItem
Definition: swhtml.hxx:145
const SwNodeIndex & GetStartParagraph() const
Definition: swhtml.hxx:169
void InsertPrev(HTMLAttr *pPrv)
Definition: swhtml.cxx:5546
sal_Int32 GetStartContent() const
Definition: swhtml.hxx:172
SwNodeIndex m_nStartPara
Definition: swhtml.hxx:137
HTMLAttr * Clone(const SwNode &rEndPara, sal_Int32 nEndCnt) const
Definition: swhtml.cxx:5519
static void ResetFrameFormatAttrs(SfxItemSet &rFrameSet)
Definition: shellio.cxx:621
const SfxPoolItem * GetCurItem() const
const SfxPoolItem * NextItem()
sal_uInt16 Which() const
tools::Long m_nRightMargin
Definition: svxcss1.hxx:135
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
tools::Long m_nLeftMargin
Definition: svxcss1.hxx:135
short GetTextFirstLineOffset() const
tools::Long GetRight() const
tools::Long GetTextLeft() const
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
sal_uInt16 GetUpper() const
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
sal_uInt16 GetLower() const
static bool MayBePositioned(const SvxCSS1PropertyInfo &rPropInfo, bool bAutoWidth=false)
Definition: htmlcss1.cxx:1417
Definition: doc.hxx:197
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1337
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps.
Definition: paratr.hxx:72
sal_uInt8 GetLines() const
Definition: paratr.hxx:110
sal_uInt8 GetChars() const
Definition: paratr.hxx:113
void Set(const SwHTMLNumRuleInfo &rInf)
Definition: htmlnum.hxx:93
HTMLAttrs m_aSetAttrTab
Definition: swhtml.hxx:382
bool EndSection(bool bLFStripped=false)
Definition: htmlsect.cxx:502
size_t m_nContextStAttrMin
Definition: swhtml.hxx:425
std::unique_ptr< HTMLAttrContext > PopContext(HtmlTokenId nToken=HtmlTokenId::NONE)
Definition: htmlcss1.cxx:2115
void SetAnchorAndAdjustment(sal_Int16 eVertOri, sal_Int16 eHoriOri, const SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFrameSet)
Definition: htmlgrin.cxx:151
void InsertAttrs(std::deque< std::unique_ptr< HTMLAttr > > rAttrs)
Definition: swhtml.cxx:3483
void InsertBookmark(const OUString &rName)
Definition: htmlgrin.cxx:1393
bool CreateContainer(std::u16string_view rClass, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:505
HTMLAttrContexts m_aContexts
Definition: swhtml.hxx:385
void InsertAttr(const SfxPoolItem &rItem, bool bInsAtStart)
Definition: swhtml.cxx:3474
static void SetSpace(const Size &rPixSpace, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:243
void SaveAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3319
std::shared_ptr< HTMLAttrTable > m_xAttrTab
Definition: swhtml.hxx:384
void SetAttr(bool bChkEnd=true, bool bBeforeTable=false, std::deque< std::unique_ptr< HTMLAttr > > *pPostIts=nullptr)
Definition: swhtml.hxx:516
void ClearContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:421
void SaveDocContext(HTMLAttrContext *pCntxt, HtmlContextFlags nFlags, const SwPosition *pNewPos)
Definition: htmlctxt.cxx:273
void EndContextAttrs(HTMLAttrContext *pContext)
Definition: htmlcss1.cxx:2229
void StripTrailingPara()
Definition: htmlgrin.cxx:1448
bool DoPositioning(SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:468
void DeleteAttr(HTMLAttr *pAttr)
Definition: swhtml.cxx:3261
void InsertFlyFrame(const SfxItemSet &rItemSet, HTMLAttrContext *pCntxt, const OUString &rId)
Definition: htmlsect.cxx:755
HTMLAttrs m_aParaAttrs
Definition: swhtml.hxx:383
HTMLAttr ** GetAttrTabEntry(sal_uInt16 nWhich)
Definition: htmlcss1.cxx:1533
SwPaM * m_pPam
Definition: swhtml.hxx:399
SwHTMLNumRuleInfo & GetNumInfo()
Definition: swhtml.hxx:566
static void SetFixSize(const Size &rPixSize, const Size &rTwipDfltSize, bool bPercentWidth, bool bPercentHeight, SvxCSS1PropertyInfo const &rPropInfo, SfxItemSet &rFlyItemSet)
Definition: htmlplug.cxx:165
void NewAttr(const std::shared_ptr< HTMLAttrTable > &rAttrTab, HTMLAttr **ppAttr, const SfxPoolItem &rItem)
Definition: swhtml.cxx:3083
rtl::Reference< SwDoc > m_xDoc
Definition: swhtml.hxx:398
void RestoreDocContext(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:324
std::unique_ptr< SwCSS1Parser > m_pCSS1Parser
Definition: swhtml.hxx:394
void SplitPREListingXMP(HTMLAttrContext *pCntxt)
Definition: htmlctxt.cxx:782
bool AppendTextNode(SwHTMLAppendMode eMode=AM_NORMAL, bool bUpdateNum=true)
Definition: swhtml.cxx:2190
void GetMarginsFromContext(sal_uInt16 &nLeft, sal_uInt16 &nRight, short &nIndent, bool bIgnoreCurrent=false) const
Definition: htmlcss1.cxx:2155
void EndContext(HTMLAttrContext *pContext)
Definition: htmlctxt.cxx:372
void FixHeaderFooterDistance(bool bHeader, const SwPosition *pOldPos)
Definition: htmlsect.cxx:414
void SplitAttrTab(const SwPosition &rNewPos)
Definition: htmlctxt.cxx:174
static void SetFrameFormatAttrs(SfxItemSet &rItemSet, HtmlFrameFormatFlags nFlags, SfxItemSet &rFrameItemSet)
Definition: htmlcss1.cxx:2076
bool EndAttr(HTMLAttr *pAttr, bool bChkEmpty=true)
Definition: swhtml.cxx:3099
size_t m_nContextStMin
Definition: swhtml.hxx:424
void GetULSpaceFromContext(sal_uInt16 &rUpper, sal_uInt16 &rLower) const
Definition: htmlcss1.cxx:2196
static void SetVarSize(SvxCSS1PropertyInfo const &rPropInfo, SfxItemSet &rFlyItemSet, SwTwips nDfltWidth=MINLAY, sal_uInt8 nDefaultPercentWidth=0)
Definition: htmlcss1.cxx:2037
void RestoreAttrTab(std::shared_ptr< HTMLAttrTable > const &rNewAttrTab)
Definition: swhtml.cxx:3444
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
const SwPosition * GetPoint() const
Definition: pam.hxx:253
float u
constexpr sal_uInt16 RES_FRMATR_BEGIN(RES_PARATR_LIST_END)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
constexpr sal_uInt16 RES_PARATR_BEGIN(RES_TXTATR_END)
constexpr TypedWhichId< SvxFirstLineIndentItem > RES_MARGIN_FIRSTLINE(91)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr sal_uInt16 RES_FRMATR_END(141)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_BACKGROUND(21)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(112)
constexpr TypedWhichId< SvxRightMarginItem > RES_MARGIN_RIGHT(93)
constexpr TypedWhichId< SvxTextLeftMarginItem > RES_MARGIN_TEXTLEFT(92)
constexpr TypedWhichId< SvxBoxItem > RES_CHRATR_BOX(40)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(98)
HtmlTokenId
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
Marks a position in the document model.
Definition: pam.hxx:38
SwNode & GetNode() const
Definition: pam.hxx:81
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
@ AM_NONE
Definition: swhtml.hxx:208
std::deque< HTMLAttr * > HTMLAttrs
Definition: swhtml.hxx:78
HtmlContextFlags
Definition: swhtml.hxx:317