KiCad PCB EDA Suite
Loading...
Searching...
No Matches
text_attributes.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Ola Rinta-Koski
5 * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef TEXT_ATTRIBUTES_H
22#define TEXT_ATTRIBUTES_H
23
24#include <math/vector2d.h>
25#include <gal/color4d.h>
26#include <geometry/eda_angle.h>
27#include <gal/gal.h>
28
29
30namespace KIFONT
31{
32class FONT;
33};
34
35
36// Graphic Text alignments:
37//
38// NB: values -1,0,1 are used in computations, do not change them
39//
40
41// This is API surface mapped to common.types.HorizontalAlignment
43{
48};
49
50// This is API surface mapped to common.types.VertialAlignment
52{
57};
58
59
65{
66 // Could use the -1/1 promise of the enum too.
67 switch( aAlign )
68 {
75 break;
76 }
77 return aAlign;
78};
79
80
86{
87 switch( aAlign )
88 {
95 break;
96 }
97 return aAlign;
98};
99
100
109{
110 if( x < 0 )
111
113 else if( x > 0 )
115
117}
118
119
121{
122public:
123 TEXT_ATTRIBUTES( KIFONT::FONT* aFont = nullptr );
124
125 int Compare( const TEXT_ATTRIBUTES& aRhs ) const;
126
127 bool operator==( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) == 0; }
128 bool operator>( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) > 0; }
129 bool operator<( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) < 0; }
130
138 bool m_Bold;
145
146 // If true, keep rotation angle between -90...90 degrees for readability
148};
149
150
151extern GAL_API std::ostream& operator<<( std::ostream& aStream, const TEXT_ATTRIBUTES& aAttributes );
152
153
154template<>
155struct std::hash<TEXT_ATTRIBUTES>
156{
157 std::size_t operator()( const TEXT_ATTRIBUTES& aAttributes ) const
158 {
159 return hash_val( aAttributes.m_Font, aAttributes.m_Halign, aAttributes.m_Valign,
160 aAttributes.m_Angle.AsDegrees(), aAttributes.m_LineSpacing,
161 aAttributes.m_StrokeWidth, aAttributes.m_Italic, aAttributes.m_Bold,
162 aAttributes.m_Underlined, aAttributes.m_Color, aAttributes.m_Visible,
163 aAttributes.m_Mirrored, aAttributes.m_Multiline, aAttributes.m_Size.x,
164 aAttributes.m_Size.y );
165 }
166};
167
168#endif //TEXT_ATTRIBUTES_H
double AsDegrees() const
Definition: eda_angle.h:113
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
KIGFX::COLOR4D m_Color
bool operator==(const TEXT_ATTRIBUTES &aRhs) const
GR_TEXT_H_ALIGN_T m_Halign
bool operator<(const TEXT_ATTRIBUTES &aRhs) const
bool operator>(const TEXT_ATTRIBUTES &aRhs) const
GR_TEXT_V_ALIGN_T m_Valign
KIFONT::FONT * m_Font
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1195
#define GAL_API
Definition: gal.h:28
static constexpr std::size_t hash_val(const Types &... args)
Definition: hash.h:51
std::size_t operator()(const TEXT_ATTRIBUTES &aAttributes) const
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
constexpr GR_TEXT_H_ALIGN_T ToHAlignment(int x)
Convert an integral value to horizontal alignment.