Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/xoutdev/xtabptrn.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
22
#include <vcl/virdev.hxx>
23
#include <svx/strings.hrc>
24
#include <svx/dialmgr.hxx>
25
#include <svx/xtable.hxx>
26
#include <rtl/ustrbuf.hxx>
27
#include <vcl/settings.hxx>
28
#include <vcl/svapp.hxx>
29
#include <vcl/BitmapTools.hxx>
30
31
using namespace com::sun::star;
32
33
XBitmapEntry* XPatternList::GetBitmap(tools::Long nIndex) const
34
0
{
35
0
    return static_cast<XBitmapEntry*>( XPropertyList::Get(nIndex) );
36
0
}
37
38
uno::Reference< container::XNameContainer > XPatternList::createInstance()
39
0
{
40
0
    return SvxUnoXBitmapTable_createInstance( *this );
41
0
}
42
43
bool XPatternList::Create()
44
517
{
45
517
    OUStringBuffer aStr(SvxResId(RID_SVXSTR_PATTERN));
46
517
    std::array<sal_uInt8,64> aArray;
47
517
    Bitmap aBitmap;
48
517
    const sal_Int32 nLen(aStr.getLength() - 1);
49
50
517
    aArray.fill(0);
51
52
    // white/white bitmap
53
517
    aStr.append(" 1");
54
517
    aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_WHITE, COL_WHITE);
55
517
    Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
56
57
    // black/white bitmap
58
517
    aArray[ 0] = 1; aArray[ 9] = 1; aArray[18] = 1; aArray[27] = 1;
59
517
    aArray[36] = 1; aArray[45] = 1; aArray[54] = 1; aArray[63] = 1;
60
517
    aStr[nLen] = '2';
61
517
    aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_BLACK, COL_WHITE);
62
517
    Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
63
64
    // lightred/white bitmap
65
517
    aArray[ 7] = 1; aArray[14] = 1; aArray[21] = 1; aArray[28] = 1;
66
517
    aArray[35] = 1; aArray[42] = 1; aArray[49] = 1; aArray[56] = 1;
67
517
    aStr[nLen] = '3';
68
517
    aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_LIGHTRED, COL_WHITE);
69
517
    Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
70
71
    // lightblue/white bitmap
72
517
    aArray[24] = 1; aArray[25] = 1; aArray[26] = 1;
73
517
    aArray[29] = 1; aArray[30] = 1; aArray[31] = 1;
74
517
    aStr[nLen] = '4';
75
517
    aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_LIGHTBLUE, COL_WHITE);
76
517
    Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
77
78
517
    return true;
79
517
}
80
81
Bitmap XPatternList::CreateBitmap( tools::Long nIndex, const Size& rSize ) const
82
0
{
83
0
    assert( nIndex < Count() );
84
85
0
    if(nIndex < Count())
86
0
    {
87
0
        Bitmap rBitmap(GetBitmap( nIndex )->GetGraphicObject().GetGraphic().GetBitmap());
88
0
        ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
89
0
        pVirtualDevice->SetOutputSizePixel(rSize);
90
91
0
        if(rBitmap.HasAlpha())
92
0
        {
93
0
            const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
94
95
0
            if(rStyleSettings.GetPreviewUsesCheckeredBackground())
96
0
            {
97
0
                const Point aNull(0, 0);
98
0
                static const sal_uInt32 nLen(8);
99
0
                static const Color aW(COL_WHITE);
100
0
                static const Color aG(0xef, 0xef, 0xef);
101
102
0
                pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
103
0
            }
104
0
            else
105
0
            {
106
0
                pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
107
0
                pVirtualDevice->Erase();
108
0
            }
109
0
        }
110
111
0
        if(rBitmap.GetSizePixel().Width() >= rSize.Width() && rBitmap.GetSizePixel().Height() >= rSize.Height())
112
0
        {
113
0
            rBitmap.Scale(rSize);
114
0
            pVirtualDevice->DrawBitmap(Point(0, 0), rBitmap);
115
0
        }
116
0
        else
117
0
        {
118
0
            const Size aBitmapSize(rBitmap.GetSizePixel());
119
120
0
            for(tools::Long y(0); y < rSize.Height(); y += aBitmapSize.Height())
121
0
            {
122
0
                for(tools::Long x(0); x < rSize.Width(); x += aBitmapSize.Width())
123
0
                {
124
0
                    pVirtualDevice->DrawBitmap(
125
0
                        Point(x, y),
126
0
                        rBitmap);
127
0
                }
128
0
            }
129
0
        }
130
0
        rBitmap = pVirtualDevice->GetBitmap(Point(0, 0), rSize);
131
0
        return rBitmap;
132
0
    }
133
0
    else
134
0
        return Bitmap();
135
0
}
136
137
Bitmap XPatternList::CreateBitmapForUI( tools::Long nIndex )
138
0
{
139
0
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
140
0
    const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
141
0
    return CreateBitmap(nIndex, rSize);
142
0
}
143
144
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */