diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index 7281977fbb..f87914eab6 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -118,7 +118,8 @@ void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContaine attrs.m_Angle = aText->GetDrawRotation(); - font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs ); + font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs, + aOwner->GetFontMetrics() ); } } diff --git a/common/drawing_sheet/ds_draw_item.cpp b/common/drawing_sheet/ds_draw_item.cpp index a4134230c3..1f6fb53799 100644 --- a/common/drawing_sheet/ds_draw_item.cpp +++ b/common/drawing_sheet/ds_draw_item.cpp @@ -58,9 +58,17 @@ #include #include #include +#include + // ============================ BASE CLASS ============================== +const KIFONT::METRICS& DS_DRAW_ITEM_BASE::GetFontMetrics() const +{ + return KIFONT::METRICS::Default(); +} + + void DS_DRAW_ITEM_BASE::ViewGetLayers( int aLayers[], int& aCount ) const { aCount = 1; diff --git a/common/drawing_sheet/ds_painter.cpp b/common/drawing_sheet/ds_painter.cpp index baea6e5a62..7ef19fe2f4 100644 --- a/common/drawing_sheet/ds_painter.cpp +++ b/common/drawing_sheet/ds_painter.cpp @@ -270,7 +270,8 @@ void KIGFX::DS_PAINTER::draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const attrs.m_StrokeWidth = std::max( aItem->GetEffectiveTextPenWidth(), m_renderSettings.GetDefaultPenWidth() ); - font->Draw( m_gal, aItem->GetShownText( true ), aItem->GetTextPos(), attrs ); + font->Draw( m_gal, aItem->GetShownText( true ), aItem->GetTextPos(), attrs, + aItem->GetFontMetrics() ); } diff --git a/common/eda_text.cpp b/common/eda_text.cpp index c2d6e2cb16..6803d442a1 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -22,11 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file eda_text.cpp - * @brief Implementation of base KiCad text object. - */ - #include // for max #include // for NULL #include // for swap @@ -473,6 +468,11 @@ KIFONT::FONT* EDA_TEXT::getDrawFont() const } +const KIFONT::METRICS& EDA_TEXT::getFontMetrics() const +{ + return KIFONT::METRICS::Default(); +} + void EDA_TEXT::ClearRenderCache() { @@ -508,7 +508,7 @@ EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolved attrs.m_Angle = resolvedAngle; font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset, - attrs ); + attrs, getFontMetrics() ); m_render_cache_font = aFont; m_render_cache_angle = resolvedAngle; m_render_cache_text = forResolvedText; @@ -538,7 +538,7 @@ void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly ) int EDA_TEXT::GetInterline() const { - return KiROUND( getDrawFont()->GetInterline( GetTextHeight() ) ); + return KiROUND( getDrawFont()->GetInterline( GetTextHeight(), getFontMetrics() ) ); } @@ -577,20 +577,21 @@ BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const VECTOR2D fontSize( GetTextSize() ); bool bold = IsBold(); bool italic = IsItalic(); - VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic ); + VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, + getFontMetrics() ); int overbarOffset = 0; // Creates bounding box (rectangle) for horizontal, left and top justified text. The // bounding box will be moved later according to the actual text options VECTOR2I textsize = VECTOR2I( extents.x, extents.y ); VECTOR2I pos = drawPos; - int fudgeFactor = extents.y * 0.17; + int fudgeFactor = KiROUND( extents.y * 0.17 ); if( font->IsStroke() ) textsize.y += fudgeFactor; if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() ) - pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y ) ); + pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) ); if( text.Contains( wxT( "~{" ) ) ) overbarOffset = extents.y / 6; @@ -606,13 +607,15 @@ BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const for( unsigned ii = 1; ii < strings.GetCount(); ii++ ) { text = strings.Item( ii ); - extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic ); + extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, + getFontMetrics() ); textsize.x = std::max( textsize.x, extents.x ); } // interline spacing is only *between* lines, so total height is the height of the first // line plus the interline distance (with interline spacing) for all subsequent lines - textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y ) ); + textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y, + getFontMetrics() ) ); } textsize.y += overbarOffset; @@ -780,7 +783,7 @@ void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTO font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), font ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() ); } @@ -949,7 +952,7 @@ std::shared_ptr EDA_TEXT::GetEffectiveTextShape( bool aTriangula if( cache ) callback_gal.DrawGlyphs( *cache ); else - font->Draw( &callback_gal, shownText, drawPos, attrs ); + font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() ); } else { @@ -969,7 +972,7 @@ std::shared_ptr EDA_TEXT::GetEffectiveTextShape( bool aTriangula if( cache ) callback_gal.DrawGlyphs( *cache ); else - font->Draw( &callback_gal, shownText, drawPos, attrs ); + font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() ); } return shape; diff --git a/common/font/font.cpp b/common/font/font.cpp index b38f02c797..8d6c8c4f6b 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -46,6 +46,15 @@ using namespace KIFONT; +METRICS g_defaultMetrics; + + +const METRICS& METRICS::Default() +{ + return g_defaultMetrics; +} + + FONT* FONT::s_defaultFont = nullptr; std::map< std::tuple, FONT*> FONT::s_fontMap; @@ -165,20 +174,21 @@ bool FONT::IsStroke( const wxString& aFontName ) void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition, wxArrayString& aTextLines, std::vector& aPositions, - std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const + std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs, + const METRICS& aFontMetrics ) const { wxStringSplit( aText, aTextLines, '\n' ); int lineCount = aTextLines.Count(); aPositions.reserve( lineCount ); - int interline = GetInterline( aAttrs.m_Size.y, aAttrs.m_LineSpacing ); + int interline = GetInterline( aAttrs.m_Size.y, aFontMetrics ) * aAttrs.m_LineSpacing; int height = 0; for( int i = 0; i < lineCount; i++ ) { VECTOR2I pos( aPosition.x, aPosition.y + i * interline ); VECTOR2I end = boundingBoxSingleLine( nullptr, aTextLines[i], pos, aAttrs.m_Size, - aAttrs.m_Italic ); + aAttrs.m_Italic, aFontMetrics ); VECTOR2I bBox( end - pos ); aExtents.push_back( bBox ); @@ -236,7 +246,8 @@ void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition, * @param aAttrs are the styling attributes of the text, including its rotation */ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition, - const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs ) const + const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs, + const METRICS& aFontMetrics ) const { if( !aGal || aText.empty() ) return; @@ -248,7 +259,7 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit std::vector positions; std::vector extents; - getLinePositions( aText, position, strings_list, positions, extents, aAttrs ); + getLinePositions( aText, position, strings_list, positions, extents, aAttrs, aFontMetrics ); aGal->SetLineWidth( aAttrs.m_StrokeWidth ); @@ -256,7 +267,7 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit { drawSingleLineText( aGal, nullptr, strings_list[i], positions[i], aAttrs.m_Size, aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, aAttrs.m_Italic, - aAttrs.m_Underlined ); + aAttrs.m_Underlined, aFontMetrics ); } } @@ -267,7 +278,8 @@ 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 EDA_ANGLE& aAngle, - bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) + bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle, + const METRICS& aFontMetrics ) { VECTOR2I nextPosition = aPosition; bool drawUnderline = false; @@ -307,7 +319,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, aAngle, aMirror, aOrigin, textStyle ); + aSize, aAngle, aMirror, aOrigin, textStyle, aFontMetrics ); } } @@ -315,7 +327,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a { // Shorten the bar a little so its rounded ends don't make it over-long double barTrim = aSize.x * 0.1; - double barOffset = aFont->ComputeUnderlineVerticalPosition( aSize.y ); + double barOffset = aFontMetrics.GetUnderlineVerticalPosition( aSize.y ); VECTOR2D barStart( aPosition.x + barTrim, aPosition.y - barOffset ); VECTOR2D barEnd( nextPosition.x - barTrim, nextPosition.y - barOffset ); @@ -337,7 +349,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a { // Shorten the bar a little so its rounded ends don't make it over-long double barTrim = aSize.x * 0.1; - double barOffset = aFont->ComputeOverbarVerticalPosition( aSize.y ); + double barOffset = aFontMetrics.GetOverbarVerticalPosition( aSize.y ); VECTOR2D barStart( aPosition.x + barTrim, aPosition.y - barOffset ); VECTOR2D barEnd( nextPosition.x - barTrim, nextPosition.y - barOffset ); @@ -362,7 +374,7 @@ 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 + TEXT_STYLE_FLAGS aTextStyle, const METRICS& aFontMetrics ) const { std::lock_guard lock( s_markupCacheMutex ); @@ -381,14 +393,14 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vectorroot ); return ::drawMarkup( aBoundingBox, aGlyphs, markup->root.get(), aPosition, this, aSize, aAngle, - aMirror, aOrigin, aTextStyle ); + aMirror, aOrigin, aTextStyle, aFontMetrics ); } void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, - bool aItalic, bool aUnderline ) const + bool aItalic, bool aUnderline, const METRICS& aFontMetrics ) const { if( !aGal ) return; @@ -404,14 +416,14 @@ void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxSt std::vector> glyphs; (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin, - textStyle ); + textStyle, aFontMetrics ); aGal->DrawGlyphs( glyphs ); } VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSize, int aThickness, - bool aBold, bool aItalic ) const + bool aBold, bool aItalic, const METRICS& aFontMetrics ) const { // TODO do we need to parse every time - have we already parsed? BOX2I boundingBox; @@ -424,7 +436,7 @@ VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSiz textStyle |= TEXT_STYLE::ITALIC; (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, ANGLE_0, false, VECTOR2I(), - textStyle ); + textStyle, aFontMetrics ); if( IsStroke() ) { @@ -442,7 +454,7 @@ VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSiz VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, - bool aItalic ) const + bool aItalic, const METRICS& aFontMetrics ) const { TEXT_STYLE_FLAGS textStyle = 0; @@ -450,7 +462,7 @@ VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText, textStyle |= TEXT_STYLE::ITALIC; VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, ANGLE_0, false, - VECTOR2I(), textStyle ); + VECTOR2I(), textStyle, aFontMetrics ); return extents; } diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index b986ee7725..283b6f282c 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -4,8 +4,6 @@ * Copyright (C) 2021 Ola Rinta-Koski * Copyright (C) 2021-2023 Kicad Developers, see AUTHORS.txt for contributors. * - * Outline font class - * * 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 Free Software Foundation; either version 2 @@ -146,47 +144,18 @@ FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName, int aFaceIndex ) } -/** - * Compute the vertical position of an overbar. This is the distance between the text - * baseline and the overbar. - */ -double OUTLINE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const -{ - // The overbar on actual text is positioned above the bounding box of the glyphs. However, - // that's expensive to calculate so we use an estimation here (as this is only used for - // calculating bounding boxes). - return aGlyphHeight * m_outlineFontSizeCompensation; -} - - -/** - * Compute the vertical position of an underline. This is the distance between the text - * baseline and the underline. - */ -double OUTLINE_FONT::ComputeUnderlineVerticalPosition( double aGlyphHeight ) const -{ - return aGlyphHeight * m_underlineOffsetScaler; -} - - /** * Compute the distance (interline) between 2 lines of text (for multiline texts). This is * the distance between baselines, not the space between line bounding boxes. */ -double OUTLINE_FONT::GetInterline( double aGlyphHeight, double aLineSpacing ) const +double OUTLINE_FONT::GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const { - double pitch = INTERLINE_PITCH_RATIO; + double glyphToFontHeight = 1.0; if( GetFace()->units_per_EM ) - pitch = GetFace()->height / GetFace()->units_per_EM; + glyphToFontHeight = GetFace()->height / GetFace()->units_per_EM; - double interline = aLineSpacing * aGlyphHeight * pitch * m_outlineFontSizeCompensation; - - // FONT TODO this hack is an attempt to fix interline spacing by eyeballing it - static constexpr double interlineHackMultiplier = 1.2; - interline *= interlineHackMultiplier; - - return interline; + return aFontMetrics.GetInterline( aGlyphHeight * glyphToFontHeight ); } @@ -241,7 +210,8 @@ BOX2I OUTLINE_FONT::getBoundingBox( const std::vector>& a void OUTLINE_FONT::GetLinesAsGlyphs( std::vector>* aGlyphs, const wxString& aText, const VECTOR2I& aPosition, - const TEXT_ATTRIBUTES& aAttrs ) const + const TEXT_ATTRIBUTES& aAttrs, + const METRICS& aFontMetrics ) const { wxArrayString strings; std::vector positions; @@ -251,12 +221,12 @@ void OUTLINE_FONT::GetLinesAsGlyphs( std::vector>* aGlyph if( aAttrs.m_Italic ) textStyle |= TEXT_STYLE::ITALIC; - getLinePositions( aText, aPosition, strings, positions, extents, aAttrs ); + getLinePositions( aText, aPosition, strings, positions, extents, aAttrs, aFontMetrics ); for( size_t i = 0; i < strings.GetCount(); i++ ) { (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size, - aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle ); + aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle, aFontMetrics ); } } diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index bd4b53a641..942d89ed75 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -6,8 +6,6 @@ * @author Maciej Suminski * Copyright (C) 2016-2023 Kicad Developers, see AUTHORS.txt for contributors. * - * Stroke font class - * * 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 Free Software Foundation; either version 2 @@ -43,12 +41,6 @@ using namespace KIFONT; -///< Factor that determines relative vertical position of the overbar. -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; - ///< Scale factor for a glyph static constexpr double STROKE_FONT_SCALE = 1.0 / 21.0; @@ -199,23 +191,11 @@ void STROKE_FONT::loadNewStrokeFont( const char* const aNewStrokeFont[], int aNe } -double STROKE_FONT::GetInterline( double aGlyphHeight, double aLineSpacing ) const +double STROKE_FONT::GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const { - // Do not add the glyph thickness to the interline. This makes bold text line-spacing - // different from normal text, which is poor typography. - return ( aGlyphHeight * aLineSpacing * INTERLINE_PITCH_RATIO ); -} + static double LEGACY_FACTOR = 1.0435; // Adjustment to match legacy spacing - -double STROKE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const -{ - return aGlyphHeight * OVERBAR_POSITION_FACTOR; -} - - -double STROKE_FONT::ComputeUnderlineVerticalPosition( double aGlyphHeight ) const -{ - return aGlyphHeight * UNDERLINE_POSITION_FACTOR; + return aFontMetrics.GetInterline( aGlyphHeight ) * LEGACY_FACTOR; } diff --git a/common/font/text_attributes.cpp b/common/font/text_attributes.cpp index 963a66f7d5..392c6b7412 100644 --- a/common/font/text_attributes.cpp +++ b/common/font/text_attributes.cpp @@ -18,7 +18,6 @@ */ #include - #include @@ -68,10 +67,10 @@ int TEXT_ATTRIBUTES::Compare( const TEXT_ATTRIBUTES& aRhs ) const return m_StrokeWidth - aRhs.m_StrokeWidth; if( m_Angle.AsDegrees() != aRhs.m_Angle.AsDegrees() ) - return m_Angle.AsDegrees() - aRhs.m_Angle.AsDegrees(); + return m_Angle.AsDegrees() < aRhs.m_Angle.AsDegrees() ? -1 : 1; if( m_LineSpacing != aRhs.m_LineSpacing ) - return m_LineSpacing - aRhs.m_LineSpacing; + return m_LineSpacing < aRhs.m_LineSpacing ? -1 : 1; if( m_Halign != aRhs.m_Halign ) return m_Halign - aRhs.m_Halign; diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 4f3a724bcc..ef2739894d 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -273,7 +273,7 @@ void GAL::BitmapText( const wxString& aText, const VECTOR2I& aPosition, const ED attrs.m_Size = VECTOR2I( m_attributes.m_Size.x, m_attributes.m_Size.y * 0.95 ); attrs.m_StrokeWidth = GetLineWidth() * 0.74; - font->Draw( this, aText, aPosition, attrs ); + font->Draw( this, aText, aPosition, attrs, KIFONT::METRICS::Default() ); } diff --git a/common/gr_text.cpp b/common/gr_text.cpp index 16e2a2b12d..c90a5711d2 100644 --- a/common/gr_text.cpp +++ b/common/gr_text.cpp @@ -110,13 +110,14 @@ int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict ) } -int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize, - int aThickness, bool aBold, bool aItalic ) +int GRTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize, + int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS& aFontMetrics ) { if( !aFont ) aFont = KIFONT::FONT::GetFont(); - return KiROUND( aFont->StringBoundaryLimits( aText, aSize, aThickness, aBold, aItalic ).x ); + return KiROUND( aFont->StringBoundaryLimits( aText, aSize, aThickness, aBold, aItalic, + aFontMetrics ).x ); } @@ -141,7 +142,8 @@ int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText, const EDA_ANGLE& aOrient, const VECTOR2I& aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont ) + int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics ) { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; bool fill_mode = true; @@ -182,7 +184,7 @@ void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const COLOR4D& aColor, const attributes.m_Valign = aV_justify; attributes.m_Size = aSize; - aFont->Draw( &callback_gal, aText, aPos, attributes ); + aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); } diff --git a/common/plotters/DXF_plotter.cpp b/common/plotters/DXF_plotter.cpp index cf2072417c..dc8e4adff9 100644 --- a/common/plotters/DXF_plotter.cpp +++ b/common/plotters/DXF_plotter.cpp @@ -863,19 +863,20 @@ bool containsNonAsciiChars( const wxString& string ) } -void DXF_PLOTTER::Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData ) +void DXF_PLOTTER::Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { // Fix me: see how to use DXF text mode for multiline texts if( aMultilineAllowed && !aText.Contains( wxT( "\n" ) ) ) @@ -889,7 +890,7 @@ void DXF_PLOTTER::Text( const VECTOR2I& aPos, // Perhaps multiline texts could be handled as DXF text entity // but I do not want spend time about this (JPC) PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, - aBold, aMultilineAllowed, aFont, aData ); + aBold, aMultilineAllowed, aFont, aFontMetrics, aData ); } else { @@ -907,11 +908,13 @@ void DXF_PLOTTER::Text( const VECTOR2I& aPos, } -void DXF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData ) +void DXF_PLOTTER::PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { TEXT_ATTRIBUTES attrs = aAttributes; // Fix me: see how to use DXF text mode for multiline texts @@ -925,15 +928,16 @@ void DXF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, // output text as graphics. // Perhaps multiline texts could be handled as DXF text entity // but I do not want spend time about that (JPC) - PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData ); + PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData ); } else - plotOneLineOfText( aPos, aColor, aText, attrs ); + { + plotOneLineOfText( aPos, aColor, aText, attrs ); + } } void DXF_PLOTTER::plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes ) + const wxString& aText, const TEXT_ATTRIBUTES& aAttributes ) { /* Emit text as a text entity. This loses formatting and shape but it's more useful as a CAD object */ @@ -989,9 +993,9 @@ void DXF_PLOTTER::plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor "%d\n" // H alignment " 73\n" "%d\n", // V alignment - aAttributes.m_Bold ? - (aAttributes.m_Italic ? "KICADBI" : "KICADB") - : (aAttributes.m_Italic ? "KICADI" : "KICAD"), TO_UTF8( cname ), + aAttributes.m_Bold ? ( aAttributes.m_Italic ? "KICADBI" : "KICADB" ) + : ( aAttributes.m_Italic ? "KICADI" : "KICAD" ), + TO_UTF8( cname ), formatCoord( origin_dev.x ).c_str(), formatCoord( origin_dev.x ).c_str(), formatCoord( origin_dev.y ).c_str(), formatCoord( origin_dev.y ).c_str(), formatCoord( size_dev.y ).c_str(), formatCoord( fabs( size_dev.x / size_dev.y ) ).c_str(), diff --git a/common/plotters/GERBER_plotter.cpp b/common/plotters/GERBER_plotter.cpp index d82f5480f5..76f4d522ff 100644 --- a/common/plotters/GERBER_plotter.cpp +++ b/common/plotters/GERBER_plotter.cpp @@ -1976,19 +1976,20 @@ void GERBER_PLOTTER::FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiamet } -void GERBER_PLOTTER::Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData ) +void GERBER_PLOTTER::Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { GBR_METADATA* gbr_metadata = static_cast( aData ); @@ -1996,22 +1997,24 @@ void GERBER_PLOTTER::Text( const VECTOR2I& aPos, formatNetAttribute( &gbr_metadata->m_NetlistMetadata ); PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, - aItalic, aBold, aMultilineAllowed, aFont, aData ); + aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics, aData ); } -void GERBER_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData ) +void GERBER_PLOTTER::PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { GBR_METADATA* gbr_metadata = static_cast( aData ); if( gbr_metadata ) formatNetAttribute( &gbr_metadata->m_NetlistMetadata ); - PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData ); + PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData ); } void GERBER_PLOTTER::SetLayerPolarity( bool aPositive ) diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index f5965e7f2e..8a38165aa2 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -1551,19 +1551,20 @@ function ShM(aEntries) { } -void PDF_PLOTTER::Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData ) +void PDF_PLOTTER::Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { // PDF files do not like 0 sized texts which create broken files. if( aSize.x == 0 || aSize.y == 0 ) @@ -1596,7 +1597,8 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos, if( !aFont ) aFont = KIFONT::FONT::GetFont(); - VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic ) ); + VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic, + aFontMetrics ) ); VECTOR2I box_x( full_box.x, 0 ); VECTOR2I box_y( 0, full_box.y ); @@ -1623,7 +1625,8 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos, // Extract the changed width and rotate by the orientation to get the offset for the // next word - VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth, aBold, aItalic ).x, 0 ); + VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth, + aBold, aItalic, aFontMetrics ).x, 0 ); RotatePoint( bbox, aOrient ); pos += bbox; @@ -1647,15 +1650,17 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos, // Plot the stroked text (if requested) PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, - aBold, aMultilineAllowed, aFont ); + aBold, aMultilineAllowed, aFont, aFontMetrics ); } -void PDF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData ) +void PDF_PLOTTER::PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { VECTOR2I size = aAttributes.m_Size; @@ -1666,12 +1671,9 @@ void PDF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, if( aAttributes.m_Mirrored ) size.x = -size.x; - PDF_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, - aAttributes.m_Halign, aAttributes.m_Valign, - aAttributes.m_StrokeWidth, - aAttributes.m_Italic, aAttributes.m_Bold, - aAttributes.m_Multiline, - aFont, aData ); + PDF_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, aAttributes.m_Halign, + aAttributes.m_Valign, aAttributes.m_StrokeWidth, aAttributes.m_Italic, + aAttributes.m_Bold, aAttributes.m_Multiline, aFont, aFontMetrics, aData ); } diff --git a/common/plotters/PS_plotter.cpp b/common/plotters/PS_plotter.cpp index 0a4fa8a38b..410f9fa76f 100644 --- a/common/plotters/PS_plotter.cpp +++ b/common/plotters/PS_plotter.cpp @@ -333,15 +333,11 @@ int PSLIKE_PLOTTER::returnPostscriptTextWidth( const wxString& aText, int aXSize : ( aItalic ? hvo_widths : hv_widths ); double tally = 0; - for( unsigned i = 0; i < aText.length(); i++ ) + for( wchar_t asciiCode : aText) { - wchar_t AsciiCode = aText[i]; - // Skip the negation marks and untabled points. - if( AsciiCode != '~' && AsciiCode < 256 ) - { - tally += width_table[AsciiCode]; - } + if( asciiCode != '~' && asciiCode < 256 ) + tally += width_table[asciiCode]; } // Widths are proportional to height, but height is enlarged by a scaling factor. @@ -349,38 +345,6 @@ int PSLIKE_PLOTTER::returnPostscriptTextWidth( const wxString& aText, int aXSize } -void PSLIKE_PLOTTER::postscriptOverlinePositions( const wxString& aText, int aXSize, - bool aItalic, bool aBold, - std::vector *pos_pairs ) -{ - /* XXX This function is *too* similar to returnPostscriptTextWidth. - Consider merging them... */ - const double *width_table = aBold ? ( aItalic ? hvbo_widths : hvb_widths ) - : ( aItalic ? hvo_widths : hv_widths ); - double tally = 0; - - for( unsigned i = 0; i < aText.length(); i++ ) - { - wchar_t AsciiCode = aText[i]; - - // Skip the negation marks and untabled points - if( AsciiCode != '~' && AsciiCode < 256 ) - { - tally += width_table[AsciiCode]; - } - else - { - if( AsciiCode == '~' ) - pos_pairs->push_back( KiROUND( aXSize * tally / postscriptTextAscent ) ); - } - } - - // Special rule: we have to complete the last bar if the ~ aren't matched - if( pos_pairs->size() % 2 == 1 ) - pos_pairs->push_back( KiROUND( aXSize * tally / postscriptTextAscent ) ); -} - - void PS_PLOTTER::SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil, double aScale, bool aMirror ) { @@ -937,19 +901,20 @@ bool PS_PLOTTER::EndPlot() -void PS_PLOTTER::Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData ) +void PS_PLOTTER::Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { SetCurrentLineWidth( aWidth ); SetColor( aColor ); @@ -963,16 +928,17 @@ void PS_PLOTTER::Text( const VECTOR2I& aPos, } PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, - aBold, aMultilineAllowed, aFont, aData ); + aBold, aMultilineAllowed, aFont, aFontMetrics, aData ); } -void PS_PLOTTER::PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData ) +void PS_PLOTTER::PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { SetCurrentLineWidth( aAttributes.m_StrokeWidth ); SetColor( aColor ); @@ -985,7 +951,7 @@ void PS_PLOTTER::PlotText( const VECTOR2I& aPos, fprintf( m_outputFile, "%s %g %g phantomshow\n", ps_test.c_str(), pos_dev.x, pos_dev.y ); } - PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData ); + PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData ); } diff --git a/common/plotters/SVG_plotter.cpp b/common/plotters/SVG_plotter.cpp index 311ff404af..bd7ffd0f37 100644 --- a/common/plotters/SVG_plotter.cpp +++ b/common/plotters/SVG_plotter.cpp @@ -169,7 +169,6 @@ SVG_PLOTTER::SVG_PLOTTER() m_brush_rgb_color = 0; // current color value (black) m_brush_alpha = 1.0; m_dashed = PLOT_DASH_TYPE::SOLID; - m_useInch = false; // millimeters are always the svg unit m_precision = 4; // default: 4 digits in mantissa. } @@ -778,19 +777,20 @@ bool SVG_PLOTTER::EndPlot() } -void SVG_PLOTTER::Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData ) +void SVG_PLOTTER::Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { setFillMode( FILL_T::NO_FILL ); SetColor( aColor ); @@ -817,7 +817,7 @@ void SVG_PLOTTER::Text( const VECTOR2I& aPos, // aSize.x or aSize.y is < 0 for mirrored texts. // The actual text size value is the absolute value - text_size.x = std::abs( GraphicTextWidth( aText, aFont, aSize, aWidth, aBold, aItalic ) ); + text_size.x = std::abs( GRTextWidth( aText, aFont, aSize, aWidth, aBold, aItalic, aFontMetrics ) ); text_size.y = std::abs( aSize.x * 4/3 ); // Hershey font height to em size conversion VECTOR2D anchor_pos_dev = userToDeviceCoordinates( aPos ); VECTOR2D text_pos_dev = userToDeviceCoordinates( text_pos ); @@ -849,27 +849,26 @@ void SVG_PLOTTER::Text( const VECTOR2I& aPos, TO_UTF8( XmlEsc( aText ) ) ); PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, - aBold, aMultilineAllowed, aFont ); + aBold, aMultilineAllowed, aFont, aFontMetrics ); fputs( "", m_outputFile ); } -void SVG_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData ) +void SVG_PLOTTER::PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { VECTOR2I size = aAttributes.m_Size; if( aAttributes.m_Mirrored ) size.x = -size.x; - SVG_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, - aAttributes.m_Halign, aAttributes.m_Valign, - aAttributes.m_StrokeWidth, - aAttributes.m_Italic, aAttributes.m_Bold, - aAttributes.m_Multiline, - aFont, aData ); + SVG_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, aAttributes.m_Halign, + aAttributes.m_Valign, aAttributes.m_StrokeWidth, aAttributes.m_Italic, + aAttributes.m_Bold, aAttributes.m_Multiline, aFont, aFontMetrics, aData ); } diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp index c6a3bc7133..1d54025f3c 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -153,7 +153,7 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL plotter->Text( text->GetTextPos(), color, text->GetShownText( true ), text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(), - text->IsMultilineAllowed(), font ); + text->IsMultilineAllowed(), font, text->GetFontMetrics() ); } break; diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 43c5d50dbe..bb6f2d3d10 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -712,19 +712,20 @@ void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int a } -void PLOTTER::Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aPenWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData ) +void PLOTTER::Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aPenWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; @@ -770,14 +771,16 @@ void PLOTTER::Text( const VECTOR2I& aPos, if( !aFont ) aFont = KIFONT::FONT::GetFont(); - aFont->Draw( &callback_gal, aText, aPos, attributes ); + aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); } -void PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData ) +void PLOTTER::PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData ) { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; @@ -812,5 +815,5 @@ void PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor, if( !aFont ) aFont = KIFONT::FONT::GetFont(); - aFont->Draw( &callback_gal, aText, aPos, attributes ); + aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); } diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index bca6a8fd33..649d39f500 100644 --- a/common/preview_items/preview_utils.cpp +++ b/common/preview_items/preview_utils.cpp @@ -187,6 +187,6 @@ void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& a for( const wxString& str : aStrings ) { textPos.y += textDims.LinePitch; - font->Draw( gal, str, textPos, textAttrs ); + font->Draw( gal, str, textPos, textAttrs, KIFONT::METRICS::Default() ); } } diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp index 0a0b77fa93..936f52cca7 100644 --- a/common/preview_items/ruler_item.cpp +++ b/common/preview_items/ruler_item.cpp @@ -248,7 +248,7 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT if( drawLabel ) { wxString label = DimensionLabel( "", tickSpace * i, aIuScale, aUnits, false ); - font->Draw( gal, label, tickPos + labelOffset, labelAttrs ); + font->Draw( gal, label, tickPos + labelOffset, labelAttrs, KIFONT::METRICS::Default() ); } } } diff --git a/eeschema/dialogs/panel_setup_formatting.cpp b/eeschema/dialogs/panel_setup_formatting.cpp index d4000cfd26..0052b46a09 100644 --- a/eeschema/dialogs/panel_setup_formatting.cpp +++ b/eeschema/dialogs/panel_setup_formatting.cpp @@ -110,6 +110,7 @@ bool PANEL_SETUP_FORMATTING::TransferDataToWindow() ctrl->SetValue( EDA_UNIT_UTILS::UI::StringFromValue( unityScale, units, value ) ) SET_VALUE( m_textOffsetRatioCtrl, EDA_UNITS::PERCENT, settings.m_TextOffsetRatio * 100.0 ); + SET_VALUE( m_overbarHeightCtrl, EDA_UNITS::PERCENT, settings.m_FontMetrics.m_OverbarHeight * 100.0 ); SET_VALUE( m_dashLengthCtrl, EDA_UNITS::UNSCALED, settings.m_DashedLineDashRatio ); SET_VALUE( m_gapLengthCtrl, EDA_UNITS::UNSCALED, settings.m_DashedLineGapRatio ); SET_VALUE( m_labelSizeRatioCtrl, EDA_UNITS::PERCENT, settings.m_LabelSizeRatio * 100.0 ); @@ -166,6 +167,7 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() #define GET_VALUE( units, str ) EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, units, str ) settings.m_TextOffsetRatio = GET_VALUE( EDA_UNITS::PERCENT, m_textOffsetRatioCtrl->GetValue() ) / 100.0; + settings.m_FontMetrics.m_OverbarHeight = GET_VALUE( EDA_UNITS::PERCENT, m_overbarHeightCtrl->GetValue() ) / 100.0; settings.m_DashedLineDashRatio = GET_VALUE( EDA_UNITS::UNSCALED, m_dashLengthCtrl->GetValue() ); settings.m_DashedLineGapRatio = GET_VALUE( EDA_UNITS::UNSCALED, m_gapLengthCtrl->GetValue() ); settings.m_LabelSizeRatio = GET_VALUE( EDA_UNITS::PERCENT, m_labelSizeRatioCtrl->GetValue() ) / 100.0; diff --git a/eeschema/dialogs/panel_setup_formatting_base.cpp b/eeschema/dialogs/panel_setup_formatting_base.cpp index 3a7cd89a6f..be1b879cba 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.cpp +++ b/eeschema/dialogs/panel_setup_formatting_base.cpp @@ -63,6 +63,17 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi m_textSizeUnits->Wrap( -1 ); fgSizer2->Add( m_textSizeUnits, 0, wxALIGN_CENTER_VERTICAL|wxFIXED_MINSIZE, 5 ); + m_overbarHieghtLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Overbar offset ratio:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_overbarHieghtLabel->Wrap( -1 ); + fgSizer2->Add( m_overbarHieghtLabel, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + m_overbarHeightCtrl = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer2->Add( m_overbarHeightCtrl, 0, wxEXPAND, 5 ); + + m_overbarHeightUnits = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("%"), wxDefaultPosition, wxDefaultSize, 0 ); + m_overbarHeightUnits->Wrap( -1 ); + fgSizer2->Add( m_overbarHeightUnits, 0, wxALIGN_CENTER_VERTICAL, 5 ); + m_textOffsetRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Label offset ratio:"), wxDefaultPosition, wxDefaultSize, 0 ); m_textOffsetRatioLabel->Wrap( -1 ); m_textOffsetRatioLabel->SetToolTip( _("Percentage of the text size to offset labels above (or below) a wire, bus, or pin") ); @@ -78,7 +89,7 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi m_offsetRatioUnits->Wrap( -1 ); fgSizer2->Add( m_offsetRatioUnits, 0, wxALIGN_CENTER_VERTICAL|wxFIXED_MINSIZE, 5 ); - m_labelSizeRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Global label margin:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_labelSizeRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Global label margin ratio:"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelSizeRatioLabel->Wrap( -1 ); m_labelSizeRatioLabel->SetToolTip( _("Percentage of the text size to use as space around a global label") ); diff --git a/eeschema/dialogs/panel_setup_formatting_base.fbp b/eeschema/dialogs/panel_setup_formatting_base.fbp index f301a08602..72b9bc8a05 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.fbp +++ b/eeschema/dialogs/panel_setup_formatting_base.fbp @@ -430,6 +430,192 @@ -1 + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Overbar offset ratio: + 0 + + 0 + + + 0 + + 1 + m_overbarHieghtLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_overbarHeightCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + % + 0 + + 0 + + + 0 + + 1 + m_overbarHeightUnits + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + 5 wxALIGN_CENTER_VERTICAL @@ -648,7 +834,7 @@ 0 0 wxID_ANY - Global label margin: + Global label margin ratio: 0 0 diff --git a/eeschema/dialogs/panel_setup_formatting_base.h b/eeschema/dialogs/panel_setup_formatting_base.h index 479a433846..e9f1e6ef83 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.h +++ b/eeschema/dialogs/panel_setup_formatting_base.h @@ -45,6 +45,9 @@ class PANEL_SETUP_FORMATTING_BASE : public wxPanel wxStaticText* m_textSizeLabel; wxTextCtrl* m_textSizeCtrl; wxStaticText* m_textSizeUnits; + wxStaticText* m_overbarHieghtLabel; + wxTextCtrl* m_overbarHeightCtrl; + wxStaticText* m_overbarHeightUnits; wxStaticText* m_textOffsetRatioLabel; wxTextCtrl* m_textOffsetRatioCtrl; wxStaticText* m_offsetRatioUnits; diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 56664cd6f1..1c0fbf9744 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -155,7 +155,7 @@ void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); GRPrintText( DC, text_pos, color, text, GetTextAngle(), GetTextSize(), GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), font ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), font, GetFontMetrics() ); } @@ -402,7 +402,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs attrs.m_Angle = orient; attrs.m_Multiline = false; - aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font ); + aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() ); } diff --git a/eeschema/lib_item.cpp b/eeschema/lib_item.cpp index 56e269791b..6f3cb94fc1 100644 --- a/eeschema/lib_item.cpp +++ b/eeschema/lib_item.cpp @@ -137,6 +137,12 @@ const wxString& LIB_ITEM::GetDefaultFont() const } +const KIFONT::METRICS& LIB_ITEM::GetFontMetrics() const +{ + return KIFONT::METRICS::Default(); +} + + void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData, const TRANSFORM& aTransform, bool aDimmed ) { diff --git a/eeschema/lib_item.h b/eeschema/lib_item.h index 957e8a240d..9fada1c6f7 100644 --- a/eeschema/lib_item.h +++ b/eeschema/lib_item.h @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-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 @@ -38,6 +38,13 @@ class PLOTTER; class LIB_PIN; class MSG_PANEL_ITEM; +namespace KIFONT +{ +class FONT; +class METRICS; +} + + using KIGFX::RENDER_SETTINGS; extern const int fill_tab[]; @@ -172,6 +179,8 @@ public: const wxString& GetDefaultFont() const; + const KIFONT::METRICS& GetFontMetrics() const; + virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const { // For historical reasons, a stored value of 0 means "default width" and negative diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 409e1f406e..85cc062922 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -448,14 +448,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos x = x1 + aTextInside; GRPrintText( DC, VECTOR2I( x, y1 ), nameColor, name, ANGLE_HORIZONTAL, pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, - namePenWidth, false, false, font ); + namePenWidth, false, false, font, GetFontMetrics() ); } else // Orient == PIN_LEFT { x = x1 - aTextInside; GRPrintText( DC, VECTOR2I( x, y1 ), nameColor, name, ANGLE_HORIZONTAL, pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, - namePenWidth, false, false, font ); + namePenWidth, false, false, font, GetFontMetrics() ); } } @@ -463,7 +463,8 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos { GRPrintText( DC, VECTOR2I(( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor, number, ANGLE_HORIZONTAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font ); + GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font, + GetFontMetrics() ); } } else /* Its a vertical line. */ @@ -477,14 +478,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos { GRPrintText( DC, VECTOR2I( x1, y ), nameColor, name, ANGLE_VERTICAL, pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, - namePenWidth, false, false, font ); + namePenWidth, false, false, font, GetFontMetrics() ); } if( aDrawPinNum ) { GRPrintText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor, number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font ); + GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font, + GetFontMetrics() ); } } else /* PIN_UP */ @@ -495,14 +497,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos { GRPrintText( DC, VECTOR2I( x1, y ), nameColor, name, ANGLE_VERTICAL, pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, - namePenWidth, false, false, font ); + namePenWidth, false, false, font, GetFontMetrics() ); } if( aDrawPinNum ) { GRPrintText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor, number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font ); + GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font, + GetFontMetrics() ); } } } @@ -518,14 +521,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos x = ( x1 + aPinPos.x ) / 2; GRPrintText( DC, VECTOR2I( x, y1 - name_offset ), nameColor, name, ANGLE_HORIZONTAL, pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, - namePenWidth, false, false, font ); + namePenWidth, false, false, font, GetFontMetrics() ); } if( aDrawPinNum ) { x = ( x1 + aPinPos.x ) / 2; GRPrintText( DC, VECTOR2I( x, y1 + num_offset ), numColor, number, ANGLE_HORIZONTAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, - numPenWidth, false, false, font ); + numPenWidth, false, false, font, GetFontMetrics() ); } } else /* Its a vertical line. */ @@ -535,14 +538,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos y = ( y1 + aPinPos.y) / 2; GRPrintText( DC, VECTOR2I( x1 - name_offset, y ), nameColor, name, ANGLE_VERTICAL, pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, - namePenWidth, false, false, font ); + namePenWidth, false, false, font, GetFontMetrics() ); } if( aDrawPinNum ) { GRPrintText( DC, VECTOR2I( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), numColor, number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_TOP, numPenWidth, false, false, font ); + GR_TEXT_V_ALIGN_TOP, numPenWidth, false, false, font, GetFontMetrics() ); } } } @@ -612,7 +615,7 @@ void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECT } GRPrintText( DC, txtpos, color, typeName, orient, VECTOR2I( textSize, textSize ), hjustify, - GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font ); + GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font, GetFontMetrics() ); } @@ -826,7 +829,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIE attrs.m_Valign = vJustify; attrs.m_Multiline = false; - aPlotter->PlotText( VECTOR2I( px, py ), color, text, attrs, font ); + aPlotter->PlotText( VECTOR2I( px, py ), color, text, attrs, font, GetFontMetrics() ); }; /* Draw the text inside, but the pin numbers outside. */ @@ -1231,8 +1234,10 @@ void LIB_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxStri VECTOR2D fontSize( aSize, aSize ); int penWidth = GetPenSizeForNormal( aSize ); - aCache->m_Extents.x = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false ).x; - aCache->m_Extents.y = aFont->StringBoundaryLimits( hText, fontSize, penWidth, false, false ).y; + aCache->m_Extents.x = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false, + GetFontMetrics() ).x; + aCache->m_Extents.y = aFont->StringBoundaryLimits( hText, fontSize, penWidth, false, false, + GetFontMetrics() ).y; } @@ -1293,7 +1298,8 @@ const BOX2I LIB_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNa double stroke = fontSize / 8.0; VECTOR2I typeTextSize = font->StringBoundaryLimits( GetElectricalTypeName(), VECTOR2D( fontSize, fontSize ), - KiROUND( stroke ), false, false ); + KiROUND( stroke ), false, false, + GetFontMetrics() ); typeTextLength = typeTextSize.x + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + TARGET_PIN_RADIUS; minsizeV = std::max( minsizeV, typeTextSize.y / 2 ); @@ -1313,7 +1319,7 @@ const BOX2I LIB_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNa // pin name is inside the body (or invisible) // pin number is above the line begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_OFFSET ); - begin.x = std::min( -typeTextLength, m_length - ( numberTextLength / 2) ); + begin.x = std::min( -typeTextLength, m_length - ( numberTextLength / 2 ) ); end.x = m_length + nameTextLength; end.y = std::min( -minsizeV, -nameTextHeight / 2 ); diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 2a5ca15fde..ab9878c985 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -327,7 +327,7 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset, attrs.m_StrokeWidth = penWidth; attrs.m_Angle = t1 ? ANGLE_HORIZONTAL : ANGLE_VERTICAL; - plotter->PlotText( pos, color, GetText(), attrs, font ); + plotter->PlotText( pos, color, GetText(), attrs, font, GetFontMetrics() ); } @@ -411,7 +411,7 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, GRPrintText( DC, txtpos, color, GetShownText( true ), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), - font ); + font, GetFontMetrics() ); } diff --git a/eeschema/lib_textbox.cpp b/eeschema/lib_textbox.cpp index e62bb0de34..d162cd7257 100644 --- a/eeschema/lib_textbox.cpp +++ b/eeschema/lib_textbox.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-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 @@ -323,7 +323,7 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs GRPrintText( DC, text.GetDrawPos(), color, text.GetShownText( true ), text.GetTextAngle(), text.GetTextSize(), text.GetHorizJustify(), text.GetVertJustify(), penWidth, - text.IsItalic(), text.IsBold(), font ); + text.IsItalic(), text.IsBold(), font, GetFontMetrics() ); } @@ -472,7 +472,8 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) { - aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font ); + aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font, + GetFontMetrics() ); } } diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 83681f0626..1d4ea34468 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -310,7 +310,8 @@ SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forP { m_renderCache.clear(); - outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs ); + outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs, + GetFontMetrics() ); m_renderCachePos = forPosition; m_renderCacheValid = true; @@ -402,7 +403,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset GRPrintText( DC, textpos, color, GetShownText( true ), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), - font ); + font, GetFontMetrics() ); } @@ -1204,7 +1205,7 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const attrs.m_Angle = orient; attrs.m_Multiline = false; - aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font ); + aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() ); if( IsHypertext() ) { diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 28593d6a65..4511c98153 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -270,6 +270,8 @@ public: protected: KIFONT::FONT* getDrawFont() const override; + const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } + private: int m_id; ///< Field index, @see enum MANDATORY_FIELD_T diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index 97a8b406f4..f9b97bf7d5 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-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 @@ -323,6 +323,15 @@ const wxString& SCH_ITEM::GetDefaultFont() const } +const KIFONT::METRICS& SCH_ITEM::GetFontMetrics() const +{ + if( SCHEMATIC* schematic = Schematic() ) + return schematic->Settings().m_FontMetrics; + + return KIFONT::METRICS::Default(); +} + + bool SCH_ITEM::RenderAsBitmap( double aWorldScale ) const { if( IsHypertext() ) diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 9cee36c092..3e44f721dd 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-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 @@ -42,12 +42,15 @@ class SCH_SHEET_PATH; class SCHEMATIC; class LINE_READER; class SCH_EDIT_FRAME; -class wxFindReplaceData; class PLOTTER; -class NETLIST_OBJECT; class NETLIST_OBJECT_LIST; class PLOTTER; +namespace KIFONT +{ +class METRICS; +} + using KIGFX::RENDER_SETTINGS; @@ -272,6 +275,8 @@ public: const wxString& GetDefaultFont() const; + const KIFONT::METRICS& GetFontMetrics() const; + bool RenderAsBitmap( double aWorldScale ) const override; /** diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 0a984d378d..e7f800b088 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -1074,7 +1074,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const } else { - aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font ); + aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() ); if( s_poly.size() ) aPlotter->PlotPoly( s_poly, FILL_T::NO_FILL, penWidth ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index bd619bf506..2e520c7b1c 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -607,7 +607,7 @@ static bool isFieldsLayer( int aLayer ) void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs ) + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ) { KIFONT::FONT* font = aAttrs.m_Font; @@ -620,7 +620,7 @@ void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, m_gal->SetIsFill( font->IsOutline() ); m_gal->SetIsStroke( font->IsStroke() ); - font->Draw( m_gal, aText, aPosition, aAttrs ); + font->Draw( m_gal, aText, aPosition, aAttrs, aFontMetrics ); } @@ -640,7 +640,7 @@ void SCH_PAINTER::bitmapText( const wxString& aText, const VECTOR2D& aPosition, void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs ) + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ) { TEXT_ATTRIBUTES attrs( aAttrs ); KIFONT::FONT* font = aAttrs.m_Font; @@ -664,7 +664,7 @@ void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition callback_gal.SetIsFill( false ); callback_gal.SetIsStroke( true ); callback_gal.SetLineWidth( (float) attrs.m_StrokeWidth ); - font->Draw( &callback_gal, aText, aPosition, attrs ); + font->Draw( &callback_gal, aText, aPosition, attrs, aFontMetrics ); BOX2I bbox = knockouts.BBox( attrs.m_StrokeWidth * 2 ); SHAPE_POLY_SET finalPoly; @@ -686,7 +686,7 @@ void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs ) + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ) { KIFONT::FONT* font = aAttrs.m_Font; @@ -697,7 +697,7 @@ void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, } VECTOR2I extents = font->StringBoundaryLimits( aText, aAttrs.m_Size, aAttrs.m_StrokeWidth, - aAttrs.m_Bold, aAttrs.m_Italic ); + aAttrs.m_Bold, aAttrs.m_Italic, aFontMetrics ); BOX2I box( aPosition, VECTOR2I( extents.x, aAttrs.m_Size.y ) ); switch( aAttrs.m_Halign ) @@ -1078,7 +1078,8 @@ void SCH_PAINTER::draw( const LIB_FIELD* aField, int aLayer, bool aDimmed ) if( drawingShadows ) attrs.m_StrokeWidth += getShadowWidth( !aField->IsSelected() ); - strokeText( UnescapeString( aField->GetShownText( true ) ), textpos, attrs ); + strokeText( UnescapeString( aField->GetShownText( true ) ), textpos, attrs, + aField->GetFontMetrics() ); } // Draw the umbilical line when in the schematic editor @@ -1174,7 +1175,7 @@ void SCH_PAINTER::draw( const LIB_TEXT* aText, int aLayer, bool aDimmed ) // vertically centered. attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER; - strokeText( shownText, pos, attrs ); + strokeText( shownText, pos, attrs, aText->GetFontMetrics() ); } } @@ -1205,7 +1206,7 @@ void SCH_PAINTER::draw( const LIB_TEXTBOX* aTextBox, int aLayer, bool aDimmed ) attrs.m_Angle = aTextBox->GetDrawRotation(); attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) ); - strokeText( shownText, aTextBox->GetDrawPos(), attrs ); + strokeText( shownText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() ); }; m_gal->SetStrokeColor( color ); @@ -1417,7 +1418,7 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize ); attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_CURRENTS ); - knockoutText( aPin->GetOperatingPoint(), mid, attrs ); + knockoutText( aPin->GetOperatingPoint(), mid, attrs, aPin->GetFontMetrics() ); } } @@ -1694,11 +1695,11 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) if( drawingShadows && !attrs.m_Font->IsOutline() ) { - strokeText( text[i], aPos, attrs ); + strokeText( text[i], aPos, attrs, aPin->GetFontMetrics() ); } else if( drawingShadows ) { - boxText( text[i], aPos, attrs ); + boxText( text[i], aPos, attrs, aPin->GetFontMetrics() ); } else if( nonCached( aPin ) && renderTextAsBitmap ) { @@ -1707,7 +1708,7 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) } else { - strokeText( text[i], aPos, attrs ); + strokeText( text[i], aPos, attrs, aPin->GetFontMetrics() ); const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); } }; @@ -1931,7 +1932,7 @@ void SCH_PAINTER::draw( const SCH_LINE* aLine, int aLayer ) attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize ); attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_VOLTAGES ); - knockoutText( aLine->GetOperatingPoint(), pos, attrs ); + knockoutText( aLine->GetOperatingPoint(), pos, attrs, aLine->GetFontMetrics() ); } if( drawingOP ) @@ -2168,7 +2169,7 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer ) 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 ); + strokeText( shownText, aText->GetDrawPos() + text_offset, attrs, aText->GetFontMetrics() ); } else if( drawingShadows ) @@ -2224,7 +2225,8 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer ) } else { - strokeText( shownText, aText->GetDrawPos() + text_offset, attrs ); + strokeText( shownText, aText->GetDrawPos() + text_offset, attrs, + aText->GetFontMetrics() ); } const_cast( aText )->ClearFlags( IS_SHOWN_AS_BITMAP ); @@ -2268,7 +2270,7 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer ) } else { - strokeText( shownText, aTextBox->GetDrawPos(), attrs ); + strokeText( shownText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() ); } }; @@ -2653,7 +2655,7 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed ) } else { - strokeText( shownText, textpos, attributes ); + strokeText( shownText, textpos, attributes, aField->GetFontMetrics() ); } const_cast( aField )->ClearFlags( IS_SHOWN_AS_BITMAP ); diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 6549fedca2..1a3896ea25 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -195,13 +195,13 @@ private: void triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); void strokeText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttributes ); + const TEXT_ATTRIBUTES& aAttributes, const KIFONT::METRICS& aFontMetrics ); void bitmapText( const wxString& aText, const VECTOR2D& aPosition, const TEXT_ATTRIBUTES& aAttributes ); void knockoutText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs ); + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ); void boxText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs ); + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ); wxString expandLibItemTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 35971a45e0..f2a56a1167 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -488,7 +488,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const { VECTOR2I textpos = positions[ii] + text_offset; wxString& txt = strings_list.Item( ii ); - aPlotter->PlotText( textpos, color, txt, attrs, font ); + aPlotter->PlotText( textpos, color, txt, attrs, font, GetFontMetrics() ); } if( HasHyperlink() ) diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 6b811f6b6a..b08b55f887 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -233,6 +233,8 @@ public: protected: KIFONT::FONT* getDrawFont() const override; + const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } + protected: /** * The orientation of text and any associated drawing elements of derived objects. diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index fdf70958fe..a2a1a42e88 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-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 @@ -431,7 +431,8 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) { - aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font ); + aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font, + GetFontMetrics() ); } if( HasHyperlink() ) diff --git a/eeschema/sch_textbox.h b/eeschema/sch_textbox.h index ae8e4d74bf..58062b78d2 100644 --- a/eeschema/sch_textbox.h +++ b/eeschema/sch_textbox.h @@ -123,6 +123,8 @@ public: protected: KIFONT::FONT* getDrawFont() const override; + const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } + protected: bool m_excludeFromSim; }; diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index 1d327c6ce0..1c9c87b5e7 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -132,6 +132,9 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_params.emplace_back( new PARAM( "drawing.label_size_ratio", &m_LabelSizeRatio, DEFAULT_LABEL_SIZE_RATIO, 0.0, 2.0 ) ); + m_params.emplace_back( new PARAM( "drawing.overbar_offset_ratio", + &m_FontMetrics.m_OverbarHeight, m_FontMetrics.m_OverbarHeight ) ); + m_params.emplace_back( new PARAM_SCALED( "drawing.pin_symbol_size", &m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ), schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) ); @@ -188,15 +191,15 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names ); }, {} ) ); - m_params.emplace_back( - new PARAM( "bom_settings", &m_BomSettings, BOM_PRESET::GroupedByValue() ) ); - m_params.emplace_back( - new PARAM_LIST( "bom_presets", &m_BomPresets, {} ) ); + m_params.emplace_back( new PARAM( "bom_settings", + &m_BomSettings, BOM_PRESET::GroupedByValue() ) ); + m_params.emplace_back( new PARAM_LIST( "bom_presets", + &m_BomPresets, {} ) ); - m_params.emplace_back( - new PARAM( "bom_fmt_settings", &m_BomFmtSettings, BOM_FMT_PRESET::CSV() ) ); - m_params.emplace_back( - new PARAM_LIST( "bom_fmt_presets", &m_BomFmtPresets, {} ) ); + m_params.emplace_back( new PARAM( "bom_fmt_settings", + &m_BomFmtSettings, BOM_FMT_PRESET::CSV() ) ); + m_params.emplace_back( new PARAM_LIST( "bom_fmt_presets", + &m_BomFmtPresets, {} ) ); m_params.emplace_back( new PARAM( "page_layout_descr_file", &m_SchDrawingSheetFileName, "" ) ); diff --git a/eeschema/schematic_settings.h b/eeschema/schematic_settings.h index 26f346f7c5..c682f880a9 100644 --- a/eeschema/schematic_settings.h +++ b/eeschema/schematic_settings.h @@ -24,6 +24,7 @@ #include #include #include +#include class NGSPICE_SETTINGS; @@ -86,13 +87,15 @@ public: TEMPLATES m_TemplateFieldNames; /// List of stored BOM presets - BOM_PRESET m_BomSettings; - std::vector m_BomPresets; + BOM_PRESET m_BomSettings; + std::vector m_BomPresets; /// List of stored BOM format presets BOM_FMT_PRESET m_BomFmtSettings; std::vector m_BomFmtPresets; + KIFONT::METRICS m_FontMetrics; + /** * Ngspice simulator settings. */ diff --git a/include/board_item.h b/include/board_item.h index 99711ce449..79584a92f9 100644 --- a/include/board_item.h +++ b/include/board_item.h @@ -42,6 +42,11 @@ class SHAPE; class PCB_GROUP; class FOOTPRINT; +namespace KIFONT +{ +class METRICS; +} + /** * Conditionally flashed vias and pads that interact with zones of different priority can be @@ -191,6 +196,8 @@ public: virtual STROKE_PARAMS GetStroke() const; virtual void SetStroke( const STROKE_PARAMS& aStroke ); + const KIFONT::METRICS& GetFontMetrics() const; + /** * Return the primary layer this item is on. */ diff --git a/include/drawing_sheet/ds_draw_item.h b/include/drawing_sheet/ds_draw_item.h index fa9b9a2ddd..336f9ed4f2 100644 --- a/include/drawing_sheet/ds_draw_item.h +++ b/include/drawing_sheet/ds_draw_item.h @@ -75,6 +75,8 @@ public: return 1; } + const KIFONT::METRICS& GetFontMetrics() const; + // The function to print a WS_DRAW_ITEM virtual void PrintWsItem( const RENDER_SETTINGS* aSettings ) { @@ -346,6 +348,9 @@ public: #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif + +protected: + const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } }; diff --git a/include/eda_text.h b/include/eda_text.h index fcc5c4e668..57714f808a 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -49,6 +49,11 @@ namespace KIGFX class COLOR4D; } +namespace KIFONT +{ + class METRICS; + } + using KIGFX::RENDER_SETTINGS; using KIGFX::COLOR4D; @@ -59,12 +64,10 @@ using KIGFX::COLOR4D; /** - * This is the "default-of-the-default" hardcoded text size; individual - * application define their own default policy starting with this - * (usually with a user option or project). + * This is the "default-of-the-default" hardcoded text size; individual application define their + * own default policy starting with this (usually with a user option or project). */ #define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000") -#define DIM_ANCRE_TEXTE 2 // Anchor size for text /** @@ -233,8 +236,8 @@ public: * @param aColor text color. * @param aDisplay_mode #FILLED or #SKETCH. */ - void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, - const COLOR4D& aColor, OUTLINE_MODE aDisplay_mode = FILLED ); + void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, const COLOR4D& aColor, + OUTLINE_MODE aDisplay_mode = FILLED ); /** * build a list of segments (SHAPE_SEGMENT) to describe a text shape. @@ -363,6 +366,8 @@ public: protected: virtual KIFONT::FONT* getDrawFont() const; + virtual const KIFONT::METRICS& getFontMetrics() const; + void cacheShownText(); /** diff --git a/include/font/font.h b/include/font/font.h index a0f147aea6..c88f800e7d 100644 --- a/include/font/font.h +++ b/include/font/font.h @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2021 Ola Rinta-Koski - * Copyright (C) 2021-2022 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2023 Kicad Developers, see AUTHORS.txt for contributors. * * Font abstract base class * @@ -42,12 +42,12 @@ class GAL; enum TEXT_STYLE { - BOLD = 1, - ITALIC = 1 << 1, - SUBSCRIPT = 1 << 2, + BOLD = 1, + ITALIC = 1 << 1, + SUBSCRIPT = 1 << 2, SUPERSCRIPT = 1 << 3, - OVERBAR = 1 << 4, - UNDERLINE = 1 << 5 + OVERBAR = 1 << 4, + UNDERLINE = 1 << 5 }; @@ -87,17 +87,42 @@ inline bool IsSubscript( TEXT_STYLE_FLAGS aFlags ) } -inline bool IsOverbar( TEXT_STYLE_FLAGS aFlags ) -{ - return aFlags & TEXT_STYLE::OVERBAR; -} - - -std::string TextStyleAsString( TEXT_STYLE_FLAGS aFlags ); - - namespace KIFONT { +class METRICS +{ +public: + /** + * Compute the vertical position of an overbar. This is the distance between the text + * baseline and the overbar. + */ + double GetOverbarVerticalPosition( double aGlyphHeight ) const + { + return aGlyphHeight * m_OverbarHeight; + } + + /** + * Compute the vertical position of an underline. This is the distance between the text + * baseline and the underline. + */ + double GetUnderlineVerticalPosition( double aGlyphHeight ) const + { + return aGlyphHeight * m_UnderlineOffset; + } + + double GetInterline( double aFontHeight ) const + { + return aFontHeight * m_InterlinePitch; + } + + static const METRICS& Default(); + +public: + double m_InterlinePitch = 1.68; + double m_OverbarHeight = 1.23; + double m_UnderlineOffset = -0.16; +}; + /** * FONT is an abstract base class for both outline and stroke fonts */ @@ -132,12 +157,13 @@ public: * @param aAttrs are the styling attributes of the text, including its rotation */ void Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition, - const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs ) const; + const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttributes, + const METRICS& aFontMetrics ) const; void Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition, - const TEXT_ATTRIBUTES& aAttributes ) const + const TEXT_ATTRIBUTES& aAttributes, const METRICS& aFontMetrics ) const { - Draw( aGal, aText, aPosition, VECTOR2I( 0, 0 ), aAttributes ); + Draw( aGal, aText, aPosition, VECTOR2I( 0, 0 ), aAttributes, aFontMetrics ); } /** @@ -146,7 +172,7 @@ public: * @return a VECTOR2I giving the width and height of text. */ VECTOR2I StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSize, int aThickness, - bool aBold, bool aItalic ) const; + bool aBold, bool aItalic, const METRICS& aFontMetrics ) const; /** * Insert \n characters into text to ensure that no lines are wider than \a aColumnWidth. @@ -154,23 +180,11 @@ public: void LinebreakText( wxString& aText, int aColumnWidth, const VECTOR2I& aGlyphSize, int aThickness, bool aBold, bool aItalic ) const; - /** - * Compute the vertical position of an overbar. This is the distance between the text - * baseline and the overbar. - */ - virtual double ComputeOverbarVerticalPosition( double aGlyphHeight ) const = 0; - - /** - * Compute the vertical position of an underline. This is the distance between the text - * baseline and the underline. - */ - virtual double ComputeUnderlineVerticalPosition( double aGlyphHeight ) const = 0; - /** * Compute the distance (interline) between 2 lines of text (for multiline texts). This is * the distance between baselines, not the space between line bounding boxes. */ - virtual double GetInterline( double aGlyphHeight, double aLineSpacing = 1.0 ) const = 0; + virtual double GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const = 0; /** * Convert text string to an array of GLYPHs. @@ -225,7 +239,7 @@ protected: void drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, - bool aItalic, bool aUnderline ) const; + bool aItalic, bool aUnderline, const METRICS& aFontMetrics ) const; /** * Computes the bounding box for a single line of text. @@ -238,23 +252,22 @@ protected: * @return new cursor position */ VECTOR2I boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText, const VECTOR2I& aPosition, - const VECTOR2I& aSize, bool aItalic ) const; + const VECTOR2I& aSize, bool aItalic, const METRICS& aFontMetrics ) const; void getLinePositions( const wxString& aText, const VECTOR2I& aPosition, wxArrayString& aTextLines, std::vector& aPositions, - std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const; + std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs, + const METRICS& aFontMetrics ) 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 VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle, + const METRICS& aFontMetrics ) 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.61; // The golden mean - private: static FONT* getDefaultFont(); diff --git a/include/font/outline_font.h b/include/font/outline_font.h index 77e0f56ea8..e483ab1dea 100644 --- a/include/font/outline_font.h +++ b/include/font/outline_font.h @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2021 Ola Rinta-Koski - * Copyright (C) 2021-2022 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2023 Kicad Developers, see AUTHORS.txt for contributors. * * Outline font class * @@ -89,23 +89,11 @@ public: */ static OUTLINE_FONT* LoadFont( const wxString& aFontFileName, bool aBold, bool aItalic ); - /** - * Compute the vertical position of an overbar. This is the distance between the text - * baseline and the overbar. - */ - double ComputeOverbarVerticalPosition( double aGlyphHeight ) const override; - - /** - * Compute the vertical position of an underline. This is the distance between the text - * baseline and the underline. - */ - double ComputeUnderlineVerticalPosition( double aGlyphHeight ) const override; - /** * Compute the distance (interline) between 2 lines of text (for multiline texts). This is * the distance between baselines, not the space between line bounding boxes. */ - double GetInterline( double aGlyphHeight = 0.0, double aLineSpacing = 1.0 ) const override; + double GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const override; VECTOR2I GetTextAsGlyphs( BOX2I* aBoundingBox, std::vector>* aGlyphs, const wxString& aText, const VECTOR2I& aSize, @@ -113,7 +101,8 @@ public: const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const override; void GetLinesAsGlyphs( std::vector>* aGlyphs, const wxString& aText, - const VECTOR2I& aPosition, const TEXT_ATTRIBUTES& aAttrs ) const; + const VECTOR2I& aPosition, const TEXT_ATTRIBUTES& aAttrs, + const METRICS& aFontMetrics ) const; const FT_Face& GetFace() const { return m_face; } diff --git a/include/font/stroke_font.h b/include/font/stroke_font.h index f1e73e52e3..7e2202656f 100644 --- a/include/font/stroke_font.h +++ b/include/font/stroke_font.h @@ -64,23 +64,11 @@ public: */ static STROKE_FONT* LoadFont( const wxString& aFontName ); - /** - * Compute the vertical position of an overbar. This is the distance between the text - * baseline and the overbar. - */ - double ComputeOverbarVerticalPosition( double aGlyphHeight ) const override; - - /** - * Compute the vertical position of an underline. This is the distance between the text - * baseline and the underline. - */ - double ComputeUnderlineVerticalPosition( double aGlyphHeight ) const override; - /** * Compute the distance (interline) between 2 lines of text (for multiline texts). This is * the distance between baselines, not the space between line bounding boxes. */ - double GetInterline( double aGlyphHeight, double aLineSpacing = 1.0 ) const override; + double GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const override; VECTOR2I GetTextAsGlyphs( BOX2I* aBoundingBox, std::vector>* aGlyphs, const wxString& aText, const VECTOR2I& aSize, diff --git a/include/font/text_attributes.h b/include/font/text_attributes.h index 4faa9f8a04..c6dd599596 100644 --- a/include/font/text_attributes.h +++ b/include/font/text_attributes.h @@ -23,7 +23,7 @@ #include #include -#include "../../libs/kimath/include/geometry/eda_angle.h" +#include namespace KIFONT @@ -82,9 +82,7 @@ public: bool m_Multiline; VECTOR2I m_Size; - /** - * If true, keep rotation angle between -90...90 degrees for readability - */ + // If true, keep rotation angle between -90...90 degrees for readability bool m_KeepUpright; }; diff --git a/include/gr_text.h b/include/gr_text.h index ace03b6490..2e76154990 100644 --- a/include/gr_text.h +++ b/include/gr_text.h @@ -33,19 +33,10 @@ namespace KIGFX class COLOR4D; } -/** - * Minimum dimension in pixel for drawing/no drawing a text used in Pcbnew to decide to - * draw (or not) some texts ( like net names on pads/tracks ). - * - * When a text height is smaller than MIN_TEXT_SIZE, it is not drawn by Pcbnew. - */ -#define MIN_TEXT_SIZE 5 - -/* Absolute minimum dimension in pixel to draw a text as text or a line - * When a text height is smaller than MIN_DRAWABLE_TEXT_SIZE, - * it is drawn, but like a line by the draw text function -*/ -#define MIN_DRAWABLE_TEXT_SIZE 3 +namespace KIFONT +{ + class METRICS; +} class PLOTTER; @@ -105,12 +96,10 @@ inline int GetKnockoutTextMargin( const VECTOR2I& aSize, int aThickness ) /** - * The full X size is GraphicTextWidth + the thickness of graphic lines. - * * @return the X size of the graphic text. */ -int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize, - int aThickness, bool aBold, bool aItalic ); +int GRTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize, + int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS& aFontMetrics ); /** * Print a graphic text through wxDC. @@ -133,7 +122,8 @@ int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const KIGFX::COLOR4D& aColor, const wxString& aText, const EDA_ANGLE& aOrient, const VECTOR2I& aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont ); + int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics ); #endif /* GR_TEXT_H */ diff --git a/include/plotters/plotter.h b/include/plotters/plotter.h index c64b26e255..4f2783db69 100644 --- a/include/plotters/plotter.h +++ b/include/plotters/plotter.h @@ -22,12 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF) - * - * @file plotter.h - */ - #ifndef PLOT_COMMON_H_ #define PLOT_COMMON_H_ @@ -426,26 +420,28 @@ public: * @param aData is a parameter used by some plotters in SetCurrentLineWidth(), * not directly used here. */ - virtual void Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aPenWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed, - KIFONT::FONT* aFont, - void* aData = nullptr ); + virtual void Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aPenWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ); - virtual void PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData = nullptr ); + virtual void PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ); /** * Create a clickable hyperlink with a rectangular click area * diff --git a/include/plotters/plotter_dxf.h b/include/plotters/plotter_dxf.h index f557cc625d..f2f6af89d9 100644 --- a/include/plotters/plotter_dxf.h +++ b/include/plotters/plotter_dxf.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-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 @@ -17,12 +17,6 @@ * with this program. If not, see . */ -/** - * Plotting engine (DXF) - * - * @file plotter_dxf.h - */ - #pragma once #include "plotter.h" @@ -162,16 +156,19 @@ public: int aWidth, bool aItalic, bool aBold, - bool aMultilineAllowed = false, - KIFONT::FONT* aFont = nullptr, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, void* aData = nullptr ) override; - virtual void PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData = nullptr ) override; + virtual void PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; + /** * Set the units to use for plotting the DXF file. * @@ -215,9 +212,8 @@ protected: const EDA_ANGLE& aEndAngle, double aRadius, FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH ) override; - void plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes ); + void plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText, + const TEXT_ATTRIBUTES& aAttrs ); bool m_textAsLines; COLOR4D m_currentColor; diff --git a/include/plotters/plotter_gerber.h b/include/plotters/plotter_gerber.h index f4d768a45c..363a59a2e1 100644 --- a/include/plotters/plotter_gerber.h +++ b/include/plotters/plotter_gerber.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-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 @@ -18,12 +18,6 @@ * with this program. If not, see . */ -/** - * Plotting engine (Gerber) - * - * @file plotter_gerber.h - */ - #pragma once #include "plotter.h" @@ -110,27 +104,29 @@ public: virtual void PenTo( const VECTOR2I& pos, char plume ) override; - virtual void Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - KIFONT::FONT* aFont = nullptr, - void* aData = nullptr ) override; + virtual void Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; - virtual void PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData = nullptr ) override; + virtual void PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; /** * Filled circular flashes are stored as apertures diff --git a/include/plotters/plotters_pslike.h b/include/plotters/plotters_pslike.h index 76b777181e..ceb83e14c7 100644 --- a/include/plotters/plotters_pslike.h +++ b/include/plotters/plotters_pslike.h @@ -83,9 +83,8 @@ public: void* aData ) override; /** - * The SetColor implementation is split with the subclasses: - * The PSLIKE computes the rgb values, the subclass emits the - * operator to actually do it + * The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb + * values, the subclass emits the operator to actually do it */ virtual void SetColor( const COLOR4D& color ) override; @@ -93,9 +92,8 @@ protected: /** * This is the core for postscript/PDF text alignment. * - * It computes the transformation matrix to generate a user space - * system aligned with the text. Even the PS uses the concat - * operator to simplify PDF generation (concat is everything PDF + * It computes the transformation matrix to generate a user space system aligned with the text. + * Even the PS uses the concat operator to simplify PDF generation (concat is everything PDF * has to modify the CTM. Lots of parameters, both in and out. */ void computeTextParameters( const VECTOR2I& aPos, @@ -117,15 +115,6 @@ protected: double *ctm_f, double *heightFactor ); - /** - * Computes the x coordinates for the overlining in a string of text. - * Fills the passed vector with couples of (start, stop) values to be - * used in the text coordinate system (use computeTextParameters to - * obtain the parameters to establish such a system) - */ - void postscriptOverlinePositions( const wxString& aText, int aXSize, bool aItalic, bool aBold, - std::vector *pos_pairs ); - /// convert a wxString unicode string to a char string compatible with the accepted /// string plotter format (convert special chars and non ascii7 chars) virtual std::string encodeStringForPlotter( const wxString& aUnicode ); @@ -137,10 +126,9 @@ protected: static const double postscriptTextAscent; // = 0.718; /** - * Sister function for the GraphicTextWidth in drawtxt.cpp - * Does the same processing (i.e. calculates a text string width) but - * using postscript metrics for the Helvetica font (optionally used for - * PS and PDF plotting + * Sister function for the GRTextWidth in gr_text.cpp + * Does the same processing (i.e. calculates a text string width) but using postscript metrics + * for the Helvetica font (optionally used for PS and PDF plotting */ int returnPostscriptTextWidth( const wxString& aText, int aXSize, bool aItalic, bool aBold ); @@ -217,26 +205,28 @@ public: double aScaleFactor ) override; virtual void PenTo( const VECTOR2I& pos, char plume ) override; - virtual void Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - KIFONT::FONT* aFont = nullptr, - void* aData = nullptr ) override; + virtual void Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; - virtual void PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData = nullptr ) override; + virtual void PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; protected: @@ -347,26 +337,28 @@ public: virtual void PenTo( const VECTOR2I& pos, char plume ) override; - virtual void Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - KIFONT::FONT* aFont = nullptr, - void* aData = nullptr ) override; + virtual void Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; - virtual void PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData = nullptr ) override; + virtual void PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; void HyperlinkBox( const BOX2I& aBox, const wxString& aDestinationURL ) override; @@ -605,27 +597,29 @@ public: */ virtual void EndBlock( void* aData ) override; - virtual void Text( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const EDA_ANGLE& aOrient, - const VECTOR2I& aSize, - enum GR_TEXT_H_ALIGN_T aH_justify, - enum GR_TEXT_V_ALIGN_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - KIFONT::FONT* aFont = nullptr, - void* aData = nullptr ) override; + virtual void Text( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const EDA_ANGLE& aOrient, + const VECTOR2I& aSize, + enum GR_TEXT_H_ALIGN_T aH_justify, + enum GR_TEXT_V_ALIGN_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; - virtual void PlotText( const VECTOR2I& aPos, - const COLOR4D& aColor, - const wxString& aText, - const TEXT_ATTRIBUTES& aAttributes, - KIFONT::FONT* aFont, - void* aData = nullptr ) override; + virtual void PlotText( const VECTOR2I& aPos, + const COLOR4D& aColor, + const wxString& aText, + const TEXT_ATTRIBUTES& aAttributes, + KIFONT::FONT* aFont, + const KIFONT::METRICS& aFontMetrics, + void* aData = nullptr ) override; protected: virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle, @@ -665,9 +659,6 @@ protected: // color, pen size, fill mode ... // the new SVG stype must be output on file PLOT_DASH_TYPE m_dashed; // plot line style - bool m_useInch; // is 0 if the step size is 10**-n*mm - // is 1 if the step size is 10**-n*inch - // Where n is given from m_precision unsigned m_precision; // How fine the step size is // Use 3-6 (3 means um precision, 6 nm precision) in PcbNew // 3-4 in other modules (avoid values >4 to avoid overflow) diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp index 2dfcd75959..26c2dfb9d7 100644 --- a/pcbnew/board_item.cpp +++ b/pcbnew/board_item.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-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 @@ -92,6 +92,12 @@ void BOARD_ITEM::SetStroke( const STROKE_PARAMS& aStroke ) } +const KIFONT::METRICS& BOARD_ITEM::GetFontMetrics() const +{ + return KIFONT::METRICS::Default(); +} + + wxString BOARD_ITEM::GetLayerName() const { const BOARD* board = GetBoard(); diff --git a/pcbnew/exporters/gen_drill_report_files.cpp b/pcbnew/exporters/gen_drill_report_files.cpp index 477683c86d..365da54eeb 100644 --- a/pcbnew/exporters/gen_drill_report_files.cpp +++ b/pcbnew/exporters/gen_drill_report_files.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -275,7 +276,8 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_ attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER; attrs.m_Multiline = false; - plotter->PlotText( VECTOR2I( plotX, plotY ), COLOR4D::UNSPECIFIED, Text, attrs, nullptr /* stroke font */ ); + plotter->PlotText( VECTOR2I( plotX, plotY ), COLOR4D::UNSPECIFIED, Text, attrs, + nullptr /* stroke font */, KIFONT::METRICS::Default() ); // For some formats (PS, PDF SVG) we plot the drill size list on more than one column // because the list must be contained inside the printed page @@ -334,7 +336,8 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_ if( tool.m_Hole_NotPlated ) msg += wxT( " (not plated)" ); - plotter->PlotText( VECTOR2I( plotX, y ), COLOR4D::UNSPECIFIED, msg, attrs, nullptr /* stroke font */ ); + plotter->PlotText( VECTOR2I( plotX, y ), COLOR4D::UNSPECIFIED, msg, attrs, + nullptr /* stroke font */, KIFONT::METRICS::Default() ); intervalle = KiROUND( ( ( charSize * charScale ) + TextWidth ) * 1.2 ); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 51960a21e4..8f0f9ca8d5 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1893,7 +1893,7 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer ) void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition, - const TEXT_ATTRIBUTES& aAttrs ) + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ) { KIFONT::FONT* font = aAttrs.m_Font; @@ -1919,7 +1919,7 @@ void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition, pos += fudge; } - font->Draw( m_gal, aText, pos, aAttrs ); + font->Draw( m_gal, aText, pos, aAttrs, aFontMetrics ); } @@ -2045,7 +2045,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) } else { - strokeText( resolvedText, aText->GetTextPos(), attrs ); + strokeText( resolvedText, aText->GetTextPos(), attrs, aText->GetFontMetrics() ); } } @@ -2158,7 +2158,7 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) } else { - strokeText( resolvedText, aTextBox->GetDrawPos(), attrs ); + strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() ); } } @@ -2292,7 +2292,8 @@ void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer ) attrs.m_Size = VECTOR2I( textSize, textSize ); attrs.m_StrokeWidth = GetPenSizeForNormal( textSize ); - KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs ); + KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs, + aGroup->GetFontMetrics() ); } } } @@ -2466,7 +2467,7 @@ void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer ) } else { - strokeText( resolvedText, aDimension->GetTextPos(), attrs ); + strokeText( resolvedText, aDimension->GetTextPos(), attrs, aDimension->GetFontMetrics() ); } } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 7461c93311..3af55cb921 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN - * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @author Maciej Suminski @@ -59,6 +59,12 @@ class NET_SETTINGS; class NETINFO_LIST; class TEXT_ATTRIBUTES; +namespace KIFONT +{ +class FONT; +class METRICS; +} + namespace KIGFX { class GAL; @@ -209,7 +215,7 @@ protected: virtual int getViaDrillSize( const PCB_VIA* aVia ) const; void strokeText( const wxString& aText, const VECTOR2I& aPosition, - const TEXT_ATTRIBUTES& aAttrs ); + const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ); protected: PCB_RENDER_SETTINGS m_pcbSettings; diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index afa4e6a17b..016a8a150c 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -484,7 +484,7 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, textShape.Append( point.x, point.y ); } ); - font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs ); + font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs, GetFontMetrics() ); textShape.Simplify( SHAPE_POLY_SET::PM_FAST ); if( IsKnockout() ) diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index a12f384bdf..bada23a393 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -176,6 +176,8 @@ protected: virtual void swapData( BOARD_ITEM* aImage ) override; int getKnockoutMargin() const; + + const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } }; #endif // #define PCB_TEXT_H diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index 1460c63a47..d3ed322cd2 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -476,7 +476,7 @@ void PCB_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearanc buffer.Append( point.x, point.y ); } ); - font->Draw( &callback_gal, GetShownText( true ), GetDrawPos(), GetAttributes() ); + font->Draw( &callback_gal, GetShownText( true ), GetDrawPos(), GetAttributes(), GetFontMetrics() ); if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE ) { diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index 907e6d7973..b1bd130c82 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -136,6 +136,8 @@ public: protected: virtual void swapData( BOARD_ITEM* aImage ) override; + + const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } }; #endif // #define PCB_TEXTBOX_H diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h index a776edc1b0..df86f231a1 100644 --- a/pcbnew/pcbplot.h +++ b/pcbnew/pcbplot.h @@ -44,6 +44,12 @@ class ZONE; class REPORTER; class wxFileName; +namespace KIFONT +{ +class FONT; +class METRICS; +} + // Define min and max reasonable values for plot/print scale #define PLOT_MIN_SCALE 0.01 @@ -82,7 +88,8 @@ public: void PlotDimension( const PCB_DIMENSION_BASE* aDim ); void PlotPcbTarget( const PCB_TARGET* aMire ); void PlotZones( const ZONE* aZone, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPolysList ); - void PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout ); + void PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout, + const KIFONT::METRICS& aFontMetrics ); void PlotShape( const PCB_SHAPE* aShape ); /** diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index c530a7981e..7938101eec 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -282,7 +282,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint ) if( GetPlotReference() && m_layerMask[textLayer] && ( textItem->IsVisible() || GetPlotInvisibleText() ) ) { - PlotText( textItem, textLayer, textItem->IsKnockout() ); + PlotText( textItem, textLayer, textItem->IsKnockout(), textItem->GetFontMetrics() ); } textItem = &aFootprint->Value(); @@ -291,7 +291,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint ) if( GetPlotValue() && m_layerMask[textLayer] && ( textItem->IsVisible() || GetPlotInvisibleText() ) ) { - PlotText( textItem, textLayer, textItem->IsKnockout() ); + PlotText( textItem, textLayer, textItem->IsKnockout(), textItem->GetFontMetrics() ); } @@ -333,7 +333,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint ) if( text->GetText() == wxT( "${VALUE}" ) && !GetPlotValue() ) continue; - PlotText( text, textLayer, text->IsKnockout() ); + PlotText( text, textLayer, text->IsKnockout(), text->GetFontMetrics() ); } } @@ -349,14 +349,14 @@ void BRDITEMS_PLOTTER::PlotBoardGraphicItem( const BOARD_ITEM* item ) case PCB_TEXT_T: { const PCB_TEXT* text = static_cast( item ); - PlotText( text, text->GetLayer(), text->IsKnockout() ); + PlotText( text, text->GetLayer(), text->IsKnockout(), text->GetFontMetrics() ); break; } case PCB_TEXTBOX_T: { const PCB_TEXTBOX* textbox = static_cast( item ); - PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout() ); + PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout(), textbox->GetFontMetrics() ); PlotShape( textbox ); break; } @@ -390,7 +390,7 @@ void BRDITEMS_PLOTTER::PlotDimension( const PCB_DIMENSION_BASE* aDim ) // the white items are not seen on a white paper or screen m_plotter->SetColor( color != WHITE ? color : LIGHTGRAY); - PlotText( aDim, aDim->GetLayer(), false ); + PlotText( aDim, aDim->GetLayer(), false, aDim->GetFontMetrics() ); PCB_SHAPE temp_item; @@ -513,7 +513,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) if( m_layerMask[ textbox->GetLayer() ] ) { - PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout() ); + PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout(), + textbox->GetFontMetrics() ); PlotShape( textbox ); } @@ -546,7 +547,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) #include -void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout ) +void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout, + const KIFONT::METRICS& aFontMetrics ) { KIFONT::FONT* font = aText->GetFont(); @@ -609,12 +611,12 @@ void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, boo for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) { wxString& txt = strings_list.Item( ii ); - m_plotter->PlotText( positions[ii], color, txt, attrs, font, &gbr_metadata ); + m_plotter->PlotText( positions[ii], color, txt, attrs, font, aFontMetrics, &gbr_metadata ); } } else { - m_plotter->PlotText( pos, color, shownText, attrs, font, &gbr_metadata ); + m_plotter->PlotText( pos, color, shownText, attrs, font, aFontMetrics, &gbr_metadata ); } }