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>
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>
52#include <o3tl/string_view.hxx>
53#include <osl/diagnose.h>
57
58using namespace com::sun::star;
59
61 SwNode & rWhere,
62 const OUString& rGrfName,
63 const OUString& rFltName,
64 const Graphic* pGraphic,
65 SwGrfFormatColl *pGrfColl,
66 SwAttrSet const * pAutoAttr ) :
67 SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
68 mbInBaseLinkSwapIn(true),
69 // #i73788#
70 mbLinkedInputStreamReady( false ),
71 mbIsStreamReadOnly( false )
72{
75
76 ReRead(rGrfName, rFltName, pGraphic, false);
77}
78
86 std::u16string_view rGrfName,
87 const OUString& rFltName,
88 SwGrfFormatColl *pGrfColl,
89 SwAttrSet const * pAutoAttr ) :
90 SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
91 mbInBaseLinkSwapIn(true),
92 // #i73788#
93 mbLinkedInputStreamReady( false ),
94 mbIsStreamReadOnly( false )
95{
96 Graphic aGrf; aGrf.SetDefaultType();
97 maGrfObj.SetGraphic( aGrf );
98
101
102 InsertLink( rGrfName, rFltName );
103 if( IsLinkedFile() )
104 {
105 INetURLObject aUrl( rGrfName );
106 if( INetProtocol::File == aUrl.GetProtocol() &&
108 {
109 // file exists, so create connection without an update
110 static_cast<SwBaseLink*>( mxLink.get() )->Connect();
111 }
112 }
113}
114
116 const OUString& rGrfName, const OUString& rFltName,
117 const Graphic* pGraphic,
118 bool bNewGrf )
119{
120 bool bReadGrf = false;
121 bool bSetTwipSize = true;
122 mpReplacementGraphic.reset();
123
124 OSL_ENSURE( pGraphic || !rGrfName.isEmpty(),
125 "GraphicNode without a name, Graphic or GraphicObject" );
126
127 OUString sURLLink;
128 if (pGraphic)
129 {
130 Graphic aGraphic(*pGraphic);
131
132 sURLLink = aGraphic.getOriginURL();
133 if (sURLLink.isEmpty() && !rGrfName.isEmpty())
134 {
135 sURLLink = rGrfName;
136 aGraphic.setOriginURL(sURLLink);
137 }
138 }
139 else
140 {
141 sURLLink = rGrfName;
142 }
143
144 // with name
145 if( mxLink.is() )
146 {
147 OSL_ENSURE( !mbInSwapIn, "ReRead: I am still in SwapIn" );
148
149 if( !sURLLink.isEmpty() )
150 {
151 // Note: if there is DDE in the FltName, then it is a DDE-linked graphic
152 OUString sCmd( sURLLink );
153 if( !rFltName.isEmpty() )
154 {
156 if( rFltName == "DDE" )
158 else
159 {
160 sfx2::MakeLnkName( sCmd, nullptr, sURLLink, std::u16string_view(), &rFltName );
162 }
163
164 if( nNewType != mxLink->GetObjType() )
165 {
166 mxLink->Disconnect();
167 static_cast<SwBaseLink*>( mxLink.get() )->SetObjType( nNewType );
168 }
169 }
170
171 mxLink->SetLinkSourceName( sCmd );
172 }
173 else // no name anymore, so remove link
174 {
176 mxLink.clear();
177 }
178
179 if( pGraphic )
180 {
181 maGrfObj.SetGraphic( *pGraphic );
183 bReadGrf = true;
184 }
185 else
186 {
187 // reset data of the old graphic so that the correct placeholder is
188 // shown in case the new link could not be loaded
189 Graphic aGrf; aGrf.SetDefaultType();
190 maGrfObj.SetGraphic( aGrf );
191
192 if( mxLink.is() )
193 {
194 if( getLayoutFrame( GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) )
195 {
196 CallSwClientNotify(sw::GrfRereadAndInCacheHint());
197 }
198 else if ( bNewGrf )
199 {
200 //TODO refLink->setInputStream(getInputStream());
201 static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
202 }
203 }
205 bSetTwipSize = false;
206 }
207 }
208 else if( pGraphic && sURLLink.isEmpty() )
209 {
210 maGrfObj.SetGraphic( *pGraphic );
212 bReadGrf = true;
213 }
214 // Was the graphic already loaded?
215 else if( !bNewGrf && GraphicType::NONE != maGrfObj.GetType() )
216 return true;
217 else
218 {
219 // create new link for the graphic object
220 InsertLink( sURLLink, rFltName );
221
222 if( GetNodes().IsDocNodes() )
223 {
224 if( pGraphic )
225 {
226 maGrfObj.SetGraphic( *pGraphic );
228 bReadGrf = true;
229 // create connection without update, as we have the graphic
230 static_cast<SwBaseLink*>( mxLink.get() )->Connect();
231 }
232 else
233 {
234 Graphic aGrf;
235 aGrf.SetDefaultType();
236 maGrfObj.SetGraphic( aGrf );
238 if ( bNewGrf )
239 {
240 static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
241 }
242 }
243 }
244 }
245
246 // Bug 39281: Do not delete Size immediately - Events on ImageMaps should have
247 // something to work with when swapping
248 if( bSetTwipSize )
250
251 // create an updates for the frames
252 if( bReadGrf && bNewGrf )
253 {
254 const SwUpdateAttr aHint(0,0,0);
255 CallSwClientNotify(sw::LegacyModifyHint(&aHint, &aHint));
256 }
257
258 return bReadGrf;
259}
260
262{
263 mpReplacementGraphic.reset();
264
265 // #i73788#
266 mpThreadConsumer.reset();
267
268 SwDoc& rDoc = GetDoc();
269 if( mxLink.is() )
270 {
271 OSL_ENSURE( !mbInSwapIn, "DTOR: I am still in SwapIn" );
273 mxLink->Disconnect();
274 }
275 else
276 {
277 // #i40014# - A graphic node, which is in a linked
278 // section, whose link is another section in the document, doesn't
279 // have to remove the stream from the storage.
280 // Because it's hard to detect this case here and it would only fix
281 // one problem with shared graphic files - there are also problems,
282 // a certain graphic file is referenced by two independent graphic nodes,
283 // brush item or drawing objects, the stream isn't no longer removed here.
284 // To do this stuff correctly, a reference counting on shared streams
285 // inside one document has to be implemented.
286 }
287 //#39289# delete frames already here since the Frames' dtor needs the graphic for its StopAnimation
288 if( HasWriterListeners() )
289 DelFrames(nullptr);
291}
292
295{
296 // try to access SwFlyFrameFormat; since title/desc/name are set there, there is no
297 // use to continue if it is not yet set. If not yet set, call onGraphicChanged()
298 // when it is set.
299 SwFlyFrameFormat* pFlyFormat = dynamic_cast< SwFlyFrameFormat* >(GetFlyFormat());
300
301 if(!pFlyFormat)
302 return;
303
304 OUString aName;
305 OUString aTitle;
306 OUString aDesc;
307 auto const & rVectorGraphicDataPtr = GetGrf().getVectorGraphicData();
308
309 if (rVectorGraphicDataPtr)
310 {
311 const drawinglayer::primitive2d::Primitive2DContainer aSequence(rVectorGraphicDataPtr->getPrimitive2DSequence());
312
313 if(!aSequence.empty())
314 {
317
318 aProcessor.process(aSequence);
319
321
322 if(pResult)
323 {
324 aName = pResult->getName();
325 aTitle = pResult->getTitle();
326 aDesc = pResult->getDesc();
327 }
328 }
329 }
330
331 if(!aTitle.isEmpty())
332 {
333 SetTitle(aTitle);
334 }
335 else if (!aName.isEmpty())
336 {
338 }
339
340 if(!aDesc.isEmpty())
341 {
342 SetDescription(aDesc);
343 }
344}
345
346void SwGrfNode::SetGraphic(const Graphic& rGraphic)
347{
348 maGrfObj.SetGraphic(rGraphic);
350}
351
353{
354 CallSwClientNotify(sw::PreGraphicArrivedHint());
355 CallSwClientNotify(sw::PostGraphicArrivedHint());
356}
357
358const Graphic& SwGrfNode::GetGrf(bool bWait) const
359{
360 const_cast<SwGrfNode*>(this)->SwapIn(bWait);
361 return maGrfObj.GetGraphic();
362}
363
364const GraphicObject& SwGrfNode::GetGrfObj(bool bWait) const
365{
366 const_cast<SwGrfNode*>(this)->SwapIn(bWait);
367 return maGrfObj;
368}
369
371{
373 {
374 auto const & rVectorGraphicDataPtr = GetGrfObj().GetGraphic().getVectorGraphicData();
375
376 if (rVectorGraphicDataPtr)
377 {
378 const_cast< SwGrfNode* >(this)->mpReplacementGraphic.reset( new GraphicObject(rVectorGraphicDataPtr->getReplacement()) );
379 }
380 else if (GetGrfObj().GetGraphic().GetType() == GraphicType::GdiMetafile)
381 {
382 // Replacement graphic for PDF and metafiles is just the bitmap.
383 const_cast<SwGrfNode*>(this)->mpReplacementGraphic.reset( new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx()) );
384 }
385 }
386
387 return mpReplacementGraphic.get();
388}
389
391 const OUString& rGrfName,
392 const OUString& rFltName,
393 const Graphic* pGraphic,
394 SwGrfFormatColl* pGrfColl,
395 SwAttrSet const * pAutoAttr )
396{
397 OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
398 SwGrfNode *pNode;
399 // create object delayed, only from a SW/G-reader
400 if( !pGraphic )
401 pNode = new SwGrfNode( rWhere, rGrfName,
402 rFltName, pGrfColl, pAutoAttr );
403 else
404 pNode = new SwGrfNode( rWhere, rGrfName,
405 rFltName, pGraphic, pGrfColl, pAutoAttr );
406 return pNode;
407}
408
410{
411 if( !mnGrfSize.Width() && !mnGrfSize.Height() )
412 {
413 const_cast<SwGrfNode*>(this)->SwapIn();
414 }
415 return mnGrfSize;
416}
417
422bool SwGrfNode::SwapIn(bool bWaitForData)
423{
424 if(mbInSwapIn) // not recursively!
425 return true;
426
427 bool bRet = false;
428 mbInSwapIn = true;
429 SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
430
431 if( pLink )
432 {
433 if( (GraphicType::NONE == maGrfObj.GetType() ||
434 GraphicType::Default == maGrfObj.GetType()) &&
436 {
437 // link was not loaded yet
438 if( pLink->SwapIn( bWaitForData ) )
439 {
440 bRet = true;
441 mbInBaseLinkSwapIn = false;
442 }
443 else if( GraphicType::Default == maGrfObj.GetType() )
444 {
445 // no default bitmap anymore, thus re-paint
446 mpReplacementGraphic.reset();
447
450 CallSwClientNotify(sw::GraphicPieceArrivedHint());
451 }
452 }
453 else
454 {
455 bRet = true;
456 }
457 }
458 else
459 bRet = true;
460
461 if (bRet)
462 {
463 if( !mnGrfSize.Width() && !mnGrfSize.Height() )
465 }
466 mbInSwapIn = false;
467 return bRet;
468}
469
470bool SwGrfNode::GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const
471{
472 bool bRet = false;
473 if( mxLink.is() && mxLink->GetLinkManager() )
474 {
478 mxLink.get(), nullptr, pFileNm, nullptr, pFilterNm );
479 else if( sfx2::SvBaseLinkObjectType::ClientDde == nType && pFileNm && pFilterNm )
480 {
481 OUString sApp;
482 OUString sTopic;
483 OUString sItem;
485 mxLink.get(), &sApp, &sTopic, &sItem ) )
486 {
487 *pFileNm = sApp + OUStringChar(sfx2::cTokenSeparator)
488 + sTopic + OUStringChar(sfx2::cTokenSeparator)
489 + sItem;
490 *pFilterNm = "DDE";
491 bRet = true;
492 }
493 }
494 }
495 return bRet;
496}
497
503{
504 if( mxLink.is() )
505 {
506 OSL_ENSURE( !mbInSwapIn, "SavePersistentData: I am still in SwapIn" );
508 return true;
509 }
510
511 // swap in first if in storage
512 if( HasEmbeddedStreamName() && !SwapIn() )
513 return false;
514
515 // #i44367#
516 // Do not delete graphic file in storage, because the graphic file could
517 // be referenced by other graphic nodes.
518 // Because it's hard to detect this case here and it would only fix
519 // one problem with shared graphic files - there are also problems, if
520 // a certain graphic file is referenced by two independent graphic nodes,
521 // brush item or drawing objects, the stream isn't no longer removed here.
522 // To do this stuff correct, a reference counting on shared streams
523 // inside one document has to be implemented.
524 // Important note: see also fix for #i40014#
525
526 // swap out into temp file
527 return true;
528}
529
531{
532 if( mxLink.is() )
533 {
535 mxLink->SetVisible( rIDLA.IsVisibleLinks() );
537 if( getIDocumentLayoutAccess().GetCurrentLayout() )
538 mxLink->Update();
539 }
540 return true;
541}
542
543void SwGrfNode::InsertLink( std::u16string_view rGrfName, const OUString& rFltName )
544{
545 mxLink = new SwBaseLink( SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::GDIMETAFILE, this );
546
548 if( !GetNodes().IsDocNodes() )
549 return;
550
551 mxLink->SetVisible( rIDLA.IsVisibleLinks() );
552 if( rFltName == "DDE" )
553 {
554 sal_Int32 nTmp = 0;
555 const OUString sApp{ o3tl::getToken(rGrfName, 0, sfx2::cTokenSeparator, nTmp ) };
556 const std::u16string_view sTopic{ o3tl::getToken(rGrfName, 0, sfx2::cTokenSeparator, nTmp ) };
557 const std::u16string_view sItem{ rGrfName.substr( nTmp ) };
558 rIDLA.GetLinkManager().InsertDDELink( mxLink.get(), sApp, sTopic, sItem );
559 }
560 else
561 {
562 const bool bSync = rFltName == "SYNCHRON";
563 mxLink->SetSynchron( bSync );
564 mxLink->SetContentType( SotClipboardFormatId::SVXB );
565
568 (!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) );
569 }
570}
571
573{
574 if( !mxLink.is() )
575 return;
576
577 Graphic aLocalGraphic(maGrfObj.GetGraphic());
578 const bool bHasOriginalData(aLocalGraphic.IsGfxLink());
579
580 {
581 mbInSwapIn = true;
582 SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
583 pLink->SwapIn( true, true );
584 mbInSwapIn = false;
585 }
586
588 mxLink.clear();
589 aLocalGraphic.setOriginURL("");
590
591 // #i15508# added extra processing after getting rid of the link. Use whatever is
592 // known from the formerly linked graphic to get to a state as close to a directly
593 // unlinked inserted graphic as possible. Goal is to have a valid GfxLink at the
594 // ImplGraphic (see there) that holds temporary data to the original data and type
595 // information about the original data. Only when this is given will
596 // SvXMLGraphicHelper::ImplInsertGraphicURL which is used at export use that type
597 // and use the original graphic at export for the ODF, without evtl. recoding
598 // of the bitmap graphic data to something without loss (e.g. PNG) but bigger
599 if(bHasOriginalData)
600 {
601 // #i15508# if we have the original data at the Graphic, let it survive
602 // by using that Graphic again, this time at a GraphicObject without link.
603 // This happens e.g. when inserting a linked graphic and breaking the link
604 maGrfObj.SetGraphic(aLocalGraphic);
605 }
606}
607
608void SwGrfNode::SetTwipSize( const Size& rSz )
609{
610 mnGrfSize = rSz;
612 {
613 // resize Image-Map to size of the graphic
615
616 // do not re-scale Image-Map
617 SetScaleImageMap( false );
618 }
619}
620
622{
623 if( !mnGrfSize.Width() || !mnGrfSize.Height() )
624 return;
625
626 // re-scale Image-Map
627 SwFrameFormat* pFormat = GetFlyFormat();
628
629 if( !pFormat )
630 return;
631
632 SwFormatURL aURL( pFormat->GetURL() );
633 if ( !aURL.GetMap() )
634 return;
635
636 bool bScale = false;
637 Fraction aScaleX( 1, 1 );
638 Fraction aScaleY( 1, 1 );
639
640 const SwFormatFrameSize& rFrameSize = pFormat->GetFrameSize();
641 const SvxBoxItem& rBox = pFormat->GetBox();
642
643 if( !rFrameSize.GetWidthPercent() )
644 {
645 SwTwips nWidth = rFrameSize.GetWidth();
646
647 nWidth -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) +
648 rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
649
650 OSL_ENSURE( nWidth>0, "Do any 0 twip wide graphics exist!?" );
651
652 if( mnGrfSize.Width() != nWidth )
653 {
654 aScaleX = Fraction( mnGrfSize.Width(), nWidth );
655 bScale = true;
656 }
657 }
658 if( !rFrameSize.GetHeightPercent() )
659 {
660 SwTwips nHeight = rFrameSize.GetHeight();
661
662 nHeight -= rBox.CalcLineSpace(SvxBoxItemLine::TOP) +
663 rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
664
665 OSL_ENSURE( nHeight>0, "Do any 0 twip high graphics exist!?" );
666
667 if( mnGrfSize.Height() != nHeight )
668 {
669 aScaleY = Fraction( mnGrfSize.Height(), nHeight );
670 bScale = true;
671 }
672 }
673
674 if( bScale )
675 {
676 aURL.GetMap()->Scale( aScaleX, aScaleY );
677 pFormat->SetFormatAttr( aURL );
678 }
679}
680
682{
683 // copy formats into the other document
684 SwGrfFormatColl* pColl = rDoc.CopyGrfColl( *GetGrfColl() );
685
686 Graphic aTmpGrf = GetGrf();
687
688 OUString sFile, sFilter;
689 if( IsLinkedFile() )
690 sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sFile, nullptr, &sFilter );
691 else if( IsLinkedDDE() )
692 {
693 OUString sTmp1, sTmp2;
694 sfx2::LinkManager::GetDisplayNames( mxLink.get(), &sTmp1, &sTmp2, &sFilter );
695 sfx2::MakeLnkName( sFile, &sTmp1, sTmp2, sFilter );
696 sFilter = "DDE";
697 }
698
699 SwGrfNode* pGrfNd = SwNodes::MakeGrfNode( rIdx, sFile, sFilter,
700 &aTmpGrf, pColl,
701 GetpSwAttrSet() );
702 pGrfNd->SetTitle( GetTitle() );
703 pGrfNd->SetDescription( GetDescription() );
705 return pGrfNd;
706}
707
710 const SwFrame* pFrame ) const
711{
712 const SwAttrSet& rSet = GetSwAttrSet();
713
714 rGA.SetDrawMode( rSet.GetDrawModeGrf().GetValue() );
715
716 const SwMirrorGrf & rMirror = rSet.GetMirrorGrf();
717 BmpMirrorFlags nMirror = BmpMirrorFlags::NONE;
718 if( rMirror.IsGrfToggle() && pFrame && !pFrame->FindPageFrame()->OnRightPage() )
719 {
720 switch( rMirror.GetValue() )
721 {
723 nMirror = BmpMirrorFlags::Horizontal;
724 break;
726 nMirror = BmpMirrorFlags::NONE;
727 break;
729 nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
730 break;
731 default:
732 nMirror = BmpMirrorFlags::Vertical;
733 break;
734 }
735 }
736 else
737 switch( rMirror.GetValue() )
738 {
740 nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
741 break;
743 nMirror = BmpMirrorFlags::Horizontal;
744 break;
746 nMirror = BmpMirrorFlags::Vertical;
747 break;
748 default: break;
749 }
750
751 rGA.SetMirrorFlags( nMirror );
752
753 const SwCropGrf& rCrop = rSet.GetCropGrf();
754
755 tools::Long nCropLeft = rCrop.GetLeft();
756 tools::Long nCropTop = rCrop.GetTop();
757 tools::Long nCropRight = rCrop.GetRight();
758 tools::Long nCropBottom = rCrop.GetBottom();
759
760 // take mirroring of crop values into consideration
761 // while cropping a flipped image. otherwise,
762 // cropping will crop the opposite side of the image.
763 if (rGA.GetMirrorFlags() & BmpMirrorFlags::Vertical)
764 {
765 nCropTop = rCrop.GetBottom();
766 nCropBottom = rCrop.GetTop();
767 }
768
769 if (rGA.GetMirrorFlags() & BmpMirrorFlags::Horizontal)
770 {
771 nCropLeft = rCrop.GetRight();
772 nCropRight = rCrop.GetLeft();
773 }
774
775 rGA.SetCrop( convertTwipToMm100( nCropLeft ),
776 convertTwipToMm100( nCropTop ),
777 convertTwipToMm100( nCropRight ),
778 convertTwipToMm100( nCropBottom ));
779
780 const SwRotationGrf& rRotation = rSet.GetRotationGrf();
781 rGA.SetRotation( rRotation.GetValue() );
782
783 rGA.SetLuminance( rSet.GetLuminanceGrf().GetValue() );
784 rGA.SetContrast( rSet.GetContrastGrf().GetValue() );
785 rGA.SetChannelR( rSet.GetChannelRGrf().GetValue() );
786 rGA.SetChannelG( rSet.GetChannelGGrf().GetValue() );
787 rGA.SetChannelB( rSet.GetChannelBGrf().GetValue() );
788 rGA.SetGamma( rSet.GetGammaGrf().GetValue() );
789 rGA.SetInvert( rSet.GetInvertGrf().GetValue() );
790
791 const sal_uInt16 nTrans = rSet.GetTransparencyGrf().GetValue();
792 rGA.SetAlpha( 255 - static_cast<sal_uInt8>(FRound(
793 std::min( nTrans, sal_uInt16(100) ) * 2.55 )) );
794
795 return rGA;
796}
797
799{
800 return maGrfObj.IsTransparent() ||
802}
803
805{
806 if ( !IsLinkedFile() )
807 {
808 OSL_FAIL( "<SwGrfNode::TriggerAsyncLoad()> - Method is misused. Method call is only valid for graphic nodes, which refer a linked graphic file" );
809 return;
810 }
811
812 if (mpThreadConsumer != nullptr)
813 return;
814
816
817 OUString sGrfNm;
818 sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
819 OUString sReferer;
821 if (sh != nullptr && sh->HasName())
822 {
823 sReferer = sh->GetMedium()->GetName();
824 }
825 mpThreadConsumer->CreateThread( sGrfNm, sReferer );
826}
827
828
830 const css::uno::Reference<css::io::XInputStream>& xInputStream,
831 const bool bIsStreamReadOnly )
832{
833 if ( IsLinkedFile() )
834 {
835 if ( xInputStream.is() )
836 {
837 mxInputStream = xInputStream;
838 mbIsStreamReadOnly = bIsStreamReadOnly;
840 CallSwClientNotify(sw::LinkedGraphicStreamArrivedHint());
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();
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: */
constexpr auto convertTwipToMm100(N n)
sal_uInt8 GetValue() const
void SetGamma(double fGamma)
void SetRotation(Degree10 nRotate10)
void SetChannelR(short nChannelRPercent)
void SetMirrorFlags(BmpMirrorFlags nMirrFlags)
void SetContrast(short nContrastPercent)
BmpMirrorFlags GetMirrorFlags() const
void SetChannelB(short nChannelBPercent)
void SetCrop(tools::Long nLeft_100TH_MM, tools::Long nTop_100TH_MM, tools::Long nRight_100TH_MM, tools::Long nBottom_100TH_MM)
void SetInvert(bool bInvert)
void SetDrawMode(GraphicDrawMode eDrawMode)
void SetLuminance(short nLuminancePercent)
void SetAlpha(sal_uInt8 cAlpha)
void SetChannelG(short nChannelGPercent)
void SetGraphic(const Graphic &rGraphic)
const Graphic & GetGraphic() const
GraphicType GetType() const
bool IsTransparent() const
OUString getOriginURL() const
GraphicType GetType() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
bool IsGfxLink() const
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
void SetDefaultType()
void setOriginURL(OUString const &rOriginURL)
Document links administration interface.
virtual sfx2::LinkManager & GetLinkManager()=0
virtual bool IsVisibleLinks() const =0
Insert links in-/visibly into LinkManager (linked ranges).
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
EnumT GetValue() const
const OUString & GetName() const
bool HasName() const
SfxMedium * GetMedium() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
sal_Int16 CalcLineSpace(SvxBoxItemLine nLine, bool bEvenIfNoLine=false, bool bAllowNegative=false) const
sal_Int32 GetTop() const
sal_Int32 GetRight() const
sal_Int32 GetLeft() const
sal_Int32 GetBottom() const
tools::Long GetHeight() const
tools::Long GetWidth() const
class to provide creation of a thread to retrieve an input stream given by a URL and to consume the r...
const SwTransparencyGrf & GetTransparencyGrf(bool=true) const
Definition: grfatr.hxx:302
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:727
void DelFrames(SwRootFrame const *pLayout)
Method deletes all views of document for the node.
Definition: node.cxx:1432
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:493
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
Definition: node.cxx:1679
Definition: doc.hxx:197
SwGrfFormatColl * CopyGrfColl(const SwGrfFormatColl &rColl)
copy the graphic nodes
Definition: docfmt.cxx:1258
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:274
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:653
sal_uInt8 GetWidthPercent() const
Definition: fmtfsize.hxx:91
sal_uInt8 GetHeightPercent() const
Definition: fmtfsize.hxx:88
SfxPoolItem subclass that wraps a URL.
Definition: fmturl.hxx:33
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:108
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:77
Style of a layout element.
Definition: frmfmt.hxx:72
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool OnRightPage() const
Definition: frame.hxx:739
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
void ScaleImageMap()
Scale an image-map: the image-map becomes zoomed in / out by factor between graphic-size and border-s...
Definition: ndgrf.cxx:621
void onGraphicChanged()
allow reaction on change of content of GraphicObject, so always call when GraphicObject content chang...
Definition: ndgrf.cxx:294
std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer
Definition: ndgrf.hxx:49
Size mnGrfSize
Definition: ndgrf.hxx:41
virtual Size GetTwipSize() const override
Definition: ndgrf.cxx:409
bool IsLinkedFile() const
Definition: ndgrf.hxx:160
bool HasEmbeddedStreamName() const
Definition: ndgrf.hxx:118
void SetGraphic(const Graphic &rGraphic)
isolated only way to set GraphicObject to allow more actions when doing so
Definition: ndgrf.cxx:346
void SetTwipSize(const Size &rSz)
Definition: ndgrf.cxx:608
bool mbInBaseLinkSwapIn
Definition: ndgrf.hxx:43
const tools::SvRef< sfx2::SvBaseLink > & GetLink() const
Definition: ndgrf.hxx:128
GraphicObject maGrfObj
Definition: ndgrf.hxx:38
bool IsLinkedDDE() const
Definition: ndgrf.hxx:165
void SetScaleImageMap(bool b)
Definition: ndgrf.hxx:103
bool mbLinkedInputStreamReady
Definition: ndgrf.hxx:50
GraphicAttr & GetGraphicAttr(GraphicAttr &, const SwFrame *pFrame) const
Returns the with our graphic attributes filled Graphic-Attr-Structure.
Definition: ndgrf.cxx:709
bool mbInSwapIn
Definition: ndgrf.hxx:42
void UpdateLinkWithInputStream()
Definition: ndgrf.cxx:845
bool IsScaleImageMap() const
Definition: ndgrf.hxx:102
void ReleaseLink()
Definition: ndgrf.cxx:572
const GraphicObject & GetGrfObj(bool bWait=false) const
Definition: ndgrf.cxx:364
const Graphic & GetGrf(bool bWait=false) const
Definition: ndgrf.cxx:358
virtual SwContentNode * MakeCopy(SwDoc &, SwNode &, bool bNewFrames) const override
in ndcopy.cxx
Definition: ndgrf.cxx:681
virtual bool SavePersistentData() override
Communicate to graphic that node is in Undo-range.
Definition: ndgrf.cxx:502
bool mbIsStreamReadOnly
Definition: ndgrf.hxx:52
bool GetFileFilterNms(OUString *pFileNm, OUString *pFilterNm) const
Definition: ndgrf.cxx:470
void InsertLink(std::u16string_view rGrfName, const OUString &rFltName)
Definition: ndgrf.cxx:543
const GraphicObject * GetReplacementGrfObj() const
Definition: ndgrf.cxx:370
void ApplyInputStream(const css::uno::Reference< css::io::XInputStream > &xInputStream, const bool bIsStreamReadOnly)
Definition: ndgrf.cxx:829
SwGrfNode(SwNode &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:60
css::uno::Reference< css::io::XInputStream > mxInputStream
Definition: ndgrf.hxx:51
bool mbScaleImageMap
Scale image map in SetTwipSize.
Definition: ndgrf.hxx:47
virtual ~SwGrfNode() override
Definition: ndgrf.cxx:261
void TriggerAsyncRetrieveInputStream()
Definition: ndgrf.cxx:804
bool SwapIn(bool bWaitForData=false)
Loading of graphic immediately before displaying.
Definition: ndgrf.cxx:422
void TriggerGraphicArrived()
Definition: ndgrf.cxx:352
bool mbChangeTwipSize
Definition: ndgrf.hxx:45
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:115
std::unique_ptr< GraphicObject > mpReplacementGraphic
Definition: ndgrf.hxx:39
bool mbFrameInPaint
To avoid Start-/EndActions in Paint via SwapIn.
Definition: ndgrf.hxx:46
bool IsTransparent() const
Definition: ndgrf.cxx:798
virtual bool RestorePersistentData() override
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndgrf.cxx:530
tools::SvRef< sfx2::SvBaseLink > mxLink
If graphics only as link then pointer is set.
Definition: ndgrf.hxx:40
bool IsAsyncRetrieveInputStreamPossible() const
Definition: ndgrf.cxx:863
bool IsGrfToggle() const
Definition: grfatr.hxx:65
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
Definition: ndnotxt.hxx:30
SwGrfFormatColl * GetGrfColl() const
Definition: ndnotxt.hxx:57
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
Definition: ndnotxt.cxx:85
OUString GetDescription() const
Definition: ndnotxt.cxx:282
bool HasAutomaticContour() const
Definition: ndnotxt.hxx:77
OUString GetTitle() const
Definition: ndnotxt.cxx:258
const tools::PolyPolygon * HasContour() const
Definition: ndnotxt.cxx:105
void SetTitle(const OUString &rTitle)
Definition: ndnotxt.cxx:245
void SetDescription(const OUString &rDescription)
Definition: ndnotxt.cxx:270
Base class of the Writer document model elements.
Definition: node.hxx:98
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:738
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwDoc & GetDoc()
Definition: node.hxx:233
const IDocumentLinksAdministration & getIDocumentLinksAdministration() const
Provides access to the document links administration interface.
Definition: node.cxx:2145
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2143
static SwGrfNode * MakeGrfNode(SwNode &rWhere, const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic, SwGrfFormatColl *pColl, SwAttrSet const *pAutoAttr=nullptr)
in ndgrf.cxx
Definition: ndgrf.cxx:390
Degree10 GetValue() const
Definition: grfatr.hxx:109
void process(const primitive2d::Primitive2DContainer &rSource)
const primitive2d::ObjectInfoPrimitive2D * getResult() const
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
void InsertDDELink(SvBaseLink *, const OUString &rServer, std::u16string_view rTopic, std::u16string_view rItem)
void Remove(SvBaseLink const *pLink)
T * get() const
bool is() const
URL aURL
tools::Long FRound(double fVal)
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
BmpMirrorFlags
OUString aName
SvBaseLink * pLink
SVL_DLLPUBLIC bool IsDocument(const OUString &rURL)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
const sal_Unicode cTokenSeparator
SvBaseLinkObjectType
void MakeLnkName(OUString &rName, const OUString *pType, std::u16string_view rFile, std::u16string_view rLink, const OUString *pFilter)
long Long
SwNodeType
Definition: ndtyp.hxx:28
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
QPRO_FUNC_TYPE nType
static SfxItemSet & rSet
Size GetGraphicSizeTwip(const Graphic &rGraphic, vcl::RenderContext *pOutDev)
Definition: swtypes.cxx:28
tools::Long SwTwips
Definition: swtypes.hxx:51
unsigned char sal_uInt8