Add bezier rendering.

This commit is contained in:
jmsgrogan 2023-01-11 08:26:08 +00:00
parent b7f75f903e
commit 1eeaebd0a9
3 changed files with 65 additions and 33 deletions

View file

@ -1,21 +1,22 @@
#include "FontGlyph.h"
void GlyphRunOutlines::addToFeature(const Point& point)
void GlyphRunOutlines::addSegment(const GlyphRunSegment& segment)
{
mFeatures[mFeatures.size() - 1].mPoints.push_back(point);
mFeatures[mFeatures.size() - 1].mSegments.push_back(segment);
}
void GlyphRunOutlines::startFeature(const Point& point, bool isFilled)
{
GlyphRunOutline feature;
GlyphRunFeature feature;
feature.mFilled = isFilled;
feature.mPoints.push_back(point);
mFeatures.push_back(feature);
}
const std::vector<GlyphRunOutline> GlyphRunOutlines::getFeatures() const
{
return mFeatures;
GlyphRunSegment segment;
segment.mType = GlyphRunSegment::Type::POINT;
segment.mPoints.push_back(point);
feature.mSegments.push_back(segment);
mFeatures.push_back(feature);
}
std::string GlyphRunOutlines::toPostScriptPath()
@ -23,15 +24,31 @@ std::string GlyphRunOutlines::toPostScriptPath()
std::string path;
for (const auto& feature : mFeatures)
{
if (feature.mPoints.empty())
if (feature.mSegments.empty())
{
continue;
}
auto last_point = feature.mPoints[0];
path += "M" + std::to_string(last_point.getX()) + " " + std::to_string(last_point.getY()) + " ";
for (std::size_t idx = 1; idx < feature.mPoints.size(); idx++)
auto start_point = feature.mSegments[0].mPoints[0];
path += "M" + std::to_string(start_point.getX()) + " " + std::to_string(start_point.getY()) + " ";
for (std::size_t idx = 1; idx < feature.mSegments.size(); idx++)
{
path += "L" + std::to_string(feature.mPoints[idx].getX()) + " " + std::to_string(feature.mPoints[idx].getY()) + " ";
if (feature.mSegments[idx].mType == GlyphRunSegment::Type::LINE)
{
for (const auto& point : feature.mSegments[idx].mPoints)
{
path += "L" + std::to_string(point.getX()) + " " + std::to_string(point.getY()) + " ";
}
}
else if (feature.mSegments[idx].mType == GlyphRunSegment::Type::BEZIER)
{
path += "C";
for (const auto& point : feature.mSegments[idx].mPoints)
{
path += std::to_string(point.getX()) + " " + std::to_string(point.getY()) + " ";
}
}
}
path += "z ";
}