PyObject *
PyIMEngine::py_get_surrounding_text (PyIMEngineObject *self, PyObject *args)
{
	PyObject *tuple;

	int maxlen_before = -1;
	int maxlen_after = -1;

	if (!PyArg_ParseTuple (args, "|ii:get_surrounding_text", &maxlen_before, &maxlen_after))
		return NULL;

	WideString text;
	int cursor;
	int provided = self->engine.get_surrounding_text(text, cursor, maxlen_before, maxlen_after);
	
	tuple = PyTuple_New (2);

	if (!provided) {
		text = L"";
		cursor = 0;
	}

#if Py_UNICODE_SIZE == 4
	PyTuple_SET_ITEM (tuple, 0, PyUnicode_FromUnicode ((Py_UNICODE *)text.c_str(), text.length()));
#else
	gunichar2 *utf16_str = g_ucs4_to_utf16 (text.c_str(), -1, NULL, NULL, NULL);
	PyTuple_SET_ITEM (tuple, 0, PyUnicode_FromUnicode ((Py_UNICODE *)utf16_str, text.length()));
#endif
	PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong ((long) cursor));
	
	return tuple;
}
Exemplo n.º 2
0
void RichEditFrame::setRichText(WideString text)
{
  EditStreamCookie cookie;
  cookie.str = text;
  cookie.pos = 0;
  EDITSTREAM es;
  es.dwCookie = (DWORD_PTR) &cookie;
  es.dwError = 0;
  es.pfnCallback = StreamCallback;
  SendMessage(hWnd, EM_EXLIMITTEXT, 0, (text.length() < 32768 ? 32768 : text.length() + 1));
  SendMessage(hWnd, EM_STREAMIN, SF_RTF, (uint32) &es);
}
	//---------------------------------
	WideString StringUtils::translateToXML ( const WideString &srcString )
	{
		WideString returnString; 

		for ( unsigned int i=0; i<srcString.length(); ++i )
		{
			switch ( srcString[i])
			{
			case '\r':  
				returnString += L"&#13";
				break;
			case '<':  
				returnString += L"&lt;";
				break;
			case '>': 
				returnString += L"&gt;";
				break;
			case '&':  
				returnString += L"&amp;";
				break;
			case '"':  
				returnString += L"&quot;";
				break;
			case '\'':  
				returnString += L"&apos;";
				break;
			default :   
				returnString += srcString[i];
			}
		}

		return returnString;
	}
Exemplo n.º 4
0
bool LodDistanceControl::TextFieldKeyPressed(UITextField * textField, int32 replacementLocation, int32 replacementLength, const WideString & replacementString)
{
    if (replacementLength < 0) 
    {
        return true;
    }
    
    WideString newText = textField->GetAppliedChanges(replacementLocation, replacementLength, replacementString);
    bool allOk;
    int pointsCount = 0;
    for (int i = 0; i < newText.length(); i++) 
    {
        allOk = false;
        if (newText[i] == L'-' && i == 0)
        {
            allOk = true;
        }
        else if(newText[i] >= L'0' && newText[i] <= L'9')
        {
            allOk = true;
        }
        else if(newText[i] == L'.' && pointsCount == 0)
        {
            allOk = true;
            pointsCount++;
        }
        if (!allOk) 
        {
            return false;
        }
    }
    return true;
};
Exemplo n.º 5
0
void
HangulInstance::hangul_update_preedit_string ()
{
    WideString wstr = get_preedit_string ();

    if (wstr.length ()) {
        AttributeList attrs;
        attrs.push_back(Attribute(0, m_preedit.length(), SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_UNDERLINE));
        attrs.push_back(Attribute(m_preedit.length(), wstr.length() - m_preedit.length(), SCIM_ATTR_DECORATE, SCIM_ATTR_DECORATE_REVERSE));
        show_preedit_string ();
        update_preedit_string (wstr, attrs);
        update_preedit_caret (wstr.length());
    } else {
        hide_preedit_string ();
    }
}
Exemplo n.º 6
0
SIZE FontSys::getTextSize(HFONT font, WideString text)
{
  SIZE sz;
  SelectObject(instance.hDC, font);
  GetTextExtentPoint32(instance.hDC, text, text.length(), &sz);
  return sz;
}
Exemplo n.º 7
0
AttributeList
SKKCandList::get_attributes (int index) const
{
    AttributeList al = CommonLookupTable::get_attributes(index);
    if (annot_view && annot_pos &&
        (annot_target || get_cursor_pos() == index)) {
        WideString annot = get_annot(index);
        WideString cand = get_cand(index);
        if (annot_highlight && !annot.empty()) {
            al.push_back(Attribute(cand.length(), annot.length(),
                                   SCIM_ATTR_BACKGROUND,
                                   annot_bgcolor));
        }
    }
    return al;
}
Exemplo n.º 8
0
bool
SKKCandList::append_candidate (const WideString &cand,
                               const WideString &annot,
                               const WideString &cand_orig,
                               const AttributeList &attrs)
{
    if (cand.length() == 0)
        return false;

    if (m_candvec.size() < candvec_size) {
        m_candvec.push_back(CandEnt(cand, annot, cand_orig));
        return true;
    } else {
        m_annot_buf->m_index.push_back(m_annot_buf->m_buffer.size());
        if (!annot.empty())
            m_annot_buf->m_buffer.insert(m_annot_buf->m_buffer.end(),
                                      annot.begin(), annot.end());
        m_cand_orig_buf->m_index.push_back(m_cand_orig_buf->m_buffer.size());
        if (!cand_orig.empty())
            m_cand_orig_buf->m_buffer.insert(m_cand_orig_buf->m_buffer.end(),
                                             cand_orig.begin(),
                                             cand_orig.end());
        return CommonLookupTable::append_candidate(cand, attrs);
    }
}
Exemplo n.º 9
0
CScValue *CScValue::GetProp(char *Name) {
	if (m_Type == VAL_VARIABLE_REF) return m_ValRef->GetProp(Name);

	if (m_Type == VAL_STRING && strcmp(Name, "Length") == 0) {
		Game->m_ScValue->m_Type = VAL_INT;

		if (Game->m_TextEncoding == TEXT_ANSI) {
			Game->m_ScValue->SetInt(strlen(m_ValString));
		} else {
			WideString wstr = StringUtil::Utf8ToWide(m_ValString);
			Game->m_ScValue->SetInt(wstr.length());
		}

		return Game->m_ScValue;
	}

	CScValue *ret = NULL;

	if (m_Type == VAL_NATIVE && m_ValNative) ret = m_ValNative->ScGetProperty(Name);

	if (ret == NULL) {
		m_ValIter = m_ValObject.find(Name);
		if (m_ValIter != m_ValObject.end()) ret = m_ValIter->second;
	}
	return ret;
}
Exemplo n.º 10
0
QString WideString2QStrint(const WideString& str)
{
#ifdef __DAVAENGINE_MACOS__
	return QString::fromStdWString(str);
#else
	return QString((const QChar*)str.c_str(), str.length());
#endif
}
Exemplo n.º 11
0
void
HangulInstance::update_candidates ()
{
    m_lookup_table.clear ();
    m_candidate_comments.clear ();

    HanjaList* list = NULL;

    // search for symbol character
    // key string for symbol character is like:
    //  'ㄱ', 'ㄴ', 'ㄷ', etc
    WideString preeditw = get_preedit_string();
    if (preeditw.length() == 1) {
	String key = utf8_wcstombs(preeditw);
	list = hanja_table_match_suffix(m_factory->m_symbol_table, key.c_str());
    }

    // search for hanja
    if (list == NULL) {
	String str = get_candidate_string();
	SCIM_DEBUG_IMENGINE(1) << "candidate string: " << str << "\n";

	if (str.length() > 0) {
	    if (is_hanja_mode() || m_factory->m_commit_by_word) {
		list = hanja_table_match_prefix(m_factory->m_hanja_table,
						    str.c_str());
	    } else {
		list = hanja_table_match_suffix(m_factory->m_hanja_table,
						    str.c_str());
	    }
	}
    } 
    
    if (list != NULL) {
	int n = hanja_list_get_size(list);
	for (int i = 0; i < n; ++i) {
	    const char* value = hanja_list_get_nth_value(list, i);
	    const char* comment = hanja_list_get_nth_comment(list, i);
	    WideString candidate = utf8_mbstowcs(value, -1);
	    m_lookup_table.append_candidate(candidate);
	    m_candidate_comments.push_back(String(comment));
	}

	m_lookup_table.set_page_size (9);
	m_lookup_table.show_cursor ();

	update_lookup_table (m_lookup_table);
	show_lookup_table ();

	hangul_update_aux_string ();

	hanja_list_delete(list);
    }

    if (m_lookup_table.number_of_candidates() <= 0) {
	delete_candidates();
    }
}
bool
NativeLookupTable::append_entry (const WideString &entry)
{
    if (entry.length () > 0) {
        m_strings.push_back (entry);
        return true;
    }
    return false;
}
Exemplo n.º 13
0
void LinkFrame::resetSize()
{
  HDC hDC = GetDC(hWnd);
  SelectObject(hDC, hFont);
  SIZE sz;
  WideString text = getText();
  GetTextExtentPoint32(hDC, text, text.length(), &sz);
  ReleaseDC(hWnd, hDC);
  setSize(sz.cx, sz.cy);
}
	//--------------------------------
	bool StringUtils::equalsIgnoreCase ( const WideString& s1, const WideString& s2 ) 
	{
		if ( s1.length() != s2.length() )
			return false;

		WideString::const_iterator it1=s1.begin();
		WideString::const_iterator it2=s2.begin();

		// has the end of at least one of the strings been reached?
		while ( (it1!=s1.end()) && (it2!=s2.end()) ) 
		{ 
			if(::toupper(*it1) != ::toupper(*it2)) //letters differ?
				return false; 
			// proceed to the next character in each string
			++it1;
			++it2;
		}
		return true;
	}
Exemplo n.º 15
0
void
ArrayInstance::space_key_press()
{
    // space is the page down key when keying symbols and phrases
    if (m_lookup_table.number_of_candidates() > m_lookup_table.get_page_size())
    {
        lookup_table_page_down();
        return;
    }

    WideString inkey = m_preedit_string;
    
    // If the user is already press the space before, 
    // commit the first candidate in the lookup table
    if (commit_press_count == 1)
    {
        WideString str = m_lookup_table.get_candidate_in_current_page (0);
        if (str.compare(utf8_mbstowcs(SCIM_ARRAY_EMPTY_CHAR)) == 0) {
            hide_lookup_table();
            return;
        }
        if (str.length()) {
            send_commit_string(inkey, str);
            return;
        }
    }

    create_lookup_table(_ScimArray::Array_Table);
    update_lookup_table(m_lookup_table);
    if (m_lookup_table.number_of_candidates() > 1)
    {
        show_lookup_table();
        commit_press_count++;
        return;
    }
    hide_lookup_table();
    WideString str = m_lookup_table.get_candidate_in_current_page (0);
    if (str.length() && str.compare(utf8_mbstowcs(SCIM_ARRAY_EMPTY_CHAR))) {
        send_commit_string(inkey, str);
        return;
    }
}
Exemplo n.º 16
0
HGLOBAL CreateGlobalText(WideString text)
{
  HGLOBAL data = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * 2);
  wchar_t* ptr = (wchar_t*) GlobalLock(data);
  if (ptr)
  {
    wcscpy(ptr, text.c_str());
    GlobalUnlock(data);
  }
  return data;
}
Exemplo n.º 17
0
	//--------------------------------
	bool Utils::createDirectoryRecursive( const WideString &pathString )
	{
		if (pathString.length() == 0)
			return false;

		WideString path = pathString;

		if (path[path.length()-1] != '/' && path[path.length()-1] != '\\')
			path.push_back('\\');

		std::list<WideString> paths;
		size_t offset = WideString::npos;
		while ((offset != 0) && (offset = pathString.find_last_of(L"/\\", offset)) != WideString::npos)
		{
			paths.push_front(pathString.substr(0, offset + 1));
			if (offset != 0) --offset;
		}

		bool pathExists = true;
		const wchar_t* currentPath = _wgetcwd(0, 0);

		for (std::list<WideString>::const_iterator iPath = paths.begin(); iPath != paths.end(); ++iPath)
		{
			// if path exists
			if (_wchdir((*iPath).c_str()) == 0)
				continue;

			// path does not exist, try to create it
			_wmkdir((*iPath).c_str());
			
			if (_wchdir((*iPath).c_str()) != 0)
			{
				pathExists = false;
				break;
			}
		}

		// Restore current path
		_wchdir(currentPath);
		return pathExists;
	}
Exemplo n.º 18
0
int FontSys::getMTextHeight (HFONT font, int width, WideString text)
{
  SIZE sz;
  SelectObject(instance.hDC, font);
  WideString word;
  WideString curline;
  int height = 0;
  for (int i = 0; i <= text.length (); i++)
  {
    if (text[i] && text[i] != '\n' && !s_isspace (text[i]))
      word += text[i];
    if (text[i] == 0 || s_isspace (text[i]))
    {
      WideString tmp = curline + word;
      GetTextExtentPoint32(instance.hDC, tmp, tmp.length(), &sz);
      int wd = sz.cx;
      if (text[i] == '\n' || (wd > width && curline.length ()))
      {
        GetTextExtentPoint32(instance.hDC, curline, curline.length(), &sz);
        height += sz.cy;
        curline = L"";
      }
      curline += word;
      if (text[i])
        curline += text[i];
      word = L"";
    }
  }
  if (curline.length ())
  {
    GetTextExtentPoint32(instance.hDC, curline, curline.length(), &sz);
    height += sz.cy;
  }
  return height;
}
Exemplo n.º 19
0
int CBFontTT::GetTextWidth(byte  *Text, int MaxLength) {
	WideString text;

	if (Game->m_TextEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
	else text = StringUtil::AnsiToWide((char *)Text);

	if (MaxLength >= 0 && text.length() > MaxLength) text = text.substr(0, MaxLength);

	int textWidth, textHeight;
	MeasureText(text, -1, -1, textWidth, textHeight);

	return textWidth;
}
	String StringUtils::wideString2utf8String( const WideString& wideString )
	{
		size_t widesize = wideString.length();
		String returnString;

		if ( sizeof( wchar_t ) == 2 )
		{
			size_t utf8size = MAX_UTF8_CHAR_LENGTH * widesize + 1;
			returnString.resize( utf8size, '\0' );
			const UTF16* sourcestart = reinterpret_cast<const UTF16*>( wideString.c_str() );
			const UTF16* sourceend = sourcestart + widesize;
			UTF8* targetstart = reinterpret_cast<UTF8*>( &((returnString)[ 0 ]) );
			UTF8* thisFirstWChar = targetstart;
			UTF8* targetend = targetstart + utf8size;
			ConversionResult res = ConvertUTF16toUTF8( &sourcestart, sourceend, &targetstart, targetend, strictConversion );

			if ( res != conversionOK )
			{
				throw Exception(Exception::ERROR_WIDE_2_UTF8, String("Could not convert from wide string to UTF8."));
			}

			returnString.resize(targetstart - thisFirstWChar);
		}

		else if ( sizeof( wchar_t ) == 4 )
		{
			size_t utf8size = MAX_UTF8_CHAR_LENGTH * widesize + 1;
			returnString.resize( utf8size, '\0' );
			const UTF32* sourcestart = reinterpret_cast<const UTF32*>( wideString.c_str() );
			const UTF32* sourceend = sourcestart + widesize;
			UTF8* targetstart = reinterpret_cast<UTF8*>( &((returnString)[ 0 ]) );
			UTF8* thisFirstWChar = targetstart;
			UTF8* targetend = targetstart + utf8size;
			ConversionResult res = ConvertUTF32toUTF8( &sourcestart, sourceend, &targetstart, targetend, strictConversion );

			if ( res != conversionOK )
			{
				throw Exception(Exception::ERROR_WIDE_2_UTF8, String("Could not convert from wide string to UTF8."));
			}

			returnString.resize(targetstart - thisFirstWChar);
		}

		else
		{
			throw Exception(Exception::ERROR_WIDE_2_UTF8, String("Could not convert from wide string to UTF8."));
		}
		return returnString;
	}
Exemplo n.º 21
0
void
PinyinPhraseLib::create_pinyin_index ()
{
	if (!m_pinyin_table || !m_pinyin_table->size()) return;

	clear_phrase_index ();

	uint32 pinyin_offset = 0;

	WideString content;
	Phrase phrase;

	for (uint32 i=0; i<m_phrase_lib.number_of_phrases (); i++) {
		phrase = m_phrase_lib.get_phrase_by_index (i);

		content = phrase.get_content ();

		std::vector<PinyinKeyVector> key_vv;
		m_pinyin_table->find_key_strings (key_vv, content);

		for (uint32 j=0; j<key_vv.size(); j++) {
			for (uint32 k=0; k<key_vv[j].size(); k++)
				m_pinyin_lib.push_back (key_vv[j][k]);

			insert_pinyin_phrase_into_index (phrase.get_phrase_offset (), pinyin_offset);

			pinyin_offset = m_pinyin_lib.size ();
		}
#if 0
		if (key_vv.size () > 1 && content.length () > 1) {
			for (uint32 x=0; x<key_vv.size (); x++) {
				std::cerr << phrase.frequency () << "\t| " << 
						utf8_wcstombs (content) << " =";
				for (uint32 y=0; y<key_vv[x].size (); y++)
					std::cerr << " " << key_vv[x][y];
				std::cerr << "\n";
			}
		}
#endif
		std::cout << "." << std::flush;
	}

	sort_phrase_tables ();

	std::cout << "Phrase Number = " << count_phrase_number () << "\n";
}
Exemplo n.º 22
0
/*
 * manipulating the caret
 */
unsigned int
Preedit::get_caret_pos (void)
{
    if (is_converting ()) {
        return m_conversion.get_segment_position ();
    } else {
        if (get_input_mode () == SCIM_ANTHY_MODE_HALF_KATAKANA) {
            // FIXME! It's ad-hoc
            WideString substr;
            substr = m_reading.get (0, m_reading.get_caret_pos (),
                                    SCIM_ANTHY_STRING_HALF_KATAKANA);
            return substr.length ();
        } else {
            return m_reading.get_caret_pos ();
        }
    }
}
Exemplo n.º 23
0
void
HangulInstance::flush()
{
    SCIM_DEBUG_IMENGINE(2) << "flush.\n";

    hide_preedit_string();

    WideString wstr = m_preedit;
    const ucschar *str = hangul_ic_flush(m_hic);
    while (*str != 0)
	wstr.push_back (*str++);

    if (wstr.length())
        commit_string(wstr);

    delete_candidates ();
    m_preedit.clear();
}
Exemplo n.º 24
0
bool UITextFieldAndroid::TextFieldKeyPressed(int32 replacementLocation, int32 replacementLength, const WideString &text)
{
	bool res = true;
	UITextFieldDelegate* delegate = textField->GetDelegate();
	if (delegate)
		res = delegate->TextFieldKeyPressed(textField, replacementLocation, replacementLength, text);

	if (res)
	{
		WideString curText = textField->GetText();
		if (curText.length() >= replacementLocation)
		{
			curText.replace(replacementLocation, replacementLength, text);
			this->text = curText;
		}
	}
	return res;
}
Exemplo n.º 25
0
Phrase
PinyinPhraseLib::append (const WideString &phrase, const PinyinKeyVector &keys)
{
	if (phrase.length () == 0 || !valid ())
		return Phrase ();

	Phrase tmp = m_phrase_lib.find (phrase);

	if (tmp.valid () && tmp.is_enable ())
		return tmp;

	tmp = m_phrase_lib.append (phrase);

	if (!tmp.valid ())
		return Phrase ();

	insert_phrase_into_index (tmp, keys);
	return tmp;
}
Exemplo n.º 26
0
void
CannaJRKanji::set_guide_line (void)
{
    if (m_ks.info & KanjiGLineInfo) {
        WideString dest;
        AttributeList attrs;
        convert_string (dest, attrs,
                        (const char *) m_ks.gline.line,
                        m_ks.gline.length,
                        m_ks.gline.revPos,
                        m_ks.gline.revLen);
        m_canna->update_aux_string (dest, attrs);
        if (dest.length () > 0) {
            m_aux_string_visible = true;
            m_canna->show_aux_string ();
        } else {
            m_aux_string_visible = false;
            m_canna->hide_aux_string ();
        }
    }
}
Exemplo n.º 27
0
void
ArrayInstance::send_commit_string(const WideString& inkey, const WideString& str)
{
    // phrases, no need to check specil codes
    if (str.length() > 1)
    {
        commit_string(str);
        reset();
        return;
    }
    if (m_special_code_only)
    {
        if (!check_special_code_only(inkey, str))
        {
            show_special_code(inkey, str);
            return ;
        }
    }
    commit_string (str);
    reset ();
    show_special_code(inkey, str);
}
Exemplo n.º 28
0
void HintManager::ShowHint(const WideString &hintMessage, const DAVA::Rect &controlRectAbsolute)
{
    if(0 != hintMessage.length())
    {
        //Add control
        HintControl *hintControl = new HintControl();
        hintControl->SetText(hintMessage);
        
        Rect screenRect = UIScreenManager::Instance()->GetScreen()->GetRect(true);
        
        Vector2 requestedSize = hintControl->GetSize();
        if(requestedSize.dx < controlRectAbsolute.GetSize().dx)
        {
            Vector2 pos(controlRectAbsolute.x - screenRect.x, controlRectAbsolute.y - screenRect.y + controlRectAbsolute.dy);
            hintControl->SetPosition(pos);
        }
        else if(controlRectAbsolute.x - screenRect.x < requestedSize.dx)
        {
            Vector2 pos(controlRectAbsolute.x - screenRect.x, controlRectAbsolute.y - screenRect.y + controlRectAbsolute.dy);
            hintControl->SetPosition(pos);
        }
        else 
        {
            Vector2 pos(controlRectAbsolute.x - screenRect.x + controlRectAbsolute.dx - requestedSize.dx, controlRectAbsolute.y - screenRect.y + controlRectAbsolute.dy);
            hintControl->SetPosition(pos);
        }
        
        ControlsFactory::AddBorder(hintControl);
        UIScreenManager::Instance()->GetScreen()->AddControl(hintControl);
        
        Animation *hintAlphaAnimation = hintControl->ColorAnimation( Color::Transparent(), NOTIFICATION_TIME, 
                                                                     Interpolation::EASY_IN, 2);
        hintAlphaAnimation->AddEvent(Animation::EVENT_ANIMATION_END, 
                                    Message(this, &HintManager::OnAlphaAnimationDone, hintControl));
        hints.push_back(hintControl);
    }
}
Exemplo n.º 29
0
bool
CannaJRKanji::process_key_event (const KeyEvent &key)
{
    int size = 1024, n, ch;
    char buf[1024 + 1];

    if (match_key_event (m_canna->m_factory->m_on_off_key, key, 0)) {
        m_enabled = !m_enabled;
        set_mode_line ();
        m_canna->reset ();
        return true;
    }

    if (!m_enabled)
        return false;

    ch = translate_key_event (key);
    if (ch == 0xffff)
        return false;

    n = jrKanjiString (m_context_id, ch, buf, size, &m_ks);

    // commit string
    if (n > 0 && !(m_ks.info & KanjiThroughInfo)) {
        buf[n] = '\0';
        WideString dest;
        m_iconv.convert (dest, buf);
        m_canna->commit_string (dest);
    }

    // mode line string
    if (m_ks.info & KanjiModeInfo)
        set_mode_line ();

    // guide line string
    set_guide_line ();

    // preedit string
    if (m_ks.length > 0) {
        WideString dest;
        AttributeList attrs;
        unsigned int pos;
        pos = convert_string (dest, attrs,
                              (const char *) m_ks.echoStr,
                              m_ks.length,
                              m_ks.revPos,
                              m_ks.revLen);

        m_canna->update_preedit_string (dest, attrs);
        m_canna->update_preedit_caret (pos);

        if (!m_preediting && dest.length () <= 0) {
            m_canna->hide_preedit_string ();
            return !(m_ks.info & KanjiThroughInfo);
        } else {
            m_preediting = true;
            m_canna->show_preedit_string ();
            m_canna->hide_lookup_table ();
            return true;
        }

    } else if (m_ks.length == 0) {
        m_canna->update_preedit_string (utf8_mbstowcs (""));

        m_canna->hide_preedit_string ();
        m_canna->hide_lookup_table ();

        if (m_preediting) {
            m_preediting = false;
            return true;
        } else {
            return !(m_ks.info & KanjiThroughInfo);
        }
    }

    m_canna->hide_lookup_table ();

    return !(m_ks.info & KanjiThroughInfo);
}
Exemplo n.º 30
0
void CBFontTT::DrawText(byte  *Text, int X, int Y, int Width, TTextAlign Align, int MaxHeight, int MaxLength) {
	if (Text == NULL || strcmp((char *)Text, "") == 0) return;

	WideString text;

	if (Game->m_TextEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
	else text = StringUtil::AnsiToWide((char *)Text);

	if (MaxLength >= 0 && text.length() > MaxLength) text = text.substr(0, MaxLength);

	CBRenderSDL *m_Renderer = (CBRenderSDL *)Game->m_Renderer;

	// find cached surface, if exists
	int MinPriority = INT_MAX;
	int MinIndex = -1;
	CBSurface *Surface = NULL;
	int textOffset = 0;

	for (int i = 0; i < NUM_CACHED_TEXTS; i++) {
		if (m_CachedTexts[i] == NULL) {
			MinPriority = 0;
			MinIndex = i;
		} else {
			if (m_CachedTexts[i]->m_Text == text && m_CachedTexts[i]->m_Align == Align && m_CachedTexts[i]->m_Width == Width && m_CachedTexts[i]->m_MaxHeight == MaxHeight && m_CachedTexts[i]->m_MaxLength == MaxLength) {
				Surface = m_CachedTexts[i]->m_Surface;
				textOffset = m_CachedTexts[i]->m_TextOffset;
				m_CachedTexts[i]->m_Priority++;
				m_CachedTexts[i]->m_Marked = true;
				break;
			} else {
				if (m_CachedTexts[i]->m_Priority < MinPriority) {
					MinPriority = m_CachedTexts[i]->m_Priority;
					MinIndex = i;
				}
			}
		}
	}

	// not found, create one
	if (!Surface) {
		Surface = RenderTextToTexture(text, Width, Align, MaxHeight, textOffset);
		if (Surface) {
			// write surface to cache
			if (m_CachedTexts[MinIndex] != NULL) delete m_CachedTexts[MinIndex];
			m_CachedTexts[MinIndex] = new CBCachedTTFontText;

			m_CachedTexts[MinIndex]->m_Surface = Surface;
			m_CachedTexts[MinIndex]->m_Align = Align;
			m_CachedTexts[MinIndex]->m_Width = Width;
			m_CachedTexts[MinIndex]->m_MaxHeight = MaxHeight;
			m_CachedTexts[MinIndex]->m_MaxLength = MaxLength;
			m_CachedTexts[MinIndex]->m_Priority = 1;
			m_CachedTexts[MinIndex]->m_Text = text;
			m_CachedTexts[MinIndex]->m_TextOffset = textOffset;
			m_CachedTexts[MinIndex]->m_Marked = true;
		}
	}


	// and paint it
	if (Surface) {
		RECT rc;
		CBPlatform::SetRect(&rc, 0, 0, Surface->GetWidth(), Surface->GetHeight());
		for (int i = 0; i < m_Layers.GetSize(); i++) {
			uint32 Color = m_Layers[i]->m_Color;
			uint32 OrigForceAlpha = m_Renderer->m_ForceAlphaColor;
			if (m_Renderer->m_ForceAlphaColor != 0) {
				Color = DRGBA(D3DCOLGetR(Color), D3DCOLGetG(Color), D3DCOLGetB(Color), D3DCOLGetA(m_Renderer->m_ForceAlphaColor));
				m_Renderer->m_ForceAlphaColor = 0;
			}
			Surface->DisplayTransOffset(X, Y - textOffset, rc, Color, BLEND_NORMAL, false, false, m_Layers[i]->m_OffsetX, m_Layers[i]->m_OffsetY);

			m_Renderer->m_ForceAlphaColor = OrigForceAlpha;
		}
	}


}