dxf and svg import: accept unicode filenames
Fixes: lp:1805613 https://bugs.launchpad.net/kicad/+bug/1805613
This commit is contained in:
parent
766156ed87
commit
5b3202d8f3
|
@ -117,12 +117,44 @@ DL_Dxf::~DL_Dxf()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads the given file and calls the appropriate functions in
|
||||
* the given creation interface for every entity found in the file.
|
||||
*
|
||||
* @param file Input the file pointer to read
|
||||
* @param creationInterface
|
||||
* Pointer to the class which takes care of the entities in the file.
|
||||
*
|
||||
* @retval true if fp is valid (i.e. not NULL), false otherwise.
|
||||
*/
|
||||
bool DL_Dxf::in( FILE* fp, DL_CreationInterface* creationInterface )
|
||||
{
|
||||
firstCall = true;
|
||||
currentObjectType = DL_UNKNOWN;
|
||||
|
||||
if( fp )
|
||||
{
|
||||
std::locale oldLocale = std::locale::global( std::locale( "C" ) ); // use dot in numbers
|
||||
|
||||
while( readDxfGroups( fp, creationInterface ) )
|
||||
{
|
||||
}
|
||||
|
||||
std::locale::global( oldLocale );
|
||||
fclose( fp );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads the given file and calls the appropriate functions in
|
||||
* the given creation interface for every entity found in the file.
|
||||
*
|
||||
* @param file Input
|
||||
* Path and name of file to read
|
||||
* Note: file is not very well utf8 compatible, depending on the platform.
|
||||
* @param creationInterface
|
||||
* Pointer to the class which takes care of the entities in the file.
|
||||
*
|
||||
|
|
|
@ -124,10 +124,9 @@ public:
|
|||
DL_Dxf();
|
||||
~DL_Dxf();
|
||||
|
||||
bool in( const std::string& file,
|
||||
DL_CreationInterface* creationInterface );
|
||||
bool readDxfGroups( FILE* fp,
|
||||
DL_CreationInterface* creationInterface );
|
||||
bool in( FILE* fp, DL_CreationInterface* creationInterface );
|
||||
bool in( const std::string& file, DL_CreationInterface* creationInterface );
|
||||
bool readDxfGroups( FILE* fp, DL_CreationInterface* creationInterface );
|
||||
static bool getStrippedLine( std::string& s, unsigned int size,
|
||||
FILE* stream, bool stripSpace = true );
|
||||
|
||||
|
|
|
@ -133,14 +133,18 @@ double DXF_IMPORT_PLUGIN::mapWidth( double aDxfWidth )
|
|||
|
||||
bool DXF_IMPORT_PLUGIN::ImportDxfFile( const wxString& aFile )
|
||||
{
|
||||
LOCALE_IO locale;
|
||||
|
||||
DL_Dxf dxf_reader;
|
||||
std::string filename = TO_UTF8( aFile );
|
||||
bool success = true;
|
||||
|
||||
if( !dxf_reader.in( filename, this ) ) // if file open failed
|
||||
success = false;
|
||||
// wxFopen takes care of unicode filenames across platforms
|
||||
FILE* fp = wxFopen( aFile, "rt" );
|
||||
|
||||
if( fp == nullptr )
|
||||
return false;
|
||||
|
||||
// Note the dxf reader takes care of switching to "C" locale before reading the file
|
||||
// and will close the file after reading
|
||||
bool success = dxf_reader.in( fp, this );
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include "nanosvg.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
@ -3668,17 +3667,14 @@ NSVGimage* nsvgParse( char* input, const char* units, float dpi )
|
|||
}
|
||||
|
||||
|
||||
NSVGimage* nsvgParseFromFile( const char* filename, const char* units, float dpi )
|
||||
NSVGimage* nsvgParseFromFile( FILE *fp, const char* units, float dpi )
|
||||
{
|
||||
FILE* fp = NULL;
|
||||
size_t size;
|
||||
char* data = NULL;
|
||||
NSVGimage* image = NULL;
|
||||
|
||||
fp = fopen( filename, "rb" );
|
||||
|
||||
if( !fp )
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
fseek( fp, 0, SEEK_END );
|
||||
size = ftell( fp );
|
||||
|
|
|
@ -66,6 +66,8 @@
|
|||
nsvgDelete(image);
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
enum NSVGpaintType {
|
||||
NSVG_PAINT_NONE = 0,
|
||||
NSVG_PAINT_COLOR = 1,
|
||||
|
@ -158,7 +160,8 @@ typedef struct NSVGimage
|
|||
} NSVGimage;
|
||||
|
||||
// Parses SVG file from a file, returns SVG image as paths.
|
||||
NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi);
|
||||
// fp will be closed after reading the file
|
||||
NSVGimage* nsvgParseFromFile( FILE* fp, const char* units, float dpi);
|
||||
|
||||
// Parses SVG file from a null terminated string, returns SVG image as paths.
|
||||
// Important note: changes the string.
|
||||
|
|
|
@ -55,7 +55,14 @@ bool SVG_IMPORT_PLUGIN::Load( const wxString& aFileName )
|
|||
{
|
||||
wxCHECK( m_importer, false );
|
||||
|
||||
m_parsedImage = nsvgParseFromFile( aFileName.c_str(), "mm", 96 );
|
||||
// wxFopen takes care of unicode filenames across platforms
|
||||
FILE* fp = wxFopen( aFileName, "rt" );
|
||||
|
||||
if( fp == nullptr )
|
||||
return false;
|
||||
|
||||
// nsvgParseFromFile will close the file after reading
|
||||
m_parsedImage = nsvgParseFromFile( fp, "mm", 96 );
|
||||
|
||||
wxCHECK( m_parsedImage, false );
|
||||
|
||||
|
|
Loading…
Reference in New Issue