Fix some (minor) issues when drawing shadow texts of RULER_ITEM and pin names.

From master branch (commits 355575e4, 1698fb66 and 965aaa21)
Fixes #15019
https://gitlab.com/kicad/code/kicad/-/issues/15019
This commit is contained in:
jean-pierre charras 2023-06-22 13:20:47 +02:00
parent 24ed144200
commit 713cb032b5
3 changed files with 61 additions and 4 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2019-2021 Kicad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2023 Kicad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License as published by the
@ -154,6 +154,22 @@ void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& a
textPos.x -= 15.0 / gal->GetWorldScale(); textPos.x -= 15.0 / gal->GetWorldScale();
} }
// text is left (or right) aligned, so a shadow text need a small offset to be draw
// around the basic text
int shadowXoffset = aDrawingDropShadows ? textDims.ShadowWidth : 0;
// Due to the fact a shadow text is drawn left or right aligned,
// it needs an offset = shadowWidth/2 to be drawn at the same place as normal text
// But for some reason we need to slightly modify this offset
// for a better look for KiCad font (better alignment of shadow shape)
const float adjust = 1.2f; // Value chosen after tests
shadowXoffset *= adjust;
if( ( textAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT ) != viewFlipped )
textPos.x -= shadowXoffset;
else
textPos.x += shadowXoffset;
gal->SetStrokeColor( aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_AUX_ITEMS ) ); gal->SetStrokeColor( aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_AUX_ITEMS ) );
textAttrs.m_Mirrored = viewFlipped; // Prevent text flipping when view is flipped textAttrs.m_Mirrored = viewFlipped; // Prevent text flipping when view is flipped
textAttrs.m_Size = textDims.GlyphSize; textAttrs.m_Size = textDims.GlyphSize;

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017-2022 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2017-2023 Kicad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -167,25 +167,50 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
EDA_ANGLE labelAngle = - EDA_ANGLE( tickLine ); EDA_ANGLE labelAngle = - EDA_ANGLE( tickLine );
VECTOR2I labelOffset = tickLine.Resize( majorTickLen ); VECTOR2I labelOffset = tickLine.Resize( majorTickLen );
// text is left (or right) aligned, so shadow text need a small offset to be draw
// around the basic text
int shadowXoffset = 0;
if( aDrawingDropShadows ) if( aDrawingDropShadows )
{
labelDims.StrokeWidth += 2 * labelDims.ShadowWidth; labelDims.StrokeWidth += 2 * labelDims.ShadowWidth;
shadowXoffset = labelDims.ShadowWidth;
// Due to the fact a shadow text is drawn left or right aligned,
// it needs an offset = shadowXoffset to be drawn at the same place as normal text
// But for some reason we need to slightly modify this offset
// for a better look for KiCad font (better alignment of shadow shape)
const float adjust = 1.2f; // Value chosen after tests
shadowXoffset *= adjust;
}
if( aView->IsMirroredX() ) if( aView->IsMirroredX() )
{
labelOffset = -labelOffset; labelOffset = -labelOffset;
shadowXoffset = -shadowXoffset;
}
TEXT_ATTRIBUTES labelAttrs; TEXT_ATTRIBUTES labelAttrs;
labelAttrs.m_Size = labelDims.GlyphSize; labelAttrs.m_Size = labelDims.GlyphSize;
labelAttrs.m_StrokeWidth = labelDims.StrokeWidth; labelAttrs.m_StrokeWidth = labelDims.StrokeWidth;
labelAttrs.m_Mirrored = aView->IsMirroredX(); // Prevent text mirrored when view is mirrored
if( EDA_ANGLE( aLine ) > ANGLE_0 ) if( EDA_ANGLE( aLine ) > ANGLE_0 )
{ {
labelAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT; labelAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
labelAttrs.m_Angle = labelAngle; labelAttrs.m_Angle = labelAngle;
// Adjust the text position of the shadow shape:
labelOffset.x -= shadowXoffset * labelAttrs.m_Angle.Cos();;
labelOffset.y += shadowXoffset * labelAttrs.m_Angle.Sin();;
} }
else else
{ {
labelAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT; labelAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT;
labelAttrs.m_Angle = labelAngle + ANGLE_180; labelAttrs.m_Angle = labelAngle + ANGLE_180;
// Adjust the text position of the shadow shape:
labelOffset.x += shadowXoffset * labelAttrs.m_Angle.Cos();;
labelOffset.y -= shadowXoffset * labelAttrs.m_Angle.Sin();;
} }
BOX2D viewportD = aView->GetViewport(); BOX2D viewportD = aView->GetViewport();
@ -194,6 +219,8 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
viewport.Inflate( majorTickLen * 2 ); // Doesn't have to be accurate, just big enough not viewport.Inflate( majorTickLen * 2 ); // Doesn't have to be accurate, just big enough not
// to exclude anything that should be partially drawn // to exclude anything that should be partially drawn
int isign = aView->IsMirroredX() ? -1 : 1;
for( int i = 0; i < numTicks; ++i ) for( int i = 0; i < numTicks; ++i )
{ {
const VECTOR2D tickPos = aOrigin + aLine.Resize( tickSpace * i ); const VECTOR2D tickPos = aOrigin + aLine.Resize( tickSpace * i );
@ -216,7 +243,7 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
} }
gal->SetLineWidth( labelAttrs.m_StrokeWidth / 2 ); gal->SetLineWidth( labelAttrs.m_StrokeWidth / 2 );
gal->DrawLine( tickPos, tickPos + tickLine.Resize( length ) ); gal->DrawLine( tickPos, tickPos + tickLine.Resize( length*isign ) );
if( drawLabel ) if( drawLabel )
{ {
@ -244,9 +271,10 @@ void drawBacksideTicks( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTO
TEXT_DIMS textDims = GetConstantGlyphHeight( gal, -1 ); TEXT_DIMS textDims = GetConstantGlyphHeight( gal, -1 );
const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions; const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions;
VECTOR2D backTickVec = aLine; VECTOR2D backTickVec = aLine;
int isign = aView->IsMirroredX() ? -1 : 1;
RotatePoint( backTickVec, -ANGLE_90 ); RotatePoint( backTickVec, -ANGLE_90 );
backTickVec = backTickVec.Resize( aTickLen ); backTickVec = backTickVec.Resize( aTickLen * isign );
BOX2D viewportD = aView->GetViewport(); BOX2D viewportD = aView->GetViewport();
BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) ); BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );

View File

@ -1512,6 +1512,19 @@ void SCH_PAINTER::draw( const LIB_PIN *aPin, int aLayer, bool aDimmed )
for( float& t : thickness ) for( float& t : thickness )
t += shadowWidth; t += shadowWidth;
// Due to the fact a shadow text in position INSIDE or OUTSIDE is drawn left or right aligned,
// it needs an offset = shadowWidth/2 to be drawn at the same place as normal text
// texts drawn as GR_TEXT_H_ALIGN_CENTER do not need a specific offset.
// this offset is shadowWidth/2 but for some reason we need to slightly modify this offset
// for a better look (better alignment of shadow shape), for KiCad font only
if( !KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font )->IsOutline() )
{
const float adjust = 1.2f; // Value chosen after tests
float shadowOffset = shadowWidth/2.0f * adjust;
insideOffset -= shadowOffset;
outsideOffset -= shadowOffset;
}
} }
auto drawText = auto drawText =