LibreOffice Module sw (master)  1
ndgrf.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <hintids.hxx>
21 #include <mdiexp.hxx>
22 #include <tools/helpers.hxx>
23 #include <tools/urlobj.hxx>
24 #include <tools/fract.hxx>
25 #include <svl/undo.hxx>
26 #include <svl/fstathelper.hxx>
27 #include <vcl/imap.hxx>
28 #include <vcl/graphicfilter.hxx>
29 #include <sot/storage.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <sfx2/linkmgr.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <sot/formats.hxx>
34 #include <fmtfsize.hxx>
35 #include <fmturl.hxx>
36 #include <frmfmt.hxx>
37 #include <doc.hxx>
40 #include <frmatr.hxx>
41 #include <grfatr.hxx>
42 #include <swtypes.hxx>
43 #include <ndgrf.hxx>
44 #include <fmtcol.hxx>
45 #include <hints.hxx>
46 #include <swbaslnk.hxx>
47 #include <pagefrm.hxx>
48 #include <editsh.hxx>
49 #include <pam.hxx>
50 
51 #include <rtl/ustring.hxx>
53 #include <com/sun/star/embed/ElementModes.hpp>
54 #include <o3tl/deleter.hxx>
55 #include <vcl/svapp.hxx>
59 
60 using namespace com::sun::star;
61 
63  const SwNodeIndex & rWhere,
64  const OUString& rGrfName,
65  const OUString& rFltName,
66  const Graphic* pGraphic,
67  SwGrfFormatColl *pGrfColl,
68  SwAttrSet const * pAutoAttr ) :
69  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
70  maGrfObj(),
71  // #i73788#
72  mbLinkedInputStreamReady( false ),
73  mbIsStreamReadOnly( false )
74 {
76  bFrameInPaint = bScaleImageMap = false;
77 
78  ReRead(rGrfName, rFltName, pGraphic, false);
79 }
80 
82  const GraphicObject& rGrfObj,
83  SwGrfFormatColl *pGrfColl,
84  SwAttrSet const * pAutoAttr ) :
85  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
86  maGrfObj(rGrfObj),
87  // #i73788#
88  mbLinkedInputStreamReady( false ),
89  mbIsStreamReadOnly( false )
90 {
92  bFrameInPaint = bScaleImageMap = false;
93 }
94 
102  const OUString& rGrfName,
103  const OUString& rFltName,
104  SwGrfFormatColl *pGrfColl,
105  SwAttrSet const * pAutoAttr ) :
106  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
107  maGrfObj(),
108  // #i73788#
109  mbLinkedInputStreamReady( false ),
110  mbIsStreamReadOnly( false )
111 {
112  Graphic aGrf; aGrf.SetDefaultType();
113  maGrfObj.SetGraphic( aGrf, rGrfName );
114 
116  bFrameInPaint = bScaleImageMap = false;
117 
118  InsertLink( rGrfName, rFltName );
119  if( IsLinkedFile() )
120  {
121  INetURLObject aUrl( rGrfName );
122  if( INetProtocol::File == aUrl.GetProtocol() &&
124  {
125  // file exists, so create connection without an update
126  static_cast<SwBaseLink*>( refLink.get() )->Connect();
127  }
128  }
129 }
130 
132  const OUString& rGrfName, const OUString& rFltName,
133  const Graphic* pGraphic,
134  bool bNewGrf )
135 {
136  bool bReadGrf = false;
137  bool bSetTwipSize = true;
138  mpReplacementGraphic.reset();
139 
140  OSL_ENSURE( pGraphic || !rGrfName.isEmpty(),
141  "GraphicNode without a name, Graphic or GraphicObject" );
142 
143  OUString sURLLink;
144  if (pGraphic)
145  {
146  Graphic aGraphic(*pGraphic);
147 
148  sURLLink = aGraphic.getOriginURL();
149  if (sURLLink.isEmpty() && !rGrfName.isEmpty())
150  {
151  sURLLink = rGrfName;
152  aGraphic.setOriginURL(sURLLink);
153  }
154  }
155  else
156  {
157  sURLLink = rGrfName;
158  }
159 
160  // with name
161  if( refLink.is() )
162  {
163  OSL_ENSURE( !bInSwapIn, "ReRead: I am still in SwapIn" );
164 
165  if( !sURLLink.isEmpty() )
166  {
167  // Note: if there is DDE in the FltName, then it is a DDE-linked graphic
168  OUString sCmd( sURLLink );
169  if( !rFltName.isEmpty() )
170  {
171  sal_uInt16 nNewType;
172  if( rFltName == "DDE" )
173  nNewType = OBJECT_CLIENT_DDE;
174  else
175  {
176  sfx2::MakeLnkName( sCmd, nullptr, sURLLink, OUString(), &rFltName );
177  nNewType = OBJECT_CLIENT_GRF;
178  }
179 
180  if( nNewType != refLink->GetObjType() )
181  {
182  refLink->Disconnect();
183  static_cast<SwBaseLink*>( refLink.get() )->SetObjType( nNewType );
184  }
185  }
186 
187  refLink->SetLinkSourceName( sCmd );
188  }
189  else // no name anymore, so remove link
190  {
192  refLink.clear();
193  }
194 
195  if( pGraphic )
196  {
197  maGrfObj.SetGraphic( *pGraphic, sURLLink );
199  bReadGrf = true;
200  }
201  else
202  {
203  // reset data of the old graphic so that the correct placeholder is
204  // shown in case the new link could not be loaded
205  Graphic aGrf; aGrf.SetDefaultType();
206  maGrfObj.SetGraphic( aGrf, sURLLink );
207 
208  if( refLink.is() )
209  {
210  if( getLayoutFrame( GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) )
211  {
213  ModifyNotification( &aMsgHint, &aMsgHint );
214  }
215  else if ( bNewGrf )
216  {
217  //TODO refLink->setInputStream(getInputStream());
218  static_cast<SwBaseLink*>( refLink.get() )->SwapIn();
219  }
220  }
222  bSetTwipSize = false;
223  }
224  }
225  else if( pGraphic && sURLLink.isEmpty() )
226  {
227  maGrfObj.SetGraphic( *pGraphic );
229  bReadGrf = true;
230  }
231  // Was the graphic already loaded?
232  else if( !bNewGrf && GraphicType::NONE != maGrfObj.GetType() )
233  return true;
234  else
235  {
236  // create new link for the graphic object
237  InsertLink( sURLLink, rFltName );
238 
239  if( GetNodes().IsDocNodes() )
240  {
241  if( pGraphic )
242  {
243  maGrfObj.SetGraphic( *pGraphic, sURLLink );
245  bReadGrf = true;
246  // create connection without update, as we have the graphic
247  static_cast<SwBaseLink*>( refLink.get() )->Connect();
248  }
249  else
250  {
251  Graphic aGrf;
252  aGrf.SetDefaultType();
253  maGrfObj.SetGraphic( aGrf, sURLLink );
255  if ( bNewGrf )
256  {
257  static_cast<SwBaseLink*>( refLink.get() )->SwapIn();
258  }
259  }
260  }
261  }
262 
263  // Bug 39281: Do not delete Size immediately - Events on ImageMaps should have
264  // something to work with when swapping
265  if( bSetTwipSize )
267 
268  // create an updates for the frames
269  if( bReadGrf && bNewGrf )
270  {
271  SwMsgPoolItem aMsgHint( RES_UPDATE_ATTR );
272  ModifyNotification( &aMsgHint, &aMsgHint );
273  }
274 
275  return bReadGrf;
276 }
277 
279 {
280  mpReplacementGraphic.reset();
281 
282  // #i73788#
283  mpThreadConsumer.reset();
284 
285  SwDoc* pDoc = GetDoc();
286  if( refLink.is() )
287  {
288  OSL_ENSURE( !bInSwapIn, "DTOR: I am still in SwapIn" );
290  refLink->Disconnect();
291  }
292  else
293  {
294  // #i40014# - A graphic node, which is in a linked
295  // section, whose link is another section in the document, doesn't
296  // have to remove the stream from the storage.
297  // Because it's hard to detect this case here and it would only fix
298  // one problem with shared graphic files - there are also problems,
299  // a certain graphic file is referenced by two independent graphic nodes,
300  // brush item or drawing objects, the stream isn't no longer removed here.
301  // To do this stuff correctly, a reference counting on shared streams
302  // inside one document has to be implemented.
303  }
304  //#39289# delete frames already here since the Frames' dtor needs the graphic for its StopAnimation
305  if( HasWriterListeners() )
306  DelFrames(nullptr);
307 }
308 
311 {
312  // try to access SwFlyFrameFormat; since title/desc/name are set there, there is no
313  // use to continue if it is not yet set. If not yet set, call onGraphicChanged()
314  // when it is set.
315  SwFlyFrameFormat* pFlyFormat = dynamic_cast< SwFlyFrameFormat* >(GetFlyFormat());
316 
317  if(pFlyFormat)
318  {
319  OUString aName;
320  OUString aTitle;
321  OUString aDesc;
322  const VectorGraphicDataPtr& rVectorGraphicDataPtr = GetGrf().getVectorGraphicData();
323 
324  if(rVectorGraphicDataPtr.get())
325  {
326  const drawinglayer::primitive2d::Primitive2DContainer aSequence(rVectorGraphicDataPtr->getPrimitive2DSequence());
327 
328  if(!aSequence.empty())
329  {
331  drawinglayer::processor2d::ObjectInfoPrimitiveExtractor2D aProcessor(aViewInformation2D);
332 
333  aProcessor.process(aSequence);
334 
335  const drawinglayer::primitive2d::ObjectInfoPrimitive2D* pResult = aProcessor.getResult();
336 
337  if(pResult)
338  {
339  aName = pResult->getName();
340  aTitle = pResult->getTitle();
341  aDesc = pResult->getDesc();
342  }
343  }
344  }
345 
346  if(!aTitle.isEmpty())
347  {
348  SetTitle(aTitle);
349  }
350  else if (!aName.isEmpty())
351  {
352  SetTitle(aName);
353  }
354 
355  if(!aDesc.isEmpty())
356  {
357  SetDescription(aDesc);
358  }
359  }
360 }
361 
362 void SwGrfNode::SetGraphic(const Graphic& rGraphic)
363 {
364  maGrfObj.SetGraphic(rGraphic, OUString());
366 }
367 
368 const Graphic& SwGrfNode::GetGrf(bool bWait) const
369 {
370  const_cast<SwGrfNode*>(this)->SwapIn(bWait);
371  return maGrfObj.GetGraphic();
372 }
373 
374 const GraphicObject& SwGrfNode::GetGrfObj(bool bWait) const
375 {
376  const_cast<SwGrfNode*>(this)->SwapIn(bWait);
377  return maGrfObj;
378 }
379 
381 {
383  {
384  const VectorGraphicDataPtr& rVectorGraphicDataPtr = GetGrfObj().GetGraphic().getVectorGraphicData();
385 
386  if(rVectorGraphicDataPtr.get())
387  {
388  const_cast< SwGrfNode* >(this)->mpReplacementGraphic.reset( new GraphicObject(rVectorGraphicDataPtr->getReplacement()) );
389  }
390  else if (GetGrfObj().GetGraphic().hasPdfData() ||
391  GetGrfObj().GetGraphic().GetType() == GraphicType::GdiMetafile)
392  {
393  // Replacement graphic for PDF and metafiles is just the bitmap.
394  const_cast<SwGrfNode*>(this)->mpReplacementGraphic.reset( new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx()) );
395  }
396  }
397 
398  return mpReplacementGraphic.get();
399 }
400 
402  const OUString& rGrfName,
403  const OUString& rFltName,
404  const Graphic* pGraphic,
405  SwGrfFormatColl* pGrfColl,
406  SwAttrSet const * pAutoAttr )
407 {
408  OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
409  SwGrfNode *pNode;
410  // create object delayed, only from a SW/G-reader
411  if( !pGraphic )
412  pNode = new SwGrfNode( rWhere, rGrfName,
413  rFltName, pGrfColl, pAutoAttr );
414  else
415  pNode = new SwGrfNode( rWhere, rGrfName,
416  rFltName, pGraphic, pGrfColl, pAutoAttr );
417  return pNode;
418 }
419 
421  const GraphicObject& rGrfObj,
422  SwGrfFormatColl* pGrfColl )
423 {
424  OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
425  return new SwGrfNode( rWhere, rGrfObj, pGrfColl, nullptr );
426 }
427 
429 {
430  if( !nGrfSize.Width() && !nGrfSize.Height() )
431  {
432  const_cast<SwGrfNode*>(this)->SwapIn();
433  }
434  return nGrfSize;
435 }
436 
441 bool SwGrfNode::SwapIn(bool bWaitForData)
442 {
443  if(bInSwapIn) // not recursively!
444  return true;
445 
446  bool bRet = false;
447  bInSwapIn = true;
448  SwBaseLink* pLink = static_cast<SwBaseLink*>( refLink.get() );
449 
450  if( pLink )
451  {
452  if( GraphicType::NONE == maGrfObj.GetType() ||
453  GraphicType::Default == maGrfObj.GetType() )
454  {
455  // link was not loaded yet
456  if( pLink->SwapIn( bWaitForData ) )
457  {
458  bRet = true;
459  }
460  else if( GraphicType::Default == maGrfObj.GetType() )
461  {
462  // no default bitmap anymore, thus re-paint
463  mpReplacementGraphic.reset();
464 
468  ModifyNotification( &aMsgHint, &aMsgHint );
469  }
470  }
471  else
472  {
473  bRet = true;
474  }
475  }
476  else
477  bRet = true;
478 
479  if (bRet)
480  {
481  if( !nGrfSize.Width() && !nGrfSize.Height() )
483  }
484  bInSwapIn = false;
485  return bRet;
486 }
487 
488 bool SwGrfNode::GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const
489 {
490  bool bRet = false;
491  if( refLink.is() && refLink->GetLinkManager() )
492  {
493  sal_uInt16 nType = refLink->GetObjType();
494  if( OBJECT_CLIENT_GRF == nType )
496  refLink.get(), nullptr, pFileNm, nullptr, pFilterNm );
497  else if( OBJECT_CLIENT_DDE == nType && pFileNm && pFilterNm )
498  {
499  OUString sApp;
500  OUString sTopic;
501  OUString sItem;
503  refLink.get(), &sApp, &sTopic, &sItem ) )
504  {
505  *pFileNm = sApp + OUStringLiteral1(sfx2::cTokenSeparator)
506  + sTopic + OUStringLiteral1(sfx2::cTokenSeparator)
507  + sItem;
508  *pFilterNm = "DDE";
509  bRet = true;
510  }
511  }
512  }
513  return bRet;
514 }
515 
521 {
522  if( refLink.is() )
523  {
524  OSL_ENSURE( !bInSwapIn, "SavePersistentData: I am still in SwapIn" );
526  return true;
527  }
528 
529  // swap in first if in storage
530  if( HasEmbeddedStreamName() && !SwapIn() )
531  return false;
532 
533  // #i44367#
534  // Do not delete graphic file in storage, because the graphic file could
535  // be referenced by other graphic nodes.
536  // Because it's hard to detect this case here and it would only fix
537  // one problem with shared graphic files - there are also problems, if
538  // a certain graphic file is referenced by two independent graphic nodes,
539  // brush item or drawing objects, the stream isn't no longer removed here.
540  // To do this stuff correct, a reference counting on shared streams
541  // inside one document has to be implemented.
542  // Important note: see also fix for #i40014#
543 
544  // swap out into temp file
545  return true;
546 }
547 
549 {
550  if( refLink.is() )
551  {
553  refLink->SetVisible( rIDLA.IsVisibleLinks() );
556  refLink->Update();
557  }
558  return true;
559 }
560 
561 void SwGrfNode::InsertLink( const OUString& rGrfName, const OUString& rFltName )
562 {
563  refLink = new SwBaseLink( SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::GDIMETAFILE, this );
564 
566  if( GetNodes().IsDocNodes() )
567  {
568  refLink->SetVisible( rIDLA.IsVisibleLinks() );
569  if( rFltName == "DDE" )
570  {
571  sal_Int32 nTmp = 0;
572  const OUString sApp{ rGrfName.getToken( 0, sfx2::cTokenSeparator, nTmp ) };
573  const OUString sTopic{ rGrfName.getToken( 0, sfx2::cTokenSeparator, nTmp ) };
574  const OUString sItem{ rGrfName.copy( nTmp ) };
575  rIDLA.GetLinkManager().InsertDDELink( refLink.get(), sApp, sTopic, sItem );
576  }
577  else
578  {
579  const bool bSync = rFltName == "SYNCHRON";
580  refLink->SetSynchron( bSync );
581  refLink->SetContentType( SotClipboardFormatId::SVXB );
582 
584  OBJECT_CLIENT_GRF, rGrfName,
585  (!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) );
586  }
587  }
588 }
589 
591 {
592  if( refLink.is() )
593  {
594  Graphic aLocalGraphic(maGrfObj.GetGraphic());
595  const bool bHasOriginalData(aLocalGraphic.IsGfxLink());
596 
597  {
598  bInSwapIn = true;
599  SwBaseLink* pLink = static_cast<SwBaseLink*>( refLink.get() );
600  pLink->SwapIn( true, true );
601  bInSwapIn = false;
602  }
603 
605  refLink.clear();
606  aLocalGraphic.setOriginURL("");
607 
608  // #i15508# added extra processing after getting rid of the link. Use whatever is
609  // known from the formerly linked graphic to get to a state as close to a directly
610  // unlinked inserted graphic as possible. Goal is to have a valid GfxLink at the
611  // ImplGraphic (see there) that holds temporary data to the original data and type
612  // information about the original data. Only when this is given will
613  // SvXMLGraphicHelper::ImplInsertGraphicURL which is used at export use that type
614  // and use the original graphic at export for the ODF, without evtl. recoding
615  // of the bitmap graphic data to something without loss (e.g. PNG) but bigger
616  if(bHasOriginalData)
617  {
618  // #i15508# if we have the original data at the Graphic, let it survive
619  // by using that Graphic again, this time at a GraphicObject without link.
620  // This happens e.g. when inserting a linked graphic and breaking the link
621  maGrfObj.SetGraphic(aLocalGraphic);
622  }
623  }
624 }
625 
626 void SwGrfNode::SetTwipSize( const Size& rSz )
627 {
628  nGrfSize = rSz;
629  if( IsScaleImageMap() && nGrfSize.Width() && nGrfSize.Height() )
630  {
631  // resize Image-Map to size of the graphic
632  ScaleImageMap();
633 
634  // do not re-scale Image-Map
635  SetScaleImageMap( false );
636  }
637 }
638 
640 {
641  if( !nGrfSize.Width() || !nGrfSize.Height() )
642  return;
643 
644  // re-scale Image-Map
645  SwFrameFormat* pFormat = GetFlyFormat();
646 
647  if( !pFormat )
648  return;
649 
650  SwFormatURL aURL( pFormat->GetURL() );
651  if ( !aURL.GetMap() )
652  return;
653 
654  bool bScale = false;
655  Fraction aScaleX( 1, 1 );
656  Fraction aScaleY( 1, 1 );
657 
658  const SwFormatFrameSize& rFrameSize = pFormat->GetFrameSize();
659  const SvxBoxItem& rBox = pFormat->GetBox();
660 
661  if( !rFrameSize.GetWidthPercent() )
662  {
663  SwTwips nWidth = rFrameSize.GetWidth();
664 
665  nWidth -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) +
666  rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
667 
668  OSL_ENSURE( nWidth>0, "Do any 0 twip wide graphics exist!?" );
669 
670  if( nGrfSize.Width() != nWidth )
671  {
672  aScaleX = Fraction( nGrfSize.Width(), nWidth );
673  bScale = true;
674  }
675  }
676  if( !rFrameSize.GetHeightPercent() )
677  {
678  SwTwips nHeight = rFrameSize.GetHeight();
679 
680  nHeight -= rBox.CalcLineSpace(SvxBoxItemLine::TOP) +
681  rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
682 
683  OSL_ENSURE( nHeight>0, "Do any 0 twip high graphics exist!?" );
684 
685  if( nGrfSize.Height() != nHeight )
686  {
687  aScaleY = Fraction( nGrfSize.Height(), nHeight );
688  bScale = true;
689  }
690  }
691 
692  if( bScale )
693  {
694  aURL.GetMap()->Scale( aScaleX, aScaleY );
695  pFormat->SetFormatAttr( aURL );
696  }
697 }
698 
699 SwContentNode* SwGrfNode::MakeCopy(SwDoc* pDoc, const SwNodeIndex& rIdx, bool) const
700 {
701  // copy formats into the other document
702  SwGrfFormatColl* pColl = pDoc->CopyGrfColl( *GetGrfColl() );
703 
704  Graphic aTmpGrf = GetGrf();
705 
706  OUString sFile, sFilter;
707  if( IsLinkedFile() )
708  sfx2::LinkManager::GetDisplayNames( refLink.get(), nullptr, &sFile, nullptr, &sFilter );
709  else if( IsLinkedDDE() )
710  {
711  OUString sTmp1, sTmp2;
712  sfx2::LinkManager::GetDisplayNames( refLink.get(), &sTmp1, &sTmp2, &sFilter );
713  sfx2::MakeLnkName( sFile, &sTmp1, sTmp2, sFilter );
714  sFilter = "DDE";
715  }
716 
717  SwGrfNode* pGrfNd = SwNodes::MakeGrfNode( rIdx, sFile, sFilter,
718  &aTmpGrf, pColl,
719  GetpSwAttrSet() );
720  pGrfNd->SetTitle( GetTitle() );
721  pGrfNd->SetDescription( GetDescription() );
722  pGrfNd->SetContour( HasContour(), HasAutomaticContour() );
723  return pGrfNd;
724 }
725 
728  const SwFrame* pFrame ) const
729 {
730  const SwAttrSet& rSet = GetSwAttrSet();
731 
732  rGA.SetDrawMode( rSet.GetDrawModeGrf().GetValue() );
733 
734  const SwMirrorGrf & rMirror = rSet.GetMirrorGrf();
735  BmpMirrorFlags nMirror = BmpMirrorFlags::NONE;
736  if( rMirror.IsGrfToggle() && pFrame && !pFrame->FindPageFrame()->OnRightPage() )
737  {
738  switch( rMirror.GetValue() )
739  {
740  case MirrorGraph::Dont:
741  nMirror = BmpMirrorFlags::Horizontal;
742  break;
744  nMirror = BmpMirrorFlags::NONE;
745  break;
747  nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
748  break;
749  default:
750  nMirror = BmpMirrorFlags::Vertical;
751  break;
752  }
753  }
754  else
755  switch( rMirror.GetValue() )
756  {
757  case MirrorGraph::Both:
758  nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
759  break;
761  nMirror = BmpMirrorFlags::Horizontal;
762  break;
764  nMirror = BmpMirrorFlags::Vertical;
765  break;
766  default: break;
767  }
768 
769  rGA.SetMirrorFlags( nMirror );
770 
771  const SwCropGrf& rCrop = rSet.GetCropGrf();
772  rGA.SetCrop( convertTwipToMm100( rCrop.GetLeft() ),
773  convertTwipToMm100( rCrop.GetTop() ),
774  convertTwipToMm100( rCrop.GetRight() ),
775  convertTwipToMm100( rCrop.GetBottom() ));
776 
777  const SwRotationGrf& rRotation = rSet.GetRotationGrf();
778  rGA.SetRotation( rRotation.GetValue() );
779 
780  rGA.SetLuminance( rSet.GetLuminanceGrf().GetValue() );
781  rGA.SetContrast( rSet.GetContrastGrf().GetValue() );
782  rGA.SetChannelR( rSet.GetChannelRGrf().GetValue() );
783  rGA.SetChannelG( rSet.GetChannelGGrf().GetValue() );
784  rGA.SetChannelB( rSet.GetChannelBGrf().GetValue() );
785  rGA.SetGamma( rSet.GetGammaGrf().GetValue() );
786  rGA.SetInvert( rSet.GetInvertGrf().GetValue() );
787 
788  const sal_uInt16 nTrans = rSet.GetTransparencyGrf().GetValue();
789  rGA.SetTransparency( static_cast<sal_uInt8>(FRound(
790  std::min( nTrans, sal_uInt16(100) ) * 2.55 )) );
791 
792  return rGA;
793 }
794 
796 {
797  return maGrfObj.IsTransparent() ||
799 }
800 
802 {
803  if ( !IsLinkedFile() )
804  {
805  OSL_FAIL( "<SwGrfNode::TriggerAsyncLoad()> - Method is misused. Method call is only valid for graphic nodes, which refer a linked graphic file" );
806  return;
807  }
808 
809  if (mpThreadConsumer == nullptr)
810  {
812 
813  OUString sGrfNm;
814  sfx2::LinkManager::GetDisplayNames( refLink.get(), nullptr, &sGrfNm );
815  OUString sReferer;
816  SfxObjectShell * sh = GetDoc()->GetPersist();
817  if (sh != nullptr && sh->HasName())
818  {
819  sReferer = sh->GetMedium()->GetName();
820  }
821  mpThreadConsumer->CreateThread( sGrfNm, sReferer );
822  }
823 }
824 
825 
827  const css::uno::Reference<css::io::XInputStream>& xInputStream,
828  const bool bIsStreamReadOnly )
829 {
830  if ( IsLinkedFile() )
831  {
832  if ( xInputStream.is() )
833  {
834  mxInputStream = xInputStream;
835  mbIsStreamReadOnly = bIsStreamReadOnly;
838  ModifyNotification( &aMsgHint, &aMsgHint );
839  }
840  }
841 }
842 
844 {
845  // do not work on link, if a <SwapIn> has been triggered.
846  if ( !bInSwapIn && IsLinkedFile() )
847  {
849  GetLink()->Update();
851  ModifyNotification( &aMsgHint, &aMsgHint );
852 
853  // #i88291#
854  mxInputStream.clear();
856  mbLinkedInputStreamReady = false;
857  mpThreadConsumer.reset();
858  }
859 }
860 
861 // #i90395#
863 {
864  bool bRet = false;
865 
866  if ( IsLinkedFile() )
867  {
868  OUString sGrfNm;
869  sfx2::LinkManager::GetDisplayNames( refLink.get(), nullptr, &sGrfNm );
870  if ( !sGrfNm.startsWith( "vnd.sun.star.pkg:" ) )
871  {
872  bRet = true;
873  }
874  }
875 
876  return bRet;
877 }
878 
879 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwGrfNode(const SwNodeIndex &rWhere, const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic, SwGrfFormatColl *pGrfColl, SwAttrSet const *pAutoAttr)
Ctor for reading (SW/G) without graphics.
Definition: ndgrf.cxx:62
bool GetValue() const
Graphic GetGraphic() const
Definition: ndnotxt.cxx:231
long Width() const
bool is() const
void SetTransparency(sal_uInt8 cTransparency)
void SetDescription(const OUString &rDescription)
Definition: ndnotxt.cxx:272
void SetGamma(double fGamma)
Base class of the Writer layout elements.
Definition: frame.hxx:295
std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer
Definition: ndgrf.hxx:48
SVL_DLLPUBLIC bool IsDocument(const OUString &rURL)
const VectorGraphicDataPtr & getVectorGraphicData() const
const SwGammaGrf & GetGammaGrf(bool=true) const
Definition: grfatr.hxx:296
void ApplyInputStream(const css::uno::Reference< css::io::XInputStream > &xInputStream, const bool bIsStreamReadOnly)
Definition: ndgrf.cxx:826
const double & GetValue() const
Definition: grfatr.hxx:209
sal_Int32 GetLeft() const
bool HasEmbeddedStreamName() const
Definition: ndgrf.hxx:123
const tools::SvRef< sfx2::SvBaseLink > & GetLink() const
Definition: ndgrf.hxx:133
virtual void ModifyNotification(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: node.hxx:475
long FRound(double fVal)
bool HasAutomaticContour() const
Definition: ndnotxt.hxx:78
virtual const SwRootFrame * GetCurrentLayout() const =0
long Height() const
#define RES_GRF_REREAD_AND_INCACHE
Definition: hintids.hxx:305
void ScaleImageMap()
Scale an image-map: the image-map becomes zoomed in / out by factor between graphic-size and border-s...
Definition: ndgrf.cxx:639
bool bScaleImageMap
Scale image map in SetTwipSize.
Definition: ndgrf.hxx:46
long GetWidth() const
const OUString & GetName() const
void SetInvert(bool bInvert)
void SetTitle(const OUString &rTitle)
Definition: ndnotxt.cxx:247
const sal_Unicode cTokenSeparator
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1148
Definition: doc.hxx:185
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:292
sal_uInt16 GetValue() const
void SetMirrorFlags(BmpMirrorFlags nMirrFlags)
void setOriginURL(OUString const &rOriginURL)
bool IsLinkedFile() const
Definition: ndgrf.hxx:165
const SwChannelRGrf & GetChannelRGrf(bool=true) const
Definition: grfatr.hxx:290
long SwTwips
Definition: swtypes.hxx:49
bool bFrameInPaint
To avoid Start-/EndActions in Paint via SwapIn.
Definition: ndgrf.hxx:45
const GraphicObject * GetReplacementGrfObj() const
Definition: ndgrf.cxx:380
tools::SvRef< sfx2::SvBaseLink > refLink
If graphics only as link then pointer is set.
Definition: ndgrf.hxx:40
bool HasWriterListeners() const
Definition: calbck.hxx:211
void SetDrawMode(GraphicDrawMode eDrawMode)
Size nGrfSize
Definition: ndgrf.hxx:41
#define RES_LINKED_GRAPHIC_STREAM_ARRIVED
Definition: hintids.hxx:313
virtual ~SwGrfNode() override
Definition: ndgrf.cxx:278
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:84
const tools::PolyPolygon * HasContour() const
Definition: ndnotxt.cxx:107
#define OBJECT_CLIENT_GRF
const SwChannelBGrf & GetChannelBGrf(bool=true) const
Definition: grfatr.hxx:294
#define RES_UPDATE_ATTR
Definition: hintids.hxx:289
bool IsAsyncRetrieveInputStreamPossible() const
Definition: ndgrf.cxx:862
const SwTransparencyGrf & GetTransparencyGrf(bool=true) const
Definition: grfatr.hxx:300
FUNC_TYPE const nType
void TriggerAsyncRetrieveInputStream()
Definition: ndgrf.cxx:801
GraphicAttr & GetGraphicAttr(GraphicAttr &, const SwFrame *pFrame) const
Returns the with our graphic attributes filled Graphic-Attr-Structure.
Definition: ndgrf.cxx:727
static SwGrfNode * MakeGrfNode(const SwNodeIndex &rWhere, const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic, SwGrfFormatColl *pColl, SwAttrSet const *pAutoAttr=nullptr)
in ndgrf.cxx
Definition: ndgrf.cxx:401
bool OnRightPage() const
Definition: frame.hxx:711
#define RES_GRAPHIC_ARRIVED
Definition: hintids.hxx:298
class to provide creation of a thread to retrieve an input stream given by a URL and to consume the r...
bool GetFileFilterNms(OUString *pFileNm, OUString *pFilterNm) const
Definition: ndgrf.cxx:488
const SwCropGrf & GetCropGrf(bool=true) const
Definition: grfatr.hxx:282
const IDocumentLinksAdministration & getIDocumentLinksAdministration() const
Provides access to the document links administration interface.
Definition: node.cxx:2060
SwGrfFormatColl * GetGrfColl() const
Definition: ndnotxt.hxx:58
#define RES_GRAPHIC_PIECE_ARRIVED
Definition: hintids.hxx:299
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
T * get() const
Style of a layout element.
Definition: frmfmt.hxx:57
SwNodeType
Definition: ndtyp.hxx:28
sal_Int16 GetValue() const
bool mbLinkedInputStreamReady
Definition: ndgrf.hxx:49
void SetGraphic(const Graphic &rGraphic)
isolated only way to set GraphicObject to allow more actions when doing so
Definition: ndgrf.cxx:362
GraphicType GetType() const
css::uno::Reference< css::io::XInputStream > mxInputStream
Definition: ndgrf.hxx:50
void Remove(SvBaseLink const *pLink)
void SetContrast(short nContrastPercent)
void SetCrop(long nLeft_100TH_MM, long nTop_100TH_MM, long nRight_100TH_MM, long nBottom_100TH_MM)
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
virtual bool SavePersistentData() override
Communicate to graphic that node is in Undo-range.
Definition: ndgrf.cxx:520
void InsertFileLink(sfx2::SvBaseLink &, sal_uInt16 nFileType, const OUString &rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
const primitive2d::ObjectInfoPrimitive2D * getResult() const
sal_uInt8 GetHeightPercent() const
Definition: fmtfsize.hxx:88
void DelFrames(SwRootFrame const *pLayout)
Method deletes all views of document for the node.
Definition: node.cxx:1346
SwDoc * GetDoc()
Definition: node.hxx:702
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:78
void SetChannelG(short nChannelGPercent)
void process(const primitive2d::Primitive2DContainer &rSource)
BmpMirrorFlags
GraphicObject maGrfObj
Definition: ndgrf.hxx:38
Marks a node in the document model.
Definition: ndindex.hxx:31
bool HasName() const
OUString getOriginURL() const
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
Document links administration interface.
const SwRotationGrf & GetRotationGrf(bool=true) const
Definition: grfatr.hxx:284
const SwContrastGrf & GetContrastGrf(bool=true) const
Definition: grfatr.hxx:288
OUString GetDescription() const
Definition: ndnotxt.cxx:284
sal_uInt8 GetWidthPercent() const
Definition: fmtfsize.hxx:91
void SetChannelR(short nChannelRPercent)
bool ReRead(const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic=nullptr, bool bModify=true)
Re-read in case graphic was not OK.
Definition: ndgrf.cxx:131
void SetTwipSize(const Size &rSz)
Definition: ndgrf.cxx:626
const GraphicObject & GetGrfObj(bool bWait=false) const
Definition: ndgrf.cxx:374
bool IsScaleImageMap() const
Definition: ndgrf.hxx:107
GraphicType GetType() const
virtual Size GetTwipSize() const override
Definition: ndgrf.cxx:428
void InsertLink(const OUString &rGrfName, const OUString &rFltName)
Definition: ndgrf.cxx:561
void SetChannelB(short nChannelBPercent)
void InsertDDELink(SvBaseLink *, const OUString &rServer, const OUString &rTopic, const OUString &rItem)
SwGrfFormatColl * CopyGrfColl(const SwGrfFormatColl &rColl)
copy the graphic nodes
Definition: docfmt.cxx:1255
void SetGraphic(const Graphic &rGraphic, const GraphicObject *pCopyObj=nullptr)
std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2058
bool bChgTwipSize
Definition: ndgrf.hxx:44
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
sal_Int32 GetBottom() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const SwMirrorGrf & GetMirrorGrf(bool=true) const
Definition: grfatr.hxx:280
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
sal_Int32 GetTop() const
bool IsLinkedDDE() const
Definition: ndgrf.hxx:170
void MakeLnkName(OUString &rName, const OUString *pType, const OUString &rFile, const OUString &rLink, const OUString *pFilter)
void SetScaleImageMap(bool b)
Definition: ndgrf.hxx:108
const Graphic & GetGraphic() const
OUString GetTitle() const
Definition: ndnotxt.cxx:260
void SetLuminance(short nLuminancePercent)
#define OBJECT_CLIENT_DDE
INetProtocol GetProtocol() const
virtual SwContentNode * MakeCopy(SwDoc *, const SwNodeIndex &, bool bNewFrames) const override
in ndcopy.cxx
Definition: ndgrf.cxx:699
bool mbIsStreamReadOnly
Definition: ndgrf.hxx:51
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:634
void UpdateLinkWithInputStream()
Definition: ndgrf.cxx:843
std::unique_ptr< GraphicObject > mpReplacementGraphic
Definition: ndgrf.hxx:39
void onGraphicChanged()
allow reaction on change of content of GraphicObject, so always call when GraphicObject content chang...
Definition: ndgrf.cxx:310
const SwChannelGGrf & GetChannelGGrf(bool=true) const
Definition: grfatr.hxx:292
bool bInSwapIn
Definition: ndgrf.hxx:42
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
sal_uInt16 CalcLineSpace(SvxBoxItemLine nLine, bool bEvenIfNoLine=false) const
sal_Int32 GetRight() const
virtual sfx2::LinkManager & GetLinkManager()=0
const SwDrawModeGrf & GetDrawModeGrf(bool=true) const
Definition: grfatr.hxx:302
OString const aName
bool SwapIn(bool bWaitForData=false)
Loading of graphic immediately before displaying.
Definition: ndgrf.cxx:441
bool hasPdfData() const
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
void ReleaseLink()
Definition: ndgrf.cxx:590
const SwInvertGrf & GetInvertGrf(bool=true) const
Definition: grfatr.hxx:298
bool IsTransparent() const
Definition: ndgrf.cxx:795
void SetDefaultType()
sal_uInt8 GetValue() const
const SwLuminanceGrf & GetLuminanceGrf(bool=true) const
Definition: grfatr.hxx:286
long GetHeight() const
virtual bool RestorePersistentData() override
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndgrf.cxx:548
bool IsTransparent() const
bool IsGrfToggle() const
Definition: grfatr.hxx:65
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:710
void SetRotation(sal_uInt16 nRotate10)
const Graphic & GetGrf(bool bWait=false) const
Definition: ndgrf.cxx:368
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
Definition: ndnotxt.cxx:87
Size GetGraphicSizeTwip(const Graphic &rGraphic, vcl::RenderContext *pOutDev)
Definition: swtypes.cxx:28
virtual bool IsVisibleLinks() const =0
Insert links in-/visibly into LinkManager (linked ranges).
EnumT GetValue() const
SfxMedium * GetMedium() const