Files
ppsspp/ext/native/util/text/wrap_text.h
T
Unknown W. Brackets 977f75ce1e UI: Fix text wrap when kerning adjusts spaces.
This was happening for some setting info messages.  The sum of the word
lengths didn't actually match the line length, because more space was
added between some words.
2017-06-03 10:14:55 -07:00

38 lines
864 B
C++

#pragma once
#include <string>
class WordWrapper {
public:
WordWrapper(const char *str, float maxW)
: str_(str), maxW_(maxW) {
}
std::string Wrapped();
protected:
virtual float MeasureWidth(const char *str, size_t bytes) = 0;
void Wrap();
void WrapBeforeWord();
void AppendWord(int endIndex, bool addNewline);
static bool IsCJK(uint32_t c);
static bool IsPunctuation(uint32_t c);
static bool IsSpace(uint32_t c);
static bool IsShy(uint32_t c);
const char *const str_;
const float maxW_;
std::string out_;
// Index of last output / start of current word.
int lastIndex_ = 0;
// Index of last line start.
int lastLineStart_ = 0;
// Position the current word starts at.
float x_ = 0.0f;
// Most recent width of word since last index.
float wordWidth_;
// Force the next word to cut partially and wrap.
bool forceEarlyWrap_ = false;
};