Пример #1
0
 void operator()(const std::u16string& str) {
     m_serializer->acquire(sizeof(std::uint32_t) + str.size());
     write_int(m_serializer, static_cast<std::uint32_t>(str.size()));
     for (char16_t c : str) {
         // force writer to use exactly 16 bit
         write_int(m_serializer, static_cast<std::uint16_t>(c));
     }
 }
TEST(InputU16StringBufferTest, CopiesValue)
{
	std::u16string const data(u"dummy data");
	cpp_odbc::level2::input_u16string_buffer buffer(data);

	ASSERT_EQ(data.size(), buffer.size());

	for (std::size_t i = 0; i < data.size(); ++i) {
		EXPECT_EQ(data[i], buffer.data_pointer()[i]);
	}
}
Пример #3
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;
    }
Пример #4
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::
Пример #5
0
void LineEdit::IntValidator::erase(std::u16string &string,
                                   size_t &scursor,
                                   size_t &ecursor) const {
  Validator::erase(string,scursor,ecursor);
  if(string.size()==1 && string[0]=='-')
    string[0] = '0';

  if(string.empty())
    string.push_back('0');
  }
Пример #6
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;
}
Пример #7
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;
	}
    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;
            }
        }
    }
Пример #9
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;
}
Пример #10
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);
 }
Пример #11
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;
  }
}
Пример #12
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';
      }
    }
  }
Пример #13
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;
    }
  }
Пример #14
0
std::string CodeConvertU16(const std::u16string & s)
{

	const int Max_In_Size = 4;
	std::locale sys_loc("");
	const char16_t * src_insrc = s.c_str();
	const size_t BUFFER_SIZE = s.size() * Max_In_Size;
	const size_t OUT_SIZE = sizeof(char);
	// TODO:
	//  reasonable size , it may be too large the allocation to
	//  on the Out[BUFFER_SIZE]
	char * extern_buffer = new char[BUFFER_SIZE];
	memset(extern_buffer, 0, BUFFER_SIZE * OUT_SIZE);

	const char16_t * intern_from = src_insrc;
	const char16_t * intern_from_end = intern_from + s.size();
	const char16_t * intern_from_next = 0;

	char * extern_from = extern_buffer;
	char * extern_from_end = extern_from + BUFFER_SIZE;
	char * extern_from_next = 0;

	typedef std::codecvt<char16_t, char, std::mbstate_t> CodeCvtFacet;

	// TODO:
	//  it is required to have the typename in front of the
	//     CodeCvtFacet
	// It is because of the CodeCvtFacet is a dependent scope, which means it required
	// to explicitly tell the compiler that the CodeCvtFacet is a type
	//
	typename CodeCvtFacet::result cvt_rst = std::use_facet<CodeCvtFacet>(sys_loc).out(
	                                            out_cvt_state,
	                                            intern_from,
	                                            intern_from_end,
	                                            intern_from_next,
	                                            extern_from,
	                                            extern_from_end,
	                                            extern_from_next
	                                        );

	if (cvt_rst != CodeCvtFacet::ok) {
		switch (cvt_rst) {
		case CodeCvtFacet::error:
			std::cerr << "partial";
			break;
		case CodeCvtFacet::partial:
			std::cerr << "partial";
			break;
		case CodeCvtFacet::noconv:
			std::cerr << "noconv";
			break;
		default:
			std::cerr << "unknown";
			break;

		}
		std::cerr << ", please check out_cvt_state."
		          << std::endl;
	}
	std::string result = extern_buffer;
	delete[] extern_buffer;
	return result;
}
Пример #15
0
// Takes UTF16 input in logical order and applies Arabic shaping to the input while maintaining
// logical order. Output won't be intelligible until the bidirectional algorithm is applied
std::u16string applyArabicShaping(const std::u16string& input) {
    UErrorCode errorCode = U_ZERO_ERROR;

    const int32_t outputLength =
        u_shapeArabic(mbgl::utf16char_cast<const UChar*>(input.c_str()), static_cast<int32_t>(input.size()), nullptr, 0,
                      (U_SHAPE_LETTERS_SHAPE & U_SHAPE_LETTERS_MASK) |
                          (U_SHAPE_TEXT_DIRECTION_LOGICAL & U_SHAPE_TEXT_DIRECTION_MASK),
                      &errorCode);

    // Pre-flighting will always set U_BUFFER_OVERFLOW_ERROR
    errorCode = U_ZERO_ERROR;

    std::u16string outputText(outputLength, 0);

    u_shapeArabic(mbgl::utf16char_cast<const UChar*>(input.c_str()), static_cast<int32_t>(input.size()), mbgl::utf16char_cast<UChar*>(&outputText[0]), outputLength,
                  (U_SHAPE_LETTERS_SHAPE & U_SHAPE_LETTERS_MASK) |
                      (U_SHAPE_TEXT_DIRECTION_LOGICAL & U_SHAPE_TEXT_DIRECTION_MASK),
                  &errorCode);

    // If the algorithm fails for any reason, fall back to non-transformed text
    if (U_FAILURE(errorCode))
        return input;

    return outputText;
}
Пример #16
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);
}
input_u16string_buffer::input_u16string_buffer(std::u16string const & data) :
	data_(data.size() + 1)
{
	memcpy(data_.data(), data.data(), data_.size() * sizeof(char16_t));
}
Пример #18
0
std::string to_utf8(const std::u16string &s)
{
	std::wstring_convert<std::codecvt_utf8<int16_t>, int16_t> convert;
	auto p = reinterpret_cast<const int16_t *>(s.data());
	return convert.to_bytes(p, p + s.size());
}
Пример #19
0
// VS 2015 Bug: https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error?forum=vcgeneral
std::string utf16_to_utf8(std::u16string utf16_string)
{
	std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t> convert;
	auto p = reinterpret_cast<const int16_t *>(utf16_string.data());
	return convert.to_bytes(p, p + utf16_string.size());
}
Пример #20
0
void RenderString::CreateRenderCharacters(const std::u16string& newString) {
	if (!newString.empty() && mFont) {
		int advanceAccum = 0; // the accumulated horizontal advance for the current line
		int kerningAccum = 0; // the accumulated kerning offset for the current line
		int lineOffset = 0; // the vertical offset of the current line
		int lineHeight = mFont->GetLineHeight(); // retrieve and store the new line offset
		
		if (!mString.empty() && !mRenderChars.empty()) { // if we already have characters entered...
			if (mString.back() == u'\n') { // if the last character entered was a new line...
				lineOffset = mRenderChars.back().mLineHeight + lineHeight; // adjust the line offset for following characters
			}
			else {
				// laod the states of the accumulators from the previous characters entered
				advanceAccum = mRenderChars.back().mAdvanceAccum;
				kerningAccum = mRenderChars.back().mKerningAccum;
				lineOffset = mRenderChars.back().mLineHeight;
				
				kerningAccum += mFont->GetKerning(mString.back(), newString.front()); // adjust the kerning offset for the new character
			}
		}
		
		for (unsigned int i = 0u; i < newString.size(); ++i) {
			char16_t codePoint = newString.at(i);
			
			if (codePoint == u'\n') { // if the current character is a new line...
				advanceAccum = 0; // reset the horizontal advance
				kerningAccum = 0; // reset the kerning offset
				lineOffset += lineHeight; // increment the vertical offset by the new line height
				continue; // go to the next character
			}
			
			try {
				const FontBase::Glyph& glyph = mFont->GetGlyph(codePoint); // get the glyph object for the current character
				Shape shape = glyph.mBaseShape; // get the glyph shape from the glyph object
				float height = 0.0f; // the height of the glyph shape used for positional offsetting
				
				{
					const std::vector<glm::vec2>& bbox = shape.GetLocalBoundingBox(); // get the bounding box of the glyph
					if (!bbox.empty()) { // if the bounding box is valid...
						height = bbox.at(2).y - bbox.at(0).y; // calculate the height of the glyph shape
					}
				}
				
				shape.SetPosition(glm::vec2((advanceAccum + kerningAccum) + glyph.mBearing.x,
						((mFont->GetBearingMax().y - glyph.mBearing.y) - mFont->GetBearingMax().y) + lineOffset)); // position the glyph shape
				
				{ // update the local bounding box
					// get the bounding box of the newly added character
					std::vector<glm::vec2> bbox = shape.GetGlobalBoundingBox();
					
					if (bbox.size() > 3) { // if the bounding box is valid...
						mTopLeft.x = std::min(bbox.at(0).x, mTopLeft.x);
						mTopLeft.y = std::min(bbox.at(0).y, mTopLeft.y);
						
						mBottomRight.x = std::max(bbox.at(2).x, mBottomRight.x);
						mBottomRight.y = std::max(bbox.at(2).y, mBottomRight.y);
					}
				}
				
				advanceAccum += glyph.mAdvance; // increment the horizontal advance accumulator by the current glyph's advance metric
				if (i != newString.size() - 1) { // if this is not the final character in the string...
					kerningAccum += mFont->GetKerning(codePoint, newString.at(i + 1)); // increment the kerning offset by the kerning value of this and the next character
				}
				
				mRenderChars.push_back({std::move(shape), advanceAccum, kerningAccum, lineOffset,
						mTopLeft, mBottomRight});
			} catch(std::exception& e) {
				std::cout << "unknown codepoint: " << codePoint << std::endl;
			}
		}
		
		// update the full sized (not yet scaled) local bounding box
		glm::vec2 dimensions = mBottomRight - mTopLeft;
		mLocalBoundingBoxFull.clear();
		mLocalBoundingBoxFull.emplace_back(0.0f, 0.0f);
		mLocalBoundingBoxFull.emplace_back(dimensions.x, 0.0f);
		mLocalBoundingBoxFull.emplace_back(dimensions.x, dimensions.y);
		mLocalBoundingBoxFull.emplace_back(0.0f, dimensions.y);
	}
}
Пример #21
0
Tempest::Size Tempest::FontElement::textSize(const std::u16string &str ) const {
  return textSize( str.c_str(), str.c_str()+str.size() );
  }