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 {
211 CallSwClientNotify(sw::GrfRereadAndInCacheHint());
212 }
213 else if ( bNewGrf )
214 {
215 //TODO refLink->setInputStream(getInputStream());
216 static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
217 }
218 }
220 bSetTwipSize = false;
221 }
222 }
223 else if( pGraphic && sURLLink.isEmpty() )
224 {
225 maGrfObj.SetGraphic( *pGraphic );
227 bReadGrf = true;
228 }
229 // Was the graphic already loaded?
230 else if( !bNewGrf && GraphicType::NONE != maGrfObj.GetType() )
231 return true;
232 else
233 {
234 // create new link for the graphic object
235 InsertLink( sURLLink, rFltName );
236
237 if( GetNodes().IsDocNodes() )
238 {
239 if( pGraphic )
240 {
241 maGrfObj.SetGraphic( *pGraphic );
243 bReadGrf = true;
244 // create connection without update, as we have the graphic
245 static_cast<SwBaseLink*>( mxLink.get() )->Connect();
246 }
247 else
248 {
249 Graphic aGrf;
250 aGrf.SetDefaultType();
251 maGrfObj.SetGraphic( aGrf );
253 if ( bNewGrf )
254 {
255 static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
256 }
257 }
258 }
259 }
260
261 // Bug 39281: Do not delete Size immediately - Events on ImageMaps should have
262 // something to work with when swapping
263 if( bSetTwipSize )
265
266 // create an updates for the frames
267 if( bReadGrf && bNewGrf )
268 {
269 const SwUpdateAttr aHint(0,0,0);
270 CallSwClientNotify(sw::LegacyModifyHint(&aHint, &aHint));
271 }
272
273 return bReadGrf;
274}
275
277{
278 mpReplacementGraphic.reset();
279
280 // #i73788#
281 mpThreadConsumer.reset();
282
283 SwDoc& rDoc = GetDoc();
284 if( mxLink.is() )
285 {
286 OSL_ENSURE( !mbInSwapIn, "DTOR: I am still in SwapIn" );
288 mxLink->Disconnect();
289 }
290 else
291 {
292 // #i40014# - A graphic node, which is in a linked
293 // section, whose link is another section in the document, doesn't
294 // have to remove the stream from the storage.
295 // Because it's hard to detect this case here and it would only fix
296 // one problem with shared graphic files - there are also problems,
297 // a certain graphic file is referenced by two independent graphic nodes,
298 // brush item or drawing objects, the stream isn't no longer removed here.
299 // To do this stuff correctly, a reference counting on shared streams
300 // inside one document has to be implemented.
301 }
302 //#39289# delete frames already here since the Frames' dtor needs the graphic for its StopAnimation
303 if( HasWriterListeners() )
304 DelFrames(nullptr);
306}
307
310{
311 // try to access SwFlyFrameFormat; since title/desc/name are set there, there is no
312 // use to continue if it is not yet set. If not yet set, call onGraphicChanged()
313 // when it is set.
314 SwFlyFrameFormat* pFlyFormat = dynamic_cast< SwFlyFrameFormat* >(GetFlyFormat());
315
316 if(!pFlyFormat)
317 return;
318
319 OUString aName;
320 OUString aTitle;
321 OUString aDesc;
322 auto const & rVectorGraphicDataPtr = GetGrf().getVectorGraphicData();
323
324 if (rVectorGraphicDataPtr)
325 {
326 const drawinglayer::primitive2d::Primitive2DContainer aSequence(rVectorGraphicDataPtr->getPrimitive2DSequence());
327
328 if(!aSequence.empty())
329 {
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{
369 CallSwClientNotify(sw::PreGraphicArrivedHint());
370 CallSwClientNotify(sw::PostGraphicArrivedHint());
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
473 CallSwClientNotify(sw::GraphicPieceArrivedHint());
474 }
475 }
476 else
477 {
478 bRet = true;
479 }
480 }
481 else
482 bRet = true;
483
484 if (bRet)
485 {
486 if( !mnGrfSize.Width() && !mnGrfSize.Height() )
488 }
489 mbInSwapIn = false;
490 return bRet;
491}
492
493bool SwGrfNode::GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const
494{
495 bool bRet = false;
496 if( mxLink.is() && mxLink->GetLinkManager() )
497 {
501 mxLink.get(), nullptr, pFileNm, nullptr, pFilterNm );
502 else if( sfx2::SvBaseLinkObjectType::ClientDde == nType && pFileNm && pFilterNm )
503 {
504 OUString sApp;
505 OUString sTopic;
506 OUString sItem;
508 mxLink.get(), &sApp, &sTopic, &sItem ) )
509 {
510 *pFileNm = sApp + OUStringChar(sfx2::cTokenSeparator)
511 + sTopic + OUStringChar(sfx2::cTokenSeparator)
512 + sItem;
513 *pFilterNm = "DDE";
514 bRet = true;
515 }
516 }
517 }
518 return bRet;
519}
520
526{
527 if( mxLink.is() )
528 {
529 OSL_ENSURE( !mbInSwapIn, "SavePersistentData: I am still in SwapIn" );
531 return true;
532 }
533
534 // swap in first if in storage
535 if( HasEmbeddedStreamName() && !SwapIn() )
536 return false;
537
538 // #i44367#
539 // Do not delete graphic file in storage, because the graphic file could
540 // be referenced by other graphic nodes.
541 // Because it's hard to detect this case here and it would only fix
542 // one problem with shared graphic files - there are also problems, if
543 // a certain graphic file is referenced by two independent graphic nodes,
544 // brush item or drawing objects, the stream isn't no longer removed here.
545 // To do this stuff correct, a reference counting on shared streams
546 // inside one document has to be implemented.
547 // Important note: see also fix for #i40014#
548
549 // swap out into temp file
550 return true;
551}
552
554{
555 if( mxLink.is() )
556 {
558 mxLink->SetVisible( rIDLA.IsVisibleLinks() );
560 if( getIDocumentLayoutAccess().GetCurrentLayout() )
561 mxLink->Update();
562 }
563 return true;
564}
565
566void SwGrfNode::InsertLink( std::u16string_view rGrfName, const OUString& rFltName )
567{
568 mxLink = new SwBaseLink( SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::GDIMETAFILE, this );
569
571 if( !GetNodes().IsDocNodes() )
572 return;
573
574 mxLink->SetVisible( rIDLA.IsVisibleLinks() );
575 if( rFltName == "DDE" )
576 {
577 sal_Int32 nTmp = 0;
578 const OUString sApp{ o3tl::getToken(rGrfName, 0, sfx2::cTokenSeparator, nTmp ) };
579 const std::u16string_view sTopic{ o3tl::getToken(rGrfName, 0, sfx2::cTokenSeparator, nTmp ) };
580 const std::u16string_view sItem{ rGrfName.substr( nTmp ) };
581 rIDLA.GetLinkManager().InsertDDELink( mxLink.get(), sApp, sTopic, sItem );
582 }
583 else
584 {
585 const bool bSync = rFltName == "SYNCHRON";
586 mxLink->SetSynchron( bSync );
587 mxLink->SetContentType( SotClipboardFormatId::SVXB );
588
591 (!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) );
592 }
593}
594
596{
597 if( !mxLink.is() )
598 return;
599
600 Graphic aLocalGraphic(maGrfObj.GetGraphic());
601 const bool bHasOriginalData(aLocalGraphic.IsGfxLink());
602
603 {
604 mbInSwapIn = true;
605 SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
606 pLink->SwapIn( true, true );
607 mbInSwapIn = false;
608 }
609
611 mxLink.clear();
612 aLocalGraphic.setOriginURL("");
613
614 // #i15508# added extra processing after getting rid of the link. Use whatever is
615 // known from the formerly linked graphic to get to a state as close to a directly
616 // unlinked inserted graphic as possible. Goal is to have a valid GfxLink at the
617 // ImplGraphic (see there) that holds temporary data to the original data and type
618 // information about the original data. Only when this is given will
619 // SvXMLGraphicHelper::ImplInsertGraphicURL which is used at export use that type
620 // and use the original graphic at export for the ODF, without evtl. recoding
621 // of the bitmap graphic data to something without loss (e.g. PNG) but bigger
622 if(bHasOriginalData)
623 {
624 // #i15508# if we have the original data at the Graphic, let it survive
625 // by using that Graphic again, this time at a GraphicObject without link.
626 // This happens e.g. when inserting a linked graphic and breaking the link
627 maGrfObj.SetGraphic(aLocalGraphic);
628 }
629}
630
631void SwGrfNode::SetTwipSize( const Size& rSz )
632{
633 mnGrfSize = rSz;
635 {
636 // resize Image-Map to size of the graphic
638
639 // do not re-scale Image-Map
640 SetScaleImageMap( false );
641 }
642}
643
645{
646 if( !mnGrfSize.Width() || !mnGrfSize.Height() )
647 return;
648
649 // re-scale Image-Map
650 SwFrameFormat* pFormat = GetFlyFormat();
651
652 if( !pFormat )
653 return;
654
655 SwFormatURL aURL( pFormat->GetURL() );
656 if ( !aURL.GetMap() )
657 return;
658
659 bool bScale = false;
660 Fraction aScaleX( 1, 1 );
661 Fraction aScaleY( 1, 1 );
662
663 const SwFormatFrameSize& rFrameSize = pFormat->GetFrameSize();
664 const SvxBoxItem& rBox = pFormat->GetBox();
665
666 if( !rFrameSize.GetWidthPercent() )
667 {
668 SwTwips nWidth = rFrameSize.GetWidth();
669
670 nWidth -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) +
671 rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
672
673 OSL_ENSURE( nWidth>0, "Do any 0 twip wide graphics exist!?" );
674
675 if( mnGrfSize.Width() != nWidth )
676 {
677 aScaleX = Fraction( mnGrfSize.Width(), nWidth );
678 bScale = true;
679 }
680 }
681 if( !rFrameSize.GetHeightPercent() )
682 {
683 SwTwips nHeight = rFrameSize.GetHeight();
684
685 nHeight -= rBox.CalcLineSpace(SvxBoxItemLine::TOP) +
686 rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
687
688 OSL_ENSURE( nHeight>0, "Do any 0 twip high graphics exist!?" );
689
690 if( mnGrfSize.Height() != nHeight )
691 {
692 aScaleY = Fraction( mnGrfSize.Height(), nHeight );
693 bScale = true;
694 }
695 }
696
697 if( bScale )
698 {
699 aURL.GetMap()->Scale( aScaleX, aScaleY );
700 pFormat->SetFormatAttr( aURL );
701 }
702}
703
705{
706 // copy formats into the other document
707 SwGrfFormatColl* pColl = rDoc.CopyGrfColl( *GetGrfColl() );
708
709 Graphic aTmpGrf = GetGrf();
710
711 OUString sFile, sFilter;
712 if( IsLinkedFile() )
713 sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sFile, nullptr, &sFilter );
714 else if( IsLinkedDDE() )
715 {
716 OUString sTmp1, sTmp2;
717 sfx2::LinkManager::GetDisplayNames( mxLink.get(), &sTmp1, &sTmp2, &sFilter );
718 sfx2::MakeLnkName( sFile, &sTmp1, sTmp2, sFilter );
719 sFilter = "DDE";
720 }
721
722 SwGrfNode* pGrfNd = SwNodes::MakeGrfNode( rIdx, sFile, sFilter,
723 &aTmpGrf, pColl,
724 GetpSwAttrSet() );
725 pGrfNd->SetTitle( GetTitle() );
726 pGrfNd->SetDescription( GetDescription() );
728 return pGrfNd;
729}
730
733 const SwFrame* pFrame ) const
734{
735 const SwAttrSet& rSet = GetSwAttrSet();
736
737 rGA.SetDrawMode( rSet.GetDrawModeGrf().GetValue() );
738
739 const SwMirrorGrf & rMirror = rSet.GetMirrorGrf();
740 BmpMirrorFlags nMirror = BmpMirrorFlags::NONE;
741 if( rMirror.IsGrfToggle() && pFrame && !pFrame->FindPageFrame()->OnRightPage() )
742 {
743 switch( rMirror.GetValue() )
744 {
746 nMirror = BmpMirrorFlags::Horizontal;
747 break;
749 nMirror = BmpMirrorFlags::NONE;
750 break;
752 nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
753 break;
754 default:
755 nMirror = BmpMirrorFlags::Vertical;
756 break;
757 }
758 }
759 else
760 switch( rMirror.GetValue() )
761 {
763 nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
764 break;
766 nMirror = BmpMirrorFlags::Horizontal;
767 break;
769 nMirror = BmpMirrorFlags::Vertical;
770 break;
771 default: break;
772 }
773
774 rGA.SetMirrorFlags( nMirror );
775
776 const SwCropGrf& rCrop = rSet.GetCropGrf();
777
778 tools::Long nCropLeft = rCrop.GetLeft();
779 tools::Long nCropTop = rCrop.GetTop();
780 tools::Long nCropRight = rCrop.GetRight();
781 tools::Long nCropBottom = rCrop.GetBottom();
782
783 // take mirroring of crop values into consideration
784 // while cropping a flipped image. otherwise,
785 // cropping will crop the opposite side of the image.
786 if (rGA.GetMirrorFlags() & BmpMirrorFlags::Vertical)
787 {
788 nCropTop = rCrop.GetBottom();
789 nCropBottom = rCrop.GetTop();
790 }
791
792 if (rGA.GetMirrorFlags() & BmpMirrorFlags::Horizontal)
793 {
794 nCropLeft = rCrop.GetRight();
795 nCropRight = rCrop.GetLeft();
796 }
797
798 rGA.SetCrop( convertTwipToMm100( nCropLeft ),
799 convertTwipToMm100( nCropTop ),
800 convertTwipToMm100( nCropRight ),
801 convertTwipToMm100( nCropBottom ));
802
803 const SwRotationGrf& rRotation = rSet.GetRotationGrf();
804 rGA.SetRotation( rRotation.GetValue() );
805
806 rGA.SetLuminance( rSet.GetLuminanceGrf().GetValue() );
807 rGA.SetContrast( rSet.GetContrastGrf().GetValue() );
808 rGA.SetChannelR( rSet.GetChannelRGrf().GetValue() );
809 rGA.SetChannelG( rSet.GetChannelGGrf().GetValue() );
810 rGA.SetChannelB( rSet.GetChannelBGrf().GetValue() );
811 rGA.SetGamma( rSet.GetGammaGrf().GetValue() );
812 rGA.SetInvert( rSet.GetInvertGrf().GetValue() );
813
814 const sal_uInt16 nTrans = rSet.GetTransparencyGrf().GetValue();
815 rGA.SetAlpha( 255 - static_cast<sal_uInt8>(FRound(
816 std::min( nTrans, sal_uInt16(100) ) * 2.55 )) );
817
818 return rGA;
819}
820
822{
823 return maGrfObj.IsTransparent() ||
825}
826
828{
829 if ( !IsLinkedFile() )
830 {
831 OSL_FAIL( "<SwGrfNode::TriggerAsyncLoad()> - Method is misused. Method call is only valid for graphic nodes, which refer a linked graphic file" );
832 return;
833 }
834
835 if (mpThreadConsumer != nullptr)
836 return;
837
839
840 OUString sGrfNm;
841 sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
842 OUString sReferer;
844 if (sh != nullptr && sh->HasName())
845 {
846 sReferer = sh->GetMedium()->GetName();
847 }
848 mpThreadConsumer->CreateThread( sGrfNm, sReferer );
849}
850
851
853 const css::uno::Reference<css::io::XInputStream>& xInputStream,
854 const bool bIsStreamReadOnly )
855{
856 if ( IsLinkedFile() )
857 {
858 if ( xInputStream.is() )
859 {
860 mxInputStream = xInputStream;
861 mbIsStreamReadOnly = bIsStreamReadOnly;
863 CallSwClientNotify(sw::LinkedGraphicStreamArrivedHint());
864 }
865 }
866}
867
869{
870 // do not work on link, if a <SwapIn> has been triggered.
871 if ( mbInSwapIn || !IsLinkedFile() )
872 return;
873
874 GetLink()->setStreamToLoadFrom( mxInputStream, mbIsStreamReadOnly );
875 GetLink()->Update();
877
878 // #i88291#
879 mxInputStream.clear();
880 GetLink()->clearStreamToLoadFrom();
882 mpThreadConsumer.reset();
883}
884
885// #i90395#
887{
888 bool bRet = false;
889
890 if ( IsLinkedFile() )
891 {
892 OUString sGrfNm;
893 sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
894 if ( !sGrfNm.startsWith( "vnd.sun.star.pkg:" ) )
895 {
896 bRet = true;
897 }
898 }
899
900 return bRet;
901}
902
903/* 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:1225
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:765
void DelFrames(SwRootFrame const *pLayout)
Method deletes all views of document for the node.
Definition: node.cxx:1434
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:493
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
Definition: node.cxx:1689
Definition: doc.hxx:195
SwGrfFormatColl * CopyGrfColl(const SwGrfFormatColl &rColl)
copy the graphic nodes
Definition: docfmt.cxx:1239
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:268
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:653
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: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: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: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:644
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:631
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:732
bool mbInSwapIn
Definition: ndgrf.hxx:42
void UpdateLinkWithInputStream()
Definition: ndgrf.cxx:868
bool IsScaleImageMap() const
Definition: ndgrf.hxx:106
void ReleaseLink()
Definition: ndgrf.cxx:595
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:704
virtual bool SavePersistentData() override
Communicate to graphic that node is in Undo-range.
Definition: ndgrf.cxx:525
bool mbIsStreamReadOnly
Definition: ndgrf.hxx:52
bool GetFileFilterNms(OUString *pFileNm, OUString *pFilterNm) const
Definition: ndgrf.cxx:493
void InsertLink(std::u16string_view rGrfName, const OUString &rFltName)
Definition: ndgrf.cxx:566
const GraphicObject * GetReplacementGrfObj() const
Definition: ndgrf.cxx:385
void ApplyInputStream(const css::uno::Reference< css::io::XInputStream > &xInputStream, const bool bIsStreamReadOnly)
Definition: ndgrf.cxx:852
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:827
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:821
virtual bool RestorePersistentData() override
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndgrf.cxx:553
tools::SvRef< sfx2::SvBaseLink > mxLink
If graphics only as link then pointer is set.
Definition: ndgrf.hxx:40
bool IsAsyncRetrieveInputStreamPossible() const
Definition: ndgrf.cxx:886
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:739
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:744
SwDoc & GetDoc()
Definition: node.hxx:233
const IDocumentLinksAdministration & getIDocumentLinksAdministration() const
Provides access to the document links administration interface.
Definition: node.cxx:2155
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2153
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)
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