Cleanup text alignment between version 6 and 7
Version 7 text alignment changed subtly for stroke fonts from version 6. Additionally, the output has been different between screen and plotting, leading to offset text in plotted output relative to the text shown on screen. This introduces a fudge factor in FONT::getLinePositions to correct the offset in the plotting output relative to v6. This also changes the SCH_PAINTER and PCB_PAINTER to correct the relative offsets between GAL and PLOTTER classes. The source of these offsets is atm unclear. Fixes https://gitlab.com/kicad/code/kicad/issues/14755
This commit is contained in:
parent
20ec8ed303
commit
0de24bfd59
|
@ -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<std::unique_ptr<GLYPH>>* 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<std::unique_ptr<GLYPH>>* a
|
|||
for( const std::unique_ptr<MARKUP::NODE>& 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<std::unique_ptr<GLYPH>>* a
|
|||
|
||||
VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* 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<std::mutex> lock( s_markupCacheMutex );
|
||||
|
||||
|
@ -376,7 +382,7 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYP
|
|||
|
||||
wxASSERT( markup && markup->root );
|
||||
|
||||
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<std::unique_ptr<GLYPH>> 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;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ void OUTLINE_FONT::GetLinesAsGlyphs( std::vector<std::unique_ptr<GLYPH>>* 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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@ protected:
|
|||
std::vector<VECTOR2I>& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const;
|
||||
|
||||
VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* 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;
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue