MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ copy()

MAYAFLUX_API CopiedText MayaFlux::Portal::Text::copy ( std::string_view  text,
const LayoutResult &  layout,
size_t  a,
size_t  b 
)

Copy a byte range: the text it spans, and the quads that render it.

start/end are normalized (min/max) and clamped to [0, text.size()]. Both are assumed to already be codepoint boundaries, the same assumption next_codepoint_offset()/previous_codepoint_offset() maintain for a caller's cursor; this does not re-snap them to one.

Quads are taken from layout, matched by GlyphQuad::byte_offset falling in the normalized range, at whatever position they were laid out at. Shift them yourself if the copy needs to be positioned relative to its own origin rather than the source layout's. layout must be the result of laying out this same text (or one whose byte offsets line up with it); passing a layout for unrelated text returns a meaningless, but not unsafe, quads list.

Parameters
textSource UTF-8 string the byte range indexes into.
layoutLayoutResult produced from that same text.
aOne end of the byte range.
bThe other end of the byte range.
Returns
The extracted text, its normalized range, and matching quads.

Definition at line 217 of file TypeSetter.cpp.

218{
220 out.start = std::min(std::min(a, b), text.size());
221 out.end = std::min(std::max(a, b), text.size());
222
223 if (out.start >= out.end) {
224 return out;
225 }
226
227 out.text = std::string(text.substr(out.start, out.end - out.start));
228
229 for (const auto& q : layout.quads) {
230 if (q.byte_offset >= out.start && q.byte_offset < out.end) {
231 out.quads.push_back(q);
232 }
233 }
234
235 return out;
236}
size_t a
size_t b
double q
std::vector< float > * out
size_t start
Normalized, clamped byte range actually used.
Result of copy(): a byte range's text plus the quads that render it.

References a, b, out, q, MayaFlux::Portal::Text::LayoutResult::quads, and MayaFlux::Portal::Text::CopiedText::start.