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
60#define TO_HJUSTIFY( x ) static_cast<GR_TEXT_H_ALIGN_T>( x )
61#define TO_VJUSTIFY( x ) static_cast<GR_TEXT_V_ALIGN_T>( x )
62
63
65{
66public:
67 TEXT_ATTRIBUTES( KIFONT::FONT* aFont = nullptr );
68
69 int Compare( const TEXT_ATTRIBUTES& aRhs ) const;
70
71 bool operator==( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) == 0; }
72 bool operator>( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) > 0; }
73 bool operator<( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) < 0; }
74
82 bool m_Bold;
89
90 // If true, keep rotation angle between -90...90 degrees for readability
92};
93
94
95extern GAL_API std::ostream& operator<<( std::ostream& aStream, const TEXT_ATTRIBUTES& aAttributes );
96
97
98template<>
99struct std::hash<TEXT_ATTRIBUTES>
100{
101 std::size_t operator()( const TEXT_ATTRIBUTES& aAttributes ) const
102 {
103 return hash_val( aAttributes.m_Font, aAttributes.m_Halign, aAttributes.m_Valign,
104 aAttributes.m_Angle.AsDegrees(), aAttributes.m_LineSpacing,
105 aAttributes.m_StrokeWidth, aAttributes.m_Italic, aAttributes.m_Bold,
106 aAttributes.m_Underlined, aAttributes.m_Color, aAttributes.m_Visible,
107 aAttributes.m_Mirrored, aAttributes.m_Multiline, aAttributes.m_Size.x,
108 aAttributes.m_Size.y );
109 }
110};
111
112#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
#define GAL_API
Definition: gal.h:28
static 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
GAL_API std::ostream & operator<<(std::ostream &aStream, const TEXT_ATTRIBUTES &aAttributes)
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