Use safer UTF8 conversion routines to prevent crashes.
Fixes https://gitlab.com/kicad/code/kicad/issues/10982
This commit is contained in:
parent
2c6a2c3479
commit
941d7f94ad
|
@ -34,6 +34,7 @@
|
|||
|
||||
// The "official" name of the building Kicad stroke font (always existing)
|
||||
#include <font/kicad_font_name.h>
|
||||
#include "macros.h"
|
||||
|
||||
|
||||
// markup_parser.h includes pegtl.hpp which includes windows.h... which leaks #define DrawText
|
||||
|
@ -211,11 +212,11 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
|
|||
|
||||
if( aNode->has_content() )
|
||||
{
|
||||
std::string txt = aNode->string();
|
||||
BOX2I bbox;
|
||||
BOX2I bbox;
|
||||
|
||||
nextPosition = aFont->GetTextAsGlyphs( &bbox, aGlyphs, txt, aSize, aPosition, aAngle,
|
||||
aMirror, aOrigin, textStyle );
|
||||
nextPosition = aFont->GetTextAsGlyphs( &bbox, aGlyphs, aNode->wxString(), aSize,
|
||||
aPosition, aAngle, aMirror, aOrigin,
|
||||
textStyle );
|
||||
|
||||
if( aBoundingBox )
|
||||
aBoundingBox->Merge( bbox );
|
||||
|
@ -238,7 +239,7 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYP
|
|||
const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin,
|
||||
TEXT_STYLE_FLAGS aTextStyle ) const
|
||||
{
|
||||
MARKUP::MARKUP_PARSER markupParser( aText.ToStdString() );
|
||||
MARKUP::MARKUP_PARSER markupParser( TO_UTF8( aText ) );
|
||||
std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
|
||||
|
||||
return ::drawMarkup( aBoundingBox, aGlyphs, root, aPosition, this, aSize, aAngle, aMirror,
|
||||
|
@ -348,14 +349,15 @@ void wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords,
|
|||
|
||||
if( escapeChar )
|
||||
{
|
||||
wxString word = wxString::Format( "%c{", escapeChar );
|
||||
wxString word = wxString::Format( wxT( "%c{" ), escapeChar );
|
||||
int width = 0;
|
||||
|
||||
if( aNode->has_content() )
|
||||
{
|
||||
VECTOR2I next = aFont->GetTextAsGlyphs( nullptr, nullptr, aNode->string(), aSize,
|
||||
{0,0}, ANGLE_0, false, {0,0}, textStyle );
|
||||
word += aNode->string();
|
||||
VECTOR2I next = aFont->GetTextAsGlyphs( nullptr, nullptr, aNode->wxString(),
|
||||
aSize, { 0, 0 }, ANGLE_0, false, { 0, 0 },
|
||||
textStyle );
|
||||
word += aNode->wxString();
|
||||
width += next.x;
|
||||
}
|
||||
|
||||
|
@ -370,14 +372,14 @@ void wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords,
|
|||
width += childWord.second;
|
||||
}
|
||||
|
||||
word += "}";
|
||||
word += wxT( "}" );
|
||||
aWords->emplace_back( std::make_pair( word, width ) );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString space( wxS( " " ) );
|
||||
wxString textRun( aNode->string() );
|
||||
wxString textRun = aNode->wxString();
|
||||
wxArrayString words;
|
||||
|
||||
wxStringSplit( textRun, words, ' ' );
|
||||
|
@ -403,7 +405,7 @@ void wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords,
|
|||
void FONT::wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords, const wxString& aText,
|
||||
const VECTOR2I& aSize, TEXT_STYLE_FLAGS aTextStyle ) const
|
||||
{
|
||||
MARKUP::MARKUP_PARSER markupParser( aText.ToStdString() );
|
||||
MARKUP::MARKUP_PARSER markupParser( TO_UTF8( aText ) );
|
||||
std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
|
||||
|
||||
::wordbreakMarkup( aWords, root, this, aSize, aTextStyle );
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <markup_parser.h>
|
||||
#include <sstream>
|
||||
#include "macros.h"
|
||||
|
||||
using namespace MARKUP;
|
||||
|
||||
|
@ -56,6 +57,12 @@ std::string NODE::typeString() const
|
|||
}
|
||||
|
||||
|
||||
wxString NODE::wxString() const
|
||||
{
|
||||
return FROM_UTF8( string().c_str() );
|
||||
}
|
||||
|
||||
|
||||
std::string NODE::asString() const
|
||||
{
|
||||
std::stringstream os;
|
||||
|
|
|
@ -42,6 +42,8 @@ struct NODE : parse_tree::basic_node<NODE>
|
|||
|
||||
std::string typeString() const;
|
||||
|
||||
wxString wxString() const;
|
||||
|
||||
bool isOverbar() const { return is_type<MARKUP::overbar>(); }
|
||||
bool isSubscript() const { return is_type<MARKUP::subscript>(); }
|
||||
bool isSuperscript() const { return is_type<MARKUP::superscript>(); }
|
||||
|
|
Loading…
Reference in New Issue