1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#pragma once
10
11#include <libg/Color.h>
12#include <libg/Context.h>
13#include <libg/Font.h>
14#include <string>
15
16namespace WinServer {
17namespace Helpers {
18
19 [[gnu::always_inline]] inline static size_t text_width(const std::string& text, const LG::Font& f)
20 {
21 size_t width = 0;
22 const size_t letter_spacing = f.glyph_spacing();
23
24 for (int i = 0; i < text.size(); i++) {
25 width += f.glyph_width(text[i]) + letter_spacing;
26 }
27 return width;
28 }
29
30 [[gnu::always_inline]] inline static void draw_text(LG::Context& ctx, LG::Point<int> pt, const std::string& text, const LG::Font& f)
31 {
32 const size_t letter_spacing = f.glyph_spacing();
33
34 for (int i = 0; i < text.size(); i++) {
35 ctx.draw(pt, f.glyph_bitmap(text[i]));
36 pt.offset_by(f.glyph_width(text[i]) + letter_spacing, 0);
37 }
38 }
39
40} // namespace Helpers
41} // namespace WinServer