diff --git a/common/font/font.cpp b/common/font/font.cpp index ecf2dc3a93..e1f5797811 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -194,6 +194,13 @@ void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition, VECTOR2I offset( 0, 0 ); offset.y += aAttrs.m_Size.y; + if( IsStroke() ) + { + // Fudge factors to match 6.0 positioning + offset.x += aAttrs.m_StrokeWidth / 1.52; + offset.y -= aAttrs.m_StrokeWidth * 0.052; + } + switch( aAttrs.m_Valign ) { case GR_TEXT_V_ALIGN_TOP: break; @@ -212,7 +219,7 @@ void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition, { case GR_TEXT_H_ALIGN_LEFT: break; case GR_TEXT_H_ALIGN_CENTER: lineOffset.x = -lineSize.x / 2; break; - case GR_TEXT_H_ALIGN_RIGHT: lineOffset.x = -lineSize.x; break; + case GR_TEXT_H_ALIGN_RIGHT: lineOffset.x = -( lineSize.x + offset.x ); break; } aPositions.push_back( aPosition + lineOffset ); @@ -261,11 +268,10 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit */ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, const MARKUP::NODE* aNode, const VECTOR2I& aPosition, - const KIFONT::FONT* aFont, const VECTOR2I& aSize, const VECTOR2I& aOffset, - const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, - TEXT_STYLE_FLAGS aTextStyle ) + const KIFONT::FONT* aFont, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, + bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) { - VECTOR2I nextPosition = aPosition + aOffset; + VECTOR2I nextPosition = aPosition; bool drawUnderline = false; bool drawOverbar = false; @@ -303,7 +309,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a for( const std::unique_ptr& child : aNode->children ) { nextPosition = drawMarkup( aBoundingBox, aGlyphs, child.get(), nextPosition, aFont, - aSize, VECTOR2I(), aAngle, aMirror, aOrigin, textStyle ); + aSize, aAngle, aMirror, aOrigin, textStyle ); } } @@ -357,8 +363,8 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, - const VECTOR2I& aOffset, const EDA_ANGLE& aAngle, bool aMirror, - const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const + const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, + TEXT_STYLE_FLAGS aTextStyle ) const { std::lock_guard lock( s_markupCacheMutex ); @@ -376,7 +382,7 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vectorroot ); - return ::drawMarkup( aBoundingBox, aGlyphs, markup->root.get(), aPosition, this, aSize, aOffset, aAngle, + return ::drawMarkup( aBoundingBox, aGlyphs, markup->root.get(), aPosition, this, aSize, aAngle, aMirror, aOrigin, aTextStyle ); } @@ -390,13 +396,8 @@ void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxSt return; TEXT_STYLE_FLAGS textStyle = 0; - VECTOR2I offset; - if( !IsOutline() ) - { - offset.x = aGal->GetLineWidth() / 1.52; - offset.y = -aGal->GetLineWidth() * 0.052; - } + if( aItalic ) textStyle |= TEXT_STYLE::ITALIC; @@ -405,7 +406,7 @@ void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxSt std::vector> glyphs; - (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, offset, aAngle, aMirror, aOrigin, + (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin, textStyle ); aGal->DrawGlyphs( glyphs ); @@ -425,8 +426,8 @@ VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSiz if( aItalic ) textStyle |= TEXT_STYLE::ITALIC; - (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, VECTOR2I(), ANGLE_0, false, - VECTOR2I(), textStyle ); + (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, ANGLE_0, false, VECTOR2I(), + textStyle ); if( IsStroke() ) { @@ -451,8 +452,8 @@ VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText, if( aItalic ) textStyle |= TEXT_STYLE::ITALIC; - VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, VECTOR2I(), ANGLE_0, - false, VECTOR2I(), textStyle ); + VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, ANGLE_0, false, + VECTOR2I(), textStyle ); return extents; } diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index 9585e00b6a..cbc33ee493 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -255,7 +255,7 @@ void OUTLINE_FONT::GetLinesAsGlyphs( std::vector>* aGlyph for( size_t i = 0; i < strings.GetCount(); i++ ) { - (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size, VECTOR2I(), + (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size, aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle ); } } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index c031a9a610..bb8953beb0 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -2103,6 +2103,21 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer ) m_gal->SetIsStroke( true ); attrs.m_StrokeWidth += getShadowWidth( !aText->IsSelected() ); attrs.m_Underlined = false; + + // Fudge factors to match 6.0 positioning + // New text stroking has width dependent offset but we need to + // center the shadow on the stroke. NB this offset is in font.cpp also + double fudge = getShadowWidth( !aText->IsSelected() ) / 1.52; + + if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_0 ) + text_offset.x -= fudge; + else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_90 ) + text_offset.y -= fudge; + else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_0 ) + text_offset.x += fudge; + else if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_90 ) + text_offset.y += fudge; + strokeText( shownText, aText->GetDrawPos() + text_offset, attrs ); } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 196f12385d..cd1eaf4ebe 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -137,7 +137,8 @@ SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) : VECTOR2I SCH_TEXT::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const { - return VECTOR2I( 0, 0 ); + // Fudge factor to match KiCad 6 + return VECTOR2I( 0, -2500 ); } diff --git a/include/font/font.h b/include/font/font.h index 07c57db51c..a0f147aea6 100644 --- a/include/font/font.h +++ b/include/font/font.h @@ -245,7 +245,7 @@ protected: std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const; VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, - const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aOffset, + const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 01d517476c..bf387121ba 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1864,7 +1864,23 @@ void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition, m_gal->SetIsFill( font->IsOutline() ); m_gal->SetIsStroke( font->IsStroke() ); - font->Draw( m_gal, aText, aPosition, aAttrs ); + VECTOR2I pos( aPosition ); + VECTOR2I fudge + { KiROUND( 0.16 * aAttrs.m_StrokeWidth ), 0 }; + RotatePoint( fudge, aAttrs.m_Angle ); + + if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && !aAttrs.m_Mirrored ) + || ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && aAttrs.m_Mirrored ) ) + { + pos -= fudge; + } + else if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && !aAttrs.m_Mirrored ) + || ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && aAttrs.m_Mirrored ) ) + { + pos += fudge; + } + + font->Draw( m_gal, aText, pos, aAttrs ); }