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