MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / bendTextAlongCurve

Function bendTextAlongCurve

source/MRSymbolMesh/MRAlignTextToMesh.cpp:90–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90Expected<Mesh> bendTextAlongCurve( const CurveFunc& curve, const BendTextAlongCurveParams& params )
91{
92 MR_TIMER;
93 if ( !curve.func )
94 {
95 assert( false );
96 return unexpected( "No curve provided" );
97 }
98
99 auto contoursOrError = createSymbolContours( params.symbolMesh );
100 if ( !contoursOrError.has_value() )
101 return unexpected( std::move( contoursOrError.error() ) );
102
103 auto& conts = *contoursOrError;
104
105 auto bbox = findContoursBBox( conts );
106 if ( !bbox.valid() )
107 return unexpected( "Symbols mesh is empty" );
108
109 int numLines = 1;
110 for ( auto c : params.symbolMesh.text )
111 if ( c == '\n' )
112 ++numLines;
113
114 auto diagonal = bbox.size();
115
116 const float symbolDependentMultiplier = params.fontBasedSizeCalc ? diagonal.y / params.symbolMesh.MaxGeneratedFontHeight / numLines : 1.0f;
117 auto scale = symbolDependentMultiplier * ( params.fontHeight * numLines * ( 1.0f + params.symbolMesh.symbolsDistanceAdditionalOffset.y ) ) / diagonal.y;
118 scaleContours( conts, scale );
119
120 Vector2f relPivot = params.pivotBoxPoint;
121 if ( params.fontBasedSizeCalc )
122 {
123 float absYPivot =
124 ( 1 - numLines ) * params.symbolMesh.MaxGeneratedFontHeight * ( 1 - params.pivotBoxPoint.y ) + params.symbolMesh.MaxGeneratedFontHeight * params.pivotBoxPoint.y;
125 relPivot.y = ( absYPivot - bbox.min.y ) / diagonal.y;
126 }
127
128 return bendContoursAlongCurve( conts, curve, {
129 .pivotCurveTime = params.pivotCurveTime,
130 .pivotBoxPoint = relPivot,
131 .periodicCurve = params.periodicCurve,
132 .stretch = params.stretch,
133 .extrusion = params.surfaceOffset
134 } );
135}
136
137Expected<Mesh> bendTextAlongCurve( const CurvePoints& cp, const BendTextAlongCurveParams& params )
138{

Callers 2

TESTFunction · 0.85
bendTextAlongSurfacePathFunction · 0.85

Calls 9

createSymbolContoursFunction · 0.85
findContoursBBoxFunction · 0.85
scaleContoursFunction · 0.85
bendContoursAlongCurveFunction · 0.85
curveFromPointsFunction · 0.85
errorMethod · 0.80
unexpectedFunction · 0.50
validMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68