TextLayout::TextLayout(const char *_str) { str = reinterpret_cast<char *>(malloc(strlen(_str)+1)); strcpy(str, _str); m_justify = false; float wordWidth = 0; char *wordstart = str; for (unsigned int i=0; i<strlen(_str);) { wordWidth = 0; wordstart = str+i; while (str[i] && !isspace(str[i])) { /* skip color control code things! */ if (str[i] == '#') { unsigned int hexcol; if (sscanf(str+i, "#%3x", &hexcol)==1) { i+=4; continue; } } const TextureFont::glfglyph_t &glyph = Gui::Screen::GetFont()->GetGlyph(str[i]); wordWidth += glyph.advx; i++; } words.push_back(word_t(wordstart, wordWidth)); if (str[i] == '\n') words.push_back(word_t(0,0)); str[i++] = 0; } }
/// return tag of child node by id word_t get_xtag(word_t id) const { #ifdef PATL_ALIGNHACK return linktag_[id] & word_t(1); #else return tagsid_ >> id & word_t(1); #endif }
/// return node id relate to parent word_t get_parent_id() const { #ifdef PATL_ALIGNHACK return parentid_ & word_t(1); #else return tagsid_ >> 2 & word_t(1); #endif }
TextLayout::TextLayout(const char *_str, RefCountedPtr<Text::TextureFont> font, ColourMarkupMode markup) { // XXX ColourMarkupSkip not correctly implemented yet assert(markup != ColourMarkupSkip); m_colourMarkup = markup; m_font = font ? font : Gui::Screen::GetFont(); str = reinterpret_cast<char *>(malloc(strlen(_str)+1)); strcpy(str, _str); m_justify = false; float wordWidth = 0; char *wordstart = str; int i = 0; while (str[i]) { wordWidth = 0; wordstart = &str[i]; while (str[i] && str[i] != ' ' && str[i] != '\r' && str[i] != '\n') { /* skip color control code things! */ if ((markup != ColourMarkupNone) && (str[i] == '#')) { unsigned int hexcol; if (sscanf(&str[i], "#%3x", &hexcol)==1) { i+=4; continue; } } Uint32 chr; int n = Text::utf8_decode_char(&chr, &str[i]); assert(n); i += n; const Text::TextureFont::glfglyph_t &glyph = m_font->GetGlyph(chr); wordWidth += glyph.advx; // XXX this should do kerning } words.push_back(word_t(wordstart, wordWidth)); if (str[i]) { if (str[i] == '\n') words.push_back(word_t(0,0)); str[i++] = 0; } } }
void setup_a(const Oracle *oracl) { vertex vtx(oracl->new_algo(this)); vtx.ascend(); a_ = oracl->get_by(vtx)->a_ | (word_t(1) << get_i()->height()); }
void TextLayout::SetText(const char *_str) { str = std::string(_str); m_justify = false; float wordWidth = 0; const char *wordstart = str.c_str(); words.clear(); int i = 0; while (str[i]) { wordWidth = 0; wordstart = &str[i]; while (str[i] && str[i] != ' ' && str[i] != '\r' && str[i] != '\n') { /* skip color control code things! */ if ((m_colourMarkup != ColourMarkupNone) && (str[i] == '#')) { unsigned int hexcol; if (sscanf(&str[i], "#%3x", &hexcol) == 1) { i += 4; continue; } } Uint32 chr; int n = Text::utf8_decode_char(&chr, &str[i]); assert(n); i += n; const Text::TextureFont::Glyph &glyph = m_font->GetGlyph(chr); wordWidth += glyph.advX; // XXX this should do kerning } words.push_back(word_t(wordstart, wordWidth)); if (str[i]) { if (str[i] == '\n') words.push_back(word_t(0, 0)); str[i++] = 0; } } prevWidth = -1.0f; prevColor = Color::WHITE; }
void set_inode() { il_ = reinterpret_cast<word_t>(this) | word_t(1); }
bool is_inode() const { return il_ & word_t(1); }
void set_l(const this_t *pL) { il_ = reinterpret_cast<word_t>(pL) | word_t(1); }
void set_root_a() { a_ = word_t(1) << get_i()->height(); }