KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_target3001_fonts.cpp
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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
21
22#include <algorithm>
23#include <cmath>
24#include <limits>
25#include <memory>
26#include <vector>
27
28#include <base_units.h>
29#include <eda_text.h>
30#include <font/font.h>
31#include <font/glyph_types.h>
34
35
37static double lastCentreFromStem( const wxString& aText, const VECTOR2I& aSize )
38{
39 auto strokes = [&]( const wxString& aStr )
40 {
41 std::vector<std::unique_ptr<KIFONT::GLYPH>> glyphs;
42
43 KIFONT::FONT::GetFont()->GetTextAsGlyphs( nullptr, &glyphs, aStr, aSize, VECTOR2I( 0, 0 ), ANGLE_0, false,
44 VECTOR2I( 0, 0 ), 0 );
45
46 return glyphs;
47 };
48
49 auto span = [&]( const KIFONT::GLYPH& aGlyph )
50 {
51 std::pair<double, double> result( std::numeric_limits<double>::max(), std::numeric_limits<double>::lowest() );
52
53 for( const std::vector<VECTOR2D>& stroke : static_cast<const KIFONT::STROKE_GLYPH&>( aGlyph ) )
54 {
55 for( const VECTOR2D& pt : stroke )
56 {
57 result.first = std::min( result.first, pt.x );
58 result.second = std::max( result.second, pt.x );
59 }
60 }
61
62 return result;
63 };
64
65 std::pair<double, double> last = span( *strokes( aText ).back() );
66
67 return ( last.first + last.second ) / 2.0 - span( *strokes( wxS( "H" ) ).front() ).first;
68}
69
70
71BOOST_AUTO_TEST_SUITE( Target3001Fonts )
72
73
74BOOST_AUTO_TEST_CASE( DinGlyphsFollowVendorAdvance )
75{
76 // Note in vorverst_vdc_v4.6.1_FET,Differenzverstaerker; the vendor PDF centres its last glyph 57.64 mm from the pen
78 elem.text.font = "DIN-ISO-ANSI";
79 elem.text.height = 3000000;
80 elem.text.width = 1500000;
81 elem.text.weight = 13;
82
83 EDA_TEXT text( pcbIUScale, wxS( "X5: 200: 1,51V; 201: +1,62V; 202: 1,65V; " ) );
85
86 fonts.Apply( &text, elem, 1 );
87
88 double centre = lastCentreFromStem( text.GetText(), text.GetTextSize() );
89
90 BOOST_CHECK_LT( std::abs( centre - pcbIUScale.mmToIU( 57.64 ) ), pcbIUScale.mmToIU( 1.0 ) );
91}
92
93
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:144
virtual VECTOR2I GetTextAsGlyphs(BOX2I *aBBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aSize, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, TEXT_STYLE_FLAGS aTextStyle) const =0
Convert text string to an array of GLYPHs.
Maps TARGET 3001!
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:448
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:437
One element of any class.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static double lastCentreFromStem(const wxString &aText, const VECTOR2I &aSize)
Centre of the last glyph of aText at aSize, measured from the stem of H.
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707