From 3d9784ded39c8b56077fe6fea9a19adfd714a47f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 24 Dec 2024 13:30:05 +0000 Subject: [PATCH] Plot from render cache if fonts aren't embedded. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18672 --- pcbnew/pcb_text.cpp | 7 +++- pcbnew/plot_brditems_plotter.cpp | 70 +++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index b038c00353..97b7e3f156 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -514,6 +514,7 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); TEXT_ATTRIBUTES attrs = GetAttributes(); + wxString shownText = GetShownText( true ); attrs.m_Angle = GetDrawRotation(); @@ -537,7 +538,11 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, textShape.Append( point.x, point.y ); } ); - font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs, GetFontMetrics() ); + if( auto* cache = GetRenderCache( font, shownText ) ) + callback_gal.DrawGlyphs( *cache ); + else + font->Draw( &callback_gal, shownText, GetTextPos(), attrs, GetFontMetrics() ); + textShape.Simplify(); if( IsKnockout() ) diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 1b08ba02ab..69e6dec9c7 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -36,7 +36,9 @@ #include // for VECTOR2I #include #include - +#include +#include +#include #include // for dyn_cast, PCB_DIMENSION_T #include #include // for GBR_NETLIST_METADATA @@ -665,7 +667,6 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) } -#include void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout, const KIFONT::METRICS& aFontMetrics, bool aStrikeout ) { @@ -738,31 +739,52 @@ void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, boo for( int ii = 0; ii < finalPoly.OutlineCount(); ++ii ) m_plotter->PlotPoly( finalPoly.Outline( ii ), FILL_T::FILLED_SHAPE, 0, &gbr_metadata ); } - else if( aText->IsMultilineAllowed() ) - { - std::vector positions; - wxArrayString strings_list; - wxStringSplit( shownText, strings_list, '\n' ); - positions.reserve( strings_list.Count() ); - - aText->GetLinePositions( positions, (int) strings_list.Count() ); - - for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) - { - wxString& txt = strings_list.Item( ii ); - m_plotter->PlotText( positions[ii], color, txt, attrs, font, aFontMetrics, - &gbr_metadata ); - } - - if( aStrikeout && strings_list.Count() == 1 ) - strikeoutText( static_cast( aText ) ); - } else { - m_plotter->PlotText( pos, color, shownText, attrs, font, aFontMetrics, &gbr_metadata ); + if( font->IsOutline() && !m_board->GetEmbeddedFiles()->GetAreFontsEmbedded() ) + { + KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - if( aStrikeout ) - strikeoutText( static_cast( aText ) ); + CALLBACK_GAL callback_gal( empty_opts, + // Stroke callback + [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 ) + { + m_plotter->ThickSegment( aPt1, aPt2, attrs.m_StrokeWidth, FILLED, nullptr ); + }, + // Polygon callback + [&]( const SHAPE_LINE_CHAIN& aPoly ) + { + m_plotter->PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, &gbr_metadata ); + } ); + + callback_gal.DrawGlyphs( *aText->GetRenderCache( font, shownText ) ); + } + else if( aText->IsMultilineAllowed() ) + { + std::vector positions; + wxArrayString strings_list; + wxStringSplit( shownText, strings_list, '\n' ); + positions.reserve( strings_list.Count() ); + + aText->GetLinePositions( positions, (int) strings_list.Count() ); + + for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) + { + wxString& txt = strings_list.Item( ii ); + m_plotter->PlotText( positions[ii], color, txt, attrs, font, aFontMetrics, + &gbr_metadata ); + } + + if( aStrikeout && strings_list.Count() == 1 ) + strikeoutText( static_cast( aText ) ); + } + else + { + m_plotter->PlotText( pos, color, shownText, attrs, font, aFontMetrics, &gbr_metadata ); + + if( aStrikeout ) + strikeoutText( static_cast( aText ) ); + } } }