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 <vcl/graphicfilter.hxx>
71 : #include <tools/urlobj.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 12 : void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
157 : sal_Int16 eHoriOri,
158 : const SfxItemSet &rCSS1ItemSet,
159 : const SvxCSS1PropertyInfo &rCSS1PropInfo,
160 : SfxItemSet& rFrmItemSet )
161 : {
162 12 : const SfxItemSet *pCntnrItemSet = 0;
163 12 : sal_uInt16 i = aContexts.size();
164 46 : while( !pCntnrItemSet && i > nContextStMin )
165 22 : pCntnrItemSet = aContexts[--i]->GetFrmItemSet();
166 :
167 12 : 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 12 : else if( SwCSS1Parser::MayBePositioned( rCSS1PropInfo, true ) )
174 : {
175 : // Wenn die Ausrichtung anhand der CSS1-Optionen gesetzt werden kann
176 : // werden die benutzt.
177 2 : SetAnchorAndAdjustment( rCSS1ItemSet, rCSS1PropInfo, rFrmItemSet );
178 : }
179 : else
180 : {
181 : // Sonst wird die Ausrichtung entsprechend der normalen HTML-Optionen
182 : // gesetzt.
183 10 : SetAnchorAndAdjustment( eVertOri, eHoriOri, rFrmItemSet );
184 : }
185 12 : }
186 :
187 10 : void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
188 : sal_Int16 eHoriOri,
189 : SfxItemSet& rFrmSet,
190 : bool bDontAppend )
191 : {
192 10 : bool bMoveBackward = false;
193 10 : SwFmtAnchor aAnchor( FLY_AS_CHAR );
194 10 : sal_Int16 eVertRel = text::RelOrientation::FRAME;
195 :
196 10 : 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( 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 ), false, 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, 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 = 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 10 : rFrmSet.Put( SwFmtVertOrient( 0, eVertOri, eVertRel) );
269 :
270 10 : if( bMoveBackward )
271 0 : pPam->Move( fnMoveBackward );
272 :
273 10 : aAnchor.SetAnchor( pPam->GetPoint() );
274 :
275 10 : if( bMoveBackward )
276 0 : pPam->Move( fnMoveForward );
277 :
278 10 : rFrmSet.Put( aAnchor );
279 10 : }
280 :
281 12 : void SwHTMLParser::RegisterFlyFrm( SwFrmFmt *pFlyFmt )
282 : {
283 : // automatisch verankerte Rahmen muessen noch um eine Position
284 : // nach vorne verschoben werden.
285 36 : if( RES_DRAWFRMFMT != pFlyFmt->Which() &&
286 12 : (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 12 : }
293 :
294 : /* */
295 :
296 38 : void SwHTMLParser::GetDefaultScriptType( ScriptType& rType,
297 : OUString& rTypeStr ) const
298 : {
299 38 : SwDocShell *pDocSh = pDoc->GetDocShell();
300 38 : SvKeyValueIterator* pHeaderAttrs = pDocSh ? pDocSh->GetHeaderAttributes()
301 76 : : 0;
302 38 : rType = GetScriptType( pHeaderAttrs );
303 38 : rTypeStr = GetScriptTypeString( pHeaderAttrs );
304 38 : }
305 :
306 : /* */
307 :
308 8 : void SwHTMLParser::InsertImage()
309 : {
310 : // und jetzt auswerten
311 16 : OUString sAltNm, aId, aClass, aStyle, aMap, sHTMLGrfName;
312 16 : OUString sGrfNm;
313 8 : sal_Int16 eVertOri = text::VertOrientation::TOP;
314 8 : sal_Int16 eHoriOri = text::HoriOrientation::NONE;
315 8 : long nWidth=0, nHeight=0;
316 8 : long nVSpace=0, nHSpace=0;
317 :
318 8 : sal_uInt16 nBorder = (aAttrTab.pINetFmt ? 1 : 0);
319 8 : bool bIsMap = false;
320 8 : bool bPrcWidth = false;
321 8 : bool bPrcHeight = false;
322 16 : SvxMacroItem aMacroItem(RES_FRMMACRO);
323 :
324 : ScriptType eDfltScriptType;
325 16 : OUString sDfltScriptType;
326 8 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
327 :
328 8 : const HTMLOptions& rHTMLOptions = GetOptions();
329 42 : for (size_t i = rHTMLOptions.size(); i; )
330 : {
331 26 : sal_uInt16 nEvent = 0;
332 26 : ScriptType eScriptType2 = eDfltScriptType;
333 26 : const HTMLOption& rOption = rHTMLOptions[--i];
334 26 : 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 8 : sGrfNm = rOption.GetString();
347 8 : if( !InternalImgToPrivateURL(sGrfNm) )
348 8 : sGrfNm = INetURLObject::GetAbsURL( sBaseURL, sGrfNm );
349 8 : break;
350 : case HTML_O_ALIGN:
351 : eVertOri =
352 : rOption.GetEnum( aHTMLImgVAlignTable,
353 2 : text::VertOrientation::TOP );
354 : eHoriOri =
355 : rOption.GetEnum( aHTMLImgHAlignTable,
356 2 : text::HoriOrientation::NONE );
357 2 : break;
358 : case HTML_O_WIDTH:
359 : // erstmal nur als Pixelwerte merken!
360 6 : nWidth = rOption.GetNumber();
361 6 : bPrcWidth = (rOption.GetString().indexOf('%') != -1);
362 6 : if( bPrcWidth && nWidth>100 )
363 0 : nWidth = 100;
364 6 : break;
365 : case HTML_O_HEIGHT:
366 : // erstmal nur als Pixelwerte merken!
367 6 : nHeight = rOption.GetNumber();
368 6 : bPrcHeight = (rOption.GetString().indexOf('%') != -1);
369 6 : if( bPrcHeight && nHeight>100 )
370 0 : nHeight = 100;
371 6 : 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 2 : nBorder = (sal_uInt16)rOption.GetNumber();
383 2 : break;
384 : case HTML_O_ISMAP:
385 0 : bIsMap = true;
386 0 : break;
387 : case HTML_O_USEMAP:
388 0 : aMap = rOption.GetString();
389 0 : break;
390 : case HTML_O_NAME:
391 2 : sHTMLGrfName = rOption.GetString();
392 2 : 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 8 : 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 24 : if( !pPam->GetPoint()->nContent.GetIndex() &&
438 8 : GetNumInfo().GetDepth() > 0 && GetNumInfo().GetDepth() <= MAXLEVEL &&
439 8 : !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( 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 8 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
465 16 : SvxCSS1PropertyInfo aPropInfo;
466 8 : if( HasStyleOptions( aStyle, aId, aClass ) )
467 0 : ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo );
468 :
469 8 : SfxItemSet aFrmSet( pDoc->GetAttrPool(),
470 16 : RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
471 8 : if( !IsNewDoc() )
472 0 : Reader::ResetFrmFmtAttrs( aFrmSet );
473 :
474 : // Umrandung setzen
475 8 : long nHBorderWidth = 0, nVBorderWidth = 0;
476 8 : if( nBorder )
477 : {
478 6 : nHBorderWidth = (long)nBorder;
479 6 : nVBorderWidth = (long)nBorder;
480 6 : SvxCSS1Parser::PixelToTwip( nVBorderWidth, nHBorderWidth );
481 :
482 6 : ::editeng::SvxBorderLine aHBorderLine( NULL, nHBorderWidth );
483 6 : ::editeng::SvxBorderLine aVBorderLine( NULL, nVBorderWidth );
484 :
485 6 : if( aAttrTab.pINetFmt )
486 : {
487 : const OUString& rURL =
488 6 : ((const SwFmtINetFmt&)aAttrTab.pINetFmt->GetItem()).GetValue();
489 :
490 6 : pCSS1Parser->SetATagStyles();
491 6 : sal_uInt16 nPoolId = static_cast< sal_uInt16 >(pDoc->IsVisitedURL( rURL )
492 : ? RES_POOLCHR_INET_VISIT
493 6 : : RES_POOLCHR_INET_NORMAL);
494 6 : const SwCharFmt *pCharFmt = pCSS1Parser->GetCharFmtFromPool( nPoolId );
495 6 : aHBorderLine.SetColor( pCharFmt->GetColor().GetValue() );
496 6 : 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 6 : SvxBoxItem aBoxItem( RES_BOX );
508 6 : aBoxItem.SetLine( &aHBorderLine, BOX_LINE_TOP );
509 6 : aBoxItem.SetLine( &aHBorderLine, BOX_LINE_BOTTOM );
510 6 : aBoxItem.SetLine( &aVBorderLine, BOX_LINE_LEFT );
511 6 : aBoxItem.SetLine( &aVBorderLine, BOX_LINE_RIGHT );
512 6 : aFrmSet.Put( aBoxItem );
513 : }
514 :
515 : // Ausrichtung setzen
516 8 : SetAnchorAndAdjustment( eVertOri, eHoriOri, aItemSet, aPropInfo, aFrmSet );
517 :
518 : // Abstaende setzen
519 8 : SetSpace( Size( nHSpace, nVSpace), aItemSet, aPropInfo, aFrmSet );
520 :
521 : // Sonstige CSS1-Attribute Setzen
522 8 : SetFrmFmtAttrs( aItemSet, aPropInfo, HTML_FF_BOX, aFrmSet );
523 :
524 8 : Size aTwipSz( bPrcWidth ? 0 : nWidth, bPrcHeight ? 0 : nHeight );
525 8 : if( (aTwipSz.Width() || aTwipSz.Height()) && Application::GetDefaultDevice() )
526 : {
527 : aTwipSz = Application::GetDefaultDevice()
528 6 : ->PixelToLogic( aTwipSz, MapMode( MAP_TWIP ) );
529 : }
530 :
531 : // CSS1-Groesse auf "normale" Groesse umrechnen
532 8 : switch( aPropInfo.eWidthType )
533 : {
534 : case SVX_CSS1_LTYPE_TWIP:
535 0 : aTwipSz.Width() = aPropInfo.nWidth;
536 0 : nWidth = 1; // != 0
537 0 : bPrcWidth = false;
538 0 : break;
539 : case SVX_CSS1_LTYPE_PERCENTAGE:
540 0 : aTwipSz.Width() = 0;
541 0 : nWidth = aPropInfo.nWidth;
542 0 : bPrcWidth = true;
543 0 : break;
544 : default:
545 : ;
546 : }
547 8 : switch( aPropInfo.eHeightType )
548 : {
549 : case SVX_CSS1_LTYPE_TWIP:
550 0 : aTwipSz.Height() = aPropInfo.nHeight;
551 0 : nHeight = 1; // != 0
552 0 : bPrcHeight = false;
553 0 : break;
554 : case SVX_CSS1_LTYPE_PERCENTAGE:
555 0 : aTwipSz.Height() = 0;
556 0 : nHeight = aPropInfo.nHeight;
557 0 : bPrcHeight = true;
558 0 : break;
559 : default:
560 : ;
561 : }
562 :
563 8 : Size aGrfSz( 0, 0 );
564 8 : bool bSetTwipSize = true; // Twip-Size am Node setzen?
565 8 : bool bChangeFrmSize = false; // Frame-Format nachtraeglich anpassen?
566 8 : bool bRequestGrfNow = false;
567 8 : bool bSetScaleImageMap = false;
568 8 : sal_uInt8 nPrcWidth = 0, nPrcHeight = 0;
569 :
570 8 : 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 2 : if( pTable!=0 && !nWidth )
577 : {
578 0 : bRequestGrfNow = true;
579 0 : IncGrfsThatResizeTable();
580 : }
581 :
582 : // Die Groesse des Rahmens wird nachtraeglich gesetzt
583 2 : bChangeFrmSize = true;
584 2 : aGrfSz = aTwipSz;
585 4 : if( !nWidth && !nHeight )
586 : {
587 2 : aTwipSz.Width() = HTML_DFLT_IMG_WIDTH;
588 2 : 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 6 : bSetTwipSize = false;
621 :
622 6 : if( bPrcWidth )
623 0 : nPrcWidth = (sal_uInt8)nWidth;
624 :
625 6 : if( bPrcHeight )
626 0 : nPrcHeight = (sal_uInt8)nHeight;
627 : }
628 :
629 : // Image-Map setzen
630 8 : aMap = comphelper::string::stripEnd(aMap, ' ');
631 8 : 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 8 : 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 8 : aTwipSz.Width() += 2*nVBorderWidth;
675 8 : if( aTwipSz.Width() < MINFLY )
676 0 : aTwipSz.Width() = MINFLY;
677 : }
678 8 : 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 8 : aTwipSz.Height() += 2*nHBorderWidth;
688 8 : if( aTwipSz.Height() < MINFLY )
689 0 : aTwipSz.Height() = MINFLY;
690 : }
691 :
692 8 : SwFmtFrmSize aFrmSize( ATT_FIX_SIZE, aTwipSz.Width(), aTwipSz.Height() );
693 8 : aFrmSize.SetWidthPercent( nPrcWidth );
694 8 : aFrmSize.SetHeightPercent( nPrcHeight );
695 8 : aFrmSet.Put( aFrmSize );
696 :
697 16 : Graphic aGraphic;
698 16 : INetURLObject aGraphicURL( sGrfNm );
699 8 : if( aGraphicURL.GetProtocol() == INET_PROT_DATA )
700 : {
701 2 : std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData());
702 2 : if (pStream)
703 : {
704 2 : if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream))
705 2 : sGrfNm = "";
706 2 : }
707 : }
708 : // sBaseURL is empty if the source is clipboard
709 6 : else if (sBaseURL.isEmpty())
710 : {
711 0 : if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aGraphicURL))
712 0 : sGrfNm = "";
713 : }
714 8 : if (!sGrfNm.isEmpty())
715 : {
716 6 : aGraphic.SetDefaultType();
717 : }
718 :
719 : // passing empty sGrfNm here, means we don't want the graphic to be linked
720 8 : SwFrmFmt *pFlyFmt = pDoc->getIDocumentContentOperations().Insert( *pPam, sGrfNm, aEmptyOUStr, &aGraphic,
721 8 : &aFrmSet, NULL, NULL );
722 16 : SwGrfNode *pGrfNd = pDoc->GetNodes()[ pFlyFmt->GetCntnt().GetCntntIdx()
723 16 : ->GetIndex()+1 ]->GetGrfNode();
724 :
725 8 : if( !sHTMLGrfName.isEmpty() )
726 : {
727 2 : pFlyFmt->SetName( sHTMLGrfName );
728 :
729 : // ggfs. eine Grafik anspringen
730 2 : if( JUMPTO_GRAPHIC == eJumpTo && sHTMLGrfName == sJmpMark )
731 : {
732 0 : bChkJumpMark = true;
733 0 : eJumpTo = JUMPTO_NONE;
734 : }
735 : }
736 :
737 8 : if (pGrfNd)
738 : {
739 8 : if( !sAltNm.isEmpty() )
740 0 : pGrfNd->SetTitle( sAltNm );
741 :
742 8 : if( bSetTwipSize )
743 2 : pGrfNd->SetTwipSize( aGrfSz );
744 :
745 8 : pGrfNd->SetChgTwipSize( bChangeFrmSize, bChangeFrmSize );
746 :
747 8 : if( bSetScaleImageMap )
748 0 : pGrfNd->SetScaleImageMap( true );
749 : }
750 :
751 8 : if( aAttrTab.pINetFmt )
752 : {
753 : const SwFmtINetFmt &rINetFmt =
754 6 : (const SwFmtINetFmt&)aAttrTab.pINetFmt->GetItem();
755 :
756 6 : SwFmtURL aURL( pFlyFmt->GetURL() );
757 :
758 6 : aURL.SetURL( rINetFmt.GetValue(), bIsMap );
759 6 : aURL.SetTargetFrameName( rINetFmt.GetTargetFrame() );
760 6 : aURL.SetName( rINetFmt.GetName() );
761 6 : pFlyFmt->SetFmtAttr( aURL );
762 :
763 : {
764 : const SvxMacro *pMacro;
765 : static const sal_uInt16 aEvents[] = {
766 : SFX_EVENT_MOUSEOVER_OBJECT,
767 : SFX_EVENT_MOUSECLICK_OBJECT,
768 : SFX_EVENT_MOUSEOUT_OBJECT,
769 : 0 };
770 :
771 24 : for( sal_uInt16 n = 0; aEvents[ n ]; ++n )
772 18 : if( 0 != ( pMacro = rINetFmt.GetMacro( aEvents[ n ] ) ))
773 0 : aMacroItem.SetMacro( aEvents[ n ], *pMacro );
774 : }
775 :
776 18 : if ((FLY_AS_CHAR == pFlyFmt->GetAnchor().GetAnchorId()) &&
777 6 : aAttrTab.pINetFmt->GetSttPara() ==
778 12 : pPam->GetPoint()->nNode &&
779 6 : aAttrTab.pINetFmt->GetSttCnt() ==
780 6 : pPam->GetPoint()->nContent.GetIndex() - 1 )
781 : {
782 : // das Attribut wurde unmitellbar vor einer zeichengeb.
783 : // Grafik eingefuegt, also verschieben wir es
784 6 : aAttrTab.pINetFmt->SetStart( *pPam->GetPoint() );
785 :
786 : // Wenn das Attribut auch ein Sprungziel ist, fuegen
787 : // wir noch eine Bookmark vor der Grafik ein, weil das
788 : // SwFmtURL kein Sprungziel ist.
789 6 : if( !rINetFmt.GetName().isEmpty() )
790 : {
791 0 : pPam->Move( fnMoveBackward );
792 0 : InsertBookmark( rINetFmt.GetName() );
793 0 : pPam->Move( fnMoveForward );
794 : }
795 6 : }
796 :
797 : }
798 :
799 8 : if( !aMacroItem.GetMacroTable().empty() )
800 0 : pFlyFmt->SetFmtAttr( aMacroItem );
801 :
802 : // Wenn die Grafik gleich angeforder wird, muss dies geschehen,
803 : // nachdem das Format vollstaendig aufgebaut ist, weil es evtl.
804 : // gleich (synchron) angepasst wird (war bug #40983#)
805 8 : if (bRequestGrfNow && pGrfNd)
806 : {
807 0 : pGrfNd->SwapIn();
808 : }
809 :
810 : // Ggf. Frames anlegen und Auto-gebundenen Rahmen registrieren
811 8 : RegisterFlyFrm( pFlyFmt );
812 :
813 8 : if( !aId.isEmpty() )
814 24 : InsertBookmark( aId );
815 : }
816 :
817 : /* */
818 :
819 20 : void SwHTMLParser::InsertBodyOptions()
820 : {
821 : pDoc->SetTxtFmtColl( *pPam,
822 20 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_TEXT ) );
823 :
824 40 : OUString aBackGround, aId, aStyle, aLang, aDir;
825 20 : Color aBGColor, aTextColor, aLinkColor, aVLinkColor;
826 20 : bool bBGColor=false, bTextColor=false;
827 20 : bool bLinkColor=false, bVLinkColor=false;
828 :
829 : ScriptType eDfltScriptType;
830 40 : OUString sDfltScriptType;
831 20 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
832 :
833 20 : const HTMLOptions& rHTMLOptions = GetOptions();
834 66 : for (size_t i = rHTMLOptions.size(); i; )
835 : {
836 26 : const HTMLOption& rOption = rHTMLOptions[--i];
837 26 : ScriptType eScriptType2 = eDfltScriptType;
838 26 : OUString aEvent;
839 26 : bool bSetEvent = false;
840 :
841 26 : switch( rOption.GetToken() )
842 : {
843 : case HTML_O_ID:
844 0 : aId = rOption.GetString();
845 0 : break;
846 : case HTML_O_BACKGROUND:
847 0 : aBackGround = rOption.GetString();
848 0 : break;
849 : case HTML_O_BGCOLOR:
850 0 : rOption.GetColor( aBGColor );
851 0 : bBGColor = true;
852 0 : break;
853 : case HTML_O_TEXT:
854 2 : rOption.GetColor( aTextColor );
855 2 : bTextColor = true;
856 2 : break;
857 : case HTML_O_LINK:
858 2 : rOption.GetColor( aLinkColor );
859 2 : bLinkColor = true;
860 2 : break;
861 : case HTML_O_VLINK:
862 0 : rOption.GetColor( aVLinkColor );
863 0 : bVLinkColor = true;
864 0 : break;
865 :
866 : case HTML_O_SDONLOAD:
867 0 : eScriptType2 = STARBASIC;
868 : //fallthrough
869 : case HTML_O_ONLOAD:
870 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC );
871 0 : bSetEvent = true;
872 0 : break;
873 :
874 : case HTML_O_SDONUNLOAD:
875 0 : eScriptType2 = STARBASIC;
876 : //fallthrough
877 : case HTML_O_ONUNLOAD:
878 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC );
879 0 : bSetEvent = true;
880 0 : break;
881 :
882 : case HTML_O_SDONFOCUS:
883 0 : eScriptType2 = STARBASIC;
884 : //fallthrough
885 : case HTML_O_ONFOCUS:
886 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC );
887 0 : bSetEvent = true;
888 0 : break;
889 :
890 : case HTML_O_SDONBLUR:
891 0 : eScriptType2 = STARBASIC;
892 : //fallthrough
893 : case HTML_O_ONBLUR:
894 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC );
895 0 : bSetEvent = true;
896 0 : break;
897 :
898 : case HTML_O_ONERROR:
899 0 : break;
900 :
901 : case HTML_O_STYLE:
902 0 : aStyle = rOption.GetString();
903 0 : bTextColor = true;
904 0 : break;
905 : case HTML_O_LANG:
906 10 : aLang = rOption.GetString();
907 10 : break;
908 : case HTML_O_DIR:
909 10 : aDir = rOption.GetString();
910 10 : break;
911 : }
912 :
913 26 : if( bSetEvent )
914 : {
915 0 : const OUString& rEvent = rOption.GetString();
916 0 : if( !rEvent.isEmpty() )
917 : InsertBasicDocEvent( aEvent, rEvent, eScriptType2,
918 0 : sDfltScriptType );
919 : }
920 26 : }
921 :
922 20 : if( bTextColor && !pCSS1Parser->IsBodyTextSet() )
923 : {
924 : // Die Textfarbe wird an der Standard-Vorlage gesetzt
925 2 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_STANDARD )
926 2 : ->SetFmtAttr( SvxColorItem(aTextColor, RES_CHRATR_COLOR) );
927 2 : pCSS1Parser->SetBodyTextSet();
928 : }
929 :
930 : // Die Item fuer die Seitenvorlage vorbereiten (Hintergrund, Umrandung)
931 : // Beim BrushItem muessen schon gesetzte werte erhalten bleiben!
932 20 : SvxBrushItem aBrushItem( pCSS1Parser->makePageDescBackground() );
933 20 : bool bSetBrush = false;
934 :
935 20 : if( bBGColor && !pCSS1Parser->IsBodyBGColorSet() )
936 : {
937 : // Hintergrundfarbe aus "BGCOLOR"
938 0 : OUString aLink;
939 0 : if( !aBrushItem.GetGraphicLink().isEmpty() )
940 0 : aLink = aBrushItem.GetGraphicLink();
941 0 : SvxGraphicPosition ePos = aBrushItem.GetGraphicPos();
942 :
943 0 : aBrushItem.SetColor( aBGColor );
944 :
945 0 : if( !aLink.isEmpty() )
946 : {
947 0 : aBrushItem.SetGraphicLink( aLink );
948 0 : aBrushItem.SetGraphicPos( ePos );
949 : }
950 0 : bSetBrush = true;
951 0 : pCSS1Parser->SetBodyBGColorSet();
952 : }
953 :
954 20 : if( !aBackGround.isEmpty() && !pCSS1Parser->IsBodyBackgroundSet() )
955 : {
956 : // Hintergrundgrafik aus "BACKGROUND"
957 0 : aBrushItem.SetGraphicLink( INetURLObject::GetAbsURL( sBaseURL, aBackGround ) );
958 0 : aBrushItem.SetGraphicPos( GPOS_TILED );
959 0 : bSetBrush = true;
960 0 : pCSS1Parser->SetBodyBackgroundSet();
961 : }
962 :
963 20 : if( !aStyle.isEmpty() || !aDir.isEmpty() )
964 : {
965 10 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
966 20 : SvxCSS1PropertyInfo aPropInfo;
967 20 : OUString aDummy;
968 10 : ParseStyleOptions( aStyle, aDummy, aDummy, aItemSet, aPropInfo, 0, &aDir );
969 :
970 : // Ein par Attribute muessen an der Seitenvorlage gesetzt werden,
971 : // und zwar die, die nicht vererbit werden
972 : pCSS1Parser->SetPageDescAttrs( bSetBrush ? &aBrushItem : 0,
973 10 : &aItemSet );
974 :
975 : const SfxPoolItem *pItem;
976 : static const sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONTSIZE,
977 : RES_CHRATR_CJK_FONTSIZE,
978 : RES_CHRATR_CTL_FONTSIZE };
979 40 : for( sal_uInt16 i=0; i<3; i++ )
980 : {
981 60 : if( SfxItemState::SET == aItemSet.GetItemState( aWhichIds[i], false,
982 30 : &pItem ) &&
983 0 : static_cast <const SvxFontHeightItem * >(pItem)->GetProp() != 100)
984 : {
985 : sal_uInt32 nHeight =
986 0 : ( aFontHeights[2] *
987 0 : static_cast <const SvxFontHeightItem * >(pItem)->GetProp() ) / 100;
988 0 : SvxFontHeightItem aNewItem( nHeight, 100, aWhichIds[i] );
989 0 : aItemSet.Put( aNewItem );
990 : }
991 : }
992 :
993 : // alle noch uebrigen Optionen koennen an der Standard-Vorlage
994 : // gesetzt werden und gelten dann automatisch als defaults
995 10 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_STANDARD )
996 20 : ->SetFmtAttr( aItemSet );
997 : }
998 10 : else if( bSetBrush )
999 : {
1000 0 : pCSS1Parser->SetPageDescAttrs( &aBrushItem );
1001 : }
1002 :
1003 20 : if( bLinkColor && !pCSS1Parser->IsBodyLinkSet() )
1004 : {
1005 : SwCharFmt *pCharFmt =
1006 2 : pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_INET_NORMAL);
1007 2 : pCharFmt->SetFmtAttr( SvxColorItem(aLinkColor, RES_CHRATR_COLOR) );
1008 2 : pCSS1Parser->SetBodyLinkSet();
1009 : }
1010 20 : if( bVLinkColor && !pCSS1Parser->IsBodyVLinkSet() )
1011 : {
1012 : SwCharFmt *pCharFmt =
1013 0 : pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_INET_VISIT);
1014 0 : pCharFmt->SetFmtAttr( SvxColorItem(aVLinkColor, RES_CHRATR_COLOR) );
1015 0 : pCSS1Parser->SetBodyVLinkSet();
1016 : }
1017 20 : if( !aLang.isEmpty() )
1018 : {
1019 10 : LanguageType eLang = LanguageTag::convertToLanguageTypeWithFallback( aLang );
1020 10 : if( LANGUAGE_DONTKNOW != eLang )
1021 : {
1022 10 : sal_uInt16 nWhich = 0;
1023 10 : switch( SvtLanguageOptions::GetScriptTypeOfLanguage( eLang ) )
1024 : {
1025 : case SCRIPTTYPE_LATIN:
1026 10 : nWhich = RES_CHRATR_LANGUAGE;
1027 10 : break;
1028 : case SCRIPTTYPE_ASIAN:
1029 0 : nWhich = RES_CHRATR_CJK_LANGUAGE;
1030 0 : break;
1031 : case SCRIPTTYPE_COMPLEX:
1032 0 : nWhich = RES_CHRATR_CTL_LANGUAGE;
1033 0 : break;
1034 : }
1035 10 : if( nWhich )
1036 : {
1037 10 : SvxLanguageItem aLanguage( eLang, nWhich );
1038 10 : aLanguage.SetWhich( nWhich );
1039 10 : pDoc->SetDefault( aLanguage );
1040 : }
1041 : }
1042 : }
1043 :
1044 20 : if( !aId.isEmpty() )
1045 20 : InsertBookmark( aId );
1046 20 : }
1047 :
1048 : /* */
1049 :
1050 10 : void SwHTMLParser::NewAnchor()
1051 : {
1052 : // den voherigen Link beenden, falls es einen gab
1053 10 : _HTMLAttrContext *pOldCntxt = PopContext( HTML_ANCHOR_ON );
1054 10 : if( pOldCntxt )
1055 : {
1056 : // und ggf. die Attribute beenden
1057 0 : EndContext( pOldCntxt );
1058 0 : delete pOldCntxt;
1059 : }
1060 :
1061 10 : SvxMacroTableDtor aMacroTbl;
1062 20 : OUString sHRef, aName, sTarget;
1063 20 : OUString aId, aStyle, aClass, aLang, aDir;
1064 10 : bool bHasHRef = false, bFixed = false;
1065 :
1066 : ScriptType eDfltScriptType;
1067 20 : OUString sDfltScriptType;
1068 10 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
1069 :
1070 10 : const HTMLOptions& rHTMLOptions = GetOptions();
1071 44 : for (size_t i = rHTMLOptions.size(); i; )
1072 : {
1073 24 : sal_uInt16 nEvent = 0;
1074 24 : ScriptType eScriptType2 = eDfltScriptType;
1075 24 : const HTMLOption& rOption = rHTMLOptions[--i];
1076 24 : switch( rOption.GetToken() )
1077 : {
1078 : case HTML_O_NAME:
1079 0 : aName = rOption.GetString();
1080 0 : break;
1081 :
1082 : case HTML_O_HREF:
1083 8 : sHRef = rOption.GetString();
1084 8 : bHasHRef = true;
1085 8 : break;
1086 : case HTML_O_TARGET:
1087 2 : sTarget = rOption.GetString();
1088 2 : break;
1089 :
1090 : case HTML_O_STYLE:
1091 4 : aStyle = rOption.GetString();
1092 4 : break;
1093 : case HTML_O_ID:
1094 4 : aId = rOption.GetString();
1095 4 : break;
1096 : case HTML_O_CLASS:
1097 2 : aClass = rOption.GetString();
1098 2 : break;
1099 : case HTML_O_SDFIXED:
1100 0 : bFixed = true;
1101 0 : break;
1102 : case HTML_O_LANG:
1103 0 : aLang = rOption.GetString();
1104 0 : break;
1105 : case HTML_O_DIR:
1106 0 : aDir = rOption.GetString();
1107 0 : break;
1108 :
1109 : case HTML_O_SDONCLICK:
1110 0 : eScriptType2 = STARBASIC;
1111 : //fall-through
1112 : case HTML_O_ONCLICK:
1113 0 : nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
1114 0 : goto ANCHOR_SETEVENT;
1115 :
1116 : case HTML_O_SDONMOUSEOVER:
1117 0 : eScriptType2 = STARBASIC;
1118 : //fall-through
1119 : case HTML_O_ONMOUSEOVER:
1120 0 : nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
1121 0 : goto ANCHOR_SETEVENT;
1122 :
1123 : case HTML_O_SDONMOUSEOUT:
1124 0 : eScriptType2 = STARBASIC;
1125 : //fall-through
1126 : case HTML_O_ONMOUSEOUT:
1127 0 : nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
1128 0 : goto ANCHOR_SETEVENT;
1129 : ANCHOR_SETEVENT:
1130 : {
1131 0 : OUString sTmp( rOption.GetString() );
1132 0 : if( !sTmp.isEmpty() )
1133 : {
1134 0 : sTmp = convertLineEnd(sTmp, GetSystemLineEnd());
1135 0 : OUString sScriptType;
1136 0 : if( EXTENDED_STYPE == eScriptType2 )
1137 0 : sScriptType = sDfltScriptType;
1138 0 : aMacroTbl.Insert( nEvent, SvxMacro( sTmp, sScriptType, eScriptType2 ));
1139 0 : }
1140 : }
1141 0 : break;
1142 :
1143 : }
1144 : }
1145 :
1146 : // Sprungziele, die unseren ipmliziten Zielen entsprechen, schmeissen
1147 : // wir hier ganz rigoros raus.
1148 10 : if( !aName.isEmpty() )
1149 : {
1150 : OUString sDecoded( INetURLObject::decode( aName, '%',
1151 : INetURLObject::DECODE_UNAMBIGUOUS,
1152 0 : RTL_TEXTENCODING_UTF8 ));
1153 0 : sal_Int32 nPos = sDecoded.lastIndexOf( cMarkSeparator );
1154 0 : if( nPos != -1 )
1155 : {
1156 0 : OUString sCmp(comphelper::string::remove(sDecoded.copy(nPos+1), ' '));
1157 0 : if( !sCmp.isEmpty() )
1158 : {
1159 0 : sCmp = sCmp.toAsciiLowerCase();
1160 0 : if( sCmp == "region" ||
1161 0 : sCmp == "frame" ||
1162 0 : sCmp == "graphic" ||
1163 0 : sCmp == "ole" ||
1164 0 : sCmp == "table" ||
1165 0 : sCmp == "outline" ||
1166 0 : sCmp == "text" )
1167 : {
1168 0 : aName = "";
1169 : }
1170 0 : }
1171 0 : }
1172 : }
1173 :
1174 : // einen neuen Kontext anlegen
1175 10 : _HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_ANCHOR_ON );
1176 :
1177 10 : bool bEnAnchor = false, bFtnAnchor = false, bFtnEnSymbol = false;
1178 10 : OUString aFtnName;
1179 20 : OUString aStrippedClass( aClass );
1180 10 : SwCSS1Parser::GetScriptFromClass( aStrippedClass, false );
1181 24 : if( aStrippedClass.getLength() >=9 && bHasHRef && sHRef.getLength() > 1 &&
1182 14 : ('s' == aStrippedClass[0] || 'S' == aStrippedClass[0]) &&
1183 0 : ('d' == aStrippedClass[1] || 'D' == aStrippedClass[1]) )
1184 : {
1185 0 : if( aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdendnote_anc ) )
1186 0 : bEnAnchor = true;
1187 0 : else if( aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdfootnote_anc ) )
1188 0 : bFtnAnchor = true;
1189 0 : else if( aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdendnote_sym ) ||
1190 0 : aStrippedClass.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_sdfootnote_sym ) )
1191 0 : bFtnEnSymbol = true;
1192 0 : if( bEnAnchor || bFtnAnchor || bFtnEnSymbol )
1193 : {
1194 0 : aFtnName = sHRef.copy( 1 );
1195 0 : aClass = aStrippedClass = aName = aEmptyOUStr;
1196 0 : bHasHRef = false;
1197 : }
1198 : }
1199 :
1200 : // Styles parsen
1201 10 : if( HasStyleOptions( aStyle, aId, aStrippedClass, &aLang, &aDir ) )
1202 : {
1203 8 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
1204 16 : SvxCSS1PropertyInfo aPropInfo;
1205 :
1206 8 : if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
1207 : {
1208 8 : DoPositioning( aItemSet, aPropInfo, pCntxt );
1209 8 : InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
1210 8 : }
1211 : }
1212 :
1213 10 : if( bHasHRef )
1214 : {
1215 8 : if( !sHRef.isEmpty() )
1216 : {
1217 8 : sHRef = URIHelper::SmartRel2Abs( INetURLObject(sBaseURL), sHRef, Link(), false );
1218 : }
1219 : else
1220 : {
1221 : // Bei leerer URL das Directory nehmen
1222 0 : INetURLObject aURLObj( aPathToFile );
1223 0 : sHRef = aURLObj.GetPartBeforeLastName();
1224 : }
1225 :
1226 8 : pCSS1Parser->SetATagStyles();
1227 8 : SwFmtINetFmt aINetFmt( sHRef, sTarget );
1228 8 : aINetFmt.SetName( aName );
1229 :
1230 8 : if( !aMacroTbl.empty() )
1231 0 : aINetFmt.SetMacroTbl( &aMacroTbl );
1232 :
1233 : // das Default-Attribut setzen
1234 8 : InsertAttr( &aAttrTab.pINetFmt, aINetFmt, pCntxt );
1235 : }
1236 2 : else if( !aName.isEmpty() )
1237 : {
1238 0 : InsertBookmark( aName );
1239 : }
1240 :
1241 10 : if( bEnAnchor || bFtnAnchor )
1242 : {
1243 0 : InsertFootEndNote( aFtnName, bEnAnchor, bFixed );
1244 0 : bInFootEndNoteAnchor = bCallNextToken = true;
1245 : }
1246 10 : else if( bFtnEnSymbol )
1247 : {
1248 0 : bInFootEndNoteSymbol = bCallNextToken = true;
1249 : }
1250 :
1251 : // den Kontext merken
1252 30 : PushContext( pCntxt );
1253 10 : }
1254 :
1255 10 : void SwHTMLParser::EndAnchor()
1256 : {
1257 10 : if( bInFootEndNoteAnchor )
1258 : {
1259 0 : FinishFootEndNote();
1260 0 : bInFootEndNoteAnchor = false;
1261 : }
1262 10 : else if( bInFootEndNoteSymbol )
1263 : {
1264 0 : bInFootEndNoteSymbol = false;
1265 : }
1266 :
1267 10 : EndTag( HTML_ANCHOR_OFF );
1268 10 : }
1269 :
1270 : /* */
1271 :
1272 8 : void SwHTMLParser::InsertBookmark( const OUString& rName )
1273 : {
1274 8 : _HTMLAttr* pTmp = new _HTMLAttr( *pPam->GetPoint(),
1275 8 : SfxStringItem( RES_FLTR_BOOKMARK, rName ));
1276 8 : aSetAttrTab.push_back( pTmp );
1277 8 : }
1278 :
1279 20 : bool SwHTMLParser::HasCurrentParaBookmarks( bool bIgnoreStack ) const
1280 : {
1281 20 : bool bHasMarks = false;
1282 20 : sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
1283 :
1284 : // first step: are there still bookmark in the attribute-stack?
1285 : // bookmarks are added to the end of the stack - thus we only have
1286 : // to check the last bookmark
1287 20 : if( !bIgnoreStack )
1288 : {
1289 : _HTMLAttr* pAttr;
1290 10 : for( sal_uInt16 i = aSetAttrTab.size(); i; )
1291 : {
1292 6 : pAttr = aSetAttrTab[ --i ];
1293 6 : if( RES_FLTR_BOOKMARK == pAttr->pItem->Which() )
1294 : {
1295 0 : if( pAttr->GetSttParaIdx() == nNodeIdx )
1296 0 : bHasMarks = true;
1297 0 : break;
1298 : }
1299 : }
1300 : }
1301 :
1302 20 : if( !bHasMarks )
1303 : {
1304 : // second step: when we didn't find a bookmark, check if there is one set already
1305 20 : IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1306 84 : for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
1307 56 : ppMark != pMarkAccess->getAllMarksEnd();
1308 : ++ppMark)
1309 : {
1310 8 : const ::sw::mark::IMark* pBookmark = ppMark->get();
1311 :
1312 8 : const sal_uLong nBookNdIdx = pBookmark->GetMarkPos().nNode.GetIndex();
1313 8 : if( nBookNdIdx==nNodeIdx )
1314 : {
1315 0 : bHasMarks = true;
1316 0 : break;
1317 : }
1318 8 : else if( nBookNdIdx > nNodeIdx )
1319 0 : break;
1320 : }
1321 : }
1322 :
1323 20 : return bHasMarks;
1324 : }
1325 :
1326 : /* */
1327 :
1328 540 : void SwHTMLParser::StripTrailingPara()
1329 : {
1330 540 : bool bSetSmallFont = false;
1331 :
1332 540 : SwCntntNode* pCNd = pPam->GetCntntNode();
1333 540 : if( !pPam->GetPoint()->nContent.GetIndex() )
1334 : {
1335 1080 : if( pCNd && pCNd->StartOfSectionIndex()+2 <
1336 540 : pCNd->EndOfSectionIndex() )
1337 : {
1338 530 : sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
1339 :
1340 530 : const SwFrmFmts& rFrmFmtTbl = *pDoc->GetSpzFrmFmts();
1341 :
1342 552 : for( sal_uInt16 i=0; i<rFrmFmtTbl.size(); i++ )
1343 : {
1344 22 : SwFrmFmt const*const pFmt = rFrmFmtTbl[i];
1345 22 : SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
1346 22 : SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
1347 42 : if (pAPos &&
1348 40 : ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
1349 42 : (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
1350 0 : pAPos->nNode == nNodeIdx )
1351 :
1352 0 : return; // den Knoten duerfen wir nicht loeschen
1353 : }
1354 :
1355 530 : SetAttr( false ); // die noch offenen Attribute muessen
1356 : // beendet werden, bevor der Node
1357 : // geloescht wird, weil sonst der
1358 : // End-Index in die Botanik zeigt
1359 :
1360 530 : if( pCNd->Len() && pCNd->IsTxtNode() )
1361 : {
1362 : // es wurden Felder in den Node eingefuegt, die muessen
1363 : // wir jetzt verschieben
1364 2 : SwTxtNode *pPrvNd = pDoc->GetNodes()[nNodeIdx-1]->GetTxtNode();
1365 2 : if( pPrvNd )
1366 : {
1367 2 : SwIndex aSrc( pCNd, 0 );
1368 2 : pCNd->GetTxtNode()->CutText( pPrvNd, aSrc, pCNd->Len() );
1369 : }
1370 : }
1371 :
1372 : // jetz muessen wir noch eventuell vorhandene Bookmarks verschieben
1373 530 : IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1374 1710 : for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
1375 1140 : ppMark != pMarkAccess->getAllMarksEnd();
1376 : ++ppMark)
1377 : {
1378 40 : ::sw::mark::IMark* pMark = ppMark->get();
1379 :
1380 40 : sal_uLong nBookNdIdx = pMark->GetMarkPos().nNode.GetIndex();
1381 40 : if(nBookNdIdx==nNodeIdx)
1382 : {
1383 0 : SwNodeIndex nNewNdIdx(pPam->GetPoint()->nNode);
1384 0 : SwCntntNode* pNd = pDoc->GetNodes().GoPrevious(&nNewNdIdx);
1385 0 : if(!pNd)
1386 : {
1387 : OSL_ENSURE(false, "Hoppla, wo ist mein Vorgaenger-Node");
1388 0 : return;
1389 : }
1390 : // #i81002# - refactoring
1391 : // Do not directly manipulate member of <SwBookmark>
1392 : {
1393 0 : SwPosition aNewPos(*pNd);
1394 0 : aNewPos.nContent.Assign(pNd, pNd->Len());
1395 0 : const SwPaM aPaM(aNewPos);
1396 0 : pMarkAccess->repositionMark(ppMark->get(), aPaM);
1397 0 : }
1398 : }
1399 40 : else if( nBookNdIdx > nNodeIdx )
1400 0 : break;
1401 : }
1402 :
1403 530 : pPam->GetPoint()->nContent.Assign( 0, 0 );
1404 530 : pPam->SetMark();
1405 530 : pPam->DeleteMark();
1406 530 : pDoc->GetNodes().Delete( pPam->GetPoint()->nNode );
1407 530 : pPam->Move( fnMoveBackward, fnGoNode );
1408 : }
1409 10 : else if( pCNd && pCNd->IsTxtNode() && pTable )
1410 : {
1411 : // In leeren Zellen stellen wir einen kleinen Font ein, damit die
1412 : // Zelle nicht hoeher wird als die Grafik bzw. so niedrig wie
1413 : // moeglich bleibt.
1414 0 : bSetSmallFont = true;
1415 : }
1416 : }
1417 0 : else if( pCNd && pCNd->IsTxtNode() && pTable &&
1418 0 : pCNd->StartOfSectionIndex()+2 ==
1419 0 : pCNd->EndOfSectionIndex() )
1420 : {
1421 : // Wenn die Zelle nur zeichengebundene Grafiken/Rahmen enthaelt
1422 : // stellen wir ebenfalls einen kleinen Font ein.
1423 0 : bSetSmallFont = true;
1424 0 : SwTxtNode* pTxtNd = pCNd->GetTxtNode();
1425 :
1426 0 : sal_Int32 nPos = pPam->GetPoint()->nContent.GetIndex();
1427 0 : while( bSetSmallFont && nPos>0 )
1428 : {
1429 0 : --nPos;
1430 : bSetSmallFont =
1431 0 : (CH_TXTATR_BREAKWORD == pTxtNd->GetTxt()[nPos]) &&
1432 0 : (0 != pTxtNd->GetTxtAttrForCharAt( nPos, RES_TXTATR_FLYCNT ));
1433 : }
1434 : }
1435 :
1436 540 : if( bSetSmallFont )
1437 : {
1438 : //Added default to CJK and CTL
1439 0 : SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
1440 0 : pCNd->SetAttr( aFontHeight );
1441 0 : SvxFontHeightItem aFontHeightCJK( 40, 100, RES_CHRATR_CJK_FONTSIZE );
1442 0 : pCNd->SetAttr( aFontHeightCJK );
1443 0 : SvxFontHeightItem aFontHeightCTL( 40, 100, RES_CHRATR_CTL_FONTSIZE );
1444 0 : pCNd->SetAttr( aFontHeightCTL );
1445 : }
1446 270 : }
1447 :
1448 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|