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

◆ repress()

MAYAFLUX_API bool MayaFlux::Portal::Text::repress ( const std::shared_ptr< Buffers::TextBuffer > &  target,
std::string_view  text,
glm::vec4  color = { 1.F, 1.F, 1.F, 1.F },
RedrawPolicy  policy = RedrawPolicy::Clip 
)

Re-composite a UTF-8 string into an existing TextBuffer.

Always clears the buffer before compositing. Render bounds and atlas are read from the target buffer. When the target has a pre-allocated vertical budget the compositing bounds are the budget dimensions, so no VKImage rebuild occurs as long as content fits.

Parameters
targetExisting TextBuffer to write into.
textUTF-8 string to composite.
colorRGBA glyph color.
policyControls reallocation behaviour when text exceeds budget.
Returns
True on success.

Definition at line 264 of file InkPress.cpp.

269{
270 if (!target) {
271 MF_ERROR(Journal::Component::Portal, Journal::Context::API,
272 "repress: target buffer is null");
273 return false;
274 }
275
276 GlyphAtlas* atlas = resolve_atlas(nullptr);
277 if (!atlas) {
278 return false;
279 }
280
281 target->clear_accumulated_text();
282 target->reset_cursor();
283
284 const uint32_t buf_w = target->get_budget_width();
285 const uint32_t buf_h = target->get_budget_height();
286 const uint32_t bound_h = target->get_render_bounds_h();
287
288 const auto result = composite(text, *atlas, color, buf_w, bound_h,
289 static_cast<float>(atlas->line_height()));
290 if (!result) {
291 MF_WARN(Journal::Component::Portal, Journal::Context::API,
292 "repress: no glyphs produced for '{}'", std::string(text));
293 return false;
294 }
295
296 if (result->h > buf_h && policy == RedrawPolicy::Fit) {
297 const uint32_t new_h = std::min(result->h, bound_h);
298 target->resize_texture(buf_w, new_h);
299 target->set_budget(buf_w, new_h);
300 target->set_pixel_data(result->pixels.data(), result->pixels.size());
301 target->get_cursor_x() = result->cursor_x;
302 target->get_cursor_y() = result->cursor_y;
303 target->set_accumulated_text(text);
304
305 MF_DEBUG(Journal::Component::Portal, Journal::Context::API,
306 "repress(Fit): resized to {}x{}", buf_w, new_h);
307 return true;
308 }
309
310 const size_t buf_bytes = static_cast<size_t>(buf_w) * buf_h * 4;
311 std::vector<uint8_t> cleared(buf_bytes, 0);
312
313 const uint32_t copy_h = std::min(result->h, buf_h);
314 for (uint32_t row = 0; row < copy_h; ++row) {
315 std::memcpy(
316 cleared.data() + static_cast<size_t>(row) * buf_w * 4,
317 result->pixels.data() + static_cast<size_t>(row) * buf_w * 4,
318 static_cast<size_t>(buf_w) * 4);
319 }
320
321 target->set_pixel_data(cleared.data(), buf_bytes);
322 target->get_cursor_x() = result->cursor_x;
323 target->get_cursor_y() = result->cursor_y;
324 // target->get_cursor_y() = result->h;
325 target->set_accumulated_text(text);
326
327 MF_DEBUG(Journal::Component::Portal, Journal::Context::API,
328 "repress(Clip): '{}' -> {}x{} into {}x{} budget",
329 std::string(text), buf_w, result->h, buf_w, buf_h);
330
331 return true;
332}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::optional< glm::vec3 > color

References MayaFlux::Journal::API, color, Fit, MayaFlux::Portal::Text::GlyphAtlas::line_height(), MF_DEBUG, MF_ERROR, MF_WARN, and MayaFlux::Journal::Portal.

+ Here is the call graph for this function: