This repository has been archived on 2022-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
glyphs-juke/src/Text.h

47 lines
889 B
C
Raw Normal View History

2021-08-23 05:22:56 +00:00
#pragma once
#include <cstdint>
#include <string>
#include "iWritable.h"
namespace gj {
class Text : public WritableBase {
public:
Text(Text&&) = default;
Text(const Text&) = default;
Text& operator=(Text&&) = default;
Text& operator=(const Text&) = default;
Text(const std::wstring& str, uint32_t x = 0, uint32_t y = 0) :
WritableBase(x, y), entity_(str) {
}
void Write(Textbuffer& fb) const override {
const int32_t w = static_cast<int32_t>(fb.width());
const int32_t h = static_cast<int32_t>(fb.height());
char16_t* ptr = fb.ptr();
int32_t x = x_, y = y_;
if (y >= h) return;
const size_t len = entity_.size();
for (size_t i = 0; i < len; ++i) {
if (x < 0) continue;
if (x >= w) return;
ptr[x+y*w] = entity_[i];
x += (entity_[i] > UINT8_MAX)? 2: 1;
}
}
private:
std::wstring entity_;
};
}