Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svx/source/xoutdev/xtabgrdt.cxx
Line
Count
Source (jump to first uncovered line)
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
22
#include <vcl/virdev.hxx>
23
#include <svx/strings.hrc>
24
#include <svx/dialmgr.hxx>
25
#include <svx/xtable.hxx>
26
27
#include <rtl/ustrbuf.hxx>
28
#include <vcl/svapp.hxx>
29
#include <vcl/settings.hxx>
30
#include <osl/diagnose.h>
31
32
#include <drawinglayer/attribute/fillgradientattribute.hxx>
33
#include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
34
#include <drawinglayer/primitive2d/PolyPolygonGradientPrimitive2D.hxx>
35
#include <drawinglayer/processor2d/baseprocessor2d.hxx>
36
#include <drawinglayer/processor2d/processor2dtools.hxx>
37
#include <basegfx/polygon/b2dpolygontools.hxx>
38
#include <memory>
39
40
using namespace com::sun::star;
41
42
XGradientList::XGradientList( const OUString& rPath, const OUString& rReferer )
43
163k
:   XPropertyList( XPropertyListType::Gradient, rPath, rReferer )
44
163k
{
45
163k
}
46
47
XGradientList::~XGradientList()
48
163k
{
49
163k
}
50
51
void XGradientList::Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex)
52
0
{
53
0
    XPropertyList::Replace(std::move(pEntry), nIndex);
54
0
}
55
56
XGradientEntry* XGradientList::GetGradient(tools::Long nIndex) const
57
0
{
58
0
    return static_cast<XGradientEntry*>( XPropertyList::Get( nIndex ) );
59
0
}
60
61
uno::Reference< container::XNameContainer > XGradientList::createInstance()
62
995
{
63
995
    return SvxUnoXGradientTable_createInstance( *this );
64
995
}
65
66
bool XGradientList::Create()
67
1.92k
{
68
1.92k
    OUStringBuffer aStr(SvxResId(RID_SVXSTR_GRADIENT) + " 1");
69
1.92k
    sal_Int32 nLen = aStr.getLength() - 1;
70
71
    // XGradient() default already creates [COL_BLACK, COL_WHITE] as defaults
72
1.92k
    Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(),aStr.toString()));
73
74
1.92k
    aStr[nLen] = '2';
75
1.92k
    Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_BLUE.getBColor(),    COL_RED.getBColor()),     css::awt::GradientStyle_AXIAL     ,  300_deg10,20,20,10,100,100),aStr.toString()));
76
1.92k
    aStr[nLen] = '3';
77
1.92k
    Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_RED.getBColor(),     COL_YELLOW.getBColor()),  css::awt::GradientStyle_RADIAL    ,  600_deg10,30,30,20,100,100),aStr.toString()));
78
1.92k
    aStr[nLen] = '4';
79
1.92k
    Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_YELLOW.getBColor(),  COL_GREEN.getBColor()),   css::awt::GradientStyle_ELLIPTICAL,  900_deg10,40,40,30,100,100),aStr.toString()));
80
1.92k
    aStr[nLen] = '5';
81
1.92k
    Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_GREEN.getBColor(),   COL_MAGENTA.getBColor()), css::awt::GradientStyle_SQUARE    , 1200_deg10,50,50,40,100,100),aStr.toString()));
82
1.92k
    aStr[nLen] = '6';
83
1.92k
    Insert(std::make_unique<XGradientEntry>(basegfx::BGradient(basegfx::BColorStops(COL_MAGENTA.getBColor(), COL_YELLOW.getBColor()),  css::awt::GradientStyle_RECT      , 1900_deg10,60,60,50,100,100),aStr.toString()));
84
85
1.92k
    return true;
86
1.92k
}
87
88
BitmapEx XGradientList::CreateBitmap( tools::Long nIndex, const Size& rSize ) const
89
0
{
90
0
    BitmapEx aRetval;
91
92
0
    OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
93
94
0
    if(nIndex < Count())
95
0
    {
96
0
        const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
97
        // prepare polygon geometry for rectangle
98
0
        basegfx::B2DPolygon aRectangle(
99
0
            basegfx::utils::createPolygonFromRect(
100
0
                basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
101
102
0
        const basegfx::BGradient& rGradient = GetGradient(nIndex)->GetGradient();
103
0
        basegfx::BColorStops aColorStops(rGradient.GetColorStops());
104
105
0
        if (rGradient.GetStartIntens() != 100 || rGradient.GetEndIntens() != 100)
106
0
        {
107
            // Need to do the (old, crazy) blend against black
108
0
            aColorStops.blendToIntensity(
109
0
                    rGradient.GetStartIntens() * 0.01,
110
0
                rGradient.GetEndIntens() * 0.01,
111
0
                basegfx::BColor()); // COL_BLACK
112
0
        }
113
114
0
        drawinglayer::attribute::FillGradientAttribute aFillGradient(
115
0
            rGradient.GetGradientStyle(),
116
0
            static_cast<double>(rGradient.GetBorder()) * 0.01,
117
0
            static_cast<double>(rGradient.GetXOffset()) * 0.01,
118
0
            static_cast<double>(rGradient.GetYOffset()) * 0.01,
119
0
            toRadians(rGradient.GetAngle()),
120
0
            aColorStops);
121
122
0
        const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
123
0
            new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
124
0
                basegfx::B2DPolyPolygon(aRectangle),
125
0
                std::move(aFillGradient)));
126
127
0
        const basegfx::BColor aBlack(0.0, 0.0, 0.0);
128
0
        const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
129
0
            new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
130
0
                std::move(aRectangle),
131
0
                aBlack));
132
133
        // prepare VirtualDevice
134
0
        ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
135
0
        const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
136
137
0
        pVirtualDevice->SetOutputSizePixel(rSize);
138
0
        pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
139
0
            ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
140
0
            : DrawModeFlags::Default);
141
142
        // create processor and draw primitives
143
0
        std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
144
0
            *pVirtualDevice,
145
0
            aNewViewInformation2D));
146
147
0
        drawinglayer::primitive2d::Primitive2DContainer aSequence {
148
0
            aGradientPrimitive,
149
0
            aBlackRectanglePrimitive };
150
151
0
        pProcessor2D->process(aSequence);
152
0
        pProcessor2D.reset();
153
154
        // get result bitmap and scale
155
0
        aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
156
0
    }
157
158
0
    return aRetval;
159
0
}
160
161
BitmapEx XGradientList::CreateBitmapForUI(tools::Long nIndex)
162
0
{
163
0
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
164
0
    const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
165
0
    return CreateBitmap(nIndex, rSize);
166
0
}
167
168
BitmapEx XGradientList::GetBitmapForPreview(tools::Long nIndex, const Size& rSize)
169
0
{
170
0
    return CreateBitmap(nIndex, rSize);
171
0
}
172
173
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */