Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/xoutdev/xtabhtch.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 <tools/mapunit.hxx>
22
#include <vcl/rendercontext/DrawModeFlags.hxx>
23
#include <vcl/svapp.hxx>
24
25
#include <vcl/virdev.hxx>
26
#include <vcl/settings.hxx>
27
#include <svx/strings.hrc>
28
#include <svx/dialmgr.hxx>
29
30
#include <drawinglayer/attribute/fillhatchattribute.hxx>
31
#include <drawinglayer/primitive2d/PolyPolygonHatchPrimitive2D.hxx>
32
#include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
33
#include <drawinglayer/processor2d/baseprocessor2d.hxx>
34
#include <drawinglayer/processor2d/processor2dtools.hxx>
35
#include <basegfx/matrix/b2dhommatrix.hxx>
36
#include <basegfx/polygon/b2dpolygontools.hxx>
37
#include <osl/diagnose.h>
38
#include <rtl/ustrbuf.hxx>
39
#include <memory>
40
41
using namespace ::com::sun::star;
42
43
XHatchList::XHatchList(const OUString& rPath, const OUString& rReferer)
44
109k
  : XPropertyList( XPropertyListType::Hatch, rPath, rReferer )
45
109k
{
46
109k
}
47
48
XHatchList::~XHatchList()
49
109k
{
50
109k
}
51
52
void XHatchList::Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex)
53
0
{
54
0
    XPropertyList::Replace(std::move(pEntry), nIndex);
55
0
}
56
57
XHatchEntry* XHatchList::GetHatch(tools::Long nIndex) const
58
0
{
59
0
    return static_cast<XHatchEntry*>( XPropertyList::Get(nIndex) );
60
0
}
61
62
uno::Reference< container::XNameContainer > XHatchList::createInstance()
63
0
{
64
0
    return SvxUnoXHatchTable_createInstance( *this );
65
0
}
66
67
bool XHatchList::Create()
68
406
{
69
406
    OUStringBuffer aStr(SvxResId(RID_SVXSTR_HATCH) + " 1");
70
71
406
    sal_Int32 nLen = aStr.getLength() - 1;
72
406
    Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLACK,css::drawing::HatchStyle_SINGLE,100,  0_deg10),aStr.toString()));
73
406
    aStr[nLen] = '2';
74
406
    Insert(std::make_unique<XHatchEntry>(XHatch(COL_RED  ,css::drawing::HatchStyle_DOUBLE, 80,450_deg10),aStr.toString()));
75
406
    aStr[nLen] = '3';
76
406
    Insert(std::make_unique<XHatchEntry>(XHatch(COL_BLUE ,css::drawing::HatchStyle_TRIPLE,120,  0_deg10),aStr.toString()));
77
78
406
    return true;
79
406
}
80
81
Bitmap XHatchList::CreateBitmap( tools::Long nIndex, const Size& rSize) const
82
0
{
83
0
    Bitmap aRetval;
84
0
    OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
85
86
0
    if(nIndex < Count())
87
0
    {
88
0
        const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
89
90
        // prepare polygon geometry for rectangle
91
0
        basegfx::B2DPolygon aRectangle(
92
0
            basegfx::utils::createPolygonFromRect(
93
0
                basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
94
95
0
        const XHatch& rHatch = GetHatch(nIndex)->GetHatch();
96
0
        drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HatchStyle::Triple);
97
98
0
        switch(rHatch.GetHatchStyle())
99
0
        {
100
0
            case css::drawing::HatchStyle_SINGLE :
101
0
            {
102
0
                aHatchStyle = drawinglayer::attribute::HatchStyle::Single;
103
0
                break;
104
0
            }
105
0
            case css::drawing::HatchStyle_DOUBLE :
106
0
            {
107
0
                aHatchStyle = drawinglayer::attribute::HatchStyle::Double;
108
0
                break;
109
0
            }
110
0
            default :
111
0
            {
112
0
                aHatchStyle = drawinglayer::attribute::HatchStyle::Triple; // css::drawing::HatchStyle_TRIPLE
113
0
                break;
114
0
            }
115
0
        }
116
117
0
        const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapPixel)));
118
0
        const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
119
0
        const double fScaleValue(aScaleVector.getLength());
120
121
0
        drawinglayer::attribute::FillHatchAttribute aFillHatch(
122
0
            aHatchStyle,
123
0
            static_cast<double>(rHatch.GetDistance()) * fScaleValue,
124
0
            toRadians(rHatch.GetAngle()),
125
0
            rHatch.GetColor().getBColor(),
126
0
            3, // same default as VCL, a minimum of three discrete units (pixels) offset
127
0
            false);
128
129
0
        const basegfx::BColor aBlack(0.0, 0.0, 0.0);
130
0
        const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive(
131
0
            new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
132
0
                basegfx::B2DPolyPolygon(aRectangle),
133
0
                aBlack,
134
0
                std::move(aFillHatch)));
135
136
0
        const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
137
0
            new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
138
0
                std::move(aRectangle),
139
0
                aBlack));
140
141
        // prepare VirtualDevice
142
0
        ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
143
0
        const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
144
145
0
        pVirtualDevice->SetOutputSizePixel(rSize);
146
0
        pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
147
0
            ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
148
0
            : DrawModeFlags::Default);
149
150
0
        if(rStyleSettings.GetPreviewUsesCheckeredBackground())
151
0
        {
152
0
            const Point aNull(0, 0);
153
0
            static const sal_uInt32 nLen(8);
154
0
            static const Color aW(COL_WHITE);
155
0
            static const Color aG(0xef, 0xef, 0xef);
156
0
            pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
157
0
        }
158
0
        else
159
0
        {
160
0
            pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
161
0
            pVirtualDevice->Erase();
162
0
        }
163
164
        // create processor and draw primitives
165
0
        std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
166
0
            *pVirtualDevice,
167
0
            aNewViewInformation2D));
168
169
0
        drawinglayer::primitive2d::Primitive2DContainer aSequence {
170
0
            aHatchPrimitive, aBlackRectanglePrimitive };
171
0
        pProcessor2D->process(aSequence);
172
0
        pProcessor2D.reset();
173
174
        // get result bitmap and scale
175
0
        aRetval = pVirtualDevice->GetBitmap(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
176
0
    }
177
178
0
    return aRetval;
179
0
}
180
181
Bitmap XHatchList::CreateBitmapForUI(tools::Long nIndex)
182
0
{
183
0
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
184
0
    const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
185
0
    Bitmap aRetVal = CreateBitmap(nIndex, rSize);
186
0
    return aRetVal;
187
0
}
188
189
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */