From 1698fb6608794565e85710aee44430e99174ef87 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 23 Jun 2023 10:32:23 +0200 Subject: [PATCH] Refinement of commit 355575e4 (drawing shadow texts of RULER_ITEM and pin names) Also handle non Kicad fonts (that do not use shadow texts) Fixes #15019 https://gitlab.com/kicad/code/kicad/-/issues/15019 --- common/preview_items/preview_utils.cpp | 9 ++++++++- common/preview_items/ruler_item.cpp | 8 +++++++- eeschema/sch_painter.cpp | 15 +++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index 0f8f90d493..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 @@ -158,6 +158,13 @@ void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& a // 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 diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp index 41097ce10b..0df5bbd141 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 @@ -175,6 +175,12 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT { 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() ) diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 5fcf7a5091..ed083a66ca 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -1628,11 +1628,18 @@ 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 ISIDE or OUTSIDE is drawn left or right aligned, - // it needs an offset = shadowWidth/2 to be drawn at the same place as normal text + // 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. - insideOffset -= shadowWidth/2.0f; - outsideOffset -= shadowWidth/2.0f; + // 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 =