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 <sal/config.h>
21 
22 #include <string_view>
23 
24 #include <hintids.hxx>
25 #include <tools/helpers.hxx>
26 #include <tools/urlobj.hxx>
27 #include <tools/fract.hxx>
28 #include <tools/UnitConversion.hxx>
29 #include <svl/fstathelper.hxx>
30 #include <vcl/imap.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/linkmgr.hxx>
33 #include <editeng/boxitem.hxx>
34 #include <sot/formats.hxx>
35 #include <fmtfsize.hxx>
36 #include <fmturl.hxx>
37 #include <frmfmt.hxx>
38 #include <doc.hxx>
41 #include <frmatr.hxx>
42 #include <grfatr.hxx>
43 #include <swtypes.hxx>
44 #include <ndgrf.hxx>
45 #include <fmtcol.hxx>
46 #include <hints.hxx>
47 #include <swbaslnk.hxx>
48 #include <pagefrm.hxx>
49 
50 #include <rtl/ustring.hxx>
51 #include <o3tl/deleter.hxx>
55 
56 using namespace com::sun::star;
57 
59  const SwNodeIndex & rWhere,
60  const OUString& rGrfName,
61  const OUString& rFltName,
62  const Graphic* pGraphic,
63  SwGrfFormatColl *pGrfColl,
64  SwAttrSet const * pAutoAttr ) :
65  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
66  maGrfObj(),
67  mbInBaseLinkSwapIn(true),
68  // #i73788#
69  mbLinkedInputStreamReady( false ),
70  mbIsStreamReadOnly( false )
71 {
74 
75  ReRead(rGrfName, rFltName, pGraphic, false);
76 }
77 
79  const GraphicObject& rGrfObj,
80  SwGrfFormatColl *pGrfColl,
81  SwAttrSet const * pAutoAttr ) :
82  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
83  maGrfObj(rGrfObj),
84  mbInBaseLinkSwapIn(true),
85  // #i73788#
86  mbLinkedInputStreamReady( false ),
87  mbIsStreamReadOnly( false )
88 {
91 }
92 
100  const OUString& rGrfName,
101  const OUString& rFltName,
102  SwGrfFormatColl *pGrfColl,
103  SwAttrSet const * pAutoAttr ) :
104  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
105  maGrfObj(),
106  mbInBaseLinkSwapIn(true),
107  // #i73788#
108  mbLinkedInputStreamReady( false ),
109  mbIsStreamReadOnly( false )
110 {
111  Graphic aGrf; aGrf.SetDefaultType();
112  maGrfObj.SetGraphic( aGrf );
113 
116 
117  InsertLink( rGrfName, rFltName );
118  if( IsLinkedFile() )
119  {
120  INetURLObject aUrl( rGrfName );
121  if( INetProtocol::File == aUrl.GetProtocol() &&
123  {
124  // file exists, so create connection without an update
125  static_cast<SwBaseLink*>( mxLink.get() )->Connect();
126  }
127  }
128 }
129 
131  const OUString& rGrfName, const OUString& rFltName,
132  const Graphic* pGraphic,
133  bool bNewGrf )
134 {
135  bool bReadGrf = false;
136  bool bSetTwipSize = true;
137  mpReplacementGraphic.reset();
138 
139  OSL_ENSURE( pGraphic || !rGrfName.isEmpty(),
140  "GraphicNode without a name, Graphic or GraphicObject" );
141 
142  OUString sURLLink;
143  if (pGraphic)
144  {
145  Graphic aGraphic(*pGraphic);
146 
147  sURLLink = aGraphic.getOriginURL();
148  if (sURLLink.isEmpty() && !rGrfName.isEmpty())
149  {
150  sURLLink = rGrfName;
151  aGraphic.setOriginURL(sURLLink);
152  }
153  }
154  else
155  {
156  sURLLink = rGrfName;
157  }
158 
159  // with name
160  if( mxLink.is() )
161  {
162  OSL_ENSURE( !mbInSwapIn, "ReRead: I am still in SwapIn" );
163 
164  if( !sURLLink.isEmpty() )
165  {
166  // Note: if there is DDE in the FltName, then it is a DDE-linked graphic
167  OUString sCmd( sURLLink );
168  if( !rFltName.isEmpty() )
169  {
171  if( rFltName == "DDE" )
173  else
174  {
175  sfx2::MakeLnkName( sCmd, nullptr, sURLLink, std::u16string_view(), &rFltName );
177  }
178 
179  if( nNewType != mxLink->GetObjType() )
180  {
181  mxLink->Disconnect();
182  static_cast<SwBaseLink*>( mxLink.get() )->SetObjType( nNewType );
183  }
184  }
185 
186  mxLink->SetLinkSourceName( sCmd );
187  }
188  else // no name anymore, so remove link
189  {
191  mxLink.clear();
192  }
193 
194  if( pGraphic )
195  {
196  maGrfObj.SetGraphic( *pGraphic );
198  bReadGrf = true;
199  }
200  else
201  {
202  // reset data of the old graphic so that the correct placeholder is
203  // shown in case the new link could not be loaded
204  Graphic aGrf; aGrf.SetDefaultType();
205  maGrfObj.SetGraphic( aGrf );
206 
207  if( mxLink.is() )
208  {
209  if( getLayoutFrame( GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) )
210  {
212  }
213  else if ( bNewGrf )
214  {
215  //TODO refLink->setInputStream(getInputStream());
216  static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
217  }
218  }
220  bSetTwipSize = false;
221  }
222  }
223  else if( pGraphic && sURLLink.isEmpty() )
224  {
225  maGrfObj.SetGraphic( *pGraphic );
227  bReadGrf = true;
228  }
229  // Was the graphic already loaded?
230  else if( !bNewGrf && GraphicType::NONE != maGrfObj.GetType() )
231  return true;
232  else
233  {
234  // create new link for the graphic object
235  InsertLink( sURLLink, rFltName );
236 
237  if( GetNodes().IsDocNodes() )
238  {
239  if( pGraphic )
240  {
241  maGrfObj.SetGraphic( *pGraphic );
243  bReadGrf = true;
244  // create connection without update, as we have the graphic
245  static_cast<SwBaseLink*>( mxLink.get() )->Connect();
246  }
247  else
248  {
249  Graphic aGrf;
250  aGrf.SetDefaultType();
251  maGrfObj.SetGraphic( aGrf );
253  if ( bNewGrf )
254  {
255  static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
256  }
257  }
258  }
259  }
260 
261  // Bug 39281: Do not delete Size immediately - Events on ImageMaps should have
262  // something to work with when swapping
263  if( bSetTwipSize )
265 
266  // create an updates for the frames
267  if( bReadGrf && bNewGrf )
268  {
269  const SwUpdateAttr aHint(0,0,0);
270  CallSwClientNotify(sw::LegacyModifyHint(&aHint, &aHint));
271  }
272 
273  return bReadGrf;
274 }
275 
277 {
278  mpReplacementGraphic.reset();
279 
280  // #i73788#
281  mpThreadConsumer.reset();
282 
283  SwDoc& rDoc = GetDoc();
284  if( mxLink.is() )
285  {
286  OSL_ENSURE( !mbInSwapIn, "DTOR: I am still in SwapIn" );
288  mxLink->Disconnect();
289  }
290  else
291  {
292  // #i40014# - A graphic node, which is in a linked
293  // section, whose link is another section in the document, doesn't
294  // have to remove the stream from the storage.
295  // Because it's hard to detect this case here and it would only fix
296  // one problem with shared graphic files - there are also problems,
297  // a certain graphic file is referenced by two independent graphic nodes,
298  // brush item or drawing objects, the stream isn't no longer removed here.
299  // To do this stuff correctly, a reference counting on shared streams
300  // inside one document has to be implemented.
301  }
302  //#39289# delete frames already here since the Frames' dtor needs the graphic for its StopAnimation
303  if( HasWriterListeners() )
304  DelFrames(nullptr);
306 }
307 
310 {
311  // try to access SwFlyFrameFormat; since title/desc/name are set there, there is no
312  // use to continue if it is not yet set. If not yet set, call onGraphicChanged()
313  // when it is set.
314  SwFlyFrameFormat* pFlyFormat = dynamic_cast< SwFlyFrameFormat* >(GetFlyFormat());
315 
316  if(!pFlyFormat)
317  return;
318 
319  OUString aName;
320  OUString aTitle;
321  OUString aDesc;
322  auto const & rVectorGraphicDataPtr = GetGrf().getVectorGraphicData();
323 
324  if (rVectorGraphicDataPtr)
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 void SwGrfNode::SetGraphic(const Graphic& rGraphic)
362 {
363  maGrfObj.SetGraphic(rGraphic);
365 }
366 
368 {
371 }
372 
373 const Graphic& SwGrfNode::GetGrf(bool bWait) const
374 {
375  const_cast<SwGrfNode*>(this)->SwapIn(bWait);
376  return maGrfObj.GetGraphic();
377 }
378 
379 const GraphicObject& SwGrfNode::GetGrfObj(bool bWait) const
380 {
381  const_cast<SwGrfNode*>(this)->SwapIn(bWait);
382  return maGrfObj;
383 }
384 
386 {
388  {
389  auto const & rVectorGraphicDataPtr = GetGrfObj().GetGraphic().getVectorGraphicData();
390 
391  if (rVectorGraphicDataPtr)
392  {
393  const_cast< SwGrfNode* >(this)->mpReplacementGraphic.reset( new GraphicObject(rVectorGraphicDataPtr->getReplacement()) );
394  }
395  else if (GetGrfObj().GetGraphic().GetType() == GraphicType::GdiMetafile)
396  {
397  // Replacement graphic for PDF and metafiles is just the bitmap.
398  const_cast<SwGrfNode*>(this)->mpReplacementGraphic.reset( new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx()) );
399  }
400  }
401 
402  return mpReplacementGraphic.get();
403 }
404 
406  const OUString& rGrfName,
407  const OUString& rFltName,
408  const Graphic* pGraphic,
409  SwGrfFormatColl* pGrfColl,
410  SwAttrSet const * pAutoAttr )
411 {
412  OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
413  SwGrfNode *pNode;
414  // create object delayed, only from a SW/G-reader
415  if( !pGraphic )
416  pNode = new SwGrfNode( rWhere, rGrfName,
417  rFltName, pGrfColl, pAutoAttr );
418  else
419  pNode = new SwGrfNode( rWhere, rGrfName,
420  rFltName, pGraphic, pGrfColl, pAutoAttr );
421  return pNode;
422 }
423 
425  const GraphicObject& rGrfObj,
426  SwGrfFormatColl* pGrfColl )
427 {
428  OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
429  return new SwGrfNode( rWhere, rGrfObj, pGrfColl, nullptr );
430 }
431 
433 {
434  if( !mnGrfSize.Width() && !mnGrfSize.Height() )
435  {
436  const_cast<SwGrfNode*>(this)->SwapIn();
437  }
438  return mnGrfSize;
439 }
440 
445 bool SwGrfNode::SwapIn(bool bWaitForData)
446 {
447  if(mbInSwapIn) // not recursively!
448  return true;
449 
450  bool bRet = false;
451  mbInSwapIn = true;
452  SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
453 
454  if( pLink )
455  {
456  if( (GraphicType::NONE == maGrfObj.GetType() ||
457  GraphicType::Default == maGrfObj.GetType()) &&
459  {
460  // link was not loaded yet
461  if( pLink->SwapIn( bWaitForData ) )
462  {
463  bRet = true;
464  mbInBaseLinkSwapIn = false;
465  }
466  else if( GraphicType::Default == maGrfObj.GetType() )
467  {
468  // no default bitmap anymore, thus re-paint
469  mpReplacementGraphic.reset();
470 
474  CallSwClientNotify(sw::LegacyModifyHint(&aMsgHint, &aMsgHint));
475  }
476  }
477  else
478  {
479  bRet = true;
480  }
481  }
482  else
483  bRet = true;
484 
485  if (bRet)
486  {
487  if( !mnGrfSize.Width() && !mnGrfSize.Height() )
489  }
490  mbInSwapIn = false;
491  return bRet;
492 }
493 
494 bool SwGrfNode::GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const
495 {
496  bool bRet = false;
497  if( mxLink.is() && mxLink->GetLinkManager() )
498  {
502  mxLink.get(), nullptr, pFileNm, nullptr, pFilterNm );
503  else if( sfx2::SvBaseLinkObjectType::ClientDde == nType && pFileNm && pFilterNm )
504  {
505  OUString sApp;
506  OUString sTopic;
507  OUString sItem;
509  mxLink.get(), &sApp, &sTopic, &sItem ) )
510  {
511  *pFileNm = sApp + OUStringChar(sfx2::cTokenSeparator)
512  + sTopic + OUStringChar(sfx2::cTokenSeparator)
513  + sItem;
514  *pFilterNm = "DDE";
515  bRet = true;
516  }
517  }
518  }
519  return bRet;
520 }
521 
527 {
528  if( mxLink.is() )
529  {
530  OSL_ENSURE( !mbInSwapIn, "SavePersistentData: I am still in SwapIn" );
532  return true;
533  }
534 
535  // swap in first if in storage
536  if( HasEmbeddedStreamName() && !SwapIn() )
537  return false;
538 
539  // #i44367#
540  // Do not delete graphic file in storage, because the graphic file could
541  // be referenced by other graphic nodes.
542  // Because it's hard to detect this case here and it would only fix
543  // one problem with shared graphic files - there are also problems, if
544  // a certain graphic file is referenced by two independent graphic nodes,
545  // brush item or drawing objects, the stream isn't no longer removed here.
546  // To do this stuff correct, a reference counting on shared streams
547  // inside one document has to be implemented.
548  // Important note: see also fix for #i40014#
549 
550  // swap out into temp file
551  return true;
552 }
553 
555 {
556  if( mxLink.is() )
557  {
559  mxLink->SetVisible( rIDLA.IsVisibleLinks() );
560  rIDLA.GetLinkManager().InsertDDELink( mxLink.get() );
562  mxLink->Update();
563  }
564  return true;
565 }
566 
567 void SwGrfNode::InsertLink( const OUString& rGrfName, const OUString& rFltName )
568 {
569  mxLink = new SwBaseLink( SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::GDIMETAFILE, this );
570 
572  if( !GetNodes().IsDocNodes() )
573  return;
574 
575  mxLink->SetVisible( rIDLA.IsVisibleLinks() );
576  if( rFltName == "DDE" )
577  {
578  sal_Int32 nTmp = 0;
579  const OUString sApp{ rGrfName.getToken( 0, sfx2::cTokenSeparator, nTmp ) };
580  const OUString sTopic{ rGrfName.getToken( 0, sfx2::cTokenSeparator, nTmp ) };
581  const OUString sItem{ rGrfName.copy( nTmp ) };
582  rIDLA.GetLinkManager().InsertDDELink( mxLink.get(), sApp, sTopic, sItem );
583  }
584  else
585  {
586  const bool bSync = rFltName == "SYNCHRON";
587  mxLink->SetSynchron( bSync );
588  mxLink->SetContentType( SotClipboardFormatId::SVXB );
589 
592  (!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) );
593  }
594 }
595 
597 {
598  if( !mxLink.is() )
599  return;
600 
601  Graphic aLocalGraphic(maGrfObj.GetGraphic());
602  const bool bHasOriginalData(aLocalGraphic.IsGfxLink());
603 
604  {
605  mbInSwapIn = true;
606  SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
607  pLink->SwapIn( true, true );
608  mbInSwapIn = false;
609  }
610 
612  mxLink.clear();
613  aLocalGraphic.setOriginURL("");
614 
615  // #i15508# added extra processing after getting rid of the link. Use whatever is
616  // known from the formerly linked graphic to get to a state as close to a directly
617  // unlinked inserted graphic as possible. Goal is to have a valid GfxLink at the
618  // ImplGraphic (see there) that holds temporary data to the original data and type
619  // information about the original data. Only when this is given will
620  // SvXMLGraphicHelper::ImplInsertGraphicURL which is used at export use that type
621  // and use the original graphic at export for the ODF, without evtl. recoding
622  // of the bitmap graphic data to something without loss (e.g. PNG) but bigger
623  if(bHasOriginalData)
624  {
625  // #i15508# if we have the original data at the Graphic, let it survive
626  // by using that Graphic again, this time at a GraphicObject without link.
627  // This happens e.g. when inserting a linked graphic and breaking the link
628  maGrfObj.SetGraphic(aLocalGraphic);
629  }
630 }
631 
632 void SwGrfNode::SetTwipSize( const Size& rSz )
633 {
634  mnGrfSize = rSz;
636  {
637  // resize Image-Map to size of the graphic
638  ScaleImageMap();
639 
640  // do not re-scale Image-Map
641  SetScaleImageMap( false );
642  }
643 }
644 
646 {
647  if( !mnGrfSize.Width() || !mnGrfSize.Height() )
648  return;
649 
650  // re-scale Image-Map
651  SwFrameFormat* pFormat = GetFlyFormat();
652 
653  if( !pFormat )
654  return;
655 
656  SwFormatURL aURL( pFormat->GetURL() );
657  if ( !aURL.GetMap() )
658  return;
659 
660  bool bScale = false;
661  Fraction aScaleX( 1, 1 );
662  Fraction aScaleY( 1, 1 );
663 
664  const SwFormatFrameSize& rFrameSize = pFormat->GetFrameSize();
665  const SvxBoxItem& rBox = pFormat->GetBox();
666 
667  if( !rFrameSize.GetWidthPercent() )
668  {
669  SwTwips nWidth = rFrameSize.GetWidth();
670 
671  nWidth -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) +
672  rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
673 
674  OSL_ENSURE( nWidth>0, "Do any 0 twip wide graphics exist!?" );
675 
676  if( mnGrfSize.Width() != nWidth )
677  {
678  aScaleX = Fraction( mnGrfSize.Width(), nWidth );
679  bScale = true;
680  }
681  }
682  if( !rFrameSize.GetHeightPercent() )
683  {
684  SwTwips nHeight = rFrameSize.GetHeight();
685 
686  nHeight -= rBox.CalcLineSpace(SvxBoxItemLine::TOP) +
687  rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
688 
689  OSL_ENSURE( nHeight>0, "Do any 0 twip high graphics exist!?" );
690 
691  if( mnGrfSize.Height() != nHeight )
692  {
693  aScaleY = Fraction( mnGrfSize.Height(), nHeight );
694  bScale = true;
695  }
696  }
697 
698  if( bScale )
699  {
700  aURL.GetMap()->Scale( aScaleX, aScaleY );
701  pFormat->SetFormatAttr( aURL );
702  }
703 }
704 
705 SwContentNode* SwGrfNode::MakeCopy(SwDoc& rDoc, const SwNodeIndex& rIdx, bool) const
706 {
707  // copy formats into the other document
708  SwGrfFormatColl* pColl = rDoc.CopyGrfColl( *GetGrfColl() );
709 
710  Graphic aTmpGrf = GetGrf();
711 
712  OUString sFile, sFilter;
713  if( IsLinkedFile() )
714  sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sFile, nullptr, &sFilter );
715  else if( IsLinkedDDE() )
716  {
717  OUString sTmp1, sTmp2;
718  sfx2::LinkManager::GetDisplayNames( mxLink.get(), &sTmp1, &sTmp2, &sFilter );
719  sfx2::MakeLnkName( sFile, &sTmp1, sTmp2, sFilter );
720  sFilter = "DDE";
721  }
722 
723  SwGrfNode* pGrfNd = SwNodes::MakeGrfNode( rIdx, sFile, sFilter,
724  &aTmpGrf, pColl,
725  GetpSwAttrSet() );
726  pGrfNd->SetTitle( GetTitle() );
727  pGrfNd->SetDescription( GetDescription() );
728  pGrfNd->SetContour( HasContour(), HasAutomaticContour() );
729  return pGrfNd;
730 }
731 
734  const SwFrame* pFrame ) const
735 {
736  const SwAttrSet& rSet = GetSwAttrSet();
737 
738  rGA.SetDrawMode( rSet.GetDrawModeGrf().GetValue() );
739 
740  const SwMirrorGrf & rMirror = rSet.GetMirrorGrf();
741  BmpMirrorFlags nMirror = BmpMirrorFlags::NONE;
742  if( rMirror.IsGrfToggle() && pFrame && !pFrame->FindPageFrame()->OnRightPage() )
743  {
744  switch( rMirror.GetValue() )
745  {
746  case MirrorGraph::Dont:
747  nMirror = BmpMirrorFlags::Horizontal;
748  break;
750  nMirror = BmpMirrorFlags::NONE;
751  break;
753  nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
754  break;
755  default:
756  nMirror = BmpMirrorFlags::Vertical;
757  break;
758  }
759  }
760  else
761  switch( rMirror.GetValue() )
762  {
763  case MirrorGraph::Both:
764  nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
765  break;
767  nMirror = BmpMirrorFlags::Horizontal;
768  break;
770  nMirror = BmpMirrorFlags::Vertical;
771  break;
772  default: break;
773  }
774 
775  rGA.SetMirrorFlags( nMirror );
776 
777  const SwCropGrf& rCrop = rSet.GetCropGrf();
778  rGA.SetCrop( convertTwipToMm100( rCrop.GetLeft() ),
779  convertTwipToMm100( rCrop.GetTop() ),
780  convertTwipToMm100( rCrop.GetRight() ),
781  convertTwipToMm100( rCrop.GetBottom() ));
782 
783  const SwRotationGrf& rRotation = rSet.GetRotationGrf();
784  rGA.SetRotation( rRotation.GetValue() );
785 
786  rGA.SetLuminance( rSet.GetLuminanceGrf().GetValue() );
787  rGA.SetContrast( rSet.GetContrastGrf().GetValue() );
788  rGA.SetChannelR( rSet.GetChannelRGrf().GetValue() );
789  rGA.SetChannelG( rSet.GetChannelGGrf().GetValue() );
790  rGA.SetChannelB( rSet.GetChannelBGrf().GetValue() );
791  rGA.SetGamma( rSet.GetGammaGrf().GetValue() );
792  rGA.SetInvert( rSet.GetInvertGrf().GetValue() );
793 
794  const sal_uInt16 nTrans = rSet.GetTransparencyGrf().GetValue();
795  rGA.SetAlpha( 255 - static_cast<sal_uInt8>(FRound(
796  std::min( nTrans, sal_uInt16(100) ) * 2.55 )) );
797 
798  return rGA;
799 }
800 
802 {
803  return maGrfObj.IsTransparent() ||
805 }
806 
808 {
809  if ( !IsLinkedFile() )
810  {
811  OSL_FAIL( "<SwGrfNode::TriggerAsyncLoad()> - Method is misused. Method call is only valid for graphic nodes, which refer a linked graphic file" );
812  return;
813  }
814 
815  if (mpThreadConsumer != nullptr)
816  return;
817 
819 
820  OUString sGrfNm;
821  sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
822  OUString sReferer;
823  SfxObjectShell * sh = GetDoc().GetPersist();
824  if (sh != nullptr && sh->HasName())
825  {
826  sReferer = sh->GetMedium()->GetName();
827  }
828  mpThreadConsumer->CreateThread( sGrfNm, sReferer );
829 }
830 
831 
833  const css::uno::Reference<css::io::XInputStream>& xInputStream,
834  const bool bIsStreamReadOnly )
835 {
836  if ( IsLinkedFile() )
837  {
838  if ( xInputStream.is() )
839  {
840  mxInputStream = xInputStream;
841  mbIsStreamReadOnly = bIsStreamReadOnly;
844  CallSwClientNotify(sw::LegacyModifyHint(&aMsgHint, &aMsgHint));
845  }
846  }
847 }
848 
850 {
851  // do not work on link, if a <SwapIn> has been triggered.
852  if ( mbInSwapIn || !IsLinkedFile() )
853  return;
854 
856  GetLink()->Update();
858 
859  // #i88291#
860  mxInputStream.clear();
862  mbLinkedInputStreamReady = false;
863  mpThreadConsumer.reset();
864 }
865 
866 // #i90395#
868 {
869  bool bRet = false;
870 
871  if ( IsLinkedFile() )
872  {
873  OUString sGrfNm;
874  sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
875  if ( !sGrfNm.startsWith( "vnd.sun.star.pkg:" ) )
876  {
877  bRet = true;
878  }
879  }
880 
881  return bRet;
882 }
883 
884 /* 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:58
bool GetValue() const
Graphic GetGraphic() const
Definition: ndnotxt.cxx:229
bool is() const
void SetDescription(const OUString &rDescription)
Definition: ndnotxt.cxx:270
void SetGamma(double fGamma)
Base class of the Writer layout elements.
Definition: frame.hxx:313
tools::Long GetWidth() const
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer
Definition: ndgrf.hxx:49
SVL_DLLPUBLIC bool IsDocument(const OUString &rURL)
URL aURL
const SwGammaGrf & GetGammaGrf(bool=true) const
Definition: grfatr.hxx:298
void ApplyInputStream(const css::uno::Reference< css::io::XInputStream > &xInputStream, const bool bIsStreamReadOnly)
Definition: ndgrf.cxx:832
const double & GetValue() const
Definition: grfatr.hxx:211
sal_Int32 GetLeft() const
bool HasEmbeddedStreamName() const
Definition: ndgrf.hxx:122
const tools::SvRef< sfx2::SvBaseLink > & GetLink() const
Definition: ndgrf.hxx:132
bool HasAutomaticContour() const
Definition: ndnotxt.hxx:78
virtual const SwRootFrame * GetCurrentLayout() const =0
tools::SvRef< sfx2::SvBaseLink > mxLink
If graphics only as link then pointer is set.
Definition: ndgrf.hxx:40
void ScaleImageMap()
Scale an image-map: the image-map becomes zoomed in / out by factor between graphic-size and border-s...
Definition: ndgrf.cxx:645
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
const OUString & GetName() const
void SetInvert(bool bInvert)
void SetTitle(const OUString &rTitle)
Definition: ndnotxt.cxx:245
const sal_Unicode cTokenSeparator
constexpr TypedWhichId< SwMsgPoolItem > RES_LINKED_GRAPHIC_STREAM_ARRIVED(189)
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1212
Definition: doc.hxx:187
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:260
void SetMirrorFlags(BmpMirrorFlags nMirrFlags)
void setOriginURL(OUString const &rOriginURL)
bool IsLinkedFile() const
Definition: ndgrf.hxx:164
const SwChannelRGrf & GetChannelRGrf(bool=true) const
Definition: grfatr.hxx:292
bool mbScaleImageMap
Scale image map in SetTwipSize.
Definition: ndgrf.hxx:47
const GraphicObject * GetReplacementGrfObj() const
Definition: ndgrf.cxx:385
bool HasWriterListeners() const
Definition: calbck.hxx:197
void SetDrawMode(GraphicDrawMode eDrawMode)
bool mbInSwapIn
Definition: ndgrf.hxx:42
virtual ~SwGrfNode() override
Definition: ndgrf.cxx:276
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:84
const tools::PolyPolygon * HasContour() const
Definition: ndnotxt.cxx:105
constexpr auto convertTwipToMm100(N n)
constexpr tools::Long Width() const
Size mnGrfSize
Definition: ndgrf.hxx:41
const SwChannelBGrf & GetChannelBGrf(bool=true) const
Definition: grfatr.hxx:296
bool IsAsyncRetrieveInputStreamPossible() const
Definition: ndgrf.cxx:867
const SwTransparencyGrf & GetTransparencyGrf(bool=true) const
Definition: grfatr.hxx:302
void TriggerAsyncRetrieveInputStream()
Definition: ndgrf.cxx:807
GraphicAttr & GetGraphicAttr(GraphicAttr &, const SwFrame *pFrame) const
Returns the with our graphic attributes filled Graphic-Attr-Structure.
Definition: ndgrf.cxx:733
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:405
bool OnRightPage() const
Definition: frame.hxx:731
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:494
const SwCropGrf & GetCropGrf(bool=true) const
Definition: grfatr.hxx:284
const IDocumentLinksAdministration & getIDocumentLinksAdministration() const
Provides access to the document links administration interface.
Definition: node.cxx:2099
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
Definition: node.cxx:1653
SwGrfFormatColl * GetGrfColl() const
Definition: ndnotxt.hxx:58
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:452
T * get() const
Style of a layout element.
Definition: frmfmt.hxx:58
SwNodeType
Definition: ndtyp.hxx:28
sal_Int16 GetValue() const
bool mbLinkedInputStreamReady
Definition: ndgrf.hxx:50
void SetAlpha(sal_uInt8 cAlpha)
SwDoc & GetDoc()
Definition: node.hxx:212
virtual SwContentNode * MakeCopy(SwDoc &, const SwNodeIndex &, bool bNewFrames) const override
in ndcopy.cxx
Definition: ndgrf.cxx:705
void SetGraphic(const Graphic &rGraphic)
isolated only way to set GraphicObject to allow more actions when doing so
Definition: ndgrf.cxx:361
GraphicType GetType() const
css::uno::Reference< css::io::XInputStream > mxInputStream
Definition: ndgrf.hxx:51
void Remove(SvBaseLink const *pLink)
void SetContrast(short nContrastPercent)
tools::Long FRound(double fVal)
SwPageFrame * FindPageFrame()
Definition: frame.hxx:678
virtual bool SavePersistentData() override
Communicate to graphic that node is in Undo-range.
Definition: ndgrf.cxx:526
void SetRotation(Degree10 nRotate10)
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:1406
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:78
void SetChannelG(short nChannelGPercent)
SvBaseLinkObjectType
void TriggerGraphicArrived()
Definition: ndgrf.cxx:367
void process(const primitive2d::Primitive2DContainer &rSource)
BmpMirrorFlags
bool mbChangeTwipSize
Definition: ndgrf.hxx:45
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:697
Document links administration interface.
const SwRotationGrf & GetRotationGrf(bool=true) const
Definition: grfatr.hxx:286
const SwContrastGrf & GetContrastGrf(bool=true) const
Definition: grfatr.hxx:290
OUString GetDescription() const
Definition: ndnotxt.cxx:282
sal_uInt8 GetWidthPercent() const
Definition: fmtfsize.hxx:91
void SetChannelR(short nChannelRPercent)
tools::Long GetHeight() const
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:130
void SetTwipSize(const Size &rSz)
Definition: ndgrf.cxx:632
constexpr TypedWhichId< SwMsgPoolItem > RES_GRAPHIC_PIECE_ARRIVED(177)
const GraphicObject & GetGrfObj(bool bWait=false) const
Definition: ndgrf.cxx:379
bool IsScaleImageMap() const
Definition: ndgrf.hxx:106
tools::Long SwTwips
Definition: swtypes.hxx:49
GraphicType GetType() const
virtual Size GetTwipSize() const override
Definition: ndgrf.cxx:432
void InsertLink(const OUString &rGrfName, const OUString &rFltName)
Definition: ndgrf.cxx:567
void SetChannelB(short nChannelBPercent)
Degree10 GetValue() const
Definition: grfatr.hxx:109
SwGrfFormatColl * CopyGrfColl(const SwGrfFormatColl &rColl)
copy the graphic nodes
Definition: docfmt.cxx:1232
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2097
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:450
void MakeLnkName(OUString &rName, const OUString *pType, std::u16string_view rFile, std::u16string_view rLink, const OUString *pFilter)
sal_Int32 GetBottom() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const SwMirrorGrf & GetMirrorGrf(bool=true) const
Definition: grfatr.hxx:282
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
sal_Int32 GetTop() const
void InsertDDELink(SvBaseLink *, const OUString &rServer, std::u16string_view rTopic, std::u16string_view rItem)
bool IsLinkedDDE() const
Definition: ndgrf.hxx:169
void SetScaleImageMap(bool b)
Definition: ndgrf.hxx:107
const Graphic & GetGraphic() const
SvBaseLink * pLink
constexpr tools::Long Height() const
OUString GetTitle() const
Definition: ndnotxt.cxx:258
void SetGraphic(const Graphic &rGraphic)
void SetLuminance(short nLuminancePercent)
OUString aName
INetProtocol GetProtocol() const
bool mbIsStreamReadOnly
Definition: ndgrf.hxx:52
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:637
void UpdateLinkWithInputStream()
Definition: ndgrf.cxx:849
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:309
const SwChannelGGrf & GetChannelGGrf(bool=true) const
Definition: grfatr.hxx:294
QPRO_FUNC_TYPE nType
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:718
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:324
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:304
bool SwapIn(bool bWaitForData=false)
Loading of graphic immediately before displaying.
Definition: ndgrf.cxx:445
void ReleaseLink()
Definition: ndgrf.cxx:596
const SwInvertGrf & GetInvertGrf(bool=true) const
Definition: grfatr.hxx:300
bool IsTransparent() const
Definition: ndgrf.cxx:801
void SetDefaultType()
void SetCrop(tools::Long nLeft_100TH_MM, tools::Long nTop_100TH_MM, tools::Long nRight_100TH_MM, tools::Long nBottom_100TH_MM)
sal_uInt8 GetValue() const
bool mbInBaseLinkSwapIn
Definition: ndgrf.hxx:43
const SwLuminanceGrf & GetLuminanceGrf(bool=true) const
Definition: grfatr.hxx:288
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
virtual bool RestorePersistentData() override
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndgrf.cxx:554
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:719
const Graphic & GetGrf(bool bWait=false) const
Definition: ndgrf.cxx:373
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
Definition: ndnotxt.cxx:85
bool mbFrameInPaint
To avoid Start-/EndActions in Paint via SwapIn.
Definition: ndgrf.hxx:46
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