LibreOffice Module sw (master) 1
paintfrm.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 <utility>
21#include <vcl/canvastools.hxx>
22#include <vcl/lazydelete.hxx>
23#include <sfx2/docfile.hxx>
24#include <sfx2/printer.hxx>
25#include <sfx2/progress.hxx>
26#include <editeng/brushitem.hxx>
27#include <editeng/prntitem.hxx>
28#include <editeng/boxitem.hxx>
29#include <editeng/shaditem.hxx>
30#include <svx/ctredlin.hxx>
31#include <svx/framelink.hxx>
32#include <drawdoc.hxx>
33#include <tgrditem.hxx>
34#include <calbck.hxx>
35#include <fmtsrnd.hxx>
36#include <fmtclds.hxx>
37#include <fmturl.hxx>
38#include <strings.hrc>
39#include <swmodule.hxx>
40#include <rootfrm.hxx>
41#include <pagefrm.hxx>
42#include <section.hxx>
43#include <sectfrm.hxx>
44#include <viewimp.hxx>
45#include <dflyobj.hxx>
46#include <flyfrm.hxx>
47#include <frmatr.hxx>
48#include <frmtool.hxx>
49#include <viewopt.hxx>
50#include <dview.hxx>
51#include <dcontact.hxx>
52#include <txtfrm.hxx>
53#include <ftnfrm.hxx>
54#include <tabfrm.hxx>
55#include <rowfrm.hxx>
56#include <cellfrm.hxx>
57#include <notxtfrm.hxx>
58#include <layact.hxx>
59#include <pagedesc.hxx>
60#include <ptqueue.hxx>
61#include <noteurl.hxx>
62#include "virtoutp.hxx"
63#include <lineinfo.hxx>
64#include <dbg_lay.hxx>
65#include <docsh.hxx>
66#include <svx/svdogrp.hxx>
67#include <sortedobjs.hxx>
69#include <bodyfrm.hxx>
70#include <hffrm.hxx>
71#include <colfrm.hxx>
73#include <swfont.hxx>
74
82
83#include <ndole.hxx>
84#include <PostItMgr.hxx>
86#include <vcl/settings.hxx>
87
89
91
92#include <bitmaps.hlst>
101#include <svx/unoapi.hxx>
102#include <svx/svdpagv.hxx>
103#include <svx/xfillit0.hxx>
107#include <sal/log.hxx>
108
109#include <memory>
110#include <vector>
111#include <algorithm>
112#include <wrtsh.hxx>
113#include <edtwin.hxx>
114#include <view.hxx>
115#include <paintfrm.hxx>
116#include <textboxhelper.hxx>
118
119#include <vcl/BitmapTools.hxx>
120#include <comphelper/lok.hxx>
122#include <vcl/GraphicLoader.hxx>
124
125#include <svl/style.hxx>
126#include <ndtxt.hxx>
127#include <unotools/configmgr.hxx>
128#include <vcl/hatch.hxx>
129
130using namespace ::editeng;
131using namespace ::com::sun::star;
132
133namespace {
134
135struct SwPaintProperties;
136
137//Class declaration; here because they are only used in this file
138enum class SubColFlags {
139 Page = 0x01, //Helplines of the page
140 Tab = 0x08, //Helplines inside tables
141 Fly = 0x10, //Helplines inside fly frames
142 Sect = 0x20, //Helplines inside sections
143};
144
145}
146
147namespace o3tl {
148 template<> struct typed_flags<SubColFlags> : is_typed_flags<SubColFlags, 0x39> {};
149}
150
151namespace {
152
153// Classes collecting the border lines and help lines
154class SwLineRect : public SwRect
155{
157 SvxBorderLineStyle m_nStyle;
158 const SwTabFrame* m_pTabFrame;
159 SubColFlags m_nSubColor; //colorize subsidiary lines
160 bool m_bPainted; //already painted?
161 sal_uInt8 m_nLock; //To distinguish the line and the hell layer.
162public:
163 SwLineRect( const SwRect &rRect, const Color *pCol, const SvxBorderLineStyle nStyle,
164 const SwTabFrame *pT , const SubColFlags nSCol );
165
166 const Color& GetColor() const { return m_aColor; }
167 SvxBorderLineStyle GetStyle() const { return m_nStyle; }
168 const SwTabFrame* GetTab() const { return m_pTabFrame; }
169 void SetPainted() { m_bPainted = true; }
170 void Lock(bool bLock)
171 {
172 if (bLock)
173 ++m_nLock;
174 else if (m_nLock)
175 --m_nLock;
176 }
177 bool IsPainted() const { return m_bPainted; }
178 bool IsLocked() const { return m_nLock != 0; }
179 SubColFlags GetSubColor() const { return m_nSubColor; }
180
181 bool MakeUnion(const SwRect& rRect, SwPaintProperties const& properties);
182};
183
184}
185
186#ifdef IOS
187static void dummy_function()
188{
189 pid_t pid = getpid();
190 (void) pid;
191}
192#endif
193
194namespace {
195
196class SwLineRects
197{
198public:
199 std::vector<SwLineRect> m_aLineRects;
200 typedef std::vector< SwLineRect >::const_iterator const_iterator;
201 typedef std::vector< SwLineRect >::iterator iterator;
202 typedef std::vector< SwLineRect >::reverse_iterator reverse_iterator;
203 typedef std::vector< SwLineRect >::size_type size_type;
204 size_t m_nLastCount; //avoid unnecessary cycles in PaintLines
205 SwLineRects()
206 : m_nLastCount(0)
207 {
208#ifdef IOS
209 // Work around what is either a compiler bug in Xcode 5.1.1,
210 // or some unknown problem in this file. If I ifdef out this
211 // call, I get a crash in SwSubsRects::PaintSubsidiary: the
212 // address of the rLi reference variable is claimed to be
213 // 0x4000000!
214 dummy_function();
215#endif
216 }
217 void AddLineRect( const SwRect& rRect, const Color *pColor, const SvxBorderLineStyle nStyle,
218 const SwTabFrame *pTab, const SubColFlags nSCol, SwPaintProperties const &properties );
219 void ConnectEdges( OutputDevice const *pOut, SwPaintProperties const &properties );
220 void PaintLines ( OutputDevice *pOut, SwPaintProperties const &properties );
221 void LockLines( bool bLock );
222
223 //Limit lines to 100
224 bool isFull() const { return m_aLineRects.size() > 100; }
225};
226
227class SwSubsRects : public SwLineRects
228{
229 void RemoveSuperfluousSubsidiaryLines( const SwLineRects &rRects, SwPaintProperties const &properties );
230public:
231 void PaintSubsidiary( OutputDevice *pOut, const SwLineRects *pRects, SwPaintProperties const &properties );
232};
233
234class BorderLines
235{
237public:
238 void AddBorderLines(drawinglayer::primitive2d::Primitive2DContainer&& rContainer);
240 {
242 lines.swap(m_Lines);
243 return lines;
244 }
245};
246
247}
248
249// Default zoom factor
250const double aEdgeScale = 0.5;
251
252//To optimize the expensive RetouchColor determination
254
255namespace sw
256{
258{
259 return &aGlobalRetoucheColor;
260}
261}
262
263namespace {
264
268struct SwPaintProperties {
269 // Only repaint the Fly content as well as the background of the Fly content if
270 // a metafile is taken of the Fly.
271 bool bSFlyMetafile;
272 VclPtr<OutputDevice> pSFlyMetafileOut;
273 SwViewShell *pSGlobalShell;
274
275 // Retouch for transparent Flys is done by the background of the Flys.
276 // The Fly itself should certainly not be spared out. See PaintSwFrameBackground and
277 // lcl_SubtractFlys()
278 SwFlyFrame *pSRetoucheFly;
279 SwFlyFrame *pSRetoucheFly2;
280 SwFlyFrame *pSFlyOnlyDraw;
281
282 // The borders will be collected in pSLines during the Paint and later
283 // possibly merge them.
284 // The help lines will be collected and merged in gProp.pSSubsLines. These will
285 // be compared with pSLines before the work in order to avoid help lines
286 // to hide borders.
287 std::unique_ptr<BorderLines> pBLines;
288 std::unique_ptr<SwLineRects> pSLines;
289 std::unique_ptr<SwSubsRects> pSSubsLines;
290
291 // global variable for sub-lines of body, header, footer, section and footnote frames.
292 std::unique_ptr<SwSubsRects> pSSpecSubsLines;
293 SfxProgress *pSProgress;
294
295 // Sizes of a pixel and the corresponding halves. Will be reset when
296 // entering SwRootFrame::PaintSwFrame
297 tools::Long nSPixelSzW;
298 tools::Long nSPixelSzH;
299 tools::Long nSHalfPixelSzW;
300 tools::Long nSHalfPixelSzH;
301 tools::Long nSMinDistPixelW;
302 tools::Long nSMinDistPixelH;
303
304 Color aSGlobalRetoucheColor;
305
306 // Current zoom factor
307 double aSScaleX;
308 double aSScaleY;
309
310 SwPaintProperties()
311 : bSFlyMetafile(false)
312 , pSFlyMetafileOut(nullptr)
313 , pSGlobalShell(nullptr)
314 , pSRetoucheFly(nullptr)
315 , pSRetoucheFly2(nullptr)
316 , pSFlyOnlyDraw(nullptr)
317 , pSProgress(nullptr)
318 , nSPixelSzW(0)
319 , nSPixelSzH(0)
320 , nSHalfPixelSzW(0)
321 , nSHalfPixelSzH(0)
322 , nSMinDistPixelW(0)
323 , nSMinDistPixelH(0)
324 , aSScaleX(1)
325 , aSScaleY(1)
326 {
327 }
328
329};
330
331}
332
333static SwPaintProperties gProp;
334
336{
337 return !gProp.pSGlobalShell->GetViewOptions()->IsPagePreview() &&
338 !gProp.pSGlobalShell->GetViewOptions()->IsReadonly() &&
339 !gProp.pSGlobalShell->GetViewOptions()->IsFormView() &&
340 gProp.pSGlobalShell->GetViewOptions()->IsObjectBoundaries();
341}
342//other subsidiary lines enabled?
344{
345 return !gProp.pSGlobalShell->GetViewOptions()->IsPagePreview() &&
346 !gProp.pSGlobalShell->GetViewOptions()->IsReadonly() &&
347 !gProp.pSGlobalShell->GetViewOptions()->IsFormView() &&
348 !gProp.pSGlobalShell->GetViewOptions()->IsWhitespaceHidden() &&
349 gProp.pSGlobalShell->GetViewOptions()->IsDocBoundaries();
350}
351//subsidiary lines for sections
353{
354 return !gProp.pSGlobalShell->GetViewOptions()->IsPagePreview() &&
355 !gProp.pSGlobalShell->GetViewOptions()->IsReadonly() &&
356 !gProp.pSGlobalShell->GetViewOptions()->IsFormView() &&
357 gProp.pSGlobalShell->GetViewOptions()->IsSectionBoundaries();
358}
359
360
361namespace {
362
363bool isTableBoundariesEnabled()
364{
365 if (!gProp.pSGlobalShell->GetViewOptions()->IsTable())
366 return false;
367
368 if (gProp.pSGlobalShell->GetViewOptions()->IsPagePreview())
369 return false;
370
371 if (gProp.pSGlobalShell->GetViewOptions()->IsReadonly())
372 return false;
373
374 if (gProp.pSGlobalShell->GetViewOptions()->IsFormView())
375 return false;
376
377 return gProp.pSGlobalShell->GetViewOptions()->IsTableBoundaries();
378}
379
380}
381
389{
390 // determine 'small' twip-to-pixel relation
391 bool bSmallTwipToPxRelW = false;
392 bool bSmallTwipToPxRelH = false;
393 {
394 Size aCheckTwipToPxRelSz( pOut->PixelToLogic( Size( 100, 100 )) );
395 if ( (aCheckTwipToPxRelSz.Width()/100.0) < 2.0 )
396 {
397 bSmallTwipToPxRelW = true;
398 }
399 if ( (aCheckTwipToPxRelSz.Height()/100.0) < 2.0 )
400 {
401 bSmallTwipToPxRelH = true;
402 }
403 }
404
405 Size aSz( pOut->PixelToLogic( Size( 1,1 )) );
406
407 gProp.nSPixelSzW = aSz.Width();
408 if( !gProp.nSPixelSzW )
409 gProp.nSPixelSzW = 1;
410 gProp.nSPixelSzH = aSz.Height();
411 if( !gProp.nSPixelSzH )
412 gProp.nSPixelSzH = 1;
413
414 // consider 'small' twip-to-pixel relations
415 if ( !bSmallTwipToPxRelW )
416 {
417 gProp.nSHalfPixelSzW = gProp.nSPixelSzW / 2 + 1;
418 }
419 else
420 {
421 gProp.nSHalfPixelSzW = 0;
422 }
423 // consider 'small' twip-to-pixel relations
424 if ( !bSmallTwipToPxRelH )
425 {
426 gProp.nSHalfPixelSzH = gProp.nSPixelSzH / 2 + 1;
427 }
428 else
429 {
430 gProp.nSHalfPixelSzH = 0;
431 }
432
433 gProp.nSMinDistPixelW = gProp.nSPixelSzW * 2 + 1;
434 gProp.nSMinDistPixelH = gProp.nSPixelSzH * 2 + 1;
435
436 const MapMode &rMap = pOut->GetMapMode();
437 gProp.aSScaleX = double(rMap.GetScaleX());
438 gProp.aSScaleY = double(rMap.GetScaleY());
439}
440
441namespace {
442
446class SwSavePaintStatics : public SwPaintProperties
447{
448public:
449 SwSavePaintStatics();
450 ~SwSavePaintStatics();
451};
452
453}
454
455SwSavePaintStatics::SwSavePaintStatics()
456{
457 // Saving globales
458 bSFlyMetafile = gProp.bSFlyMetafile;
459 pSGlobalShell = gProp.pSGlobalShell;
460 pSFlyMetafileOut = gProp.pSFlyMetafileOut;
461 pSRetoucheFly = gProp.pSRetoucheFly;
462 pSRetoucheFly2 = gProp.pSRetoucheFly2;
463 pSFlyOnlyDraw = gProp.pSFlyOnlyDraw;
464 pBLines = std::move(gProp.pBLines);
465 pSLines = std::move(gProp.pSLines);
466 pSSubsLines = std::move(gProp.pSSubsLines);
467 pSSpecSubsLines = std::move(gProp.pSSpecSubsLines);
468 pSProgress = gProp.pSProgress;
469 nSPixelSzW = gProp.nSPixelSzW;
470 nSPixelSzH = gProp.nSPixelSzH;
471 nSHalfPixelSzW = gProp.nSHalfPixelSzW;
472 nSHalfPixelSzH = gProp.nSHalfPixelSzH;
473 nSMinDistPixelW = gProp.nSMinDistPixelW;
474 nSMinDistPixelH = gProp.nSMinDistPixelH ;
475 aSGlobalRetoucheColor = aGlobalRetoucheColor;
476 aSScaleX = gProp.aSScaleX;
477 aSScaleY = gProp.aSScaleY;
478
479 // Restoring globales to default
480 gProp.bSFlyMetafile = false;
481 gProp.pSFlyMetafileOut = nullptr;
482 gProp.pSRetoucheFly = nullptr;
483 gProp.pSRetoucheFly2 = nullptr;
484 gProp.nSPixelSzW = gProp.nSPixelSzH =
485 gProp.nSHalfPixelSzW = gProp.nSHalfPixelSzH =
486 gProp.nSMinDistPixelW = gProp.nSMinDistPixelH = 0;
487 gProp.aSScaleX = gProp.aSScaleY = 1.0;
488 gProp.pSProgress = nullptr;
489}
490
491SwSavePaintStatics::~SwSavePaintStatics()
492{
493 // Restoring globales to saved one
494 gProp.pSGlobalShell = pSGlobalShell;
495 gProp.bSFlyMetafile = bSFlyMetafile;
496 gProp.pSFlyMetafileOut = pSFlyMetafileOut;
497 gProp.pSRetoucheFly = pSRetoucheFly;
498 gProp.pSRetoucheFly2 = pSRetoucheFly2;
499 gProp.pSFlyOnlyDraw = pSFlyOnlyDraw;
500 gProp.pBLines = std::move(pBLines);
501 gProp.pSLines = std::move(pSLines);
502 gProp.pSSubsLines = std::move(pSSubsLines);
503 gProp.pSSpecSubsLines = std::move(pSSpecSubsLines);
504 gProp.pSProgress = pSProgress;
505 gProp.nSPixelSzW = nSPixelSzW;
506 gProp.nSPixelSzH = nSPixelSzH;
507 gProp.nSHalfPixelSzW = nSHalfPixelSzW;
508 gProp.nSHalfPixelSzH = nSHalfPixelSzH;
509 gProp.nSMinDistPixelW = nSMinDistPixelW;
510 gProp.nSMinDistPixelH = nSMinDistPixelH;
511 aGlobalRetoucheColor = aSGlobalRetoucheColor;
512 gProp.aSScaleX = aSScaleX;
513 gProp.aSScaleY = aSScaleY;
514}
515
516void BorderLines::AddBorderLines(drawinglayer::primitive2d::Primitive2DContainer&& rContainer)
517{
518 if(!rContainer.empty())
519 {
520 m_Lines.append(std::move(rContainer));
521 }
522}
523
524SwLineRect::SwLineRect(const SwRect& rRect, const Color* pCol, const SvxBorderLineStyle nStyl,
525 const SwTabFrame* pT, const SubColFlags nSCol)
526 : SwRect(rRect)
527 , m_nStyle(nStyl)
528 , m_pTabFrame(pT)
529 , m_nSubColor(nSCol)
530 , m_bPainted(false)
531 , m_nLock(0)
532{
533 if ( pCol != nullptr )
534 m_aColor = *pCol;
535}
536
537bool SwLineRect::MakeUnion( const SwRect &rRect, SwPaintProperties const & properties)
538{
539 // It has already been tested outside, whether the rectangles have
540 // the same orientation (horizontal or vertical), color, etc.
541 if ( Height() > Width() ) //Vertical line
542 {
543 if ( Left() == rRect.Left() && Width() == rRect.Width() )
544 {
545 // Merge when there is no gap between the lines
546 const tools::Long nAdd = properties.nSPixelSzW + properties.nSHalfPixelSzW;
547 if ( Bottom() + nAdd >= rRect.Top() &&
548 Top() - nAdd <= rRect.Bottom() )
549 {
550 Bottom( std::max( Bottom(), rRect.Bottom() ) );
551 Top ( std::min( Top(), rRect.Top() ) );
552 return true;
553 }
554 }
555 }
556 else
557 {
558 if ( Top() == rRect.Top() && Height() == rRect.Height() )
559 {
560 // Merge when there is no gap between the lines
561 const tools::Long nAdd = properties.nSPixelSzW + properties.nSHalfPixelSzW;
562 if ( Right() + nAdd >= rRect.Left() &&
563 Left() - nAdd <= rRect.Right() )
564 {
565 Right( std::max( Right(), rRect.Right() ) );
566 Left ( std::min( Left(), rRect.Left() ) );
567 return true;
568 }
569 }
570 }
571 return false;
572}
573
574void SwLineRects::AddLineRect( const SwRect &rRect, const Color *pCol, const SvxBorderLineStyle nStyle,
575 const SwTabFrame *pTab, const SubColFlags nSCol, SwPaintProperties const & properties )
576{
577 // Loop backwards because lines which can be combined, can usually be painted
578 // in the same context
579 for (reverse_iterator it = m_aLineRects.rbegin(); it != m_aLineRects.rend(); ++it)
580 {
581 SwLineRect &rLRect = *it;
582 // Test for the orientation, color, table
583 if ( rLRect.GetTab() == pTab &&
584 !rLRect.IsPainted() && rLRect.GetSubColor() == nSCol &&
585 (rLRect.Height() > rLRect.Width()) == (rRect.Height() > rRect.Width()) &&
586 (pCol && rLRect.GetColor() == *pCol) )
587 {
588 if ( rLRect.MakeUnion( rRect, properties ) )
589 return;
590 }
591 }
592 m_aLineRects.emplace_back(rRect, pCol, nStyle, pTab, nSCol);
593}
594
595void SwLineRects::ConnectEdges( OutputDevice const *pOut, SwPaintProperties const & properties )
596{
597 if ( pOut->GetOutDevType() != OUTDEV_PRINTER )
598 {
599 // I'm not doing anything for a too small zoom
600 if ( properties.aSScaleX < aEdgeScale || properties.aSScaleY < aEdgeScale )
601 return;
602 }
603
604 static const tools::Long nAdd = 20;
605
606 std::vector<SwLineRect*> aCheck;
607
608 for (size_t i = 0; i < m_aLineRects.size(); ++i)
609 {
610 SwLineRect& rL1 = m_aLineRects[i];
611 if ( !rL1.GetTab() || rL1.IsPainted() || rL1.IsLocked() )
612 continue;
613
614 aCheck.clear();
615
616 const bool bVert = rL1.Height() > rL1.Width();
617 tools::Long nL1a, nL1b, nL1c, nL1d;
618
619 if ( bVert )
620 {
621 nL1a = rL1.Top(); nL1b = rL1.Left();
622 nL1c = rL1.Right(); nL1d = rL1.Bottom();
623 }
624 else
625 {
626 nL1a = rL1.Left(); nL1b = rL1.Top();
627 nL1c = rL1.Bottom(); nL1d = rL1.Right();
628 }
629
630 // Collect all lines to possibly link with i1
631 for (iterator it2 = m_aLineRects.begin(); it2 != m_aLineRects.end(); ++it2)
632 {
633 SwLineRect &rL2 = *it2;
634 if ( rL2.GetTab() != rL1.GetTab() ||
635 rL2.IsPainted() ||
636 rL2.IsLocked() ||
637 (bVert == (rL2.Height() > rL2.Width())) )
638 continue;
639
640 tools::Long nL2a, nL2b, nL2c, nL2d;
641 if ( bVert )
642 {
643 nL2a = rL2.Top(); nL2b = rL2.Left();
644 nL2c = rL2.Right(); nL2d = rL2.Bottom();
645 }
646 else
647 {
648 nL2a = rL2.Left(); nL2b = rL2.Top();
649 nL2c = rL2.Bottom(); nL2d = rL2.Right();
650 }
651
652 if ( (nL1a - nAdd < nL2d && nL1d + nAdd > nL2a) &&
653 ((nL1b > nL2b && nL1c < nL2c) ||
654 (nL1c >= nL2c && nL1b - nAdd < nL2c) ||
655 (nL1b <= nL2b && nL1c + nAdd > nL2b)) )
656 {
657 aCheck.push_back( &rL2 );
658 }
659 }
660 if ( aCheck.size() < 2 )
661 continue;
662
663 bool bRemove = false;
664
665 // For each line test all following ones.
666 for ( size_t k = 0; !bRemove && k < aCheck.size(); ++k )
667 {
668 SwLineRect &rR1 = *aCheck[k];
669
670 for ( size_t k2 = k+1; !bRemove && k2 < aCheck.size(); ++k2 )
671 {
672 SwLineRect &rR2 = *aCheck[k2];
673 if ( bVert )
674 {
675 SwLineRect *pLA = nullptr;
676 SwLineRect *pLB = nullptr;
677 if ( rR1.Top() < rR2.Top() )
678 {
679 pLA = &rR1; pLB = &rR2;
680 }
681 else if ( rR1.Top() > rR2.Top() )
682 {
683 pLA = &rR2; pLB = &rR1;
684 }
685 // are k1 and k2 describing a double line?
686 if ( pLA && pLA->Bottom() + 60 > pLB->Top() )
687 {
688 if ( rL1.Top() < pLA->Top() )
689 {
690 if ( rL1.Bottom() == pLA->Bottom() )
691 continue; //Small mistake (where?)
692
693 SwRect aIns( rL1 );
694 aIns.Bottom( pLA->Bottom() );
695 if ( !rL1.Contains( aIns ) )
696 continue;
697 m_aLineRects.emplace_back(aIns, &rL1.GetColor(),
698 SvxBorderLineStyle::SOLID, rL1.GetTab(),
699 SubColFlags::Tab);
700 if ( isFull() )
701 {
702 --i;
703 k = aCheck.size();
704 break;
705 }
706 }
707
708 if ( rL1.Bottom() > pLB->Bottom() )
709 rL1.Top( pLB->Top() ); // extend i1 on the top
710 else
711 bRemove = true; //stopping, remove i1
712 }
713 }
714 else
715 {
716 SwLineRect *pLA = nullptr;
717 SwLineRect *pLB = nullptr;
718 if ( rR1.Left() < rR2.Left() )
719 {
720 pLA = &rR1; pLB = &rR2;
721 }
722 else if ( rR1.Left() > rR2.Left() )
723 {
724 pLA = &rR2; pLB = &rR1;
725 }
726 // Is it double line?
727 if ( pLA && pLA->Right() + 60 > pLB->Left() )
728 {
729 if ( rL1.Left() < pLA->Left() )
730 {
731 if ( rL1.Right() == pLA->Right() )
732 continue; //small error
733
734 SwRect aIns( rL1 );
735 aIns.Right( pLA->Right() );
736 if ( !rL1.Contains( aIns ) )
737 continue;
738 m_aLineRects.emplace_back(aIns, &rL1.GetColor(),
739 SvxBorderLineStyle::SOLID, rL1.GetTab(),
740 SubColFlags::Tab);
741 if ( isFull() )
742 {
743 --i;
744 k = aCheck.size();
745 break;
746 }
747 }
748 if ( rL1.Right() > pLB->Right() )
749 rL1.Left( pLB->Left() );
750 else
751 bRemove = true;
752 }
753 }
754 }
755 }
756 if ( bRemove )
757 {
758 m_aLineRects.erase(m_aLineRects.begin() + i);
759 --i;
760 }
761 }
762}
763
764void SwSubsRects::RemoveSuperfluousSubsidiaryLines( const SwLineRects &rRects, SwPaintProperties const & properties )
765{
766 // All help lines that are covered by any border will be removed or split
767 for (size_t i = 0; i < m_aLineRects.size(); ++i)
768 {
769 // get a copy instead of a reference, because an <insert> may destroy
770 // the object due to a necessary array resize.
771 const SwLineRect aSubsLineRect(m_aLineRects[i]);
772
773 // add condition <aSubsLineRect.IsLocked()> in order to consider only
774 // border lines, which are *not* locked.
775 if ( aSubsLineRect.IsPainted() ||
776 aSubsLineRect.IsLocked() )
777 continue;
778
779 const bool bVerticalSubs = aSubsLineRect.Height() > aSubsLineRect.Width();
780 SwRect aSubsRect( aSubsLineRect );
781 if ( bVerticalSubs )
782 {
783 aSubsRect.AddLeft ( - (properties.nSPixelSzW+properties.nSHalfPixelSzW) );
784 aSubsRect.AddRight ( properties.nSPixelSzW+properties.nSHalfPixelSzW );
785 }
786 else
787 {
788 aSubsRect.AddTop ( - (properties.nSPixelSzH+properties.nSHalfPixelSzH) );
789 aSubsRect.AddBottom( properties.nSPixelSzH+properties.nSHalfPixelSzH );
790 }
791 for (const_iterator itK = rRects.m_aLineRects.begin(); itK != rRects.m_aLineRects.end();
792 ++itK)
793 {
794 const SwLineRect &rLine = *itK;
795
796 // do *not* consider painted or locked border lines.
797 // #i1837# - locked border lines have to be considered.
798 if ( rLine.IsLocked () )
799 continue;
800
801 if ( !bVerticalSubs == ( rLine.Height() > rLine.Width() ) ) //same direction?
802 continue;
803
804 if ( aSubsRect.Overlaps( rLine ) )
805 {
806 if ( bVerticalSubs ) // Vertical?
807 {
808 if ( aSubsRect.Left() <= rLine.Right() &&
809 aSubsRect.Right() >= rLine.Left() )
810 {
811 tools::Long nTmp = rLine.Top()-(properties.nSPixelSzH+1);
812 if ( aSubsLineRect.Top() < nTmp )
813 {
814 SwRect aNewSubsRect( aSubsLineRect );
815 aNewSubsRect.Bottom( nTmp );
816 m_aLineRects.emplace_back(aNewSubsRect, nullptr,
817 aSubsLineRect.GetStyle(), nullptr,
818 aSubsLineRect.GetSubColor());
819 }
820 nTmp = rLine.Bottom()+properties.nSPixelSzH+1;
821 if ( aSubsLineRect.Bottom() > nTmp )
822 {
823 SwRect aNewSubsRect( aSubsLineRect );
824 aNewSubsRect.Top( nTmp );
825 m_aLineRects.emplace_back(aNewSubsRect, nullptr,
826 aSubsLineRect.GetStyle(), nullptr,
827 aSubsLineRect.GetSubColor());
828 }
829 m_aLineRects.erase(m_aLineRects.begin() + i);
830 --i;
831 break;
832 }
833 }
834 else // Horizontal
835 {
836 if ( aSubsRect.Top() <= rLine.Bottom() &&
837 aSubsRect.Bottom() >= rLine.Top() )
838 {
839 tools::Long nTmp = rLine.Left()-(properties.nSPixelSzW+1);
840 if ( aSubsLineRect.Left() < nTmp )
841 {
842 SwRect aNewSubsRect( aSubsLineRect );
843 aNewSubsRect.Right( nTmp );
844 m_aLineRects.emplace_back(aNewSubsRect, nullptr,
845 aSubsLineRect.GetStyle(), nullptr,
846 aSubsLineRect.GetSubColor());
847 }
848 nTmp = rLine.Right()+properties.nSPixelSzW+1;
849 if ( aSubsLineRect.Right() > nTmp )
850 {
851 SwRect aNewSubsRect( aSubsLineRect );
852 aNewSubsRect.Left( nTmp );
853 m_aLineRects.emplace_back(aNewSubsRect, nullptr,
854 aSubsLineRect.GetStyle(), nullptr,
855 aSubsLineRect.GetSubColor());
856 }
857 m_aLineRects.erase(m_aLineRects.begin() + i);
858 --i;
859 break;
860 }
861 }
862 }
863 }
864 }
865}
866
867void SwLineRects::LockLines( bool bLock )
868{
869 for (SwLineRect& rLRect : m_aLineRects)
870 rLRect.Lock(bLock);
871}
872
873static void lcl_DrawDashedRect( OutputDevice * pOut, SwLineRect const & rLRect )
874{
875 tools::Long startX = rLRect.Left( ), endX;
876 tools::Long startY = rLRect.Top( ), endY;
877
878 // Discriminate vertically stretched rect from horizontally stretched
879 // and restrict minimum nHalfLWidth to 1
880 tools::Long nHalfLWidth = std::max( std::min( rLRect.Width( ), rLRect.Height( ) ) / 2, tools::Long(1) );
881
882 if ( rLRect.Height( ) > rLRect.Width( ) )
883 {
884 startX += nHalfLWidth;
885 endX = startX;
886 endY = startY + rLRect.Height( );
887 }
888 else
889 {
890 startY += nHalfLWidth;
891 endY = startY;
892 endX = startX + rLRect.Width( );
893 }
894
895 svtools::DrawLine( *pOut, Point( startX, startY ), Point( endX, endY ),
896 sal_uInt32( nHalfLWidth * 2 ), rLRect.GetStyle( ) );
897}
898
899void SwLineRects::PaintLines( OutputDevice *pOut, SwPaintProperties const &properties )
900{
901 // Paint the borders. Sadly two passes are needed.
902 // Once for the inside and once for the outside edges of tables
903 if (m_aLineRects.size() == m_nLastCount)
904 return;
905
906 // #i16816# tagged pdf support
907 SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, *pOut );
908
910 pOut->SetFillColor();
911 pOut->SetLineColor();
912 ConnectEdges( pOut, properties );
913 const Color *pLast = nullptr;
914
915 bool bPaint2nd = false;
916 size_t nMinCount = m_aLineRects.size();
917
918 for (size_t i = 0; i < m_aLineRects.size(); ++i)
919 {
920 SwLineRect& rLRect = m_aLineRects[i];
921
922 if ( rLRect.IsPainted() )
923 continue;
924
925 if ( rLRect.IsLocked() )
926 {
927 nMinCount = std::min( nMinCount, i );
928 continue;
929 }
930
931 // Paint it now or in the second pass?
932 bool bPaint = true;
933 if ( rLRect.GetTab() )
934 {
935 if ( rLRect.Height() > rLRect.Width() )
936 {
937 // Vertical edge, overlapping with the table edge?
938 SwTwips nLLeft = rLRect.Left() - 30,
939 nLRight = rLRect.Right() + 30,
940 nTLeft = rLRect.GetTab()->getFrameArea().Left() + rLRect.GetTab()->getFramePrintArea().Left(),
941 nTRight = rLRect.GetTab()->getFrameArea().Left() + rLRect.GetTab()->getFramePrintArea().Right();
942 if ( (nTLeft >= nLLeft && nTLeft <= nLRight) ||
943 (nTRight>= nLLeft && nTRight<= nLRight) )
944 bPaint = false;
945 }
946 else
947 {
948 // Horizontal edge, overlapping with the table edge?
949 SwTwips nLTop = rLRect.Top() - 30,
950 nLBottom = rLRect.Bottom() + 30,
951 nTTop = rLRect.GetTab()->getFrameArea().Top() + rLRect.GetTab()->getFramePrintArea().Top(),
952 nTBottom = rLRect.GetTab()->getFrameArea().Top() + rLRect.GetTab()->getFramePrintArea().Bottom();
953 if ( (nTTop >= nLTop && nTTop <= nLBottom) ||
954 (nTBottom >= nLTop && nTBottom <= nLBottom) )
955 bPaint = false;
956 }
957 }
958 if ( bPaint )
959 {
960 if ( !pLast || *pLast != rLRect.GetColor() )
961 {
962 pLast = &rLRect.GetColor();
963
964 DrawModeFlags nOldDrawMode = pOut->GetDrawMode();
965 if( properties.pSGlobalShell->GetWin() &&
967 pOut->SetDrawMode( DrawModeFlags::Default );
968
969 pOut->SetLineColor( *pLast );
970 pOut->SetFillColor( *pLast );
971 pOut->SetDrawMode( nOldDrawMode );
972 }
973
974 if( !rLRect.IsEmpty() )
975 lcl_DrawDashedRect( pOut, rLRect );
976 rLRect.SetPainted();
977 }
978 else
979 bPaint2nd = true;
980 }
981 if ( bPaint2nd )
982 {
983 for (size_t i = 0; i < m_aLineRects.size(); ++i)
984 {
985 SwLineRect& rLRect = m_aLineRects[i];
986 if ( rLRect.IsPainted() )
987 continue;
988
989 if ( rLRect.IsLocked() )
990 {
991 nMinCount = std::min( nMinCount, i );
992 continue;
993 }
994
995 if ( !pLast || *pLast != rLRect.GetColor() )
996 {
997 pLast = &rLRect.GetColor();
998
999 DrawModeFlags nOldDrawMode = pOut->GetDrawMode();
1000 if( properties.pSGlobalShell->GetWin() &&
1002 {
1003 pOut->SetDrawMode( DrawModeFlags::Default );
1004 }
1005
1006 pOut->SetFillColor( *pLast );
1007 pOut->SetDrawMode( nOldDrawMode );
1008 }
1009 if( !rLRect.IsEmpty() )
1010 lcl_DrawDashedRect( pOut, rLRect );
1011 rLRect.SetPainted();
1012 }
1013 }
1014 m_nLastCount = nMinCount;
1015 pOut->Pop();
1016
1017}
1018
1019void SwSubsRects::PaintSubsidiary( OutputDevice *pOut,
1020 const SwLineRects *pRects,
1021 SwPaintProperties const & properties )
1022{
1023 if (m_aLineRects.empty())
1024 return;
1025
1026 // #i16816# tagged pdf support
1027 SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, *pOut );
1028
1029 // Remove all help line that are almost covered (tables)
1030 for (size_type i = 0; i != m_aLineRects.size(); ++i)
1031 {
1032 SwLineRect& rLi = m_aLineRects[i];
1033 const bool bVerticalSubs = rLi.Height() > rLi.Width();
1034
1035 for (size_type k = i + 1; k != m_aLineRects.size(); ++k)
1036 {
1037 SwLineRect& rLk = m_aLineRects[k];
1038 if ( rLi.SSize() == rLk.SSize() )
1039 {
1040 if ( bVerticalSubs == ( rLk.Height() > rLk.Width() ) )
1041 {
1042 if ( bVerticalSubs )
1043 {
1044 tools::Long nLi = rLi.Right();
1045 tools::Long nLk = rLk.Right();
1046 if ( rLi.Top() == rLk.Top() &&
1047 ((nLi < rLk.Left() && nLi+21 > rLk.Left()) ||
1048 (nLk < rLi.Left() && nLk+21 > rLi.Left())))
1049 {
1050 m_aLineRects.erase(m_aLineRects.begin() + i);
1051 // don't continue with inner loop any more:
1052 // the array may shrink!
1053 --i;
1054 break;
1055 }
1056 }
1057 else
1058 {
1059 tools::Long nLi = rLi.Bottom();
1060 tools::Long nLk = rLk.Bottom();
1061 if ( rLi.Left() == rLk.Left() &&
1062 ((nLi < rLk.Top() && nLi+21 > rLk.Top()) ||
1063 (nLk < rLi.Top() && nLk+21 > rLi.Top())))
1064 {
1065 m_aLineRects.erase(m_aLineRects.begin() + i);
1066 // don't continue with inner loop any more:
1067 // the array may shrink!
1068 --i;
1069 break;
1070 }
1071 }
1072 }
1073 }
1074 }
1075 }
1076
1077 if (pRects && (!pRects->m_aLineRects.empty()))
1078 RemoveSuperfluousSubsidiaryLines( *pRects, properties );
1079
1080 if (m_aLineRects.empty())
1081 return;
1082
1084 pOut->SetLineColor();
1085
1086 // Reset draw mode in high contrast mode in order to get fill color
1087 // set at output device. Recover draw mode after draw of lines.
1088 // Necessary for the subsidiary lines painted by the fly frames.
1089 DrawModeFlags nOldDrawMode = pOut->GetDrawMode();
1090 if( gProp.pSGlobalShell->GetWin() &&
1092 {
1093 pOut->SetDrawMode( DrawModeFlags::Default );
1094 }
1095
1096 for (SwLineRect& rLRect : m_aLineRects)
1097 {
1098 // Add condition <!rLRect.IsLocked()> to prevent paint of locked subsidiary lines.
1099 if ( !rLRect.IsPainted() &&
1100 !rLRect.IsLocked() )
1101 {
1102 const Color *pCol = nullptr;
1103 SwViewShell *pShell = properties.pSGlobalShell;
1104 const SwViewOption *pOpt = pShell->GetViewOptions();
1105 switch ( rLRect.GetSubColor() )
1106 {
1107 case SubColFlags::Page: pCol = &pOpt->GetDocBoundariesColor(); break;
1108 case SubColFlags::Fly: pCol = &pOpt->GetObjectBoundariesColor(); break;
1109 case SubColFlags::Tab: pCol = &pOpt->GetTableBoundariesColor(); break;
1110 case SubColFlags::Sect: pCol = &pOpt->GetSectionBoundColor(); break;
1111 }
1112
1113 if (pCol && pOut->GetFillColor() != *pCol)
1114 pOut->SetFillColor( *pCol );
1115 pOut->DrawRect( rLRect.SVRect() );
1116
1117 rLRect.SetPainted();
1118 }
1119 }
1120
1121 pOut->SetDrawMode( nOldDrawMode );
1122
1123 pOut->Pop();
1124}
1125
1126// Various functions that are use in this file.
1127
1135void SwAlignRect( SwRect &rRect, const SwViewShell *pSh, const vcl::RenderContext* pRenderContext )
1136{
1137 if( !rRect.HasArea() )
1138 return;
1139
1140 // Make sure that view shell (parameter <pSh>) exists, if the output device
1141 // is taken from this view shell --> no output device, no alignment
1142 // Output device taken from view shell <pSh>, if <gProp.bSFlyMetafile> not set
1143 if ( !gProp.bSFlyMetafile && !pSh )
1144 {
1145 return;
1146 }
1147
1148 const vcl::RenderContext *pOut = gProp.bSFlyMetafile ?
1149 gProp.pSFlyMetafileOut.get() : pRenderContext;
1150
1151 // Hold original rectangle in pixel
1152 const tools::Rectangle aOrgPxRect = pOut->LogicToPixel( rRect.SVRect() );
1153 // Determine pixel-center rectangle in twip
1154 const SwRect aPxCenterRect( pOut->PixelToLogic( aOrgPxRect ) );
1155
1156 // Perform adjustments on pixel level.
1157 SwRect aAlignedPxRect( aOrgPxRect );
1158 if ( rRect.Top() > aPxCenterRect.Top() )
1159 {
1160 // 'leave pixel overlapping on top'
1161 aAlignedPxRect.AddTop( 1 );
1162 }
1163
1164 if ( rRect.Bottom() < aPxCenterRect.Bottom() )
1165 {
1166 // 'leave pixel overlapping on bottom'
1167 aAlignedPxRect.AddBottom( - 1 );
1168 }
1169
1170 if ( rRect.Left() > aPxCenterRect.Left() )
1171 {
1172 // 'leave pixel overlapping on left'
1173 aAlignedPxRect.AddLeft( 1 );
1174 }
1175
1176 if ( rRect.Right() < aPxCenterRect.Right() )
1177 {
1178 // 'leave pixel overlapping on right'
1179 aAlignedPxRect.AddRight( - 1 );
1180 }
1181
1182 // Consider negative width/height check, if aligned SwRect has negative width/height.
1183 // If Yes, adjust it to width/height = 0 twip.
1184 // NOTE: A SwRect with negative width/height can occur, if the width/height
1185 // of the given SwRect in twip was less than a pixel in twip and that
1186 // the alignment calculates that the aligned SwRect should not contain
1187 // the pixels the width/height is on.
1188 if ( aAlignedPxRect.Width() < 0 )
1189 {
1190 aAlignedPxRect.Width(0);
1191 }
1192 if ( aAlignedPxRect.Height() < 0 )
1193 {
1194 aAlignedPxRect.Height(0);
1195 }
1196 // Consider zero width/height for converting a rectangle from
1197 // pixel to logic it needs a width/height. Thus, set width/height
1198 // to one, if it's zero and correct this on the twip level after the conversion.
1199 bool bZeroWidth = false;
1200 if ( aAlignedPxRect.Width() == 0 )
1201 {
1202 aAlignedPxRect.Width(1);
1203 bZeroWidth = true;
1204 }
1205 bool bZeroHeight = false;
1206 if ( aAlignedPxRect.Height() == 0 )
1207 {
1208 aAlignedPxRect.Height(1);
1209 bZeroHeight = true;
1210 }
1211
1212 rRect = SwRect(pOut->PixelToLogic( aAlignedPxRect.SVRect() ));
1213
1214 // Consider zero width/height and adjust calculated aligned twip rectangle.
1215 // Reset width/height to zero; previous negative width/height haven't to be considered.
1216 if ( bZeroWidth )
1217 {
1218 rRect.Width(0);
1219 }
1220 if ( bZeroHeight )
1221 {
1222 rRect.Height(0);
1223 }
1224}
1225
1241void SwAlignGrfRect( SwRect *pGrfRect, const vcl::RenderContext &rOut )
1242{
1243 tools::Rectangle aPxRect = rOut.LogicToPixel( pGrfRect->SVRect() );
1244 pGrfRect->Pos( rOut.PixelToLogic( aPxRect.TopLeft() ) );
1245 pGrfRect->SSize( rOut.PixelToLogic( aPxRect.GetSize() ) );
1246}
1247
1248static tools::Long lcl_AlignWidth( const tools::Long nWidth, SwPaintProperties const & properties )
1249{
1250 if ( nWidth )
1251 {
1252 const tools::Long nW = nWidth % properties.nSPixelSzW;
1253
1254 if ( !nW || nW > properties.nSHalfPixelSzW )
1255 return std::max(tools::Long(1), nWidth - properties.nSHalfPixelSzW);
1256 }
1257 return nWidth;
1258}
1259
1260static tools::Long lcl_AlignHeight( const tools::Long nHeight, SwPaintProperties const & properties )
1261{
1262 if ( nHeight )
1263 {
1264 const tools::Long nH = nHeight % properties.nSPixelSzH;
1265
1266 if ( !nH || nH > properties.nSHalfPixelSzH )
1267 return std::max(tools::Long(1), nHeight - properties.nSHalfPixelSzH);
1268 }
1269 return nHeight;
1270}
1271
1275static void lcl_CalcBorderRect( SwRect &rRect, const SwFrame *pFrame,
1276 const SwBorderAttrs &rAttrs,
1277 const bool bShadow,
1278 SwPaintProperties const & properties)
1279{
1280 // Special handling for cell frames.
1281 // The printing area of a cell frame is completely enclosed in the frame area
1282 // and a cell frame has no shadow. Thus, for cell frames the calculated
1283 // area equals the frame area.
1284 // Notes: Borders of cell frames in R2L text direction will switch its side
1285 // - left border is painted on the right; right border on the left.
1286 // See <lcl_PaintLeftLine> and <lcl_PaintRightLine>.
1287 if( pFrame->IsSctFrame() )
1288 {
1289 rRect = pFrame->getFramePrintArea();
1290 rRect.Pos() += pFrame->getFrameArea().Pos();
1291 }
1292 else if ( pFrame->IsCellFrame() )
1293 rRect = pFrame->getFrameArea();
1294 else
1295 {
1296 rRect = pFrame->getFramePrintArea();
1297 rRect.Pos() += pFrame->getFrameArea().Pos();
1298
1299 SwRectFn fnRect = pFrame->IsVertical() ? ( pFrame->IsVertLR() ? (pFrame->IsVertLRBT() ? fnRectVertL2RB2T : fnRectVertL2R) : fnRectVert ) : fnRectHori;
1300
1301 const SvxBoxItem &rBox = rAttrs.GetBox();
1302 const bool bTop = 0 != (pFrame->*fnRect->fnGetTopMargin)();
1303 if ( bTop || rBox.GetTop() )
1304 {
1305 SwTwips nDiff = rBox.GetTop() ?
1306 rBox.CalcLineSpace( SvxBoxItemLine::TOP, /*bEvenIfNoLine=*/false, /*bAllowNegative=*/true ) :
1307 rBox.GetDistance( SvxBoxItemLine::TOP );
1308 if( nDiff )
1309 (rRect.*fnRect->fnSubTop)( nDiff );
1310 }
1311
1312 const bool bBottom = 0 != (pFrame->*fnRect->fnGetBottomMargin)();
1313 if ( bBottom )
1314 {
1315 SwTwips nDiff = 0;
1316 // #i29550#
1317 if ( pFrame->IsTabFrame() &&
1318 static_cast<const SwTabFrame*>(pFrame)->IsCollapsingBorders() )
1319 {
1320 // For collapsing borders, we have to add the height of
1321 // the height of the last line
1322 nDiff = static_cast<const SwTabFrame*>(pFrame)->GetBottomLineSize();
1323 }
1324 else
1325 {
1326 nDiff = rBox.GetBottom() ?
1327 rBox.CalcLineSpace( SvxBoxItemLine::BOTTOM ) :
1328 rBox.GetDistance( SvxBoxItemLine::BOTTOM );
1329 }
1330 if( nDiff )
1331 (rRect.*fnRect->fnAddBottom)( nDiff );
1332 }
1333
1334 if ( rBox.GetLeft() )
1335 (rRect.*fnRect->fnSubLeft)( rBox.CalcLineSpace( SvxBoxItemLine::LEFT ) );
1336 else
1337 (rRect.*fnRect->fnSubLeft)( rBox.GetDistance( SvxBoxItemLine::LEFT ) );
1338
1339 if ( rBox.GetRight() )
1340 (rRect.*fnRect->fnAddRight)( rBox.CalcLineSpace( SvxBoxItemLine::RIGHT ) );
1341 else
1342 (rRect.*fnRect->fnAddRight)( rBox.GetDistance( SvxBoxItemLine::RIGHT ) );
1343
1344 if ( bShadow && rAttrs.GetShadow().GetLocation() != SvxShadowLocation::NONE )
1345 {
1346 const SvxShadowItem &rShadow = rAttrs.GetShadow();
1347 if ( bTop )
1348 (rRect.*fnRect->fnSubTop)(rShadow.CalcShadowSpace(SvxShadowItemSide::TOP));
1349 (rRect.*fnRect->fnSubLeft)(rShadow.CalcShadowSpace(SvxShadowItemSide::LEFT));
1350 if ( bBottom )
1351 (rRect.*fnRect->fnAddBottom)
1352 (rShadow.CalcShadowSpace( SvxShadowItemSide::BOTTOM ));
1353 (rRect.*fnRect->fnAddRight)(rShadow.CalcShadowSpace(SvxShadowItemSide::RIGHT));
1354 }
1355 }
1356
1357 ::SwAlignRect( rRect, properties.pSGlobalShell, properties.pSGlobalShell ? properties.pSGlobalShell->GetOut() : nullptr );
1358}
1359
1364static void lcl_ExtendLeftAndRight( SwRect& _rRect,
1365 const SwFrame& _rFrame,
1366 const SwBorderAttrs& _rAttrs,
1367 const SwRectFn& _rRectFn )
1368{
1369 if ( _rAttrs.JoinedWithPrev( _rFrame ) )
1370 {
1371 const SwFrame* pPrevFrame = _rFrame.GetPrev();
1372 (_rRect.*_rRectFn->fnSetTop)( (pPrevFrame->*_rRectFn->fnGetPrtBottom)() );
1373 }
1374 if ( _rAttrs.JoinedWithNext( _rFrame ) )
1375 {
1376 const SwFrame* pNextFrame = _rFrame.GetNext();
1377 (_rRect.*_rRectFn->fnSetBottom)( (pNextFrame->*_rRectFn->fnGetPrtTop)() );
1378 }
1379}
1380
1384{
1385 static MapMode aMapMode(MapUnit::MapTwip);
1386 static const Size aSingleUnit = Application::GetDefaultDevice()->PixelToLogic(Size(1, 1), aMapMode);
1387
1388 double x1 = rRect.Left() + aSingleUnit.getWidth();
1389 double y1 = rRect.Top() + aSingleUnit.getHeight();
1390 double x2 = rRect.Right() - aSingleUnit.getWidth();
1391 double y2 = rRect.Bottom() - aSingleUnit.getHeight();
1392
1393 return basegfx::B2DRange(x1, y1, x2, y2);
1394}
1395
1396static void lcl_SubtractFlys( const SwFrame *pFrame, const SwPageFrame *pPage,
1397 const SwRect &rRect, SwRegionRects &rRegion, basegfx::utils::B2DClipState& rClipState, SwPaintProperties const & rProperties)
1398{
1399 const SwSortedObjs& rObjs = *pPage->GetSortedObjs();
1400 const SwFlyFrame* pSelfFly = pFrame->IsInFly() ? pFrame->FindFlyFrame() : gProp.pSRetoucheFly2;
1401 if (!gProp.pSRetoucheFly)
1402 gProp.pSRetoucheFly = gProp.pSRetoucheFly2;
1403
1404 for (size_t j = 0; (j < rObjs.size()) && !rRegion.empty(); ++j)
1405 {
1406 const SwAnchoredObject* pAnchoredObj = rObjs[j];
1407 const SdrObject* pSdrObj = pAnchoredObj->GetDrawObj();
1408
1409 // Do not consider invisible objects
1411 continue;
1412
1413 const SwFlyFrame *pFly = pAnchoredObj->DynCastFlyFrame();
1414 if (!pFly)
1415 continue;
1416
1417 if (pSelfFly == pFly || gProp.pSRetoucheFly == pFly || !rRect.Overlaps(pFly->getFrameArea()))
1418 continue;
1419
1420 if (!pFly->GetFormat()->GetPrint().GetValue() &&
1421 (OUTDEV_PRINTER == gProp.pSGlobalShell->GetOut()->GetOutDevType() ||
1422 gProp.pSGlobalShell->IsPreview()))
1423 continue;
1424
1425 const bool bLowerOfSelf = pSelfFly && pFly->IsLowerOf( pSelfFly );
1426
1427 //For character bound Flys only examine those Flys in which it is not
1428 //anchored itself.
1429 //Why only for character bound ones you may ask? It never makes sense to
1430 //subtract frames in which it is anchored itself right?
1431 if (pSelfFly && pSelfFly->IsLowerOf(pFly))
1432 continue;
1433
1434 //Any why does it not apply for the RetoucheFly too?
1435 if (gProp.pSRetoucheFly && gProp.pSRetoucheFly->IsLowerOf(pFly))
1436 continue;
1437
1438#if OSL_DEBUG_LEVEL > 0
1439 //Flys who are anchored inside their own one, must have a bigger OrdNum
1440 //or be character bound.
1441 if (pSelfFly && bLowerOfSelf)
1442 {
1443 OSL_ENSURE( pFly->IsFlyInContentFrame() ||
1444 pSdrObj->GetOrdNumDirect() > pSelfFly->GetVirtDrawObj()->GetOrdNumDirect(),
1445 "Fly with wrong z-Order" );
1446 }
1447#endif
1448
1449 bool bStopOnHell = true;
1450 if (pSelfFly)
1451 {
1452 const SdrObject *pTmp = pSelfFly->GetVirtDrawObj();
1453 if (pSdrObj->GetLayer() == pTmp->GetLayer())
1454 {
1455 if (pSdrObj->GetOrdNumDirect() < pTmp->GetOrdNumDirect())
1456 //In the same layer we only observe those that are above.
1457 continue;
1458 }
1459 else
1460 {
1461 if (!bLowerOfSelf && !pFly->GetFormat()->GetOpaque().GetValue())
1462 //From other layers we are only interested in non
1463 //transparent ones or those that are internal
1464 continue;
1465 bStopOnHell = false;
1466 }
1467 }
1468 if (gProp.pSRetoucheFly)
1469 {
1470 const SdrObject *pTmp = gProp.pSRetoucheFly->GetVirtDrawObj();
1471 if ( pSdrObj->GetLayer() == pTmp->GetLayer() )
1472 {
1473 if ( pSdrObj->GetOrdNumDirect() < pTmp->GetOrdNumDirect() )
1474 //In the same layer we only observe those that are above.
1475 continue;
1476 }
1477 else
1478 {
1479 if (!pFly->IsLowerOf( gProp.pSRetoucheFly ) && !pFly->GetFormat()->GetOpaque().GetValue())
1480 //From other layers we are only interested in non
1481 //transparent ones or those that are internal
1482 continue;
1483 bStopOnHell = false;
1484 }
1485 }
1486
1487 //If the content of the Fly is transparent, we subtract it only if it's
1488 //contained in the hell layer.
1490 bool bHell = pSdrObj->GetLayer() == rIDDMA.GetHellId();
1491 if ( (bStopOnHell && bHell) ||
1495 ( !bHell && pFly->Lower() && pFly->Lower()->IsNoTextFrame() &&
1496 (static_cast<SwNoTextFrame const*>(pFly->Lower())->IsTransparent() ||
1497 static_cast<SwNoTextFrame const*>(pFly->Lower())->HasAnimation() ||
1498 pFly->GetFormat()->GetSurround().IsContour()
1499 )
1500 )
1501 )
1502 continue;
1503
1504 // Own if-statements for transparent background/shadow of fly frames
1505 // in order to handle special conditions.
1506 if (pFly->IsBackgroundTransparent())
1507 {
1508 // Background <pFly> is transparent drawn. Thus normally, its region
1509 // have not to be subtracted from given region.
1510 // But, if method is called for a fly frame and
1511 // <pFly> is a direct lower of this fly frame and
1512 // <pFly> inherites its transparent background brush from its parent,
1513 // then <pFly> frame area have to be subtracted from given region.
1514 // NOTE: Because in Status Quo transparent backgrounds can only be
1515 // assigned to fly frames, the handle of this special case
1516 // avoids drawing of transparent areas more than once, if
1517 // a fly frame inherites a transparent background from its
1518 // parent fly frame.
1519 if (pFrame->IsFlyFrame() &&
1520 (pFly->GetAnchorFrame()->FindFlyFrame() == pFrame) &&
1522 )
1523 {
1524 SwRect aRect;
1525 SwBorderAttrAccess aAccess( SwFrame::GetCache(), static_cast<SwFrame const *>(pFly) );
1526 const SwBorderAttrs &rAttrs = *aAccess.Get();
1527 ::lcl_CalcBorderRect( aRect, pFly, rAttrs, true, rProperties );
1528 rRegion -= aRect;
1529 rClipState.subtractRange(lcl_ShrinkFly(aRect));
1530 continue;
1531 }
1532 else
1533 {
1534 continue;
1535 }
1536 }
1537
1538 if (bHell && pFly->GetAnchorFrame()->IsInFly())
1539 {
1540 //So the border won't get dismantled by the background of the other
1541 //Fly.
1542 SwRect aRect;
1543 SwBorderAttrAccess aAccess( SwFrame::GetCache(), static_cast<SwFrame const *>(pFly) );
1544 const SwBorderAttrs &rAttrs = *aAccess.Get();
1545 ::lcl_CalcBorderRect( aRect, pFly, rAttrs, true, rProperties );
1546 rRegion -= aRect;
1547 rClipState.subtractRange(lcl_ShrinkFly(aRect));
1548 }
1549 else
1550 {
1551 SwRect aRect( pFly->getFramePrintArea() );
1552 aRect += pFly->getFrameArea().Pos();
1553 rRegion -= aRect;
1554 rClipState.subtractRange(lcl_ShrinkFly(aRect));
1555 }
1556 }
1557 if (gProp.pSRetoucheFly == gProp.pSRetoucheFly2)
1558 gProp.pSRetoucheFly = nullptr;
1559}
1560
1561static void lcl_implDrawGraphicBackground(const SvxBrushItem& _rBackgrdBrush,
1562 vcl::RenderContext& _rOut,
1563 const SwRect& _rAlignedPaintRect,
1564 const GraphicObject& _rGraphicObj,
1565 SwPaintProperties const & properties)
1566{
1571 const Color aColor( ( (_rBackgrdBrush.GetColor() != COL_TRANSPARENT) || properties.bSFlyMetafile )
1572 ? _rBackgrdBrush.GetColor()
1574
1577 sal_Int8 nTransparencyPercent = 0;
1578 bool bDrawTransparent = false;
1579 if ( aColor.IsTransparent() )
1581 {
1582 bDrawTransparent = true;
1583 nTransparencyPercent = ((255 - aColor.GetAlpha())*100 + 0x7F)/0xFF;
1584 }
1585 else if ( (_rGraphicObj.GetAttr().IsTransparent()) &&
1586 (_rBackgrdBrush.GetColor() == COL_TRANSPARENT) )
1589 {
1590 bDrawTransparent = true;
1591 nTransparencyPercent = 100 - (_rGraphicObj.GetAttr().GetAlpha() * 100 + 127) / 255;
1592 }
1593
1594 if ( bDrawTransparent )
1595 {
1597 if( _rOut.GetFillColor() != aColor.GetRGBColor() )
1598 _rOut.SetFillColor( aColor.GetRGBColor() );
1599 tools::PolyPolygon aPoly( _rAlignedPaintRect.SVRect() );
1600 _rOut.DrawTransparent( aPoly, nTransparencyPercent );
1601 }
1602 else
1603 {
1605 if ( _rOut.GetFillColor() != aColor )
1606 _rOut.SetFillColor( aColor );
1607 _rOut.DrawRect( _rAlignedPaintRect.SVRect() );
1608 }
1609}
1610
1643static void lcl_DrawGraphicBackground( const SvxBrushItem& _rBackgrdBrush,
1644 OutputDevice& _rOut,
1645 const SwRect& _rAlignedPaintRect,
1646 const GraphicObject& _rGraphicObj,
1647 bool _bNumberingGraphic,
1648 SwPaintProperties const & properties,
1649 bool _bBackgrdAlreadyDrawn = false)
1650{
1651 // draw background with background color, if
1652 // (1) graphic is not used as a numbering AND
1653 // (2) background is not already drawn AND
1654 // (3) intrinsic graphic is transparent OR intrinsic graphic doesn't exists
1655 if ( !_bNumberingGraphic &&
1656 !_bBackgrdAlreadyDrawn &&
1657 ( _rGraphicObj.IsTransparent() || _rGraphicObj.GetType() == GraphicType::NONE )
1658 )
1659 {
1660 lcl_implDrawGraphicBackground( _rBackgrdBrush, _rOut, _rAlignedPaintRect, _rGraphicObj, properties );
1661 }
1662}
1663
1679static void lcl_DrawGraphic( const SvxBrushItem& rBrush, vcl::RenderContext &rOutDev,
1680 const SwViewShell &rSh, const SwRect &rGrf, const SwRect &rOut,
1681 bool bGrfNum,
1682 SwPaintProperties const & properties,
1683 bool bBackgrdAlreadyDrawn )
1684 // add parameter <bBackgrdAlreadyDrawn> to indicate
1685 // that the background is already drawn.
1686{
1687 // Calculate align rectangle from parameter <rGrf> and use aligned
1688 // rectangle <aAlignedGrfRect> in the following code
1689 SwRect aAlignedGrfRect = rGrf;
1690 ::SwAlignRect( aAlignedGrfRect, &rSh, &rOutDev );
1691
1692 // Change type from <bool> to <bool>.
1693 const bool bNotInside = !rOut.Contains( aAlignedGrfRect );
1694 if ( bNotInside )
1695 {
1697 rOutDev.IntersectClipRegion( rOut.SVRect() );
1698 }
1699
1700 GraphicObject *pGrf = const_cast<GraphicObject*>(rBrush.GetGraphicObject());
1701
1702 OUString aOriginURL = pGrf->GetGraphic().getOriginURL();
1703 if (pGrf->GetGraphic().GetType() == GraphicType::Default && !aOriginURL.isEmpty())
1704 {
1705 Graphic aGraphic = vcl::graphic::loadFromURL(aOriginURL);
1706 pGrf->SetGraphic(aGraphic);
1707 }
1708
1709 // Outsource drawing of background with a background color
1710 ::lcl_DrawGraphicBackground( rBrush, rOutDev, aAlignedGrfRect, *pGrf, bGrfNum, properties, bBackgrdAlreadyDrawn );
1711
1712 // Because for drawing a graphic left-top-corner and size coordinates are
1713 // used, these coordinates have to be determined on pixel level.
1714 ::SwAlignGrfRect( &aAlignedGrfRect, rOutDev );
1715
1716 const basegfx::B2DHomMatrix aGraphicTransform(
1718 aAlignedGrfRect.Width(), aAlignedGrfRect.Height(),
1719 aAlignedGrfRect.Left(), aAlignedGrfRect.Top()));
1720
1722 rOutDev,
1723 *pGrf,
1724 pGrf->GetAttr(),
1725 aGraphicTransform,
1726 OUString(),
1727 OUString(),
1728 OUString());
1729
1730 if ( bNotInside )
1731 rOutDev.Pop();
1732}
1733
1736 const SwRect& rOriginalLayoutRect,
1737 const SwRegionRects& rPaintRegion,
1738 const basegfx::utils::B2DClipState& rClipState,
1739 vcl::RenderContext& rOut)
1740{
1741 if(rFillAttributes && rFillAttributes->isUsed())
1742 {
1743 basegfx::B2DRange aPaintRange(
1744 rPaintRegion.GetOrigin().Left(),
1745 rPaintRegion.GetOrigin().Top(),
1746 rPaintRegion.GetOrigin().Right(),
1747 rPaintRegion.GetOrigin().Bottom());
1748
1749 if (!aPaintRange.isEmpty() &&
1750 !rPaintRegion.empty() &&
1751 !basegfx::fTools::equalZero(aPaintRange.getWidth()) &&
1752 !basegfx::fTools::equalZero(aPaintRange.getHeight()))
1753 {
1754 // need to expand for correct AAed and non-AAed visualization as primitive.
1755 // This must probably be removed again when we will be able to get all Writer visualization
1756 // as primitives and Writer prepares all it's stuff in high precision coordinates (also
1757 // needs to avoid moving boundaries around to better show overlapping stuff...)
1759 {
1760 // if AAed in principle expand by 0.5 in all directions. Since painting edges of
1761 // AAed regions does not add to no transparence (0.5 opacity covered by 0.5 opacity
1762 // is not full opacity but 0.75 opacity) we need some overlap here to avoid paint
1763 // artifacts. Checked experimentally - a little bit more in Y is needed, probably
1764 // due to still existing integer alignment and crunching in writer.
1765 static const double fExpandX = 0.55;
1766 static const double fExpandY = 0.70;
1767 const basegfx::B2DVector aSingleUnit(rOut.GetInverseViewTransformation() * basegfx::B2DVector(fExpandX, fExpandY));
1768
1769 aPaintRange.expand(aPaintRange.getMinimum() - aSingleUnit);
1770 aPaintRange.expand(aPaintRange.getMaximum() + aSingleUnit);
1771 }
1772 else
1773 {
1774 // if not AAed expand by one unit to bottom right due to the missing unit
1775 // from SwRect/Rectangle integer handling
1776 const basegfx::B2DVector aSingleUnit(rOut.GetInverseViewTransformation() * basegfx::B2DVector(1.0, 1.0));
1777
1778 aPaintRange.expand(aPaintRange.getMaximum() + aSingleUnit);
1779 }
1780
1781 const basegfx::B2DRange aDefineRange(
1782 rOriginalLayoutRect.Left(),
1783 rOriginalLayoutRect.Top(),
1784 rOriginalLayoutRect.Right(),
1785 rOriginalLayoutRect.Bottom());
1786
1787 const drawinglayer::primitive2d::Primitive2DContainer& rSequence = rFillAttributes->getPrimitive2DSequence(
1788 aPaintRange,
1789 aDefineRange);
1790
1791 if(rSequence.size())
1792 {
1794 pPrimitives(&rSequence);
1796 // tdf#86578 the awful lcl_SubtractFlys hack
1797 if (rPaintRegion.size() > 1 || rPaintRegion[0] != rPaintRegion.GetOrigin())
1798 {
1799 basegfx::B2DPolyPolygon const& maskRegion(rClipState.getClipPoly());
1800 primitives.resize(1);
1803 pPrimitives = &primitives;
1804 }
1805 assert(pPrimitives && pPrimitives->size());
1806
1808 aViewInformation2D.setViewTransformation(rOut.GetViewTransformation());
1809 aViewInformation2D.setViewport(aPaintRange);
1810
1811 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createProcessor2DFromOutputDevice(
1812 rOut,
1813 aViewInformation2D) );
1814 pProcessor->process(*pPrimitives);
1815 return true;
1816 }
1817 }
1818 }
1819
1820 return false;
1821}
1822
1824 const SvxBrushItem *pBrush,
1825 vcl::RenderContext &rOutDev,
1826 const SwRect &rOrg,
1827 const SwRect &rOut,
1828 const sal_uInt8 nGrfNum,
1829 const bool bConsiderBackgroundTransparency )
1830 // Add 6th parameter to indicate that method should
1831 // consider background transparency, saved in the color of the brush item
1832{
1833 SwViewShell &rSh = *gProp.pSGlobalShell;
1834 bool bReplaceGrfNum = GRFNUM_REPLACE == nGrfNum;
1835 bool bGrfNum = GRFNUM_NO != nGrfNum;
1836 Size aGrfSize;
1838 if( pBrush && !bReplaceGrfNum )
1839 {
1840 if( rSh.GetViewOptions()->IsGraphic() )
1841 {
1842 OUString referer;
1843 SfxObjectShell * sh = rSh.GetDoc()->GetPersist();
1844 if (sh != nullptr && sh->HasName()) {
1845 referer = sh->GetMedium()->GetName();
1846 }
1847 const Graphic* pGrf = pBrush->GetGraphic(referer);
1848 if( pGrf && GraphicType::NONE != pGrf->GetType() )
1849 {
1850 ePos = pBrush->GetGraphicPos();
1851 if( pGrf->IsSupportedGraphic() )
1852 // don't the use the specific output device! Bug 94802
1853 aGrfSize = ::GetGraphicSizeTwip( *pGrf, nullptr );
1854 }
1855 }
1856 else
1857 bReplaceGrfNum = bGrfNum;
1858 }
1859
1860 SwRect aGrf;
1861 aGrf.SSize( aGrfSize );
1862 bool bDraw = true;
1863 bool bRetouche = true;
1864 switch ( ePos )
1865 {
1866 case GPOS_LT:
1867 aGrf.Pos() = rOrg.Pos();
1868 break;
1869
1870 case GPOS_MT:
1871 aGrf.Pos().setY( rOrg.Top() );
1872 aGrf.Pos().setX( rOrg.Left() + rOrg.Width()/2 - aGrfSize.Width()/2 );
1873 break;
1874
1875 case GPOS_RT:
1876 aGrf.Pos().setY( rOrg.Top() );
1877 aGrf.Pos().setX( rOrg.Right() - aGrfSize.Width() );
1878 break;
1879
1880 case GPOS_LM:
1881 aGrf.Pos().setY( rOrg.Top() + rOrg.Height()/2 - aGrfSize.Height()/2 );
1882 aGrf.Pos().setX( rOrg.Left() );
1883 break;
1884
1885 case GPOS_MM:
1886 aGrf.Pos().setY( rOrg.Top() + rOrg.Height()/2 - aGrfSize.Height()/2 );
1887 aGrf.Pos().setX( rOrg.Left() + rOrg.Width()/2 - aGrfSize.Width()/2 );
1888 break;
1889
1890 case GPOS_RM:
1891 aGrf.Pos().setY( rOrg.Top() + rOrg.Height()/2 - aGrfSize.Height()/2 );
1892 aGrf.Pos().setX( rOrg.Right() - aGrfSize.Width() );
1893 break;
1894
1895 case GPOS_LB:
1896 aGrf.Pos().setY( rOrg.Bottom() - aGrfSize.Height() );
1897 aGrf.Pos().setX( rOrg.Left() );
1898 break;
1899
1900 case GPOS_MB:
1901 aGrf.Pos().setY( rOrg.Bottom() - aGrfSize.Height() );
1902 aGrf.Pos().setX( rOrg.Left() + rOrg.Width()/2 - aGrfSize.Width()/2 );
1903 break;
1904
1905 case GPOS_RB:
1906 aGrf.Pos().setY( rOrg.Bottom() - aGrfSize.Height() );
1907 aGrf.Pos().setX( rOrg.Right() - aGrfSize.Width() );
1908 break;
1909
1910 case GPOS_AREA:
1911 aGrf = rOrg;
1912 // Despite the fact that the background graphic has to fill the complete
1913 // area, we already checked, whether the graphic will completely fill out
1914 // the region the <rOut> that is to be painted. Thus, nothing has to be
1915 // touched again.
1916 // E.g. this is the case for a Fly Frame without a background
1917 // brush positioned on the border of the page which inherited the background
1918 // brush from the page.
1919 bRetouche = !rOut.Contains( aGrf );
1920 break;
1921
1922 case GPOS_TILED:
1923 {
1924 // draw background of tiled graphic before drawing tiled graphic in loop
1925 // determine graphic object
1926 GraphicObject* pGraphicObj = const_cast< GraphicObject* >(pBrush->GetGraphicObject());
1927 // calculate aligned paint rectangle
1928 SwRect aAlignedPaintRect = rOut;
1929 ::SwAlignRect( aAlignedPaintRect, &rSh, &rOutDev );
1930 // draw background color for aligned paint rectangle
1931 lcl_DrawGraphicBackground( *pBrush, rOutDev, aAlignedPaintRect, *pGraphicObj, bGrfNum, gProp );
1932
1933 // set left-top-corner of background graphic to left-top-corner of the
1934 // area, from which the background brush is determined.
1935 aGrf.Pos() = rOrg.Pos();
1936 // setup clipping at output device
1938 rOutDev.IntersectClipRegion( rOut.SVRect() );
1939 // use new method <GraphicObject::DrawTiled(::)>
1940 {
1941 // calculate paint offset
1942 Point aPaintOffset( aAlignedPaintRect.Pos() - aGrf.Pos() );
1943 // draw background graphic tiled for aligned paint rectangle
1944 // #i42643#
1945 // For PDF export, every draw operation for bitmaps takes a
1946 // noticeable amount of place (~50 characters). Thus, optimize
1947 // between tile bitmap size and number of drawing operations here.
1948
1949 // A_out
1950 // n_chars = k1 * ---------- + k2 * A_bitmap
1951 // A_bitmap
1952
1953 // minimum n_chars is obtained for (derive for A_bitmap,
1954 // set to 0, take positive solution):
1955 // k1
1956 // A_bitmap = Sqrt( ---- A_out )
1957 // k2
1958
1959 // where k1 is the number of chars per draw operation, and
1960 // k2 is the number of chars per bitmap pixel.
1961 // This is approximately 50 and 7 for current PDF writer, respectively.
1962
1963 const double k1( 50 );
1964 const double k2( 7 );
1965 const Size aSize( aAlignedPaintRect.SSize() );
1966 const double Abitmap( k1/k2 * static_cast<double>(aSize.Width())*aSize.Height() );
1967
1968 pGraphicObj->DrawTiled( rOutDev,
1969 aAlignedPaintRect.SVRect(),
1970 aGrf.SSize(),
1971 Size( aPaintOffset.X(), aPaintOffset.Y() ),
1972 std::max( 128, static_cast<int>( sqrt(sqrt( Abitmap)) + .5 ) ) );
1973 }
1974 // reset clipping at output device
1975 rOutDev.Pop();
1976 // set <bDraw> and <bRetouche> to false, indicating that background
1977 // graphic and background are already drawn.
1978 bDraw = bRetouche = false;
1979 }
1980 break;
1981
1982 case GPOS_NONE:
1983 bDraw = false;
1984 break;
1985
1986 default: OSL_ENSURE( false, "new Graphic position?" );
1987 }
1988
1991 bool bGrfBackgrdAlreadyDrawn = false;
1992 if ( bRetouche )
1993 {
1995 rOutDev.SetLineColor();
1996
1997 // check, if an existing background graphic (not filling the complete
1998 // background) is transparent drawn and the background color is
1999 // "no fill" respectively "auto fill", if background transparency
2000 // has to be considered.
2001 // If YES, memorize transparency of background graphic.
2002 // check also, if background graphic bitmap is transparent.
2003 bool bTransparentGrfWithNoFillBackgrd = false;
2004 sal_Int32 nGrfTransparency = 0;
2005 bool bGrfIsTransparent = false;
2006 if ( (ePos != GPOS_NONE) &&
2007 (ePos != GPOS_TILED) && (ePos != GPOS_AREA)
2008 )
2009 {
2010 GraphicObject *pGrf = const_cast<GraphicObject*>(pBrush->GetGraphicObject());
2011 if ( bConsiderBackgroundTransparency )
2012 {
2013 GraphicAttr aGrfAttr = pGrf->GetAttr();
2014 if ( (aGrfAttr.IsTransparent()) &&
2015 (pBrush->GetColor() == COL_TRANSPARENT)
2016 )
2017 {
2018 bTransparentGrfWithNoFillBackgrd = true;
2019 nGrfTransparency = 255 - aGrfAttr.GetAlpha();
2020 }
2021 }
2022 if ( pGrf->IsTransparent() )
2023 {
2024 bGrfIsTransparent = true;
2025 }
2026 }
2027
2028 // to get color of brush, check background color against COL_TRANSPARENT ("no fill"/"auto fill")
2029 // instead of checking, if transparency is not set.
2030 const Color aColor( pBrush &&
2031 ( (pBrush->GetColor() != COL_TRANSPARENT) ||
2032 gProp.bSFlyMetafile )
2033 ? pBrush->GetColor()
2035
2036 // determine, if background region have to be
2037 // drawn transparent.
2038 // background region has to be drawn transparent, if
2039 // background transparency have to be considered
2040 // AND
2041 // ( background color is transparent OR
2042 // background graphic is transparent and background color is "no fill"
2043 // )
2044
2045 enum DrawStyle {
2046 Default,
2048 } eDrawStyle = Default;
2049
2050 if (bConsiderBackgroundTransparency &&
2051 ( ( aColor.IsTransparent()) ||
2052 bTransparentGrfWithNoFillBackgrd ) )
2053 {
2054 eDrawStyle = Transparent;
2055 }
2056
2057 // #i75614# reset draw mode in high contrast mode in order to get fill color set
2058 const DrawModeFlags nOldDrawMode = rOutDev.GetDrawMode();
2059 if ( gProp.pSGlobalShell->GetWin() &&
2061 {
2062 rOutDev.SetDrawMode( DrawModeFlags::Default );
2063 }
2064
2065 // If background region has to be drawn transparent, set only the RGB values of the background color as
2066 // the fill color for the output device.
2067 switch (eDrawStyle)
2068 {
2069 case Transparent:
2070 {
2071 if( rOutDev.GetFillColor() != aColor.GetRGBColor() )
2072 rOutDev.SetFillColor( aColor.GetRGBColor() );
2073 break;
2074 }
2075 default:
2076 {
2077 if( rOutDev.GetFillColor() != aColor )
2078 rOutDev.SetFillColor( aColor );
2079 break;
2080 }
2081 }
2082
2083 // #i75614#
2084 // restore draw mode
2085 rOutDev.SetDrawMode( nOldDrawMode );
2086
2087 switch (eDrawStyle)
2088 {
2089 case Transparent:
2090 {
2091 // background region have to be drawn transparent.
2092 // Thus, create a poly-polygon from the region and draw it with
2093 // the corresponding transparency percent.
2094 tools::PolyPolygon aDrawPoly( rOut.SVRect() );
2095 if ( aGrf.HasArea() )
2096 {
2097 if ( !bGrfIsTransparent )
2098 {
2099 // subtract area of background graphic from draw area
2100 // Consider only that part of the graphic area that is overlapping with draw area.
2101 SwRect aTmpGrf = aGrf;
2102 aTmpGrf.Intersection( rOut );
2103 if ( aTmpGrf.HasArea() )
2104 {
2105 tools::Polygon aGrfPoly( aTmpGrf.SVRect() );
2106 aDrawPoly.Insert( aGrfPoly );
2107 }
2108 }
2109 else
2110 bGrfBackgrdAlreadyDrawn = true;
2111 }
2112 // calculate transparency percent:
2113 // ( <transparency value[0x01..0xFF]>*100 + 0x7F ) / 0xFF
2114 // If there is a background graphic with a background color "no fill"/"auto fill",
2115 // the transparency value is taken from the background graphic,
2116 // otherwise take the transparency value from the color.
2117 sal_Int8 nTransparencyPercent = static_cast<sal_Int8>(
2118 (( bTransparentGrfWithNoFillBackgrd ? nGrfTransparency : (255 - aColor.GetAlpha())
2119 )*100 + 0x7F)/0xFF);
2120 // draw poly-polygon transparent
2121 rOutDev.DrawTransparent( aDrawPoly, nTransparencyPercent );
2122
2123 break;
2124 }
2125 case Default:
2126 default:
2127 {
2128 SwRegionRects aRegion( rOut, 4 );
2129 if ( !bGrfIsTransparent )
2130 aRegion -= aGrf;
2131 else
2132 bGrfBackgrdAlreadyDrawn = true;
2133 // loop rectangles of background region, which has to be drawn
2134 for( size_t i = 0; i < aRegion.size(); ++i )
2135 {
2136 rOutDev.DrawRect( aRegion[i].SVRect() );
2137 }
2138 }
2139 }
2140 rOutDev.Pop();
2141 }
2142
2143 if( bDraw && aGrf.Overlaps( rOut ) )
2144 lcl_DrawGraphic( *pBrush, rOutDev, rSh, aGrf, rOut, bGrfNum, gProp,
2145 bGrfBackgrdAlreadyDrawn );
2146
2147 if( bReplaceGrfNum )
2148 {
2149 const BitmapEx& rBmp = rSh.GetReplacementBitmap(false);
2150 vcl::Font aTmp( rOutDev.GetFont() );
2151 Graphic::DrawEx(rOutDev, OUString(), aTmp, rBmp, rOrg.Pos(), rOrg.SSize());
2152 }
2153}
2154
2163static void lcl_AdjustRectToPixelSize( SwRect& io_aSwRect, const vcl::RenderContext &aOut )
2164{
2165 // local constant object of class <Size> to determine number of Twips
2166 // representing a pixel.
2167 const Size aTwipToPxSize( aOut.PixelToLogic( Size( 1,1 )) );
2168
2169 // local object of class <Rectangle> in Twip coordinates
2170 // calculated from given rectangle aligned to pixel centers.
2171 const tools::Rectangle aPxCenterRect = aOut.PixelToLogic(
2172 aOut.LogicToPixel( io_aSwRect.SVRect() ) );
2173
2174 // local constant object of class <Rectangle> representing given rectangle
2175 // in pixel.
2176 const tools::Rectangle aOrgPxRect = aOut.LogicToPixel( io_aSwRect.SVRect() );
2177
2178 // calculate adjusted rectangle from pixel centered rectangle.
2179 // Due to rounding differences <aPxCenterRect> doesn't exactly represents
2180 // the Twip-centers. Thus, adjust borders by half of pixel width/height plus 1.
2181 // Afterwards, adjust calculated Twip-positions of the all borders.
2182 tools::Rectangle aSizedRect = aPxCenterRect;
2183 aSizedRect.AdjustLeft( -(aTwipToPxSize.Width()/2 + 1) );
2184 aSizedRect.AdjustRight( aTwipToPxSize.Width()/2 + 1 );
2185 aSizedRect.AdjustTop( -(aTwipToPxSize.Height()/2 + 1) );
2186 aSizedRect.AdjustBottom(aTwipToPxSize.Height()/2 + 1);
2187
2188 // adjust left()
2189 while ( aOut.LogicToPixel(aSizedRect).Left() < aOrgPxRect.Left() )
2190 {
2191 aSizedRect.AdjustLeft( 1 );
2192 }
2193 // adjust right()
2194 while ( aOut.LogicToPixel(aSizedRect).Right() > aOrgPxRect.Right() )
2195 {
2196 aSizedRect.AdjustRight( -1 );
2197 }
2198 // adjust top()
2199 while ( aOut.LogicToPixel(aSizedRect).Top() < aOrgPxRect.Top() )
2200 {
2201 aSizedRect.AdjustTop( 1 );
2202 }
2203 // adjust bottom()
2204 while ( aOut.LogicToPixel(aSizedRect).Bottom() > aOrgPxRect.Bottom() )
2205 {
2206 aSizedRect.AdjustBottom( -1 );
2207 }
2208
2209 io_aSwRect = SwRect( aSizedRect );
2210
2211#if OSL_DEBUG_LEVEL > 0
2212 tools::Rectangle aTestOrgPxRect = aOut.LogicToPixel( io_aSwRect.SVRect() );
2213 tools::Rectangle aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
2214 OSL_ENSURE( aTestOrgPxRect == aTestNewPxRect,
2215 "Error in lcl_AlignRectToPixelSize(..): Adjusted rectangle has incorrect position or size");
2216 // check Left()
2217 aSizedRect.AdjustLeft( -1 );
2218 aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
2219 OSL_ENSURE( aTestOrgPxRect.Left() >= (aTestNewPxRect.Left()+1),
2220 "Error in lcl_AlignRectToPixelSize(..): Left() not correct adjusted");
2221 aSizedRect.AdjustLeft( 1 );
2222 // check Right()
2223 aSizedRect.AdjustRight( 1 );
2224 aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
2225 OSL_ENSURE( aTestOrgPxRect.Right() <= (aTestNewPxRect.Right()-1),
2226 "Error in lcl_AlignRectToPixelSize(..): Right() not correct adjusted");
2227 aSizedRect.AdjustRight( -1 );
2228 // check Top()
2229 aSizedRect.AdjustTop( -1 );
2230 aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
2231 OSL_ENSURE( aTestOrgPxRect.Top() >= (aTestNewPxRect.Top()+1),
2232 "Error in lcl_AlignRectToPixelSize(..): Top() not correct adjusted");
2233 aSizedRect.AdjustTop( 1 );
2234 // check Bottom()
2235 aSizedRect.AdjustBottom( 1 );
2236 aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
2237 OSL_ENSURE( aTestOrgPxRect.Bottom() <= (aTestNewPxRect.Bottom()-1),
2238 "Error in lcl_AlignRectToPixelSize(..): Bottom() not correct adjusted");
2239 aSizedRect.AdjustBottom( -1 );
2240#endif
2241}
2242
2243// FUNCTIONS USED FOR COLLAPSING TABLE BORDER LINES START
2244
2245namespace {
2246
2247struct SwLineEntry
2248{
2249 SwTwips mnKey;
2250 SwTwips mnStartPos;
2251 SwTwips mnEndPos;
2252 SwTwips mnLimitedEndPos;
2253 bool mbOuter;
2254
2255 svx::frame::Style maAttribute;
2256
2257 enum OverlapType { NO_OVERLAP, OVERLAP1, OVERLAP2, OVERLAP3 };
2258
2259 enum class VerticalType { LEFT, RIGHT };
2260
2261public:
2262 SwLineEntry( SwTwips nKey,
2263 SwTwips nStartPos,
2264 SwTwips nEndPos,
2265 bool bOuter,
2266 const svx::frame::Style& rAttribute );
2267
2268 OverlapType Overlaps( const SwLineEntry& rComp ) const;
2269
2274 void LimitVerticalEndPos(const SwFrame& rFrame, VerticalType eType);
2275};
2276
2277}
2278
2279SwLineEntry::SwLineEntry( SwTwips nKey,
2280 SwTwips nStartPos,
2281 SwTwips nEndPos,
2282 bool bOuter,
2283 const svx::frame::Style& rAttribute )
2284 : mnKey( nKey ),
2285 mnStartPos( nStartPos ),
2286 mnEndPos( nEndPos ),
2287 mnLimitedEndPos(0),
2288 mbOuter(bOuter),
2289 maAttribute( rAttribute )
2290{
2291}
2292
2293/*
2294
2295 1. ---------- rOld
2296 ---------- rNew
2297
2298 2. ---------- rOld
2299 ------------- rNew
2300
2301 3. ------- rOld
2302 ------------- rNew
2303
2304 4. ------------- rOld
2305 ---------- rNew
2306
2307 5. ---------- rOld
2308 ---- rNew
2309
2310 6. ---------- rOld
2311 ---------- rNew
2312
2313 7. ------------- rOld
2314 ---------- rNew
2315
2316 8. ---------- rOld
2317 ------------- rNew
2318
2319 9. ---------- rOld
2320 ---------- rNew
2321*/
2322
2323SwLineEntry::OverlapType SwLineEntry::Overlaps( const SwLineEntry& rNew ) const
2324{
2325 SwLineEntry::OverlapType eRet = OVERLAP3;
2326
2327 if ( mnStartPos >= rNew.mnEndPos || mnEndPos <= rNew.mnStartPos )
2328 eRet = NO_OVERLAP;
2329
2330 // 1, 2, 3
2331 else if ( mnEndPos < rNew.mnEndPos )
2332 eRet = OVERLAP1;
2333
2334 // 4, 5, 6, 7
2335 else if (mnStartPos <= rNew.mnStartPos)
2336 eRet = OVERLAP2;
2337
2338 // 8, 9
2339 return eRet;
2340}
2341
2342void SwLineEntry::LimitVerticalEndPos(const SwFrame& rFrame, VerticalType eType)
2343{
2344 if (!rFrame.IsCellFrame())
2345 {
2346 return;
2347 }
2348
2349 const auto& rCellFrame = static_cast<const SwCellFrame&>(rFrame);
2350 std::vector<const SwCellFrame*> aCoveredCells = rCellFrame.GetCoveredCells();
2351 // Iterate in reverse order, so we can stop at the first cell that has a border. This can
2352 // determine what is the minimal end position that is safe to use as a limit.
2353 for (auto it = aCoveredCells.rbegin(); it != aCoveredCells.rend(); ++it)
2354 {
2355 const SwCellFrame* pCoveredCell = *it;
2356 SwBorderAttrAccess aAccess( SwFrame::GetCache(), pCoveredCell );
2357 const SwBorderAttrs& rAttrs = *aAccess.Get();
2358 const SvxBoxItem& rBox = rAttrs.GetBox();
2359 if (eType == VerticalType::LEFT && rBox.GetLeft())
2360 {
2361 break;
2362 }
2363
2364 if (eType == VerticalType::RIGHT && rBox.GetRight())
2365 {
2366 break;
2367 }
2368
2369 mnLimitedEndPos = pCoveredCell->getFrameArea().Top();
2370 }
2371}
2372
2373namespace {
2374
2375struct lt_SwLineEntry
2376{
2377 bool operator()( const SwLineEntry& e1, const SwLineEntry& e2 ) const
2378 {
2379 return e1.mnStartPos < e2.mnStartPos;
2380 }
2381};
2382
2383}
2384
2385typedef std::set< SwLineEntry, lt_SwLineEntry > SwLineEntrySet;
2386typedef std::map< SwTwips, SwLineEntrySet > SwLineEntryMap;
2387
2388namespace {
2389
2390class SwTabFramePainter
2391{
2392 SwLineEntryMap maVertLines;
2393 SwLineEntryMap maHoriLines;
2394 const SwTabFrame& mrTabFrame;
2395
2396 void Insert( SwLineEntry&, bool bHori );
2397 void Insert(const SwFrame& rFrame, const SvxBoxItem& rBoxItem, const SwRect &rPaintArea);
2398 void HandleFrame(const SwLayoutFrame& rFrame, const SwRect& rPaintArea);
2399 void FindStylesForLine( Point&,
2400 Point&,
2402 bool bHori,
2403 bool bOuter ) const;
2404
2405public:
2406 explicit SwTabFramePainter( const SwTabFrame& rTabFrame );
2407
2408 void PaintLines( OutputDevice& rDev, const SwRect& rRect ) const;
2409};
2410
2411}
2412
2413SwTabFramePainter::SwTabFramePainter( const SwTabFrame& rTabFrame )
2414 : mrTabFrame( rTabFrame )
2415{
2416 SwRect aPaintArea = rTabFrame.GetUpper()->GetPaintArea();
2417 HandleFrame(rTabFrame, aPaintArea);
2418}
2419
2420void SwTabFramePainter::HandleFrame(const SwLayoutFrame& rLayoutFrame, const SwRect& rPaintArea)
2421{
2422 // Add border lines of cell frames. Skip covered cells. Skip cells
2423 // in special row span row, which do not have a negative row span:
2424 if ( rLayoutFrame.IsCellFrame() && !rLayoutFrame.IsCoveredCell() )
2425 {
2426 const SwCellFrame* pThisCell = static_cast<const SwCellFrame*>(&rLayoutFrame);
2427 const SwRowFrame* pRowFrame = static_cast<const SwRowFrame*>(pThisCell->GetUpper());
2428 const tools::Long nRowSpan = pThisCell->GetTabBox()->getRowSpan();
2429 if ( !pRowFrame->IsRowSpanLine() || nRowSpan > 1 || nRowSpan < -1 )
2430 {
2431 SwBorderAttrAccess aAccess( SwFrame::GetCache(), &rLayoutFrame );
2432 const SwBorderAttrs& rAttrs = *aAccess.Get();
2433 const SvxBoxItem& rBox = rAttrs.GetBox();
2434 Insert(rLayoutFrame, rBox, rPaintArea);
2435 }
2436 }
2437
2438 // Recurse into lower layout frames, but do not recurse into lower tabframes.
2439 const SwFrame* pLower = rLayoutFrame.Lower();
2440 while ( pLower )
2441 {
2442 if (pLower->IsLayoutFrame() && !pLower->IsTabFrame())
2443 {
2444 const SwLayoutFrame* pLowerLayFrame = static_cast<const SwLayoutFrame*>(pLower);
2445 HandleFrame(*pLowerLayFrame, rPaintArea);
2446 }
2447 pLower = pLower->GetNext();
2448 }
2449}
2450
2451void SwTabFramePainter::PaintLines(OutputDevice& rDev, const SwRect& rRect) const
2452{
2453 // #i16816# tagged pdf support
2454 SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, rDev );
2455
2456 SwLineEntryMap::const_iterator aIter = maHoriLines.begin();
2457 bool bHori = true;
2458
2459 // color for subsidiary lines:
2460 const Color& rCol( gProp.pSGlobalShell->GetViewOptions()->GetTableBoundariesColor() );
2461
2462 // high contrast mode:
2463 // overrides the color of non-subsidiary lines.
2464 const Color* pHCColor = nullptr;
2465 DrawModeFlags nOldDrawMode = rDev.GetDrawMode();
2466 if( gProp.pSGlobalShell->GetWin() &&
2468 {
2469 pHCColor = &gProp.pSGlobalShell->GetViewOptions()->GetFontColor();
2470 rDev.SetDrawMode( DrawModeFlags::Default );
2471 }
2472
2473 const SwFrame* pUpper = mrTabFrame.GetUpper();
2474 SwRect aUpper( pUpper->getFramePrintArea() );
2475 aUpper.Pos() += pUpper->getFrameArea().Pos();
2476 SwRect aUpperAligned( aUpper );
2477 ::SwAlignRect( aUpperAligned, gProp.pSGlobalShell, &rDev );
2478
2479 // prepare SdrFrameBorderDataVector
2481
2482 while ( true )
2483 {
2484 if ( bHori && aIter == maHoriLines.end() )
2485 {
2486 aIter = maVertLines.begin();
2487 bHori = false;
2488 }
2489
2490 if ( !bHori && aIter == maVertLines.end() )
2491 break;
2492
2493 const SwLineEntrySet& rEntrySet = (*aIter).second;
2494 for (const SwLineEntry& rEntry : rEntrySet)
2495 {
2496 const svx::frame::Style& rEntryStyle( rEntry.maAttribute );
2497
2498 Point aStart, aEnd;
2499 if ( bHori )
2500 {
2501 aStart.setX( rEntry.mnStartPos );
2502 aStart.setY( rEntry.mnKey );
2503 aEnd.setX( rEntry.mnEndPos );
2504 aEnd.setY( rEntry.mnKey );
2505 }
2506 else
2507 {
2508 aStart.setX( rEntry.mnKey );
2509 aStart.setY( rEntry.mnStartPos );
2510 aEnd.setX( rEntry.mnKey );
2511 aEnd.setY( rEntry.mnEndPos );
2512 }
2513
2514 svx::frame::Style aStyles[ 7 ];
2515 aStyles[ 0 ] = rEntryStyle;
2516 FindStylesForLine(aStart, aEnd, aStyles, bHori, rEntry.mbOuter);
2517
2518 if (!bHori && rEntry.mnLimitedEndPos)
2519 {
2520 aEnd.setY(rEntry.mnLimitedEndPos);
2521 }
2522
2523 SwRect aRepaintRect( aStart, aEnd );
2524
2525 // the repaint rectangle has to be moved a bit for the centered lines:
2526 SwTwips nRepaintRectSize = !rEntryStyle.GetWidth() ? 1 : rEntryStyle.GetWidth();
2527 if ( bHori )
2528 {
2529 aRepaintRect.Height( 2 * nRepaintRectSize );
2530 aRepaintRect.Pos().AdjustY( -nRepaintRectSize );
2531
2532 // To decide on visibility it is also necessary to expand the RepaintRect
2533 // to left/right according existing BorderLine overlap matchings, else there
2534 // will be repaint errors when scrolling in e.t TripleLine BorderLines.
2535 // aStyles[1] == aLFromT, aStyles[3] == aLFromB, aStyles[4] == aRFromT, aStyles[6] == aRFromB
2536 if(aStyles[1].IsUsed() || aStyles[3].IsUsed() || aStyles[4].IsUsed() || aStyles[6].IsUsed())
2537 {
2538 const double fLineWidthMaxLeft(std::max(aStyles[1].GetWidth(), aStyles[3].GetWidth()));
2539 const double fLineWidthMaxRight(std::max(aStyles[4].GetWidth(), aStyles[6].GetWidth()));
2540 aRepaintRect.Width(aRepaintRect.Width() + (fLineWidthMaxLeft + fLineWidthMaxRight));
2541 aRepaintRect.Pos().AdjustX( -fLineWidthMaxLeft );
2542 }
2543 }
2544 else
2545 {
2546 aRepaintRect.Width( 2 * nRepaintRectSize );
2547 aRepaintRect.Pos().AdjustX( -nRepaintRectSize );
2548
2549 // Accordingly to horizontal case, but for top/bottom
2550 // aStyles[3] == aTFromR, aStyles[1] == aTFromL, aStyles[6] == aBFromR, aStyles[4] == aBFromL
2551 if(aStyles[3].IsUsed() || aStyles[1].IsUsed() || aStyles[6].IsUsed() || aStyles[4].IsUsed())
2552 {
2553 const double fLineWidthMaxTop(std::max(aStyles[3].GetWidth(), aStyles[1].GetWidth()));
2554 const double fLineWidthMaxBottom(std::max(aStyles[6].GetWidth(), aStyles[4].GetWidth()));
2555 aRepaintRect.Height(aRepaintRect.Height() + (fLineWidthMaxTop + fLineWidthMaxBottom));
2556 aRepaintRect.Pos().AdjustY( -fLineWidthMaxTop );
2557 }
2558 }
2559
2560 if (!rRect.Overlaps(aRepaintRect))
2561 {
2562 continue;
2563 }
2564
2565 // subsidiary lines
2566 const Color* pTmpColor = nullptr;
2567 if (0 == aStyles[ 0 ].GetWidth())
2568 {
2569 if (isTableBoundariesEnabled() && gProp.pSGlobalShell->GetWin())
2570 aStyles[ 0 ].Set( rCol, rCol, rCol, false, 1, 0, 0 );
2571 else
2572 aStyles[0].SetType(SvxBorderLineStyle::NONE);
2573 }
2574 else
2575 pTmpColor = pHCColor;
2576
2577 // The (twip) positions will be adjusted to meet these requirements:
2578 // 1. The y coordinates are located in the middle of the pixel grid
2579 // 2. The x coordinated are located at the beginning of the pixel grid
2580 // This is done, because the horizontal lines are painted "at
2581 // beginning", whereas the vertical lines are painted "centered".
2582 // By making the line sizes a multiple of one pixel size, we can
2583 // assure that all lines having the same twip size have the same
2584 // pixel size, independent of their position on the screen.
2585 Point aPaintStart = rDev.PixelToLogic( rDev.LogicToPixel(aStart) );
2586 Point aPaintEnd = rDev.PixelToLogic( rDev.LogicToPixel(aEnd) );
2587
2588 if (gProp.pSGlobalShell->GetWin())
2589 {
2590 // The table borders do not use SwAlignRect, but all the other frames do.
2591 // Therefore we tweak the outer borders a bit to achieve that the outer
2592 // borders match the subsidiary lines of the upper:
2593 if (aStart.X() == aUpper.Left())
2594 aPaintStart.setX( aUpperAligned.Left() );
2595 else if (aStart.X() == aUpper.Right_())
2596 aPaintStart.setX( aUpperAligned.Right_() );
2597 if (aStart.Y() == aUpper.Top())
2598 aPaintStart.setY( aUpperAligned.Top() );
2599 else if (aStart.Y() == aUpper.Bottom_())
2600 aPaintStart.setY( aUpperAligned.Bottom_() );
2601
2602 if (aEnd.X() == aUpper.Left())
2603 aPaintEnd.setX( aUpperAligned.Left() );
2604 else if (aEnd.X() == aUpper.Right_())
2605 aPaintEnd.setX( aUpperAligned.Right_() );
2606 if (aEnd.Y() == aUpper.Top())
2607 aPaintEnd.setY( aUpperAligned.Top() );
2608 else if (aEnd.Y() == aUpper.Bottom_())
2609 aPaintEnd.setY( aUpperAligned.Bottom_() );
2610 }
2611
2612 if(aStyles[0].IsUsed())
2613 {
2614 if (bHori)
2615 {
2616 const basegfx::B2DPoint aOrigin(aPaintStart.X(), aPaintStart.Y());
2617 const basegfx::B2DVector aX(basegfx::B2DPoint(aPaintEnd.X(), aPaintEnd.Y()) - aOrigin);
2618
2619 if(!aX.equalZero())
2620 {
2622 aData.emplace_back(
2623 aOrigin,
2624 aX,
2625 aStyles[0],
2626 pTmpColor);
2628
2629 rInstance.addSdrConnectStyleData(true, aStyles[1], -aY, true); // aLFromT
2630 rInstance.addSdrConnectStyleData(true, aStyles[2], -aX, true); // aLFromL
2631 rInstance.addSdrConnectStyleData(true, aStyles[3], aY, false); // aLFromB
2632
2633 rInstance.addSdrConnectStyleData(false, aStyles[4], -aY, true); // aRFromT
2634 rInstance.addSdrConnectStyleData(false, aStyles[5], aX, false); // aRFromR
2635 rInstance.addSdrConnectStyleData(false, aStyles[6], aY, false); // aRFromB
2636 }
2637 }
2638 else // vertical
2639 {
2640 const basegfx::B2DPoint aOrigin(aPaintStart.X(), aPaintStart.Y());
2641 const basegfx::B2DVector aX(basegfx::B2DPoint(aPaintEnd.X(), aPaintEnd.Y()) - aOrigin);
2642
2643 if(!aX.equalZero())
2644 {
2646 aData.emplace_back(
2647 aOrigin,
2648 aX,
2649 aStyles[0],
2650 pTmpColor);
2652
2653 rInstance.addSdrConnectStyleData(true, aStyles[3], -aY, false); // aTFromR
2654 rInstance.addSdrConnectStyleData(true, aStyles[2], -aX, true); // aTFromT
2655 rInstance.addSdrConnectStyleData(true, aStyles[1], aY, true); // aTFromL
2656
2657 rInstance.addSdrConnectStyleData(false, aStyles[6], -aY, false); // aBFromR
2658 rInstance.addSdrConnectStyleData(false, aStyles[5], aX, false); // aBFromB
2659 rInstance.addSdrConnectStyleData(false, aStyles[4], aY, true); // aBFromL
2660 }
2661 }
2662 }
2663 }
2664 ++aIter;
2665 }
2666
2667 // create instance of SdrFrameBorderPrimitive2D if
2668 // SdrFrameBorderDataVector is used
2669 if(!aData.empty())
2670 {
2672 aSequence.append(
2675 std::move(aData),
2676 true))); // force visualization to minimal one discrete unit (pixel)
2677 // paint
2678 mrTabFrame.ProcessPrimitives(aSequence);
2679 }
2680
2681 // restore output device:
2682 rDev.SetDrawMode( nOldDrawMode );
2683}
2684
2690void SwTabFramePainter::FindStylesForLine( Point& rStartPoint,
2691 Point& rEndPoint,
2692 svx::frame::Style* pStyles,
2693 bool bHori, bool bOuter ) const
2694{
2695 // For example, aLFromB means: this vertical line intersects my horizontal line at its left end,
2696 // from bottom.
2697 // pStyles[ 1 ] = bHori ? aLFromT : TFromL
2698 // pStyles[ 2 ] = bHori ? aLFromL : TFromT,
2699 // pStyles[ 3 ] = bHori ? aLFromB : TFromR,
2700 // pStyles[ 4 ] = bHori ? aRFromT : BFromL,
2701 // pStyles[ 5 ] = bHori ? aRFromR : BFromB,
2702 // pStyles[ 6 ] = bHori ? aRFromB : BFromR,
2703
2704 bool bWordTableCell = false;
2705 SwViewShell* pShell = mrTabFrame.getRootFrame()->GetCurrShell();
2706 if (pShell)
2707 {
2708 const IDocumentSettingAccess& rIDSA = pShell->GetDoc()->getIDocumentSettingAccess();
2709 bWordTableCell = rIDSA.get(DocumentSettingId::TABLE_ROW_KEEP);
2710 }
2711
2712 SwLineEntryMap::const_iterator aMapIter = maVertLines.find( rStartPoint.X() );
2713 OSL_ENSURE( aMapIter != maVertLines.end(), "FindStylesForLine: Error" );
2714 const SwLineEntrySet& rVertSet = (*aMapIter).second;
2715
2716 for ( const SwLineEntry& rEntry : rVertSet )
2717 {
2718 if ( bHori )
2719 {
2720 if ( rStartPoint.Y() == rEntry.mnStartPos )
2721 pStyles[ 3 ] = rEntry.maAttribute;
2722 else if ( rStartPoint.Y() == rEntry.mnEndPos )
2723 pStyles[ 1 ] = rEntry.maAttribute;
2724
2725 if (bWordTableCell && rStartPoint.X() == rEntry.mnKey && !bOuter && rEntry.mbOuter)
2726 {
2727 rStartPoint.AdjustX(rEntry.maAttribute.GetWidth());
2728 }
2729 }
2730 else
2731 {
2732 if ( rStartPoint.Y() == rEntry.mnEndPos )
2733 pStyles[ 2 ] = rEntry.maAttribute;
2734 else if ( rEndPoint.Y() == rEntry.mnStartPos )
2735 pStyles[ 5 ] = rEntry.maAttribute;
2736 }
2737 }
2738
2739 aMapIter = maHoriLines.find( rStartPoint.Y() );
2740 OSL_ENSURE( aMapIter != maHoriLines.end(), "FindStylesForLine: Error" );
2741 const SwLineEntrySet& rHoriSet = (*aMapIter).second;
2742
2743 for ( const SwLineEntry& rEntry : rHoriSet )
2744 {
2745 if ( bHori )
2746 {
2747 if ( rStartPoint.X() == rEntry.mnEndPos )
2748 pStyles[ 2 ] = rEntry.maAttribute;
2749 else if ( rEndPoint.X() == rEntry.mnStartPos )
2750 pStyles[ 5 ] = rEntry.maAttribute;
2751 }
2752 else
2753 {
2754 if ( rStartPoint.X() == rEntry.mnEndPos )
2755 pStyles[ 1 ] = rEntry.maAttribute;
2756 else if ( rStartPoint.X() == rEntry.mnStartPos )
2757 pStyles[ 3 ] = rEntry.maAttribute;
2758
2759 if (bWordTableCell && rStartPoint.Y() == rEntry.mnKey && !bOuter && rEntry.mbOuter)
2760 {
2761 rStartPoint.AdjustY(rEntry.maAttribute.GetWidth());
2762 }
2763 }
2764 }
2765
2766 if ( bHori )
2767 {
2768 aMapIter = maVertLines.find( rEndPoint.X() );
2769 OSL_ENSURE( aMapIter != maVertLines.end(), "FindStylesForLine: Error" );
2770 const SwLineEntrySet& rVertSet2 = (*aMapIter).second;
2771
2772 for ( const SwLineEntry& rEntry : rVertSet2 )
2773 {
2774 if ( rEndPoint.Y() == rEntry.mnStartPos )
2775 pStyles[ 6 ] = rEntry.maAttribute;
2776 else if ( rEndPoint.Y() == rEntry.mnEndPos )
2777 pStyles[ 4 ] = rEntry.maAttribute;
2778
2779 if (bWordTableCell && rEndPoint.X() == rEntry.mnKey && !bOuter && rEntry.mbOuter)
2780 {
2781 rEndPoint.AdjustX(-rEntry.maAttribute.GetWidth());
2782 }
2783 }
2784 }
2785 else
2786 {
2787 aMapIter = maHoriLines.find( rEndPoint.Y() );
2788 OSL_ENSURE( aMapIter != maHoriLines.end(), "FindStylesForLine: Error" );
2789 const SwLineEntrySet& rHoriSet2 = (*aMapIter).second;
2790
2791 for ( const SwLineEntry& rEntry : rHoriSet2 )
2792 {
2793 if ( rEndPoint.X() == rEntry.mnEndPos )
2794 pStyles[ 4 ] = rEntry.maAttribute;
2795 else if ( rEndPoint.X() == rEntry.mnStartPos )
2796 pStyles[ 6 ] = rEntry.maAttribute;
2797
2798 if (bWordTableCell && rEndPoint.Y() == rEntry.mnKey && !bOuter && rEntry.mbOuter)
2799 {
2800 rEndPoint.AdjustY(-rEntry.maAttribute.GetWidth());
2801 }
2802 }
2803 }
2804}
2805
2813 SwTabFrame const& rTabFrame, SwFrame const& rFrame, SvxBoxItem const& rBoxItem)
2814{
2815 SwRowFrame const*const pThisRowFrame =
2816 dynamic_cast<const SwRowFrame*>(rFrame.GetUpper());
2817 return (pThisRowFrame
2818 && (pThisRowFrame->GetUpper() == &rTabFrame)
2819 && ( rTabFrame.IsFollow()
2820 // tdf#150308 first table row isn't equal to the table row of the first
2821 // row frame of the first table frame: there are invisible deleted rows
2822 // in Hide Changes mode before the first visible table row
2823 || rTabFrame.GetTable()->GetTabLines().front() != pThisRowFrame->GetTabLine() )
2824 && !rTabFrame.GetTable()->GetRowsToRepeat()
2825 && ( !pThisRowFrame->GetPrev()
2826 || static_cast<const SwRowFrame*>(pThisRowFrame->GetPrev())
2827 ->IsRowSpanLine())
2828 && !rBoxItem.GetTop()
2829 && rBoxItem.GetBottom());
2830}
2831
2832void SwTabFramePainter::Insert(const SwFrame& rFrame, const SvxBoxItem& rBoxItem, const SwRect& rPaintArea)
2833{
2834 // build 4 line entries for the 4 borders:
2835 SwRect aBorderRect = rFrame.getFrameArea();
2836
2837 aBorderRect.Intersection(rPaintArea);
2838
2840 mrTabFrame, rFrame, rBoxItem));
2841 bool const bVert = mrTabFrame.IsVertical();
2842 bool const bR2L = mrTabFrame.IsRightToLeft();
2843
2844 bool bWordTableCell = false;
2845 SwViewShell* pShell = rFrame.getRootFrame()->GetCurrShell();
2846 if (pShell)
2847 {
2848 const IDocumentSettingAccess& rIDSA = pShell->GetDoc()->getIDocumentSettingAccess();
2849 bWordTableCell = rIDSA.get(DocumentSettingId::TABLE_ROW_KEEP);
2850 }
2851
2852 // no scaling needed, it's all in the primitives and the target device
2854 aL.SetWordTableCell(bWordTableCell);
2856 aR.SetWordTableCell(bWordTableCell);
2858 aT.SetWordTableCell(bWordTableCell);
2860 aB.SetWordTableCell(bWordTableCell);
2861
2862 // First cell in a row.
2863 bool bLeftIsOuter = rFrame.IsCellFrame() && rFrame.GetUpper()->GetLower() == &rFrame;
2864 // Last cell in a row.
2865 bool bRightIsOuter = rFrame.IsCellFrame() && rFrame.GetNext() == nullptr;
2866 // First row in a table.
2867 bool bTopIsOuter = rFrame.IsCellFrame() && rFrame.GetUpper()->GetUpper()->GetLower() == rFrame.GetUpper();
2868 // Last row in a table.
2869 bool bBottomIsOuter = rFrame.IsCellFrame() && rFrame.GetUpper()->GetNext() == nullptr;
2870
2871 aR.MirrorSelf();
2872 if (!bWordTableCell || !bBottomIsOuter)
2873 {
2874 // Outer horizontal lines are never mirrored in Word.
2875 aB.MirrorSelf();
2876 }
2877
2878 const SwTwips nLeft = aBorderRect.Left_();
2879 const SwTwips nRight = aBorderRect.Right_();
2880 const SwTwips nTop = aBorderRect.Top_();
2881 const SwTwips nBottom = aBorderRect.Bottom_();
2882
2883 aL.SetRefMode( svx::frame::RefMode::Centered );
2884 aR.SetRefMode( svx::frame::RefMode::Centered );
2885 aT.SetRefMode( !bVert ? svx::frame::RefMode::Begin : svx::frame::RefMode::End );
2886 aB.SetRefMode( !bVert ? svx::frame::RefMode::Begin : svx::frame::RefMode::End );
2887
2888 if (bWordTableCell && bLeftIsOuter)
2889 {
2890 // Outer vertical lines are always mirrored in Word.
2891 aL.MirrorSelf();
2892 }
2893
2894 SwLineEntry aLeft (nLeft, nTop, nBottom, bLeftIsOuter,
2895 bVert ? aB : (bR2L ? aR : aL));
2896 if (bWordTableCell && rBoxItem.GetLeft())
2897 {
2898 aLeft.LimitVerticalEndPos(rFrame, SwLineEntry::VerticalType::LEFT);
2899 }
2900
2901 SwLineEntry aRight (nRight, nTop, nBottom, bRightIsOuter,
2902 bVert ? (bBottomAsTop ? aB : aT) : (bR2L ? aL : aR));
2903 if (bWordTableCell && rBoxItem.GetRight())
2904 {
2905 aRight.LimitVerticalEndPos(rFrame, SwLineEntry::VerticalType::RIGHT);
2906 }
2907
2908 SwLineEntry aTop (nTop, nLeft, nRight, bTopIsOuter,
2909 bVert ? aL : (bBottomAsTop ? aB : aT));
2910
2911 SwLineEntry aBottom(nBottom, nLeft, nRight, bBottomIsOuter,
2912 bVert ? aR : aB);
2913
2914 Insert( aLeft, false );
2915 Insert( aRight, false );
2916 Insert( aTop, true );
2917 Insert( aBottom, true );
2918}
2919
2920void SwTabFramePainter::Insert( SwLineEntry& rNew, bool bHori )
2921{
2922 // get all lines from structure, that have key entry of pLE
2923 SwLineEntryMap* pLine2 = bHori ? &maHoriLines : &maVertLines;
2924 const SwTwips nKey = rNew.mnKey;
2925 SwLineEntryMap::iterator aMapIter = pLine2->find( nKey );
2926
2927 SwLineEntrySet* pLineSet = aMapIter != pLine2->end() ? &((*aMapIter).second) : nullptr;
2928 if ( !pLineSet )
2929 {
2930 SwLineEntrySet aNewSet;
2931 (*pLine2)[ nKey ] = aNewSet;
2932 pLineSet = &(*pLine2)[ nKey ];
2933 }
2934 SwLineEntrySet::iterator aIter = pLineSet->begin();
2935
2936 bool bWordTableCell = false;
2937 SwViewShell* pShell = mrTabFrame.getRootFrame()->GetCurrShell();
2938 if (pShell)
2939 {
2940 const IDocumentSettingAccess& rIDSA = pShell->GetDoc()->getIDocumentSettingAccess();
2941 bWordTableCell = rIDSA.get(DocumentSettingId::TABLE_ROW_KEEP);
2942 }
2943 while ( aIter != pLineSet->end() && rNew.mnStartPos < rNew.mnEndPos )
2944 {
2945 const SwLineEntry& rOld = *aIter;
2946
2947 if (rOld.mnLimitedEndPos || (bWordTableCell && (rOld.mbOuter != rNew.mbOuter)))
2948 {
2949 // Don't merge with this line entry as it ends sooner than mnEndPos.
2950 ++aIter;
2951 continue;
2952 }
2953
2954 const SwLineEntry::OverlapType nOverlapType = rOld.Overlaps( rNew );
2955
2956 const svx::frame::Style& rOldAttr = rOld.maAttribute;
2957 const svx::frame::Style& rNewAttr = rNew.maAttribute;
2958 const svx::frame::Style& rCmpAttr = std::max(rNewAttr, rOldAttr);
2959
2960 if ( SwLineEntry::OVERLAP1 == nOverlapType )
2961 {
2962 OSL_ENSURE( rNew.mnStartPos >= rOld.mnStartPos, "Overlap type 3? How this?" );
2963
2964 // new left segment
2965 const SwLineEntry aLeft(nKey, rOld.mnStartPos, rNew.mnStartPos, rOld.mbOuter, rOldAttr);
2966
2967 // new middle segment
2968 const SwLineEntry aMiddle(nKey, rNew.mnStartPos, rOld.mnEndPos, rOld.mbOuter, rCmpAttr);
2969
2970 // new right segment
2971 rNew.mnStartPos = rOld.mnEndPos;
2972
2973 // update current lines set
2974 pLineSet->erase( aIter );
2975 if ( aLeft.mnStartPos < aLeft.mnEndPos ) pLineSet->insert( aLeft );
2976 if ( aMiddle.mnStartPos < aMiddle.mnEndPos ) pLineSet->insert( aMiddle );
2977
2978 aIter = pLineSet->begin();
2979
2980 continue; // start over
2981 }
2982 else if ( SwLineEntry::OVERLAP2 == nOverlapType )
2983 {
2984 // new left segment
2985 const SwLineEntry aLeft(nKey, rOld.mnStartPos, rNew.mnStartPos, rOld.mbOuter, rOldAttr);
2986
2987 // new middle segment
2988 const SwLineEntry aMiddle(nKey, rNew.mnStartPos, rNew.mnEndPos, rOld.mbOuter, rCmpAttr);
2989
2990 // new right segment
2991 const SwLineEntry aRight(nKey, rNew.mnEndPos, rOld.mnEndPos, rOld.mbOuter, rOldAttr);
2992
2993 // update current lines set
2994 pLineSet->erase( aIter );
2995 if ( aLeft.mnStartPos < aLeft.mnEndPos ) pLineSet->insert( aLeft );
2996 if ( aMiddle.mnStartPos < aMiddle.mnEndPos ) pLineSet->insert( aMiddle );
2997 if ( aRight.mnStartPos < aRight.mnEndPos ) pLineSet->insert( aRight );
2998
2999 rNew.mnStartPos = rNew.mnEndPos; // rNew should not be inserted!
3000
3001 break; // we are finished
3002 }
3003 else if ( SwLineEntry::OVERLAP3 == nOverlapType )
3004 {
3005 // new left segment
3006 const SwLineEntry aLeft(nKey, rNew.mnStartPos, rOld.mnStartPos, rOld.mbOuter, rNewAttr);
3007
3008 // new middle segment
3009 const SwLineEntry aMiddle(nKey, rOld.mnStartPos, rNew.mnEndPos, rOld.mbOuter, rCmpAttr);
3010
3011 // new right segment
3012 const SwLineEntry aRight(nKey, rNew.mnEndPos, rOld.mnEndPos, rOld.mbOuter, rOldAttr);
3013
3014 // update current lines set
3015 pLineSet->erase( aIter );
3016 if ( aLeft.mnStartPos < aLeft.mnEndPos ) pLineSet->insert( aLeft );
3017 if ( aMiddle.mnStartPos < aMiddle.mnEndPos ) pLineSet->insert( aMiddle );
3018 if ( aRight.mnStartPos < aRight.mnEndPos ) pLineSet->insert( aRight );
3019
3020 rNew.mnStartPos = rNew.mnEndPos; // rNew should not be inserted!
3021
3022 break; // we are finished
3023 }
3024
3025 ++aIter;
3026 }
3027
3028 if ( rNew.mnStartPos < rNew.mnEndPos ) // insert rest
3029 pLineSet->insert( rNew );
3030}
3031
3036namespace
3037{
3038 class SwViewObjectContactRedirector : public sdr::contact::ViewObjectContactRedirector
3039 {
3040 private:
3041 const SwViewShell& mrViewShell;
3042
3043 public:
3044 explicit SwViewObjectContactRedirector( const SwViewShell& rSh )
3045 : mrViewShell( rSh )
3046 {};
3047
3049 const sdr::contact::ViewObjectContact& rOriginal,
3050 const sdr::contact::DisplayInfo& rDisplayInfo,
3052 {
3053 bool bPaint( true );
3054
3055 SdrObject* pObj = rOriginal.GetViewContact().TryToGetSdrObject();
3056 if ( pObj )
3057 {
3058 bPaint = SwFlyFrame::IsPaint( pObj, &mrViewShell );
3059 }
3060
3061 if ( !bPaint )
3062 {
3063 return;
3064 }
3065
3067 rOriginal, rDisplayInfo, rVisitor );
3068 }
3069 };
3070
3071} // end of anonymous namespace
3072// <--
3073
3083void SwRootFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& rRect, SwPrintData const*const pPrintData) const
3084{
3085 OSL_ENSURE( Lower() && Lower()->IsPageFrame(), "Lower of root is no page." );
3086
3087 PROTOCOL( this, PROT::FileInit, DbgAction::NONE, nullptr)
3088
3089 bool bResetRootPaint = false;
3090 SwViewShell *pSh = mpCurrShell;
3091
3092 if ( pSh->GetWin() )
3093 {
3094 if ( pSh->GetOut() == pSh->GetWin()->GetOutDev() && !pSh->GetWin()->IsVisible() )
3095 {
3096 return;
3097 }
3099 {
3100 SwPaintQueue::Add( pSh, rRect );
3101 return;
3102 }
3103 }
3104 else
3105 SwRootFrame::s_isInPaint = bResetRootPaint = true;
3106
3107 std::unique_ptr<SwSavePaintStatics> pStatics;
3108 if ( gProp.pSGlobalShell )
3109 pStatics.reset(new SwSavePaintStatics());
3110 gProp.pSGlobalShell = pSh;
3111
3112 if( !pSh->GetWin() )
3113 gProp.pSProgress = SfxProgress::GetActiveProgress( static_cast<SfxObjectShell*>(pSh->GetDoc()->GetDocShell()) );
3114
3115 ::SwCalcPixStatics( pSh->GetOut() );
3117
3118 // Copy rRect; for one, rRect could become dangling during the below action, and for another it
3119 // needs to be copied to aRect anyway as that is modified further down below:
3120 SwRect aRect( rRect );
3121
3122 //Trigger an action to clear things up if needed.
3123 //Using this trick we can ensure that all values are valid in all paints -
3124 //no problems, no special case(s).
3125 // #i92745#
3126 // Extend check on certain states of the 'current' <SwViewShell> instance to
3127 // all existing <SwViewShell> instances.
3128 bool bPerformLayoutAction( true );
3129 {
3130 for(SwViewShell& rTmpViewShell : pSh->GetRingContainer())
3131 {
3132 if ( rTmpViewShell.IsInEndAction() ||
3133 rTmpViewShell.IsPaintInProgress() ||
3134 ( rTmpViewShell.Imp()->IsAction() &&
3135 rTmpViewShell.Imp()->GetLayAction().IsActionInProgress() ) )
3136 {
3137 bPerformLayoutAction = false;
3138 }
3139
3140 if(!bPerformLayoutAction)
3141 break;
3142 }
3143 }
3144 if ( bPerformLayoutAction )
3145 {
3146 const_cast<SwRootFrame*>(this)->ResetTurbo();
3147 SwLayAction aAction( const_cast<SwRootFrame*>(this), pSh->Imp() );
3148 aAction.SetPaint( false );
3149 aAction.SetComplete( false );
3150 aAction.SetReschedule( gProp.pSProgress != nullptr );
3151 aAction.Action(&rRenderContext);
3153 if ( !pSh->ActionPend() )
3154 pSh->Imp()->DeletePaintRegion();
3155 }
3156
3157 aRect.Intersection( pSh->VisArea() );
3158
3159 const bool bExtraData = ::IsExtraData( GetFormat()->GetDoc() );
3160
3161 gProp.pSLines.reset(new SwLineRects); // Container for borders.
3162
3163 // #104289#. During painting, something (OLE) can
3164 // load the linguistic, which in turn can cause a reformat
3165 // of the document. Dangerous! We better set this flag to
3166 // avoid the reformat.
3167 const bool bOldAction = IsCallbackActionEnabled();
3168 const_cast<SwRootFrame*>(this)->SetCallbackActionEnabled( false );
3169
3170 const SwPageFrame *pPage = pSh->Imp()->GetFirstVisPage(&rRenderContext);
3171
3172 // #126222. The positions of headers and footers of the previous
3173 // pages have to be updated, else these headers and footers could
3174 // get visible at a wrong position.
3175 const SwPageFrame *pPageDeco = static_cast<const SwPageFrame*>(pPage->GetPrev());
3176 while (pPageDeco)
3177 {
3178 pPageDeco->PaintDecorators();
3179 OSL_ENSURE(!pPageDeco->GetPrev() || pPageDeco->GetPrev()->IsPageFrame(),
3180 "Neighbour of page is not a page.");
3181 pPageDeco = static_cast<const SwPageFrame*>(pPageDeco->GetPrev());
3182 }
3183
3184 const bool bBookMode = gProp.pSGlobalShell->GetViewOptions()->IsViewLayoutBookMode();
3185 if ( bBookMode && pPage->GetPrev() && static_cast<const SwPageFrame*>(pPage->GetPrev())->IsEmptyPage() )
3186 pPage = static_cast<const SwPageFrame*>(pPage->GetPrev());
3187
3188 // #i68597#
3189 const bool bGridPainting(pSh->GetWin() && pSh->Imp()->HasDrawView() && pSh->Imp()->GetDrawView()->IsGridVisible());
3190
3191 // Hide all page break controls before showing them again
3192 SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >( gProp.pSGlobalShell );
3193 if ( pWrtSh )
3194 {
3195 SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
3197 const SwPageFrame* pHiddenPage = pPage;
3198 while ( pHiddenPage->GetPrev() != nullptr )
3199 {
3200 pHiddenPage = static_cast< const SwPageFrame* >( pHiddenPage->GetPrev() );
3201 SwFrameControlPtr pControl = rMngr.GetControl( FrameControlType::PageBreak, pHiddenPage );
3202 if ( pControl )
3203 pControl->ShowAll( false );
3204 }
3205 }
3206
3207 // #i76669#
3208 SwViewObjectContactRedirector aSwRedirector( *pSh );
3209
3210 while ( pPage )
3211 {
3212 const bool bPaintRightShadow = pPage->IsRightShadowNeeded();
3213 const bool bPaintLeftShadow = pPage->IsLeftShadowNeeded();
3214 const bool bRightSidebar = pPage->SidebarPosition() == sw::sidebarwindows::SidebarPosition::RIGHT;
3215
3216 if ( !pPage->IsEmptyPage() )
3217 {
3218 SwRect aPaintRect;
3219 SwPageFrame::GetBorderAndShadowBoundRect( pPage->getFrameArea(), pSh, &rRenderContext, aPaintRect,
3220 bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
3221
3222 if ( aRect.Overlaps( aPaintRect ) )
3223 {
3224 if ( pSh->GetWin() )
3225 {
3226 gProp.pSSubsLines.reset(new SwSubsRects);
3227 gProp.pSSpecSubsLines.reset(new SwSubsRects);
3228 }
3229 gProp.pBLines.reset(new BorderLines);
3230
3231 aPaintRect.Intersection_( aRect );
3232
3233 if ( bExtraData &&
3234 pSh->GetWin() && pSh->IsInEndAction() )
3235 {
3236 // enlarge paint rectangle to complete page width, subtract
3237 // current paint area and invalidate the resulting region.
3238 SwRectFnSet aRectFnSet(pPage);
3239 SwRect aPageRectTemp( aPaintRect );
3240 aRectFnSet.SetLeftAndWidth( aPageRectTemp,
3241 aRectFnSet.GetLeft(pPage->getFrameArea()),
3242 aRectFnSet.GetWidth(pPage->getFrameArea()) );
3243 aPageRectTemp.Intersection_( pSh->VisArea() );
3244 vcl::Region aPageRectRegion( aPageRectTemp.SVRect() );
3245 aPageRectRegion.Exclude( aPaintRect.SVRect() );
3246 pSh->GetWin()->Invalidate( aPageRectRegion, InvalidateFlags::Children );
3247 }
3248
3249 // #i80793#
3250 // enlarge paint rectangle for objects overlapping the same pixel
3251 // in all cases and before the DrawingLayer overlay is initialized.
3252 lcl_AdjustRectToPixelSize( aPaintRect, *(pSh->GetOut()) );
3253
3254 // #i68597#
3255 // moved paint pre-process for DrawingLayer overlay here since the above
3256 // code dependent from bExtraData may expand the PaintRect
3257 {
3258 // #i75172# if called from SwViewShell::ImplEndAction it should no longer
3259 // really be used but handled by SwViewShell::ImplEndAction already
3260 const vcl::Region aDLRegion(aPaintRect.SVRect());
3261 pSh->DLPrePaint2(aDLRegion);
3262 }
3263
3264 if(OUTDEV_WINDOW == gProp.pSGlobalShell->GetOut()->GetOutDevType())
3265 {
3266 // changed method SwLayVout::Enter(..)
3267 // 2nd parameter is no longer <const> and will be set to the
3268 // rectangle the virtual output device is calculated from <aPaintRect>,
3269 // if the virtual output is used.
3270 s_pVout->Enter(pSh, aPaintRect, !s_isNoVirDev);
3271
3272 // Adjust paint rectangle to pixel size
3273 // Thus, all objects overlapping on pixel level with the unadjusted
3274 // paint rectangle will be considered in the paint.
3275 lcl_AdjustRectToPixelSize( aPaintRect, *(pSh->GetOut()) );
3276 }
3277
3278 // maybe this can be put in the above scope. Since we are not sure, just leave it ATM
3279 s_pVout->SetOrgRect( aPaintRect );
3280
3281 // determine background color of page for <PaintLayer> method
3282 // calls, paint <hell> or <heaven>
3283 const Color aPageBackgrdColor(pPage->GetDrawBackgroundColor());
3284
3285 pPage->PaintBaBo( aPaintRect, pPage );
3286
3287 if ( pSh->Imp()->HasDrawView() )
3288 {
3289 gProp.pSLines->LockLines( true );
3291 pSh->Imp()->PaintLayer( rIDDMA.GetHellId(),
3292 pPrintData,
3293 *pPage, pPage->getFrameArea(),
3294 &aPageBackgrdColor,
3295 pPage->IsRightToLeft(),
3296 &aSwRedirector );
3297 gProp.pSLines->PaintLines( pSh->GetOut(), gProp );
3298 gProp.pSLines->LockLines( false );
3299 }
3300
3302 pPage->PaintBaBo( aPaintRect, pPage, /*bOnlyTextBackground=*/true );
3303
3304 if( pSh->GetWin() )
3305 {
3306 // collect sub-lines
3307 pPage->RefreshSubsidiary( aPaintRect );
3308 // paint special sub-lines
3309 gProp.pSSpecSubsLines->PaintSubsidiary( pSh->GetOut(), nullptr, gProp );
3310 }
3311
3312 pPage->PaintSwFrame( rRenderContext, aPaintRect );
3313
3314 // no paint of page border and shadow, if writer is in place mode.
3315 if( pSh->GetWin() && pSh->GetDoc()->GetDocShell() &&
3316 !pSh->GetDoc()->GetDocShell()->IsInPlaceActive() )
3317 {
3318 SwPageFrame::PaintBorderAndShadow( pPage->getFrameArea(), pSh, bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
3319 SwPageFrame::PaintNotesSidebar( pPage->getFrameArea(), pSh, pPage->GetPhyPageNum(), bRightSidebar);
3320 }
3321
3322 gProp.pSLines->PaintLines( pSh->GetOut(), gProp );
3323 if ( pSh->GetWin() )
3324 {
3325 gProp.pSSubsLines->PaintSubsidiary( pSh->GetOut(), gProp.pSLines.get(), gProp );
3326 gProp.pSSubsLines.reset();
3327 gProp.pSSpecSubsLines.reset();
3328 }
3329 // fdo#42750: delay painting these until after subsidiary lines
3330 // fdo#45562: delay painting these until after hell layer
3331 // fdo#47717: but do it before heaven layer
3332 ProcessPrimitives(gProp.pBLines->GetBorderLines_Clear());
3333
3334 if ( pSh->Imp()->HasDrawView() )
3335 {
3337 pPrintData,
3338 *pPage, pPage->getFrameArea(),
3339 &aPageBackgrdColor,
3340 pPage->IsRightToLeft(),
3341 &aSwRedirector );
3342 }
3343
3344 if ( bExtraData )
3345 pPage->RefreshExtraData( aPaintRect );
3346
3347 gProp.pBLines.reset();
3348 s_pVout->Leave();
3349
3350 // #i68597#
3351 // needed to move grid painting inside Begin/EndDrawLayer bounds and to change
3352 // output rect for it accordingly
3353 if(bGridPainting)
3354 {
3355 SdrPaintView* pPaintView = pSh->Imp()->GetDrawView();
3356 SdrPageView* pPageView = pPaintView->GetSdrPageView();
3357 pPageView->DrawPageViewGrid(*pSh->GetOut(), aPaintRect.SVRect(), pSh->GetViewOptions()->GetTextGridColor() );
3358 }
3359
3360 // #i68597#
3361 // moved paint post-process for DrawingLayer overlay here, see above
3362 {
3363 pSh->DLPostPaint2(true);
3364 }
3365 }
3366
3367 pPage->PaintDecorators( );
3368 pPage->PaintBreak();
3369 }
3370 else if ( bBookMode && pSh->GetWin() && !pSh->GetDoc()->GetDocShell()->IsInPlaceActive() )
3371 {
3372 // paint empty page
3373 SwRect aPaintRect;
3374 SwRect aEmptyPageRect( pPage->getFrameArea() );
3375
3376 // code from vprint.cxx
3377 const SwPageFrame& rFormatPage = pPage->GetFormatPage();
3378 aEmptyPageRect.SSize( rFormatPage.getFrameArea().SSize() );
3379
3380 SwPageFrame::GetBorderAndShadowBoundRect( aEmptyPageRect, pSh, &rRenderContext, aPaintRect,
3381 bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
3382 aPaintRect.Intersection_( aRect );
3383
3384 if ( aRect.Overlaps( aEmptyPageRect ) )
3385 {
3386 // #i75172# if called from SwViewShell::ImplEndAction it should no longer
3387 // really be used but handled by SwViewShell::ImplEndAction already
3388 {
3389 const vcl::Region aDLRegion(aPaintRect.SVRect());
3390 pSh->DLPrePaint2(aDLRegion);
3391 }
3392
3393 if( pSh->GetOut()->GetFillColor() != aGlobalRetoucheColor )
3395 // No line color
3396 pSh->GetOut()->SetLineColor();
3397 // Use aligned page rectangle
3398 {
3399 SwRect aTmpPageRect( aEmptyPageRect );
3400 ::SwAlignRect( aTmpPageRect, pSh, &rRenderContext );
3401 aEmptyPageRect = aTmpPageRect;
3402 }
3403
3404 pSh->GetOut()->DrawRect( aEmptyPageRect.SVRect() );
3405
3406 // paint empty page text
3407 const vcl::Font& rEmptyPageFont = SwPageFrame::GetEmptyPageFont();
3408 const vcl::Font aOldFont( pSh->GetOut()->GetFont() );
3409
3410 pSh->GetOut()->SetFont( rEmptyPageFont );
3411 pSh->GetOut()->DrawText( aEmptyPageRect.SVRect(), SwResId( STR_EMPTYPAGE ),
3412 DrawTextFlags::VCenter |
3413 DrawTextFlags::Center |
3414 DrawTextFlags::Clip );
3415
3416 pSh->GetOut()->SetFont( aOldFont );
3417 // paint shadow and border for empty page
3418 SwPageFrame::PaintBorderAndShadow( aEmptyPageRect, pSh, bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
3419 SwPageFrame::PaintNotesSidebar( aEmptyPageRect, pSh, pPage->GetPhyPageNum(), bRightSidebar);
3420
3421 {
3422 pSh->DLPostPaint2(true);
3423 }
3424 }
3425 }
3426
3427 OSL_ENSURE( !pPage->GetNext() || pPage->GetNext()->IsPageFrame(),
3428 "Neighbour of page is not a page." );
3429 pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
3430 }
3431
3432 gProp.pSLines.reset();
3433
3434 if ( bResetRootPaint )
3436 if ( pStatics )
3437 pStatics.reset();
3438 else
3439 {
3440 gProp.pSProgress = nullptr;
3441 gProp.pSGlobalShell = nullptr;
3442 }
3443
3444 const_cast<SwRootFrame*>(this)->SetCallbackActionEnabled( bOldAction );
3445}
3446
3448{
3449 vcl::RenderContext* pRenderContext = pCont->getRootFrame()->GetCurrShell()->GetOut();
3450
3451 //It's possible that the Cont will get destroyed.
3452 SwContentFrame *pCnt = pCont->ContainsContent();
3453 while ( pCnt && pCnt->IsInFootnote() )
3454 {
3455 pCnt->Calc(pRenderContext);
3456 pCnt = pCnt->GetNextContentFrame();
3457 }
3458}
3459
3460namespace {
3461
3462class SwShortCut
3463{
3464 SwRectDist m_fnCheck;
3465 tools::Long m_nLimit;
3466
3467public:
3468 SwShortCut( const SwFrame& rFrame, const SwRect& rRect );
3469 bool Stop(const SwRect& rRect) const { return (rRect.*m_fnCheck)(m_nLimit) > 0; }
3470};
3471
3472}
3473
3474SwShortCut::SwShortCut( const SwFrame& rFrame, const SwRect& rRect )
3475{
3476 bool bVert = rFrame.IsVertical();
3477 bool bR2L = rFrame.IsRightToLeft();
3478 if( rFrame.IsNeighbourFrame() && bVert == bR2L )
3479 {
3480 if( bVert )
3481 {
3482 m_fnCheck = &SwRect::GetBottomDistance;
3483 m_nLimit = rRect.Top();
3484 }
3485 else
3486 {
3487 m_fnCheck = &SwRect::GetLeftDistance;
3488 m_nLimit = rRect.Left() + rRect.Width();
3489 }
3490 }
3491 else if( bVert == rFrame.IsNeighbourFrame() )
3492 {
3493 m_fnCheck = &SwRect::GetTopDistance;
3494 m_nLimit = rRect.Top() + rRect.Height();
3495 }
3496 else
3497 {
3498 if ( rFrame.IsVertLR() )
3499 {
3500 m_fnCheck = &SwRect::GetLeftDistance;
3501 m_nLimit = rRect.Right();
3502 }
3503 else
3504 {
3505 m_fnCheck = &SwRect::GetRightDistance;
3506 m_nLimit = rRect.Left();
3507 }
3508 }
3509}
3510
3511void SwLayoutFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& rRect, SwPrintData const*const) const
3512{
3513 // #i16816# tagged pdf support
3514 Frame_Info aFrameInfo(*this, false);
3515 SwTaggedPDFHelper aTaggedPDFHelper( nullptr, &aFrameInfo, nullptr, rRenderContext );
3516 ::std::optional<SwTaggedPDFHelper> oTaggedLink;
3517 if (IsFlyFrame())
3518 {
3519 // tdf#154939 Link nested inside Figure
3520 auto const pItem(GetFormat()->GetAttrSet().GetItemIfSet(RES_URL));
3521 if (pItem && !pItem->GetURL().isEmpty())
3522 {
3523 Frame_Info linkInfo(*this, true);
3524 oTaggedLink.emplace(nullptr, &linkInfo, nullptr, rRenderContext);
3525 }
3526 }
3527
3528 const SwFrame *pFrame = Lower();
3529 if ( !pFrame )
3530 return;
3531
3532 SwFrameDeleteGuard g(const_cast<SwLayoutFrame*>(this)); // lock because Calc() and recursion
3533 SwShortCut aShortCut( *pFrame, rRect );
3534 bool bCnt = pFrame->IsContentFrame();
3535 if ( bCnt )
3536 pFrame->Calc(&rRenderContext);
3537
3538 if ( pFrame->IsFootnoteContFrame() )
3539 {
3540 ::lcl_EmergencyFormatFootnoteCont( const_cast<SwFootnoteContFrame*>(static_cast<const SwFootnoteContFrame*>(pFrame)) );
3541 pFrame = Lower();
3542 }
3543
3544 const SwPageFrame *pPage = nullptr;
3545 bool bWin = gProp.pSGlobalShell->GetWin() != nullptr;
3547 // Tiled rendering is similar to printing in this case: painting transparently multiple
3548 // times will result in darker colors: avoid that.
3549 bWin = false;
3550
3551 while ( IsAnLower( pFrame ) )
3552 {
3553 SwRect aPaintRect( pFrame->GetPaintArea() );
3554 if( aShortCut.Stop( aPaintRect ) )
3555 break;
3556 if ( bCnt && gProp.pSProgress )
3558
3559 //We need to retouch if a frame explicitly requests it.
3560 //First do the retouch, because this could flatten the borders.
3561 if ( pFrame->IsRetouche() )
3562 {
3563 if ( pFrame->IsRetoucheFrame() && bWin && !pFrame->GetNext() )
3564 {
3565 if ( !pPage )
3566 pPage = FindPageFrame();
3567 pFrame->Retouch( pPage, rRect );
3568 }
3569 pFrame->ResetRetouche();
3570 }
3571
3572 if ( rRect.Overlaps( aPaintRect ) )
3573 {
3574 if ( bCnt && pFrame->IsCompletePaint() &&
3575 !rRect.Contains( aPaintRect ) && Application::AnyInput( VclInputFlags::KEYBOARD ) )
3576 {
3577 //fix(8104): It may happen, that the processing wasn't complete
3578 //but some parts of the paragraph were still repainted.
3579 //This could lead to the situation, that other parts of the
3580 //paragraph won't be repainted at all. The only solution seems
3581 //to be an invalidation of the window.
3582 //To not make it too severe the rectangle is limited by
3583 //painting the desired part and only invalidating the
3584 //remaining paragraph parts.
3585 if ( aPaintRect.Left() == rRect.Left() &&
3586 aPaintRect.Right() == rRect.Right() )
3587 {
3588 aPaintRect.Bottom( rRect.Top() - 1 );
3589 if ( aPaintRect.Height() > 0 )
3590 gProp.pSGlobalShell->InvalidateWindows(aPaintRect);
3591 aPaintRect.Top( rRect.Bottom() + 1 );
3592 aPaintRect.Bottom( pFrame->getFrameArea().Bottom() );
3593 if ( aPaintRect.Height() > 0 )
3594 gProp.pSGlobalShell->InvalidateWindows(aPaintRect);
3595 aPaintRect.Top( pFrame->getFrameArea().Top() );
3596 aPaintRect.Bottom( pFrame->getFrameArea().Bottom() );
3597 }
3598 else
3599 {
3600 gProp.pSGlobalShell->InvalidateWindows( aPaintRect );
3601 pFrame = pFrame->GetNext();
3602 if ( pFrame )
3603 {
3604 bCnt = pFrame->IsContentFrame();
3605 if ( bCnt )
3606 pFrame->Calc(&rRenderContext);
3607 }
3608 continue;
3609 }
3610 }
3611 pFrame->ResetCompletePaint();
3612 aPaintRect.Intersection_( rRect );
3613
3614 pFrame->PaintSwFrame( rRenderContext, aPaintRect );
3615
3616 if ( Lower() && Lower()->IsColumnFrame() )
3617 {
3618 //Paint the column separator line if needed. The page is
3619 //responsible for the page frame - not the upper.
3620 const SwFrameFormat *pFormat = GetUpper() && GetUpper()->IsPageFrame()
3621 ? GetUpper()->GetFormat()
3622 : GetFormat();
3623 const SwFormatCol &rCol = pFormat->GetCol();
3624 if ( rCol.GetLineAdj() != COLADJ_NONE )
3625 {
3626 if ( !pPage )
3627 pPage = pFrame->FindPageFrame();
3628
3629 PaintColLines( aPaintRect, rCol, pPage );
3630 }
3631 }
3632 }
3633 if ( !bCnt && pFrame->GetNext() && pFrame->GetNext()->IsFootnoteContFrame() )
3634 ::lcl_EmergencyFormatFootnoteCont( const_cast<SwFootnoteContFrame*>(static_cast<const SwFootnoteContFrame*>(pFrame->GetNext())) );
3635
3636 pFrame = pFrame->GetNext();
3637
3638 if ( pFrame )
3639 {
3640 bCnt = pFrame->IsContentFrame();
3641 if ( bCnt )
3642 pFrame->Calc(&rRenderContext);
3643 }
3644 }
3645}
3646
3648 const basegfx::B2DPoint& rStart, const basegfx::B2DPoint& rEnd,
3649 basegfx::BColor aColor )
3650{
3652
3653 std::vector< double > aStrokePattern;
3654 basegfx::B2DPolygon aLinePolygon;
3655 aLinePolygon.append(rStart);
3656 aLinePolygon.append(rEnd);
3657
3659 if ( rSettings.GetHighContrastMode( ) )
3660 {
3661 // Only a solid line in high contrast mode
3662 aColor = rSettings.GetDialogTextColor().getBColor();
3663 }
3664 else
3665 {
3666 // Get a color for the contrast
3667 basegfx::BColor aHslLine = basegfx::utils::rgb2hsl( aColor );
3668 double nLuminance = aHslLine.getZ() * 2.5;
3669 if ( nLuminance == 0 )
3670 nLuminance = 0.5;
3671 else if ( nLuminance >= 1.0 )
3672 nLuminance = aHslLine.getZ() * 0.4;
3673 aHslLine.setZ( nLuminance );
3674 const basegfx::BColor aOtherColor = basegfx::utils::hsl2rgb( aHslLine );
3675
3676 // Compute the plain line
3677 aSeq[0] =
3679 aLinePolygon, aOtherColor );
3680
3681 // Dashed line in twips
3682 aStrokePattern.push_back( 40 );
3683 aStrokePattern.push_back( 40 );
3684
3685 aSeq.resize( 2 );
3686 }
3687
3688 // Compute the dashed line primitive
3689 aSeq[ aSeq.size( ) - 1 ] =
3691 basegfx::B2DPolyPolygon( aLinePolygon ),
3693 drawinglayer::attribute::StrokeAttribute( std::move(aStrokePattern) ) );
3694
3695
3696 return aSeq;
3697}
3698
3700{
3701 if ( gProp.pSGlobalShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
3702 gProp.pSGlobalShell->GetViewOptions()->IsPDFExport() ||
3703 gProp.pSGlobalShell->GetViewOptions()->IsReadonly() ||
3704 gProp.pSGlobalShell->IsPreview() )
3705 return;
3706
3707 const SwFrame* pBodyFrame = Lower();
3708 while ( pBodyFrame && !pBodyFrame->IsBodyFrame() )
3709 pBodyFrame = pBodyFrame->GetNext();
3710
3711 if ( pBodyFrame )
3712 {
3713 const SwLayoutFrame* pLayBody = static_cast< const SwLayoutFrame* >( pBodyFrame );
3714 const SwFlowFrame *pFlowFrame = pLayBody->ContainsContent();
3715
3716 // Test if the first node is a table
3717 const SwFrame* pFirstFrame = pLayBody->Lower();
3718 if ( pFirstFrame && pFirstFrame->IsTabFrame() )
3719 pFlowFrame = static_cast< const SwTabFrame* >( pFirstFrame );
3720
3721 SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >( gProp.pSGlobalShell );
3722 if ( pWrtSh )
3723 {
3724 SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
3726
3727 if ( pFlowFrame && pFlowFrame->IsPageBreak( true ) )
3728 rMngr.SetPageBreakControl( this );
3729 else
3731 }
3732 }
3734}
3735
3737{
3738 if ( gProp.pSGlobalShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
3739 gProp.pSGlobalShell->GetViewOptions()->IsPDFExport() ||
3740 gProp.pSGlobalShell->GetViewOptions()->IsReadonly() ||
3741 gProp.pSGlobalShell->IsPreview() )
3742 return;
3743
3744 const SwFrame* pBodyFrame = Lower();
3745 while ( pBodyFrame && !pBodyFrame->IsBodyFrame() )
3746 pBodyFrame = pBodyFrame->GetNext();
3747
3748 if ( !pBodyFrame )
3749 return;
3750
3751 const SwContentFrame *pCnt = static_cast< const SwLayoutFrame* >( pBodyFrame )->ContainsContent();
3752 if ( !(pCnt && pCnt->IsColBreak( true )) )
3753 return;
3754
3755 // Paint the break only if:
3756 // * Not in header footer edition, to avoid conflicts with the
3757 // header/footer marker
3758 // * Non-printing characters are shown, as this is more consistent
3759 // with other formatting marks
3760 if ( !(!gProp.pSGlobalShell->IsShowHeaderFooterSeparator( FrameControlType::Header ) &&
3761 !gProp.pSGlobalShell->IsShowHeaderFooterSeparator( FrameControlType::Footer ) &&
3762 gProp.pSGlobalShell->GetViewOptions()->IsLineBreak()) )
3763 return;
3764
3765 SwRect aRect( pCnt->getFramePrintArea() );
3766 aRect.Pos() += pCnt->getFrameArea().Pos();
3767
3768 // Draw the line
3769 basegfx::B2DPoint aStart( double( aRect.Left() ), aRect.Top() );
3770 basegfx::B2DPoint aEnd( double( aRect.Right() ), aRect.Top() );
3771 double nWidth = aRect.Width();
3772 if ( IsVertical( ) )
3773 {
3774 aStart = basegfx::B2DPoint( double( aRect.Right() ), double( aRect.Top() ) );
3775 aEnd = basegfx::B2DPoint( double( aRect.Right() ), double( aRect.Bottom() ) );
3776 nWidth = aRect.Height();
3777 }
3778
3779 basegfx::BColor aLineColor = gProp.pSGlobalShell->GetViewOptions()->GetPageBreakColor().getBColor();
3780
3782 lcl_CreateDashedIndicatorPrimitive( aStart, aEnd, aLineColor );
3783
3784 // Add the text above
3785 OUString aBreakText = SwResId(STR_COLUMN_BREAK);
3786
3787 basegfx::B2DVector aFontSize;
3788 OutputDevice* pOut = gProp.pSGlobalShell->GetOut();
3789 vcl::Font aFont = pOut->GetSettings().GetStyleSettings().GetToolFont();
3790 aFont.SetFontHeight( 8 * 20 );
3791 pOut->SetFont( aFont );
3793 aFontSize, aFont, IsRightToLeft(), false );
3794
3795 tools::Rectangle aTextRect;
3796 pOut->GetTextBoundRect( aTextRect, aBreakText );
3797 tools::Long nTextOff = ( nWidth - aTextRect.GetWidth() ) / 2;
3798
3800 aFontSize.getX(), aFontSize.getY(),
3801 aRect.Left() + nTextOff, aRect.Top() ) );
3802 if ( IsVertical() )
3803 {
3805 aFontSize.getX(), aFontSize.getY(), 0.0, M_PI_2,
3806 aRect.Right(), aRect.Top() + nTextOff );
3807 }
3808
3809 aSeq.push_back(
3811 aTextMatrix,
3812 aBreakText, 0, aBreakText.getLength(),
3813 std::vector< double >(),
3814 {},
3815 std::move(aFontAttr),
3816 lang::Locale(),
3817 aLineColor ) );
3818
3820}
3821
3823{
3824 const SwFrame* pFrame = Lower();
3825 while ( pFrame )
3826 {
3827 if ( pFrame->IsLayoutFrame() )
3828 static_cast< const SwLayoutFrame*>( pFrame )->PaintBreak( );
3829 pFrame = pFrame->GetNext();
3830 }
3831}
3832
3834{
3835 SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >( gProp.pSGlobalShell );
3836 if ( !pWrtSh )
3837 return;
3838
3839 SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
3840
3841 const SwLayoutFrame* pBody = FindBodyCont();
3842 if ( !pBody )
3843 return;
3844
3845 SwRect aBodyRect( pBody->getFrameArea() );
3846
3847 if ( !(gProp.pSGlobalShell->GetOut()->GetOutDevType() != OUTDEV_PRINTER &&
3848 !gProp.pSGlobalShell->GetViewOptions()->IsPDFExport() &&
3849 !gProp.pSGlobalShell->IsPreview() &&
3850 !gProp.pSGlobalShell->GetViewOptions()->IsReadonly() &&
3851 !gProp.pSGlobalShell->GetViewOptions()->getBrowseMode() &&
3852 ( gProp.pSGlobalShell->IsShowHeaderFooterSeparator( FrameControlType::Header ) ||
3853 gProp.pSGlobalShell->IsShowHeaderFooterSeparator( FrameControlType::Footer ) )) )
3854 return;
3855
3856 bool bRtl = AllSettings::GetLayoutRTL();
3857 const SwRect& rVisArea = gProp.pSGlobalShell->VisArea();
3858 tools::Long nXOff = std::min( aBodyRect.Right(), rVisArea.Right() );
3859 if ( bRtl )
3860 nXOff = std::max( aBodyRect.Left(), rVisArea.Left() );
3861
3862 // Header
3863 if ( gProp.pSGlobalShell->IsShowHeaderFooterSeparator( FrameControlType::Header ) )
3864 {
3865 const SwFrame* pHeaderFrame = Lower();
3866 if ( !pHeaderFrame->IsHeaderFrame() )
3867 pHeaderFrame = nullptr;
3868
3869 tools::Long nHeaderYOff = aBodyRect.Top();
3870 Point nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nHeaderYOff ) );
3872 }
3873
3874 // Footer
3875 if ( !gProp.pSGlobalShell->IsShowHeaderFooterSeparator( FrameControlType::Footer ) )
3876 return;
3877
3878 const SwFrame* pFootnoteContFrame = Lower();
3879 while ( pFootnoteContFrame )
3880 {
3881 if ( pFootnoteContFrame->IsFootnoteContFrame() )
3882 aBodyRect.AddBottom( pFootnoteContFrame->getFrameArea().Bottom() - aBodyRect.Bottom() );
3883 pFootnoteContFrame = pFootnoteContFrame->GetNext();
3884 }
3885
3886 tools::Long nFooterYOff = aBodyRect.Bottom();
3887 Point nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nFooterYOff ) );
3889}
3890
3905{
3906 bool bBackgroundTransparent = GetFormat()->IsBackgroundTransparent();
3907 if ( !bBackgroundTransparent &&
3908 GetFormat()->IsBackgroundBrushInherited() )
3909 {
3910 const SvxBrushItem* pBackgroundBrush = nullptr;
3911 std::optional<Color> xSectionTOXColor;
3912 SwRect aDummyRect;
3914
3915 if ( GetBackgroundBrush( aFillAttributes, pBackgroundBrush, xSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false) )
3916 {
3917 if ( xSectionTOXColor &&
3918 (xSectionTOXColor->IsTransparent()) &&
3919 (xSectionTOXColor != COL_TRANSPARENT) )
3920 {
3921 bBackgroundTransparent = true;
3922 }
3923 else if(aFillAttributes && aFillAttributes->isUsed())
3924 {
3925 bBackgroundTransparent = aFillAttributes->isTransparent();
3926 }
3927 else if ( pBackgroundBrush )
3928 {
3929 if ( (pBackgroundBrush->GetColor().IsTransparent()) &&
3930 (pBackgroundBrush->GetColor() != COL_TRANSPARENT) )
3931 {
3932 bBackgroundTransparent = true;
3933 }
3934 else
3935 {
3936 const GraphicObject *pTmpGrf =
3937 pBackgroundBrush->GetGraphicObject();
3938 if ( pTmpGrf &&
3939 (pTmpGrf->GetAttr().IsTransparent())
3940 )
3941 {
3942 bBackgroundTransparent = true;
3943 }
3944 }
3945 }
3946 }
3947 }
3948
3949 return bBackgroundTransparent;
3950};
3951
3953{
3954 SdrObjUserCall *pUserCall = GetUserCall(pObj);
3955
3956 if ( nullptr == pUserCall )
3957 return true;
3958
3959 //Attribute dependent, don't paint for printer or Preview
3960 bool bPaint = gProp.pSFlyOnlyDraw ||
3961 static_cast<SwContact*>(pUserCall)->GetFormat()->GetPrint().GetValue();
3962 if ( !bPaint )
3963 bPaint = pSh->GetWin() && !pSh->IsPreview();
3964
3965 if ( bPaint )
3966 {
3967 //The paint may be prevented by the superior Flys.
3968 SwFrame *pAnch = nullptr;
3969 if ( dynamic_cast< const SwFlyDrawObj *>( pObj ) != nullptr ) // i#117962#
3970 {
3971 bPaint = false;
3972 }
3973 if ( auto pFlyDraw = dynamic_cast<SwVirtFlyDrawObj *>( pObj ) )
3974 {
3975 SwFlyFrame *pFly = pFlyDraw->GetFlyFrame();
3976 if ( gProp.pSFlyOnlyDraw && gProp.pSFlyOnlyDraw == pFly )
3977 return true;
3978
3979 //Try to avoid displaying the intermediate stage, Flys which don't
3980 //overlap with the page on which they are anchored won't be
3981 //painted.
3982 //HACK: exception: printing of frames in tables, those can overlap
3983 //a page once in a while when dealing with oversized tables (HTML).
3984 SwPageFrame *pPage = pFly->FindPageFrame();
3985 if ( pPage && pPage->getFrameArea().Overlaps( pFly->getFrameArea() ) )
3986 {
3987 pAnch = pFly->AnchorFrame();
3988 }
3989
3990 }
3991 else
3992 {
3993 // Consider 'virtual' drawing objects
3994 SwDrawContact* pDrawContact = dynamic_cast<SwDrawContact*>(pUserCall);
3995 pAnch = pDrawContact ? pDrawContact->GetAnchorFrame(pObj) : nullptr;
3996 if ( pAnch )
3997 {
3998 if ( !pAnch->isFrameAreaPositionValid() )
3999 pAnch = nullptr;
4000 else if ( pSh->GetOut() == pSh->getIDocumentDeviceAccess().getPrinter( false ))
4001 {
4002 //HACK: we have to omit some of the objects for printing,
4003 //otherwise they would be printed twice.
4004 //The objects should get printed if the TableHack is active
4005 //right now. Afterwards they must not be printed if the
4006 //page over which they float position wise gets printed.
4007 const SwPageFrame *pPage = pAnch->FindPageFrame();
4008 if ( !pPage->getFrameArea().Overlaps( SwRect(pObj->GetCurrentBoundRect()) ) )
4009 pAnch = nullptr;
4010 }
4011 }
4012 else
4013 {
4014 if ( dynamic_cast< const SdrObjGroup *>( pObj ) == nullptr )
4015 {
4016 OSL_FAIL( "<SwFlyFrame::IsPaint(..)> - paint of drawing object without anchor frame!?" );
4017 }
4018 }
4019 }
4020 if ( pAnch )
4021 {
4022 if ( pAnch->IsInFly() )
4023 bPaint = SwFlyFrame::IsPaint( pAnch->FindFlyFrame()->GetVirtDrawObj(),
4024 pSh );
4025 else if ( gProp.pSFlyOnlyDraw )
4026 bPaint = false;
4027 }
4028 else
4029 bPaint = false;
4030 }
4031 return bPaint;
4032}
4033
4034void SwCellFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& rRect, SwPrintData const*const) const
4035{
4036 if ( GetLayoutRowSpan() >= 1 )
4037 SwLayoutFrame::PaintSwFrame( rRenderContext, rRect );
4038}
4039
4040namespace {
4041
4042struct BorderLinesGuard
4043{
4044 explicit BorderLinesGuard() : m_pBorderLines(std::move(gProp.pBLines))
4045 {
4046 gProp.pBLines.reset(new BorderLines);
4047 }
4048 ~BorderLinesGuard()
4049 {
4050 gProp.pBLines = std::move(m_pBorderLines);
4051 }
4052private:
4053 std::unique_ptr<BorderLines> m_pBorderLines;
4054};
4055
4056}
4057
4058// set strikethrough for deleted objects anchored to character
4060{
4061 if ( SwSortedObjs *pObjs = GetDrawObjs() )
4062 {
4063 for (SwAnchoredObject* pAnchoredObj : *pObjs)
4064 {
4065 if ( auto pFly = pAnchoredObj->DynCastFlyFrame() )
4066 {
4067 pFly->SetDeleted(bDeleted);
4068 }
4069 }
4070 }
4071}
4072
4073void SwFlyFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& rRect, SwPrintData const*const) const
4074{
4075 //optimize thumbnail generation and store procedure to improve odt saving performance, #i120030#
4076 SwViewShell *pShell = getRootFrame()->GetCurrShell();
4077 if (pShell && pShell->GetDoc() && pShell->GetDoc()->GetDocShell())
4078 {
4079 bool bInGenerateThumbnail = pShell->GetDoc()->GetDocShell()->IsInGenerateAndStoreThumbnail();
4080 if (bInGenerateThumbnail)
4081 {
4082 const SwRect& aVisRect = pShell->VisArea();
4083 if (!aVisRect.Overlaps(getFrameArea()))
4084 return;
4085 }
4086 }
4087
4088 //because of the overlapping of frames and drawing objects the flys have to
4089 //paint their borders (and those of the internal ones) directly.
4090 //e.g. #33066#
4091 gProp.pSLines->LockLines(true);
4092 BorderLinesGuard blg; // this should not paint borders added from PaintBaBo
4093
4094 SwRect aRect( rRect );
4095 aRect.Intersection_( getFrameArea() );
4096
4097 rRenderContext.Push( vcl::PushFlags::CLIPREGION );
4098 rRenderContext.SetClipRegion();
4099 const SwPageFrame* pPage = FindPageFrame();
4100
4101 const SwNoTextFrame *pNoText = Lower() && Lower()->IsNoTextFrame()
4102 ? static_cast<const SwNoTextFrame*>(Lower()) : nullptr;
4103
4104 bool bIsChart = false; //#i102950# don't paint additional borders for charts
4105 //check whether we have a chart
4106 if(pNoText)
4107 {
4108 const SwNoTextNode* pNoTNd = dynamic_cast<const SwNoTextNode*>(pNoText->GetNode());
4109 if( pNoTNd )
4110 {
4111 SwOLENode* pOLENd = const_cast<SwOLENode*>(pNoTNd->GetOLENode());
4112 if( pOLENd && pOLENd->GetOLEObj().GetObject().IsChart() )
4113 bIsChart = true;
4114 }
4115 }
4116
4117 {
4118 bool bContour = GetFormat()->GetSurround().IsContour();
4119 tools::PolyPolygon aPoly;
4120 if ( bContour )
4121 {
4122 // add 2nd parameter with value <true>
4123 // to indicate that method is called for paint in order to avoid
4124 // load of the intrinsic graphic.
4125 bContour = GetContour( aPoly, true );
4126 }
4127
4128 // #i47804# - distinguish complete background paint
4129 // and margin paint.
4130 // paint complete background for Writer text fly frames
4131 bool bPaintCompleteBack( !pNoText );
4132 // paint complete background for transparent graphic and contour,
4133 // if own background color exists.
4134 const bool bIsGraphicTransparent = pNoText && pNoText->IsTransparent();
4135 if ( !bPaintCompleteBack &&
4136 ( bIsGraphicTransparent|| bContour ) )
4137 {
4138 const SwFlyFrameFormat* pSwFrameFormat = GetFormat();
4139
4140 if (pSwFrameFormat && pSwFrameFormat->supportsFullDrawingLayerFillAttributeSet())
4141 {
4142 // check for transparency
4144
4145 // check if the new fill attributes are used
4146 if(aFillAttributes && aFillAttributes->isUsed())
4147 {
4148 bPaintCompleteBack = true;
4149 }
4150 }
4151 else
4152 {
4153 std::unique_ptr<SvxBrushItem> aBack = GetFormat()->makeBackgroundBrushItem();
4154 // to determine, if background has to be painted, by checking, if
4155 // background color is not COL_TRANSPARENT ("no fill"/"auto fill")
4156 // or a background graphic exists.
4157 bPaintCompleteBack =
4158 aBack->GetColor() != COL_TRANSPARENT ||
4159 aBack->GetGraphicPos() != GPOS_NONE;
4160 }
4161 }
4162 // paint of margin needed.
4163 const bool bPaintMarginOnly( !bPaintCompleteBack &&
4165
4166 // #i47804# - paint background of parent fly frame
4167 // for transparent graphics in layer Hell, if parent fly frame isn't
4168 // in layer Hell. It's only painted the intersection between the
4169 // parent fly frame area and the paint area <aRect>
4171
4172 if (bIsGraphicTransparent &&
4173 GetFormat()->GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::SUBTRACT_FLYS) &&
4174 GetVirtDrawObj()->GetLayer() == rIDDMA.GetHellId() &&
4176 {
4177 const SwFlyFrame* pParentFlyFrame = GetAnchorFrame()->FindFlyFrame();
4178 if ( pParentFlyFrame->GetDrawObj()->GetLayer() !=
4179 rIDDMA.GetHellId() )
4180 {
4181 SwFlyFrame* pOldRet = gProp.pSRetoucheFly2;
4182 gProp.pSRetoucheFly2 = const_cast<SwFlyFrame*>(this);
4183
4184 SwBorderAttrAccess aAccess( SwFrame::GetCache(), pParentFlyFrame );
4185 const SwBorderAttrs &rAttrs = *aAccess.Get();
4186 SwRect aPaintRect( aRect );
4187 aPaintRect.Intersection_( pParentFlyFrame->getFrameArea() );
4188 pParentFlyFrame->PaintSwFrameBackground( aPaintRect, pPage, rAttrs );
4189
4190 gProp.pSRetoucheFly2 = pOldRet;
4191 }
4192 }
4193
4194 if ( bPaintCompleteBack || bPaintMarginOnly )
4195 {
4196 //#24926# JP 01.02.96, PaintBaBo is here partially so PaintSwFrameShadowAndBorder
4197 //receives the original Rect but PaintSwFrameBackground only the limited
4198 //one.
4199
4201 rRenderContext.SetLineColor();
4202
4203 pPage = FindPageFrame();
4204
4205 SwBorderAttrAccess aAccess( SwFrame::GetCache(), static_cast<SwFrame const *>(this) );
4206 const SwBorderAttrs &rAttrs = *aAccess.Get();
4207
4208 // paint background
4209 {
4210 SwRegionRects aRegion( aRect );
4211 // #i80822#
4212 // suppress painting of background in printing area for
4213 // non-transparent graphics.
4214 if ( bPaintMarginOnly ||
4215 ( pNoText && !bIsGraphicTransparent ) )
4216 {
4217 //What we actually want to paint is the small stripe between
4218 //PrtArea and outer border.
4219 SwRect aTmp( getFramePrintArea() ); aTmp += getFrameArea().Pos();
4220 aRegion -= aTmp;
4221 }
4222 if ( bContour )
4223 {
4224 rRenderContext.Push();
4225 // #i80822#
4226 // apply clip region under the same conditions, which are
4227 // used in <SwNoTextFrame::PaintSwFrame(..)> to set the clip region
4228 // for painting the graphic/OLE. Thus, the clip region is
4229 // also applied for the PDF export.
4231
4232 if ( !rRenderContext.GetConnectMetaFile() || !pSh || !pSh->GetWin() )
4233 {
4234 rRenderContext.SetClipRegion(vcl::Region(aPoly));
4235 }
4236
4237 for ( size_t i = 0; i < aRegion.size(); ++i )
4238 {
4239 PaintSwFrameBackground( aRegion[i], pPage, rAttrs, false, true );
4240 }
4241
4242 rRenderContext.Pop();
4243 }
4244 else
4245 {
4246 for ( size_t i = 0; i < aRegion.size(); ++i )
4247 {
4248 PaintSwFrameBackground( aRegion[i], pPage, rAttrs, false, true );
4249 }
4250 }
4251 }
4252
4253 // paint border before painting background
4254 PaintSwFrameShadowAndBorder(rRect, pPage, rAttrs);
4255
4256 rRenderContext.Pop();
4257 }
4258 }
4259
4260 // fly frame will paint it's subsidiary lines and
4261 // the subsidiary lines of its lowers on its own, due to overlapping with
4262 // other fly frames or other objects.
4263 if( gProp.pSGlobalShell->GetWin()
4264 && !bIsChart ) //#i102950# don't paint additional borders for charts
4265 {
4266 bool bSubsLineRectsCreated;
4267 if ( gProp.pSSubsLines )
4268 {
4269 // Lock already existing subsidiary lines
4270 gProp.pSSubsLines->LockLines( true );
4271 bSubsLineRectsCreated = false;
4272 }
4273 else
4274 {
4275 // create new subsidiary lines
4276 gProp.pSSubsLines.reset(new SwSubsRects);
4277 bSubsLineRectsCreated = true;
4278 }
4279
4280 bool bSpecSubsLineRectsCreated;
4281 if ( gProp.pSSpecSubsLines )
4282 {
4283 // Lock already existing special subsidiary lines
4284 gProp.pSSpecSubsLines->LockLines( true );
4285 bSpecSubsLineRectsCreated = false;
4286 }
4287 else
4288 {
4289 // create new special subsidiary lines
4290 gProp.pSSpecSubsLines.reset(new SwSubsRects);
4291 bSpecSubsLineRectsCreated = true;
4292 }
4293 // Add subsidiary lines of fly frame and its lowers
4294 RefreshLaySubsidiary( pPage, aRect );
4295 // paint subsidiary lines of fly frame and its lowers
4296 gProp.pSSpecSubsLines->PaintSubsidiary( &rRenderContext, nullptr, gProp );
4297 gProp.pSSubsLines->PaintSubsidiary(&rRenderContext, gProp.pSLines.get(), gProp);
4298 if ( !bSubsLineRectsCreated )
4299 // unlock subsidiary lines
4300 gProp.pSSubsLines->LockLines( false );
4301 else
4302 {
4303 // delete created subsidiary lines container
4304 gProp.pSSubsLines.reset();
4305 }
4306
4307 if ( !bSpecSubsLineRectsCreated )
4308 // unlock special subsidiary lines
4309 gProp.pSSpecSubsLines->LockLines( false );
4310 else
4311 {
4312 // delete created special subsidiary lines container
4313 gProp.pSSpecSubsLines.reset();
4314 }
4315 }
4316
4317 SwLayoutFrame::PaintSwFrame( rRenderContext, aRect );
4318
4319 Validate();
4320
4321 {
4322 SwTaggedPDFHelper tag(nullptr, nullptr, nullptr, rRenderContext);
4323 // first paint lines added by fly frame paint
4324 // and then unlock other lines.
4325 gProp.pSLines->PaintLines( &rRenderContext, gProp );
4326 gProp.pSLines->LockLines( false );
4327 // have to paint frame borders added in heaven layer here...
4328 ProcessPrimitives(gProp.pBLines->GetBorderLines_Clear());
4329 }
4330
4332
4333 // crossing out for tracked deletion
4334 if ( GetAuthor() != std::string::npos && IsDeleted() )
4335 {
4336 tools::Long startX = aRect.Left( ), endX = aRect.Right();
4337 tools::Long startY = aRect.Top( ), endY = aRect.Bottom();
4339 rRenderContext.DrawLine(Point(startX, startY), Point(endX, endY));
4340 rRenderContext.DrawLine(Point(startX, endY), Point(endX, startY));
4341 }
4342
4343 rRenderContext.Pop();
4344
4345 if ( gProp.pSProgress && pNoText )
4347}
4348
4350{
4351 // Show the un-float button
4352 SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >( gProp.pSGlobalShell );
4353 if ( pWrtSh )
4354 {
4356 }
4357}
4358
4360{
4361 SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(gProp.pSGlobalShell);
4362
4363 if (!pWrtSh)
4364 return nullptr;
4365
4366 return &pWrtSh->GetView();
4367}
4368
4370{
4371 // Maybe avoid the dynamic_cast and just use GetActiveWrtShell()
4372 // NO! Multiple windows will not display the highlighting correctly if GetActiveWrtShell is used.
4373 SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(gProp.pSGlobalShell);
4374
4375 if (!pWrtSh)
4376 return;
4377
4378 vcl::RenderContext* pRenderContext = pWrtSh->GetOut();
4379 if (!pRenderContext)
4380 return;
4381
4382 StylesHighlighterColorMap& rParaStylesColorMap
4384
4385 if (rParaStylesColorMap.empty())
4386 return;
4387
4388 // draw styles highlighter
4389 OUString sStyleName = GetTextNodeFirst()->GetTextColl()->GetName();
4390 if (rParaStylesColorMap.find(sStyleName) != rParaStylesColorMap.end())
4391 {
4392 SwRect aFrameAreaRect(getFrameArea());
4393
4394 if (IsRightToLeft())
4395 {
4396 aFrameAreaRect.AddRight(75);
4397 aFrameAreaRect.Left(aFrameAreaRect.Right() + 300);
4398 }
4399 else
4400 {
4401 aFrameAreaRect.AddLeft(-375);
4402 aFrameAreaRect.Right(aFrameAreaRect.Left() + 300);
4403 }
4404
4405 const tools::Rectangle& rRect = aFrameAreaRect.SVRect();
4406
4407 vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, GetAppLanguage(),
4408 GetDefaultFontFlags::OnlyOne, pRenderContext));
4409 aFont.SetFontSize(Size(0, 140 * pRenderContext->GetDPIScaleFactor()));
4410 aFont.SetUnderline(FontLineStyle::LINESTYLE_NONE);
4411 aFont.SetTransparent(false);
4412 aFont.SetWeight(WEIGHT_NORMAL);
4413 aFont.SetFamily(FontFamily::FAMILY_MODERN);
4414 aFont.SetColor(COL_BLACK);
4415
4416 pRenderContext->Push(vcl::PushFlags::ALL);
4417
4418 pRenderContext->SetFillColor(rParaStylesColorMap[sStyleName].first);
4419 pRenderContext->SetLineColor(rParaStylesColorMap[sStyleName].first);
4420
4421 pRenderContext->DrawRect(rRect);
4422
4423 // draw hatch pattern if paragraph has direct formatting
4425 {
4426 Color aHatchColor(rParaStylesColorMap[sStyleName].first);
4427 // make hatch line color 41% darker than the fill color
4428 aHatchColor.ApplyTintOrShade(-4100);
4429 Hatch aHatch(HatchStyle::Single, aHatchColor, 50, 450_deg10);
4430 pRenderContext->DrawHatch(tools::PolyPolygon(rRect), aHatch);
4431 }
4432
4433 pRenderContext->SetFont(aFont);
4435 pRenderContext->SetTextFillColor(rParaStylesColorMap[sStyleName].first);
4436 pRenderContext->DrawText(rRect, OUString::number(rParaStylesColorMap[sStyleName].second),
4437 DrawTextFlags::Center | DrawTextFlags::VCenter);
4438
4439 pRenderContext->Pop();
4440 }
4441}
4442
4444{
4445 SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(gProp.pSGlobalShell);
4446 if (pWrtSh && pWrtSh->GetViewOptions()->IsShowOutlineContentVisibilityButton())
4448}
4449
4450void SwTabFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& rRect, SwPrintData const*const) const
4451{
4452 const SwViewOption* pViewOption = gProp.pSGlobalShell->GetViewOptions();
4453 if (pViewOption->IsTable())
4454 {
4455 // #i29550#
4456 if ( IsCollapsingBorders() )
4457 {
4458 SwBorderAttrAccess aAccess( SwFrame::GetCache(), static_cast<SwFrame const *>(this) );
4459 const SwBorderAttrs &rAttrs = *aAccess.Get();
4460
4461 // paint shadow
4462 if ( rAttrs.GetShadow().GetLocation() != SvxShadowLocation::NONE )
4463 {
4464 SwRect aRect;
4465 ::lcl_CalcBorderRect( aRect, this, rAttrs, true, gProp );
4466 PaintShadow( rRect, aRect, rAttrs );
4467 }
4468
4469 SwTabFramePainter aHelper(*this);
4470 aHelper.PaintLines(rRenderContext, rRect);
4471 }
4472
4473 SwLayoutFrame::PaintSwFrame( rRenderContext, rRect );
4474 }
4475 // #i6467# - no light grey rectangle for page preview
4476 else if ( gProp.pSGlobalShell->GetWin() && !gProp.pSGlobalShell->IsPreview() )
4477 {
4478 // #i6467# - intersect output rectangle with table frame
4479 SwRect aTabRect( getFramePrintArea() );
4480 aTabRect.Pos() += getFrameArea().Pos();
4481 SwRect aTabOutRect( rRect );
4482 aTabOutRect.Intersection( aTabRect );
4483 SwViewOption::DrawRect( &rRenderContext, aTabOutRect, COL_LIGHTGRAY );
4484 }
4485 const_cast<SwTabFrame*>(this)->ResetComplete();
4486}
4487
4501static void lcl_PaintShadow( const SwRect& rRect, SwRect& rOutRect,
4502 const SvxShadowItem& rShadow, const bool bDrawFullShadowRectangle,
4503 const bool bTop, const bool bBottom,
4504 const bool bLeft, const bool bRight,
4505 SwPaintProperties const & properties)
4506{
4507 const tools::Long nWidth = ::lcl_AlignWidth ( rShadow.GetWidth(), properties );
4508 const tools::Long nHeight = ::lcl_AlignHeight( rShadow.GetWidth(), properties );
4509
4510 SwRects aRegion;
4511 SwRect aOut( rOutRect );
4512
4513 switch ( rShadow.GetLocation() )
4514 {
4515 case SvxShadowLocation::BottomRight:
4516 {
4517 if ( bDrawFullShadowRectangle )
4518 {
4519 // draw full shadow rectangle
4520 aOut.Top( rOutRect.Top() + nHeight );
4521 aOut.Left( rOutRect.Left() + nWidth );
4522 aRegion.push_back( aOut );
4523 }
4524 else
4525 {
4526 if( bBottom )
4527 {
4528 aOut.Top( rOutRect.Bottom() - nHeight );
4529 if( bLeft )
4530 aOut.Left( rOutRect.Left() + nWidth );
4531 aRegion.push_back( aOut );
4532 }
4533 if( bRight )
4534 {
4535 aOut.Left( rOutRect.Right() - nWidth );
4536 if( bTop )
4537 aOut.Top( rOutRect.Top() + nHeight );
4538 else
4539 aOut.Top( rOutRect.Top() );
4540 if( bBottom )
4541 aOut.Bottom( rOutRect.Bottom() - nHeight );
4542 aRegion.push_back( aOut );
4543 }
4544 }
4545
4546 if( bRight )
4547 rOutRect.AddRight(- nWidth );
4548 if( bBottom )
4549 rOutRect.AddBottom(- nHeight );
4550 }
4551 break;
4552 case SvxShadowLocation::TopLeft:
4553 {
4554 if ( bDrawFullShadowRectangle )
4555 {
4556 // draw full shadow rectangle
4557 aOut.Bottom( rOutRect.Bottom() - nHeight );
4558 aOut.Right( rOutRect.Right() - nWidth );
4559 aRegion.push_back( aOut );
4560 }
4561 else
4562 {
4563 if( bTop )
4564 {
4565 aOut.Bottom( rOutRect.Top() + nHeight );
4566 if( bRight )
4567 aOut.Right( rOutRect.Right() - nWidth );
4568 aRegion.push_back( aOut );
4569 }
4570 if( bLeft )
4571 {
4572 aOut.Right( rOutRect.Left() + nWidth );
4573 if( bBottom )
4574 aOut.Bottom( rOutRect.Bottom() - nHeight );
4575 else
4576 aOut.Bottom( rOutRect.Bottom() );
4577 if( bTop )
4578 aOut.Top( rOutRect.Top() + nHeight );
4579 aRegion.push_back( aOut );
4580 }
4581 }
4582
4583 if( bLeft )
4584 rOutRect.AddLeft( nWidth );
4585 if( bTop )
4586 rOutRect.AddTop( nHeight );
4587 }
4588 break;
4589 case SvxShadowLocation::TopRight:
4590 {
4591 if ( bDrawFullShadowRectangle )
4592 {
4593 // draw full shadow rectangle
4594 aOut.Bottom( rOutRect.Bottom() - nHeight);
4595 aOut.Left( rOutRect.Left() + nWidth );
4596 aRegion.push_back( aOut );
4597 }
4598 else
4599 {
4600 if( bTop )
4601 {
4602 aOut.Bottom( rOutRect.Top() + nHeight );
4603 if( bLeft )
4604 aOut.Left( rOutRect.Left() + nWidth );
4605 aRegion.push_back( aOut );
4606 }
4607 if( bRight )
4608 {
4609 aOut.Left( rOutRect.Right() - nWidth );
4610 if( bBottom )
4611 aOut.Bottom( rOutRect.Bottom() - nHeight );
4612 else
4613 aOut.Bottom( rOutRect.Bottom() );
4614 if( bTop )
4615 aOut.Top( rOutRect.Top() + nHeight );
4616 aRegion.push_back( aOut );
4617 }
4618 }
4619
4620 if( bRight )
4621 rOutRect.AddRight( - nWidth );
4622 if( bTop )
4623 rOutRect.AddTop( nHeight );
4624 }
4625 break;
4626 case SvxShadowLocation::BottomLeft:
4627 {
4628 if ( bDrawFullShadowRectangle )
4629 {
4630 // draw full shadow rectangle
4631 aOut.Top( rOutRect.Top() + nHeight );
4632 aOut.Right( rOutRect.Right() - nWidth );
4633 aRegion.push_back( aOut );
4634 }
4635 else
4636 {
4637 if( bBottom )
4638 {
4639 aOut.Top( rOutRect.Bottom()- nHeight );
4640 if( bRight )
4641 aOut.Right( rOutRect.Right() - nWidth );
4642 aRegion.push_back( aOut );
4643 }
4644 if( bLeft )
4645 {
4646 aOut.Right( rOutRect.Left() + nWidth );
4647 if( bTop )
4648 aOut.Top( rOutRect.Top() + nHeight );
4649 else
4650 aOut.Top( rOutRect.Top() );
4651 if( bBottom )
4652 aOut.Bottom( rOutRect.Bottom() - nHeight );
4653 aRegion.push_back( aOut );
4654 }
4655 }
4656
4657 if( bLeft )
4658 rOutRect.AddLeft( nWidth );
4659 if( bBottom )
4660 rOutRect.AddBottom( - nHeight );
4661 }
4662 break;
4663 default:
4664 assert(false);
4665 break;
4666 }
4667
4668 vcl::RenderContext *pOut = properties.pSGlobalShell->GetOut();
4669
4670 DrawModeFlags nOldDrawMode = pOut->GetDrawMode();
4671 Color aShadowColor( rShadow.GetColor().GetRGBColor() );
4672 if( !aRegion.empty() && properties.pSGlobalShell->GetWin() &&
4674 {
4675 // In high contrast mode, the output device has already set the
4676 // DrawModeFlags::SettingsFill flag. This causes the SetFillColor function
4677 // to ignore the setting of a new color. Therefore we have to reset
4678 // the drawing mode
4679 pOut->SetDrawMode( DrawModeFlags::Default );
4680 aShadowColor = properties.pSGlobalShell->GetViewOptions()->GetFontColor();
4681 }
4682
4683 if ( pOut->GetFillColor() != aShadowColor )
4684 pOut->SetFillColor( aShadowColor );
4685
4686 pOut->SetLineColor();
4687
4688 pOut->SetDrawMode( nOldDrawMode );
4689
4690 for (const SwRect & rOut : aRegion)
4691 {
4692 aOut = rOut;
4693 if ( rRect.Overlaps( aOut ) && aOut.Height() > 0 && aOut.Width() > 0 )
4694 {
4695 aOut.Intersection_( rRect );
4696 pOut->DrawRect( aOut.SVRect() );
4697 }
4698 }
4699}
4700
4710void SwFrame::PaintShadow( const SwRect& rRect, SwRect& rOutRect,
4711 const SwBorderAttrs &rAttrs ) const
4712{
4713 SvxShadowItem rShadow = rAttrs.GetShadow();
4714
4715 const bool bCnt = IsContentFrame();
4716 const bool bTop = !bCnt || rAttrs.GetTopLine ( *(this) );
4717 const bool bBottom = !bCnt || rAttrs.GetBottomLine( *(this) );
4718
4719 if( IsVertical() )
4720 {
4721 switch( rShadow.GetLocation() )
4722 {
4723 case SvxShadowLocation::BottomRight: rShadow.SetLocation(SvxShadowLocation::BottomLeft); break;
4724 case SvxShadowLocation::TopLeft: rShadow.SetLocation(SvxShadowLocation::TopRight); break;
4725 case SvxShadowLocation::TopRight: rShadow.SetLocation(SvxShadowLocation::BottomRight); break;
4726 case SvxShadowLocation::BottomLeft: rShadow.SetLocation(SvxShadowLocation::TopLeft); break;
4727 default: break;
4728 }
4729 }
4730
4731 // determine, if full shadow rectangle have to be drawn or only two shadow rectangles beside the frame.
4732 // draw full shadow rectangle, if frame background is drawn transparent.
4733 // Status Quo:
4734 // SwLayoutFrame can have transparent drawn backgrounds. Thus,
4735 // "asked" their frame format.
4736 const bool bDrawFullShadowRectangle =
4737 ( IsLayoutFrame() &&
4738 static_cast<const SwLayoutFrame*>(this)->GetFormat()->IsBackgroundTransparent()
4739 );
4740
4741 SwRectFnSet aRectFnSet(this);
4742 ::lcl_ExtendLeftAndRight( rOutRect, *(this), rAttrs, aRectFnSet.FnRect() );
4743
4744 lcl_PaintShadow(rRect, rOutRect, rShadow, bDrawFullShadowRectangle, bTop, bBottom, true, true, gProp);
4745}
4746
4748 const SwRect& rOutRect,
4749 const SwPageFrame * pPage,
4750 const Color *pColor,
4751 const SvxBorderLineStyle nStyle ) const
4752{
4753 if ( !rOutRect.Overlaps( rRect ) )
4754 return;
4755
4756 SwRect aOut( rOutRect );
4757 aOut.Intersection_( rRect );
4758
4759 const SwTabFrame *pTab = IsCellFrame() ? FindTabFrame() : nullptr;
4760 SubColFlags nSubCol = ( IsCellFrame() || IsRowFrame() )
4761 ? SubColFlags::Tab
4762 : ( IsInSct()
4763 ? SubColFlags::Sect
4764 : ( IsInFly() ? SubColFlags::Fly : SubColFlags::Page ) );
4765 if( pColor && gProp.pSGlobalShell->GetWin() &&
4767 {
4769 const SwViewOption *pOpt = pSh->GetViewOptions();
4770 pColor = &pOpt->GetFontColor();
4771 }
4772
4773 if (pPage->GetSortedObjs() &&
4775 {
4776 SwRegionRects aRegion( aOut, 4 );
4778 ::lcl_SubtractFlys( this, pPage, aOut, aRegion, aClipState, gProp );
4779 for ( size_t i = 0; i < aRegion.size(); ++i )
4780 gProp.pSLines->AddLineRect( aRegion[i], pColor, nStyle, pTab, nSubCol, gProp );
4781 }
4782 else
4783 gProp.pSLines->AddLineRect( aOut, pColor, nStyle, pTab, nSubCol, gProp );
4784}
4785
4787{
4788 namespace {
4789
4790 class SwBorderRectanglePrimitive2D : public BufferedDecompositionPrimitive2D
4791 {
4792 private:
4795
4801
4802 protected:
4804 virtual void create2DDecomposition(
4805 Primitive2DContainer& rContainer,
4806 const geometry::ViewInformation2D& rViewInformation) const override;
4807
4808 public:
4810 SwBorderRectanglePrimitive2D(
4811 basegfx::B2DHomMatrix aB2DHomMatrix,
4812 const svx::frame::Style& rStyleTop,
4813 const svx::frame::Style& rStyleRight,
4814 const svx::frame::Style& rStyleBottom,
4815 const svx::frame::Style& rStyleLeft);
4816
4818 const basegfx::B2DHomMatrix& getB2DHomMatrix() const { return maB2DHomMatrix; }
4819 const svx::frame::Style& getStyleTop() const { return maStyleTop; }
4820 const svx::frame::Style& getStyleRight() const { return maStyleRight; }
4821 const svx::frame::Style& getStyleBottom() const { return maStyleBottom; }
4822 const svx::frame::Style& getStyleLeft() const { return maStyleLeft; }
4823
4825 virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
4826
4828 virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override;
4829
4831 virtual sal_uInt32 getPrimitive2DID() const override;
4832 };
4833
4834 }
4835
4836 void SwBorderRectanglePrimitive2D::create2DDecomposition(
4837 Primitive2DContainer& rContainer,
4838 const geometry::ViewInformation2D& /*rViewInformation*/) const
4839 {
4840 basegfx::B2DPoint aTopLeft(getB2DHomMatrix() * basegfx::B2DPoint(0.0, 0.0));
4841 basegfx::B2DPoint aTopRight(getB2DHomMatrix() * basegfx::B2DPoint(1.0, 0.0));
4842 basegfx::B2DPoint aBottomLeft(getB2DHomMatrix() * basegfx::B2DPoint(0.0, 1.0));
4843 basegfx::B2DPoint aBottomRight(getB2DHomMatrix() * basegfx::B2DPoint(1.0, 1.0));
4844
4845 // prepare SdrFrameBorderDataVector
4847
4848 if(getStyleTop().IsUsed())
4849 {
4850 // move top left/right inwards half border width
4851 basegfx::B2DVector aDown(getB2DHomMatrix() * basegfx::B2DVector(0.0, 1.0));
4852 aDown.setLength(getStyleTop().GetWidth() * 0.5);
4853 aTopLeft += aDown;
4854 aTopRight += aDown;
4855 }
4856
4857 if(getStyleBottom().IsUsed())
4858 {
4859 // move bottom left/right inwards half border width
4860 basegfx::B2DVector aUp(getB2DHomMatrix() * basegfx::B2DVector(0.0, -1.0));
4861 aUp.setLength(getStyleBottom().GetWidth() * 0.5);
4862 aBottomLeft += aUp;
4863 aBottomRight += aUp;
4864 }
4865
4866 if(getStyleLeft().IsUsed())
4867 {
4868 // move left top/bottom inwards half border width
4869 basegfx::B2DVector aRight(getB2DHomMatrix() * basegfx::B2DVector(1.0, 0.0));
4870 aRight.setLength(getStyleLeft().GetWidth() * 0.5);
4871 aTopLeft += aRight;
4872 aBottomLeft += aRight;
4873 }
4874
4875 if(getStyleRight().IsUsed())
4876 {
4877 // move right top/bottom inwards half border width
4878 basegfx::B2DVector aLeft(getB2DHomMatrix() * basegfx::B2DVector(-1.0, 0.0));
4879 aLeft.setLength(getStyleRight().GetWidth() * 0.5);
4880 aTopRight += aLeft;
4881 aBottomRight += aLeft;
4882 }
4883
4884 // go round-robin, from TopLeft to TopRight, down, left and back up. That
4885 // way, the borders will not need to be mirrored in any way
4886 if(getStyleTop().IsUsed())
4887 {
4888 // create BorderPrimitive(s) for top border
4889 const basegfx::B2DVector aVector(aTopRight - aTopLeft);
4890 aData.emplace_back(
4891 aTopLeft,
4892 aVector,
4893 getStyleTop(),
4894 nullptr);
4896
4897 if(getStyleLeft().IsUsed())
4898 {
4899 rInstance.addSdrConnectStyleData(true, getStyleLeft(), basegfx::B2DVector(aBottomLeft - aTopLeft), false);
4900 }
4901
4902 if(getStyleRight().IsUsed())
4903 {
4904 rInstance.addSdrConnectStyleData(false, getStyleRight(), basegfx::B2DVector(aBottomRight - aTopRight), false);
4905 }
4906 }
4907
4908 if(getStyleRight().IsUsed())
4909 {
4910 // create BorderPrimitive(s) for right border
4911 const basegfx::B2DVector aVector(aBottomRight - aTopRight);
4912 aData.emplace_back(
4913 aTopRight,
4914 aVector,
4915 getStyleRight(),
4916 nullptr);
4918
4919 if(getStyleTop().IsUsed())
4920 {
4921 rInstance.addSdrConnectStyleData(true, getStyleTop(), basegfx::B2DVector(aTopLeft - aTopRight), false);
4922 }
4923
4924 if(getStyleBottom().IsUsed())
4925 {
4926 rInstance.addSdrConnectStyleData(false, getStyleBottom(), basegfx::B2DVector(aBottomLeft - aBottomRight), false);
4927 }
4928 }
4929
4930 if(getStyleBottom().IsUsed())
4931 {
4932 // create BorderPrimitive(s) for bottom border
4933 const basegfx::B2DVector aVector(aBottomLeft - aBottomRight);
4934 aData.emplace_back(
4935 aBottomRight,
4936 aVector,
4937 getStyleBottom(),
4938 nullptr);
4940
4941 if(getStyleRight().IsUsed())
4942 {
4943 rInstance.addSdrConnectStyleData(true, getStyleRight(), basegfx::B2DVector(aTopRight - aBottomRight), false);
4944 }
4945
4946 if(getStyleLeft().IsUsed())
4947 {
4948 rInstance.addSdrConnectStyleData(false, getStyleLeft(), basegfx::B2DVector(aTopLeft - aBottomLeft), false);
4949 }
4950 }
4951
4952 if(getStyleLeft().IsUsed())
4953 {
4954 // create BorderPrimitive(s) for left border
4955 const basegfx::B2DVector aVector(aTopLeft - aBottomLeft);
4956 aData.emplace_back(
4957 aBottomLeft,
4958 aVector,
4959 getStyleLeft(),
4960 nullptr);
4962
4963 if(getStyleBottom().IsUsed())
4964 {
4965 rInstance.addSdrConnectStyleData(true, getStyleBottom(), basegfx::B2DVector(aBottomRight - aBottomLeft), false);
4966 }
4967
4968 if(getStyleTop().IsUsed())
4969 {
4970 rInstance.addSdrConnectStyleData(false, getStyleTop(), basegfx::B2DVector(aTopRight - aTopLeft), false);
4971 }
4972 }
4973
4974 // create instance of SdrFrameBorderPrimitive2D if
4975 // SdrFrameBorderDataVector is used
4976 if(!aData.empty())
4977 {
4978 rContainer.append(
4981 std::move(aData),
4982 true))); // force visualization to minimal one discrete unit (pixel)
4983 }
4984 }
4985
4986 SwBorderRectanglePrimitive2D::SwBorderRectanglePrimitive2D(
4987 basegfx::B2DHomMatrix aB2DHomMatrix,
4988 const svx::frame::Style& rStyleTop,
4989 const svx::frame::Style& rStyleRight,
4990 const svx::frame::Style& rStyleBottom,
4991 const svx::frame::Style& rStyleLeft)
4992 : maB2DHomMatrix(std::move(aB2DHomMatrix)),
4993 maStyleTop(rStyleTop),
4994 maStyleRight(rStyleRight),
4995 maStyleBottom(rStyleBottom),
4996 maStyleLeft(rStyleLeft)
4997 {
4998 }
4999
5000 bool SwBorderRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
5001 {
5002 if(BasePrimitive2D::operator==(rPrimitive))
5003 {
5004 const SwBorderRectanglePrimitive2D& rCompare = static_cast<const SwBorderRectanglePrimitive2D&>(rPrimitive);
5005
5006 return (getB2DHomMatrix() == rCompare.getB2DHomMatrix() &&
5007 getStyleTop() == rCompare.getStyleTop() &&
5008 getStyleRight() == rCompare.getStyleRight() &&
5009 getStyleBottom() == rCompare.getStyleBottom() &&
5010 getStyleLeft() == rCompare.getStyleLeft());
5011 }
5012
5013 return false;
5014 }
5015
5016 basegfx::B2DRange SwBorderRectanglePrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
5017 {
5018 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
5019
5020 aRetval.transform(getB2DHomMatrix());
5021 return aRetval;
5022 }
5023
5024 // provide unique ID
5025 sal_uInt32 SwBorderRectanglePrimitive2D::getPrimitive2DID() const
5026 {
5028 }
5029
5030} // end of namespace drawinglayer::primitive2d
5031
5032namespace {
5033
5034editeng::SvxBorderLine const * get_ptr(std::optional<editeng::SvxBorderLine> const & opt) {
5035 return opt ? &*opt : nullptr;
5036}
5037
5038}
5039
5041 const SwFont& rFont,
5042 const SwRect& rPaintArea,
5043 const bool bVerticalLayout,
5044 const bool bVerticalLayoutLRBT,
5045 const bool bJoinWithPrev,
5046 const bool bJoinWithNext )
5047{
5048 SwRect aAlignedRect(rPaintArea);
5049 SwAlignRect(aAlignedRect, gProp.pSGlobalShell, gProp.pSGlobalShell->GetOut());
5050
5051 bool bTop = true;
5052 bool bBottom = true;
5053 bool bLeft = true;
5054 bool bRight = true;
5055
5056 switch (rFont.GetOrientation(bVerticalLayout, bVerticalLayoutLRBT).get())
5057 {
5058 case 0 :
5059 bLeft = !bJoinWithPrev;
5060 bRight = !bJoinWithNext;
5061 break;
5062 case 900 :
5063 bBottom = !bJoinWithPrev;
5064 bTop = !bJoinWithNext;
5065 break;
5066 case 1800 :
5067 bRight = !bJoinWithPrev;
5068 bLeft = !bJoinWithNext;
5069 break;
5070 case 2700 :
5071 bTop = !bJoinWithPrev;
5072 bBottom = !bJoinWithNext;
5073 break;
5074 }
5075
5076 // Paint shadow (reduce painting rect)
5077 {
5078 const SvxShadowItem aShadow(
5079 0, &rFont.GetShadowColor(), rFont.GetShadowWidth(),
5080 rFont.GetAbsShadowLocation(bVerticalLayout, bVerticalLayoutLRBT));
5081
5082 if( aShadow.GetLocation() != SvxShadowLocation::NONE )
5083 {
5084 lcl_PaintShadow( rPaintArea, aAlignedRect, aShadow,
5085 false, bTop, bBottom, bLeft, bRight, gProp);
5086 }
5087 }
5088
5089 const basegfx::B2DHomMatrix aBorderTransform(
5091 aAlignedRect.Width(), aAlignedRect.Height(),
5092 aAlignedRect.Left(), aAlignedRect.Top()));
5093 const svx::frame::Style aStyleTop(
5094 bTop ? get_ptr(rFont.GetAbsTopBorder(bVerticalLayout, bVerticalLayoutLRBT)) : nullptr,
5095 1.0);
5096 const svx::frame::Style aStyleRight(
5097 bRight ? get_ptr(rFont.GetAbsRightBorder(bVerticalLayout, bVerticalLayoutLRBT)) : nullptr,
5098 1.0);
5099 const svx::frame::Style aStyleBottom(
5100 bBottom ? get_ptr(rFont.GetAbsBottomBorder(bVerticalLayout, bVerticalLayoutLRBT))
5101 : nullptr,
5102 1.0);
5103 const svx::frame::Style aStyleLeft(
5104 bLeft ? get_ptr(rFont.GetAbsLeftBorder(bVerticalLayout, bVerticalLayoutLRBT)) : nullptr,
5105 1.0);
5107
5108 aBorderLineTarget.append(
5110 new drawinglayer::primitive2d::SwBorderRectanglePrimitive2D(
5111 aBorderTransform,
5112 aStyleTop,
5113 aStyleRight,
5114 aStyleBottom,
5115 aStyleLeft)));
5116 gProp.pBLines->AddBorderLines(std::move(aBorderLineTarget));
5117}
5118
5120static const SwFrame* lcl_HasNextCell( const SwFrame& rFrame )
5121{
5122 OSL_ENSURE( rFrame.IsCellFrame(),
5123 "lcl_HasNextCell( const SwFrame& rFrame ) should be called with SwCellFrame" );
5124
5125 const SwFrame* pTmpFrame = &rFrame;
5126 do
5127 {
5128 if ( pTmpFrame->GetNext() )
5129 return pTmpFrame->GetNext();
5130
5131 pTmpFrame = pTmpFrame->GetUpper()->GetUpper();
5132 }
5133 while ( pTmpFrame->IsCellFrame() );
5134
5135 return nullptr;
5136}
5137
5159static const SwFrame* lcl_GetCellFrameForBorderAttrs( const SwFrame* _pCellFrame,
5160 const SwBorderAttrs& _rCellBorderAttrs,
5161 const bool _bTop )
5162{
5163 OSL_ENSURE( _pCellFrame, "No cell frame available, dying soon" );
5164
5165 // determine, if cell frame is at bottom/top border of a table frame and
5166 // the table frame has/is a follow.
5167 const SwFrame* pTmpFrame = _pCellFrame;
5168 bool bCellAtBorder = true;
5169 bool bCellAtLeftBorder = !_pCellFrame->GetPrev();
5170 bool bCellAtRightBorder = !_pCellFrame->GetNext();
5171 while( !pTmpFrame->IsRowFrame() || !pTmpFrame->GetUpper()->IsTabFrame() )
5172 {
5173 pTmpFrame = pTmpFrame->GetUpper();
5174 if ( pTmpFrame->IsRowFrame() &&
5175 (_bTop ? pTmpFrame->GetPrev() : pTmpFrame->GetNext())
5176 )
5177 {
5178 bCellAtBorder = false;
5179 }
5180 if ( pTmpFrame->IsCellFrame() )
5181 {
5182 if ( pTmpFrame->GetPrev() )
5183 {
5184 bCellAtLeftBorder = false;
5185 }
5186 if ( pTmpFrame->GetNext() )
5187 {
5188 bCellAtRightBorder = false;
5189 }
5190 }
5191 }
5192 OSL_ENSURE( pTmpFrame && pTmpFrame->IsRowFrame(), "No RowFrame available" );
5193
5194 const SwLayoutFrame* pParentRowFrame = static_cast<const SwLayoutFrame*>(pTmpFrame);
5195 const SwTabFrame* pParentTabFrame =
5196 static_cast<const SwTabFrame*>(pParentRowFrame->GetUpper());
5197
5198 const bool bCellNeedsAttribute = bCellAtBorder &&
5199 ( _bTop ?
5200 // bCellInFirstRowWithMaster
5201 ( !pParentRowFrame->GetPrev() &&
5202 pParentTabFrame->IsFollow() &&
5203 0 == pParentTabFrame->GetTable()->GetRowsToRepeat() ) :
5204 // bCellInLastRowWithFollow
5205 ( !pParentRowFrame->GetNext() &&
5206 pParentTabFrame->GetFollow() )
5207 );
5208
5209 const SwFrame* pRet = _pCellFrame;
5210 if ( bCellNeedsAttribute )
5211 {
5212 // determine, if cell frame has no borders inside the table.
5213 const SwFrame* pNextCell = nullptr;
5214 bool bNoBordersInside = false;
5215
5216 if ( bCellAtLeftBorder && ( nullptr != ( pNextCell = lcl_HasNextCell( *_pCellFrame ) ) ) )
5217 {
5218 SwBorderAttrAccess aAccess( SwFrame::GetCache(), pNextCell );
5219 const SwBorderAttrs &rBorderAttrs = *aAccess.Get();
5220 const SvxBoxItem& rBorderBox = rBorderAttrs.GetBox();
5221 bCellAtRightBorder = !lcl_HasNextCell( *pNextCell );
5222 bNoBordersInside =
5223 ( !rBorderBox.GetTop() || !pParentRowFrame->GetPrev() ) &&
5224 !rBorderBox.GetLeft() &&
5225 ( !rBorderBox.GetRight() || bCellAtRightBorder ) &&
5226 ( !rBorderBox.GetBottom() || !pParentRowFrame->GetNext() );
5227 }
5228 else
5229 {
5230 const SvxBoxItem& rBorderBox = _rCellBorderAttrs.GetBox();
5231 bNoBordersInside =
5232 ( !rBorderBox.GetTop() || !pParentRowFrame->GetPrev() ) &&
5233 ( !rBorderBox.GetLeft() || bCellAtLeftBorder ) &&
5234 ( !rBorderBox.GetRight() || bCellAtRightBorder ) &&
5235 ( !rBorderBox.GetBottom() || !pParentRowFrame->GetNext() );
5236 }
5237
5238 if ( bNoBordersInside )
5239 {
5240 if ( _bTop && !_rCellBorderAttrs.GetBox().GetTop() )
5241 {
5242 //-hack
5243 // Cell frame has no top border and no border inside the table, but
5244 // it is at the top border of a table frame, which is a follow.
5245 // Thus, use border attributes of cell frame in first row of complete table.
5246 // First, determine first table frame of complete table.
5247 SwTabFrame* pMasterTabFrame = pParentTabFrame->FindMaster( true );
5248 // determine first row of complete table.
5249 const SwFrame* pFirstRow = pMasterTabFrame->GetLower();
5250 // return first cell in first row
5251 SwFrame* pLowerCell = const_cast<SwFrame*>(pFirstRow->GetLower());
5252 while ( !pLowerCell->IsCellFrame() ||
5253 ( pLowerCell->GetLower() && pLowerCell->GetLower()->IsRowFrame() )
5254 )
5255 {
5256 pLowerCell = pLowerCell->GetLower();
5257 }
5258 OSL_ENSURE( pLowerCell && pLowerCell->IsCellFrame(), "No CellFrame available" );
5259 pRet = pLowerCell;
5260 }
5261 else if ( !_bTop && !_rCellBorderAttrs.GetBox().GetBottom() )
5262 {
5263 //-hack
5264 // Cell frame has no bottom border and no border inside the table,
5265 // but it is at the bottom border of a table frame, which has a follow.
5266 // Thus, use border attributes of cell frame in last row of complete table.
5267 // First, determine last table frame of complete table.
5268 SwTabFrame* pLastTabFrame = const_cast<SwTabFrame*>(pParentTabFrame->GetFollow());
5269 while ( pLastTabFrame->GetFollow() )
5270 {
5271 pLastTabFrame = pLastTabFrame->GetFollow();
5272 }
5273 // determine last row of complete table.
5274 SwFrame* pLastRow = pLastTabFrame->GetLastLower();
5275 // return first bottom border cell in last row
5276 SwFrame* pLowerCell = pLastRow->GetLower();
5277 while ( !pLowerCell->IsCellFrame() ||
5278 ( pLowerCell->GetLower() && pLowerCell->GetLower()->IsRowFrame() )
5279 )
5280 {
5281 if ( pLowerCell->IsRowFrame() )
5282 {
5283 while ( pLowerCell->GetNext() )
5284 {
5285 pLowerCell = pLowerCell->GetNext();
5286 }
5287 }
5288 pLowerCell = pLowerCell->GetLower();
5289 }
5290 OSL_ENSURE( pLowerCell && pLowerCell->IsCellFrame(), "No CellFrame available" );
5291 pRet = pLowerCell;
5292 }
5293 }
5294 }
5295
5296 return pRet;
5297}
5298
5299std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> SwFrame::CreateProcessor2D( ) const
5300{
5301 basegfx::B2DRange aViewRange;
5302
5303 SdrPage *pDrawPage = getRootFrame()->GetCurrShell()->Imp()->GetPageView()->GetPage();
5305 aNewViewInfos.setViewTransformation(getRootFrame()->GetCurrShell()->GetOut()->GetViewTransformation());
5306 aNewViewInfos.setViewport(aViewRange);
5307 aNewViewInfos.setVisualizedPage(GetXDrawPageForSdrPage( pDrawPage ));
5308
5310 *getRootFrame()->GetCurrShell()->GetOut(),
5311 aNewViewInfos );
5312}
5313
5315{
5316 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D = CreateProcessor2D();
5317 if ( pProcessor2D )
5318 {
5319 pProcessor2D->process( rSequence );
5320 }
5321}
5322
5325 const SwRect& rRect,
5326 const SwPageFrame* /*pPage*/,
5327 const SwBorderAttrs& rAttrs) const
5328{
5329 // There's nothing (Row,Body,Footnote,Root,Column,NoText) need to do here
5331 return;
5332
5333 if (IsCellFrame() && !gProp.pSGlobalShell->GetViewOptions()->IsTable())
5334 return;
5335
5336 // #i29550#
5337 if ( IsTabFrame() || IsCellFrame() || IsRowFrame() )
5338 {
5339 const SwTabFrame* pTabFrame = FindTabFrame();
5340 if ( pTabFrame->IsCollapsingBorders() )
5341 return;
5342
5343 if ( pTabFrame->GetTable()->IsNewModel() && ( !IsCellFrame() || IsCoveredCell() ) )
5344 return;
5345 }
5346
5347 const bool bLine = rAttrs.IsLine();
5348 const bool bShadow = rAttrs.GetShadow().GetLocation() != SvxShadowLocation::NONE;
5349
5350 // - flag to control,
5351 //-hack has to be used.
5352 const bool bb4779636HackActive = true;
5353
5354 const SwFrame* pCellFrameForBottomBorderAttrs = nullptr;
5355 const SwFrame* pCellFrameForTopBorderAttrs = nullptr;
5356 bool bFoundCellForTopOrBorderAttrs = false;
5357 if ( bb4779636HackActive && IsCellFrame() )
5358 {
5359 pCellFrameForBottomBorderAttrs = lcl_GetCellFrameForBorderAttrs( this, rAttrs, false );
5360 if ( pCellFrameForBottomBorderAttrs != this )
5361 bFoundCellForTopOrBorderAttrs = true;
5362 pCellFrameForTopBorderAttrs = lcl_GetCellFrameForBorderAttrs( this, rAttrs, true );
5363 if ( pCellFrameForTopBorderAttrs != this )
5364 bFoundCellForTopOrBorderAttrs = true;
5365 }
5366
5367 // - add condition <bFoundCellForTopOrBorderAttrs>
5368 //-hack
5369 if ( !(bLine || bShadow || bFoundCellForTopOrBorderAttrs) )
5370 return;
5371
5372 //If the rectangle is completely inside the PrtArea, no border needs to
5373 //be painted.
5374 //For the PrtArea the aligned value needs to be used, otherwise it could
5375 //happen, that some parts won't be processed.
5376 SwRect aRect( getFramePrintArea() );
5377 aRect += getFrameArea().Pos();
5378 ::SwAlignRect( aRect, gProp.pSGlobalShell, gProp.pSGlobalShell->GetOut() );
5379 // new local boolean variable in order to
5380 // suspend border paint under special cases - see below.
5381 // NOTE: This is a fix for the implementation of feature #99657#.
5382 bool bDrawOnlyShadowForTransparentFrame = false;
5383 if ( aRect.Contains( rRect ) )
5384 {
5385 // paint shadow, if background is transparent.
5386 // Because of introduced transparent background for fly frame #99657#,
5387 // the shadow have to be drawn if the background is transparent,
5388 // in spite the fact that the paint rectangle <rRect> lies fully
5389 // in the printing area.
5390 // NOTE to chosen solution:
5391 // On transparent background, continue processing, but suspend
5392 // drawing of border by setting <bDrawOnlyShadowForTransparentFrame>
5393 // to true.
5394 if ( IsLayoutFrame() &&
5395 static_cast<const SwLayoutFrame*>(this)->GetFormat()->IsBackgroundTransparent() )
5396 {
5397 bDrawOnlyShadowForTransparentFrame = true;
5398 }
5399 else
5400 {
5401 return;
5402 }
5403 }
5404
5405 ::lcl_CalcBorderRect( aRect, this, rAttrs, true, gProp );
5406 rAttrs.SetGetCacheLine( true );
5407
5408 if(bShadow)
5409 {
5410 PaintShadow(rRect, aRect, rAttrs);
5411 }
5412
5413 // suspend drawing of border
5414 // add condition < NOT bDrawOnlyShadowForTransparentFrame > - see above
5415 // - add condition <bFoundCellForTopOrBorderAttrs>
5416 //-hack.
5417 if((bLine || bFoundCellForTopOrBorderAttrs) && !bDrawOnlyShadowForTransparentFrame)
5418 {
5419 // define SvxBorderLine(s) to use
5420 const SvxBoxItem& rBox(rAttrs.GetBox());
5421 const SvxBorderLine* pLeftBorder(rBox.GetLeft());
5422 const SvxBorderLine* pRightBorder(rBox.GetRight());
5423 const SvxBorderLine* pTopBorder(rBox.GetTop());
5424 const SvxBorderLine* pBottomBorder(rBox.GetBottom());
5425
5426 // if R2L, exchange Right/Left
5427 const bool bR2L(IsCellFrame() && IsRightToLeft());
5428
5429 if(bR2L)
5430 {
5431 std::swap(pLeftBorder, pRightBorder);
5432 }
5433
5434 // if ContentFrame and joined Prev/Next, reset top/bottom as needed
5435 if(IsContentFrame())
5436 {
5437 const SwFrame* pDirRefFrame(IsCellFrame() ? FindTabFrame() : this);
5438 const SwRectFnSet aRectFnSet(pDirRefFrame);
5439 const SwRectFn& _rRectFn(aRectFnSet.FnRect());
5440
5441 if(rAttrs.JoinedWithPrev(*this))
5442 {
5443 // tdf#115296 re-add adaptation of vert distance to close the evtl.
5444 // existing gap to previous frame
5445 const SwFrame* pPrevFrame(GetPrev());
5446 (aRect.*_rRectFn->fnSetTop)( (pPrevFrame->*_rRectFn->fnGetPrtBottom)() );
5447
5448 // ...and disable top border paint/creation
5449 pTopBorder = nullptr;
5450 }
5451
5452 if(rAttrs.JoinedWithNext(*this))
5453 {
5454 // tdf#115296 re-add adaptation of vert distance to close the evtl.
5455 // existing gap to next frame
5456 const SwFrame* pNextFrame(GetNext());
5457 (aRect.*_rRectFn->fnSetBottom)( (pNextFrame->*_rRectFn->fnGetPrtTop)() );
5458
5459 // ...and disable bottom border paint/creation
5460 pBottomBorder = nullptr;
5461 }
5462 }
5463
5464 // necessary to replace TopBorder?
5465 if((!IsContentFrame() || rAttrs.GetTopLine(*this)) && IsCellFrame() && pCellFrameForTopBorderAttrs != this)
5466 {
5467 SwBorderAttrAccess aAccess(SwFrame::GetCache(), pCellFrameForTopBorderAttrs);
5468 pTopBorder = aAccess.Get()->GetBox().GetTop();
5469 }
5470
5471 // necessary to replace BottomBorder?
5472 if((!IsContentFrame() || rAttrs.GetBottomLine(*this)) && IsCellFrame() && pCellFrameForBottomBorderAttrs != this)
5473