Пример #1
0
void FontAtlas::findNewCharacters(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap)
{
    std::u16string newChars;
    FT_Encoding charEncoding = _fontFreeType->getEncoding();

    //find new characters
    if (_letterDefinitions.empty())
    {
        // fixed #16169: new android project crash in android 5.0.2 device (Nexus 7) when use 3.12.
        // While using clang compiler with gnustl_static on android, the copy assignment operator of `std::u16string`
        // will affect the memory validity, it means after `newChars` is destroyed, the memory of `u16Text` holds
        // will be a dead region. `u16text` represents the variable in `Label::_utf16Text`, when somewhere
        // allocates memory by `malloc, realloc, new, new[]`, the generated memory address may be the same
        // as `Label::_utf16Text` holds. If doing a `memset` or other memory operations, the orignal `Label::_utf16Text`
        // will be in an unknown state. Meanwhile, a bunch lots of logic which depends on `Label::_utf16Text`
        // will be broken.

        // newChars = u16Text;

        // Using `append` method is a workaround for this issue. So please be carefuly while using the assignment operator
        // of `std::u16string`.
        newChars.append(u16Text);
    }
    else
    {
        auto length = u16Text.length();
        newChars.reserve(length);
        for (size_t i = 0; i < length; ++i)
        {
            auto outIterator = _letterDefinitions.find(u16Text[i]);
            if (outIterator == _letterDefinitions.end())
            {
                newChars.push_back(u16Text[i]);
            }
        }
    }

    if (!newChars.empty())
    {
        switch (charEncoding)
        {
        case FT_ENCODING_UNICODE:
        {
            for (auto u16Code : newChars)
            {
                charCodeMap[u16Code] = u16Code;
            }
            break;
        }
        case FT_ENCODING_GB2312:
        {
            conversionU16TOGB2312(newChars, charCodeMap);
            break;
        }
        default:
            OUTPUT_LOG("FontAtlas::findNewCharacters: Unsupported encoding:%d", charEncoding);
            break;
        }
    }
}
Пример #2
0
bool mapToPixelLength(std::u16string& value)
{
    if (stripLeadingWhitespace(value).empty())
        return false;
    const char16_t* input = value.c_str();
    const char16_t* end = input + value.length();
    int u;
    end = parseInt(input, end, u);
    if (!end || u < 0)
        return false;
    if (0 < u)
        value.replace(end - input, std::u16string::npos, u"px");
    else
        value.erase(end - input);
    return true;
}
Пример #3
0
bool UTF8ToUTF16(const std::string& utf8, std::u16string& outUtf16)
{
    if (utf8.empty())
    {
        outUtf16.clear();
        return true;
    }

    bool ret = false;
    
    const size_t utf16Bytes = (utf8.length()+1) * sizeof(char16_t);
    char16_t* utf16 = (char16_t*)malloc(utf16Bytes);
    memset(utf16, 0, utf16Bytes);

    char* utf16ptr = reinterpret_cast<char*>(utf16);
    const UTF8* error = NULL;

    if (llvm::ConvertUTF8toWide(2, utf8, utf16ptr, error))
    {
        outUtf16 = utf16;
        ret = true;
    }

    free(utf16);

    return ret;
}
void MediaListImp::setMediaText(const std::u16string& mediaText)
{
    clear();
    if (!mediaText.empty()) {
        CSSParser parser;
        *this = *parser.parseMediaList(mediaText);
    }
}
Пример #5
0
void KMX_Environment::Load(std::u16string const & key, std::u16string const & value) {
  assert(!key.empty());

  if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_PLATFORM)) {
    _platform = value;
  }
  else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_BASELAYOUT)) {
    _baseLayout = value;
  }
  else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_BASELAYOUTALT)) {
    _baseLayoutAlt = value;
  }
  else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_SIMULATEALTGR)) {
    _simulateAltGr = value == u"1";
  }
  else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_CAPSLOCK)) {
    _capsLock = value == u"1";
  }
  else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_BASELAYOUTGIVESCTRLRALTFORRALT)) {
    _baseLayoutGivesCtrlRAltForRAlt = value == u"1";
  }
  else {
    // Unsupported key
    assert(false);
  }
}
Пример #6
0
    TextFlow::Word TextFlow::calculateWord(std::u16string content, float scale) const
    {
        // Empty word
        Word word;
        word.spVertices = std::shared_ptr<std::vector<glm::vec3> >(new std::vector<glm::vec3>);
        word.spTextureCoordinates = std::shared_ptr<std::vector<glm::vec2> >(new std::vector<glm::vec2>);

        // Fill word with data
        float xPixelPen = 0;
        for (uint i = 0; i < content.size(); i++)
        {
            Glyph const * pGlyph = mpFont->getGlyph(mFontSize, content[i]);
            if (pGlyph == NULL)
            {
                throwWarning(
                    OperationNotifier::Operation::RUNTIME,
                    "TextFlow has character in content not covered by character set");
                continue;
            }

            float yPixelPen = 0 - (scale * (float)(pGlyph->size.y - pGlyph->bearing.y));

            // Vertices for this quad
            glm::vec3 vertexA = glm::vec3(xPixelPen, yPixelPen, 0);
            glm::vec3 vertexB = glm::vec3(xPixelPen + (scale * pGlyph->size.x), yPixelPen, 0);
            glm::vec3 vertexC = glm::vec3(xPixelPen + (scale * pGlyph->size.x), yPixelPen + (scale * pGlyph->size.y), 0);
            glm::vec3 vertexD = glm::vec3(xPixelPen, yPixelPen + (scale * pGlyph->size.y), 0);

            // Texture coordinates for this quad
            glm::vec2 textureCoordinateA = glm::vec2(pGlyph->atlasPosition.x, pGlyph->atlasPosition.y);
            glm::vec2 textureCoordinateB = glm::vec2(pGlyph->atlasPosition.z, pGlyph->atlasPosition.y);
            glm::vec2 textureCoordinateC = glm::vec2(pGlyph->atlasPosition.z, pGlyph->atlasPosition.w);
            glm::vec2 textureCoordinateD = glm::vec2(pGlyph->atlasPosition.x, pGlyph->atlasPosition.w);

            xPixelPen += scale * pGlyph->advance.x;

            // Fill into data blocks
            word.spVertices->push_back(vertexA);
            word.spVertices->push_back(vertexB);
            word.spVertices->push_back(vertexC);
            word.spVertices->push_back(vertexC);
            word.spVertices->push_back(vertexD);
            word.spVertices->push_back(vertexA);

            word.spTextureCoordinates->push_back(textureCoordinateA);
            word.spTextureCoordinates->push_back(textureCoordinateB);
            word.spTextureCoordinates->push_back(textureCoordinateC);
            word.spTextureCoordinates->push_back(textureCoordinateC);
            word.spTextureCoordinates->push_back(textureCoordinateD);
            word.spTextureCoordinates->push_back(textureCoordinateA);
        }

        // Set width of whole word
        word.pixelWidth = xPixelPen;

        return word;
    }
Пример #7
0
inline binding_string::binding_string(handles* hnd, size_t order, const std::string& str, ub1 cs_form) : m_str(brig::unicode::transform<char16_t>(str))
{
  const size_t size((m_str.size() + 1) * sizeof(char16_t));
  if (size > SHRT_MAX) throw std::runtime_error("OCI type error");
  m_ind = OCIInd(size);
  OCIBind* bnd(0);
  hnd->check(lib::singleton().p_OCIBindByPos(hnd->stmt, &bnd, hnd->err, ub4(order), (void*)m_str.c_str(), m_ind, SQLT_STR, &m_ind, 0, 0, 0, 0, OCI_DEFAULT));
  hnd->check(lib::singleton().p_OCIAttrSet(bnd, OCI_HTYPE_BIND, (void*)&cs_form, 0, OCI_ATTR_CHARSET_FORM, hnd->err));
} // binding_string::
Пример #8
0
bool UTF16ToUTF8(const std::u16string& utf16, std::string& outUtf8)
{
    if (utf16.empty())
    {
        outUtf8.clear();
        return true;
    }

    return llvm::convertUTF16ToUTF8String(utf16, outUtf8);
}
Пример #9
0
Value::
Value(const std::u16string&  s):
type(ConstCharType().make_array(s.size()+1)),
base_address(0),
size(sizeof(char16_t)*(s.size()+1))
{
  data = new uint8_t[size];

  auto  dst = reinterpret_cast<char16_t*>(data);
  auto  src = s.cbegin();

    while(*src)
    {
      *dst++ = *src++;
    }


  dst = 0;
}
Пример #10
0
void TextLabels::renderString( const std::u16string &str, vec2 *cursor, float stretch )
{
	std::u16string::const_iterator itr;
	for( itr = str.begin(); itr != str.end(); ++itr ) {
		// retrieve character code
		uint16_t id = (uint16_t)*itr;

		if( mFont->contains( id ) ) {
			// get metrics for this character to speed up measurements
			Font::Metrics m = mFont->getMetrics( id );

			// skip whitespace characters
			if( !isWhitespaceUtf16( id ) ) {
				size_t index = mVertices.size();

				Rectf bounds = mFont->getBounds( m, mFontSize );
				mVertices.push_back( vec3( *cursor + bounds.getUpperLeft(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getUpperRight(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getLowerRight(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getLowerLeft(), 0 ) );

				bounds = mFont->getTexCoords( m );
				mTexcoords.push_back( bounds.getUpperLeft() );
				mTexcoords.push_back( bounds.getUpperRight() );
				mTexcoords.push_back( bounds.getLowerRight() );
				mTexcoords.push_back( bounds.getLowerLeft() );

				mIndices.push_back( index + 0 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 1 );
				mIndices.push_back( index + 1 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 2 );

				mOffsets.insert( mOffsets.end(), 4, mOffset );
			}

			if( id == 32 )
				cursor->x += stretch * mFont->getAdvance( m, mFontSize );
			else
				cursor->x += mFont->getAdvance( m, mFontSize );
		}
	}

	//
	mBoundsInvalid = true;
}
Пример #11
0
void UserDictionaryDecoder::DecodeHeading(IBitStream *bstr, unsigned len, std::u16string &res) {
    res.clear();
    unsigned symIdx;
    for (size_t i = 0; i < len; i++) {
        _ltHeadings.Decode(*bstr, symIdx);
        unsigned sym = _headingSymbols.at(symIdx);
        assert(sym <= 0xffff);
        res += (char16_t)sym;
    }
}
Пример #12
0
bool RegexStore::patternMatch(std::u16string& in_string) {
	//No pattern matches when we don't have a valid pattern
	if (not is_compiled) {
    return false;
	}

  //Check for a match
  regmatch_t pmatch;
	std::string tmp_str(in_string.begin(), in_string.end());
  int match = regexec(&exp, tmp_str.c_str(), 1, &pmatch, 0);
	//Make sure that each character was matched and that the entire input string
	//was consumed by the pattern
  if (0 == match and 0 == pmatch.rm_so and in_string.size() == pmatch.rm_eo) {
		return true;
  }
  else {
		return false;
  }
}
Пример #13
0
	SimpleString::SimpleString(const std::u16string _str)
	{
		length = _str.size();
		s_value = new char16_t[length + 1];
		
		for (unsigned int i = 0; i < _str.size(); ++i)
			s_value[i] = _str[i];

		s_value[length] = u'\0';

		// calculate hash;
		_hash = 5381;
		int c = 0;

		char16_t * sptr = s_value;

		while ((c = *sptr++))
			_hash = ((_hash << 5) + _hash) + c;
	}
Пример #14
0
std::vector<char16_t> getChar16VectorFromUTF16String(const std::u16string& utf16)
{
    std::vector<char16_t> ret;
    size_t len = utf16.length();
    ret.reserve(len);
    for (size_t i = 0; i < len; ++i)
    {
        ret.push_back(utf16[i]);
    }
    return ret;
}
bool convertUTF16ToUTF8String(const std::u16string& utf16, std::string &Out) {
  assert(Out.empty());

  // Avoid OOB by returning early on empty input.
  if (utf16.empty())
    return true;

  const UTF16 *Src = reinterpret_cast<const UTF16 *>(utf16.data());
  const UTF16 *SrcEnd = reinterpret_cast<const UTF16 *>(utf16.data() + utf16.length());

  // Byteswap if necessary.
  std::vector<UTF16> ByteSwapped;
  if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
    ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
    for (size_t I = 0, E = ByteSwapped.size(); I != E; ++I)
      ByteSwapped[I] = SwapByteOrder_16(ByteSwapped[I]);
    Src = &ByteSwapped[0];
    SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
  }

  // Skip the BOM for conversion.
  if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_NATIVE)
    Src++;

  // Just allocate enough space up front.  We'll shrink it later.
  Out.resize(utf16.length() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
  UTF8 *Dst = reinterpret_cast<UTF8 *>(&Out[0]);
  UTF8 *DstEnd = Dst + Out.size();

  ConversionResult CR =
      ConvertUTF16toUTF8(&Src, SrcEnd, &Dst, DstEnd, strictConversion);
  assert(CR != targetExhausted);

  if (CR != conversionOK) {
    Out.clear();
    return false;
  }

  Out.resize(reinterpret_cast<char *>(Dst) - &Out[0]);
  return true;
}
Пример #16
0
std::string to_utf8(const std::u16string& str)
{
    icu_handle::get();
    static_assert(sizeof(char16_t) == sizeof(UChar),
                  "Invalid UChar definition in ICU");
    // looks dangerous, but isn't: UChar is guaranteed to be a 16-bit
    // integer type, so all we're doing here is going between signed vs.
    // unsigned
    auto buf = reinterpret_cast<const UChar*>(str.c_str());
    icu::UnicodeString u16str{buf};
    return icu_to_u8str(u16str);
}
    std::vector<TextFlow::Word> TextFlow::calculateFitWord(std::u16string content, int maxPixelWidth, float scale) const
    {
        // Calculate word from content
        Word word = calculateWord(content, scale);

        // End of recursion
        if ((content.size() == 1 && word.pixelWidth > maxPixelWidth) || content.empty())
        {
            // Return empty vector as signal of failure
            return std::vector<Word>();
        }
        else if (word.pixelWidth <= maxPixelWidth)
        {
            // If word length is ok, just return it
            return std::vector<Word>(1, word);
        }
        else
        {
            // Word is too wide and content longer than 1, split it!
            int length = (int)content.size();
            int left = length / 2;
            int right = length - left;

            // Combine results from recursive call
            std::vector<Word> leftWord = calculateFitWord(content.substr(0, left), maxPixelWidth, scale);
            std::vector<Word> rightWord = calculateFitWord(content.substr(left+1, right), maxPixelWidth, scale);

            // If one or more of both are empty, forget it
            if (leftWord.empty() || rightWord.empty())
            {
                return std::vector<Word>();
            }
            else
            {
                std::vector<Word> words(leftWord);
                words.insert(words.end(), rightWord.begin(), rightWord.end());
                return words;
            }
        }
    }
Пример #18
0
float Font::render(const std::u16string &text, glm::vec2 position, HexColor color, int caretPosition){
	empty[g_UILayer] = false;
	LastTextHeight = 0;
	LastTextLength = 0;
	lastTextSize = text.size();
	glm::vec2 currentPosition = position;
	char16_t letter;

	for (u32 i = 0; i < text.size(); i++){
		letter = text[i];
		auto &letterInfo = fontInfo->m_letters[letter];
		if (letter == '\n'){ // new line
			LastTextLength = std::max(LastTextLength, currentPosition[0] - position.x);
			LastTextHeight += height;
			currentPosition = position - glm::vec2(0, LastTextHeight);
			continue;
		}
		if (letter > L'\u00ff'){
			currentPosition.x += genSingleSymbol(letter, currentPosition, color);
			continue;
		}
		else if (i > 0){ // kerning
			currentPosition[0] += letterInfo.kerning[text[i - 1]];
		}
		renderedFonts[g_UILayer].m_size++;

		renderedFonts[g_UILayer].positions.push_back(currentPosition + letterInfo.offset);
		renderedFonts[g_UILayer].sizes.push_back(letterInfo.size);
		renderedFonts[g_UILayer].uvs.push_back(letterInfo.uv);
		renderedFonts[g_UILayer].colors.push_back(color);
		currentPosition.x += letterInfo.advance;
	}

	if (lastTextSize > 0) // compute len
		LastTextLength = currentPosition[0] - position.x;

	// placeCaret(text, position, color, caretPosition);
	renderedFonts[g_UILayer].m_size = renderedFonts[g_UILayer].uvs.size();
	return LastTextLength + 1.f;
}
Пример #19
0
void LineEdit::IntValidator::assign(std::u16string &string,
                                    const std::u16string &arg) const {
  if(arg.size()==0){
    if(string.size()==0){
      string.resize(1);
      string[0] = '0';
      }
    return;
    }

  bool good=true;
  if(arg[0]=='-'){
    if(arg.size()!=1){
      if(arg[1]=='0' && arg.size()!=2)
        good=false;
      for(size_t i=1; good && i<arg.size(); ++i ){
        const char16_t c = arg[i];
        good &= ('0'<=c && c<='9');
        }
      } else {
      good = false;
      }
    } else {
    if(arg[0]=='0' && arg.size()!=1)
      good=false;
    for(size_t i=0; good && i<arg.size(); ++i ){
      const char16_t c = arg[i];
      good &= ('0'<=c && c<='9');
      }
    }

  if(good){
    string = arg;
    } else {
    if(string.size()==0){
      string.resize(1);
      string[0] = '0';
      }
    }
  }
Пример #20
0
std::vector<std::u16string> BiDi::processText(const std::u16string& input,
                                              std::set<std::size_t> lineBreakPoints) {
    UErrorCode errorCode = U_ZERO_ERROR;

    ubidi_setPara(impl->bidiText, mbgl::utf16char_cast<const UChar*>(input.c_str()), static_cast<int32_t>(input.size()),
                  UBIDI_DEFAULT_LTR, nullptr, &errorCode);

    if (U_FAILURE(errorCode)) {
        throw std::runtime_error(std::string("BiDi::processText: ") + u_errorName(errorCode));
    }

    return applyLineBreaking(lineBreakPoints);
}
    void IPv6AddressToString(IPv6Address address, std::uint32_t scopeId, std::u16string& buffer)
    {
        const char* const InvalidIPv6AddressStr = "Invalid IPv6 address!";
        ::in6_addr v6Addr;
        auto& desAddrBytes = v6Addr.s6_addr;
        auto& srcAddrBytes = address.Bytes;
        for (std::size_t i = 0; i < kIPv4AddressBytes; ++i)
            desAddrBytes[i] = static_cast<uchar>(srcAddrBytes[i]);

        const auto& ntFunctions = GetNtFunctions();
        ulong bufferLength = {};

        auto errCode = ntFunctions.RtlIpv6AddressToStringEx(&v6Addr, static_cast<ulong>(scopeId), 0, nullptr, &bufferLength);
        Try<std::invalid_argument>(bufferLength != 0, InvalidIPv6AddressStr);

        buffer.resize(static_cast<std::size_t>(bufferLength));
        errCode = ntFunctions.RtlIpv6AddressToStringEx(&v6Addr, static_cast<ulong>(scopeId), 0, reinterpret_cast<wchar_t*>(&buffer[0]), &bufferLength);

        assert(errCode == NtFunctions::NtSuccess);

        buffer.pop_back();
    }
bool HTMLElementImp::toPxOrPercentage(std::u16string& value)
{
    stripLeadingAndTrailingWhitespace(value);
    if (value.empty())
        return false;
    const char16_t* s = value.c_str();
    while (*s) {
        if (*s == '%')
            break;
        if (!isDigit(*s))
            return false;
        ++s;
    }
    if (!*s) {
        value += u"px";
        return true;
    }
    assert(*s == '%');
    if (!s[1] && 1 < value.length())
        return true;
    return false;
}
Пример #23
0
std::string utf16_to_ascii8(const std::u16string& utf16_string)
{
	// Strip extended codes, map to '#' instead (placeholder)
	std::vector<u8> out;
	out.reserve(utf16_string.length() + 1);

	for (const auto& code : utf16_string)
	{
		out.push_back(code > 0xFF ? '#': (u8)code);
	}

	out.push_back(0);
	return { reinterpret_cast<char*>(out.data()) };
}
    void WordSuggest::suggest(std::u16string input, Dictionary const * pDictionary, std::u16string& rBestSuggestion)
    {
        // Clear up
        mSuggestions.clear();
        mThresholds.clear();

        // Fallback for suggestion
        rBestSuggestion = u"";

        // Only do something when there is input
        if (!input.empty())
        {
            // Decide whether word should start with big letter
            bool startsWithUpperCase = false;
            char16_t lowerCaseLetter = input[0];
            if (toLower(lowerCaseLetter))
            {
                startsWithUpperCase = lowerCaseLetter != input[0];
            }

            // Ask for suggestions
            std::vector<std::u16string> suggestions = pDictionary->similarWords(input, startsWithUpperCase);
            uint i = 0;
            for (const std::u16string& rSuggestion : suggestions)
            {
                mSuggestions.push_back(std::move(mpAssetManager->createTextSimple(mFontSize, 1, rSuggestion)));

                // Only add maximal allowed number of suggestions
                if (++i >= WORD_SUGGEST_MAX_SUGGESTIONS)
                {
                    break;
                }
            }

            // Save best suggestion
            if (!suggestions.empty())
            {
                // First one is best
                rBestSuggestion = suggestions[0];
            }

            // Prepare thresholds
            mThresholds.resize(mSuggestions.size(), LerpValue(0));

            // Transform and position the suggestions initially
            transformSuggestions();
            positionSuggestions();
        }
    }
Пример #25
0
bool UserDictionaryDecoder::DecodeArticle(
        IBitStream *bstr,
        std::u16string &res,
        std::u16string const& prefix,
        LenTable& ltArticles,
        std::vector<char32_t>& articleSymbols)
{
    unsigned len = bstr->read(16);
    if (len == 0xFFFF) {
        len = bstr->read(32);
    }
    res.clear();
    unsigned symIdx;
    std::vector<uint32_t> vec;
    while ((unsigned)res.length() < len) {
        ltArticles.Decode(*bstr, symIdx);
        unsigned sym = articleSymbols.at(symIdx);
        vec.push_back(sym);
        if (sym >= 0x10000) {
            if (sym >= 0x10040) {
                unsigned startIdx = bstr->read(BitLength(len));
                unsigned len = sym - 0x1003d;
                res += res.substr(startIdx, len);
                vec.push_back(startIdx);
            } else {
                unsigned startIdx = bstr->read(BitLength(prefix.length()));
                unsigned len = sym - 0xfffd;
                res += prefix.substr(startIdx, len);
                vec.push_back(startIdx);
            }
        } else {
            res += (char16_t)sym;
        }
    }
    return true;
}
Пример #26
0
/*
 * Create a new regex pattern if necessary, or keep the old one if the
 * pattern has not changed
 * Returns true on success, false on failure.
 */
bool RegexStore::preparePattern(std::u16string& patt) {
	//New pattern? Clear out the existing regex_t
	if (is_compiled and this->pattern != patt) {
		//std::cerr<<"Replacing pattern "<<std::string(pattern.begin(), pattern.end())<<" with "<<std::string(patt.begin(), patt.end())
		regfree(&exp);
		is_compiled = false;
	}
	//Do we need to compile a new regex pattern?
	if (not is_compiled) {
		//Compile a new regex pattern using the ascii string representation
		std::string tmp_string(patt.begin(), patt.end());
		int err = regcomp(&exp, tmp_string.c_str(), REG_EXTENDED);
		//Return without creating an expression if this failed
		if (0 != err) {
			return false;
			//is_compiled remains false
		}
		else {
			pattern = patt;
			is_compiled = true;
		}
	}
	return true;
}
Пример #27
0
//same thing as contructor. can be used to reinit dirList too
void dirList::reassign(const std::u16string p)
{
    entry.clear();

    FSUSER_OpenDirectory(&d, a, fsMakePath(PATH_UTF16, p.data()));

    u32 read = 0;
    do
    {
        FS_DirectoryEntry getEnt;
        FSDIR_Read(d, &read, 1, &getEnt);
        entry.push_back(getEnt);
    }while(read > 0);

    FSDIR_Close(d);
}
Пример #28
0
void FontAtlas::findNewCharacters(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap)
{
    std::u16string newChars;
    FT_Encoding charEncoding = _fontFreeType->getEncoding();

    //find new characters
    if (_letterDefinitions.empty())
    {
        newChars = u16Text;
    }
    else
    {
        auto length = u16Text.length();
        newChars.reserve(length);
        for (size_t i = 0; i < length; ++i)
        {
            auto outIterator = _letterDefinitions.find(u16Text[i]);
            if (outIterator == _letterDefinitions.end())
            {
                newChars.push_back(u16Text[i]);
            }
        }
    }

    if (!newChars.empty())
    {
        switch (charEncoding)
        {
        case FT_ENCODING_UNICODE:
        {
            for (auto u16Code : newChars)
            {
                charCodeMap[u16Code] = u16Code;
            }
            break;
        }
        case FT_ENCODING_GB2312:
        {
            conversionU16TOGB2312(newChars, charCodeMap);
            break;
        }
        default:
            CCLOG("FontAtlas::findNewCharacters: Unsupported encoding:%d", charEncoding);
            break;
        }
    }
}
Пример #29
0
void LineEdit::IntValidator::insert(std::u16string &string,
                                    size_t &cursor, size_t &ecursor,
                                    char16_t data) const {
  if( cursor==0 ){
    if(!string.empty() && string[0]=='-')
      return;

    if(data=='-' && !(string.size()>=1 && string[0]=='0')){
      Validator::insert(string,cursor,ecursor,data);
      return;
      }

    if(data=='0' && ((string.size()==1 && string[0]=='-') || string.size()==0)){
      Validator::insert(string,cursor,ecursor,data);
      return;
      }

    if(('1'<=data && data<='9') || data=='-'){
      Validator::insert(string,cursor,ecursor,data);
      return;
      }
    return;
    }

  const size_t pos = cursor-1;
  if( data=='0'
      && !(pos<string.size() && string[pos]=='-')
      && !(string.size()==1 && string[0]=='0') ){
    Validator::insert(string,cursor,ecursor,data);
    return;
    }

  if('1'<=data && data<='9'){
    if(string.size()==1 && string[0]=='0'){
      string.clear();
      cursor  = 0;
      ecursor = cursor;
      }
    Validator::insert(string,cursor,ecursor,data);
    return;
    }
  }
Пример #30
0
 void Label::DetermineTokenWidths(const std::u16string& text, double heuristicCharWidth, std::vector<double>& tokenWidths)
 {
     double tokenWidth = 0;
     int textSize = text.size();
     for(int i = 0; i < textSize; ++i)
     {
         if (text[i] != ' ')
         {
             tokenWidth += heuristicCharWidth;
         }
         else
         {
             tokenWidths.push_back(tokenWidth);
             tokenWidth = 0;
         }
     }
     
     tokenWidths.push_back(tokenWidth);
 }