kicad/common/font/glyph.cpp

119 lines
2.9 KiB
C++
Raw Normal View History

2021-12-31 14:07:24 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 Ola Rinta-Koski <gitlab@rinta-koski.net>
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
2021-12-31 14:07:24 +00:00
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <font/glyph.h>
using namespace KIFONT;
STROKE_GLYPH::STROKE_GLYPH( const STROKE_GLYPH& aGlyph )
{
for( const std::vector<VECTOR2D>& pointList : aGlyph )
push_back( pointList );
m_boundingBox = aGlyph.m_boundingBox;
2021-12-31 14:07:24 +00:00
}
void STROKE_GLYPH::AddPoint( const VECTOR2D& aPoint )
{
if( !m_penIsDown )
{
std::vector<VECTOR2D> v;
push_back( v );
2021-12-31 14:07:24 +00:00
m_penIsDown = true;
}
back().push_back( aPoint );
2021-12-31 14:07:24 +00:00
}
void STROKE_GLYPH::RaisePen()
{
if( m_penIsDown )
back().shrink_to_fit();
2021-12-31 14:07:24 +00:00
m_penIsDown = false;
}
void STROKE_GLYPH::Finalize()
{
if( !empty() && !back().empty() )
back().shrink_to_fit();
2021-12-31 14:07:24 +00:00
}
std::unique_ptr<GLYPH> STROKE_GLYPH::Transform( const VECTOR2D& aGlyphSize, const VECTOR2D& aOffset,
double aTilt )
2021-12-31 14:07:24 +00:00
{
std::unique_ptr<STROKE_GLYPH> glyph = std::make_unique<STROKE_GLYPH>( *this );
2021-12-31 14:07:24 +00:00
VECTOR2D end = glyph->m_boundingBox.GetEnd();
2021-12-31 14:07:24 +00:00
end.x *= aGlyphSize.x;
end.y *= aGlyphSize.y;
2021-12-31 14:07:24 +00:00
if( aTilt )
end.x -= end.y * aTilt;
2021-12-31 14:07:24 +00:00
glyph->m_boundingBox.SetEnd( end );
glyph->m_boundingBox.Offset( aOffset );
2021-12-31 14:07:24 +00:00
for( std::vector<VECTOR2D>& pointList : *glyph.get() )
2021-12-31 14:07:24 +00:00
{
for( VECTOR2D& point : pointList )
{
point.x *= aGlyphSize.x;
point.y *= aGlyphSize.y;
if( aTilt )
point.x -= point.y * aTilt;
point.x += aOffset.x;
point.y += aOffset.y;
}
}
return glyph;
}
void STROKE_GLYPH::Mirror( const VECTOR2D& aMirrorOrigin )
{
double originX = aMirrorOrigin.x;
VECTOR2D pos = m_boundingBox.GetPosition();
VECTOR2D end = m_boundingBox.GetEnd();
2021-12-31 14:07:24 +00:00
pos.x = originX - ( pos.x - originX );
end.x = originX - ( end.x - originX );
2021-12-31 14:07:24 +00:00
m_boundingBox.SetOrigin( pos );
m_boundingBox.SetEnd( end );
for( std::vector<VECTOR2D>& pointList : *this )
2021-12-31 14:07:24 +00:00
{
for( VECTOR2D& point : pointList )
point.x = originX - ( point.x - originX );
2021-12-31 14:07:24 +00:00
}
}