27 #include <compoundfilereader.h> 33 #include <wx/translation.h> 35 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const CFB::CompoundFileReader& aReader,
36 const char* aStreamName )
38 const CFB::COMPOUND_FILE_ENTRY* ret =
nullptr;
39 aReader.EnumFiles( aReader.GetRootEntry(), -1,
40 [&](
const CFB::COMPOUND_FILE_ENTRY* aEntry,
const CFB::utf16string& aU16dir,
43 if( aReader.IsStream( aEntry ) )
45 std::string
name = UTF16ToUTF8( aEntry->name );
46 if( aU16dir.length() > 0 )
48 std::string dir = UTF16ToUTF8( aU16dir.c_str() );
49 if( strncmp( aStreamName, dir.c_str(), dir.length() ) == 0
50 && aStreamName[dir.length()] ==
'\\' 51 && strcmp( aStreamName + dir.length() + 1,
name.c_str() ) == 0 )
58 if( strcmp( aStreamName,
name.c_str() ) == 0 )
70 const CFB::COMPOUND_FILE_ENTRY* aEntry )
73 m_size = static_cast<size_t>( aEntry->size );
95 std::map<wxString, wxString>
kv;
97 uint32_t length = Read<uint32_t>();
112 bool hasNullByte =
m_pos[length - 1] ==
'\0';
116 wxLogError(
_(
"Missing null byte at end of property list. Imported data might be " 117 "malformed or missing." ) );
122 std::string str = std::string(
m_pos, length - ( hasNullByte ? 1 : 0 ) );
125 std::size_t token_end = 0;
127 while( token_end < str.size() && token_end != std::string::npos )
129 std::size_t token_start = str.find(
'|', token_end );
130 std::size_t token_equal = str.find(
'=', token_start );
131 token_end = str.find(
'|', token_start + 1 );
133 if( token_equal >= token_end )
138 if( token_end == std::string::npos )
140 token_end = str.size() + 1;
143 std::string keyS = str.substr( token_start + 1, token_equal - token_start - 1 );
144 std::string valueS = str.substr( token_equal + 1, token_end - token_equal - 1 );
148 wxString key( keyS.c_str(), wxConvISO8859_1 );
150 wxString canonicalKey = key.Trim(
false ).Trim(
true ).MakeUpper();
154 if( canonicalKey.StartsWith( wxT(
"%UTF8%" ) ) )
155 value = wxString( valueS.c_str(), wxConvUTF8 );
157 value = wxString( valueS.c_str(), wxConvISO8859_1 );
161 value.Replace( wxT(
"ÿ" ), wxT(
" " ) );
163 if( canonicalKey == wxT(
"DESIGNATOR" )
164 || canonicalKey == wxT(
"NAME" )
165 || canonicalKey == wxT(
"TEXT" ) )
170 kv.insert( { canonicalKey, value.Trim() } );
179 constexpr
double int_limit = ( std::numeric_limits<int>::max() - 1 ) / 2.54;
181 int32_t iu =
KiROUND( Clamp<double>( -int_limit, aValue, int_limit ) * 2.54 );
203 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
204 return value == aProps.end() ? aDefault : wxAtoi( value->second );
211 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
213 if( value == aProps.end() )
217 std::istringstream istr( (
const char*) value->second.mb_str() );
218 istr.imbue( std::locale::classic() );
229 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
231 if( value == aProps.end() )
234 return value->second == wxT(
"T" ) || value->second == wxT(
"TRUE" );
239 const wxString& aKey,
const wxString& aDefault )
241 const wxString& value =
ReadString( aProps, aKey, aDefault );
245 if( !value.EndsWith( wxT(
"mil" ), &prefix ) )
247 wxLogError(
_(
"Unit '%s' does not end with 'mil'." ), value );
253 if( !prefix.ToCDouble( &mils ) )
255 wxLogError(
_(
"Cannot convert '%s' to double." ), prefix );
264 const wxString& aKey,
const wxString& aDefault )
266 const auto& utf8Value = aProps.find( wxString( wxT(
"%UTF8%" ) ) + aKey );
268 if( utf8Value != aProps.end() )
269 return utf8Value->second;
271 const auto& value = aProps.find( aKey );
273 if( value != aProps.end() )
274 return value->second;
size_t GetRemainingBytes() const
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
const CFB::COMPOUND_FILE_ENTRY * FindStream(const CFB::CompoundFileReader &aReader, const char *aStreamName)
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
std::map< wxString, wxString > ReadProperties()
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
ALTIUM_PARSER(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
wxString AltiumPropertyToKiCadString(const wxString &aString)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
std::unique_ptr< char[]> m_content
static int32_t ConvertToKicadUnit(const double aValue)