KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easypc_text_metrics.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
30
31#ifndef EASYPC_TEXT_METRICS_H
32#define EASYPC_TEXT_METRICS_H
33
34#include <cstdint>
35#include <string>
36
37#include <math/box2.h>
38#include <math/vector2d.h>
39#include <wx/string.h>
40
41
42namespace EASYPC
43{
44
45struct SOURCE_DESIGN;
47
48
50enum TEXT_H_ALIGN : int32_t
51{
55};
56
57
59enum TEXT_V_ALIGN : int32_t
60{
64};
65
66
68{
69public:
70 explicit TEXT_METRICS( const SOURCE_TEXT_STYLE& aStyle );
71
73 bool CanMeasure() const { return !m_typeFont; }
74
75 int32_t Height() const { return m_height; }
76
78 int32_t RunWidth( const std::string& aText, size_t aBegin, size_t aEnd ) const;
79
84 BOX2I TextBox( const wxString& aText, const VECTOR2I& aAnchor, int32_t aAngle, bool aMirrored, int aHAlign,
85 int aVAlign = TEXT_V_BASELINE ) const;
86
91 VECTOR2I UprightAnchor( const wxString& aText, const VECTOR2I& aAnchor, int32_t aAngle, bool aMirrored, int aHAlign,
92 bool aKeepUpright ) const;
93
95 static std::string Encode( const wxString& aText );
96
97private:
98 void checkMeasurable() const;
99 int32_t linePitch() const;
100 int32_t charWidth( char aChar ) const;
101
102 int32_t m_height = 0;
103 int32_t m_penWidth = 0;
104 int32_t m_interlinePercent = 120;
105 int32_t m_charWidthPercent = 100;
106 bool m_proportional = false;
107 bool m_typeFont = false;
108};
109
110
115bool TextStaysUpright( const SOURCE_DESIGN& aDesign, bool aSchematic );
116
117
119int32_t UprightRotation( int32_t aAngle, bool aKeepUpright );
120
121
126wxString ToKiCadMarkup( const wxString& aText );
127
128} // namespace EASYPC
129
130#endif // EASYPC_TEXT_METRICS_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
bool CanMeasure() const
False for a TrueType style; the measuring calls throw IO_ERROR for one.
int32_t RunWidth(const std::string &aText, size_t aBegin, size_t aEnd) const
Width of bytes [aBegin, aEnd); a run that measures 0 is one height wide.
static std::string Encode(const wxString &aText)
The CP1252 bytes of aText; characters CP1252 lacks become 0.
int32_t charWidth(char aChar) const
TEXT_METRICS(const SOURCE_TEXT_STYLE &aStyle)
BOX2I TextBox(const wxString &aText, const VECTOR2I &aAnchor, int32_t aAngle, bool aMirrored, int aHAlign, int aVAlign=TEXT_V_BASELINE) const
Every line's cell, inflated by half the pen width, mirrored about the anchor and bounded after rotati...
VECTOR2I UprightAnchor(const wxString &aText, const VECTOR2I &aAnchor, int32_t aAngle, bool aMirrored, int aHAlign, bool aKeepUpright) const
When aKeepUpright and UprightRotation turns the text, the anchor moves to the far end of the first li...
bool TextStaysUpright(const SOURCE_DESIGN &aDesign, bool aSchematic)
Whether aDesign's text is drawn upright: the design's flag, which old schematics imply,...
int32_t UprightRotation(int32_t aAngle, bool aKeepUpright)
With text kept upright, an angle above 135 and up to 305 degrees turns by 180.
TEXT_V_ALIGN
Source text positions always pass BASELINE.
wxString ToKiCadMarkup(const wxString &aText)
A displayed string in KiCad's markup.
TEXT_H_ALIGN
The source text position's alignment value.
The document: OLE items, then the design.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708