Skip to content

Commit

Permalink
Cherry-pick TEXT_ATTRIBUTES and EDA_ANGLE from rockola/kicad-strokefont
Browse files Browse the repository at this point in the history
  • Loading branch information
jey5nd6 committed Dec 28, 2021
1 parent a0c4f05 commit 86cb57f
Show file tree
Hide file tree
Showing 91 changed files with 1,896 additions and 1,576 deletions.
5 changes: 5 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ set( PLUGINS_EAGLE_SRCS
plugins/eagle/eagle_parser.cpp
)

set( FONT_SRCS
)

set( COMMON_SRCS
${LIB_KICAD_SRCS}
${COMMON_ABOUT_DLG_SRCS}
Expand All @@ -307,6 +310,7 @@ set( COMMON_SRCS
${PLUGINS_ALTIUM_SRCS}
${PLUGINS_CADSTAR_SRCS}
${PLUGINS_EAGLE_SRCS}
${FONT_SRCS}
advanced_config.cpp
array_axis.cpp
array_options.cpp
Expand All @@ -325,6 +329,7 @@ set( COMMON_SRCS
dialog_shim.cpp
gr_text.cpp
dsnlexer.cpp
eda_angle.cpp
eda_base_frame.cpp
eda_dde.cpp
eda_doc.cpp
Expand Down
12 changes: 6 additions & 6 deletions common/drawing_sheet/drawing_sheet_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,24 +729,24 @@ void DRAWING_SHEET_PARSER::parseText( DS_DATA_ITEM_TEXT* aItem )
switch( token )
{
case T_center:
aItem->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER;
aItem->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER;
aItem->m_Hjustify = GR_TEXT_H_ALIGN_CENTER;
aItem->m_Vjustify = GR_TEXT_V_ALIGN_CENTER;
break;

case T_left:
aItem->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT;
aItem->m_Hjustify = GR_TEXT_H_ALIGN_LEFT;
break;

case T_right:
aItem->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT;
aItem->m_Hjustify = GR_TEXT_H_ALIGN_RIGHT;
break;

case T_top:
aItem->m_Vjustify = GR_TEXT_VJUSTIFY_TOP;
aItem->m_Vjustify = GR_TEXT_V_ALIGN_TOP;
break;

case T_bottom:
aItem->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
aItem->m_Vjustify = GR_TEXT_V_ALIGN_BOTTOM;
break;

default:
Expand Down
4 changes: 2 additions & 2 deletions common/drawing_sheet/ds_data_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ DS_DATA_ITEM_TEXT::DS_DATA_ITEM_TEXT( const wxString& aTextBase ) :
{
m_TextBase = aTextBase;
m_IncrementLabel = 1;
m_Hjustify = GR_TEXT_HJUSTIFY_LEFT;
m_Vjustify = GR_TEXT_VJUSTIFY_CENTER;
m_Hjustify = GR_TEXT_H_ALIGN_LEFT;
m_Vjustify = GR_TEXT_V_ALIGN_CENTER;
m_Italic = false;
m_Bold = false;
m_Orient = 0.0;
Expand Down
10 changes: 5 additions & 5 deletions common/drawing_sheet/ds_data_model_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,20 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
}

// Write text justification
if( aItem->m_Hjustify != GR_TEXT_HJUSTIFY_LEFT || aItem->m_Vjustify != GR_TEXT_VJUSTIFY_CENTER )
if( aItem->m_Hjustify != GR_TEXT_H_ALIGN_LEFT || aItem->m_Vjustify != GR_TEXT_V_ALIGN_CENTER )
{
m_out->Print( 0, " (justify" );

// Write T_center opt first, because it is
// also a center for both m_Hjustify and m_Vjustify
if( aItem->m_Hjustify == GR_TEXT_HJUSTIFY_CENTER )
if( aItem->m_Hjustify == GR_TEXT_H_ALIGN_CENTER )
m_out->Print( 0, " center" );
else if( aItem->m_Hjustify == GR_TEXT_HJUSTIFY_RIGHT )
else if( aItem->m_Hjustify == GR_TEXT_H_ALIGN_RIGHT )
m_out->Print( 0, " right" );

if( aItem->m_Vjustify == GR_TEXT_VJUSTIFY_TOP )
if( aItem->m_Vjustify == GR_TEXT_V_ALIGN_TOP )
m_out->Print( 0, " top" );
else if( aItem->m_Vjustify == GR_TEXT_VJUSTIFY_BOTTOM )
else if( aItem->m_Vjustify == GR_TEXT_V_ALIGN_BOTTOM )
m_out->Print( 0, " bottom" );

m_out->Print( 0, ")" );
Expand Down
2 changes: 1 addition & 1 deletion common/drawing_sheet/ds_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void KIGFX::DS_PAINTER::draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const

m_gal->Save();
m_gal->Translate( position );
m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
m_gal->Rotate( -aItem->GetTextAngle().AsRadians() );
m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
m_gal->SetLineWidth( penWidth );
m_gal->SetTextAttributes( aItem );
Expand Down
114 changes: 114 additions & 0 deletions common/eda_angle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 Ola Rinta-Koski
* Copyright (C) 2021 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 <eda_angle.h>

EDA_ANGLE EDA_ANGLE::m_angle0 = EDA_ANGLE( 0, EDA_ANGLE::DEGREES );
EDA_ANGLE EDA_ANGLE::m_angle90 = EDA_ANGLE( 90, EDA_ANGLE::DEGREES );
EDA_ANGLE EDA_ANGLE::m_angle180 = EDA_ANGLE( 180, EDA_ANGLE::DEGREES );
EDA_ANGLE EDA_ANGLE::m_angle270 = EDA_ANGLE( 270, EDA_ANGLE::DEGREES );
EDA_ANGLE EDA_ANGLE::m_angle360 = EDA_ANGLE( 360, EDA_ANGLE::DEGREES );

EDA_ANGLE EDA_ANGLE::KeepUpright() const
{
EDA_ANGLE inAngle( *this );
inAngle.Normalize();

int inDegrees = inAngle.AsDegrees();
int outDegrees;

if( inDegrees <= 45 || inDegrees >= 315 || ( inDegrees > 135 && inDegrees <= 225 ) )
outDegrees = 0;
else
outDegrees = 90;

return EDA_ANGLE( outDegrees, EDA_ANGLE::DEGREES );
}


void EDA_ANGLE::normalize( bool n720 )
{
if( GetInitialAngleType() == EDA_ANGLE::RADIANS )
{
m_radians = normalize( m_radians, EDA_ANGLE::RADIANS, n720 );
m_value = int( m_radians / TENTHS_OF_A_DEGREE_TO_RADIANS );
}
else
{
m_value = normalize( m_value, EDA_ANGLE::TENTHS_OF_A_DEGREE, n720 );
}
}


int EDA_ANGLE::normalize( int aValue, ANGLE_TYPE aAngleType, bool n720 ) const
{
int full_circle_upper;

switch( aAngleType )
{
case DEGREES:
full_circle_upper = DEGREES_FULL_CIRCLE;
break;

case TENTHS_OF_A_DEGREE:
full_circle_upper = TENTHS_OF_A_DEGREE_FULL_CIRCLE;
break;

case RADIANS:
/* ?? should not get here */
assert( 1 == 0 );
}

/* if n720 == false, clamp between 0..full_circle_upper
* if n720 == true, clamp between +/- full_circle_upper
*/
int full_circle_lower = n720 ? 0 : -full_circle_upper;

while( aValue < full_circle_lower )
aValue += full_circle_upper;

while( aValue > full_circle_upper )
aValue -= full_circle_upper;

return aValue;
}


double EDA_ANGLE::normalize( double aValue, ANGLE_TYPE aAngleType, bool n720 ) const
{
double full_circle_upper;

switch( aAngleType )
{
case DEGREES: full_circle_upper = DEGREES_FULL_CIRCLE; break;
case TENTHS_OF_A_DEGREE: full_circle_upper = TENTHS_OF_A_DEGREE_FULL_CIRCLE; break;
case RADIANS: full_circle_upper = RADIANS_FULL_CIRCLE; break;
}

double full_circle_lower = n720 ? 0 : -full_circle_upper;

while( aValue < full_circle_lower )
aValue += full_circle_upper;

while( aValue > full_circle_upper )
aValue -= full_circle_upper;

return aValue;
}
Loading

0 comments on commit 86cb57f

Please sign in to comment.