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
This commit is contained in:
parent
9dca70a773
commit
bce402a01c
|
@ -226,11 +226,8 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr
|
|||
bool aMirror, const VECTOR2I& aOrigin,
|
||||
TEXT_STYLE_FLAGS aTextStyle ) const
|
||||
{
|
||||
constexpr double SPACE_WIDTH = 0.6;
|
||||
constexpr int TAB_WIDTH = 4;
|
||||
constexpr double INTER_CHAR = 0.2;
|
||||
constexpr double TAB_WIDTH = 4 * 0.82; // Not quite as wide as 5.1/6.0 tab formatting, but
|
||||
// a better match for Scintilla, and closer to the
|
||||
// nominal SPACE_WIDTH + INTER_CHAR
|
||||
constexpr double SUPER_SUB_SIZE_MULTIPLIER = 0.7;
|
||||
constexpr double SUPER_HEIGHT_OFFSET = 0.5;
|
||||
constexpr double SUB_HEIGHT_OFFSET = 0.3;
|
||||
|
@ -238,6 +235,8 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr
|
|||
VECTOR2I cursor( aPosition );
|
||||
VECTOR2D glyphSize( aSize );
|
||||
double tilt = ( aTextStyle & TEXT_STYLE::ITALIC ) ? ITALIC_TILT : 0.0;
|
||||
double space_width = m_glyphBoundingBoxes->front().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<std::unique_ptr
|
|||
|
||||
for( wxUniChar c : aText )
|
||||
{
|
||||
// Handle tabs as locked to the nearest 4th column (in space-widths).
|
||||
// Handle tabs as locked to the next 4th column (in base-widths).
|
||||
if( c == '\t' )
|
||||
{
|
||||
int tabWidth = KiROUND( glyphSize.x * TAB_WIDTH );
|
||||
int currentIntrusion = ( cursor.x - aOrigin.x ) % tabWidth;
|
||||
char_count = ( char_count / TAB_WIDTH + 1 ) * TAB_WIDTH - 1;
|
||||
|
||||
cursor.x += tabWidth - currentIntrusion;
|
||||
int new_cursor = aPosition.x + aSize.x * char_count
|
||||
+ aSize.x * space_width;
|
||||
|
||||
while( new_cursor <= cursor.x )
|
||||
{
|
||||
char_count += TAB_WIDTH;
|
||||
new_cursor += aSize.x * TAB_WIDTH;
|
||||
}
|
||||
|
||||
cursor.x = new_cursor;
|
||||
}
|
||||
else if( c == ' ' )
|
||||
{
|
||||
// 'space' character - draw nothing, advance cursor position
|
||||
cursor.x += KiROUND( glyphSize.x * SPACE_WIDTH );
|
||||
cursor.x += KiROUND( glyphSize.x * space_width );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -293,6 +300,8 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr
|
|||
|
||||
cursor.x += KiROUND( glyphExtents.x );
|
||||
}
|
||||
|
||||
++char_count;
|
||||
}
|
||||
|
||||
VECTOR2D barOffset( 0.0, 0.0 );
|
||||
|
|
|
@ -38,6 +38,7 @@ set( QA_COMMON_SRCS
|
|||
test_lib_table.cpp
|
||||
test_markup_parser.cpp
|
||||
test_kicad_string.cpp
|
||||
test_kicad_stroke_font.cpp
|
||||
test_kiid.cpp
|
||||
test_property.cpp
|
||||
test_refdes_utils.cpp
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.TXT for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test suite for general string functions
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
|
||||
// Code under test
|
||||
#include <vector>
|
||||
#include <font/stroke_font.h>
|
||||
|
||||
/**
|
||||
* Declare the test suite
|
||||
*/
|
||||
BOOST_AUTO_TEST_SUITE( KicadStrokeFont )
|
||||
|
||||
|
||||
/**
|
||||
* Test the tab spacing.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE( TabCheck )
|
||||
{
|
||||
using CASE = std::pair<wxString, wxString>;
|
||||
|
||||
KIFONT::STROKE_FONT* font = KIFONT::STROKE_FONT::LoadFont( wxEmptyString );
|
||||
|
||||
const std::vector<CASE> 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<std::unique_ptr<KIFONT::GLYPH>> 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()
|
Loading…
Reference in New Issue