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;
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;
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;
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" );
340 text.SetFont(
nullptr );
342 VECTOR2I offset =
text.GetOffsetToMatchSCH_FIELD(
nullptr );
365 text.SetFont( font );
366 text.SetMultilineAllowed(
true );
368 VECTOR2I offset =
text.GetOffsetToMatchSCH_FIELD(
nullptr );
373 "Outline font offset Y should be negative (upward shift), got: "
374 + std::to_string( offset.
y ) );
379 BOX2I shiftedBBox = rawBBox;
380 shiftedBBox.
Offset( offset );
383 "Shifted bounding box top should be above raw bounding box top" );
397 KIFONT::FONT* outlineFont = GetFirstExistingOutlineFont();
405 const wxString fontName = outlineFont->
GetName();
406 const wxString body = wxS(
"Line 1\nLine 2\nLine 3" );
412 reference.
SetFont( outlineFont );
430 "Bounding box after ResolveFont() must match the outline-font box; the "
431 "stale fallback-font box ("
432 + std::to_string( fallbackBox.
GetHeight() ) +
" tall) was not invalidated" );
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
constexpr coord_type GetTop() const
constexpr void Offset(coord_type dx, coord_type dy)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
void SetUnresolvedFontName(const wxString &aFontName)
bool ResolveFont(const std::vector< wxString > *aEmbeddedFonts)
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 SetMultilineAllowed(bool aAllow)
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.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
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_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
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).
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I