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 The 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
43{
48};
49
52{
57};
58
59
64{
65 // Could use the -1/1 promise of the enum too.
66 switch( aAlign )
67 {
74 break;
75 }
76 return aAlign;
77};
78
79
84{
85 switch( aAlign )
86 {
93 break;
94 }
95 return aAlign;
96};
97
98
107{
108 if( x < 0 )
109
111 else if( x > 0 )
113
115}
116
117
119{
120public:
121 TEXT_ATTRIBUTES( KIFONT::FONT* aFont = nullptr );
122
123 int Compare( const TEXT_ATTRIBUTES& aRhs ) const;
124
125 bool operator==( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) == 0; }
126 bool operator>( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) > 0; }
127 bool operator<( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) < 0; }
128
136 bool m_Bold;
143
144 // If true, keep rotation angle between -90...90 degrees for readability
147};
148
149
150extern GAL_API std::ostream& operator<<( std::ostream& aStream,
151 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:1311
#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
This is API surface mapped to common.types.HorizontalAlignment.
@ 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
This is API surface mapped to common.types.VertialAlignment.
@ 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.