31#include <wx/textfile.h>
64STROKE_FONT::STROKE_FONT() :
66 m_glyphBoundingBoxes( nullptr ),
67 m_maxGlyphWidth( 0.0 )
74 if( aFontName.empty() )
93 for(
const std::vector<VECTOR2D>& pointList : *aGlyph )
95 for(
const VECTOR2D& point : pointList )
97 min.
y = std::min( min.
y, point.y );
98 max.
y = std::max( max.
y, point.y );
102 aGlyph->SetBoundingBox(
BOX2D( min, max - min ) );
118 for(
int j = 0; j < aNewStrokeFontSize; j++ )
120 std::shared_ptr<STROKE_GLYPH> glyph = std::make_shared<STROKE_GLYPH>();
122 double glyphStartX = 0.0;
123 double glyphEndX = 0.0;
124 double glyphWidth = 0.0;
128 while( aNewStrokeFont[j][i] )
131 if( aNewStrokeFont[j][i] ==
' ' && aNewStrokeFont[j][i+1] ==
'R' )
137 glyph->reserve( strokes + 1 );
141 while( aNewStrokeFont[j][i] )
144 char coordinate[2] = { 0, };
146 for(
int k : { 0, 1 } )
147 coordinate[k] = aNewStrokeFont[j][i + k];
154 glyphWidth = glyphEndX - glyphStartX;
156 else if( ( coordinate[0] ==
' ' ) && ( coordinate[1] ==
'R' ) )
177 glyph->AddPoint( point );
223 const wxString& aText,
const VECTOR2I& aSize,
225 bool aMirror,
const VECTOR2I& aOrigin,
228 constexpr double SPACE_WIDTH = 0.6;
229 constexpr double INTER_CHAR = 0.2;
230 constexpr double TAB_WIDTH = 4 * 0.82;
233 constexpr double SUPER_SUB_SIZE_MULTIPLIER = 0.7;
234 constexpr double SUPER_HEIGHT_OFFSET = 0.5;
235 constexpr double SUB_HEIGHT_OFFSET = 0.3;
243 glyphSize = glyphSize * SUPER_SUB_SIZE_MULTIPLIER;
246 cursor.y += glyphSize.
y * SUB_HEIGHT_OFFSET;
248 cursor.y -= glyphSize.
y * SUPER_HEIGHT_OFFSET;
251 for( wxUniChar c : aText )
256 int tabWidth =
KiROUND( glyphSize.
x * TAB_WIDTH );
257 int currentIntrusion = (
cursor.x - aOrigin.
x ) % tabWidth;
259 cursor.x += tabWidth - currentIntrusion;
269 int dd = (signed) c -
' ';
275 dd = (signed) c -
' ';
282 aGlyphs->push_back( source->
Transform( glyphSize,
cursor, tilt, aAngle, aMirror,
288 glyphExtents *= glyphSize;
291 glyphExtents.
x -= glyphExtents.
y * tilt;
300 double barTrim = glyphSize.
x * 0.1;
309 VECTOR2D barStart( aPosition.
x + barOffset.
x + barTrim,
cursor.y - barOffset.
y );
320 aGlyphs->push_back( overbarGlyph.
Transform( { 1.0, 1.0 }, { 0, 0 },
false,
321 aAngle, aMirror, aOrigin ) );
332 VECTOR2D barStart( aPosition.
x + barOffset.
x + barTrim,
cursor.y - barOffset.
y );
339 underlineGlyph.
AddPoint( barStart );
343 aGlyphs->push_back( underlineGlyph.
Transform( { 1.0, 1.0 }, { 0, 0 },
false,
344 aAngle, aMirror, aOrigin ) );
void SetOrigin(const Vec &pos)
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
void SetEnd(coord_type x, coord_type y)
wxString m_fontName
Font name.
wxString m_fontFileName
Font file name.
static constexpr double INTERLINE_PITCH_RATIO
Implement a stroke font drawing.
double ComputeUnderlineVerticalPosition(double aGlyphHeight) const override
Compute the vertical position of an underline.
void loadNewStrokeFont(const char *const aNewStrokeFont[], int aNewStrokeFontSize)
Load the standard KiCad stroke font.
const GLYPH_BOUNDING_BOX_LIST * m_glyphBoundingBoxes
const std::vector< std::shared_ptr< GLYPH > > * m_glyphs
double ComputeOverbarVerticalPosition(double aGlyphHeight) const override
Compute the vertical position of an overbar.
static STROKE_FONT * LoadFont(const wxString &aFontName)
Load a stroke font.
double GetInterline(double aGlyphHeight, double aLineSpacing=1.0) const override
Compute the distance (interline) between 2 lines of text (for multiline texts).
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.
void AddPoint(const VECTOR2D &aPoint)
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)
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
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 OVERBAR_POSITION_FACTOR
< Factor that determines relative vertical position of the overbar.
static constexpr double UNDERLINE_POSITION_FACTOR
Scale factor for a glyph.
static constexpr double STROKE_FONT_SCALE
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".