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