From 713cb032b5d35692f55fe31ef5fbdaf13048b709 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 22 Jun 2023 13:20:47 +0200 Subject: [PATCH] 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 --- common/preview_items/preview_utils.cpp | 18 +++++++++++++- common/preview_items/ruler_item.cpp | 34 +++++++++++++++++++++++--- eeschema/sch_painter.cpp | 13 ++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index 243bf251f1..bca6a8fd33 100644 --- a/common/preview_items/preview_utils.cpp +++ b/common/preview_items/preview_utils.cpp @@ -1,7 +1,7 @@ /* * 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 * 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(); } + // 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 ) ); textAttrs.m_Mirrored = viewFlipped; // Prevent text flipping when view is flipped textAttrs.m_Size = textDims.GlyphSize; diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp index c508a8a2dc..0a0b77fa93 100644 --- a/common/preview_items/ruler_item.cpp +++ b/common/preview_items/ruler_item.cpp @@ -1,7 +1,7 @@ /* * 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 * 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 ); 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 ) + { 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() ) + { labelOffset = -labelOffset; + shadowXoffset = -shadowXoffset; + } TEXT_ATTRIBUTES labelAttrs; labelAttrs.m_Size = labelDims.GlyphSize; labelAttrs.m_StrokeWidth = labelDims.StrokeWidth; + labelAttrs.m_Mirrored = aView->IsMirroredX(); // Prevent text mirrored when view is mirrored if( EDA_ANGLE( aLine ) > ANGLE_0 ) { labelAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT; 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 { labelAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT; 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(); @@ -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 // to exclude anything that should be partially drawn + int isign = aView->IsMirroredX() ? -1 : 1; + for( int i = 0; i < numTicks; ++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->DrawLine( tickPos, tickPos + tickLine.Resize( length ) ); + gal->DrawLine( tickPos, tickPos + tickLine.Resize( length*isign ) ); if( drawLabel ) { @@ -244,9 +271,10 @@ void drawBacksideTicks( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTO TEXT_DIMS textDims = GetConstantGlyphHeight( gal, -1 ); const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions; VECTOR2D backTickVec = aLine; + int isign = aView->IsMirroredX() ? -1 : 1; RotatePoint( backTickVec, -ANGLE_90 ); - backTickVec = backTickVec.Resize( aTickLen ); + backTickVec = backTickVec.Resize( aTickLen * isign ); BOX2D viewportD = aView->GetViewport(); BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index e25013b16f..33fb7aa0bf 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -1512,6 +1512,19 @@ void SCH_PAINTER::draw( const LIB_PIN *aPin, int aLayer, bool aDimmed ) for( float& t : thickness ) 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 =