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