Change GetEffectiveTextShape() to return outline

instead of triangulated polygon
This commit is contained in:
qu1ck 2022-02-25 04:44:59 -08:00 committed by Seth Hillbrand
parent c9746fb34b
commit b06c2585d9
3 changed files with 27 additions and 11 deletions

View File

@ -847,14 +847,15 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
}
std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate ) const
{
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
KIFONT::FONT* font = GetDrawFont();
int penWidth = GetEffectiveTextPenWidth();
CALLBACK_GAL callback_gal( empty_opts,
CALLBACK_GAL callback_gal(
empty_opts,
// Stroke callback
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
{
@ -871,6 +872,15 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
shape->AddShape( triShape );
} );
if( !aTriangulate )
{
callback_gal.SetOutlineCallback(
[&]( const SHAPE_LINE_CHAIN& aPoly )
{
shape->AddShape( aPoly.Clone() );
} );
}
TEXT_ATTRIBUTES attrs = GetAttributes();
attrs.m_Angle = GetDrawRotation();

View File

@ -26,7 +26,7 @@
#include <gal/graphics_abstraction_layer.h>
class CALLBACK_GAL: public KIGFX::GAL
class CALLBACK_GAL : public KIGFX::GAL
{
public:
CALLBACK_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions,
@ -36,24 +36,30 @@ public:
const VECTOR2I& aPt2,
const VECTOR2I& aPt3 )> aTriangleCallback ) :
GAL( aDisplayOptions )
{
{
m_strokeCallback = aStrokeCallback;
m_triangleCallback = aTriangleCallback;
m_outlineCallback = [](const SHAPE_LINE_CHAIN&){};
m_outlineCallback = []( const SHAPE_LINE_CHAIN& ) {};
m_triangulate = true;
}
}
CALLBACK_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions,
std::function<void( const VECTOR2I& aPt1,
const VECTOR2I& aPt2 )> aStrokeCallback,
std::function<void( const SHAPE_LINE_CHAIN& aPoly )> aOutlineCallback ) :
GAL( aDisplayOptions )
{
{
m_strokeCallback = aStrokeCallback;
m_triangleCallback = []( const VECTOR2I&, const VECTOR2I&, const VECTOR2I& ){};
m_triangleCallback = []( const VECTOR2I&, const VECTOR2I&, const VECTOR2I& ) {};
m_outlineCallback = aOutlineCallback;
m_triangulate = false;
}
}
void SetOutlineCallback( std::function<void( const SHAPE_LINE_CHAIN& aPoly )> aOutlineCallback )
{
m_outlineCallback = aOutlineCallback;
m_triangulate = false;
}
/**
* Draw a polygon representing an outline font glyph.
@ -74,4 +80,4 @@ private:
};
#endif // define CALLBACK_GAL_H
#endif // define CALLBACK_GAL_H

View File

@ -235,7 +235,7 @@ public:
void TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCornerBuffer,
int aClearanceValue ) const;
std::shared_ptr<SHAPE_COMPOUND> GetEffectiveTextShape() const;
std::shared_ptr<SHAPE_COMPOUND> GetEffectiveTextShape( bool aTriangulate = true ) const;
/**
* Test if \a aPoint is within the bounds of this object.