From 89ace3b0d029d74c6bb2a11cb506a1ed2508738e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 18 Nov 2019 11:35:42 +0000 Subject: [PATCH] Apply the overbar fixes from the stroke font to bitmap text. Fixes: lp:1852037 * https://bugs.launchpad.net/kicad/+bug/1852037 --- common/gal/opengl/opengl_gal.cpp | 18 +++++++++++++-- common/plotters/DXF_plotter.cpp | 38 ++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index ea8c68ec58..3d8ed913eb 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1178,14 +1178,28 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, bool wasOverbar = overbar; - if( *chIt == '~' ) + if( c == '~' ) { if( ++chIt == end ) break; - if( *chIt == '~' ) + c = *chIt; + + if( c == '~' ) { // double ~ is really a ~ so go ahead and process the second one + + // so what's a triple ~? It could be a real ~ followed by an overbar, or + // it could be an overbar followed by a real ~. The old algorithm did the + // later so we will too.... + auto tempIt = chIt; + + if( ++tempIt < end && *tempIt == '~' ) + { + // eat the first two, toggle overbar, and then process the third + ++chIt; + overbar = !overbar; + } } else { diff --git a/common/plotters/DXF_plotter.cpp b/common/plotters/DXF_plotter.cpp index 1a9f6def18..aebb85856f 100644 --- a/common/plotters/DXF_plotter.cpp +++ b/common/plotters/DXF_plotter.cpp @@ -980,7 +980,9 @@ void DXF_PLOTTER::Text( const wxPoint& aPos, */ bool overlining = false; + fputs( " 1\n", outputFile ); + for( unsigned i = 0; i < aText.length(); i++ ) { /* Here I do a bad thing: writing the output one byte at a time! @@ -990,6 +992,7 @@ void DXF_PLOTTER::Text( const wxPoint& aPos, Atleast stdio is *supposed* to do output buffering, so there is hope is not too slow */ wchar_t ch = aText[i]; + if( ch > 255 ) { // I can't encode this... @@ -999,14 +1002,35 @@ void DXF_PLOTTER::Text( const wxPoint& aPos, { if( ch == '~' ) { - // Handle the overline toggle - fputs( overlining ? "%%o" : "%%O", outputFile ); - overlining = !overlining; - } - else - { - putc( ch, outputFile ); + if( ++i == aText.length() ) + break; + + ch = aText[i]; + + if( ch == '~' ) + { + // double ~ is really a ~ so go ahead and process the second one + + // so what about a triple ~? It could be a real ~ followed by an + // overbar, or it could be an overbar followed by a real ~. The old + // eeschema algorithm did the later so we will too.... + if( i + i < aText.length() && aText[i + 1] == '~' ) + { + // eat the first two and toggle overbar + ++i; + fputs( overlining ? "%%o" : "%%O", outputFile ); + overlining = !overlining; + } + } + else + { + // Handle the overline toggle + fputs( overlining ? "%%o" : "%%O", outputFile ); + overlining = !overlining; + } } + + putc( ch, outputFile ); } } putc( '\n', outputFile );