25#include <wx/textfile.h>
63 if( aFontName.empty() )
82 for(
const std::vector<VECTOR2D>& pointList : *aGlyph )
84 for(
const VECTOR2D& point : pointList )
86 min.
y = std::min( min.
y, point.y );
87 max.
y = std::max( max.
y, point.y );
91 aGlyph->SetBoundingBox(
BOX2D( min, max - min ) );
107 for(
int j = 0; j < aNewStrokeFontSize; j++ )
109 std::shared_ptr<STROKE_GLYPH> glyph = std::make_shared<STROKE_GLYPH>();
111 double glyphStartX = 0.0;
112 double glyphEndX = 0.0;
113 double glyphWidth = 0.0;
117 while( aNewStrokeFont[j][i] )
119 if( aNewStrokeFont[j][i] ==
' ' && aNewStrokeFont[j][i+1] ==
'R' )
125 glyph->reserve( strokes + 1 );
129 while( aNewStrokeFont[j][i] )
132 char coordinate[2] = { 0, };
134 for(
int k : { 0, 1 } )
135 coordinate[k] = aNewStrokeFont[j][i + k];
142 glyphWidth = glyphEndX - glyphStartX;
144 else if( ( coordinate[0] ==
' ' ) && ( coordinate[1] ==
'R' ) )
165 glyph->AddPoint( point );
192 static double LEGACY_FACTOR = 0.9583;
194 return aFontMetrics.
GetInterline( aGlyphHeight ) * LEGACY_FACTOR;
199 const wxString& aText,
const VECTOR2I& aSize,
201 bool aMirror,
const VECTOR2I& aOrigin,
204 constexpr int TAB_WIDTH = 4;
205 constexpr double INTER_CHAR = 0.2;
206 constexpr double SUPER_SUB_SIZE_MULTIPLIER = 0.8;
207 constexpr double SUPER_HEIGHT_OFFSET = 0.35;
208 constexpr double SUB_HEIGHT_OFFSET = 0.15;
218 glyphSize = glyphSize * SUPER_SUB_SIZE_MULTIPLIER;
221 cursor.y += glyphSize.
y * SUB_HEIGHT_OFFSET;
223 cursor.y -= glyphSize.
y * SUPER_HEIGHT_OFFSET;
226 for( wxUniChar c : aText )
231 char_count = ( char_count / TAB_WIDTH + 1 ) * TAB_WIDTH - 1;
233 int new_cursor = aPosition.
x + aSize.
x * char_count
234 + aSize.
x * space_width;
236 while( new_cursor <=
cursor.x )
238 char_count += TAB_WIDTH;
239 new_cursor += aSize.
x * TAB_WIDTH;
252 int dd = (signed) c -
' ';
258 dd = (signed) c -
' ';
265 aGlyphs->push_back( source->
Transform( glyphSize,
cursor, tilt, aAngle, aMirror,
271 glyphExtents *= glyphSize;
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr const Vec GetEnd() const
constexpr void SetOrigin(const Vec &pos)
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr void SetEnd(coord_type x, coord_type y)
wxString m_fontName
Font name.
wxString m_fontFileName
Font file name.
double GetInterline(double aFontHeight) const
double GetInterline(double aGlyphHeight, const METRICS &aFontMetrics) const override
Compute the distance (interline) between 2 lines of text (for multiline texts).
void loadNewStrokeFont(const char *const aNewStrokeFont[], int aNewStrokeFontSize)
Load the standard KiCad stroke font.
const STROKE_GLYPH * GetGlyph(unsigned aIndex) const
const BOX2D & GetGlyphBoundingBox(unsigned aIndex) const
const std::vector< BOX2D > * m_glyphBoundingBoxes
const std::vector< std::shared_ptr< GLYPH > > * m_glyphs
static STROKE_FONT * LoadFont(const wxString &aFontName)
Load a stroke font.
unsigned GetGlyphCount() const
VECTOR2I GetTextAsGlyphs(BOX2I *aBoundingBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aSize, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, TEXT_STYLE_FLAGS aTextStyle) const override
Convert text string to an array of GLYPHs.
BOX2D BoundingBox() override
std::unique_ptr< GLYPH > Transform(const VECTOR2D &aGlyphSize, const VECTOR2I &aOffset, double aTilt, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin)
static bool empty(const wxTextEntryBase *aCtrl)
unsigned int TEXT_STYLE_FLAGS
static constexpr double ITALIC_TILT
Tilt factor for italic style (this is the scaling factor on dY relative coordinates to give a tilted ...
const int newstroke_font_bufsize
const char *const newstroke_font[]
Modified 2019 to include based CJK Unicode Ideographs, using code copyright (c) 2018 Lingdong Huang.
static constexpr int FONT_OFFSET
Offset (in stroke font units) to move the origin to the baseline.
std::mutex g_defaultFontLoadMutex
std::vector< std::shared_ptr< GLYPH > > g_defaultFontGlyphs
bool g_defaultFontInitialized
std::vector< BOX2D > * g_defaultFontGlyphBoundingBoxes
void buildGlyphBoundingBox(std::shared_ptr< STROKE_GLYPH > &aGlyph, double aGlyphWidth)
static constexpr double STROKE_FONT_SCALE
Scale factor for a glyph.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D