diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index e284c5b9bd..b2430b1f7d 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -67,9 +67,12 @@ void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContaine const BOARD_ITEM* aOwner ) { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = aText->GetDrawFont(); TEXT_ATTRIBUTES attrs = aText->GetAttributes(); float penWidth_3DU = TO_3DU( aText->GetEffectiveTextPenWidth() ); + KIFONT::FONT* font = aText->GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( wxEmptyString, aText->IsBold(), aText->IsItalic() ); if( aOwner && aOwner->IsKnockout() ) { diff --git a/common/drawing_sheet/ds_painter.cpp b/common/drawing_sheet/ds_painter.cpp index 72e2c4da00..ac08860269 100644 --- a/common/drawing_sheet/ds_painter.cpp +++ b/common/drawing_sheet/ds_painter.cpp @@ -252,7 +252,10 @@ void KIGFX::DS_PAINTER::draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const KIFONT::FONT* font = aItem->GetFont(); if( !font ) - font = KIFONT::FONT::GetFont( wxEmptyString, aItem->IsBold(), aItem->IsItalic() ); + { + font = KIFONT::FONT::GetFont( m_renderSettings.GetDefaultFont(), aItem->IsBold(), + aItem->IsItalic() ); + } const COLOR4D& color = m_renderSettings.GetColor( aItem, aLayer ); diff --git a/common/drawing_sheet/ds_proxy_view_item.cpp b/common/drawing_sheet/ds_proxy_view_item.cpp index cd59056ef6..e56495edc0 100644 --- a/common/drawing_sheet/ds_proxy_view_item.cpp +++ b/common/drawing_sheet/ds_proxy_view_item.cpp @@ -123,6 +123,7 @@ void DS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) ); ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) ); ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) ); + ws_settings->SetDefaultFont( settings->GetDefaultFont() ); // Draw all the components that make the drawing sheet for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() ) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 5e8685b67d..2b5d3b9dce 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -423,7 +423,7 @@ void EDA_TEXT::cacheShownText() } -KIFONT::FONT* EDA_TEXT::GetDrawFont() const +KIFONT::FONT* EDA_TEXT::getDrawFont() const { KIFONT::FONT* font = GetFont(); @@ -448,9 +448,10 @@ void EDA_TEXT::ClearBoundingBoxCache() std::vector>* -EDA_TEXT::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& aOffset ) const +EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText, + const VECTOR2I& aOffset ) const { - if( GetDrawFont()->IsOutline() ) + if( getDrawFont()->IsOutline() ) { EDA_ANGLE resolvedAngle = GetDrawRotation(); @@ -461,7 +462,7 @@ EDA_TEXT::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& aOffs { m_render_cache.clear(); - KIFONT::OUTLINE_FONT* font = static_cast( GetDrawFont() ); + KIFONT::OUTLINE_FONT* font = static_cast( getDrawFont() ); TEXT_ATTRIBUTES attrs = GetAttributes(); attrs.m_Angle = resolvedAngle; @@ -495,7 +496,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() ) ); } @@ -530,7 +531,7 @@ BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const } // calculate the H and V size - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); VECTOR2D fontSize( GetTextSize() ); bool bold = IsBold(); bool italic = IsItalic(); @@ -722,8 +723,13 @@ void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTO if( IsMirrored() ) size.x = -size.x; + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), GetDrawFont() ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), font ); } @@ -849,7 +855,7 @@ std::shared_ptr EDA_TEXT::GetEffectiveTextShape( bool aTriangula { std::shared_ptr shape = std::make_shared(); KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); TEXT_ATTRIBUTES attrs = GetAttributes(); @@ -946,7 +952,7 @@ void EDA_TEXT::TransformBoundingBoxToPolygon( SHAPE_POLY_SET* aBuffer, int aClea // TrueType bounding boxes aren't guaranteed to include all descenders, diacriticals, etc. // Since we use this for zone knockouts and DRC, we need something more accurate. - if( GetDrawFont()->IsOutline() ) + if( getDrawFont()->IsOutline() ) rect = GetEffectiveTextShape( false, false )->BBox(); rect.Inflate( aClearance ); diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp index 91cd056285..7d89d2a962 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * * * This program is free software; you can redistribute it and/or @@ -23,13 +23,13 @@ */ #include +#include #include #include #include #include #include #include -#include #include #include @@ -65,9 +65,10 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL { /* Note: Page sizes values are given in mils */ - double iusPerMil = plotter->GetIUsPerDecimil() * 10.0; - COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK; - int defaultPenWidth = plotter->RenderSettings()->GetDefaultPenWidth(); + double iusPerMil = plotter->GetIUsPerDecimil() * 10.0; + COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK; + RENDER_SETTINGS* settings = plotter->RenderSettings(); + int defaultPenWidth = settings->GetDefaultPenWidth(); if( plotColor == COLOR4D::UNSPECIFIED ) plotColor = COLOR4D( RED ); @@ -86,7 +87,7 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL drawList.SetFileName( fn.GetFullName() ); // Print only the short filename drawList.SetSheetName( aSheetName ); drawList.SetSheetPath( aSheetPath ); - drawList.SetSheetLayer( plotter->RenderSettings()->GetLayerName() ); + drawList.SetSheetLayer( settings->GetLayerName() ); drawList.SetProject( aProject ); drawList.SetIsFirstPage( aIsFirstPage ); drawList.SetProperties( aProperties ); @@ -124,11 +125,20 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL case WSG_TEXT_T: { DS_DRAW_ITEM_TEXT* text = (DS_DRAW_ITEM_TEXT*) item; + KIFONT::FONT* font = text->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), text->IsBold(), + text->IsItalic() ); + } + int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth ); + plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(), text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(), - text->IsMultilineAllowed(), text->GetDrawFont() ); + text->IsMultilineAllowed(), font ); } break; diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index fc863d671a..3fae1eda63 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -344,6 +344,8 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions( RENDER_SETTINGS* aSettings ) // HPGL Pen Size is stored in mm in config cfg->m_PlotPanel.hpgl_pen_size = m_HPGLPenSize / schIUScale.IU_PER_MM; + + aSettings->SetDefaultFont( cfg->m_Appearance.default_font ); } aSettings->LoadColors( colors ); diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index f95f973863..b5d5e2c9bc 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -516,6 +516,8 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen ) renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, renderSettings.GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) ); + renderSettings.SetDefaultFont( cfg->m_Appearance.default_font ); + if( printReference ) { m_parent->PrintDrawingSheet( &renderSettings, aScreen, aScreen->Schematic()->GetProperties(), diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 86f434064d..eeb8f4c347 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -150,6 +150,7 @@ void SCH_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) GetRenderSettings()->m_ShowPinsElectricalType = false; GetRenderSettings()->m_ShowPinNumbers = false; + GetRenderSettings()->SetDefaultFont( eeconfig()->m_Appearance.default_font ); } diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 4283537fb7..223aaf6128 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -123,7 +123,7 @@ int LIB_FIELD::GetPenWidth() const } -KIFONT::FONT* LIB_FIELD::GetDrawFont() const +KIFONT::FONT* LIB_FIELD::getDrawFont() const { KIFONT::FONT* font = EDA_TEXT::GetFont(); @@ -154,8 +154,13 @@ void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset if( aDimmed ) color = color.Mix( bg, 0.5f ); + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + GRPrintText( DC, text_pos, color, text, GetTextAngle(), GetTextSize(), GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), GetDrawFont() ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), font ); } @@ -328,6 +333,8 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs if( GetText().IsEmpty() || aBackground ) return; + RENDER_SETTINGS* renderSettings = aPlotter->RenderSettings(); + // Calculate the text orientation, according to the symbol orientation/mirror. EDA_ANGLE orient = GetTextAngle(); @@ -354,9 +361,9 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs if( GetTextColor() != COLOR4D::UNSPECIFIED ) color = GetTextColor(); else - color = aPlotter->RenderSettings()->GetLayerColor( GetDefaultLayer() ); + color = renderSettings->GetLayerColor( GetDefaultLayer() ); - bg = aPlotter->RenderSettings()->GetBackgroundColor(); + bg = renderSettings->GetBackgroundColor(); if( bg == COLOR4D::UNSPECIFIED ) bg = COLOR4D::WHITE; @@ -370,10 +377,14 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs if( aDimmed ) color = color.Mix( bg, 0.5f ); - int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() ); + int penWidth = GetEffectivePenWidth( renderSettings ); + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() ); aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify, - penWidth, IsItalic(), IsBold(), false, GetDrawFont() ); + penWidth, IsItalic(), IsBold(), false, font ); } @@ -528,7 +539,7 @@ void LIB_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Style" ), GetTextStyleName() ); diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 52c0c2f20a..3d7ee453d1 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -117,7 +117,7 @@ public: int GetPenWidth() const override; - KIFONT::FONT* GetDrawFont() const override; + KIFONT::FONT* getDrawFont() const override; /** * Copy parameters of this field to another field. Pointers are not copied. diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 889fce6808..31f9c0fd5a 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -172,12 +172,6 @@ int LIB_PIN::GetPenWidth() const } -KIFONT::FONT* LIB_PIN::GetDrawFont() const -{ - return KIFONT::FONT::GetFont( GetDefaultFont(), false, false ); -} - - wxString LIB_PIN::GetShownName() const { if( m_name == wxS( "~" ) ) @@ -380,7 +374,7 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos int x, y; wxDC* DC = aSettings->GetPrintDC(); - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false ); wxSize pinNameSize( m_nameTextSize, m_nameTextSize ); wxSize pinNumSize( m_numTextSize, m_numTextSize ); @@ -573,10 +567,11 @@ void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECT if( aDimmed ) color = color.Mix( bg, 0.5f ); - VECTOR2I txtpos = aPosition; + VECTOR2I txtpos = aPosition; int offset = schIUScale.mmToIU( 0.4 ); GR_TEXT_H_ALIGN_T hjustify = GR_TEXT_H_ALIGN_LEFT; - EDA_ANGLE orient = ANGLE_HORIZONTAL; + EDA_ANGLE orient = ANGLE_HORIZONTAL; + KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false ); switch( aOrientation ) { @@ -602,7 +597,7 @@ void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECT } GRPrintText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify, - GR_TEXT_V_ALIGN_CENTER, pensize, false, false, GetDrawFont() ); + GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font ); } @@ -749,8 +744,10 @@ void LIB_PIN::PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOri void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const { - wxString name = GetShownName(); - wxString number = GetShownNumber(); + RENDER_SETTINGS* settings = aPlotter->RenderSettings(); + KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false ); + wxString name = GetShownName(); + wxString number = GetShownNumber(); if( name.IsEmpty() ) aDrawPinName = false; @@ -763,16 +760,16 @@ void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPin int x, y; int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ), - aPlotter->RenderSettings()->GetDefaultPenWidth() ); + settings->GetDefaultPenWidth() ); int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ), - aPlotter->RenderSettings()->GetDefaultPenWidth() ); + settings->GetDefaultPenWidth() ); int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth; int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth; /* Get the num and name colors */ - COLOR4D nameColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNAM ); - COLOR4D numColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNUM ); - COLOR4D bg = aPlotter->RenderSettings()->GetBackgroundColor(); + COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM ); + COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM ); + COLOR4D bg = settings->GetBackgroundColor(); if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() ) bg = COLOR4D::WHITE; @@ -800,7 +797,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPin { aPlotter->Text( VECTOR2I( px, py ), color, text, angle, VECTOR2I( size, size ), - hJustify, vJustify, penWidth, false, false, false, GetDrawFont() ); + hJustify, vJustify, penWidth, false, false, false, font ); }; /* Draw the text inside, but the pin numbers outside. */ diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index 76dabd8ef5..effd06d4ea 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -202,8 +202,6 @@ public: int GetPenWidth() const override; - KIFONT::FONT* GetDrawFont() const; - /** * Plot the pin number and pin text info, given the pin line coordinates. * Same as DrawPinTexts((), but output is the plotter diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index d505569b05..6985a260ce 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -297,9 +297,14 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset, int penWidth = std::max( GetEffectiveTextPenWidth(), settings->GetMinPenWidth() ); + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); + plotter->Text( pos, color, GetText(), t1 ? ANGLE_HORIZONTAL : ANGLE_VERTICAL, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), - true, GetDrawFont() ); + true, font ); } @@ -309,7 +314,7 @@ int LIB_TEXT::GetPenWidth() const } -KIFONT::FONT* LIB_TEXT::GetDrawFont() const +KIFONT::FONT* LIB_TEXT::getDrawFont() const { KIFONT::FONT* font = EDA_TEXT::GetFont(); @@ -354,6 +359,11 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, orient = ANGLE_HORIZONTAL; } + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + /* * Calculate the text justification, according to the symbol orientation/mirror. * This is a bit complicated due to cumulative calculations: @@ -374,7 +384,7 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, txtpos = aTransform.TransformCoordinate( txtpos ) + aOffset; GRPrintText( DC, txtpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetDrawFont() ); + GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), font ); } @@ -387,7 +397,7 @@ void LIB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Style" ), GetTextStyleName() ); diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index b092a9a537..0b1ffe40b4 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -79,7 +79,7 @@ public: int GetPenWidth() const override; - KIFONT::FONT* GetDrawFont() const override; + KIFONT::FONT* getDrawFont() const override; const BOX2I GetBoundingBox() const override; diff --git a/eeschema/lib_textbox.cpp b/eeschema/lib_textbox.cpp index 04d63d05bf..390748b30d 100644 --- a/eeschema/lib_textbox.cpp +++ b/eeschema/lib_textbox.cpp @@ -210,7 +210,7 @@ int LIB_TEXTBOX::compare( const LIB_ITEM& aOther, int aCompareFlags ) const } -KIFONT::FONT* LIB_TEXTBOX::GetDrawFont() const +KIFONT::FONT* LIB_TEXTBOX::getDrawFont() const { KIFONT::FONT* font = EDA_TEXT::GetFont(); @@ -305,13 +305,18 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs : ANGLE_HORIZONTAL ); } + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + // NB: GetDrawPos() will want Symbol Editor (upside-down) coordinates text.SetStart( VECTOR2I( pt1.x, -pt1.y ) ); text.SetEnd( VECTOR2I( pt2.x, -pt2.y ) ); GRPrintText( DC, text.GetDrawPos(), color, text.GetShownText(), text.GetTextAngle(), text.GetTextSize(), text.GetHorizJustify(), text.GetVertJustify(), penWidth, - text.IsItalic(), text.IsBold(), text.GetDrawFont() ); + text.IsItalic(), text.IsBold(), font ); } @@ -319,10 +324,13 @@ wxString LIB_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const { wxString text = EDA_TEXT::GetShownText(); - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = GetFont(); VECTOR2D size = GetEnd() - GetStart(); int colWidth = GetTextAngle() == ANGLE_HORIZONTAL ? size.x : size.y; + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + colWidth = abs( colWidth ) - GetTextMargin() * 2; font->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), IsItalic() ); @@ -382,21 +390,22 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf return; } - VECTOR2I start = aTransform.TransformCoordinate( m_start ) + aOffset; - VECTOR2I end = aTransform.TransformCoordinate( m_end ) + aOffset; - COLOR4D bg = aPlotter->RenderSettings()->GetBackgroundColor(); + RENDER_SETTINGS* renderSettings = aPlotter->RenderSettings(); + VECTOR2I start = aTransform.TransformCoordinate( m_start ) + aOffset; + VECTOR2I end = aTransform.TransformCoordinate( m_end ) + aOffset; + COLOR4D bg = renderSettings->GetBackgroundColor(); if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() ) bg = COLOR4D::WHITE; - int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() ); + int penWidth = GetEffectivePenWidth( renderSettings ); COLOR4D color = GetStroke().GetColor(); PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle(); if( penWidth > 0 ) { if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED ) - color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ); + color = renderSettings->GetLayerColor( LAYER_DEVICE ); if( lineStyle == PLOT_DASH_TYPE::DEFAULT ) lineStyle = PLOT_DASH_TYPE::DASH; @@ -410,12 +419,17 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID ); } + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() ); + LIB_TEXTBOX text( *this ); color = GetTextColor(); if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED ) - color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ); + color = renderSettings->GetLayerColor( LAYER_DEVICE ); if( aDimmed ) color = color.Mix( bg, 0.5f ); @@ -443,7 +457,7 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf { aPlotter->Text( positions[ii], color, strings_list.Item( ii ), text.GetTextAngle(), text.GetTextSize(), text.GetHorizJustify(), text.GetVertJustify(), - penWidth, text.IsItalic(), text.IsBold(), false, GetDrawFont() ); + penWidth, text.IsItalic(), text.IsBold(), false, font ); } } @@ -453,7 +467,7 @@ void LIB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) }; int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0; diff --git a/eeschema/lib_textbox.h b/eeschema/lib_textbox.h index 257f0deb6b..63d288175b 100644 --- a/eeschema/lib_textbox.h +++ b/eeschema/lib_textbox.h @@ -57,8 +57,6 @@ public: wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override; - KIFONT::FONT* GetDrawFont() const override; - void MirrorHorizontally( const VECTOR2I& center ); void MirrorVertically( const VECTOR2I& center ); void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override; @@ -95,6 +93,9 @@ public: void ViewGetLayers( int aLayers[], int& aCount ) const override; +protected: + KIFONT::FONT* getDrawFont() const override; + private: int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 0be2c78ff9..7981acb9d2 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1607,6 +1607,7 @@ void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window ); + GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font ); KIGFX::VIEW* view = GetCanvas()->GetView(); view->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 62a6a302a8..18b29723aa 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -266,7 +266,7 @@ int SCH_FIELD::GetPenWidth() const } -KIFONT::FONT* SCH_FIELD::GetDrawFont() const +KIFONT::FONT* SCH_FIELD::getDrawFont() const { KIFONT::FONT* font = EDA_TEXT::GetFont(); @@ -295,14 +295,20 @@ std::vector>* SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition, TEXT_ATTRIBUTES& aAttrs ) const { - if( GetDrawFont()->IsOutline() ) + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + + if( font->IsOutline() ) { + KIFONT::OUTLINE_FONT* outlineFont = static_cast( font ); + if( m_renderCache.empty() || !m_renderCacheValid ) { m_renderCache.clear(); - KIFONT::OUTLINE_FONT* font = static_cast( GetDrawFont() ); - font->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs ); + outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs ); m_renderCachePos = forPosition; m_renderCacheValid = true; @@ -366,6 +372,11 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset color = color.Mix( bg, 0.5f ); } + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + /* * Calculate the text justification, according to the symbol orientation/mirror. * This is a bit complicated due to cumulative calculations: @@ -379,7 +390,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset textpos = GetBoundingBox().Centre() + aOffset; GRPrintText( DC, textpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetDrawFont() ); + GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), font ); } @@ -754,7 +765,7 @@ void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Style" ), GetTextStyleName() ); @@ -1015,8 +1026,13 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const textpos = GetBoundingBox().Centre(); } + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); + aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify, - penWidth, IsItalic(), IsBold(), false, GetDrawFont() ); + penWidth, IsItalic(), IsBold(), false, font ); if( IsHypertext() ) { diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index a155a1d485..6a0e30694e 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -170,8 +170,6 @@ public: int GetPenWidth() const override; - KIFONT::FONT* GetDrawFont() const override; - void ClearCaches() override; void ClearRenderCache() override; @@ -241,6 +239,9 @@ public: void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif +protected: + KIFONT::FONT* getDrawFont() const override; + private: int m_id; ///< Field index, @see enum MANDATORY_FIELD_T diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 3b922890db..2464f945c0 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -861,7 +861,7 @@ void SCH_LABEL_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) }; int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0; @@ -914,6 +914,11 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const penWidth = std::max( penWidth, settings->GetMinPenWidth() ); aPlotter->SetCurrentLineWidth( penWidth ); + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); + VECTOR2I textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() ); CreateGraphicShape( aPlotter->RenderSettings(), s_poly, GetTextPos() ); @@ -925,7 +930,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const { aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(), GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(), - false, GetDrawFont() ); + false, font ); 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 c53fca9b00..e3e2136742 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -1947,9 +1947,17 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer ) attrs.m_Underlined = true; } + KIFONT::FONT* font = aText->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aText->IsBold(), + aText->IsItalic() ); + } + // Adjust text drawn in an outline font to more closely mimic the positioning of // SCH_FIELD text. - if( aText->GetDrawFont()->IsOutline() ) + if( font->IsOutline() ) { BOX2I firstLineBBox = aText->GetTextBox( 0 ); int sizeDiff = firstLineBBox.GetHeight() - aText->GetTextSize().y; @@ -1971,8 +1979,8 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer ) { std::vector>* cache = nullptr; - if( !aText->IsHypertext() ) - cache = aText->GetRenderCache( shownText, text_offset ); + if( !aText->IsHypertext() && font->IsOutline() ) + cache = aText->GetRenderCache( font, shownText, text_offset ); if( cache ) { @@ -1996,6 +2004,14 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer ) COLOR4D color = getRenderColor( aTextBox, aLayer, drawingShadows ); float borderWidth = getLineWidth( aTextBox, drawingShadows ); + KIFONT::FONT* font = aTextBox->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aTextBox->IsBold(), + aTextBox->IsItalic() ); + } + auto drawText = [&]() { @@ -2014,8 +2030,8 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer ) std::vector>* cache = nullptr; - if( !aTextBox->IsHypertext() ) - cache = aTextBox->GetRenderCache( shownText ); + if( !aTextBox->IsHypertext() && font->IsOutline() ) + cache = aTextBox->GetRenderCache( font, shownText ); if( cache ) { diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 930d26f70d..b34d64effe 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -276,7 +276,7 @@ int SCH_TEXT::GetPenWidth() const } -KIFONT::FONT* SCH_TEXT::GetDrawFont() const +KIFONT::FONT* SCH_TEXT::getDrawFont() const { KIFONT::FONT* font = EDA_TEXT::GetFont(); @@ -296,9 +296,14 @@ void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED ) color = aSettings->GetLayerColor( m_layer ); + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + // Adjust text drawn in an outline font to more closely mimic the positioning of // SCH_FIELD text. - if( GetDrawFont()->IsOutline() ) + if( font->IsOutline() ) { BOX2I firstLineBBox = GetTextBox( 0 ); int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y; @@ -443,7 +448,6 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; COLOR4D color = GetTextColor(); int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() ); - KIFONT::FONT* font = GetDrawFont(); VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() ); if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED ) @@ -452,9 +456,14 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const penWidth = std::max( penWidth, settings->GetMinPenWidth() ); aPlotter->SetCurrentLineWidth( penWidth ); + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); + // Adjust text drawn in an outline font to more closely mimic the positioning of // SCH_FIELD text. - if( GetDrawFont()->IsOutline() ) + if( font->IsOutline() ) { BOX2I firstLineBBox = GetTextBox( 0 ); int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y; @@ -492,7 +501,7 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) }; int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0; diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 42ba86ae0a..e8a3d3cbf7 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -170,8 +170,6 @@ public: int GetPenWidth() const override; - KIFONT::FONT* GetDrawFont() const override; - void Move( const VECTOR2I& aMoveVector ) override { EDA_TEXT::Offset( aMoveVector ); @@ -223,6 +221,9 @@ public: static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow ); +protected: + KIFONT::FONT* getDrawFont() const override; + 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 9fddfb6fd9..c2691d8937 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -213,7 +213,7 @@ bool SCH_TEXTBOX::operator<( const SCH_ITEM& aItem ) const } -KIFONT::FONT* SCH_TEXTBOX::GetDrawFont() const +KIFONT::FONT* SCH_TEXTBOX::getDrawFont() const { KIFONT::FONT* font = EDA_TEXT::GetFont(); @@ -319,9 +319,13 @@ wxString SCH_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project ); } - KIFONT::FONT* font = GetDrawFont(); - VECTOR2D size = GetEnd() - GetStart(); - int colWidth = GetTextAngle() == ANGLE_HORIZONTAL ? size.x : size.y; + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + + VECTOR2D size = GetEnd() - GetStart(); + int colWidth = GetTextAngle() == ANGLE_HORIZONTAL ? size.x : size.y; colWidth = abs( colWidth ) - GetTextMargin() * 2; font->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), IsItalic() ); @@ -384,7 +388,6 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const } RENDER_SETTINGS* settings = aPlotter->RenderSettings(); - KIFONT::FONT* font = GetDrawFont(); int penWidth = GetPenWidth(); COLOR4D color = GetStroke().GetColor(); PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle(); @@ -405,6 +408,11 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID ); } + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); + color = GetTextColor(); if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED ) @@ -438,7 +446,7 @@ void SCH_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) }; int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0; diff --git a/eeschema/sch_textbox.h b/eeschema/sch_textbox.h index d1016de9d6..b44e1b4dac 100644 --- a/eeschema/sch_textbox.h +++ b/eeschema/sch_textbox.h @@ -70,8 +70,6 @@ public: bool operator<( const SCH_ITEM& aItem ) const override; - KIFONT::FONT* GetDrawFont() const override; - void Move( const VECTOR2I& aMoveVector ) override { EDA_SHAPE::move( aMoveVector ); @@ -112,6 +110,9 @@ public: } void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; + +protected: + KIFONT::FONT* getDrawFont() const override; }; diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index d39cf10a34..0ff75f0591 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -576,12 +576,16 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard() GRForceBlackPen( false ); dc.SetUserScale( scale, scale ); - GetRenderSettings()->SetPrintDC( &dc ); - // Init the color of the layer actually used to print the drawing sheet: - GetRenderSettings()->SetLayerColor( LAYER_DRAWINGSHEET, - GetRenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) ); + KIGFX::SCH_RENDER_SETTINGS* cfg = GetRenderSettings(); - PrintPage( GetRenderSettings() ); + cfg->SetPrintDC( &dc ); + + // Init the color of the layer actually used to print the drawing sheet: + cfg->SetLayerColor( LAYER_DRAWINGSHEET, cfg->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) ); + + cfg->SetDefaultFont( eeconfig()->m_Appearance.default_font ); + + PrintPage( cfg ); { wxLogNull doNotLog; // disable logging of failed clipboard actions diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index e6573402d0..ab9fef0ef0 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -292,6 +292,7 @@ void SYMBOL_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) SCH_BASE_FRAME::LoadSettings( GetSettings() ); GetRenderSettings()->m_ShowPinsElectricalType = m_settings->m_ShowPinElectricalType; + GetRenderSettings()->SetDefaultFont( wxEmptyString ); } diff --git a/include/eda_text.h b/include/eda_text.h index 2663f632e9..b9d3f0a5ec 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -307,7 +307,6 @@ public: */ virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const; - virtual KIFONT::FONT* GetDrawFont() const; virtual EDA_ANGLE GetDrawRotation() const { return GetTextAngle(); } virtual VECTOR2I GetDrawPos() const { return GetTextPos(); } @@ -315,7 +314,8 @@ public: virtual void ClearBoundingBoxCache(); std::vector>* - GetRenderCache( const wxString& forResolvedText, const VECTOR2I& aOffset = { 0, 0 } ) const; + GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText, + const VECTOR2I& aOffset = { 0, 0 } ) const; // Support for reading the cache from disk. void SetupRenderCache( const wxString& aResolvedText, const EDA_ANGLE& aAngle ); @@ -355,12 +355,8 @@ public: static wxString GotoPageHref( const wxString& aDestination ); protected: - /** - * A hyperlink URL. If empty, this text object is not a hyperlink. - */ - wxString m_hyperlink; + virtual KIFONT::FONT* getDrawFont() const; -private: void cacheShownText(); /** @@ -376,6 +372,13 @@ private: const COLOR4D& aColor, OUTLINE_MODE aFillMode, const wxString& aText, const VECTOR2I& aPos ); +protected: + /** + * A hyperlink URL. If empty, this text object is not a hyperlink. + */ + wxString m_hyperlink; + +private: wxString m_text; wxString m_shown_text; // Cache of unescaped text for efficient access bool m_shown_text_has_text_var_refs; diff --git a/include/render_settings.h b/include/render_settings.h index 37c21d4436..dc5780f39e 100644 --- a/include/render_settings.h +++ b/include/render_settings.h @@ -291,6 +291,9 @@ public: void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; } void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; } + void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; } + const wxString& GetDefaultFont() const { return m_defaultFont; } + // TODO: these can go away once the drawing sheet is moved to Cairo-based printing wxDC* GetPrintDC() const { return m_printDC; } void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; } @@ -335,6 +338,8 @@ protected: double m_dashLengthRatio; double m_gapLengthRatio; + wxString m_defaultFont; + bool m_isPrinting; LSET m_printLayers; diff --git a/pcbnew/drc/drc_test_provider_text_dims.cpp b/pcbnew/drc/drc_test_provider_text_dims.cpp index 27d76749d6..50c1fcd8a7 100644 --- a/pcbnew/drc/drc_test_provider_text_dims.cpp +++ b/pcbnew/drc/drc_test_provider_text_dims.cpp @@ -144,14 +144,17 @@ bool DRC_TEST_PROVIDER_TEXT_DIMS::Run() if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE ) return true; - KIFONT::FONT* font = text->GetDrawFont(); + KIFONT::FONT* font = text->GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( wxEmptyString, text->IsBold(), text->IsItalic() ); if( font->IsOutline() ) { if( !constraint.Value().HasMin() ) return true; - auto* glyphs = text->GetRenderCache( text->GetShownText() ); + auto* glyphs = text->GetRenderCache( font, text->GetShownText() ); bool collapsedStroke = false; bool collapsedArea = false; diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index 79eab2d4c6..3c36c6af55 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -303,7 +303,7 @@ void FP_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); @@ -454,7 +454,7 @@ void FP_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLay int aError, ERROR_LOC aErrorLoc ) const { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); // Note: this function is mainly used in 3D viewer. diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index 5dbbc156aa..3f140787d4 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -309,7 +309,7 @@ void FP_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); @@ -418,7 +418,7 @@ wxString FP_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const text = ExpandTextVars( text, &footprintResolver, &boardTextResolver, project ); } - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); std::vector corners = GetAnchorAndOppositeCorner(); int colWidth = ( corners[1] - corners[0] ).EuclideanNorm(); @@ -444,7 +444,7 @@ void FP_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID a int aClearance, int aError, ERROR_LOC aErrorLoc ) const { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); // Note: this function is mainly used in 3D viewer. diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 7088d40286..7dd9ce0733 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -869,11 +869,9 @@ void PCB_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) aCfg->m_Window.zoom_factors = { ZOOM_LIST_PCBNEW }; } - // Some, but not all derived classes have a PCBNEW_SETTINGS. - PCBNEW_SETTINGS* cfg = dynamic_cast( aCfg ); - - if( cfg ) - m_polarCoords = cfg->m_PolarCoords; + // Some, but not all, derived classes have a PCBNEW_SETTINGS. + if( PCBNEW_SETTINGS* pcbnew_cfg = dynamic_cast( aCfg ) ) + m_polarCoords = pcbnew_cfg->m_PolarCoords; wxASSERT( GetCanvas() ); @@ -885,6 +883,7 @@ void PCB_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { rs->SetHighlightFactor( aCfg->m_Graphics.highlight_factor ); rs->SetSelectFactor( aCfg->m_Graphics.select_factor ); + rs->SetDefaultFont( wxEmptyString ); // Always the KiCad font for PCBs } } } diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index 2ea45dbde1..b6ffdd02df 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -325,7 +325,7 @@ void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, aList.emplace_back( _( "Units" ), EDA_UNIT_UTILS::GetLabel( GetUnits() ) ); - aList.emplace_back( _( "Font" ), m_text.GetDrawFont()->GetName() ); + aList.emplace_back( _( "Font" ), m_text.GetFont() ? m_text.GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Text Thickness" ), unitsProvider.MessageTextFromValue( m_text.GetTextThickness() ) ); aList.emplace_back( _( "Text Width" ), diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 8417ffdef5..2eb8a37ac4 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1855,6 +1855,14 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() ); bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; + KIFONT::FONT* font = aText->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aText->IsBold(), + aText->IsItalic() ); + } + m_gal->SetStrokeColor( color ); m_gal->SetFillColor( color ); @@ -1870,8 +1878,6 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) knockouts.AddOutline( aPoly ); } ); - KIFONT::FONT* font = aText->GetDrawFont(); - attrs.m_StrokeWidth = getLineThickness( aText->GetEffectiveTextPenWidth() ); callback_gal.SetIsFill( font->IsOutline() ); @@ -1904,16 +1910,15 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) attrs.m_Halign = static_cast( -attrs.m_Halign ); } - std::vector>* cache = aText->GetRenderCache( resolvedText ); + std::vector>* cache = nullptr; + + if( font->IsOutline() ) + cache = aText->GetRenderCache( font, resolvedText ); if( cache ) - { m_gal->DrawGlyphs( *cache ); - } else - { strokeText( resolvedText, aText->GetTextPos(), attrs ); - } } } @@ -1925,6 +1930,14 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) PLOT_DASH_TYPE lineStyle = aTextBox->GetStroke().GetPlotStyle(); wxString resolvedText( aTextBox->GetShownText() ); + KIFONT::FONT* font = aTextBox->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aTextBox->IsBold(), + aTextBox->IsItalic() ); + } + if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked { const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer ); @@ -1987,8 +2000,6 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) attrs.m_Halign = static_cast( -attrs.m_Halign ); } - std::vector>* cache = aTextBox->GetRenderCache( resolvedText ); - if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) { const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer ); @@ -1997,14 +2008,15 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) attrs.m_StrokeWidth += m_lockedShadowMargin; } + std::vector>* cache = nullptr; + + if( font->IsOutline() ) + cache = aTextBox->GetRenderCache( font, resolvedText ); + if( cache ) - { m_gal->DrawGlyphs( *cache ); - } else - { strokeText( resolvedText, aTextBox->GetDrawPos(), attrs ); - } } @@ -2019,6 +2031,14 @@ void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer ) bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; TEXT_ATTRIBUTES attrs = aText->GetAttributes(); + KIFONT::FONT* font = aText->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aText->IsBold(), + aText->IsItalic() ); + } + m_gal->SetStrokeColor( color ); m_gal->SetFillColor( color ); attrs.m_Angle = aText->GetDrawRotation(); @@ -2035,8 +2055,6 @@ void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer ) knockouts.AddOutline( aPoly ); } ); - KIFONT::FONT* font = aText->GetDrawFont(); - attrs.m_StrokeWidth = getLineThickness( aText->GetEffectiveTextPenWidth() ); callback_gal.SetIsFill( font->IsOutline() ); @@ -2069,16 +2087,15 @@ void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer ) attrs.m_Halign = static_cast( -attrs.m_Halign ); } - std::vector>* cache = aText->GetRenderCache( resolvedText ); + std::vector>* cache = nullptr; + + if( font->IsOutline() ) + cache = aText->GetRenderCache( font, resolvedText ); if( cache ) - { m_gal->DrawGlyphs( *cache ); - } else - { strokeText( resolvedText, aText->GetTextPos(), attrs ); - } } // Draw the umbilical line @@ -2144,16 +2161,15 @@ void PCB_PAINTER::draw( const FP_TEXTBOX* aTextBox, int aLayer ) attrs.m_Halign = static_cast( -attrs.m_Halign ); } - std::vector>* cache = aTextBox->GetRenderCache( resolvedText ); + std::vector>* cache = nullptr; + + if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() ) + cache = aTextBox->GetRenderCache( aTextBox->GetFont(), resolvedText ); if( cache ) - { m_gal->DrawGlyphs( *cache ); - } else - { strokeText( resolvedText, aTextBox->GetDrawPos(), attrs ); - } } @@ -2438,7 +2454,10 @@ void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer ) else attrs.m_StrokeWidth = getLineThickness( text.GetEffectiveTextPenWidth() ); - std::vector>* cache = text.GetRenderCache( resolvedText ); + std::vector>* cache = nullptr; + + if( text.GetFont() && text.GetFont()->IsOutline() ) + cache = text.GetRenderCache( text.GetFont(), resolvedText ); if( cache ) { diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 826c94e41f..91479ffd0b 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -139,7 +139,7 @@ void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); @@ -288,7 +288,7 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLa int aClearance, int aError, ERROR_LOC aErrorLoc ) const { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); // Note: this function is mainly used in 3D viewer. diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index eb775bc8e8..cb604c9948 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -282,7 +282,7 @@ wxString PCB_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const if( board && HasTextVars() && aDepth < 10 ) text = ExpandTextVars( text, &pcbTextResolver, &boardTextResolver, board->GetProject() ); - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); std::vector corners = GetAnchorAndOppositeCorner(); int colWidth = ( corners[1] - corners[0] ).EuclideanNorm(); @@ -305,7 +305,7 @@ void PCB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); + aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); @@ -451,7 +451,7 @@ void PCB_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID int aClearance, int aError, ERROR_LOC aErrorLoc ) const { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = GetDrawFont(); + KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); // Note: this function is mainly used in 3D viewer. diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index c2e21a56c3..6c460957f3 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -402,9 +402,16 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4 m_plotter->SetColor( color ); // calculate some text parameters : - VECTOR2I size = aText->GetTextSize(); - VECTOR2I pos = aText->GetTextPos(); - int thickness = aText->GetEffectiveTextPenWidth(); + VECTOR2I size = aText->GetTextSize(); + VECTOR2I pos = aText->GetTextPos(); + int thickness = aText->GetEffectiveTextPenWidth(); + KIFONT::FONT* font = aText->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_plotter->RenderSettings()->GetDefaultFont(), + aText->IsBold(), aText->IsItalic() ); + } if( aText->IsMirrored() ) size.x = -size.x; // Text is mirrored @@ -428,7 +435,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4 m_plotter->Text( pos, aColor, aText->GetShownText(), aText->GetDrawRotation(), size, aText->GetHorizJustify(), aText->GetVertJustify(), thickness, - aText->IsItalic(), allow_bold, false, aText->GetDrawFont(), &gbr_metadata ); + aText->IsItalic(), allow_bold, false, font, &gbr_metadata ); } @@ -779,8 +786,15 @@ void BRDITEMS_PLOTTER::PlotFootprintShape( const FP_SHAPE* aShape ) void BRDITEMS_PLOTTER::PlotPcbText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout ) { + KIFONT::FONT* font = aText->GetFont(); + + if( !font ) + { + font = KIFONT::FONT::GetFont( m_plotter->RenderSettings()->GetDefaultFont(), + aText->IsBold(), aText->IsItalic() ); + } + wxString shownText( aText->GetShownText() ); - KIFONT::FONT* font = aText->GetDrawFont(); TEXT_ATTRIBUTES attrs = aText->GetAttributes(); if( shownText.IsEmpty() ) diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index 385b687706..3eed9909e0 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -547,7 +547,8 @@ void PCB_PLUGIN::formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel, void PCB_PLUGIN::formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) const { const wxString& shownText = aText->GetShownText(); - std::vector>* cache = aText->GetRenderCache( shownText ); + std::vector>* cache = aText->GetRenderCache( aText->GetFont(), + shownText ); m_out->Print( aNestLevel, "(render_cache %s %s\n", m_out->Quotew( shownText ).c_str(),