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