Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/xoutdev/xtablend.cxx
Line
Count
Source
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 <XPropertyTable.hxx>
21
#include <vcl/virdev.hxx>
22
23
#include <vcl/rendercontext/DrawModeFlags.hxx>
24
#include <vcl/svapp.hxx>
25
#include <vcl/settings.hxx>
26
27
#include <svx/strings.hrc>
28
#include <svx/dialmgr.hxx>
29
#include <osl/diagnose.h>
30
31
#include <svx/xtable.hxx>
32
#include <drawinglayer/attribute/linestartendattribute.hxx>
33
#include <drawinglayer/primitive2d/PolygonStrokeArrowPrimitive2D.hxx>
34
#include <drawinglayer/processor2d/baseprocessor2d.hxx>
35
#include <drawinglayer/processor2d/processor2dtools.hxx>
36
#include <basegfx/polygon/b2dpolygontools.hxx>
37
#include <memory>
38
39
using namespace com::sun::star;
40
41
XLineEndList::XLineEndList( const OUString& rPath, const OUString& rReferer )
42
104k
    : XPropertyList( XPropertyListType::LineEnd, rPath, rReferer )
43
104k
{
44
104k
}
45
46
XLineEndList::~XLineEndList()
47
104k
{
48
104k
}
49
50
XLineEndEntry* XLineEndList::GetLineEnd(tools::Long nIndex) const
51
0
{
52
0
    return static_cast<XLineEndEntry*>( XPropertyList::Get(nIndex) );
53
0
}
54
55
uno::Reference< container::XNameContainer > XLineEndList::createInstance()
56
49
{
57
49
    return SvxUnoXLineEndTable_createInstance( *this );
58
49
}
59
60
bool XLineEndList::Create()
61
0
{
62
0
    basegfx::B2DPolygon aTriangle;
63
0
    aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
64
0
    aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
65
0
    aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
66
0
    aTriangle.setClosed(true);
67
0
    Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aTriangle), SvxResId( RID_SVXSTR_ARROW ) ) );
68
69
0
    basegfx::B2DPolygon aSquare;
70
0
    aSquare.append(basegfx::B2DPoint(0.0, 0.0));
71
0
    aSquare.append(basegfx::B2DPoint(10.0, 0.0));
72
0
    aSquare.append(basegfx::B2DPoint(10.0, 10.0));
73
0
    aSquare.append(basegfx::B2DPoint(0.0, 10.0));
74
0
    aSquare.setClosed(true);
75
0
    Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aSquare), SvxResId( RID_SVXSTR_SQUARE ) ) );
76
77
0
    basegfx::B2DPolygon aCircle(basegfx::utils::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
78
0
    Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aCircle), SvxResId( RID_SVXSTR_CIRCLE ) ) );
79
80
0
    return true;
81
0
}
82
83
Bitmap XLineEndList::CreateBitmapForUI( tools::Long nIndex )
84
0
{
85
0
    Bitmap aRetval;
86
0
    OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
87
88
0
    if(nIndex < Count())
89
0
    {
90
0
        const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
91
0
        const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
92
93
0
        const Size aSize(rSize.Width() * 2, rSize.Height());
94
95
        // prepare line geometry
96
0
        basegfx::B2DPolygon aLine;
97
0
        const double fBorderDistance(aSize.Height() * 0.1);
98
99
0
        aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2));
100
0
        aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2));
101
102
        // prepare LineAttribute
103
0
        const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
104
0
        const double fLineWidth(StyleSettings::GetListBoxPreviewDefaultLineWidth() * 1.1);
105
0
        const drawinglayer::attribute::LineAttribute aLineAttribute(
106
0
            aLineColor,
107
0
            fLineWidth);
108
109
0
        const basegfx::B2DPolyPolygon aLineEnd(GetLineEnd(nIndex)->GetLineEnd());
110
0
        const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance));
111
0
        const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute(
112
0
            fArrowHeight,
113
0
            aLineEnd,
114
0
            false);
115
116
        // prepare line primitive
117
0
        const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive(
118
0
            new drawinglayer::primitive2d::PolygonStrokeArrowPrimitive2D(
119
0
                aLine,
120
0
                aLineAttribute,
121
0
                aLineStartEndAttribute,
122
0
                aLineStartEndAttribute));
123
124
        // prepare VirtualDevice
125
0
        ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
126
0
        const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
127
128
0
        pVirtualDevice->SetOutputSizePixel(aSize);
129
0
        pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
130
0
            ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
131
0
            : DrawModeFlags::Default);
132
133
0
        if(rStyleSettings.GetPreviewUsesCheckeredBackground())
134
0
        {
135
0
            const Point aNull(0, 0);
136
0
            static const sal_uInt32 nLen(8);
137
0
            static const Color aW(COL_WHITE);
138
0
            static const Color aG(0xef, 0xef, 0xef);
139
0
            pVirtualDevice->DrawCheckered(aNull, aSize, nLen, aW, aG);
140
0
        }
141
0
        else
142
0
        {
143
0
            pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
144
0
            pVirtualDevice->Erase();
145
0
        }
146
147
        // create processor and draw primitives
148
0
        std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
149
0
            *pVirtualDevice,
150
0
            aNewViewInformation2D));
151
152
0
        const drawinglayer::primitive2d::Primitive2DContainer aSequence { aLineStartEndPrimitive };
153
154
0
        pProcessor2D->process(aSequence);
155
0
        pProcessor2D.reset();
156
157
        // get result bitmap and scale
158
0
        aRetval = pVirtualDevice->GetBitmap(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
159
0
    }
160
161
0
    return aRetval;
162
0
}
163
164
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */