Line data Source code
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 "hintids.hxx"
21 : #include <svl/itemiter.hxx>
22 : #include <editeng/lrspitem.hxx>
23 : #include <editeng/ulspitem.hxx>
24 : #include <editeng/brushitem.hxx>
25 : #include <editeng/fhgtitem.hxx>
26 : #include <svtools/htmltokn.h>
27 : #include <editeng/boxitem.hxx>
28 :
29 : #include "doc.hxx"
30 : #include "pam.hxx"
31 : #include "ndtxt.hxx"
32 : #include "shellio.hxx"
33 : #include "paratr.hxx"
34 : #include "htmlnum.hxx"
35 : #include "css1kywd.hxx"
36 : #include "swcss1.hxx"
37 : #include "swhtml.hxx"
38 :
39 : using namespace ::com::sun::star;
40 :
41 : class _HTMLAttrContext_SaveDoc
42 : {
43 : SwHTMLNumRuleInfo aNumRuleInfo; // In Umgebung gueltige Numerierung
44 : SwPosition *pPos; // hierhin beim verlassen den
45 : // Kontexts zurueckgesprungen
46 : _HTMLAttrTable *pAttrTab; // In Umgebung gueltige Attribute,
47 : // wenn Attributierung nicht
48 : // beibehalten werden soll.
49 :
50 : sal_uInt16 nContextStMin; // In Umgebung gueltige Stack-
51 : // Untergrenze, wenn der Stack
52 : // geschuetzt werden soll.
53 : sal_uInt16 nContextStAttrMin; // In Umgebung gueltige Stack-
54 : // Untergrenze, wenn die Attribute
55 : // nicht beibehalten werden sollen.
56 :
57 : sal_Bool bStripTrailingPara : 1; // letzen Absatz entfernen?
58 : sal_Bool bKeepNumRules : 1; // Numerierung beibehalten?
59 : sal_Bool bFixHeaderDist : 1;
60 : sal_Bool bFixFooterDist : 1;
61 :
62 : public:
63 :
64 0 : _HTMLAttrContext_SaveDoc() :
65 : pPos( 0 ), pAttrTab( 0 ),
66 : nContextStMin( USHRT_MAX ), nContextStAttrMin( USHRT_MAX ),
67 : bStripTrailingPara( sal_False ), bKeepNumRules( sal_False ),
68 0 : bFixHeaderDist( sal_False ), bFixFooterDist( sal_False )
69 0 : {}
70 :
71 0 : ~_HTMLAttrContext_SaveDoc() { delete pPos; delete pAttrTab; }
72 :
73 : // Die Position gehoert uns, muss also angelegt und zerstoert werden
74 0 : void SetPos( const SwPosition& rPos ) { pPos = new SwPosition(rPos); }
75 0 : const SwPosition *GetPos() const { return pPos; }
76 :
77 : // Der Index gehoert uns nicht. Kein Anlgen und Zerstoeren.
78 0 : void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); }
79 0 : const SwHTMLNumRuleInfo& GetNumInfo() const { return aNumRuleInfo; }
80 :
81 : _HTMLAttrTable *GetAttrTab( sal_Bool bCreate= sal_False );
82 :
83 0 : void SetContextStMin( sal_uInt16 nMin ) { nContextStMin = nMin; }
84 0 : sal_uInt16 GetContextStMin() const { return nContextStMin; }
85 :
86 0 : void SetContextStAttrMin( sal_uInt16 nMin ) { nContextStAttrMin = nMin; }
87 0 : sal_uInt16 GetContextStAttrMin() const { return nContextStAttrMin; }
88 :
89 0 : void SetStripTrailingPara( sal_Bool bSet ) { bStripTrailingPara = bSet; }
90 0 : sal_Bool GetStripTrailingPara() const { return bStripTrailingPara; }
91 :
92 0 : void SetKeepNumRules( sal_Bool bSet ) { bKeepNumRules = bSet; }
93 0 : sal_Bool GetKeepNumRules() const { return bKeepNumRules; }
94 :
95 0 : void SetFixHeaderDist( sal_Bool bSet ) { bFixHeaderDist = bSet; }
96 0 : sal_Bool GetFixHeaderDist() const { return bFixHeaderDist; }
97 :
98 0 : void SetFixFooterDist( sal_Bool bSet ) { bFixFooterDist = bSet; }
99 0 : sal_Bool GetFixFooterDist() const { return bFixFooterDist; }
100 : };
101 :
102 0 : _HTMLAttrTable *_HTMLAttrContext_SaveDoc::GetAttrTab( sal_Bool bCreate )
103 : {
104 0 : if( !pAttrTab && bCreate )
105 : {
106 0 : pAttrTab = new _HTMLAttrTable;
107 0 : memset( pAttrTab, 0, sizeof( _HTMLAttrTable ));
108 : }
109 0 : return pAttrTab;
110 : }
111 :
112 0 : _HTMLAttrContext_SaveDoc *_HTMLAttrContext::GetSaveDocContext( sal_Bool bCreate )
113 : {
114 0 : if( !pSaveDocContext && bCreate )
115 0 : pSaveDocContext = new _HTMLAttrContext_SaveDoc;
116 :
117 0 : return pSaveDocContext;
118 : }
119 :
120 0 : void _HTMLAttrContext::ClearSaveDocContext()
121 : {
122 0 : delete pSaveDocContext;
123 0 : pSaveDocContext = 0;
124 0 : }
125 :
126 0 : void SwHTMLParser::SplitAttrTab( const SwPosition& rNewPos )
127 : {
128 : // preliminary paragraph attributes are not allowed here, they could
129 : // be set here and then the pointers become invalid!
130 : OSL_ENSURE(aParaAttrs.empty(),
131 : "Danger: there are non-final paragraph attributes");
132 0 : if( !aParaAttrs.empty() )
133 0 : aParaAttrs.clear();
134 :
135 0 : const SwNodeIndex* pOldEndPara = &pPam->GetPoint()->nNode;
136 0 : sal_Int32 nOldEndCnt = pPam->GetPoint()->nContent.GetIndex();
137 :
138 0 : const SwNodeIndex& rNewSttPara = rNewPos.nNode;
139 0 : sal_Int32 nNewSttCnt = rNewPos.nContent.GetIndex();
140 :
141 0 : sal_Bool bMoveBack = sal_False;
142 :
143 : // alle noch offenen Attribute beenden und hinter der Tabelle
144 : // neu aufspannen
145 0 : _HTMLAttr** pTbl = (_HTMLAttr**)&aAttrTab;
146 0 : for( sal_uInt16 nCnt = sizeof( _HTMLAttrTable ) / sizeof( _HTMLAttr* );
147 : nCnt--; ++pTbl )
148 : {
149 0 : _HTMLAttr *pAttr = *pTbl;
150 0 : while( pAttr )
151 : {
152 0 : _HTMLAttr *pNext = pAttr->GetNext();
153 0 : _HTMLAttr *pPrev = pAttr->GetPrev();
154 :
155 0 : sal_uInt16 nWhich = pAttr->pItem->Which();
156 0 : if( !nOldEndCnt && RES_PARATR_BEGIN <= nWhich &&
157 0 : pAttr->GetSttParaIdx() < pOldEndPara->GetIndex() )
158 : {
159 : // Das Attribut muss eine Content-Position weiter vorne
160 : // beendet werden
161 0 : if( !bMoveBack )
162 : {
163 0 : bMoveBack = pPam->Move( fnMoveBackward );
164 0 : nOldEndCnt = pPam->GetPoint()->nContent.GetIndex();
165 : }
166 : }
167 0 : else if( bMoveBack )
168 : {
169 0 : pPam->Move( fnMoveForward );
170 0 : nOldEndCnt = pPam->GetPoint()->nContent.GetIndex();
171 : }
172 :
173 0 : if( (RES_PARATR_BEGIN <= nWhich && bMoveBack) ||
174 0 : pAttr->GetSttParaIdx() < pOldEndPara->GetIndex() ||
175 0 : (pAttr->GetSttPara() == *pOldEndPara &&
176 0 : pAttr->GetSttCnt() != nOldEndCnt) )
177 : {
178 : // Das Attribut muss gesetzt werden. Da wir
179 : // das Original noch brauchen, weil Zeiger auf das Attribut
180 : // noch in den Kontexten existieren, muessen wir es clonen.
181 : // Die Next-Liste geht dabei verloren, aber die
182 : // Previous-Liste bleibt erhalten
183 0 : _HTMLAttr *pSetAttr = pAttr->Clone( *pOldEndPara, nOldEndCnt );
184 :
185 0 : if( pNext )
186 0 : pNext->InsertPrev( pSetAttr );
187 : else
188 : {
189 0 : if (pSetAttr->bInsAtStart)
190 0 : aSetAttrTab.push_front( pSetAttr );
191 : else
192 0 : aSetAttrTab.push_back( pSetAttr );
193 : }
194 : }
195 0 : else if( pPrev )
196 : {
197 : // Wenn das Attribut nicht gesetzt vor der Tabelle
198 : // gesetzt werden muss, muessen der Previous-Attribute
199 : // trotzdem gesetzt werden.
200 0 : if( pNext )
201 0 : pNext->InsertPrev( pPrev );
202 : else
203 : {
204 0 : if (pPrev->bInsAtStart)
205 0 : aSetAttrTab.push_front( pPrev );
206 : else
207 0 : aSetAttrTab.push_back( pPrev );
208 : }
209 : }
210 :
211 : // den Start des Attributs neu setzen
212 0 : pAttr->nSttPara = rNewSttPara;
213 0 : pAttr->nEndPara = rNewSttPara;
214 0 : pAttr->nSttCntnt = nNewSttCnt;
215 0 : pAttr->nEndCntnt = nNewSttCnt;
216 0 : pAttr->pPrev = 0;
217 :
218 0 : pAttr = pNext;
219 : }
220 : }
221 :
222 0 : if( bMoveBack )
223 0 : pPam->Move( fnMoveForward );
224 :
225 0 : }
226 :
227 0 : void SwHTMLParser::SaveDocContext( _HTMLAttrContext *pCntxt,
228 : sal_uInt16 nFlags,
229 : const SwPosition *pNewPos )
230 : {
231 0 : _HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext( sal_True );
232 0 : pSave->SetStripTrailingPara( (HTML_CNTXT_STRIP_PARA & nFlags) != 0 );
233 0 : pSave->SetKeepNumRules( (HTML_CNTXT_KEEP_NUMRULE & nFlags) != 0 );
234 0 : pSave->SetFixHeaderDist( (HTML_CNTXT_HEADER_DIST & nFlags) != 0 );
235 0 : pSave->SetFixFooterDist( (HTML_CNTXT_FOOTER_DIST & nFlags) != 0 );
236 :
237 0 : if( pNewPos )
238 : {
239 : // Wenn der PaM an eine andere Position gesetzt wird, muss
240 : // die Numerierung gerettet werden..
241 0 : if( !pSave->GetKeepNumRules() )
242 : {
243 : // Die Numerierung soll nicht beibehalten werden. Also muss
244 : // der aktuelle Zustand gerettet und die Numerierung
245 : // anschliessend ausgeschaltet werden.
246 0 : pSave->SetNumInfo( GetNumInfo() );
247 0 : GetNumInfo().Clear();
248 : }
249 :
250 0 : if( (HTML_CNTXT_KEEP_ATTRS & nFlags) != 0 )
251 : {
252 : // Attribute an aktueller Position beenden und an neuer neu anfangen
253 0 : SplitAttrTab( *pNewPos );
254 : }
255 : else
256 : {
257 0 : _HTMLAttrTable *pSaveAttrTab = pSave->GetAttrTab( sal_True );
258 0 : SaveAttrTab( *pSaveAttrTab );
259 : }
260 :
261 0 : pSave->SetPos( *pPam->GetPoint() );
262 0 : *pPam->GetPoint() = *pNewPos;
263 : }
264 :
265 : // Mit dem Setzen von nContextStMin koennen automatisch auch
266 : // keine gerade offenen Listen (DL/OL/UL) mehr beendet werden.
267 0 : if( (HTML_CNTXT_PROTECT_STACK & nFlags) != 0 )
268 : {
269 0 : pSave->SetContextStMin( nContextStMin );
270 0 : nContextStMin = aContexts.size();
271 :
272 0 : if( (HTML_CNTXT_KEEP_ATTRS & nFlags) == 0 )
273 : {
274 0 : pSave->SetContextStAttrMin( nContextStAttrMin );
275 0 : nContextStAttrMin = aContexts.size();
276 : }
277 : }
278 0 : }
279 :
280 0 : void SwHTMLParser::RestoreDocContext( _HTMLAttrContext *pCntxt )
281 : {
282 0 : _HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext();
283 0 : if( !pSave )
284 0 : return;
285 :
286 0 : if( pSave->GetStripTrailingPara() )
287 0 : StripTrailingPara();
288 :
289 0 : if( pSave->GetPos() )
290 : {
291 0 : if( pSave->GetFixHeaderDist() || pSave->GetFixFooterDist() )
292 0 : FixHeaderFooterDistance( pSave->GetFixHeaderDist(),
293 0 : pSave->GetPos() );
294 :
295 0 : _HTMLAttrTable *pSaveAttrTab = pSave->GetAttrTab();
296 0 : if( !pSaveAttrTab )
297 : {
298 : // Attribute an aktueller Position beenden und an alter neu
299 : // anfangen.
300 0 : SplitAttrTab( *pSave->GetPos() );
301 : }
302 : else
303 : {
304 0 : RestoreAttrTab( *pSaveAttrTab );
305 : }
306 :
307 0 : *pPam->GetPoint() = *pSave->GetPos();
308 :
309 : // Die bisherigen Attribute koennen wir schonmal setzen.
310 0 : SetAttr();
311 : }
312 :
313 0 : if( USHRT_MAX != pSave->GetContextStMin() )
314 : {
315 0 : nContextStMin = pSave->GetContextStMin();
316 0 : if( USHRT_MAX != pSave->GetContextStAttrMin() )
317 0 : nContextStAttrMin = pSave->GetContextStAttrMin();
318 : }
319 :
320 0 : if( !pSave->GetKeepNumRules() )
321 : {
322 : // Die bisherige gemerkte Numerierung wieder setzen
323 0 : GetNumInfo().Set( pSave->GetNumInfo() );
324 : }
325 :
326 0 : pCntxt->ClearSaveDocContext();
327 : }
328 :
329 0 : void SwHTMLParser::EndContext( _HTMLAttrContext *pContext )
330 : {
331 0 : if( pContext->GetPopStack() )
332 : {
333 : // Alle noch offenen Kontexte beenden. Der eigene
334 : // Kontext muss bereits geloscht sein!
335 0 : while( aContexts.size() > nContextStMin )
336 : {
337 0 : _HTMLAttrContext *pCntxt = PopContext();
338 : OSL_ENSURE( pCntxt != pContext,
339 : "Kontext noch im Stack" );
340 0 : if( pCntxt == pContext )
341 0 : break;
342 :
343 0 : EndContext( pCntxt );
344 0 : delete pCntxt;
345 : }
346 : }
347 :
348 : // Alle noch offenen Attribute beenden
349 0 : if( pContext->HasAttrs() )
350 0 : EndContextAttrs( pContext );
351 :
352 : // Falls ein Bereich geoeffnet wurde, den verlassen. Da Bereiche
353 : // auch innerhalb von absolut positionierten Objekten angelegt werden,
354 : // muss das passieren, bever ein alter Dokument-Kontext restauriert wird.
355 0 : if( pContext->GetSpansSection() )
356 0 : EndSection();
357 :
358 : // Rahmen und sonstige Sonderbereiche verlassen.
359 0 : if( pContext->HasSaveDocContext() )
360 0 : RestoreDocContext( pContext );
361 :
362 : // Ggf. noch einen Ansatz-Umbruch einfuegen
363 0 : if( AM_NONE != pContext->GetAppendMode() &&
364 0 : pPam->GetPoint()->nContent.GetIndex() )
365 0 : AppendTxtNode( pContext->GetAppendMode() );
366 :
367 : // PRE-/LISTING- und XMP-Umgebungen wieder starten
368 0 : if( pContext->IsFinishPREListingXMP() )
369 0 : FinishPREListingXMP();
370 :
371 0 : if( pContext->IsRestartPRE() )
372 0 : StartPRE();
373 :
374 0 : if( pContext->IsRestartXMP() )
375 0 : StartXMP();
376 :
377 0 : if( pContext->IsRestartListing() )
378 0 : StartListing();
379 0 : }
380 :
381 0 : void SwHTMLParser::ClearContext( _HTMLAttrContext *pContext )
382 : {
383 0 : _HTMLAttrs &rAttrs = pContext->GetAttrs();
384 0 : for( sal_uInt16 i=0; i<rAttrs.size(); i++ )
385 : {
386 : // einfaches Loeschen reicht hier nicht, weil das
387 : // Attribut auch aus seiner Liste ausgetragen werden
388 : // muss. Theoretisch koennt man natuerlich auch die Liste
389 : // und die Attribute getrennt loeschen, aber wenn man
390 : // dann was falsch gemacht hat, sieht es uebel aus.
391 0 : DeleteAttr( rAttrs[i] );
392 : }
393 :
394 : OSL_ENSURE( !pContext->GetSpansSection(),
395 : "Bereich kann nicht mehr verlassen werden" );
396 :
397 : OSL_ENSURE( !pContext->HasSaveDocContext(),
398 : "Rahmen kann nicht mehr verlassen werden" );
399 :
400 : // PRE-/LISTING- und XMP-Umgebungen wieder starten
401 0 : if( pContext->IsFinishPREListingXMP() )
402 0 : FinishPREListingXMP();
403 :
404 0 : if( pContext->IsRestartPRE() )
405 0 : StartPRE();
406 :
407 0 : if( pContext->IsRestartXMP() )
408 0 : StartXMP();
409 :
410 0 : if( pContext->IsRestartListing() )
411 0 : StartListing();
412 0 : }
413 :
414 0 : sal_Bool SwHTMLParser::DoPositioning( SfxItemSet &rItemSet,
415 : SvxCSS1PropertyInfo &rPropInfo,
416 : _HTMLAttrContext *pContext )
417 : {
418 0 : sal_Bool bRet = sal_False;
419 :
420 : // Unter folgenden Umstaenden wird jetzt ein Rahmen aufgemacht:
421 : // - das Tag wird absolut positioniert und left/top sind beide
422 : // gegeben und enthalten auch keine %-Angabe, oder
423 : // - das Tag soll fliessen, und
424 : // - es wurde eine Breite angegeben (in beiden Faellen noetig)
425 0 : if( SwCSS1Parser::MayBePositioned( rPropInfo ) )
426 : {
427 0 : SfxItemSet aFrmItemSet( pDoc->GetAttrPool(),
428 0 : RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
429 0 : if( !IsNewDoc() )
430 0 : Reader::ResetFrmFmtAttrs(aFrmItemSet );
431 :
432 : // Ausrichtung setzen
433 : SetAnchorAndAdjustment( text::VertOrientation::NONE, text::HoriOrientation::NONE, rItemSet, rPropInfo,
434 0 : aFrmItemSet );
435 :
436 : // Groesse setzen
437 0 : SetVarSize( rItemSet, rPropInfo, aFrmItemSet );
438 :
439 : // Abstaende setzen
440 0 : SetSpace( Size(0,0), rItemSet, rPropInfo, aFrmItemSet );
441 :
442 : // Sonstige CSS1-Attribute Setzen
443 : SetFrmFmtAttrs( rItemSet, rPropInfo,
444 : HTML_FF_BOX|HTML_FF_PADDING|HTML_FF_BACKGROUND|HTML_FF_DIRECTION,
445 0 : aFrmItemSet );
446 :
447 : InsertFlyFrame( aFrmItemSet, pContext, rPropInfo.aId,
448 0 : CONTEXT_FLAGS_ABSPOS );
449 0 : pContext->SetPopStack( sal_True );
450 0 : rPropInfo.aId = "";
451 0 : bRet = sal_True;
452 : }
453 :
454 0 : return bRet;
455 : }
456 :
457 0 : sal_Bool SwHTMLParser::CreateContainer( const OUString& rClass,
458 : SfxItemSet &rItemSet,
459 : SvxCSS1PropertyInfo &rPropInfo,
460 : _HTMLAttrContext *pContext )
461 : {
462 0 : sal_Bool bRet = sal_False;
463 0 : if( rClass.equalsIgnoreAsciiCase( "sd-abs-pos" ) &&
464 0 : pCSS1Parser->MayBePositioned( rPropInfo ) )
465 : {
466 : // Container-Klasse
467 0 : SfxItemSet *pFrmItemSet = pContext->GetFrmItemSet( pDoc );
468 0 : if( !IsNewDoc() )
469 0 : Reader::ResetFrmFmtAttrs( *pFrmItemSet );
470 :
471 : SetAnchorAndAdjustment( text::VertOrientation::NONE, text::HoriOrientation::NONE,
472 0 : rItemSet, rPropInfo, *pFrmItemSet );
473 0 : Size aDummy(0,0);
474 : SetFixSize( aDummy, aDummy, sal_False, sal_False, rItemSet, rPropInfo,
475 0 : *pFrmItemSet );
476 0 : SetSpace( aDummy, rItemSet, rPropInfo, *pFrmItemSet );
477 : SetFrmFmtAttrs( rItemSet, rPropInfo, HTML_FF_BOX|HTML_FF_BACKGROUND|HTML_FF_DIRECTION,
478 0 : *pFrmItemSet );
479 :
480 0 : bRet = sal_True;
481 : }
482 :
483 0 : return bRet;
484 : }
485 :
486 0 : void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet,
487 : SvxCSS1PropertyInfo &rPropInfo,
488 : _HTMLAttrContext *pContext,
489 : sal_Bool bCharLvl )
490 : {
491 : // Ein DropCap-Attribut basteln, wenn auf Zeichen-Ebene vor dem
492 : // ersten Zeichen ein float: left vorkommt
493 0 : if( bCharLvl && !pPam->GetPoint()->nContent.GetIndex() &&
494 0 : SVX_ADJUST_LEFT == rPropInfo.eFloat )
495 : {
496 0 : SwFmtDrop aDrop;
497 0 : aDrop.GetChars() = 1;
498 :
499 0 : pCSS1Parser->FillDropCap( aDrop, rItemSet );
500 :
501 : // Nur wenn das Initial auch ueber mehrere Zeilen geht, wird das
502 : // DropCap-Attribut gesetzt. Sonst setzten wir die Attribute hart.
503 0 : if( aDrop.GetLines() > 1 )
504 : {
505 0 : NewAttr( &aAttrTab.pDropCap, aDrop );
506 :
507 0 : _HTMLAttrs &rAttrs = pContext->GetAttrs();
508 0 : rAttrs.push_back( aAttrTab.pDropCap );
509 :
510 0 : return;
511 0 : }
512 : }
513 :
514 : // Feature: PrintExt
515 0 : if( !bCharLvl )
516 0 : pCSS1Parser->SetFmtBreak( rItemSet, rPropInfo );
517 : // /Feature: PrintExt
518 :
519 : OSL_ENSURE(aContexts.size() <= nContextStAttrMin ||
520 : aContexts.back() != pContext,
521 : "SwHTMLParser::InsertAttrs: Context already on the Stack");
522 :
523 0 : SfxItemIter aIter( rItemSet );
524 :
525 0 : const SfxPoolItem *pItem = aIter.FirstItem();
526 0 : while( pItem )
527 : {
528 0 : _HTMLAttr **ppAttr = 0;
529 :
530 0 : switch( pItem->Which() )
531 : {
532 : case RES_LR_SPACE:
533 : {
534 : // Absatz-Einzuege muessen addiert werden und werden immer
535 : // nur absatzweise gesetzt (fuer den ersten Absatz hier,
536 : // fuer alle folgenden in SetTxtCollAttrs)
537 :
538 : const SvxLRSpaceItem *pLRItem =
539 0 : (const SvxLRSpaceItem *)pItem;
540 :
541 : // die bisherigen Absatz-Abstaende holen (ohne die vom
542 : // obersten Kontext, denn den veraendern wir ja gerade) ...
543 0 : sal_uInt16 nOldLeft = 0, nOldRight = 0;
544 0 : short nOldIndent = 0;
545 0 : sal_Bool bIgnoreTop = aContexts.size() > nContextStMin &&
546 0 : aContexts.back() == pContext;
547 : GetMarginsFromContext( nOldLeft, nOldRight, nOldIndent,
548 0 : bIgnoreTop );
549 :
550 : // und noch die aktuell gueltigen
551 0 : sal_uInt16 nLeft = nOldLeft, nRight = nOldRight;
552 0 : short nIndent = nOldIndent;
553 0 : pContext->GetMargins( nLeft, nRight, nIndent );
554 :
555 : // ... und die neuen Abstaende zu den alten addieren
556 : // Hier werden nicht die aus dem Item genommen, sondern die
557 : // extra gemerkten, weil die auch negativ sein koennen. Die
558 : // Abfrage ueber das Item funktioniert aber trotzdem, denn
559 : // fuer negative Werte wird das Item (mit Wert 0) auch
560 : // eingefuegt.
561 0 : if( rPropInfo.bLeftMargin )
562 : {
563 : OSL_ENSURE( rPropInfo.nLeftMargin < 0 ||
564 : rPropInfo.nLeftMargin == pLRItem->GetTxtLeft(),
565 : "linker Abstand stimmt nicht mit Item ueberein" );
566 0 : if( rPropInfo.nLeftMargin < 0 &&
567 0 : -rPropInfo.nLeftMargin > nOldLeft )
568 0 : nLeft = 0;
569 : else
570 0 : nLeft = nOldLeft + static_cast< sal_uInt16 >(rPropInfo.nLeftMargin);
571 : }
572 0 : if( rPropInfo.bRightMargin )
573 : {
574 : OSL_ENSURE( rPropInfo.nRightMargin < 0 ||
575 : rPropInfo.nRightMargin == pLRItem->GetRight(),
576 : "rechter Abstand stimmt nicht mit Item ueberein" );
577 0 : if( rPropInfo.nRightMargin < 0 &&
578 0 : -rPropInfo.nRightMargin > nOldRight )
579 0 : nRight = 0;
580 : else
581 0 : nRight = nOldRight + static_cast< sal_uInt16 >(rPropInfo.nRightMargin);
582 : }
583 0 : if( rPropInfo.bTextIndent )
584 0 : nIndent = pLRItem->GetTxtFirstLineOfst();
585 :
586 : // und die Werte fuer nachfolgende Absaetze merken
587 0 : pContext->SetMargins( nLeft, nRight, nIndent );
588 :
589 : // das Attribut noch am aktuellen Absatz setzen
590 0 : SvxLRSpaceItem aLRItem( *pLRItem );
591 0 : aLRItem.SetTxtFirstLineOfst( nIndent );
592 0 : aLRItem.SetTxtLeft( nLeft );
593 0 : aLRItem.SetRight( nRight );
594 0 : NewAttr( &aAttrTab.pLRSpace, aLRItem );
595 0 : EndAttr( aAttrTab.pLRSpace, 0, sal_False );
596 : }
597 0 : break;
598 :
599 : case RES_UL_SPACE:
600 0 : if( !rPropInfo.bTopMargin || !rPropInfo.bBottomMargin )
601 : {
602 0 : sal_uInt16 nUpper = 0, nLower = 0;
603 0 : GetULSpaceFromContext( nUpper, nLower );
604 0 : SvxULSpaceItem aULSpace( *((const SvxULSpaceItem *)pItem) );
605 0 : if( !rPropInfo.bTopMargin )
606 0 : aULSpace.SetUpper( nUpper );
607 0 : if( !rPropInfo.bBottomMargin )
608 0 : aULSpace.SetLower( nLower );
609 :
610 0 : NewAttr( &aAttrTab.pULSpace, aULSpace );
611 :
612 : // ... und noch die Kontext-Information speichern
613 0 : _HTMLAttrs &rAttrs = pContext->GetAttrs();
614 0 : rAttrs.push_back( aAttrTab.pULSpace );
615 :
616 0 : pContext->SetULSpace( aULSpace.GetUpper(), aULSpace.GetLower() );
617 : }
618 : else
619 : {
620 0 : ppAttr = &aAttrTab.pULSpace;
621 : }
622 0 : break;
623 : case RES_CHRATR_FONTSIZE:
624 : // es werden keine Attribute mit %-Angaben gesetzt
625 0 : if( ((const SvxFontHeightItem *)pItem)->GetProp() == 100 )
626 0 : ppAttr = &aAttrTab.pFontHeight;
627 0 : break;
628 : case RES_CHRATR_CJK_FONTSIZE:
629 : // es werden keine Attribute mit %-Angaben gesetzt
630 0 : if( ((const SvxFontHeightItem *)pItem)->GetProp() == 100 )
631 0 : ppAttr = &aAttrTab.pFontHeightCJK;
632 0 : break;
633 : case RES_CHRATR_CTL_FONTSIZE:
634 : // es werden keine Attribute mit %-Angaben gesetzt
635 0 : if( ((const SvxFontHeightItem *)pItem)->GetProp() == 100 )
636 0 : ppAttr = &aAttrTab.pFontHeightCTL;
637 0 : break;
638 :
639 : case RES_BACKGROUND:
640 0 : if( bCharLvl )
641 : {
642 : // das Frame-Attr ggf. in ein Char-Attr umwandeln
643 0 : SvxBrushItem aBrushItem( *(const SvxBrushItem *)pItem );
644 0 : aBrushItem.SetWhich( RES_CHRATR_BACKGROUND );
645 :
646 : // Das Attribut setzen ...
647 0 : NewAttr( &aAttrTab.pCharBrush, aBrushItem );
648 :
649 : // ... und noch die Kontext-Information speichern
650 0 : _HTMLAttrs &rAttrs = pContext->GetAttrs();
651 0 : rAttrs.push_back( aAttrTab.pCharBrush );
652 : }
653 0 : else if( pContext->GetToken() != HTML_TABLEHEADER_ON &&
654 0 : pContext->GetToken() != HTML_TABLEDATA_ON )
655 : {
656 0 : ppAttr = &aAttrTab.pBrush;
657 : }
658 0 : break;
659 :
660 : case RES_BOX:
661 0 : if( bCharLvl )
662 : {
663 0 : SvxBoxItem aBoxItem( *(const SvxBoxItem *)pItem );
664 0 : aBoxItem.SetWhich( RES_CHRATR_BOX );
665 :
666 0 : NewAttr( &aAttrTab.pCharBox, aBoxItem );
667 :
668 0 : _HTMLAttrs &rAttrs = pContext->GetAttrs();
669 0 : rAttrs.push_back( aAttrTab.pCharBox );
670 : }
671 : else
672 : {
673 0 : ppAttr = &aAttrTab.pBox;
674 : }
675 0 : break;
676 :
677 : default:
678 : // den zu dem Item gehoehrenden Tabellen-Eintrag ermitteln ...
679 0 : ppAttr = GetAttrTabEntry( pItem->Which() );
680 0 : break;
681 : }
682 :
683 0 : if( ppAttr )
684 : {
685 : // Das Attribut setzen ...
686 0 : NewAttr( ppAttr, *pItem );
687 :
688 : // ... und noch die Kontext-Information speichern
689 0 : _HTMLAttrs &rAttrs = pContext->GetAttrs();
690 0 : rAttrs.push_back( *ppAttr );
691 : }
692 :
693 : // auf zum naechsten Item
694 0 : pItem = aIter.NextItem();
695 : }
696 :
697 0 : if( !rPropInfo.aId.isEmpty() )
698 0 : InsertBookmark( rPropInfo.aId );
699 : }
700 :
701 0 : void SwHTMLParser::InsertAttr( _HTMLAttr **ppAttr, const SfxPoolItem & rItem,
702 : _HTMLAttrContext *pCntxt )
703 : {
704 0 : if( !ppAttr )
705 : {
706 0 : ppAttr = GetAttrTabEntry( rItem.Which() );
707 0 : if( !ppAttr )
708 0 : return;
709 : }
710 :
711 : // das Attribut setzen
712 0 : NewAttr( ppAttr, rItem );
713 :
714 : // und im Kontext merken
715 0 : _HTMLAttrs &rAttrs = pCntxt->GetAttrs();
716 0 : rAttrs.push_back( *ppAttr );
717 : }
718 :
719 0 : void SwHTMLParser::SplitPREListingXMP( _HTMLAttrContext *pCntxt )
720 : {
721 : // PRE/Listing/XMP soll beim beenden des Kontexts beendet werden.
722 0 : pCntxt->SetFinishPREListingXMP( sal_True );
723 :
724 : // Und die jetzt gueltigen Flags sollen wieder gesetzt werden.
725 0 : if( IsReadPRE() )
726 0 : pCntxt->SetRestartPRE( sal_True );
727 0 : if( IsReadXMP() )
728 0 : pCntxt->SetRestartXMP( sal_True );
729 0 : if( IsReadListing() )
730 0 : pCntxt->SetRestartListing( sal_True );
731 :
732 : // PRE/Listing/XMP wird auuserdem sofort beendet
733 0 : FinishPREListingXMP();
734 0 : }
735 :
736 0 : SfxItemSet *_HTMLAttrContext::GetFrmItemSet( SwDoc *pCreateDoc )
737 : {
738 0 : if( !pFrmItemSet && pCreateDoc )
739 0 : pFrmItemSet = new SfxItemSet( pCreateDoc->GetAttrPool(),
740 0 : RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
741 0 : return pFrmItemSet;
742 : }
743 :
744 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|