41 const std::vector<wxString> fontNames = {
47 wxS(
"Liberation Sans" ),
51 wxS(
"Helvetica Neue" )
54 for(
const wxString&
name : fontNames )
72 double aMaxWidthMultiplier = 1.3 )
75 BOOST_REQUIRE_MESSAGE( font, aTestName +
": Font should not be null" );
92 int expectedMaxWidth = extents.
x * aMaxWidthMultiplier;
101 BOOST_CHECK_MESSAGE( bbox.
GetWidth() <= expectedMaxWidth,
102 aTestName +
": Bounding box width (" + std::to_string( bbox.
GetWidth() )
103 +
") exceeds expected max (" + std::to_string( expectedMaxWidth )
104 +
"). Text may have been measured twice." );
107 int expectedMinWidth = extents.
x * 0.7;
108 BOOST_CHECK_MESSAGE( bbox.
GetWidth() >= expectedMinWidth,
109 aTestName +
": Bounding box width (" + std::to_string( bbox.
GetWidth() )
110 +
") is smaller than expected min (" + std::to_string( expectedMinWidth ) +
")" );
126 aTestName +
": Body bbox width (" + std::to_string( bodyBBox.
GetWidth() )
127 +
") should be >= text bbox width (" + std::to_string( textBBox.
GetWidth() ) +
")" );
131 int maxBodyWidth = textBBox.
GetWidth() * 3;
132 BOOST_CHECK_MESSAGE( bodyBBox.
GetWidth() <= maxBodyWidth,
133 aTestName +
": Body bbox width (" + std::to_string( bodyBBox.
GetWidth() )
134 +
") is excessively large compared to text bbox width ("
135 + std::to_string( textBBox.
GetWidth() ) +
")" );
152 text.SetFont(
nullptr );
154 CheckTextBoundingBoxWidth(
text,
"SCH_TEXT with stroke font" );
176 text.SetFont( font );
178 CheckTextBoundingBoxWidth(
text,
"SCH_TEXT with outline font (" + font->
GetName() +
")" );
187 std::vector<wxString> testStrings = {
191 wxS(
"Hello World" ),
198 for(
const wxString& str : testStrings )
202 text.SetFont(
nullptr );
204 CheckTextBoundingBoxWidth(
text,
"Stroke font: '" + str +
"'" );
212 for(
const wxString& str : testStrings )
216 text.SetFont( font );
218 CheckTextBoundingBoxWidth(
text,
"Outline font: '" + str +
"'" );
233 CheckTextBoundingBoxWidth( label,
"SCH_LABEL text with stroke font" );
234 CheckLabelBodyBoundingBox( label,
"SCH_LABEL body with stroke font" );
255 CheckTextBoundingBoxWidth( label,
"SCH_LABEL text with outline font" );
256 CheckLabelBodyBoundingBox( label,
"SCH_LABEL body with outline font" );
269 CheckTextBoundingBoxWidth( label,
"SCH_GLOBALLABEL text with stroke font" );
270 CheckLabelBodyBoundingBox( label,
"SCH_GLOBALLABEL body with stroke font" );
292 CheckTextBoundingBoxWidth( label,
"SCH_GLOBALLABEL text with outline font" );
293 CheckLabelBodyBoundingBox( label,
"SCH_GLOBALLABEL body with outline font" );
306 CheckTextBoundingBoxWidth( label,
"SCH_HIERLABEL text with stroke font" );
307 CheckLabelBodyBoundingBox( label,
"SCH_HIERLABEL body with stroke font" );
328 CheckTextBoundingBoxWidth( label,
"SCH_HIERLABEL text with outline font" );
329 CheckLabelBodyBoundingBox( label,
"SCH_HIERLABEL body with outline font" );
constexpr size_type GetWidth() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
void SetFont(KIFONT::FONT *aFont)
VECTOR2I GetTextSize() const
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
const wxString & GetName() const
virtual bool IsOutline() const
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).
virtual const BOX2I GetBodyBoundingBox(const RENDER_SETTINGS *aSettings) const
Return the bounding box of the label only, without taking in account its fields.
Test fixture for label bounding box tests.
KIFONT::FONT * GetFirstExistingOutlineFont()
void CheckLabelBodyBoundingBox(SCH_LABEL_BASE &aLabel, const wxString &aTestName)
Helper function to check label body bounding box.
void CheckTextBoundingBoxWidth(const EDA_TEXT &aText, const wxString &aTestName, double aMaxWidthMultiplier=1.3)
Helper function to check that a text bounding box is reasonable.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(TextBoundingBoxStrokeFont)
Test that SCH_TEXT bounding boxes are correct with the default KiCad font (stroke font).
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I