Commit c2648237 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

8 bit string relief via class UTF8

parent f3467272
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -273,8 +273,8 @@ FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName )
                     wxString::Format( wxT( "'%s' is not a valid FPID." ),
                                       GetChars( aFootprintName ) ) );

        wxString libNickname   = FROM_UTF8( fpid.GetLibNickname().c_str() );
        wxString footprintName = FROM_UTF8( fpid.GetFootprintName().c_str() );
        wxString libNickname   = fpid.GetLibNickname();
        wxString footprintName = fpid.GetFootprintName();

        if( libNickname == fp.GetNickname() && footprintName == fp.GetFootprintName() )
            return &fp;
+18 −18
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ MODULE* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxString&
        FPID& fpid = (FPID&) ret->GetFPID();

        // Catch any misbehaving plugin, which should be setting internal footprint name properly:
        wxASSERT( aFootprintName == FROM_UTF8( fpid.GetFootprintName().c_str() ) );
        wxASSERT( aFootprintName == (wxString) fpid.GetFootprintName() );

        // and clearing nickname
        wxASSERT( !fpid.GetLibNickname().size() );
@@ -195,7 +195,7 @@ FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave( const wxString& aNickname, con
        // Try loading the footprint to see if it already exists, caller wants overwrite
        // protection, which is atypical, not the default.

        wxString fpname = FROM_UTF8( aFootprint->GetFPID().GetFootprintName().c_str() );
        wxString fpname = aFootprint->GetFPID().GetFootprintName();

        std::auto_ptr<MODULE>   m( row->plugin->FootprintLoad( row->GetFullURI( true ), fpname, row->GetProperties() ) );

@@ -480,16 +480,17 @@ PROPERTIES* FP_LIB_TABLE::ParseOptions( const std::string& aOptionsList )
}


std::string FP_LIB_TABLE::FormatOptions( const PROPERTIES* aProperties )
UTF8 FP_LIB_TABLE::FormatOptions( const PROPERTIES* aProperties )
{
    std::string ret;
    UTF8 ret;

    if( aProperties )
    {
        for( PROPERTIES::const_iterator it = aProperties->begin();  it != aProperties->end();  ++it )
        {
            const std::string& name  = it->first;
            const std::string& value = it->second;

            const UTF8& value = it->second;

            if( ret.size() )
                ret += OPT_SEP;
@@ -741,7 +742,7 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
                {
                    if( aReporter )
                    {
                        msg.Printf( _( "Cannot find footprint library file \"%s\" in any of the "
                        msg.Printf( _( "Cannot find footprint library file '%s' in any of the "
                                       "KiCad legacy library search paths.\n" ),
                                    GetChars( fn.GetFullPath() ) );
                        aReporter->Report( msg );
@@ -751,8 +752,7 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
                    continue;
                }

                module = pi->FootprintLoad( libPath,
                                            FROM_UTF8( component->GetFPID().GetFootprintName().c_str() ) );
                module = pi->FootprintLoad( libPath, component->GetFPID().GetFootprintName() );

                if( module )
                {
@@ -766,10 +766,10 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
        {
            if( aReporter )
            {
                msg.Printf( _( "Component `%s` footprint <%s> was not found in any legacy "
                msg.Printf( _( "Component `%s` footprint '%s' was not found in any legacy "
                               "library.\n" ),
                            GetChars( component->GetReference() ),
                            GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
                            GetChars( component->GetFPID().Format() ) );
                aReporter->Report( msg );
            }

@@ -811,10 +811,10 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
            {
                if( aReporter )
                {
                    msg.Printf( _( "Component `%s` footprint <%s> legacy library path <%s > "
                    msg.Printf( _( "Component `%s` footprint '%s' legacy library path <%s > "
                                   "was not found in the footprint library table.\n" ),
                                GetChars( component->GetReference() ),
                                GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
                                GetChars( component->GetFPID().Format() ) );
                    aReporter->Report( msg );
                }

@@ -830,9 +830,9 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
                {
                    if( aReporter )
                    {
                        msg.Printf( _( "Component `%s` FPID <%s> is not valid.\n" ),
                        msg.Printf( _( "Component `%s` FPID '%s' is not valid.\n" ),
                                    GetChars( component->GetReference() ),
                                    GetChars( FROM_UTF8( newFPID.Format().c_str() ) ) );
                                    GetChars( newFPID.Format() ) );
                        aReporter->Report( msg );
                    }

@@ -860,7 +860,7 @@ void FP_LIB_TABLE::SetProjectPathEnvVariable( const wxFileName& aPath )
    else
        path = aPath.GetPath();

    wxLogTrace( traceFpLibTable, wxT( "Setting env %s to <%s>." ),
    wxLogTrace( traceFpLibTable, wxT( "Setting env %s to '%s'." ),
                GetChars( ProjectPathEnvVariableName() ), GetChars( path ) );
    wxSetEnv( ProjectPathEnvVariableName(), path );
}
@@ -899,7 +899,7 @@ wxString FP_LIB_TABLE::GetProjectFileName( const wxFileName& aPath )
        fn.SetName( defaultFileName );
    }

    wxLogTrace( traceFpLibTable, wxT( "Project specific footprint library table file <%s>." ),
    wxLogTrace( traceFpLibTable, wxT( "Project specific footprint library table file '%s'." ),
                GetChars( fn.GetFullPath() ) );

    return fn.GetFullPath();
@@ -917,7 +917,7 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARS

        if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
        {
            THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path <%s>." ),
            THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
                                              GetChars( fn.GetPath() ) ) );
        }

@@ -954,7 +954,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()

    fn.SetName( GetFileName() );

    wxLogTrace( traceFpLibTable, wxT( "Global footprint library table file <%s>." ),
    wxLogTrace( traceFpLibTable, wxT( "Global footprint library table file '%s'." ),
                GetChars( fn.GetFullPath() ) );

    return fn.GetFullPath();
+6 −6
Original line number Diff line number Diff line
@@ -265,9 +265,9 @@ int FPID::SetRevision( const std::string& aRevision )
}


std::string FPID::Format() const
UTF8 FPID::Format() const
{
    std::string  ret;
    UTF8    ret;

    if( nickname.size() )
    {
@@ -287,9 +287,9 @@ std::string FPID::Format() const
}


std::string FPID::GetFootprintNameAndRev() const
UTF8 FPID::GetFootprintNameAndRev() const
{
    std::string ret;
    UTF8 ret;

    if( revision.size() )
    {
@@ -301,11 +301,11 @@ std::string FPID::GetFootprintNameAndRev() const
}


std::string FPID::Format( const std::string& aLogicalLib, const std::string& aFootprintName,
UTF8 FPID::Format( const std::string& aLogicalLib, const std::string& aFootprintName,
                          const std::string& aRevision )
    throw( PARSE_ERROR )
{
    std::string  ret;
    UTF8    ret;
    int     offset;

    if( aLogicalLib.size() )
+17 −16
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ BOX2D STROKE_FONT::computeBoundingBox( const GLYPH& aGLYPH, const VECTOR2D& aGLY
}


void STROKE_FONT::Draw( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle )
void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRotationAngle )
{
    // Context needs to be saved before any transformations
    m_gal->Save();
@@ -192,7 +192,7 @@ void STROKE_FONT::Draw( const wxString& aText, const VECTOR2D& aPosition, double
    {
        size_t length = newlinePos - begin;

        drawSingleLineText( aText.Mid( begin, length ) );
        drawSingleLineText( aText.substr( begin, length ) );
        m_gal->Translate( VECTOR2D( 0.0, lineHeight ) );

        begin = newlinePos + 1;
@@ -200,14 +200,14 @@ void STROKE_FONT::Draw( const wxString& aText, const VECTOR2D& aPosition, double
    }

    // Draw the last (or the only one) line
    if( !aText.IsEmpty() )
        drawSingleLineText( aText.Mid( begin ) );
    if( !aText.empty() )
        drawSingleLineText( aText.substr( begin ) );

    m_gal->Restore();
}


void STROKE_FONT::drawSingleLineText( const wxString& aText )
void STROKE_FONT::drawSingleLineText( const UTF8& aText )
{
    // By default the overbar is turned off
    m_overbar = false;
@@ -254,12 +254,12 @@ void STROKE_FONT::drawSingleLineText( const wxString& aText )
        xOffset = 0.0;
    }

    for( wxString::const_iterator chIt = aText.begin(); chIt != aText.end(); ++chIt )
    for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
    {
        // Toggle overbar
        if( *chIt == '~' )
        {
            if( ++chIt == aText.end() )
            if( ++chIt >= end )
                break;

            if( *chIt != '~' )      // It was a single tilda, it toggles overbar
@@ -281,6 +281,7 @@ void STROKE_FONT::drawSingleLineText( const wxString& aText )
            VECTOR2D startOverbar( xOffset, -getInterline() * OVERBAR_HEIGHT );
            VECTOR2D endOverbar( xOffset + glyphSize.x * bbox.GetEnd().x,
                                 -getInterline() * OVERBAR_HEIGHT );

            m_gal->DrawLine( startOverbar, endOverbar );
        }

@@ -317,25 +318,25 @@ void STROKE_FONT::drawSingleLineText( const wxString& aText )
}


VECTOR2D STROKE_FONT::computeTextSize( const wxString& aText ) const
VECTOR2D STROKE_FONT::computeTextSize( const UTF8& aText ) const
{
    VECTOR2D result = VECTOR2D( 0.0, m_glyphSize.y );

    for( wxString::const_iterator chIt = aText.begin(); chIt != aText.end(); ++chIt )
    for( UTF8::uni_iter it = aText.ubegin(), end = aText.uend(); it < end; ++it )
    {
        wxASSERT_MSG( *chIt != '\n',
        wxASSERT_MSG( *it != '\n',
                      wxT( "This function is intended to work with single line strings" ) );

        // If it is double tilda, then it is displayed as a single tilda
        // If it is single tilda, then it is toggling overbar, so we need to skip it
        if( *chIt == '~' )
        if( *it == '~' )
        {
            if( ++chIt == aText.end() )
            if( ++it >= end )
                break;
        }

        // Index in the bounding boxes table
        unsigned dd = *chIt - ' ';
        unsigned dd = *it - ' ';

        if( dd >= m_glyphBoundingBoxes.size() || dd < 0 )
            dd = '?' - ' ';
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

#include <utf8.h>

/* THROW_IO_ERROR needs this, but it will soon be including this file, so until some
/* THROW_IO_ERROR needs this, but it includes this file, so until some
    factoring of THROW_IO_ERROR into a separate header, defer and use the asserts.
#include <richio.h>
*/
@@ -33,7 +33,7 @@

/*
    These are not inlined so that code space is saved by encapsulating the
    creation of intermediate objects and referencing wxConvUTF8.
    creation of intermediate objects and the referencing of wxConvUTF8.
*/


Loading