From 5aba9b539f3d043c3831c7d679cdf7011e20f2f5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 24 Feb 2023 16:24:02 -0800 Subject: [PATCH] Revert font spacing/tabs to the v6 model While convoluted, this model matches as best we have found so far, the alignment with scintilla. The spacing is character size for N-1 of the characters in the 4-space tab stops. The final character is sized for the actual space character in the stroke font (0.761905) Fixes https://gitlab.com/kicad/code/kicad/issues/13791 (cherry picked from commit bce402a01c9e4b475ba52cd2ef1192d3ff01f5f1) --- common/font/stroke_font.cpp | 27 ++++-- qa/unittests/common/CMakeLists.txt | 1 + .../common/test_kicad_stroke_font.cpp | 82 +++++++++++++++++++ 3 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 qa/unittests/common/test_kicad_stroke_font.cpp diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index 83e2636ba6..ec5f583dc4 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -226,11 +226,8 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vectorfront().GetWidth(); // First char is space + int char_count = 0; if( aTextStyle & TEXT_STYLE::SUBSCRIPT || aTextStyle & TEXT_STYLE::SUPERSCRIPT ) { @@ -251,18 +250,26 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector + +// Code under test +#include +#include + +/** + * Declare the test suite + */ +BOOST_AUTO_TEST_SUITE( KicadStrokeFont ) + + +/** + * Test the tab spacing. + */ +BOOST_AUTO_TEST_CASE( TabCheck ) +{ + using CASE = std::pair; + + KIFONT::STROKE_FONT* font = KIFONT::STROKE_FONT::LoadFont( wxEmptyString ); + + const std::vector cases = { + { "v34_STM23G491\t\tController STM32\t(column 3)", + "v34_LPC1758\t\t\tController NXP\t\t(column 3)" }, + { "1\td9c1892a\t\t\tMOLEX\t\t\t1053071202\t\t\t\t\t12\t\tCONNECTOR", + "REF\tPART NUMBER\t\t\tMANUFACTURER\tMANUFACTURER PART NUMBER\tQTY\t\tCONNECTOR" }, + { "5\tC-000208\t\t\tMCMASTER/CARR\t8054T13 BLUE\t\t\t\t3960MM\tCONNECTOR", + "REF\tPART NUMBER\t\t\tMANUFACTURER\tMANUFACTURER PART NUMBER\tQTY\t\tCONNECTOR" }, + { "0\t\t\t\tlinvA\t\t\tL", + "3\t\t\t\tlloadA\t\t\tL" }, + { "6\t\t\t\tVpccA\t\t\tL", + "14\t\t\t\t--\t\t\t\tL" }, + }; + + for( const auto& c : cases ) + { + std::vector> glyphs; + BOX2I bbox; + wxString text1 = wxString::Format( c.first ); + wxString text2 = wxString::Format( c.second ); + + VECTOR2I output1 = font->GetTextAsGlyphs( &bbox, &glyphs, text1, + VECTOR2I( 1000, 1000 ), VECTOR2I( 0, 0 ), EDA_ANGLE::m_Angle0, false, + VECTOR2I( 0, 0 ), 0 ); + VECTOR2I output2 = font->GetTextAsGlyphs( &bbox, &glyphs, text2, + VECTOR2I( 1000, 1000 ), VECTOR2I( 0, 0 ), EDA_ANGLE::m_Angle0, false, + VECTOR2I( 0, 0 ), 0 ); + + BOOST_CHECK_MESSAGE( output1.x == output2.x, "Incorrect tab size for \n\t'" << text1.ToStdString() << "' and\n\t'" << text2.ToStdString() << "'" ); + } +} + + +BOOST_AUTO_TEST_SUITE_END()