KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_text_eval_render.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
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
24
25#include <boost/test/unit_test.hpp>
26#include <gr_text.h>
27#include <font/font.h>
28#include <math/util.h>
29
30BOOST_AUTO_TEST_SUITE( TextEvalRender )
31
32BOOST_AUTO_TEST_CASE( GrTextWidthEval )
33{
35 VECTOR2I size( 100, 100 );
36 int thickness = 1;
38
39 int widthExpr = GRTextWidth( wxS( "@{1+1}" ), font, size, thickness, false, false, metrics );
40 int widthExpected = KiROUND( font->StringBoundaryLimits( wxS( "2" ), size, thickness, false,
41 false, metrics ).x );
42 int widthRaw = KiROUND( font->StringBoundaryLimits( wxS( "@{1+1}" ), size, thickness, false,
43 false, metrics ).x );
44
45 BOOST_CHECK_EQUAL( widthExpr, widthExpected );
46 BOOST_CHECK( widthExpr != widthRaw );
47}
48
50
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
FONT is an abstract base class for both outline and stroke fonts.
Definition font.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:143
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition font.cpp:447
static const METRICS & Default()
Definition font.cpp:48
int GRTextWidth(const wxString &aText, KIFONT::FONT *aFont, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS &aFontMetrics)
Definition gr_text.cpp:95
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683