Remove markup_parser from headers so PEGTL doesn't leak windows.h.

This commit is contained in:
Jeff Young 2022-01-04 11:52:29 +00:00
parent 38a25fbc4d
commit cbd665db7b
3 changed files with 38 additions and 35 deletions

View File

@ -31,6 +31,11 @@
#include <trigo.h>
#include <markup_parser.h>
// 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,7 +266,7 @@ VECTOR2D FONT::getBoundingBox( const UTF8& aText, TEXT_STYLE_FLAGS aTextStyle,
}
void FONT::KiDrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition,
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?
@ -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<std::unique_ptr<GLYPH>>& aGlyphs,
VECTOR2D drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>& aGlyphs,
const std::unique_ptr<MARKUP::NODE>& aNode, const VECTOR2D& aPosition,
const VECTOR2D& aGlyphSize, const EDA_ANGLE& aAngle,
TEXT_STYLE_FLAGS aTextStyle, int aLevel ) const
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::vector<std::unique_ptr<GLYP
wxPoint pt( aPosition.x, aPosition.y );
BOX2I bbox;
nextPosition = GetTextAsGlyphs( &bbox, aGlyphs, txt, aGlyphSize, pt, aAngle, textStyle );
nextPosition = aFont->GetTextAsGlyphs( &bbox, aGlyphs, txt, aGlyphSize, pt, aAngle,
textStyle );
if( aBoundingBox )
{
@ -377,14 +383,26 @@ VECTOR2D FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYP
for( const auto& child : aNode->children )
{
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<std::unique_ptr<GLYPH>>& 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<MARKUP::NODE> 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<MARKUP::NODE> markupRoot = markupParser.Parse();
TEXT_STYLE_FLAGS textStyle = 0;
if( aIsItalic )
textStyle |= TEXT_STYLE::ITALIC;
std::vector<std::unique_ptr<GLYPH>> 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>& 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<MARKUP::NODE> markupRoot = markupParser.Parse();
TEXT_STYLE_FLAGS textStyle = 0;
if( aIsItalic )
textStyle |= TEXT_STYLE::ITALIC;
std::vector<std::unique_ptr<GLYPH>> 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;
}

View File

@ -32,7 +32,6 @@
#include <newstroke_font.h>
#include <font/glyph.h>
#include <font/stroke_font.h>
#include <markup_parser.h>
#include <geometry/shape_line_chain.h>
#include <trigo.h>
@ -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<std::unique_ptr<GLYPH>> 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();
}

View File

@ -36,12 +36,6 @@
#include <font/glyph.h>
#include <font/text_attributes.h>
namespace MARKUP
{
struct NODE;
}
namespace KIGFX
{
class GAL;
@ -137,7 +131,7 @@ public:
return Draw( aGal, aText, aPosition, VECTOR2D( 0, 0 ), aAttributes );
}
virtual void KiDrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition,
virtual void DrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttributes ) const;
/**
@ -248,9 +242,8 @@ protected:
TEXT_STYLE_FLAGS aTextStyle = 0 ) const = 0;
VECTOR2D drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>& aGlyphs,
const std::unique_ptr<MARKUP::NODE>& 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