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
42{
46};
47
49{
53};
54
55
56#define TO_HJUSTIFY( x ) static_cast<GR_TEXT_H_ALIGN_T>( x )
57#define TO_VJUSTIFY( x ) static_cast<GR_TEXT_V_ALIGN_T>( x )
58
59
61{
62public:
63 TEXT_ATTRIBUTES( KIFONT::FONT* aFont = nullptr );
64
65 int Compare( const TEXT_ATTRIBUTES& aRhs ) const;
66
67 bool operator==( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) == 0; }
68 bool operator>( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) > 0; }
69 bool operator<( const TEXT_ATTRIBUTES& aRhs ) const { return Compare( aRhs ) < 0; }
70
78 bool m_Bold;
85
86 // If true, keep rotation angle between -90...90 degrees for readability
88};
89
90
91extern GAL_API std::ostream& operator<<( std::ostream& aStream, const TEXT_ATTRIBUTES& aAttributes );
92
93
94template<>
95struct std::hash<TEXT_ATTRIBUTES>
96{
97 std::size_t operator()( const TEXT_ATTRIBUTES& aAttributes ) const
98 {
99 return hash_val( aAttributes.m_Font, aAttributes.m_Halign, aAttributes.m_Valign,
100 aAttributes.m_Angle.AsDegrees(), aAttributes.m_LineSpacing,
101 aAttributes.m_StrokeWidth, aAttributes.m_Italic, aAttributes.m_Bold,
102 aAttributes.m_Underlined, aAttributes.m_Color, aAttributes.m_Visible,
103 aAttributes.m_Mirrored, aAttributes.m_Multiline, aAttributes.m_Size.x,
104 aAttributes.m_Size.y );
105 }
106};
107
108#endif //TEXT_ATTRIBUTES_H
double AsDegrees() const
Definition: eda_angle.h:149
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
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_CENTER
@ GR_TEXT_V_ALIGN_TOP