Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/font/EmphasisMark.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10
#include <sal/config.h>
11
12
#include <font/EmphasisMark.hxx>
13
14
namespace vcl::font
15
{
16
EmphasisMark::EmphasisMark(FontEmphasisMark eEmphasis, tools::Long nHeight, sal_Int32 nDPIY)
17
2.52k
{
18
2.52k
    static const PolyFlags aAccentPolyFlags[24] =
19
2.52k
    {
20
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
21
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
22
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
23
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
24
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
25
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
26
2.52k
        PolyFlags::Normal, PolyFlags::Normal,  PolyFlags::Control,
27
2.52k
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control
28
2.52k
    };
29
30
2.52k
    static const Point aAccentPos[24] =
31
2.52k
    {
32
2.52k
        {  78,    0 },
33
2.52k
        { 348,   79 },
34
2.52k
        { 599,  235 },
35
2.52k
        { 843,  469 },
36
2.52k
        { 938,  574 },
37
2.52k
        { 990,  669 },
38
2.52k
        { 990,  773 },
39
2.52k
        { 990,  843 },
40
2.52k
        { 964,  895 },
41
2.52k
        { 921,  947 },
42
2.52k
        { 886,  982 },
43
2.52k
        { 860,  999 },
44
2.52k
        { 825,  999 },
45
2.52k
        { 764,  999 },
46
2.52k
        { 721,  964 },
47
2.52k
        { 686,  895 },
48
2.52k
        { 625,  791 },
49
2.52k
        { 556,  660 },
50
2.52k
        { 469,  504 },
51
2.52k
        { 400,  400 },
52
2.52k
        { 261,  252 },
53
2.52k
        {  61,   61 },
54
2.52k
        {   0,   27 },
55
2.52k
        {   9,    0 }
56
2.52k
    };
57
58
2.52k
    mnWidth      = 0;
59
2.52k
    mnYOff       = 0;
60
2.52k
    mbIsPolyLine   = false;
61
62
2.52k
    if ( !nHeight )
63
0
        return;
64
65
2.52k
    FontEmphasisMark    nEmphasisStyle = eEmphasis & FontEmphasisMark::Style;
66
2.52k
    tools::Long                nDotSize = 0;
67
2.52k
    switch ( nEmphasisStyle )
68
2.52k
    {
69
33
        case FontEmphasisMark::Dot:
70
            // Dot has 55% of the height
71
33
            nDotSize = (nHeight*550)/1000;
72
33
            if ( !nDotSize )
73
2
                nDotSize = 1;
74
33
            if ( nDotSize <= 2 )
75
15
                maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
76
18
            else
77
18
            {
78
18
                tools::Long nRad = nDotSize/2;
79
18
                tools::Polygon aPoly( Point( nRad, nRad ), nRad, nRad );
80
18
                maPolyPoly.Insert( aPoly );
81
18
            }
82
33
            mnYOff = ((nHeight*250)/1000)/2; // Center to the another EmphasisMarks
83
33
            mnWidth = nDotSize;
84
33
            break;
85
86
103
        case FontEmphasisMark::Circle:
87
            // Dot has 80% of the height
88
103
            nDotSize = (nHeight*800)/1000;
89
103
            if ( !nDotSize )
90
25
                nDotSize = 1;
91
103
            if ( nDotSize <= 2 )
92
25
                maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
93
78
            else
94
78
            {
95
78
                tools::Long nRad = nDotSize/2;
96
78
                tools::Polygon aPoly( Point( nRad, nRad ), nRad, nRad );
97
78
                maPolyPoly.Insert( aPoly );
98
                // Border mnWidth is 15%
99
78
                tools::Long nBorder = (nDotSize*150)/1000;
100
78
                if ( nBorder <= 1 )
101
39
                    mbIsPolyLine = true;
102
39
                else
103
39
                {
104
39
                    tools::Polygon aPoly2( Point( nRad, nRad ),
105
39
                                           nRad-nBorder, nRad-nBorder );
106
39
                    maPolyPoly.Insert( aPoly2 );
107
39
                }
108
78
            }
109
103
            mnWidth = nDotSize;
110
103
            break;
111
112
0
        case FontEmphasisMark::Disc:
113
            // Dot has 80% of the height
114
0
            nDotSize = (nHeight*800)/1000;
115
0
            if ( !nDotSize )
116
0
                nDotSize = 1;
117
0
            if ( nDotSize <= 2 )
118
0
                maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
119
0
            else
120
0
            {
121
0
                tools::Long nRad = nDotSize/2;
122
0
                tools::Polygon aPoly( Point( nRad, nRad ), nRad, nRad );
123
0
                maPolyPoly.Insert( aPoly );
124
0
            }
125
0
            mnWidth = nDotSize;
126
0
            break;
127
128
34
        case FontEmphasisMark::Accent:
129
            // Dot has 80% of the height
130
34
            nDotSize = (nHeight*800)/1000;
131
34
            if ( !nDotSize )
132
20
                nDotSize = 1;
133
34
            if ( nDotSize <= 2 )
134
20
            {
135
20
                if ( nDotSize == 1 )
136
20
                {
137
20
                    maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
138
20
                    mnWidth = nDotSize;
139
20
                }
140
0
                else
141
0
                {
142
0
                    maRect1 = tools::Rectangle( Point(), Size( 1, 1 ) );
143
0
                    maRect2 = tools::Rectangle( Point( 1, 1 ), Size( 1, 1 ) );
144
0
                }
145
20
            }
146
14
            else
147
14
            {
148
14
                tools::Polygon aPoly( SAL_N_ELEMENTS(aAccentPos), aAccentPos,
149
14
                                      aAccentPolyFlags );
150
14
                double dScale = static_cast<double>(nDotSize)/1000.0;
151
14
                aPoly.Scale( dScale, dScale );
152
14
                tools::Polygon aTemp;
153
14
                aPoly.AdaptiveSubdivide( aTemp );
154
14
                tools::Rectangle aBoundRect = aTemp.GetBoundRect();
155
14
                mnWidth = aBoundRect.GetWidth();
156
14
                nDotSize = aBoundRect.GetHeight();
157
14
                maPolyPoly.Insert( aTemp );
158
14
            }
159
34
            break;
160
2.35k
        default: break;
161
2.52k
    }
162
163
    // calculate position
164
2.52k
    tools::Long nOffY = 1+(nDPIY/300); // one visible pixel space
165
2.52k
    tools::Long nSpaceY = nHeight-nDotSize;
166
2.52k
    if ( nSpaceY >= nOffY*2 )
167
2.35k
        mnYOff += nOffY;
168
169
2.52k
    if ( !(eEmphasis & FontEmphasisMark::PosBelow) )
170
134
        mnYOff += nDotSize;
171
2.52k
}
172
}
173
174
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */