Browse Source
Text attributes object improvements.
Text attributes object improvements.
* Add compare method to COLOR4D object. * Add unit test to validate COLOR4D comparison method. * Add missing color test in text attribute comparison method. * Add unit test for text attribute object. * Remove unnecessary headers from text attribute header. * Move text attribute code into separate source file.newinvert
24 changed files with 418 additions and 55 deletions
-
1common/CMakeLists.txt
-
41common/eda_text.cpp
-
135common/font/text_attributes.cpp
-
20common/gal/color4d.cpp
-
1eeschema/netlist_exporters/netlist_exporter_spice.cpp
-
5eeschema/sch_plotter.cpp
-
1eeschema/sch_plugins/database/sch_database_plugin.cpp
-
1eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp
-
1eeschema/sim/spice_model_parser.cpp
-
1eeschema/tools/sch_move_tool.cpp
-
45include/font/text_attributes.h
-
4include/gal/color4d.h
-
1pagelayout_editor/tools/pl_edit_tool.cpp
-
1pagelayout_editor/tools/pl_point_editor.cpp
-
1pcbnew/exporters/step/exporter_step.cpp
-
3pcbnew/pcb_expr_functions.cpp
-
3pcbnew/pcbplot.h
-
1pcbnew/plot_board_layers.cpp
-
3pcbnew/plugins/legacy/legacy_plugin.cpp
-
3pcbnew/router/pns_kicad_iface.h
-
6qa/unittests/common/CMakeLists.txt
-
42qa/unittests/common/test_color4d.cpp
-
152qa/unittests/common/test_text_attributes.cpp
-
1qa/unittests/eeschema/test_netlist_exporter_spice.h
@ -0,0 +1,135 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021-2023 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 3 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, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <font/text_attributes.h>
|
|||
|
|||
#include <font/outline_font.h>
|
|||
|
|||
|
|||
TEXT_ATTRIBUTES::TEXT_ATTRIBUTES( KIFONT::FONT* aFont ) : |
|||
m_Font( aFont ), |
|||
m_Halign( GR_TEXT_H_ALIGN_CENTER ), |
|||
m_Valign( GR_TEXT_V_ALIGN_CENTER ), |
|||
m_Angle( ANGLE_0 ), |
|||
m_LineSpacing( 1.0 ), |
|||
m_StrokeWidth( 0 ), |
|||
m_Italic( false ), |
|||
m_Bold( false ), |
|||
m_Underlined( false ), |
|||
m_Color( KIGFX::COLOR4D::UNSPECIFIED ), |
|||
m_Visible( true ), |
|||
m_Mirrored( false ), |
|||
m_Multiline( true ), |
|||
m_KeepUpright( false ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
int TEXT_ATTRIBUTES::Compare( const TEXT_ATTRIBUTES& aRhs ) const |
|||
{ |
|||
wxString fontName; |
|||
|
|||
if( m_Font ) |
|||
fontName = m_Font->GetName(); |
|||
|
|||
wxString rhsFontName; |
|||
|
|||
if( aRhs.m_Font ) |
|||
rhsFontName = aRhs.m_Font->GetName(); |
|||
|
|||
int retv = fontName.Cmp( rhsFontName ); |
|||
|
|||
if( retv ) |
|||
return retv; |
|||
|
|||
if( m_Size.x != aRhs.m_Size.x ) |
|||
return m_Size.x - aRhs.m_Size.x; |
|||
|
|||
if( m_Size.y != aRhs.m_Size.y ) |
|||
return m_Size.y - aRhs.m_Size.y; |
|||
|
|||
if( m_StrokeWidth != aRhs.m_StrokeWidth ) |
|||
return m_StrokeWidth - aRhs.m_StrokeWidth; |
|||
|
|||
if( m_Angle.AsDegrees() != aRhs.m_Angle.AsDegrees() ) |
|||
return m_Angle.AsDegrees() - aRhs.m_Angle.AsDegrees(); |
|||
|
|||
if( m_LineSpacing != aRhs.m_LineSpacing ) |
|||
return m_LineSpacing - aRhs.m_LineSpacing; |
|||
|
|||
if( m_Halign != aRhs.m_Halign ) |
|||
return m_Halign - aRhs.m_Halign; |
|||
|
|||
if( m_Valign != aRhs.m_Valign ) |
|||
return m_Valign - aRhs.m_Valign; |
|||
|
|||
if( m_Italic != aRhs.m_Italic ) |
|||
return m_Italic - aRhs.m_Italic; |
|||
|
|||
if( m_Bold != aRhs.m_Bold ) |
|||
return m_Bold - aRhs.m_Bold; |
|||
|
|||
if( m_Underlined != aRhs.m_Underlined ) |
|||
return m_Underlined - aRhs.m_Underlined; |
|||
|
|||
retv = m_Color.Compare( aRhs.m_Color ); |
|||
|
|||
if( retv ) |
|||
return retv; |
|||
|
|||
if( m_Visible != aRhs.m_Visible ) |
|||
return m_Visible - aRhs.m_Visible; |
|||
|
|||
if( m_Mirrored != aRhs.m_Mirrored ) |
|||
return m_Mirrored - aRhs.m_Mirrored; |
|||
|
|||
if( m_Multiline != aRhs.m_Multiline ) |
|||
return m_Multiline - aRhs.m_Multiline; |
|||
|
|||
return m_KeepUpright - aRhs.m_KeepUpright; |
|||
} |
|||
|
|||
|
|||
std::ostream& operator<<( std::ostream& aStream, const TEXT_ATTRIBUTES& aAttributes ) |
|||
{ |
|||
aStream << "Font: \""; |
|||
|
|||
if ( aAttributes.m_Font ) |
|||
aStream << *aAttributes.m_Font; |
|||
else |
|||
aStream << "UNDEFINED"; |
|||
|
|||
aStream << "\"\n"; |
|||
aStream << "Horizontal Alignment: " << aAttributes.m_Halign << std::endl |
|||
<< "Vertical Alignment: " << aAttributes.m_Valign << std::endl |
|||
<< "Angle: " << aAttributes.m_Angle << std::endl |
|||
<< "Line Spacing: " << aAttributes.m_LineSpacing << std::endl |
|||
<< "Stroke Width: " << aAttributes.m_StrokeWidth << std::endl |
|||
<< "Italic: " << aAttributes.m_Italic << std::endl |
|||
<< "Bold: " << aAttributes.m_Bold << std::endl |
|||
<< "Underline: " << aAttributes.m_Underlined << std::endl |
|||
<< "Color: " << aAttributes.m_Color << std::endl |
|||
<< "Visible " << aAttributes.m_Visible << std::endl |
|||
<< "Mirrored " << aAttributes.m_Mirrored << std::endl |
|||
<< "Multilined: " << aAttributes.m_Multiline << std::endl |
|||
<< "Size: " << aAttributes.m_Size << std::endl |
|||
<< "Keep Upright: " << aAttributes.m_KeepUpright << std::endl; |
|||
|
|||
return aStream; |
|||
} |
@ -0,0 +1,152 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Wayne Stambaugh <stambaughw@gmail.com> |
|||
* Copyright (C) 2023 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 3 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, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
|||
|
|||
#include <font/text_attributes.h>
|
|||
#include <font/font.h>
|
|||
|
|||
|
|||
BOOST_AUTO_TEST_SUITE( TextAttributes ) |
|||
|
|||
|
|||
BOOST_AUTO_TEST_CASE( Compare ) |
|||
{ |
|||
TEXT_ATTRIBUTES a; |
|||
TEXT_ATTRIBUTES b; |
|||
|
|||
BOOST_CHECK_EQUAL( a, b ); |
|||
|
|||
a.m_Font = KIFONT::FONT::GetFont(); |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Font = nullptr; |
|||
b.m_Font = KIFONT::FONT::GetFont(); |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Font = nullptr; |
|||
a.m_Halign = GR_TEXT_H_ALIGN_RIGHT; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Halign = GR_TEXT_H_ALIGN_CENTER; |
|||
b.m_Halign = GR_TEXT_H_ALIGN_RIGHT; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Halign = GR_TEXT_H_ALIGN_CENTER; |
|||
a.m_Valign = GR_TEXT_V_ALIGN_BOTTOM; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Valign = GR_TEXT_V_ALIGN_CENTER; |
|||
b.m_Valign = GR_TEXT_V_ALIGN_BOTTOM; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Valign = GR_TEXT_V_ALIGN_CENTER; |
|||
a.m_Angle = EDA_ANGLE( 90.0, DEGREES_T ); |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Angle = EDA_ANGLE( 0.0, DEGREES_T ); |
|||
b.m_Angle = EDA_ANGLE( 90.0, DEGREES_T ); |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Angle = EDA_ANGLE( 0.0, DEGREES_T ); |
|||
a.m_StrokeWidth = 1; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_StrokeWidth = 0; |
|||
b.m_StrokeWidth = 1; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_StrokeWidth = 0; |
|||
a.m_Italic = true; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Italic = false; |
|||
b.m_Italic = true; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Italic = false; |
|||
a.m_Bold = true; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Bold = false; |
|||
b.m_Bold = true; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Bold = false; |
|||
a.m_Underlined = true; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Underlined = false; |
|||
b.m_Underlined = true; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Underlined = false; |
|||
a.m_Color = KIGFX::COLOR4D( RED ); |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Color = KIGFX::COLOR4D( UNSPECIFIED_COLOR ); |
|||
b.m_Color = KIGFX::COLOR4D( RED ); |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Color = KIGFX::COLOR4D( UNSPECIFIED_COLOR ); |
|||
b.m_Visible = false; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
b.m_Visible = true; |
|||
a.m_Visible = false; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
a.m_Visible = true; |
|||
a.m_Mirrored = true; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Mirrored = false; |
|||
b.m_Mirrored = true; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Mirrored = false; |
|||
b.m_Multiline = false; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
b.m_Multiline = true; |
|||
a.m_Multiline = false; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
a.m_Multiline = true; |
|||
a.m_Size.x = 1; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_Size.x = 0; |
|||
b.m_Size.x = 1; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_Size.x = 0; |
|||
a.m_KeepUpright = true; |
|||
BOOST_CHECK_GT( a, b ); |
|||
|
|||
a.m_KeepUpright = false; |
|||
b.m_KeepUpright = true; |
|||
BOOST_CHECK_LT( a, b ); |
|||
|
|||
b.m_KeepUpright = false; |
|||
} |
|||
|
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue