KiCad PCB EDA Suite
Loading...
Searching...
No Matches
EMBEDDED_FILES Class Reference

#include <embedded_files.h>

Inheritance diagram for EMBEDDED_FILES:
BOARD FOOTPRINT LIB_SYMBOL SCHEMATIC

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
}
 

Public Member Functions

 EMBEDDED_FILES ()=default
 
 ~EMBEDDED_FILES ()
 
EMBEDDED_FILEAddFile (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_FILEGetEmbeddedFile (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
 

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
 

Detailed Description

Definition at line 39 of file embedded_files.h.

Member Enumeration Documentation

◆ RETURN_CODE

enum class EMBEDDED_FILES::RETURN_CODE : int
strong
Enumerator
OK 

Success.

FILE_NOT_FOUND 

File not found on disk.

PERMISSIONS_ERROR 

Could not read/write file.

FILE_ALREADY_EXISTS 

File already exists in the collection.

OUT_OF_MEMORY 

Could not allocate memory.

CHECKSUM_ERROR 

Checksum in file does not match data.

Definition at line 91 of file embedded_files.h.

Constructor & Destructor Documentation

◆ EMBEDDED_FILES()

EMBEDDED_FILES::EMBEDDED_FILES ( )
default

◆ ~EMBEDDED_FILES()

EMBEDDED_FILES::~EMBEDDED_FILES ( )
inline

Definition at line 103 of file embedded_files.h.

References m_files.

Member Function Documentation

◆ AddFile() [1/2]

◆ AddFile() [2/2]

void EMBEDDED_FILES::AddFile ( EMBEDDED_FILE aFile)

Append a file to the collection.

Definition at line 110 of file embedded_files.cpp.

References m_files, and EMBEDDED_FILES::EMBEDDED_FILE::name.

◆ ClearEmbeddedFiles()

void EMBEDDED_FILES::ClearEmbeddedFiles ( bool  aDeleteFiles = true)
inline

◆ ClearEmbeddedFonts()

void EMBEDDED_FILES::ClearEmbeddedFonts ( )

Remove all embedded fonts from the collection.

Definition at line 131 of file embedded_files.cpp.

References EMBEDDED_FILES::EMBEDDED_FILE::FONT, and m_files.

Referenced by SCH_IO_KICAD_SEXPR::Format(), FP_CACHE::Save(), PCB_IO_KICAD_SEXPR::SaveBoard(), and SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().

◆ CompressAndEncode()

EMBEDDED_FILES::RETURN_CODE EMBEDDED_FILES::CompressAndEncode ( EMBEDDED_FILE aFile)
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 204 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().

◆ DecompressAndDecode()

EMBEDDED_FILES::RETURN_CODE EMBEDDED_FILES::DecompressAndDecode ( EMBEDDED_FILE aFile)
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 239 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().

◆ EmbeddedFileMap()

◆ EmbedFonts()

virtual void EMBEDDED_FILES::EmbedFonts ( )
inlinevirtual

Reimplemented in LIB_SYMBOL, SCHEMATIC, BOARD, and FOOTPRINT.

Definition at line 229 of file embedded_files.h.

◆ GetAreFontsEmbedded()

◆ GetEmbeddedFile()

EMBEDDED_FILE * EMBEDDED_FILES::GetEmbeddedFile ( const wxString &  aName) const
inline

Returns the embedded file with the given name or nullptr if it does not exist.

Definition at line 202 of file embedded_files.h.

References m_files.

Referenced by SCH_SCREEN::FixupEmbeddedData(), BOARD::FixupEmbeddedData(), and PANEL_EMBEDDED_FILES::onFontEmbedClick().

◆ GetEmbeddedFileLink()

wxString EMBEDDED_FILES::GetEmbeddedFileLink ( const EMBEDDED_FILE aFile) const
inline

Return the link for an embedded file.

Parameters
aFileis the file to get the link for.
Returns
the link for the file to be used in a hyperlink.

Definition at line 145 of file embedded_files.h.

References EMBEDDED_FILES::EMBEDDED_FILE::GetLink().

Referenced by ALTIUM_PCB::ConvertComponentBody6ToFootprintItem(), and ALTIUM_PCB::ParseComponentsBodies6Data().

◆ GetFontFiles()

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 501 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().

◆ GetFonts()

virtual std::set< KIFONT::OUTLINE_FONT * > EMBEDDED_FILES::GetFonts ( ) const
inlinevirtual

Reimplemented in LIB_SYMBOL, SCHEMATIC, BOARD, and FOOTPRINT.

Definition at line 231 of file embedded_files.h.

Referenced by PANEL_EMBEDDED_FILES::onFontEmbedClick().

◆ GetTemporaryFileName() [1/2]

wxFileName EMBEDDED_FILES::GetTemporaryFileName ( const wxString &  aName) const

◆ GetTemporaryFileName() [2/2]

wxFileName EMBEDDED_FILES::GetTemporaryFileName ( EMBEDDED_FILE aFile) const

◆ HasFile()

bool EMBEDDED_FILES::HasFile ( const wxString &  name) const
inline

◆ IsEmpty()

bool EMBEDDED_FILES::IsEmpty ( ) const
inline

◆ RemoveFile()

void EMBEDDED_FILES::RemoveFile ( const wxString &  name,
bool  aErase = true 
)

Remove a file from the collection and frees the memory.

Parameters
aNameis the name of the file to remove.

Definition at line 117 of file embedded_files.cpp.

References m_files, and name.

Referenced by PANEL_EMBEDDED_FILES::onDeleteEmbeddedFile(), PANEL_EMBEDDED_FILES::onFontEmbedClick(), EMBED_TOOL::RemoveFile(), and PANEL_EMBEDDED_FILES::TransferDataFromWindow().

◆ Seed()

static uint32_t EMBEDDED_FILES::Seed ( )
inlinestatic

◆ SetAreFontsEmbedded()

void EMBEDDED_FILES::SetAreFontsEmbedded ( bool  aEmbedFonts)
inline

◆ UpdateFontFiles()

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 507 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().

◆ WriteEmbeddedFiles()

void EMBEDDED_FILES::WriteEmbeddedFiles ( OUTPUTFORMATTER aOut,
bool  aWriteData 
) const

Output formatter for the embedded files.

Parameters
aOutis the output formatter.
aWriteDatais 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 149 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().

Member Data Documentation

◆ m_embedFonts

bool EMBEDDED_FILES::m_embedFonts = false
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 256 of file embedded_files.h.

Referenced by FOOTPRINT::FOOTPRINT(), GetAreFontsEmbedded(), and SetAreFontsEmbedded().

◆ m_files

◆ m_fontFiles

std::vector<wxString> EMBEDDED_FILES::m_fontFiles
private

Definition at line 253 of file embedded_files.h.

Referenced by GetFontFiles(), and UpdateFontFiles().


The documentation for this class was generated from the following files: