Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom transform implementation to convert text to paths
//-----------------------------------------------------------------------
// <copyright file="GlyphTransformImplementation.h" company="Global Graphics Software Ltd">
// Copyright (c) 2019 Global Graphics Software Ltd. All rights reserved.
// </copyright>
// <summary>
// This example is provided on an "as is" basis and without warranty of any kind.
// Global Graphics Software Ltd. does not warrant or make any representations regarding the use or
// results of use of this example.
// </summary>
//-----------------------------------------------------------------------
#pragma once
#include "customtransform.h"
using namespace JawsMako;
using namespace EDL;
// Convenient macro for dealing with APIs that do not yet use exceptions for
#define THROW_IF(statement, errorcode) do { if (statement) throwEDLError(errorcode); } while(false)
class GlyphTransformImplementation : public ICustomTransform::IImplementation
{
public:
// Constructor to get everything ready.
GlyphTransformImplementation(const IJawsMakoPtr &jawsMako, const float &width, const IDOMBrushPtr &brush)
{
THROW_IF(!jawsMako, EDL_ERR_BAD_ARGUMENTS);
m_jawsMako = jawsMako;
m_width = width;
m_brush = brush;
}
// Destructor
~GlyphTransformImplementation() { }
//
// Here we provide implementations for the ICustomTransform entry points we are interested in.
//
IDOMNodePtr transformGlyphs(IImplementation *genericImplementation, const IDOMGlyphsPtr &glyphs, bool &changed, const CTransformState &state) override
{
// Create paths from the glyphs
IDOMPathNodePtr path;
if (glyphs->getEquivalentPath(path))
{
// Scale the width value
FMatrix renderTransform;
path->getRenderTransform(renderTransform);
const float strokeWidth = m_width / float(renderTransform.getScale());
// Stroke the path if the width is greater than zero, otherwise fill it
if (strokeWidth > 0.0f){
path->setFill(IDOMBrushPtr());
path->setStrokeThickness(strokeWidth);
path->setStrokeMiterLimitTreatment(IDOMPathNode::eBevelLongMiters);
path->setStroke(m_brush);
// Ensure all segments are stroked
IDOMPathGeometryPtr geometry;
path->getPathData(geometry);
IDOMFigureCollectionEnumPtr figures = geometry->getFigureCollectionEnum();
figures->reset();
IDOMPathFigurePtr figure;
while (figures->getNext(&figure) && figure)
{
IDOMSegmentCollectionEnumPtr segments = figure->getSegmentCollectionEnum();
segments->reset();
IDOMPathSegmentPtr segment;
while (segments->getNext(&segment) && segment)
{
segment->setIsStroked(true);
}
}
}
else {
path->setFill(m_brush);
}
changed = true;
const IDOMNodePtr pathNode = path;
return pathNode;
}
return genericImplementation->transformGlyphs(NULL, glyphs, changed, state);
}
private:
IJawsMakoPtr m_jawsMako;
float m_width;
IDOMBrushPtr m_brush;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.