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 <comphelper/string.hxx>
22 : #include <vcl/svapp.hxx>
23 : #include <vcl/wrkwin.hxx>
24 : #include <svx/svxids.hrc>
25 : #include <sfx2/sfx.hrc>
26 : #include <i18nlangtag/languagetag.hxx>
27 : #include <svl/stritem.hxx>
28 : #include <svl/urihelper.hxx>
29 : #include <editeng/fhgtitem.hxx>
30 : #include <editeng/lrspitem.hxx>
31 : #include <editeng/adjustitem.hxx>
32 : #include <editeng/brushitem.hxx>
33 : #include <editeng/colritem.hxx>
34 : #include <editeng/boxitem.hxx>
35 : #include <editeng/ulspitem.hxx>
36 : #include <editeng/langitem.hxx>
37 : #include <editeng/scripttypeitem.hxx>
38 : #include <sfx2/docfile.hxx>
39 : #include <svtools/imap.hxx>
40 : #include <svtools/htmltokn.h>
41 : #include <svtools/htmlkywd.hxx>
42 : #include <unotools/eventcfg.hxx>
43 :
44 : #include <fmtornt.hxx>
45 : #include <fmturl.hxx>
46 : #include <fmtsrnd.hxx>
47 : #include <fmtinfmt.hxx>
48 : #include <fmtcntnt.hxx>
49 : #include <fmtanchr.hxx>
50 : #include <fmtfsize.hxx>
51 : #include "frmatr.hxx"
52 : #include "charatr.hxx"
53 : #include <frmfmt.hxx>
54 : #include <charfmt.hxx>
55 : #include <docary.hxx>
56 : #include <docsh.hxx>
57 : #include <pam.hxx>
58 : #include <doc.hxx>
59 : #include <ndtxt.hxx>
60 : #include <shellio.hxx>
61 : #include <poolfmt.hxx>
62 : #include <IMark.hxx>
63 : #include <ndgrf.hxx>
64 : #include <htmlnum.hxx>
65 : #include <swcss1.hxx>
66 : #include <swhtml.hxx>
67 : #include <numrule.hxx>
68 : #include <boost/shared_ptr.hpp>
69 :
70 : #include <sax/tools/converter.hxx>
71 : #include <vcl/graphicfilter.hxx>
72 :
73 : using namespace ::com::sun::star;
74 :
75 : HTMLOptionEnum aHTMLImgHAlignTable[] =
76 : {
77 : { OOO_STRING_SVTOOLS_HTML_AL_left, text::HoriOrientation::LEFT },
78 : { OOO_STRING_SVTOOLS_HTML_AL_right, text::HoriOrientation::RIGHT },
79 : { 0, 0 }
80 : };
81 :
82 : HTMLOptionEnum aHTMLImgVAlignTable[] =
83 : {
84 : { OOO_STRING_SVTOOLS_HTML_VA_top, text::VertOrientation::LINE_TOP },
85 : { OOO_STRING_SVTOOLS_HTML_VA_texttop, text::VertOrientation::CHAR_TOP },
86 : { OOO_STRING_SVTOOLS_HTML_VA_middle, text::VertOrientation::CENTER },
87 : { OOO_STRING_SVTOOLS_HTML_AL_center, text::VertOrientation::CENTER },
88 : { OOO_STRING_SVTOOLS_HTML_VA_absmiddle, text::VertOrientation::LINE_CENTER },
89 : { OOO_STRING_SVTOOLS_HTML_VA_bottom, text::VertOrientation::TOP },
90 : { OOO_STRING_SVTOOLS_HTML_VA_baseline, text::VertOrientation::TOP },
91 : { OOO_STRING_SVTOOLS_HTML_VA_absbottom, text::VertOrientation::LINE_BOTTOM },
92 : { 0, 0 }
93 : };
94 :
95 0 : ImageMap *SwHTMLParser::FindImageMap( const OUString& rName ) const
96 : {
97 0 : ImageMap *pMap = 0;
98 :
99 : OSL_ENSURE( rName[0] != '#', "FindImageName: Name beginnt mit #!" );
100 :
101 0 : if( pImageMaps )
102 : {
103 0 : for( sal_uInt16 i=0; i<pImageMaps->size(); i++ )
104 : {
105 0 : ImageMap *pIMap = &(*pImageMaps)[i];
106 0 : if( rName.equalsIgnoreAsciiCase( pIMap->GetName() ) )
107 : {
108 0 : pMap = pIMap;
109 0 : break;
110 : }
111 : }
112 : }
113 0 : return pMap;
114 : }
115 :
116 0 : void SwHTMLParser::ConnectImageMaps()
117 : {
118 0 : SwNodes& rNds = pDoc->GetNodes();
119 : // auf den Start-Node der 1. Section
120 0 : sal_uLong nIdx = rNds.GetEndOfAutotext().StartOfSectionIndex() + 1;
121 0 : sal_uLong nEndIdx = rNds.GetEndOfAutotext().GetIndex();
122 :
123 : SwGrfNode* pGrfNd;
124 0 : while( nMissingImgMaps > 0 && nIdx < nEndIdx )
125 : {
126 0 : SwNode *pNd = rNds[nIdx + 1];
127 0 : if( 0 != (pGrfNd = pNd->GetGrfNode()) )
128 : {
129 0 : SwFrmFmt *pFmt = pGrfNd->GetFlyFmt();
130 0 : SwFmtURL aURL( pFmt->GetURL() );
131 0 : const ImageMap *pIMap = aURL.GetMap();
132 0 : if( pIMap && pIMap->GetIMapObjectCount()==0 )
133 : {
134 : // Die (leere) Image-Map des Nodes wird entweder
135 : // durch die jetzt gefundene Image-Map ersetzt
136 : // oder geloescht.
137 : ImageMap *pNewIMap =
138 0 : FindImageMap( pIMap->GetName() );
139 0 : aURL.SetMap( pNewIMap );
140 0 : pFmt->SetFmtAttr( aURL );
141 0 : if( !pGrfNd->IsScaleImageMap() )
142 : {
143 : // die Grafikgroesse ist mitlerweile da oder dir
144 : // Grafik muss nicht skaliert werden
145 0 : pGrfNd->ScaleImageMap();
146 : }
147 0 : nMissingImgMaps--; // eine Map weniger suchen
148 0 : }
149 : }
150 0 : nIdx = rNds[nIdx]->EndOfSectionIndex() + 1;
151 : }
152 0 : }
153 :
154 : /* */
155 :
156 3 : void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
157 : sal_Int16 eHoriOri,
158 : const SfxItemSet &rCSS1ItemSet,
159 : const SvxCSS1PropertyInfo &rCSS1PropInfo,
160 : SfxItemSet& rFrmItemSet )
161 : {
162 3 : const SfxItemSet *pCntnrItemSet = 0;
163 3 : sal_uInt16 i = aContexts.size();
164 7 : while( !pCntnrItemSet && i > nContextStMin )
165 1 : pCntnrItemSet = aContexts[--i]->GetFrmItemSet();
166 :
167 3 : if( pCntnrItemSet )
168 : {
169 : // Wenn wir und in einem Container befinden wird die Verankerung
170 : // des Containers uebernommen.
171 0 : rFrmItemSet.Put( *pCntnrItemSet );
172 : }
173 3 : else if( pCSS1Parser->MayBePositioned( rCSS1PropInfo, sal_True ) )
174 : {
175 : // Wenn die Ausrichtung anhand der CSS1-Optionen gesetzt werden kann
176 : // werden die benutzt.
177 1 : SetAnchorAndAdjustment( rCSS1ItemSet, rCSS1PropInfo, rFrmItemSet );
178 : }
179 : else
180 : {
181 : // Sonst wird die Ausrichtung entsprechend der normalen HTML-Optionen
182 : // gesetzt.
183 2 : SetAnchorAndAdjustment( eVertOri, eHoriOri, rFrmItemSet );
184 : }
185 3 : }
186 :
187 2 : void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
188 : sal_Int16 eHoriOri,
189 : SfxItemSet& rFrmSet,
190 : sal_Bool bDontAppend )
191 : {
192 2 : sal_Bool bMoveBackward = sal_False;
193 2 : SwFmtAnchor aAnchor( FLY_AS_CHAR );
194 2 : sal_Int16 eVertRel = text::RelOrientation::FRAME;
195 :
196 2 : if( text::HoriOrientation::NONE != eHoriOri )
197 : {
198 : // den Absatz-Einzug bestimmen
199 0 : sal_uInt16 nLeftSpace = 0, nRightSpace = 0;
200 0 : short nIndent = 0;
201 0 : GetMarginsFromContextWithNumBul( nLeftSpace, nRightSpace, nIndent );
202 :
203 : // Horizonale Ausrichtung und Umlauf bestimmen.
204 : sal_Int16 eHoriRel;
205 : SwSurround eSurround;
206 0 : switch( eHoriOri )
207 : {
208 : case text::HoriOrientation::LEFT:
209 0 : eHoriRel = nLeftSpace ? text::RelOrientation::PRINT_AREA : text::RelOrientation::FRAME;
210 0 : eSurround = SURROUND_RIGHT;
211 0 : break;
212 : case text::HoriOrientation::RIGHT:
213 0 : eHoriRel = nRightSpace ? text::RelOrientation::PRINT_AREA : text::RelOrientation::FRAME;
214 0 : eSurround = SURROUND_LEFT;
215 0 : break;
216 : case text::HoriOrientation::CENTER: // fuer Tabellen
217 0 : eHoriRel = text::RelOrientation::FRAME;
218 0 : eSurround = SURROUND_NONE;
219 0 : break;
220 : default:
221 0 : eHoriRel = text::RelOrientation::FRAME;
222 0 : eSurround = SURROUND_PARALLEL;
223 0 : break;
224 : }
225 :
226 : // Einen neuen Absatz aufmachen, wenn der aktuelle
227 : // absatzgebundene Rahmen ohne Umlauf enthaelt.
228 0 : if( !bDontAppend && HasCurrentParaFlys( sal_True ) )
229 : {
230 : // Wenn der Absatz nur Grafiken enthaelt, braucht er
231 : // auch keinen unteren Absatz-Abstand. Da hier auch bei
232 : // Verwendung von Styles kein Abstand enstehen soll, wird
233 : // hier auch geweohnlich attributiert !!!
234 0 : sal_uInt16 nUpper=0, nLower=0;
235 0 : GetULSpaceFromContext( nUpper, nLower );
236 0 : InsertAttr( SvxULSpaceItem( nUpper, 0, RES_UL_SPACE ), sal_False, sal_True );
237 :
238 0 : AppendTxtNode( AM_NOSPACE );
239 :
240 0 : if( nUpper )
241 : {
242 0 : NewAttr( &aAttrTab.pULSpace, SvxULSpaceItem( 0, nLower, RES_UL_SPACE ) );
243 0 : aParaAttrs.push_back( aAttrTab.pULSpace );
244 0 : EndAttr( aAttrTab.pULSpace, 0, sal_False );
245 : }
246 : }
247 :
248 : // Vertikale Ausrichtung und Verankerung bestimmen.
249 0 : const sal_Int32 nCntnt = pPam->GetPoint()->nContent.GetIndex();
250 0 : if( nCntnt )
251 : {
252 0 : aAnchor.SetType( FLY_AT_CHAR );
253 0 : bMoveBackward = sal_True;
254 0 : eVertOri = text::VertOrientation::CHAR_BOTTOM;
255 0 : eVertRel = text::RelOrientation::CHAR;
256 : }
257 : else
258 : {
259 0 : aAnchor.SetType( FLY_AT_PARA );
260 0 : eVertOri = text::VertOrientation::TOP;
261 0 : eVertRel = text::RelOrientation::PRINT_AREA;
262 : }
263 :
264 0 : rFrmSet.Put( SwFmtHoriOrient( 0, eHoriOri, eHoriRel) );
265 :
266 0 : rFrmSet.Put( SwFmtSurround( eSurround ) );
267 : }
268 2 : rFrmSet.Put( SwFmtVertOrient( 0, eVertOri, eVertRel) );
269 :
270 2 : if( bMoveBackward )
271 0 : pPam->Move( fnMoveBackward );
272 :
273 2 : aAnchor.SetAnchor( pPam->GetPoint() );
274 :
275 2 : if( bMoveBackward )
276 0 : pPam->Move( fnMoveForward );
277 :
278 2 : rFrmSet.Put( aAnchor );
279 2 : }
280 :
281 3 : void SwHTMLParser::RegisterFlyFrm( SwFrmFmt *pFlyFmt )
282 : {
283 : // automatisch verankerte Rahmen muessen noch um eine Position
284 : // nach vorne verschoben werden.
285 9 : if( RES_DRAWFRMFMT != pFlyFmt->Which() &&
286 3 : (FLY_AT_PARA == pFlyFmt->GetAnchor().GetAnchorId()) &&
287 0 : SURROUND_THROUGHT == pFlyFmt->GetSurround().GetSurround() )
288 : {
289 0 : aMoveFlyFrms.push_back( pFlyFmt );
290 0 : aMoveFlyCnts.push_back( pPam->GetPoint()->nContent.GetIndex() );
291 : }
292 3 : }
293 :
294 : /* */
295 :
296 8 : void SwHTMLParser::GetDefaultScriptType( ScriptType& rType,
297 : OUString& rTypeStr ) const
298 : {
299 8 : SwDocShell *pDocSh = pDoc->GetDocShell();
300 8 : SvKeyValueIterator* pHeaderAttrs = pDocSh ? pDocSh->GetHeaderAttributes()
301 16 : : 0;
302 8 : rType = GetScriptType( pHeaderAttrs );
303 8 : rTypeStr = GetScriptTypeString( pHeaderAttrs );
304 8 : }
305 :
306 : /* */
307 :
308 1 : void SwHTMLParser::InsertImage()
309 : {
310 : // und jetzt auswerten
311 2 : OUString sAltNm, aId, aClass, aStyle, aMap, sHTMLGrfName;
312 2 : OUString sGrfNm;
313 1 : sal_Int16 eVertOri = text::VertOrientation::TOP;
314 1 : sal_Int16 eHoriOri = text::HoriOrientation::NONE;
315 1 : long nWidth=0, nHeight=0;
316 1 : long nVSpace=0, nHSpace=0;
317 :
318 1 : sal_uInt16 nBorder = (aAttrTab.pINetFmt ? 1 : 0);
319 1 : sal_Bool bIsMap = sal_False;
320 1 : sal_Bool bPrcWidth = sal_False;
321 1 : sal_Bool bPrcHeight = sal_False;
322 2 : SvxMacroItem aMacroItem(RES_FRMMACRO);
323 :
324 : ScriptType eDfltScriptType;
325 2 : OUString sDfltScriptType;
326 1 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
327 :
328 1 : const HTMLOptions& rHTMLOptions = GetOptions();
329 3 : for (size_t i = rHTMLOptions.size(); i; )
330 : {
331 1 : sal_uInt16 nEvent = 0;
332 1 : ScriptType eScriptType2 = eDfltScriptType;
333 1 : const HTMLOption& rOption = rHTMLOptions[--i];
334 1 : switch( rOption.GetToken() )
335 : {
336 : case HTML_O_ID:
337 0 : aId = rOption.GetString();
338 0 : break;
339 : case HTML_O_STYLE:
340 0 : aStyle = rOption.GetString();
341 0 : break;
342 : case HTML_O_CLASS:
343 0 : aClass = rOption.GetString();
344 0 : break;
345 : case HTML_O_SRC:
346 1 : sGrfNm = rOption.GetString();
347 1 : if( !InternalImgToPrivateURL(sGrfNm) )
348 1 : sGrfNm = INetURLObject::GetAbsURL( sBaseURL, sGrfNm );
349 1 : break;
350 : case HTML_O_ALIGN:
351 : eVertOri =
352 : rOption.GetEnum( aHTMLImgVAlignTable,
353 0 : text::VertOrientation::TOP );
354 : eHoriOri =
355 : rOption.GetEnum( aHTMLImgHAlignTable,
356 0 : text::HoriOrientation::NONE );
357 0 : break;
358 : case HTML_O_WIDTH:
359 : // erstmal nur als Pixelwerte merken!
360 0 : nWidth = rOption.GetNumber();
361 0 : bPrcWidth = (rOption.GetString().indexOf('%') != -1);
362 0 : if( bPrcWidth && nWidth>100 )
363 0 : nWidth = 100;
364 0 : break;
365 : case HTML_O_HEIGHT:
366 : // erstmal nur als Pixelwerte merken!
367 0 : nHeight = rOption.GetNumber();
368 0 : bPrcHeight = (rOption.GetString().indexOf('%') != -1);
369 0 : if( bPrcHeight && nHeight>100 )
370 0 : nHeight = 100;
371 0 : break;
372 : case HTML_O_VSPACE:
373 0 : nVSpace = rOption.GetNumber();
374 0 : break;
375 : case HTML_O_HSPACE:
376 0 : nHSpace = rOption.GetNumber();
377 0 : break;
378 : case HTML_O_ALT:
379 0 : sAltNm = rOption.GetString();
380 0 : break;
381 : case HTML_O_BORDER:
382 0 : nBorder = (sal_uInt16)rOption.GetNumber();
383 0 : break;
384 : case HTML_O_ISMAP:
385 0 : bIsMap = sal_True;
386 0 : break;
387 : case HTML_O_USEMAP:
388 0 : aMap = rOption.GetString();
389 0 : break;
390 : case HTML_O_NAME:
391 0 : sHTMLGrfName = rOption.GetString();
392 0 : break;
393 :
394 : case HTML_O_SDONLOAD:
395 0 : eScriptType2 = STARBASIC;
396 : //fallthrough
397 : case HTML_O_ONLOAD:
398 0 : nEvent = SVX_EVENT_IMAGE_LOAD;
399 0 : goto IMAGE_SETEVENT;
400 :
401 : case HTML_O_SDONABORT:
402 0 : eScriptType2 = STARBASIC;
403 : //fallthrough
404 : case HTML_O_ONABORT:
405 0 : nEvent = SVX_EVENT_IMAGE_ABORT;
406 0 : goto IMAGE_SETEVENT;
407 :
408 : case HTML_O_SDONERROR:
409 0 : eScriptType2 = STARBASIC;
410 : //fallthrough
411 : case HTML_O_ONERROR:
412 0 : nEvent = SVX_EVENT_IMAGE_ERROR;
413 0 : goto IMAGE_SETEVENT;
414 : IMAGE_SETEVENT:
415 : {
416 0 : OUString sTmp( rOption.GetString() );
417 0 : if( !sTmp.isEmpty() )
418 : {
419 0 : sTmp = convertLineEnd(sTmp, GetSystemLineEnd());
420 0 : OUString sScriptType;
421 0 : if( EXTENDED_STYPE == eScriptType2 )
422 0 : sScriptType = sDfltScriptType;
423 : aMacroItem.SetMacro( nEvent,
424 0 : SvxMacro( sTmp, sScriptType, eScriptType2 ));
425 0 : }
426 : }
427 0 : break;
428 : }
429 : }
430 :
431 1 : if( sGrfNm.isEmpty() )
432 0 : return;
433 :
434 : // Wenn wir in einer Numerierung stehen und der Absatz noch leer und
435 : // nicht numeriert ist, handelt es sich vielleicht um die Grafik
436 : // einer Bullet-Liste
437 3 : if( !pPam->GetPoint()->nContent.GetIndex() &&
438 1 : GetNumInfo().GetDepth() > 0 && GetNumInfo().GetDepth() <= MAXLEVEL &&
439 1 : !aBulletGrfs[GetNumInfo().GetDepth()-1].isEmpty() &&
440 0 : aBulletGrfs[GetNumInfo().GetDepth()-1]==sGrfNm )
441 : {
442 0 : SwTxtNode* pTxtNode = pPam->GetNode()->GetTxtNode();
443 :
444 0 : if( pTxtNode && ! pTxtNode->IsCountedInList())
445 : {
446 : OSL_ENSURE( pTxtNode->GetActualListLevel() == GetNumInfo().GetLevel(),
447 : "Numerierungs-Ebene stimmt nicht" );
448 :
449 0 : pTxtNode->SetCountedInList( true );
450 :
451 : // Rule invalisieren ist noetig, weil zwischem dem einlesen
452 : // des LI und der Grafik ein EndAction gerufen worden sein kann.
453 0 : if( GetNumInfo().GetNumRule() )
454 0 : GetNumInfo().GetNumRule()->SetInvalidRule( sal_True );
455 :
456 : // Die Vorlage novh mal setzen. Ist noetig, damit der
457 : // Erstzeilen-Einzug stimmt.
458 0 : SetTxtCollAttrs();
459 :
460 0 : return;
461 : }
462 : }
463 :
464 1 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
465 2 : SvxCSS1PropertyInfo aPropInfo;
466 1 : if( HasStyleOptions( aStyle, aId, aClass ) )
467 0 : ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo );
468 :
469 1 : SfxItemSet aFrmSet( pDoc->GetAttrPool(),
470 2 : RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
471 1 : if( !IsNewDoc() )
472 0 : Reader::ResetFrmFmtAttrs( aFrmSet );
473 :
474 : // Umrandung setzen
475 1 : long nHBorderWidth = 0, nVBorderWidth = 0;
476 1 : if( nBorder )
477 : {
478 0 : nHBorderWidth = (long)nBorder;
479 0 : nVBorderWidth = (long)nBorder;
480 0 : SvxCSS1Parser::PixelToTwip( nVBorderWidth, nHBorderWidth );
481 :
482 0 : ::editeng::SvxBorderLine aHBorderLine( NULL, nHBorderWidth );
483 0 : ::editeng::SvxBorderLine aVBorderLine( NULL, nVBorderWidth );
484 :
485 0 : if( aAttrTab.pINetFmt )
486 : {
487 : const OUString& rURL =
488 0 : ((const SwFmtINetFmt&)aAttrTab.pINetFmt->GetItem()).GetValue();
489 :
490 0 : pCSS1Parser->SetATagStyles();
491 0 : sal_uInt16 nPoolId = static_cast< sal_uInt16 >(pDoc->IsVisitedURL( rURL )
492 : ? RES_POOLCHR_INET_VISIT
493 0 : : RES_POOLCHR_INET_NORMAL);
494 0 : const SwCharFmt *pCharFmt = pCSS1Parser->GetCharFmtFromPool( nPoolId );
495 0 : aHBorderLine.SetColor( pCharFmt->GetColor().GetValue() );
496 0 : aVBorderLine.SetColor( aHBorderLine.GetColor() );
497 : }
498 : else
499 : {
500 : const SvxColorItem& rColorItem = aAttrTab.pFontColor ?
501 0 : (const SvxColorItem &)aAttrTab.pFontColor->GetItem() :
502 0 : (const SvxColorItem &)pDoc->GetDefault(RES_CHRATR_COLOR);
503 0 : aHBorderLine.SetColor( rColorItem.GetValue() );
504 0 : aVBorderLine.SetColor( aHBorderLine.GetColor() );
505 : }
506 :
507 0 : SvxBoxItem aBoxItem( RES_BOX );
508 0 : aBoxItem.SetLine( &aHBorderLine, BOX_LINE_TOP );
509 0 : aBoxItem.SetLine( &aHBorderLine, BOX_LINE_BOTTOM );
510 0 : aBoxItem.SetLine( &aVBorderLine, BOX_LINE_LEFT );
511 0 : aBoxItem.SetLine( &aVBorderLine, BOX_LINE_RIGHT );
512 0 : aFrmSet.Put( aBoxItem );
513 : }
514 :
515 : // Ausrichtung setzen
516 1 : SetAnchorAndAdjustment( eVertOri, eHoriOri, aItemSet, aPropInfo, aFrmSet );
517 :
518 : // Abstaende setzen
519 1 : SetSpace( Size( nHSpace, nVSpace), aItemSet, aPropInfo, aFrmSet );
520 :
521 : // Sonstige CSS1-Attribute Setzen
522 1 : SetFrmFmtAttrs( aItemSet, aPropInfo, HTML_FF_BOX, aFrmSet );
523 :
524 1 : Size aTwipSz( bPrcWidth ? 0 : nWidth, bPrcHeight ? 0 : nHeight );
525 1 : if( (aTwipSz.Width() || aTwipSz.Height()) && Application::GetDefaultDevice() )
526 : {
527 : aTwipSz = Application::GetDefaultDevice()
528 0 : ->PixelToLogic( aTwipSz, MapMode( MAP_TWIP ) );
529 : }
530 :
531 : // CSS1-Groesse auf "normale" Groesse umrechnen
532 1 : switch( aPropInfo.eWidthType )
533 : {
534 : case SVX_CSS1_LTYPE_TWIP:
535 0 : aTwipSz.Width() = aPropInfo.nWidth;
536 0 : nWidth = 1; // != 0
537 0 : bPrcWidth = sal_False;
538 0 : break;
539 : case SVX_CSS1_LTYPE_PERCENTAGE:
540 0 : aTwipSz.Width() = 0;
541 0 : nWidth = aPropInfo.nWidth;
542 0 : bPrcWidth = sal_True;
543 0 : break;
544 : default:
545 : ;
546 : }
547 1 : switch( aPropInfo.eHeightType )
548 : {
549 : case SVX_CSS1_LTYPE_TWIP:
550 0 : aTwipSz.Height() = aPropInfo.nHeight;
551 0 : nHeight = 1; // != 0
552 0 : bPrcHeight = sal_False;
553 0 : break;
554 : case SVX_CSS1_LTYPE_PERCENTAGE:
555 0 : aTwipSz.Height() = 0;
556 0 : nHeight = aPropInfo.nHeight;
557 0 : bPrcHeight = sal_True;
558 0 : break;
559 : default:
560 : ;
561 : }
562 :
563 1 : Size aGrfSz( 0, 0 );
564 1 : sal_Bool bSetTwipSize = sal_True; // Twip-Size am Node setzen?
565 1 : bool bChangeFrmSize = false; // Frame-Format nachtraeglich anpassen?
566 1 : sal_Bool bRequestGrfNow = sal_False;
567 1 : bool bSetScaleImageMap = false;
568 1 : sal_uInt8 nPrcWidth = 0, nPrcHeight = 0;
569 :
570 1 : if( !nWidth || !nHeight )
571 : {
572 : // Es fehlt die Breite oder die Hoehe
573 : // Wenn die Grfik in einer Tabelle steht, wird sie gleich
574 : // angefordert, damit sie eventuell schon da ist, bevor die
575 : // Tabelle layoutet wird.
576 1 : if( pTable!=0 && !nWidth )
577 : {
578 0 : bRequestGrfNow = sal_True;
579 0 : IncGrfsThatResizeTable();
580 : }
581 :
582 : // Die Groesse des Rahmens wird nachtraeglich gesetzt
583 1 : bChangeFrmSize = true;
584 1 : aGrfSz = aTwipSz;
585 2 : if( !nWidth && !nHeight )
586 : {
587 1 : aTwipSz.Width() = HTML_DFLT_IMG_WIDTH;
588 1 : aTwipSz.Height() = HTML_DFLT_IMG_HEIGHT;
589 : }
590 0 : else if( nWidth )
591 : {
592 : // eine %-Angabe
593 0 : if( bPrcWidth )
594 : {
595 0 : nPrcWidth = (sal_uInt8)nWidth;
596 0 : nPrcHeight = 255;
597 : }
598 : else
599 : {
600 0 : aTwipSz.Height() = HTML_DFLT_IMG_HEIGHT;
601 : }
602 : }
603 0 : else if( nHeight )
604 : {
605 0 : if( bPrcHeight )
606 : {
607 0 : nPrcHeight = (sal_uInt8)nHeight;
608 0 : nPrcWidth = 255;
609 : }
610 : else
611 : {
612 0 : aTwipSz.Width() = HTML_DFLT_IMG_WIDTH;
613 : }
614 : }
615 : }
616 : else
617 : {
618 : // Breite und Hoehe wurden angegeben und brauchen nicht gesetzt
619 : // zu werden
620 0 : bSetTwipSize = sal_False;
621 :
622 0 : if( bPrcWidth )
623 0 : nPrcWidth = (sal_uInt8)nWidth;
624 :
625 0 : if( bPrcHeight )
626 0 : nPrcHeight = (sal_uInt8)nHeight;
627 : }
628 :
629 : // Image-Map setzen
630 1 : aMap = comphelper::string::stripEnd(aMap, ' ');
631 1 : if( !aMap.isEmpty() )
632 : {
633 : // Da wir nur lokale Image-Maps kennen nehmen wireinfach alles
634 : // hinter dem # als Namen
635 0 : sal_Int32 nPos = aMap.indexOf( '#' );
636 0 : OUString aName;
637 0 : if ( -1 == nPos )
638 0 : aName = aMap ;
639 : else
640 0 : aName = aMap.copy(nPos+1);
641 :
642 0 : ImageMap *pImgMap = FindImageMap( aName );
643 0 : if( pImgMap )
644 : {
645 0 : SwFmtURL aURL; aURL.SetMap( pImgMap );//wird kopieiert
646 :
647 0 : bSetScaleImageMap = !nPrcWidth || !nPrcHeight;
648 0 : aFrmSet.Put( aURL );
649 : }
650 : else
651 : {
652 0 : ImageMap aEmptyImgMap( aName );
653 0 : SwFmtURL aURL; aURL.SetMap( &aEmptyImgMap );//wird kopieiert
654 0 : aFrmSet.Put( aURL );
655 0 : nMissingImgMaps++; // es fehlen noch Image-Maps
656 :
657 : // die Grafik muss beim SetTwipSize skaliert werden, wenn
658 : // wir keine Groesse am Node gesetzt haben oder die Groesse
659 : // nicht der Grafikgroesse entsprach.
660 0 : bSetScaleImageMap = true;
661 0 : }
662 : }
663 :
664 : // min. Werte einhalten !!
665 1 : if( nPrcWidth )
666 : {
667 : OSL_ENSURE( !aTwipSz.Width(),
668 : "Wieso ist da trotz %-Angabe eine Breite gesetzt?" );
669 0 : aTwipSz.Width() = aGrfSz.Width() ? aGrfSz.Width()
670 0 : : HTML_DFLT_IMG_WIDTH;
671 : }
672 : else
673 : {
674 1 : aTwipSz.Width() += 2*nVBorderWidth;
675 1 : if( aTwipSz.Width() < MINFLY )
676 0 : aTwipSz.Width() = MINFLY;
677 : }
678 1 : if( nPrcHeight )
679 : {
680 : OSL_ENSURE( !aTwipSz.Height(),
681 : "Wieso ist da trotz %-Angabe eine Hoehe gesetzt?" );
682 0 : aTwipSz.Height() = aGrfSz.Height() ? aGrfSz.Height()
683 0 : : HTML_DFLT_IMG_HEIGHT;
684 : }
685 : else
686 : {
687 1 : aTwipSz.Height() += 2*nHBorderWidth;
688 1 : if( aTwipSz.Height() < MINFLY )
689 0 : aTwipSz.Height() = MINFLY;
690 : }
691 :
692 1 : SwFmtFrmSize aFrmSize( ATT_FIX_SIZE, aTwipSz.Width(), aTwipSz.Height() );
693 1 : aFrmSize.SetWidthPercent( nPrcWidth );
694 1 : aFrmSize.SetHeightPercent( nPrcHeight );
695 1 : aFrmSet.Put( aFrmSize );
696 :
697 2 : Graphic aEmptyGrf;
698 1 : if( sGrfNm.startsWith("data:") )
699 : {
700 : // use embedded base64 encoded data
701 0 : ::com::sun::star::uno::Sequence< sal_Int8 > aPass;
702 0 : OUString sBase64Data = sGrfNm.replaceAt(0,22,"");
703 0 : ::sax::Converter::decodeBase64(aPass, sBase64Data);
704 0 : if( aPass.hasElements() )
705 : {
706 0 : SvMemoryStream aStream(aPass.getArray(), aPass.getLength(), STREAM_READ);
707 0 : GraphicFilter::GetGraphicFilter().ImportGraphic( aEmptyGrf, OUString(), aStream );
708 0 : }
709 : }
710 : else
711 : {
712 1 : aEmptyGrf.SetDefaultType();
713 : }
714 : SwFrmFmt *pFlyFmt = pDoc->Insert( *pPam, sGrfNm, aEmptyOUStr, &aEmptyGrf,
715 1 : &aFrmSet, NULL, NULL );
716 2 : SwGrfNode *pGrfNd = pDoc->GetNodes()[ pFlyFmt->GetCntnt().GetCntntIdx()
717 2 : ->GetIndex()+1 ]->GetGrfNode();
718 :
719 1 : if( !sHTMLGrfName.isEmpty() )
720 : {
721 0 : pFlyFmt->SetName( sHTMLGrfName );
722 :
723 : // ggfs. eine Grafik anspringen
724 0 : if( JUMPTO_GRAPHIC == eJumpTo && sHTMLGrfName == sJmpMark )
725 : {
726 0 : bChkJumpMark = true;
727 0 : eJumpTo = JUMPTO_NONE;
728 : }
729 : }
730 :
731 1 : if (pGrfNd)
732 : {
733 1 : if( !sAltNm.isEmpty() )
734 0 : pGrfNd->SetTitle( sAltNm );
735 :
736 1 : if( bSetTwipSize )
737 1 : pGrfNd->SetTwipSize( aGrfSz );
738 :
739 1 : pGrfNd->SetChgTwipSize( bChangeFrmSize, bChangeFrmSize );
740 :
741 1 : if( bSetScaleImageMap )
742 0 : pGrfNd->SetScaleImageMap( true );
743 : }
744 :
745 1 : if( aAttrTab.pINetFmt )
746 : {
747 : const SwFmtINetFmt &rINetFmt =
748 0 : (const SwFmtINetFmt&)aAttrTab.pINetFmt->GetItem();
749 :
750 0 : SwFmtURL aURL( pFlyFmt->GetURL() );
751 :
752 0 : aURL.SetURL( rINetFmt.GetValue(), bIsMap );
753 0 : aURL.SetTargetFrameName( rINetFmt.GetTargetFrame() );
754 0 : aURL.SetName( rINetFmt.GetName() );
755 0 : pFlyFmt->SetFmtAttr( aURL );
756 :
757 : {
758 : const SvxMacro *pMacro;
759 : static const sal_uInt16 aEvents[] = {
760 : SFX_EVENT_MOUSEOVER_OBJECT,
761 : SFX_EVENT_MOUSECLICK_OBJECT,
762 : SFX_EVENT_MOUSEOUT_OBJECT,
763 : 0 };
764 :
765 0 : for( sal_uInt16 n = 0; aEvents[ n ]; ++n )
766 0 : if( 0 != ( pMacro = rINetFmt.GetMacro( aEvents[ n ] ) ))
767 0 : aMacroItem.SetMacro( aEvents[ n ], *pMacro );
768 : }
769 :
770 0 : if ((FLY_AS_CHAR == pFlyFmt->GetAnchor().GetAnchorId()) &&
771 0 : aAttrTab.pINetFmt->GetSttPara() ==
772 0 : pPam->GetPoint()->nNode &&
773 0 : aAttrTab.pINetFmt->GetSttCnt() ==
774 0 : pPam->GetPoint()->nContent.GetIndex() - 1 )
775 : {
776 : // das Attribut wurde unmitellbar vor einer zeichengeb.
777 : // Grafik eingefuegt, also verschieben wir es
778 0 : aAttrTab.pINetFmt->SetStart( *pPam->GetPoint() );
779 :
780 : // Wenn das Attribut auch ein Sprungziel ist, fuegen
781 : // wir noch eine Bookmark vor der Grafik ein, weil das
782 : // SwFmtURL kein Sprungziel ist.
783 0 : if( !rINetFmt.GetName().isEmpty() )
784 : {
785 0 : pPam->Move( fnMoveBackward );
786 0 : InsertBookmark( rINetFmt.GetName() );
787 0 : pPam->Move( fnMoveForward );
788 : }
789 0 : }
790 :
791 : }
792 :
793 1 : if( !aMacroItem.GetMacroTable().empty() )
794 0 : pFlyFmt->SetFmtAttr( aMacroItem );
795 :
796 : // Wenn die Grafik gleich angeforder wird, muss dies geschehen,
797 : // nachdem das Format vollstaendig aufgebaut ist, weil es evtl.
798 : // gleich (synchron) angepasst wird (war bug #40983#)
799 1 : if (bRequestGrfNow && pGrfNd)
800 : {
801 0 : pGrfNd->SwapIn();
802 : }
803 :
804 : // Ggf. Frames anlegen und Auto-gebundenen Rahmen registrieren
805 1 : RegisterFlyFrm( pFlyFmt );
806 :
807 1 : if( !aId.isEmpty() )
808 3 : InsertBookmark( aId );
809 : }
810 :
811 : /* */
812 :
813 5 : void SwHTMLParser::InsertBodyOptions()
814 : {
815 : pDoc->SetTxtFmtColl( *pPam,
816 5 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_TEXT ) );
817 :
818 10 : OUString aBackGround, aId, aStyle, aLang, aDir;
819 5 : Color aBGColor, aTextColor, aLinkColor, aVLinkColor;
820 5 : sal_Bool bBGColor=sal_False, bTextColor=sal_False;
821 5 : sal_Bool bLinkColor=sal_False, bVLinkColor=sal_False;
822 :
823 : ScriptType eDfltScriptType;
824 10 : OUString sDfltScriptType;
825 5 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
826 :
827 5 : const HTMLOptions& rHTMLOptions = GetOptions();
828 19 : for (size_t i = rHTMLOptions.size(); i; )
829 : {
830 9 : const HTMLOption& rOption = rHTMLOptions[--i];
831 9 : ScriptType eScriptType2 = eDfltScriptType;
832 9 : OUString aEvent;
833 9 : sal_Bool bSetEvent = sal_False;
834 :
835 9 : switch( rOption.GetToken() )
836 : {
837 : case HTML_O_ID:
838 0 : aId = rOption.GetString();
839 0 : break;
840 : case HTML_O_BACKGROUND:
841 0 : aBackGround = rOption.GetString();
842 0 : break;
843 : case HTML_O_BGCOLOR:
844 0 : rOption.GetColor( aBGColor );
845 0 : bBGColor = sal_True;
846 0 : break;
847 : case HTML_O_TEXT:
848 0 : rOption.GetColor( aTextColor );
849 0 : bTextColor = sal_True;
850 0 : break;
851 : case HTML_O_LINK:
852 1 : rOption.GetColor( aLinkColor );
853 1 : bLinkColor = sal_True;
854 1 : break;
855 : case HTML_O_VLINK:
856 0 : rOption.GetColor( aVLinkColor );
857 0 : bVLinkColor = sal_True;
858 0 : break;
859 :
860 : case HTML_O_SDONLOAD:
861 0 : eScriptType2 = STARBASIC;
862 : //fallthrough
863 : case HTML_O_ONLOAD:
864 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC );
865 0 : bSetEvent = sal_True;
866 0 : break;
867 :
868 : case HTML_O_SDONUNLOAD:
869 0 : eScriptType2 = STARBASIC;
870 : //fallthrough
871 : case HTML_O_ONUNLOAD:
872 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC );
873 0 : bSetEvent = sal_True;
874 0 : break;
875 :
876 : case HTML_O_SDONFOCUS:
877 0 : eScriptType2 = STARBASIC;
878 : //fallthrough
879 : case HTML_O_ONFOCUS:
880 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC );
881 0 : bSetEvent = sal_True;
882 0 : break;
883 :
884 : case HTML_O_SDONBLUR:
885 0 : eScriptType2 = STARBASIC;
886 : //fallthrough
887 : case HTML_O_ONBLUR:
888 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC );
889 0 : bSetEvent = sal_True;
890 0 : break;
891 :
892 : case HTML_O_ONERROR:
893 0 : break;
894 :
895 : case HTML_O_STYLE:
896 1 : aStyle = rOption.GetString();
897 1 : bTextColor = sal_True;
898 1 : break;
899 : case HTML_O_LANG:
900 3 : aLang = rOption.GetString();
901 3 : break;
902 : case HTML_O_DIR:
903 3 : aDir = rOption.GetString();
904 3 : break;
905 : }
906 :
907 9 : if( bSetEvent )
908 : {
909 0 : const OUString& rEvent = rOption.GetString();
910 0 : if( !rEvent.isEmpty() )
911 : InsertBasicDocEvent( aEvent, rEvent, eScriptType2,
912 0 : sDfltScriptType );
913 : }
914 9 : }
915 :
916 5 : if( bTextColor && !pCSS1Parser->IsBodyTextSet() )
917 : {
918 : // Die Textfarbe wird an der Standard-Vorlage gesetzt
919 1 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_STANDARD )
920 1 : ->SetFmtAttr( SvxColorItem(aTextColor, RES_CHRATR_COLOR) );
921 1 : pCSS1Parser->SetBodyTextSet();
922 : }
923 :
924 : // Die Item fuer die Seitenvorlage vorbereiten (Hintergrund, Umrandung)
925 : // Beim BrushItem muessen schon gesetzte werte erhalten bleiben!
926 5 : SvxBrushItem aBrushItem( pCSS1Parser->GetPageDescBackground() );
927 5 : sal_Bool bSetBrush = sal_False;
928 :
929 5 : if( bBGColor && !pCSS1Parser->IsBodyBGColorSet() )
930 : {
931 : // Hintergrundfarbe aus "BGCOLOR"
932 0 : OUString aLink;
933 0 : if( !aBrushItem.GetGraphicLink().isEmpty() )
934 0 : aLink = aBrushItem.GetGraphicLink();
935 0 : SvxGraphicPosition ePos = aBrushItem.GetGraphicPos();
936 :
937 0 : aBrushItem.SetColor( aBGColor );
938 :
939 0 : if( !aLink.isEmpty() )
940 : {
941 0 : aBrushItem.SetGraphicLink( aLink );
942 0 : aBrushItem.SetGraphicPos( ePos );
943 : }
944 0 : bSetBrush = sal_True;
945 0 : pCSS1Parser->SetBodyBGColorSet();
946 : }
947 :
948 5 : if( !aBackGround.isEmpty() && !pCSS1Parser->IsBodyBackgroundSet() )
949 : {
950 : // Hintergrundgrafik aus "BACKGROUND"
951 0 : aBrushItem.SetGraphicLink( INetURLObject::GetAbsURL( sBaseURL, aBackGround ) );
952 0 : aBrushItem.SetGraphicPos( GPOS_TILED );
953 0 : bSetBrush = sal_True;
954 0 : pCSS1Parser->SetBodyBackgroundSet();
955 : }
956 :
957 5 : if( !aStyle.isEmpty() || !aDir.isEmpty() )
958 : {
959 3 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
960 6 : SvxCSS1PropertyInfo aPropInfo;
961 6 : OUString aDummy;
962 3 : ParseStyleOptions( aStyle, aDummy, aDummy, aItemSet, aPropInfo, 0, &aDir );
963 :
964 : // Ein par Attribute muessen an der Seitenvorlage gesetzt werden,
965 : // und zwar die, die nicht vererbit werden
966 : pCSS1Parser->SetPageDescAttrs( bSetBrush ? &aBrushItem : 0,
967 3 : &aItemSet );
968 :
969 : const SfxPoolItem *pItem;
970 : static const sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONTSIZE,
971 : RES_CHRATR_CJK_FONTSIZE,
972 : RES_CHRATR_CTL_FONTSIZE };
973 12 : for( sal_uInt16 i=0; i<3; i++ )
974 : {
975 18 : if( SFX_ITEM_SET == aItemSet.GetItemState( aWhichIds[i], false,
976 9 : &pItem ) &&
977 0 : static_cast <const SvxFontHeightItem * >(pItem)->GetProp() != 100)
978 : {
979 : sal_uInt32 nHeight =
980 0 : ( aFontHeights[2] *
981 0 : static_cast <const SvxFontHeightItem * >(pItem)->GetProp() ) / 100;
982 0 : SvxFontHeightItem aNewItem( nHeight, 100, aWhichIds[i] );
983 0 : aItemSet.Put( aNewItem );
984 : }
985 : }
986 :
987 : // alle noch uebrigen Optionen koennen an der Standard-Vorlage
988 : // gesetzt werden und gelten dann automatisch als defaults
989 3 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_STANDARD )
990 6 : ->SetFmtAttr( aItemSet );
991 : }
992 2 : else if( bSetBrush )
993 : {
994 0 : pCSS1Parser->SetPageDescAttrs( &aBrushItem );
995 : }
996 :
997 5 : if( bLinkColor && !pCSS1Parser->IsBodyLinkSet() )
998 : {
999 : SwCharFmt *pCharFmt =
1000 1 : pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_INET_NORMAL);
1001 1 : pCharFmt->SetFmtAttr( SvxColorItem(aLinkColor, RES_CHRATR_COLOR) );
1002 1 : pCSS1Parser->SetBodyLinkSet();
1003 : }
1004 5 : if( bVLinkColor && !pCSS1Parser->IsBodyVLinkSet() )
1005 : {
1006 : SwCharFmt *pCharFmt =
1007 0 : pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_INET_VISIT);
1008 0 : pCharFmt->SetFmtAttr( SvxColorItem(aVLinkColor, RES_CHRATR_COLOR) );
1009 0 : pCSS1Parser->SetBodyVLinkSet();
1010 : }
1011 5 : if( !aLang.isEmpty() )
1012 : {
1013 3 : LanguageType eLang = LanguageTag::convertToLanguageTypeWithFallback( aLang );
1014 3 : if( LANGUAGE_DONTKNOW != eLang )
1015 : {
1016 3 : sal_uInt16 nWhich = 0;
1017 3 : switch( SvtLanguageOptions::GetScriptTypeOfLanguage( eLang ) )
1018 : {
1019 : case SCRIPTTYPE_LATIN:
1020 3 : nWhich = RES_CHRATR_LANGUAGE;
1021 3 : break;
1022 : case SCRIPTTYPE_ASIAN:
1023 0 : nWhich = RES_CHRATR_CJK_LANGUAGE;
1024 0 : break;
1025 : case SCRIPTTYPE_COMPLEX:
1026 0 : nWhich = RES_CHRATR_CTL_LANGUAGE;
1027 0 : break;
1028 : }
1029 3 : if( nWhich )
1030 : {
1031 3 : SvxLanguageItem aLanguage( eLang, nWhich );
1032 3 : aLanguage.SetWhich( nWhich );
1033 3 : pDoc->SetDefault( aLanguage );
1034 : }
1035 : }
1036 : }
1037 :
1038 5 : if( !aId.isEmpty() )
1039 5 : InsertBookmark( aId );
1040 5 : }
1041 :
1042 : /* */
1043 :
1044 2 : void SwHTMLParser::NewAnchor()
1045 : {
1046 : // den voherigen Link beenden, falls es einen gab
1047 2 : _HTMLAttrContext *pOldCntxt = PopContext( HTML_ANCHOR_ON );
1048 2 : if( pOldCntxt )
1049 : {
1050 : // und ggf. die Attribute beenden
1051 0 : EndContext( pOldCntxt );
1052 0 : delete pOldCntxt;
1053 : }
1054 :
1055 2 : SvxMacroTableDtor aMacroTbl;
1056 4 : OUString sHRef, aName, sTarget;
1057 4 : OUString aId, aStyle, aClass, aLang, aDir;
1058 2 : sal_Bool bHasHRef = sal_False, bFixed = sal_False;
1059 :
1060 : ScriptType eDfltScriptType;
1061 4 : OUString sDfltScriptType;
1062 2 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
1063 :
1064 2 : const HTMLOptions& rHTMLOptions = GetOptions();
1065 9 : for (size_t i = rHTMLOptions.size(); i; )
1066 : {
1067 5 : sal_uInt16 nEvent = 0;
1068 5 : ScriptType eScriptType2 = eDfltScriptType;
1069 5 : const HTMLOption& rOption = rHTMLOptions[--i];
1070 5 : switch( rOption.GetToken() )
1071 : {
1072 : case HTML_O_NAME:
1073 0 : aName = rOption.GetString();
1074 0 : break;
1075 :
1076 : case HTML_O_HREF:
1077 1 : sHRef = rOption.GetString();
1078 1 : bHasHRef = sal_True;
1079 1 : break;
1080 : case HTML_O_TARGET:
1081 1 : sTarget = rOption.GetString();
1082 1 : break;
1083 :
1084 : case HTML_O_STYLE:
1085 0 : aStyle = rOption.GetString();
1086 0 : break;
1087 : case HTML_O_ID:
1088 2 : aId = rOption.GetString();
1089 2 : break;
1090 : case HTML_O_CLASS:
1091 1 : aClass = rOption.GetString();
1092 1 : break;
1093 : case HTML_O_SDFIXED:
1094 0 : bFixed = sal_True;
1095 0 : break;
1096 : case HTML_O_LANG:
1097 0 : aLang = rOption.GetString();
1098 0 : break;
1099 : case HTML_O_DIR:
1100 0 : aDir = rOption.GetString();
1101 0 : break;
1102 :
1103 : case HTML_O_SDONCLICK:
1104 0 : eScriptType2 = STARBASIC;
1105 : case HTML_O_ONCLICK:
1106 0 : nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
1107 0 : goto ANCHOR_SETEVENT;
1108 :
1109 : case HTML_O_SDONMOUSEOVER:
1110 0 : eScriptType2 = STARBASIC;
1111 : case HTML_O_ONMOUSEOVER:
1112 0 : nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
1113 0 : goto ANCHOR_SETEVENT;
1114 :
1115 : case HTML_O_SDONMOUSEOUT:
1116 0 : eScriptType2 = STARBASIC;
1117 : case HTML_O_ONMOUSEOUT:
1118 0 : nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
1119 0 : goto ANCHOR_SETEVENT;
1120 : ANCHOR_SETEVENT:
1121 : {
1122 0 : OUString sTmp( rOption.GetString() );
1123 0 : if( !sTmp.isEmpty() )
1124 : {
1125 0 : sTmp = convertLineEnd(sTmp, GetSystemLineEnd());
1126 0 : OUString sScriptType;
1127 0 : if( EXTENDED_STYPE == eScriptType2 )
1128 0 : sScriptType = sDfltScriptType;
1129 0 : aMacroTbl.Insert( nEvent, SvxMacro( sTmp, sScriptType, eScriptType2 ));
1130 0 : }
1131 : }
1132 0 : break;
1133 :
1134 : }
1135 : }
1136 :
1137 : // Sprungziele, die unseren ipmliziten Zielen entsprechen, schmeissen
1138 : // wir hier ganz rigoros raus.
1139 2 : if( !aName.isEmpty() )
1140 : {
1141 : OUString sDecoded( INetURLObject::decode( aName, '%',
1142 : INetURLObject::DECODE_UNAMBIGUOUS,
1143 0 : RTL_TEXTENCODING_UTF8 ));
1144 0 : sal_Int32 nPos = sDecoded.lastIndexOf( cMarkSeparator );
1145 0 : if( nPos != -1 )
1146 : {
1147 0 : OUString sCmp(comphelper::string::remove(sDecoded.copy(nPos+1), ' '));
1148 0 : if( !sCmp.isEmpty() )
1149 : {
1150 0 : sCmp = sCmp.toAsciiLowerCase();
1151 0 : if( sCmp == "region" ||
1152 0 : sCmp == "frame" ||
1153 0 : sCmp == "graphic" ||
1154 0 : sCmp == "ole" ||
1155 0 : sCmp == "table" ||
1156 0 : sCmp == "outline" ||
1157 0 : sCmp == "text" )
1158 : {
1159 0 : aName = "";
1160 : }
1161 0 : }
1162 0 : }
1163 : }
1164 :
1165 : // einen neuen Kontext anlegen
1166 2 : _HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_ANCHOR_ON );
1167 :
1168 2 : sal_Bool bEnAnchor = sal_False, bFtnAnchor = sal_False, bFtnEnSymbol = sal_False;
1169 2 : OUString aFtnName;
1170 4 : OUString aStrippedClass( aClass );
1171 2 : SwCSS1Parser::GetScriptFromClass( aStrippedClass, sal_False );
1172 6 : if( aStrippedClass.getLength() >=9 && bHasHRef && sHRef.getLength() > 1 &&
1173 4 : ('s' == aStrippedClass[0] || 'S' == aStrippedClass[0]) &&
1174 0 : ('d' == aStrippedClass[1] || 'D' == aStrippedClass[1]) )
1175 : {
1176 0 : if( aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdendnote_anc ) )
1177 0 : bEnAnchor = sal_True;
1178 0 : else if( aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdfootnote_anc ) )
1179 0 : bFtnAnchor = sal_True;
1180 0 : else if( aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdendnote_sym ) ||
1181 0 : aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdfootnote_sym ) )
1182 0 : bFtnEnSymbol = sal_True;
1183 0 : if( bEnAnchor || bFtnAnchor || bFtnEnSymbol )
1184 : {
1185 0 : aFtnName = sHRef.copy( 1 );
1186 0 : aClass = aStrippedClass = aName = aEmptyOUStr;
1187 0 : bHasHRef = sal_False;
1188 : }
1189 : }
1190 :
1191 : // Styles parsen
1192 2 : if( HasStyleOptions( aStyle, aId, aStrippedClass, &aLang, &aDir ) )
1193 : {
1194 2 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
1195 4 : SvxCSS1PropertyInfo aPropInfo;
1196 :
1197 2 : if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
1198 : {
1199 2 : DoPositioning( aItemSet, aPropInfo, pCntxt );
1200 2 : InsertAttrs( aItemSet, aPropInfo, pCntxt, sal_True );
1201 2 : }
1202 : }
1203 :
1204 2 : if( bHasHRef )
1205 : {
1206 1 : if( !sHRef.isEmpty() )
1207 : {
1208 1 : sHRef = URIHelper::SmartRel2Abs( INetURLObject(sBaseURL), sHRef, Link(), false );
1209 : }
1210 : else
1211 : {
1212 : // Bei leerer URL das Directory nehmen
1213 0 : INetURLObject aURLObj( aPathToFile );
1214 0 : sHRef = aURLObj.GetPartBeforeLastName();
1215 : }
1216 :
1217 1 : pCSS1Parser->SetATagStyles();
1218 1 : SwFmtINetFmt aINetFmt( sHRef, sTarget );
1219 1 : aINetFmt.SetName( aName );
1220 :
1221 1 : if( !aMacroTbl.empty() )
1222 0 : aINetFmt.SetMacroTbl( &aMacroTbl );
1223 :
1224 : // das Default-Attribut setzen
1225 1 : InsertAttr( &aAttrTab.pINetFmt, aINetFmt, pCntxt );
1226 : }
1227 1 : else if( !aName.isEmpty() )
1228 : {
1229 0 : InsertBookmark( aName );
1230 : }
1231 :
1232 2 : if( bEnAnchor || bFtnAnchor )
1233 : {
1234 0 : InsertFootEndNote( aFtnName, bEnAnchor, bFixed );
1235 0 : bInFootEndNoteAnchor = bCallNextToken = true;
1236 : }
1237 2 : else if( bFtnEnSymbol )
1238 : {
1239 0 : bInFootEndNoteSymbol = bCallNextToken = true;
1240 : }
1241 :
1242 : // den Kontext merken
1243 6 : PushContext( pCntxt );
1244 2 : }
1245 :
1246 2 : void SwHTMLParser::EndAnchor()
1247 : {
1248 2 : if( bInFootEndNoteAnchor )
1249 : {
1250 0 : FinishFootEndNote();
1251 0 : bInFootEndNoteAnchor = false;
1252 : }
1253 2 : else if( bInFootEndNoteSymbol )
1254 : {
1255 0 : bInFootEndNoteSymbol = false;
1256 : }
1257 :
1258 2 : EndTag( HTML_ANCHOR_OFF );
1259 2 : }
1260 :
1261 : /* */
1262 :
1263 4 : void SwHTMLParser::InsertBookmark( const OUString& rName )
1264 : {
1265 4 : _HTMLAttr* pTmp = new _HTMLAttr( *pPam->GetPoint(),
1266 4 : SfxStringItem( RES_FLTR_BOOKMARK, rName ));
1267 4 : aSetAttrTab.push_back( pTmp );
1268 4 : }
1269 :
1270 5 : sal_Bool SwHTMLParser::HasCurrentParaBookmarks( sal_Bool bIgnoreStack ) const
1271 : {
1272 5 : sal_Bool bHasMarks = sal_False;
1273 5 : sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
1274 :
1275 : // first step: are there still bookmark in the attribute-stack?
1276 : // bookmarks are added to the end of the stack - thus we only have
1277 : // to check the last bookmark
1278 5 : if( !bIgnoreStack )
1279 : {
1280 : _HTMLAttr* pAttr;
1281 3 : for( sal_uInt16 i = aSetAttrTab.size(); i; )
1282 : {
1283 1 : pAttr = aSetAttrTab[ --i ];
1284 1 : if( RES_FLTR_BOOKMARK == pAttr->pItem->Which() )
1285 : {
1286 0 : if( pAttr->GetSttParaIdx() == nNodeIdx )
1287 0 : bHasMarks = sal_True;
1288 0 : break;
1289 : }
1290 : }
1291 : }
1292 :
1293 5 : if( !bHasMarks )
1294 : {
1295 : // second step: when we didnt find a bookmark, check if there is one set already
1296 5 : IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1297 27 : for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
1298 18 : ppMark != pMarkAccess->getAllMarksEnd();
1299 : ++ppMark)
1300 : {
1301 4 : const ::sw::mark::IMark* pBookmark = ppMark->get();
1302 :
1303 4 : const sal_uLong nBookNdIdx = pBookmark->GetMarkPos().nNode.GetIndex();
1304 4 : if( nBookNdIdx==nNodeIdx )
1305 : {
1306 0 : bHasMarks = sal_True;
1307 0 : break;
1308 : }
1309 4 : else if( nBookNdIdx > nNodeIdx )
1310 0 : break;
1311 : }
1312 : }
1313 :
1314 5 : return bHasMarks;
1315 : }
1316 :
1317 : /* */
1318 :
1319 270 : void SwHTMLParser::StripTrailingPara()
1320 : {
1321 270 : sal_Bool bSetSmallFont = sal_False;
1322 :
1323 270 : SwCntntNode* pCNd = pPam->GetCntntNode();
1324 270 : if( !pPam->GetPoint()->nContent.GetIndex() )
1325 : {
1326 540 : if( pCNd && pCNd->StartOfSectionIndex()+2 <
1327 270 : pCNd->EndOfSectionIndex() )
1328 : {
1329 265 : sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
1330 :
1331 265 : const SwFrmFmts& rFrmFmtTbl = *pDoc->GetSpzFrmFmts();
1332 :
1333 276 : for( sal_uInt16 i=0; i<rFrmFmtTbl.size(); i++ )
1334 : {
1335 11 : SwFrmFmt const*const pFmt = rFrmFmtTbl[i];
1336 11 : SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
1337 11 : SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
1338 21 : if (pAPos &&
1339 20 : ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
1340 21 : (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
1341 0 : pAPos->nNode == nNodeIdx )
1342 :
1343 0 : return; // den Knoten duerfen wir nicht loeschen
1344 : }
1345 :
1346 265 : SetAttr( sal_False ); // die noch offenen Attribute muessen
1347 : // beendet werden, bevor der Node
1348 : // geloescht wird, weil sonst der
1349 : // End-Index in die Botanik zeigt
1350 :
1351 265 : if( pCNd->Len() && pCNd->IsTxtNode() )
1352 : {
1353 : // es wurden Felder in den Node eingefuegt, die muessen
1354 : // wir jetzt verschieben
1355 1 : SwTxtNode *pPrvNd = pDoc->GetNodes()[nNodeIdx-1]->GetTxtNode();
1356 1 : if( pPrvNd )
1357 : {
1358 1 : SwIndex aSrc( pCNd, 0 );
1359 1 : pCNd->GetTxtNode()->CutText( pPrvNd, aSrc, pCNd->Len() );
1360 : }
1361 : }
1362 :
1363 : // jetz muessen wir noch eventuell vorhandene Bookmarks verschieben
1364 265 : IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1365 855 : for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
1366 570 : ppMark != pMarkAccess->getAllMarksEnd();
1367 : ++ppMark)
1368 : {
1369 20 : ::sw::mark::IMark* pMark = ppMark->get();
1370 :
1371 20 : sal_uLong nBookNdIdx = pMark->GetMarkPos().nNode.GetIndex();
1372 20 : if(nBookNdIdx==nNodeIdx)
1373 : {
1374 0 : SwNodeIndex nNewNdIdx(pPam->GetPoint()->nNode);
1375 0 : SwCntntNode* pNd = pDoc->GetNodes().GoPrevious(&nNewNdIdx);
1376 0 : if(!pNd)
1377 : {
1378 : OSL_ENSURE(!this, "Hoppla, wo ist mein Vorgaenger-Node");
1379 0 : return;
1380 : }
1381 : // #i81002# - refactoring
1382 : // Do not directly manipulate member of <SwBookmark>
1383 : {
1384 0 : SwPosition aNewPos(*pNd);
1385 0 : aNewPos.nContent.Assign(pNd, pNd->Len());
1386 0 : const SwPaM aPaM(aNewPos);
1387 0 : pMarkAccess->repositionMark(ppMark->get(), aPaM);
1388 0 : }
1389 : }
1390 20 : else if( nBookNdIdx > nNodeIdx )
1391 0 : break;
1392 : }
1393 :
1394 265 : pPam->GetPoint()->nContent.Assign( 0, 0 );
1395 265 : pPam->SetMark();
1396 265 : pPam->DeleteMark();
1397 265 : pDoc->GetNodes().Delete( pPam->GetPoint()->nNode );
1398 265 : pPam->Move( fnMoveBackward, fnGoNode );
1399 : }
1400 5 : else if( pCNd && pCNd->IsTxtNode() && pTable )
1401 : {
1402 : // In leeren Zellen stellen wir einen kleinen Font ein, damit die
1403 : // Zelle nicht hoeher wird als die Grafik bzw. so niedrig wie
1404 : // moeglich bleibt.
1405 0 : bSetSmallFont = sal_True;
1406 : }
1407 : }
1408 0 : else if( pCNd && pCNd->IsTxtNode() && pTable &&
1409 0 : pCNd->StartOfSectionIndex()+2 ==
1410 0 : pCNd->EndOfSectionIndex() )
1411 : {
1412 : // Wenn die Zelle nur zeichengebundene Grafiken/Rahmen enthaelt
1413 : // stellen wir ebenfalls einen kleinen Font ein.
1414 0 : bSetSmallFont = sal_True;
1415 0 : SwTxtNode* pTxtNd = pCNd->GetTxtNode();
1416 :
1417 0 : sal_Int32 nPos = pPam->GetPoint()->nContent.GetIndex();
1418 0 : while( bSetSmallFont && nPos>0 )
1419 : {
1420 0 : --nPos;
1421 : bSetSmallFont =
1422 0 : (CH_TXTATR_BREAKWORD == pTxtNd->GetTxt()[nPos]) &&
1423 0 : (0 != pTxtNd->GetTxtAttrForCharAt( nPos, RES_TXTATR_FLYCNT ));
1424 : }
1425 : }
1426 :
1427 270 : if( bSetSmallFont )
1428 : {
1429 : //Added default to CJK and CTL
1430 0 : SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
1431 0 : pCNd->SetAttr( aFontHeight );
1432 0 : SvxFontHeightItem aFontHeightCJK( 40, 100, RES_CHRATR_CJK_FONTSIZE );
1433 0 : pCNd->SetAttr( aFontHeightCJK );
1434 0 : SvxFontHeightItem aFontHeightCTL( 40, 100, RES_CHRATR_CTL_FONTSIZE );
1435 0 : pCNd->SetAttr( aFontHeightCTL );
1436 : }
1437 : }
1438 :
1439 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|