summaryrefslogtreecommitdiffstats
path: root/vcl/source/font/EmphasisMark.cxx
blob: be1a20223e91022d5a53d7a72b593dbc92a01c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <sal/config.h>

#include <font/EmphasisMark.hxx>

namespace vcl::font
{
EmphasisMark::EmphasisMark(FontEmphasisMark eEmphasis, tools::Long nHeight, sal_Int32 nDPIY)
{
    static const PolyFlags aAccentPolyFlags[24] =
    {
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Normal,  PolyFlags::Control,
        PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control
    };

    static const Point aAccentPos[24] =
    {
        {  78,    0 },
        { 348,   79 },
        { 599,  235 },
        { 843,  469 },
        { 938,  574 },
        { 990,  669 },
        { 990,  773 },
        { 990,  843 },
        { 964,  895 },
        { 921,  947 },
        { 886,  982 },
        { 860,  999 },
        { 825,  999 },
        { 764,  999 },
        { 721,  964 },
        { 686,  895 },
        { 625,  791 },
        { 556,  660 },
        { 469,  504 },
        { 400,  400 },
        { 261,  252 },
        {  61,   61 },
        {   0,   27 },
        {   9,    0 }
    };

    mnWidth      = 0;
    mnYOff       = 0;
    mbIsPolyLine   = false;

    if ( !nHeight )
        return;

    FontEmphasisMark    nEmphasisStyle = eEmphasis & FontEmphasisMark::Style;
    tools::Long                nDotSize = 0;
    switch ( nEmphasisStyle )
    {
        case FontEmphasisMark::Dot:
            // Dot has 55% of the height
            nDotSize = (nHeight*550)/1000;
            if ( !nDotSize )
                nDotSize = 1;
            if ( nDotSize <= 2 )
                maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
            else
            {
                tools::Long nRad = nDotSize/2;
                tools::Polygon aPoly( Point( nRad, nRad ), nRad, nRad );
                maPolyPoly.Insert( aPoly );
            }
            mnYOff = ((nHeight*250)/1000)/2; // Center to the another EmphasisMarks
            mnWidth = nDotSize;
            break;

        case FontEmphasisMark::Circle:
            // Dot has 80% of the height
            nDotSize = (nHeight*800)/1000;
            if ( !nDotSize )
                nDotSize = 1;
            if ( nDotSize <= 2 )
                maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
            else
            {
                tools::Long nRad = nDotSize/2;
                tools::Polygon aPoly( Point( nRad, nRad ), nRad, nRad );
                maPolyPoly.Insert( aPoly );
                // Border mnWidth is 15%
                tools::Long nBorder = (nDotSize*150)/1000;
                if ( nBorder <= 1 )
                    mbIsPolyLine = true;
                else
                {
                    tools::Polygon aPoly2( Point( nRad, nRad ),
                                           nRad-nBorder, nRad-nBorder );
                    maPolyPoly.Insert( aPoly2 );
                }
            }
            mnWidth = nDotSize;
            break;

        case FontEmphasisMark::Disc:
            // Dot has 80% of the height
            nDotSize = (nHeight*800)/1000;
            if ( !nDotSize )
                nDotSize = 1;
            if ( nDotSize <= 2 )
                maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
            else
            {
                tools::Long nRad = nDotSize/2;
                tools::Polygon aPoly( Point( nRad, nRad ), nRad, nRad );
                maPolyPoly.Insert( aPoly );
            }
            mnWidth = nDotSize;
            break;

        case FontEmphasisMark::Accent:
            // Dot has 80% of the height
            nDotSize = (nHeight*800)/1000;
            if ( !nDotSize )
                nDotSize = 1;
            if ( nDotSize <= 2 )
            {
                if ( nDotSize == 1 )
                {
                    maRect1 = tools::Rectangle( Point(), Size( nDotSize, nDotSize ) );
                    mnWidth = nDotSize;
                }
                else
                {
                    maRect1 = tools::Rectangle( Point(), Size( 1, 1 ) );
                    maRect2 = tools::Rectangle( Point( 1, 1 ), Size( 1, 1 ) );
                }
            }
            else
            {
                tools::Polygon aPoly( SAL_N_ELEMENTS(aAccentPos), aAccentPos,
                                      aAccentPolyFlags );
                double dScale = static_cast<double>(nDotSize)/1000.0;
                aPoly.Scale( dScale, dScale );
                tools::Polygon aTemp;
                aPoly.AdaptiveSubdivide( aTemp );
                tools::Rectangle aBoundRect = aTemp.GetBoundRect();
                mnWidth = aBoundRect.GetWidth();
                nDotSize = aBoundRect.GetHeight();
                maPolyPoly.Insert( aTemp );
            }
            break;
        default: break;
    }

    // calculate position
    tools::Long nOffY = 1+(nDPIY/300); // one visible pixel space
    tools::Long nSpaceY = nHeight-nDotSize;
    if ( nSpaceY >= nOffY*2 )
        mnYOff += nOffY;

    if ( !(eEmphasis & FontEmphasisMark::PosBelow) )
        mnYOff += nDotSize;
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */