26#include <boost/endian/conversion.hpp>
31#include <wx/datetime.h>
32#include <wx/strconv.h>
33#include <wx/translation.h>
43 const uint8_t FMTID_SUMMARY[16] = { 0xE0, 0x85, 0x9F, 0xF2, 0xF9, 0x4F, 0x68, 0x10,
44 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 };
46 constexpr uint32_t VT_LPSTR = 30;
47 constexpr uint32_t VT_FILETIME = 64;
48 constexpr uint32_t PID_LASTSAVE_DTM = 13;
51 constexpr int64_t FILETIME_UNIX_OFFSET = 11644473600LL;
64 auto bytes = [&](
size_t aOffset,
size_t aLen ) ->
const uint8_t*
66 if( aOffset > data.size() || data.size() - aOffset < aLen )
67 THROW_IO_ERROR( wxString::Format(
_(
"Easy-PC SummaryInformation is cut short at %zu." ), aOffset ) );
69 return data.data() + aOffset;
72 auto u32 = [&](
size_t aOffset )
74 return boost::endian::load_little_u32( bytes( aOffset, 4 ) );
77 if( ( u32( 0 ) & 0xFFFF ) != 0xFFFE )
78 THROW_IO_ERROR(
_(
"Easy-PC SummaryInformation has no byte order mark." ) );
82 for( uint32_t i = 0; i < u32( 24 ) && !section; ++i )
84 if( std::memcmp( bytes( 28 +
size_t( i ) * 20, 16 ), FMTID_SUMMARY, 16 ) == 0 )
85 section = u32( 28 +
size_t( i ) * 20 + 16 );
91 static const wxCSConv cp1252( wxFONTENCODING_CP1252 );
92 std::map<uint32_t, wxString>
text;
95 for( uint32_t i = 0; i < u32( section + 4 ); ++i )
97 size_t entry = section + 8 + size_t( i ) * 8;
98 uint32_t pid = u32( entry );
99 size_t prop = section + u32( entry + 4 );
100 uint32_t type = u32( prop ) & 0xFFFF;
102 if( type == VT_LPSTR )
105 uint32_t len = u32( prop + 4 );
106 const char* chars =
reinterpret_cast<const char*
>( bytes( prop + 8, len ) );
107 text[pid] = wxString( chars, cp1252, strnlen( chars, len ) );
109 else if( type == VT_FILETIME && pid == PID_LASTSAVE_DTM )
111 uint64_t ft = u32( prop + 4 ) | ( uint64_t( u32( prop + 8 ) ) << 32 );
114 saved = wxDateTime( time_t( int64_t( ft / 10000000ULL ) - FILETIME_UNIX_OFFSET ) ).FormatISODate();
120 if( !saved.IsEmpty() )
124 for(
int i = 0; i < 4; ++i )
138 for(
bool portrait : {
false,
true } )
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetWidthMM(double aWidthInMM)
void SetHeightMM(double aHeightInMM)
double GetHeightMM() const
double GetWidthMM() const
Hold the information shown in the lower right corner of a plot, printout, or editing view.
void SetComment(int aIdx, const wxString &aComment)
void SetTitle(const wxString &aTitle)
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Title block and page size, shared by the board and schematic builders.
Loading designs, library items and projects.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
PAGE_INFO PageForExtents(const BOX2L &aExtentsNm)
Easy-PC stores no page size, so the first of A4 to A0 then A to E, landscape before portrait,...
constexpr double PAGE_MARGIN_MM
Margin added on every side of the drawn extents before choosing a page, in millimetres.
void FillTitleBlock(const DESIGN_DOCUMENT &aDoc, TITLE_BLOCK &aTitleBlock)
Fill a title block from the design's SummaryInformation property set: title from Title,...
std::vector< uint8_t > SummaryInformation
the SummaryInformation stream, if any