#pragma once
#include <string>
#include <string_view>
class WordWrapper {
public:
WordWrapper(std::string_view str, float maxW, int flags)
: str_(str), maxW_(maxW), flags_(flags) {
}
virtual ~WordWrapper() {}
std::string Wrapped();
protected:
virtual float MeasureWidth(std::string_view str) = 0;
void Wrap();
bool WrapBeforeWord();
void AppendWord(int endIndex, int lastChar, bool addNewline);
void AddEllipsis();
static bool IsCJK(uint32_t c);
static bool IsPunctuation(uint32_t c);
static bool IsSpace(uint32_t c);
static bool IsShy(uint32_t c);
static bool IsSpaceOrShy(uint32_t c) {
return IsSpace(c) || IsShy(c);
}
const std::string_view str_;
const float maxW_;
const int flags_;
std::string out_;
int lastIndex_ = 0;
int lastEllipsisIndex_ = -1;
size_t lastLineStart_ = 0;
int lastChar_ = 0;
float x_ = 0.0f;
float wordWidth_ = 0.0f;
float ellipsisWidth_ = 0.0f;
bool forceEarlyWrap_ = false;
bool scanForNewline_ = false;
bool skipNextWord_ = false;
};