Пример #1
0
int CharacterIterator::previous()
{
    int previous = m_index - 1;

    if (previous >= 0) {
        m_utf16Index = max(m_utf16Index - characterSize(previous), 0);
        m_index = previous;
    } else {
        m_index = TextBreakDone;
        m_utf16Index = TextBreakDone;
    }

    return m_index;
}
Пример #2
0
int CharacterIterator::next()
{
    int next = m_index + 1;

    if (next <= m_length) {
        m_utf16Index = min(m_utf16Index + characterSize(m_index), m_utf16Length);
        m_index = next;
    } else {
        m_index = TextBreakDone;
        m_utf16Index = TextBreakDone;
    }

    return m_index;
}
Пример #3
0
KDPoint KDContext::writeString(const char * text, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor, int maxLength, bool transparentBackground) {
  KDPoint position = p;
  int characterWidth = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH;
  int characterHeight = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT: BITMAP_SmallFont_CHARACTER_HEIGHT;
  KDPoint characterSize(characterWidth, 0);

  const char * end = text+maxLength;
  while(*text != 0 && text != end) {
    writeChar(*text, position, size, textColor, backgroundColor, transparentBackground);
    if (*text == '\n') {
      position = KDPoint(0, position.y()+characterHeight);
    } else if (*text == '\t') {
      position = position.translatedBy(KDPoint(KDText::k_tabCharacterWidth*characterWidth, 0));
    } else {
      position = position.translatedBy(characterSize);
    }
    text++;
  }
  return position;
}
Пример #4
0
void CharacterIterator::setUTF16Index(int index)
{
    if (index == m_utf16Index)
        return;
    if (index <= 0)
        m_utf16Index = m_index = 0;
    else if (index >= m_utf16Length) {
        m_utf16Index = m_utf16Length;
        m_index = m_length;
    } else if (m_length == m_utf16Length)
        m_utf16Index = m_index = index;
    else {
        m_utf16Index = index;
        int utf16Index = 0;
        int utf8Index = 0;
        while (utf16Index < index) {
            utf16Index += characterSize(utf8Index);
            utf8Index++;
        }
        m_index = utf8Index;
    }
}