mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 00:21:25 +00:00
Auto update list of fonts when embedding files
Get the list of currently used fonts to populate the list of embedded files when the user checks the "embed fonts" checkbox
This commit is contained in:
parent
6a92e5f02d
commit
3a5eeef9df
@ -24,6 +24,7 @@
|
||||
#include <bitmaps.h>
|
||||
#include <dialogs/panel_embedded_files.h>
|
||||
#include <embedded_files.h>
|
||||
#include <font/outline_font.h>
|
||||
#include <kidialog.h>
|
||||
#include <widgets/std_bitmap_button.h>
|
||||
#include <widgets/wx_grid.h>
|
||||
@ -33,6 +34,7 @@
|
||||
#include <wx/ffile.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/menu.h>
|
||||
|
||||
/* ---------- GRID_TRICKS for embedded files grid ---------- */
|
||||
@ -186,6 +188,73 @@ bool PANEL_EMBEDDED_FILES::TransferDataFromWindow()
|
||||
}
|
||||
|
||||
|
||||
void PANEL_EMBEDDED_FILES::onFontEmbedClick( wxCommandEvent& event )
|
||||
{
|
||||
Freeze();
|
||||
int row_pos = m_files_grid->GetGridCursorRow();
|
||||
int col_pos = m_files_grid->GetGridCursorCol();
|
||||
wxString row_name;
|
||||
|
||||
if( row_pos >= 0 )
|
||||
row_name = m_files_grid->GetCellValue( row_pos, 0 );
|
||||
|
||||
for( int ii = 0; ii < m_files_grid->GetNumberRows(); ii++ )
|
||||
{
|
||||
wxString name = m_files_grid->GetCellValue( ii, 0 );
|
||||
|
||||
EMBEDDED_FILES::EMBEDDED_FILE* file = m_localFiles->GetEmbeddedFile( name );
|
||||
|
||||
if( file && file->type == EMBEDDED_FILES::EMBEDDED_FILE::FILE_TYPE::FONT )
|
||||
{
|
||||
m_files_grid->DeleteRows( ii );
|
||||
ii--;
|
||||
m_localFiles->RemoveFile( name );
|
||||
}
|
||||
}
|
||||
|
||||
if( m_cbEmbedFonts->IsChecked() )
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts = m_files->GetFonts();
|
||||
|
||||
for( KIFONT::OUTLINE_FONT* font : fonts )
|
||||
{
|
||||
EMBEDDED_FILES::EMBEDDED_FILE* result =
|
||||
m_localFiles->AddFile( font->GetFileName(), true );
|
||||
|
||||
if( !result )
|
||||
{
|
||||
wxLogTrace( wxT( "KICAD_EMBED" ), wxString::Format( "Could not embed font %s",
|
||||
font->GetFileName() ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
m_files_grid->AppendRows( 1 );
|
||||
int ii = m_files_grid->GetNumberRows() - 1;
|
||||
m_files_grid->SetCellValue( ii, 0, result->name );
|
||||
m_files_grid->SetCellValue( ii, 1, result->GetLink() );
|
||||
}
|
||||
}
|
||||
|
||||
if( row_pos >= 0 )
|
||||
{
|
||||
col_pos = std::max( std::min( col_pos, m_files_grid->GetNumberCols() - 1 ), 0 );
|
||||
row_pos = std::max( std::min( row_pos, m_files_grid->GetNumberRows() - 1 ), 0 );
|
||||
m_files_grid->SetGridCursor( row_pos, col_pos );
|
||||
|
||||
for( int ii = 0; ii < m_files_grid->GetNumberRows(); ++ii )
|
||||
{
|
||||
if( m_files_grid->GetCellValue( ii, 0 ) == row_name )
|
||||
{
|
||||
m_files_grid->SetGridCursor( ii, col_pos );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thaw();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_EMBEDDED_FILES::onAddEmbeddedFile( wxCommandEvent& event )
|
||||
{
|
||||
wxFileDialog fileDialog( this, _( "Select a file to embed" ), wxEmptyString, wxEmptyString,
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
bool GetEmbedFonts() const { return m_cbEmbedFonts->GetValue(); }
|
||||
|
||||
protected:
|
||||
void onFontEmbedClick( wxCommandEvent& event ) override;
|
||||
void onAddEmbeddedFile( wxCommandEvent& event ) override;
|
||||
void onDeleteEmbeddedFile( wxCommandEvent& event ) override;
|
||||
void onExportFiles( wxCommandEvent& event ) override;
|
||||
|
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@ -103,6 +103,7 @@ PANEL_EMBEDDED_FILES_BASE::PANEL_EMBEDDED_FILES_BASE( wxWindow* parent, wxWindow
|
||||
m_files_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( PANEL_EMBEDDED_FILES_BASE::onGridRightClick ), NULL, this );
|
||||
m_browse_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onAddEmbeddedFile ), NULL, this );
|
||||
m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onDeleteEmbeddedFile ), NULL, this );
|
||||
m_cbEmbedFonts->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onFontEmbedClick ), NULL, this );
|
||||
m_export->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onExportFiles ), NULL, this );
|
||||
}
|
||||
|
||||
@ -113,6 +114,7 @@ PANEL_EMBEDDED_FILES_BASE::~PANEL_EMBEDDED_FILES_BASE()
|
||||
m_files_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( PANEL_EMBEDDED_FILES_BASE::onGridRightClick ), NULL, this );
|
||||
m_browse_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onAddEmbeddedFile ), NULL, this );
|
||||
m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onDeleteEmbeddedFile ), NULL, this );
|
||||
m_cbEmbedFonts->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onFontEmbedClick ), NULL, this );
|
||||
m_export->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_EMBEDDED_FILES_BASE::onExportFiles ), NULL, this );
|
||||
|
||||
}
|
||||
|
@ -404,6 +404,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnCheckBox">onFontEmbedClick</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="false">
|
||||
|
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@ -49,6 +49,7 @@ class PANEL_EMBEDDED_FILES_BASE : public wxPanel
|
||||
virtual void onGridRightClick( wxGridEvent& event ) { event.Skip(); }
|
||||
virtual void onAddEmbeddedFile( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void onDeleteEmbeddedFile( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void onFontEmbedClick( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void onExportFiles( wxCommandEvent& event ) { event.Skip(); }
|
||||
|
||||
|
||||
|
@ -1940,20 +1940,20 @@ const EMBEDDED_FILES* LIB_SYMBOL::GetEmbeddedFiles() const
|
||||
}
|
||||
|
||||
|
||||
void LIB_SYMBOL::EmbedFonts()
|
||||
std::set<KIFONT::OUTLINE_FONT*> LIB_SYMBOL::GetFonts() const
|
||||
{
|
||||
using OUTLINE_FONT = KIFONT::OUTLINE_FONT;
|
||||
using EMBEDDING_PERMISSION = OUTLINE_FONT::EMBEDDING_PERMISSION;
|
||||
|
||||
std::set<OUTLINE_FONT*> fonts;
|
||||
|
||||
for( SCH_ITEM& item : m_drawings )
|
||||
for( const SCH_ITEM& item : m_drawings )
|
||||
{
|
||||
if( item.Type() == SCH_TEXT_T )
|
||||
{
|
||||
auto* text = static_cast<SCH_TEXT*>( &item );
|
||||
const SCH_TEXT& text = static_cast<const SCH_TEXT&>( item );
|
||||
|
||||
if( auto* font = text->GetFont(); font && !font->IsStroke() )
|
||||
if( auto* font = text.GetFont(); font && !font->IsStroke() )
|
||||
{
|
||||
auto* outline = static_cast<OUTLINE_FONT*>( font );
|
||||
auto permission = outline->GetEmbeddingPermission();
|
||||
@ -1967,7 +1967,15 @@ void LIB_SYMBOL::EmbedFonts()
|
||||
}
|
||||
}
|
||||
|
||||
for( auto* font : fonts )
|
||||
return fonts;
|
||||
}
|
||||
|
||||
|
||||
void LIB_SYMBOL::EmbedFonts()
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts = GetFonts();
|
||||
|
||||
for( KIFONT::OUTLINE_FONT* font : fonts )
|
||||
{
|
||||
auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
|
||||
file->type = EMBEDDED_FILES::EMBEDDED_FILE::FILE_TYPE::FONT;
|
||||
|
@ -40,8 +40,14 @@ class OUTPUTFORMATTER;
|
||||
class REPORTER;
|
||||
class SYMBOL_LIB;
|
||||
class LIB_SYMBOL;
|
||||
class OUTLINE_FONT;
|
||||
class TEST_LIB_SYMBOL_FIXTURE;
|
||||
|
||||
namespace KIFONT
|
||||
{
|
||||
class OUTLINE_FONT;
|
||||
}
|
||||
|
||||
|
||||
typedef std::shared_ptr<LIB_SYMBOL> LIB_SYMBOL_SPTR; ///< shared pointer to LIB_SYMBOL
|
||||
typedef std::weak_ptr<LIB_SYMBOL> LIB_SYMBOL_REF; ///< weak pointer to LIB_SYMBOL
|
||||
@ -350,6 +356,8 @@ public:
|
||||
return GetValueField().GetText();
|
||||
}
|
||||
|
||||
std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
|
||||
|
||||
EMBEDDED_FILES* GetEmbeddedFiles() override;
|
||||
const EMBEDDED_FILES* GetEmbeddedFiles() const;
|
||||
|
||||
|
@ -885,7 +885,7 @@ const EMBEDDED_FILES* SCHEMATIC::GetEmbeddedFiles() const
|
||||
}
|
||||
|
||||
|
||||
void SCHEMATIC::EmbedFonts()
|
||||
std::set<KIFONT::OUTLINE_FONT*> SCHEMATIC::GetFonts() const
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts;
|
||||
|
||||
@ -914,6 +914,14 @@ void SCHEMATIC::EmbedFonts()
|
||||
}
|
||||
}
|
||||
|
||||
return fonts;
|
||||
}
|
||||
|
||||
|
||||
void SCHEMATIC::EmbedFonts()
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts = GetFonts();
|
||||
|
||||
for( KIFONT::OUTLINE_FONT* font : fonts )
|
||||
{
|
||||
auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
|
||||
|
@ -36,6 +36,11 @@ class SCH_SHEET;
|
||||
class SCH_SHEET_LIST;
|
||||
class SCH_GLOBALLABEL;
|
||||
|
||||
namespace KIFONT
|
||||
{
|
||||
class OUTLINE_FONT;
|
||||
}
|
||||
|
||||
|
||||
class SCHEMATIC_IFACE
|
||||
{
|
||||
@ -321,6 +326,11 @@ public:
|
||||
*/
|
||||
void EmbedFonts() override;
|
||||
|
||||
/**
|
||||
* Get a set of fonts used in the schematic
|
||||
*/
|
||||
std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
|
||||
|
||||
/**
|
||||
* Return a list of schematic files in the current project that contain instance data for
|
||||
* multiple projects.
|
||||
|
@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <wx/string.h>
|
||||
#include <wx/filename.h>
|
||||
@ -30,6 +31,11 @@
|
||||
|
||||
class OUTPUTFORMATTER;
|
||||
|
||||
namespace KIFONT
|
||||
{
|
||||
class OUTLINE_FONT;
|
||||
}
|
||||
|
||||
class EMBEDDED_FILES
|
||||
{
|
||||
public:
|
||||
@ -222,6 +228,11 @@ public:
|
||||
|
||||
virtual void EmbedFonts() {};
|
||||
|
||||
virtual std::set<KIFONT::OUTLINE_FONT*> GetFonts() const
|
||||
{
|
||||
return std::set<KIFONT::OUTLINE_FONT*>();
|
||||
};
|
||||
|
||||
void SetAreFontsEmbedded( bool aEmbedFonts )
|
||||
{
|
||||
m_embedFonts = aEmbedFonts;
|
||||
|
@ -2604,7 +2604,7 @@ const EMBEDDED_FILES* BOARD::GetEmbeddedFiles() const
|
||||
}
|
||||
|
||||
|
||||
void BOARD::EmbedFonts()
|
||||
std::set<KIFONT::OUTLINE_FONT*> BOARD::GetFonts() const
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts;
|
||||
|
||||
@ -2628,6 +2628,14 @@ void BOARD::EmbedFonts()
|
||||
}
|
||||
}
|
||||
|
||||
return fonts;
|
||||
}
|
||||
|
||||
|
||||
void BOARD::EmbedFonts()
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts = GetFonts();
|
||||
|
||||
for( KIFONT::OUTLINE_FONT* font : fonts )
|
||||
{
|
||||
auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
|
||||
|
@ -65,6 +65,11 @@ class CONNECTIVITY_DATA;
|
||||
class COMPONENT;
|
||||
class PROJECT;
|
||||
class PROGRESS_REPORTER;
|
||||
namespace KIFONT
|
||||
{
|
||||
class OUTLINE_FONT;
|
||||
}
|
||||
|
||||
struct ISOLATED_ISLANDS;
|
||||
|
||||
// The default value for m_outlinesChainingEpsilon to convert a board outlines to polygons
|
||||
@ -1267,6 +1272,11 @@ public:
|
||||
EMBEDDED_FILES* GetEmbeddedFiles() override;
|
||||
const EMBEDDED_FILES* GetEmbeddedFiles() const;
|
||||
|
||||
/**
|
||||
* Get the list of all outline fonts used in the board
|
||||
*/
|
||||
std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
|
||||
|
||||
/**
|
||||
* Finds all fonts used in the board and embeds them in the file if permissions allow
|
||||
*/
|
||||
|
@ -3959,7 +3959,7 @@ void FOOTPRINT::TransformFPShapesToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_I
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT::EmbedFonts()
|
||||
std::set<KIFONT::OUTLINE_FONT*> FOOTPRINT::GetFonts() const
|
||||
{
|
||||
using OUTLINE_FONT = KIFONT::OUTLINE_FONT;
|
||||
using EMBEDDING_PERMISSION = OUTLINE_FONT::EMBEDDING_PERMISSION;
|
||||
@ -3984,6 +3984,14 @@ void FOOTPRINT::EmbedFonts()
|
||||
}
|
||||
}
|
||||
|
||||
return fonts;
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT::EmbedFonts()
|
||||
{
|
||||
std::set<KIFONT::OUTLINE_FONT*> fonts = GetFonts();
|
||||
|
||||
for( auto* font : fonts )
|
||||
{
|
||||
auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
|
||||
|
@ -59,6 +59,10 @@ namespace KIGFX {
|
||||
class VIEW;
|
||||
}
|
||||
|
||||
namespace KIFONT {
|
||||
class OUTLINE_FONT;
|
||||
}
|
||||
|
||||
enum INCLUDE_NPTH_T
|
||||
{
|
||||
DO_NOT_INCLUDE_NPTH = false,
|
||||
@ -1008,6 +1012,11 @@ public:
|
||||
return static_cast<const EMBEDDED_FILES*>( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of outline fonts referenced in the footprint
|
||||
*/
|
||||
std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
|
||||
|
||||
void EmbedFonts() override;
|
||||
|
||||
double Similarity( const BOARD_ITEM& aOther ) const override;
|
||||
|
Loading…
Reference in New Issue
Block a user