Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/drawinglayer/primitive2d/borderlineprimitive2d.hxx
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
#pragma once
21
22
#include <drawinglayer/drawinglayerdllapi.h>
23
24
#include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx>
25
#include <drawinglayer/attribute/lineattribute.hxx>
26
#include <drawinglayer/attribute/strokeattribute.hxx>
27
28
namespace drawinglayer::primitive2d
29
{
30
/** BorderLine class
31
    Helper class holding the style definition for a single part of a full BorderLine definition.
32
    Line extends are for start/end and for Left/Right, seen in vector direction. If
33
    Left != Right that means the line has a diagonal start/end.
34
    Think about it similar to a trapezoid, but not aligned to X-Axis and using the
35
    perpendicular vector to the given one in a right-handed coordinate system.
36
*/
37
class DRAWINGLAYER_DLLPUBLIC BorderLine
38
{
39
private:
40
    // line attribute containing Width, Color and others
41
    drawinglayer::attribute::LineAttribute maLineAttribute;
42
43
    // line extends
44
    double mfStartLeft;
45
    double mfStartRight;
46
    double mfEndLeft;
47
    double mfEndRight;
48
49
    // if this is a gap, this is set to true
50
    bool mbIsGap;
51
52
public:
53
    // Constructor for visible BorderLine segments
54
    BorderLine(const drawinglayer::attribute::LineAttribute& rLineAttribute,
55
               double fStartLeft = 0.0, double fStartRight = 0.0, double fEndLeft = 0.0,
56
               double fEndRight = 0.0);
57
58
    // Constructor for gap BorderLine segments
59
    BorderLine(double fWidth);
60
61
    ~BorderLine();
62
63
9
    BorderLine(BorderLine const&) = default;
64
10.5k
    BorderLine(BorderLine&&) = default;
65
    BorderLine& operator=(BorderLine const&) = default;
66
    BorderLine& operator=(BorderLine&&) = default;
67
68
    const drawinglayer::attribute::LineAttribute& getLineAttribute() const
69
31.2k
    {
70
31.2k
        return maLineAttribute;
71
31.2k
    }
72
20.8k
    double getStartLeft() const { return mfStartLeft; }
73
10.5k
    double getStartRight() const { return mfStartRight; }
74
20.8k
    double getEndLeft() const { return mfEndLeft; }
75
10.5k
    double getEndRight() const { return mfEndRight; }
76
10.9k
    bool isGap() const { return mbIsGap; }
77
78
    /// compare operator
79
    bool operator==(const BorderLine& rBorderLine) const;
80
};
81
82
/** BorderLinePrimitive2D class
83
84
    This is the basic primitive to build frames around objects, e.g. tables.
85
    It defines a single or double line from Start to End using the LeftWidth,
86
    Distance and RightWidth definitions.
87
    The LineStart/End overlap is defined in the BorderLines definitions (see
88
    class BorderLine above).
89
*/
90
class DRAWINGLAYER_DLLPUBLIC BorderLinePrimitive2D final : public BufferedDecompositionPrimitive2D
91
{
92
private:
93
    /// the line definition
94
    basegfx::B2DPoint maStart;
95
    basegfx::B2DPoint maEnd;
96
97
    /// the single BorderLine style definition(s), one or three mostly used
98
    std::vector<BorderLine> maBorderLines;
99
100
    /// common style definitions
101
    const drawinglayer::attribute::StrokeAttribute maStrokeAttribute;
102
103
    /// create local decomposition
104
    virtual Primitive2DReference
105
    create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const override;
106
107
    /// helper to get the full width from maBorderLines
108
    double getFullWidth() const;
109
110
public:
111
    /// simplified constructor for BorderLine with single edge
112
    BorderLinePrimitive2D(const basegfx::B2DPoint& rStart, const basegfx::B2DPoint& rEnd,
113
                          std::vector<BorderLine>&& rBorderLines,
114
                          drawinglayer::attribute::StrokeAttribute aStrokeAttribute);
115
116
    /// data read access
117
73.4k
    const basegfx::B2DPoint& getStart() const { return maStart; }
118
73.4k
    const basegfx::B2DPoint& getEnd() const { return maEnd; }
119
11.2k
    const std::vector<BorderLine>& getBorderLines() const { return maBorderLines; }
120
    const drawinglayer::attribute::StrokeAttribute& getStrokeAttribute() const
121
22.6k
    {
122
22.6k
        return maStrokeAttribute;
123
22.6k
    }
124
125
    /// helper to decide if AntiAliasing should be used
126
    bool isHorizontalOrVertical(const geometry::ViewInformation2D& rViewInformation) const;
127
128
    /// compare operator
129
    virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
130
131
    /// provide unique ID
132
    virtual sal_uInt32 getPrimitive2DID() const override;
133
};
134
135
/// helper to try to merge two instances of BorderLinePrimitive2D. If it was possible,
136
/// a merged version is in the returned Primitive2DReference. Lots of preconditions
137
/// have to be met to allow that, see implementation (and maybe even expand)
138
Primitive2DReference DRAWINGLAYER_DLLPUBLIC tryMergeBorderLinePrimitive2D(
139
    const BorderLinePrimitive2D* pCandidateA, const BorderLinePrimitive2D* pCandidateB);
140
141
} // end of namespace drawinglayer::primitive2d
142
143
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */