From cbd665db7bfb0e66bac828c3e136d1bc76a7e5de Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 4 Jan 2022 11:52:29 +0000 Subject: [PATCH] Remove markup_parser from headers so PEGTL doesn't leak windows.h. --- common/font/font.cpp | 50 ++++++++++++++++++++++++------------- common/font/stroke_font.cpp | 8 ++---- include/font/font.h | 15 +++-------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/common/font/font.cpp b/common/font/font.cpp index c966724650..002aed166e 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -31,6 +31,11 @@ #include #include + +// markup_parser.h includes pegtl.hpp which includes windows.h... which leaks #define DrawText +#undef DrawText + + using namespace KIFONT; FONT* FONT::s_defaultFont = nullptr; @@ -261,8 +266,8 @@ VECTOR2D FONT::getBoundingBox( const UTF8& aText, TEXT_STYLE_FLAGS aTextStyle, } -void FONT::KiDrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttributes ) const +void FONT::DrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition, + const TEXT_ATTRIBUTES& aAttributes ) const { // FONT TODO: do we need to set the attributes to the gal at all? aGal->SetHorizontalJustify( aAttributes.m_Halign ); @@ -337,10 +342,10 @@ VECTOR2D FONT::Draw( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosit /** * @return position of cursor for drawing next substring */ -VECTOR2D FONT::drawMarkup( BOX2I* aBoundingBox, std::vector>& aGlyphs, - const std::unique_ptr& aNode, const VECTOR2D& aPosition, - const VECTOR2D& aGlyphSize, const EDA_ANGLE& aAngle, - TEXT_STYLE_FLAGS aTextStyle, int aLevel ) const +VECTOR2D drawMarkup( BOX2I* aBoundingBox, std::vector>& aGlyphs, + const std::unique_ptr& aNode, const VECTOR2D& aPosition, + const KIFONT::FONT* aFont, const VECTOR2D& aGlyphSize, const EDA_ANGLE& aAngle, + TEXT_STYLE_FLAGS aTextStyle ) { VECTOR2D nextPosition = aPosition; @@ -363,7 +368,8 @@ VECTOR2D FONT::drawMarkup( BOX2I* aBoundingBox, std::vectorGetTextAsGlyphs( &bbox, aGlyphs, txt, aGlyphSize, pt, aAngle, + textStyle ); if( aBoundingBox ) { @@ -377,14 +383,26 @@ VECTOR2D FONT::drawMarkup( BOX2I* aBoundingBox, std::vectorchildren ) { - nextPosition = drawMarkup( aBoundingBox, aGlyphs, child, nextPosition, aGlyphSize, aAngle, - textStyle, aLevel + 1 ); + nextPosition = drawMarkup( aBoundingBox, aGlyphs, child, nextPosition, aFont, aGlyphSize, + aAngle, textStyle ); } return nextPosition; } +VECTOR2D FONT::drawMarkup( BOX2I* aBoundingBox, std::vector>& aGlyphs, + const UTF8& aText, const VECTOR2D& aPosition, const VECTOR2D& aGlyphSize, + const EDA_ANGLE& aAngle, TEXT_STYLE_FLAGS aTextStyle ) const +{ + MARKUP::MARKUP_PARSER markupParser( aText ); + std::unique_ptr root = markupParser.Parse(); + + return ::drawMarkup( aBoundingBox, aGlyphs, root, aPosition, this, aGlyphSize, aAngle, + aTextStyle ); +} + + VECTOR2D FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const UTF8& aText, const VECTOR2D& aPosition, const VECTOR2D& aGlyphSize, const EDA_ANGLE& aAngle, bool aIsItalic, bool aIsMirrored ) const @@ -395,15 +413,13 @@ VECTOR2D FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const return aPosition; } - MARKUP::MARKUP_PARSER markupParser( aText ); - std::unique_ptr markupRoot = markupParser.Parse(); - TEXT_STYLE_FLAGS textStyle = 0; + TEXT_STYLE_FLAGS textStyle = 0; if( aIsItalic ) textStyle |= TEXT_STYLE::ITALIC; std::vector> glyphs; - VECTOR2D nextPosition = drawMarkup( aBoundingBox, glyphs, markupRoot, aPosition, aGlyphSize, + VECTOR2D nextPosition = drawMarkup( aBoundingBox, glyphs, aText, aPosition, aGlyphSize, aAngle, textStyle ); for( const std::unique_ptr& glyph : glyphs ) @@ -422,16 +438,14 @@ VECTOR2D FONT::boundingBoxSingleLine( BOX2I* aBoundingBox, const UTF8& aText, const VECTOR2D& aPosition, const VECTOR2D& aGlyphSize, const EDA_ANGLE& aAngle, bool aIsItalic ) const { - MARKUP::MARKUP_PARSER markupParser( aText ); - std::unique_ptr markupRoot = markupParser.Parse(); - TEXT_STYLE_FLAGS textStyle = 0; + TEXT_STYLE_FLAGS textStyle = 0; if( aIsItalic ) textStyle |= TEXT_STYLE::ITALIC; std::vector> glyphs; // ignored - VECTOR2D nextPosition = drawMarkup( aBoundingBox, glyphs, markupRoot, aPosition, aGlyphSize, - aAngle, false, textStyle ); + VECTOR2D nextPosition = drawMarkup( aBoundingBox, glyphs, aText, aPosition, aGlyphSize, + aAngle, textStyle ); return nextPosition; } diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index 4304ebb178..9f10559153 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -208,14 +207,11 @@ VECTOR2D STROKE_FONT::StringBoundaryLimits( const KIGFX::GAL* aGal, const UTF8& double aGlyphThickness ) const { // TODO do we need to parse every time - have we already parsed? - MARKUP::MARKUP_PARSER markupParser( aText ); - auto root = markupParser.Parse(); - std::vector> glyphs; // ignored BOX2I boundingBox; - (void) drawMarkup( &boundingBox, glyphs, root, VECTOR2D(), aGlyphSize, EDA_ANGLE::ANGLE_0, - false, 0 /* TODO: this should really include italic */ ); + (void) drawMarkup( &boundingBox, glyphs, aText, VECTOR2D(), aGlyphSize, EDA_ANGLE::ANGLE_0, + 0 /* TODO: this should really include TEXT_STYLE::ITALIC if set */ ); return boundingBox.GetSize(); } diff --git a/include/font/font.h b/include/font/font.h index 3fc11fd20e..8179104612 100644 --- a/include/font/font.h +++ b/include/font/font.h @@ -36,12 +36,6 @@ #include #include - -namespace MARKUP -{ -struct NODE; -} - namespace KIGFX { class GAL; @@ -137,8 +131,8 @@ public: return Draw( aGal, aText, aPosition, VECTOR2D( 0, 0 ), aAttributes ); } - virtual void KiDrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttributes ) const; + virtual void DrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition, + const TEXT_ATTRIBUTES& aAttributes ) const; /** * Compute the boundary limits of aText (the bounding box of all shapes). @@ -248,9 +242,8 @@ protected: TEXT_STYLE_FLAGS aTextStyle = 0 ) const = 0; VECTOR2D drawMarkup( BOX2I* aBoundingBox, std::vector>& aGlyphs, - const std::unique_ptr& aNode, const VECTOR2D& aPosition, - const VECTOR2D& aGlyphSize, const EDA_ANGLE& aAngle, - TEXT_STYLE_FLAGS aTextStyle, int aLevel = 0 ) const; + const UTF8& aText, const VECTOR2D& aPosition, const VECTOR2D& aGlyphSize, + const EDA_ANGLE& aAngle, TEXT_STYLE_FLAGS aTextStyle ) const; ///< Factor that determines the pitch between 2 lines. static constexpr double INTERLINE_PITCH_RATIO = 1.62; // The golden mean