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

Function alignTextToMesh

source/MRSymbolMesh/MRAlignTextToMesh.cpp:47–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45} //anonymous namespace
46
47Expected<Mesh> alignTextToMesh(
48 const Mesh& mesh, const TextMeshAlignParams& params )
49{
50 MR_TIMER;
51 auto contoursOrError = createSymbolContours( params );
52 if ( !contoursOrError.has_value() )
53 return unexpected( std::move( contoursOrError.error() ) );
54
55 auto& conts = *contoursOrError;
56
57 auto bbox = findContoursBBox( conts );
58 if ( !bbox.valid() )
59 return unexpected( "Symbols mesh is empty" );
60
61 int numLines = 1;
62 for ( auto c : params.text )
63 if ( c == '\n' )
64 ++numLines;
65
66 auto diagonal = bbox.size();
67
68 const float symbolDependentMultiplier = params.fontBasedSizeCalc ? diagonal.y / params.MaxGeneratedFontHeight / numLines : 1.0f;
69 auto scale = symbolDependentMultiplier * ( params.fontHeight * numLines * ( 1.0f + params.symbolsDistanceAdditionalOffset.y ) ) / diagonal.y;
70 scaleContours( conts, scale );
71
72 Vector2f relPivot = params.pivotPoint;
73 if ( params.fontBasedSizeCalc )
74 {
75 float absYPivot =
76 ( 1 - numLines ) * params.MaxGeneratedFontHeight * ( 1 - params.pivotPoint.y ) + params.MaxGeneratedFontHeight * params.pivotPoint.y;
77 relPivot.y = ( absYPivot - bbox.min.y ) / diagonal.y;
78 }
79
80 return alignContoursToMesh( mesh, conts, {
81 .meshPoint = params.startPoint,
82 .pivotPoint = relPivot,
83 .xDirection = params.direction,
84 .zDirection = params.textNormal,
85 .extrusion = params.surfaceOffset,
86 .maximumShift = params.textMaximumMovement
87 } );
88}
89
90Expected<Mesh> bendTextAlongCurve( const CurveFunc& curve, const BendTextAlongCurveParams& params )
91{

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected