From 81be16d058b4166b73f57e11b269a61e915ea3f5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 12 May 2023 12:37:27 -0700 Subject: [PATCH] Adjust stroke font output to match v6 output Many minor tweaks were added that changed the output of the stroke font from v5/v6. These offsets changed the gerber output expected. This reverts the changes to something much closer to the v6 output. It is not pixel-perfect but gets very close on most texts. Fixes https://gitlab.com/kicad/code/kicad/issues/14609 (cherry picked from commit 72267cf9b0638a05f8c4b6175311672948cf35db) --- common/font/font.cpp | 31 +++++++++++++++++++------------ common/font/outline_font.cpp | 2 +- common/font/stroke_font.cpp | 11 ++++------- include/font/font.h | 8 ++++---- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/common/font/font.cpp b/common/font/font.cpp index c26b101b7b..3a1f74aae7 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -188,10 +188,11 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit */ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, const std::unique_ptr& aNode, const VECTOR2I& aPosition, - const KIFONT::FONT* aFont, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, - bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) + const KIFONT::FONT* aFont, const VECTOR2I& aSize, const VECTOR2I& aOffset, + const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, + TEXT_STYLE_FLAGS aTextStyle ) { - VECTOR2I nextPosition = aPosition; + VECTOR2I nextPosition = aPosition + aOffset; bool drawUnderline = false; bool drawOverbar = false; @@ -214,7 +215,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a BOX2I bbox; nextPosition = aFont->GetTextAsGlyphs( &bbox, aGlyphs, aNode->asWxString(), aSize, - aPosition, aAngle, aMirror, aOrigin, + nextPosition, aAngle, aMirror, aOrigin, textStyle ); if( aBoundingBox ) @@ -229,7 +230,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a for( const std::unique_ptr& child : aNode->children ) { nextPosition = drawMarkup( aBoundingBox, aGlyphs, child, nextPosition, aFont, aSize, - aAngle, aMirror, aOrigin, textStyle ); + VECTOR2I(), aAngle, aMirror, aOrigin, textStyle ); } } @@ -283,13 +284,13 @@ 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 EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, - TEXT_STYLE_FLAGS aTextStyle ) const + const VECTOR2I& aOffset, const EDA_ANGLE& aAngle, bool aMirror, + const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const { MARKUP::MARKUP_PARSER markupParser( TO_UTF8( aText ) ); std::unique_ptr root = markupParser.Parse(); - return ::drawMarkup( aBoundingBox, aGlyphs, root, aPosition, this, aSize, aAngle, aMirror, + return ::drawMarkup( aBoundingBox, aGlyphs, root, aPosition, this, aSize, aOffset, aAngle, aMirror, aOrigin, aTextStyle ); } @@ -303,7 +304,13 @@ 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; @@ -312,7 +319,7 @@ void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxSt std::vector> glyphs; - (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin, + (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, offset, aAngle, aMirror, aOrigin, textStyle ); aGal->DrawGlyphs( glyphs ); @@ -332,7 +339,7 @@ VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSiz if( aItalic ) textStyle |= TEXT_STYLE::ITALIC; - (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, ANGLE_0, false, + (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, VECTOR2I(), ANGLE_0, false, VECTOR2I(), textStyle ); if( IsStroke() ) @@ -358,8 +365,8 @@ VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText, if( aItalic ) textStyle |= TEXT_STYLE::ITALIC; - VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, ANGLE_0, false, - VECTOR2I(), textStyle ); + VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, VECTOR2I(), ANGLE_0, + false, VECTOR2I(), textStyle ); return extents; } diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index cbc33ee493..9585e00b6a 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, + (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size, VECTOR2I(), aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle ); } } diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index 98bf742a67..bd4b53a641 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -44,7 +44,7 @@ using namespace KIFONT; ///< Factor that determines relative vertical position of the overbar. -static constexpr double OVERBAR_POSITION_FACTOR = 1.40; +static constexpr double OVERBAR_POSITION_FACTOR = 1.23; ///< Factor that determines relative vertical position of the underline. static constexpr double UNDERLINE_POSITION_FACTOR = -0.16; @@ -227,9 +227,9 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector 0.0 ) - glyphExtents.x -= glyphExtents.y * tilt; - cursor.x += KiROUND( glyphExtents.x ); } diff --git a/include/font/font.h b/include/font/font.h index 5f6aff2bf4..07c57db51c 100644 --- a/include/font/font.h +++ b/include/font/font.h @@ -245,15 +245,15 @@ protected: std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const; VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, - const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, - const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, - TEXT_STYLE_FLAGS aTextStyle ) const; + const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aOffset, + const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, + const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const; void wordbreakMarkup( std::vector>* aWords, const wxString& aText, const VECTOR2I& aSize, TEXT_STYLE_FLAGS aTextStyle ) const; ///< Factor that determines the pitch between 2 lines. - static constexpr double INTERLINE_PITCH_RATIO = 1.62; // The golden mean + static constexpr double INTERLINE_PITCH_RATIO = 1.61; // The golden mean private: static FONT* getDefaultFont();