KiCad PCB EDA Suite
|
#include <embedded_files.h>
Classes | |
struct | EMBEDDED_FILE |
Public Types | |
enum class | RETURN_CODE : int { OK , FILE_NOT_FOUND , PERMISSIONS_ERROR , FILE_ALREADY_EXISTS , OUT_OF_MEMORY , CHECKSUM_ERROR } |
using | FileAddedCallback = std::function< void(EMBEDDED_FILE *)> |
Public Member Functions | |
EMBEDDED_FILES ()=default | |
EMBEDDED_FILES (EMBEDDED_FILES &&other) noexcept | |
EMBEDDED_FILES (const EMBEDDED_FILES &other) | |
~EMBEDDED_FILES () | |
void | SetFileAddedCallback (FileAddedCallback callback) |
FileAddedCallback | GetFileAddedCallback () const |
EMBEDDED_FILE * | AddFile (const wxFileName &aName, bool aOverwrite) |
Load a file from disk and adds it to the collection. | |
void | AddFile (EMBEDDED_FILE *aFile) |
Append a file to the collection. | |
void | RemoveFile (const wxString &name, bool aErase=true) |
Remove a file from the collection and frees the memory. | |
void | WriteEmbeddedFiles (OUTPUTFORMATTER &aOut, bool aWriteData) const |
Output formatter for the embedded files. | |
wxString | GetEmbeddedFileLink (const EMBEDDED_FILE &aFile) const |
Return the link for an embedded file. | |
bool | HasFile (const wxString &name) const |
bool | IsEmpty () const |
const std::vector< wxString > * | UpdateFontFiles () |
Helper function to get a list of fonts for fontconfig to add to the library. | |
const std::vector< wxString > * | GetFontFiles () const |
If we just need the cached version of the font files, we can use this function which is const and will not update the font files. | |
void | ClearEmbeddedFonts () |
Remove all embedded fonts from the collection. | |
EMBEDDED_FILE * | GetEmbeddedFile (const wxString &aName) const |
Returns the embedded file with the given name or nullptr if it does not exist. | |
const std::map< wxString, EMBEDDED_FILE * > & | EmbeddedFileMap () const |
wxFileName | GetTemporaryFileName (const wxString &aName) const |
wxFileName | GetTemporaryFileName (EMBEDDED_FILE *aFile) const |
void | ClearEmbeddedFiles (bool aDeleteFiles=true) |
virtual void | EmbedFonts () |
virtual std::set< KIFONT::OUTLINE_FONT * > | GetFonts () const |
void | SetAreFontsEmbedded (bool aEmbedFonts) |
bool | GetAreFontsEmbedded () const |
EMBEDDED_FILES & | operator= (EMBEDDED_FILES &&other) noexcept |
EMBEDDED_FILES & | operator= (const EMBEDDED_FILES &other) |
Static Public Member Functions | |
static RETURN_CODE | CompressAndEncode (EMBEDDED_FILE &aFile) |
Take data from the #decompressedData buffer and compresses it using ZSTD into the #compressedEncodedData buffer. | |
static RETURN_CODE | DecompressAndDecode (EMBEDDED_FILE &aFile) |
Takes data from the #compressedEncodedData buffer and Base64 decodes it. | |
static uint32_t | Seed () |
Protected Attributes | |
bool | m_embedFonts = false |
If set, fonts will be embedded in the element on save. | |
Private Attributes | |
std::map< wxString, EMBEDDED_FILE * > | m_files |
std::vector< wxString > | m_fontFiles |
FileAddedCallback | m_fileAddedCallback |
Definition at line 40 of file embedded_files.h.
using EMBEDDED_FILES::FileAddedCallback = std::function<void(EMBEDDED_FILE*)> |
Definition at line 113 of file embedded_files.h.
|
strong |
Definition at line 92 of file embedded_files.h.
|
default |
|
noexcept |
Definition at line 528 of file embedded_files.cpp.
EMBEDDED_FILES::EMBEDDED_FILES | ( | const EMBEDDED_FILES & | other | ) |
Definition at line 553 of file embedded_files.cpp.
References m_fileAddedCallback, m_files, m_fontFiles, and name.
|
inline |
Definition at line 107 of file embedded_files.h.
References m_files.
EMBEDDED_FILES::EMBEDDED_FILE * EMBEDDED_FILES::AddFile | ( | const wxFileName & | aName, |
bool | aOverwrite | ||
) |
Load a file from disk and adds it to the collection.
aName | is the name of the file to load. |
aOverwrite | is true if the file should be overwritten if it already exists. |
Definition at line 42 of file embedded_files.cpp.
References CompressAndEncode(), EMBEDDED_FILES::EMBEDDED_FILE::DATASHEET, EMBEDDED_FILES::EMBEDDED_FILE::FONT, HasFile(), m_fileAddedCallback, m_files, EMBEDDED_FILES::EMBEDDED_FILE::MODEL, OK, and EMBEDDED_FILES::EMBEDDED_FILE::WORKSHEET.
Referenced by PANEL_EMBEDDED_FILES::AddEmbeddedFile(), EMBED_TOOL::AddFile(), ALTIUM_PCB::ConvertComponentBody6ToFootprintItem(), LIB_SYMBOL::EmbedFonts(), SCHEMATIC::EmbedFonts(), BOARD::EmbedFonts(), FOOTPRINT::EmbedFonts(), FOOTPRINT::FOOTPRINT(), PCB_IO_KICAD_SEXPR::format(), TEXT_BUTTON_URL::OnButtonClick(), PANEL_EMBEDDED_FILES::onFontEmbedClick(), DIALOG_PAGES_SETTINGS::OnWksFileSelection(), PANEL_EMBEDDED_FILES::PANEL_EMBEDDED_FILES(), ALTIUM_PCB::ParseComponentsBodies6Data(), EMBEDDED_FILES_PARSER::ParseEmbedded(), and PANEL_EMBEDDED_FILES::TransferDataFromWindow().
void EMBEDDED_FILES::AddFile | ( | EMBEDDED_FILE * | aFile | ) |
Append a file to the collection.
Definition at line 114 of file embedded_files.cpp.
References m_fileAddedCallback, m_files, and EMBEDDED_FILES::EMBEDDED_FILE::name.
|
inline |
Definition at line 234 of file embedded_files.h.
References m_files.
Referenced by PCB_IO_KICAD_SEXPR::format(), operator=(), and PANEL_EMBEDDED_FILES::TransferDataFromWindow().
void EMBEDDED_FILES::ClearEmbeddedFonts | ( | ) |
Remove all embedded fonts from the collection.
Definition at line 138 of file embedded_files.cpp.
References EMBEDDED_FILES::EMBEDDED_FILE::FONT, and m_files.
Referenced by SCH_IO_KICAD_SEXPR::Format(), PCB_IO_KICAD_SEXPR::SaveBoard(), and SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().
|
static |
Take data from the #decompressedData buffer and compresses it using ZSTD into the #compressedEncodedData buffer.
The data is then Base64 encoded. This call is used when adding a new file to the collection from disk.
Definition at line 211 of file embedded_files.cpp.
References MMH3_HASH::add(), EMBEDDED_FILES::EMBEDDED_FILE::compressedEncodedData, EMBEDDED_FILES::EMBEDDED_FILE::data_hash, EMBEDDED_FILES::EMBEDDED_FILE::decompressedData, MMH3_HASH::digest(), OK, OUT_OF_MEMORY, Seed(), and HASH_128::ToString().
Referenced by AddFile(), BOOST_AUTO_TEST_CASE(), ALTIUM_PCB::ConvertComponentBody6ToFootprintItem(), and ALTIUM_PCB::ParseComponentsBodies6Data().
|
static |
Takes data from the #compressedEncodedData buffer and Base64 decodes it.
The data is then decompressed using ZSTD and stored in the #decompressedData buffer. This call is used when loading the embedded files using the parsers.
Definition at line 246 of file embedded_files.cpp.
References MMH3_HASH::add(), CHECKSUM_ERROR, EMBEDDED_FILES::EMBEDDED_FILE::compressedEncodedData, EMBEDDED_FILES::EMBEDDED_FILE::data_hash, EMBEDDED_FILES::EMBEDDED_FILE::decompressedData, MMH3_HASH::digest(), EMBEDDED_FILES::EMBEDDED_FILE::name, OK, OUT_OF_MEMORY, Seed(), and HASH_128::ToString().
Referenced by BOOST_AUTO_TEST_CASE(), and EMBEDDED_FILES_PARSER::ParseEmbedded().
|
inline |
Definition at line 225 of file embedded_files.h.
References m_files.
Referenced by FOOTPRINT::FOOTPRINT(), PCB_IO_KICAD_SEXPR::format(), EMBED_TOOL::GetFileList(), PANEL_EMBEDDED_FILES::onExportFiles(), PANEL_EMBEDDED_FILES::PANEL_EMBEDDED_FILES(), SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol(), PANEL_EMBEDDED_FILES::TransferDataFromWindow(), and PANEL_EMBEDDED_FILES::TransferDataToWindow().
|
inlinevirtual |
Reimplemented in LIB_SYMBOL, SCHEMATIC, BOARD, and FOOTPRINT.
Definition at line 245 of file embedded_files.h.
|
inline |
Definition at line 257 of file embedded_files.h.
References m_embedFonts.
Referenced by PCB_IO_KICAD_SEXPR::format(), SCH_IO_KICAD_SEXPR::Format(), BRDITEMS_PLOTTER::PlotText(), PCB_IO_KICAD_SEXPR::SaveBoard(), SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol(), and PANEL_EMBEDDED_FILES::TransferDataToWindow().
|
inline |
Returns the embedded file with the given name or nullptr if it does not exist.
Definition at line 218 of file embedded_files.h.
References m_files.
Referenced by SCH_SCREEN::FixupEmbeddedData(), BOARD::FixupEmbeddedData(), and PANEL_EMBEDDED_FILES::onFontEmbedClick().
|
inline |
Return the link for an embedded file.
aFile | is the file to get the link for. |
Definition at line 161 of file embedded_files.h.
References EMBEDDED_FILES::EMBEDDED_FILE::GetLink().
Referenced by ALTIUM_PCB::ConvertComponentBody6ToFootprintItem(), and ALTIUM_PCB::ParseComponentsBodies6Data().
|
inline |
Definition at line 120 of file embedded_files.h.
References m_fileAddedCallback.
const std::vector< wxString > * EMBEDDED_FILES::GetFontFiles | ( | ) | const |
If we just need the cached version of the font files, we can use this function which is const and will not update the font files.
Definition at line 508 of file embedded_files.cpp.
References m_fontFiles.
Referenced by FIELDS_GRID_TABLE::initGrid(), SCH_IO_KICAD_SEXPR_PARSER::ParseSchematic(), SCH_PROPERTIES_PANEL::updateFontList(), and PCB_PROPERTIES_PANEL::updateLists().
|
inlinevirtual |
Reimplemented in LIB_SYMBOL, SCHEMATIC, BOARD, and FOOTPRINT.
Definition at line 247 of file embedded_files.h.
Referenced by PANEL_EMBEDDED_FILES::onFontEmbedClick().
wxFileName EMBEDDED_FILES::GetTemporaryFileName | ( | const wxString & | aName | ) | const |
Definition at line 463 of file embedded_files.cpp.
References PATHS::EnsurePathExists(), PATHS::GetUserCachePath(), and m_files.
Referenced by GetAssociatedDocument(), DIALOG_PAGES_SETTINGS::OnWksFileSelection(), FILENAME_RESOLVER::ResolvePath(), and UpdateFontFiles().
wxFileName EMBEDDED_FILES::GetTemporaryFileName | ( | EMBEDDED_FILE * | aFile | ) | const |
|
inline |
Definition at line 166 of file embedded_files.h.
Referenced by PANEL_EMBEDDED_FILES::AddEmbeddedFile(), and AddFile().
|
inline |
Definition at line 173 of file embedded_files.h.
References m_files.
Referenced by PCB_IO_KICAD_SEXPR::format(), SCH_IO_KICAD_SEXPR::Format(), and LIB_SYMBOL::GetDescription().
EMBEDDED_FILES & EMBEDDED_FILES::operator= | ( | const EMBEDDED_FILES & | other | ) |
Definition at line 564 of file embedded_files.cpp.
References ClearEmbeddedFiles(), m_embedFonts, m_fileAddedCallback, m_files, m_fontFiles, and name.
|
noexcept |
Definition at line 538 of file embedded_files.cpp.
Referenced by LIB_SYMBOL::operator=(), and FOOTPRINT::operator=().
void EMBEDDED_FILES::RemoveFile | ( | const wxString & | name, |
bool | aErase = true |
||
) |
Remove a file from the collection and frees the memory.
aName | is the name of the file to remove. |
Definition at line 124 of file embedded_files.cpp.
Referenced by PANEL_EMBEDDED_FILES::onDeleteEmbeddedFile(), PANEL_EMBEDDED_FILES::onFontEmbedClick(), PANEL_EMBEDDED_FILES::RemoveEmbeddedFile(), EMBED_TOOL::RemoveFile(), PANEL_EMBEDDED_FILES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow(), and DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow().
|
inlinestatic |
Definition at line 262 of file embedded_files.h.
Referenced by BOOST_AUTO_TEST_CASE(), CompressAndEncode(), DecompressAndDecode(), and EMBEDDED_FILES::EMBEDDED_FILE::Validate().
|
inline |
Definition at line 252 of file embedded_files.h.
References m_embedFonts.
Referenced by PCB_IO_KICAD_SEXPR_PARSER::parseBOARD_unchecked(), SCH_IO_KICAD_SEXPR_PARSER::ParseSchematic(), and PANEL_EMBEDDED_FILES::TransferDataFromWindow().
|
inline |
Definition at line 115 of file embedded_files.h.
References m_fileAddedCallback.
Referenced by PANEL_EMBEDDED_FILES::PANEL_EMBEDDED_FILES().
const std::vector< wxString > * EMBEDDED_FILES::UpdateFontFiles | ( | ) |
Helper function to get a list of fonts for fontconfig to add to the library.
This is necessary because EMBEDDED_FILES lives in common at the moment and fontconfig is in libkicommon. This will create the cache files in the KiCad cache directory (if they do not already exist) and return the temp files names
Definition at line 514 of file embedded_files.cpp.
References EMBEDDED_FILES::EMBEDDED_FILE::FONT, GetTemporaryFileName(), m_files, m_fontFiles, and name.
Referenced by SCH_SCREEN::FixupEmbeddedData(), FIELDS_GRID_TABLE::initGrid(), PCB_IO_KICAD_SEXPR_PARSER::Parse(), SCH_IO_KICAD_SEXPR_PARSER::ParseSymbol(), and SCH_PROPERTIES_PANEL::updateFontList().
void EMBEDDED_FILES::WriteEmbeddedFiles | ( | OUTPUTFORMATTER & | aOut, |
bool | aWriteData | ||
) | const |
Output formatter for the embedded files.
aOut | is the output formatter. |
aWriteData | is true if the actual data should be written. This is false when writing an element that is already embedded in a file that itself has embedded files (boards, schematics, etc.). |
Definition at line 156 of file embedded_files.cpp.
References EMBEDDED_FILES::EMBEDDED_FILE::compressedEncodedData, EMBEDDED_FILES::EMBEDDED_FILE::data_hash, EMBEDDED_FILES::EMBEDDED_FILE::DATASHEET, EMBEDDED_FILES::EMBEDDED_FILE::FONT, m_files, MIME_BASE64_LENGTH, EMBEDDED_FILES::EMBEDDED_FILE::MODEL, name, EMBEDDED_FILES::EMBEDDED_FILE::name, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), EMBEDDED_FILES::EMBEDDED_FILE::type, and EMBEDDED_FILES::EMBEDDED_FILE::WORKSHEET.
Referenced by PCB_IO_KICAD_SEXPR::format(), SCH_IO_KICAD_SEXPR::Format(), and SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().
|
protected |
If set, fonts will be embedded in the element on save.
Otherwise, font files embedded in the element will be removed on save.
Definition at line 276 of file embedded_files.h.
Referenced by FOOTPRINT::FOOTPRINT(), GetAreFontsEmbedded(), operator=(), and SetAreFontsEmbedded().
|
private |
Definition at line 273 of file embedded_files.h.
Referenced by AddFile(), EMBEDDED_FILES(), GetFileAddedCallback(), operator=(), and SetFileAddedCallback().
|
private |
Definition at line 271 of file embedded_files.h.
Referenced by AddFile(), ClearEmbeddedFiles(), ClearEmbeddedFonts(), EMBEDDED_FILES(), EmbeddedFileMap(), GetEmbeddedFile(), GetTemporaryFileName(), HasFile(), IsEmpty(), operator=(), RemoveFile(), UpdateFontFiles(), WriteEmbeddedFiles(), and ~EMBEDDED_FILES().
|
private |
Definition at line 272 of file embedded_files.h.
Referenced by EMBEDDED_FILES(), GetFontFiles(), operator=(), and UpdateFontFiles().