当前位置: 首页>>代码示例>>C++>>正文


C++ std::u32string类代码示例

本文整理汇总了C++中std::u32string的典型用法代码示例。如果您正苦于以下问题:C++ u32string类的具体用法?C++ u32string怎么用?C++ u32string使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了u32string类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getTextLength

int32_t FreeTypeFont::getTextLength(const std::u32string& text, const size_t size)
{
    if (!face)
    {
        return -1;
    }

    int32_t textLength = 0;

    size_t textIndex = 0;

    FontCacheEntry* fontCacheEntry;

    while (textIndex < text.length())
    {
        fontCacheEntry = getGlyph(text[textIndex], size);

        if (fontCacheEntry == nullptr)
        {
            return -1;
        }

        textLength += fontCacheEntry->advanceX;

        textIndex++;
    }

    return textLength;
}
开发者ID:Xertz,项目名称:Vulkan,代码行数:29,代码来源:FreeTypeFont.cpp

示例2: operator

 void operator()(const std::u32string& str) {
     m_serializer->acquire(sizeof(std::uint32_t) + str.size());
     write_int(m_serializer, static_cast<std::uint32_t>(str.size()));
     for (char32_t c : str) {
         // force writer to use exactly 32 bit
         write_int(m_serializer, static_cast<std::uint32_t>(c));
     }
 }
开发者ID:lihongjun,项目名称:libcppa,代码行数:8,代码来源:binary_serializer.cpp

示例3:

inline void
designer< T, C, N >::drawText( T x, T y, const std::u32string &text ) {

	// Set the pen position
	setPenPosition( x, y );

	// Draw the unicode string
	drawText( text.begin(), text.end() );
}
开发者ID:vehagn,项目名称:Rpi-hw,代码行数:9,代码来源:designer-inl.hpp

示例4: doFillGlyphCache

void FreeTypeFont::doFillGlyphCache(GlyphCache& cache, const std::u32string& characters) {
    /** @bug Crash when atlas is too small */

    /* Get glyph codes from characters */
    std::vector<FT_UInt> charIndices;
    charIndices.resize(characters.size()+1);
    charIndices[0] = 0;
    std::transform(characters.begin(), characters.end(), charIndices.begin()+1,
        [this](const char32_t c) { return FT_Get_Char_Index(ftFont, c); });

    /* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */
    std::sort(charIndices.begin(), charIndices.end());
    charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end());

    /* Sizes of all characters */
    std::vector<Vector2i> charSizes;
    charSizes.reserve(charIndices.size());
    for(FT_UInt c: charIndices) {
        CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(ftFont, c, FT_LOAD_DEFAULT) == 0);
        charSizes.push_back(Vector2i(ftFont->glyph->metrics.width, ftFont->glyph->metrics.height)/64);
    }

    /* Create texture atlas */
    const std::vector<Range2Di> charPositions = cache.reserve(charSizes);

    /* Render all characters to the atlas and create character map */
    Containers::Array<char> pixmap{Containers::ValueInit, std::size_t(cache.textureSize().product())};
    for(std::size_t i = 0; i != charPositions.size(); ++i) {
        /* Load and render glyph */
        /** @todo B&W only if radius != 0 */
        FT_GlyphSlot glyph = ftFont->glyph;
        CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0);
        CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0);

        /* Copy rendered bitmap to texture image */
        const FT_Bitmap& bitmap = glyph->bitmap;
        CORRADE_INTERNAL_ASSERT(std::abs(Int(bitmap.width)-charPositions[i].sizeX()) <= 2);
        CORRADE_INTERNAL_ASSERT(std::abs(Int(bitmap.rows)-charPositions[i].sizeY()) <= 2);
        for(Int yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout)
            for(Int xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout)
                pixmap[yout*cache.textureSize().x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin];

        /* Insert glyph parameters into cache */
        cache.insert(charIndices[i],
            Vector2i(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].sizeY()),
            charPositions[i]);
    }

    /* Set cache image */
    #ifndef MAGNUM_TARGET_GLES2
    Image2D image(PixelFormat::Red, PixelType::UnsignedByte, cache.textureSize(), std::move(pixmap));
    #else
    Image2D image(Context::current() && Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>() ?
        PixelFormat::Red : PixelFormat::Luminance, PixelType::UnsignedByte, cache.textureSize(), std::move(pixmap));
    #endif
    cache.setImage({}, image);
}
开发者ID:Squareys,项目名称:magnum-plugins,代码行数:57,代码来源:FreeTypeFont.cpp

示例5: TagItems

 TagItems(const std::u32string& tagStartWithAttrs) {
   size_t tmp;
   if(tagStartWithAttrs.length() > 0 && (tmp = tagStartWithAttrs.find(' ')) != std::u32string::npos) {
     tagStart = tagStartWithAttrs.substr(0, tmp);
     tagEnd = tagStart + U">";
     tagEnd.insert(1, U"/");
   }
   else {
     tagStart = tagStartWithAttrs;
     tagEnd = tagStartWithAttrs  + U">";
     tagEnd.insert(1, U"/");
   }
 }
开发者ID:andresmeidla,项目名称:html-hound,代码行数:13,代码来源:htmlhound.cpp

示例6: prepareText

VkBool32 FreeTypeFont::prepareText(const ICommandBuffersSP& cmdBuffer, const std::u32string& text, const size_t size)
{
    if (!face || !cmdBuffer.get())
    {
        return VK_FALSE;
    }

    size_t textIndex = 0;

    FontCacheEntry* fontCacheEntry;

    while (textIndex < text.length())
    {
        fontCacheEntry = getGlyph(cmdBuffer, text[textIndex], size);

        if (fontCacheEntry == nullptr)
        {
            return VK_FALSE;
        }

        textIndex++;
    }

    return VK_TRUE;
}
开发者ID:Xertz,项目名称:Vulkan,代码行数:25,代码来源:FreeTypeFont.cpp

示例7: findNewCharacters

void FontAtlas::findNewCharacters(const std::u32string& u32Text, std::unordered_map<unsigned int, unsigned int>& charCodeMap)
{
    std::u32string 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::u32string`
        // will affect the memory validity, it means after `newChars` is destroyed, the memory of `u32Text` holds
        // will be a dead region. `u32text` represents the variable in `Label::_utf32Text`, when somewhere
        // allocates memory by `malloc, realloc, new, new[]`, the generated memory address may be the same
        // as `Label::_utf32Text` holds. If doing a `memset` or other memory operations, the orignal `Label::_utf32Text`
        // will be in an unknown state. Meanwhile, a bunch lots of logic which depends on `Label::_utf32Text`
        // will be broken.
        
        // newChars = u32Text;
        
        // Using `append` method is a workaround for this issue. So please be carefuly while using the assignment operator
        // of `std::u32string`.
        newChars.append(u32Text);
    }
    else
    {
        auto length = u32Text.length();
        newChars.reserve(length);
        for (size_t i = 0; i < length; ++i)
        {
            auto outIterator = _letterDefinitions.find(u32Text[i]);
            if (outIterator == _letterDefinitions.end())
            {
                newChars.push_back(u32Text[i]);
            }
        }
    }

    if (!newChars.empty())
    {
        switch (charEncoding)
        {
        case FT_ENCODING_UNICODE:
        {
            for (auto u32Code : newChars)
            {
                charCodeMap[u32Code] = u32Code;
            }
            break;
        }
        case FT_ENCODING_GB2312:
        {
            conversionU32TOGB2312(newChars, charCodeMap);
            break;
        }
        default:
            CCLOG("FontAtlas::findNewCharacters: Unsupported encoding:%d", charEncoding);
            break;
        }
    }
}
开发者ID:FenneX,项目名称:FenneXEmptyProject,代码行数:60,代码来源:CCFontAtlas.cpp

示例8: UTF8ToUTF32

bool UTF8ToUTF32(const std::string& utf8, std::u32string& outUtf32)
{
	if (utf8.empty())
	{
		outUtf32.clear();
		return true;
	}

	bool ret = false;

	const size_t utf32Bytes = (utf8.length() + 1) * sizeof(char32_t);
	char32_t* utf32 = (char32_t*)malloc(utf32Bytes);
	memset(utf32, 0, utf32Bytes);

	char* utf32ptr = reinterpret_cast<char*>(utf32);
	const UTF8* error = NULL;

	if (llvm::ConvertUTF8toWide(4, utf8, utf32ptr, error))
	{
		outUtf32 = utf32;
		ret = true;
	}

	free(utf32);

	return ret;
}
开发者ID:lmxing1987,项目名称:CrossApp,代码行数:27,代码来源:ccUTF8.cpp

示例9: findTags

int findTags(const std::u32string& html, std::map<std::u32string, std::vector<Position> >& tags) {
  size_t index = 0;
  size_t htmlLen = html.length();
  while((index = html.find(U"<", index)) != std::u32string::npos) {
    for(std::map<std::u32string, std::vector<Position> >::iterator itr = tags.begin(); itr != tags.end(); ++itr) {
      const std::u32string& str = itr->first;
      if(index + str.length() <= htmlLen) {
        if(memcmp(html.c_str() + index, str.c_str(), str.length()*sizeof(str[0])) == 0) {
          itr->second.push_back(Position(index, 0));
        }
      }
    }
    ++index;
  }
  return 0;
}
开发者ID:andresmeidla,项目名称:html-hound,代码行数:16,代码来源:htmlhound.cpp

示例10: setPunctuationChars

//--------------------------------------------------------------
void ofxEditorSyntax::setPunctuationChars(const std::u32string &chars) {
	if(chars.length() == 0) {
		ofLogWarning("ofxEditorSyntax") << "empty punctuation string";
		return;
	}
	punctuationChars = chars;
}
开发者ID:Akira-Hayasaka,项目名称:ofxGLEditor,代码行数:8,代码来源:ofxEditorSyntax.cpp

示例11: str

renderer_i::texture sfml2_renderer::make_text_label(const std::u32string& text,
                                                    const color& fill,
                                                    const font& font,
                                                    float point_size,
                                                    text_style style)
{
    const sfml2_font& tmp = dynamic_cast<const sfml2_font&>(*font);
    const sf::Font& sffont = tmp.sf_font();

    sf::String str(reinterpret_cast<const sf::Uint32*>(text.c_str()));
    sf::Text label(str, sffont, (int)point_size);
    sf::RenderTexture rt;

    auto size = label.getLocalBounds();
    if (!rt.create(size.width + 1, font->height(point_size) + 1))
        throw std::runtime_error("cannot create sf::RenderTexture");

    rt.clear(sf::Color::Transparent);
    label.move(0, -label.getLocalBounds().top);
    label.setColor(col(fill));
    label.setStyle(static_cast<sf::Uint32>(style));
    rt.draw(label);
    rt.display();
    return texture{new sfml2_texture{rt.getTexture()}};
}
开发者ID:Nocte-,项目名称:hexahedra,代码行数:25,代码来源:sfml2.cpp

示例12: setOperatorChars

//--------------------------------------------------------------
void ofxEditorSyntax::setOperatorChars(const std::u32string &chars) {
	if(chars.length() == 0) {
		ofLogWarning("ofxEditorSyntax") << "empty operator string";
		return;
	}
	operatorChars = chars;
}
开发者ID:Akira-Hayasaka,项目名称:ofxGLEditor,代码行数:8,代码来源:ofxEditorSyntax.cpp

示例13: dynamicHint

Text::Text(Mat4f const & transformation, std::string const & fontname, std::u32string const & text) :
   dynamicHint(text.empty()), modelMat(transformation),
   fontname(fontname), string(text),
   vao(nullptr), vbo(nullptr), ibo(nullptr)
{
   init();
}
开发者ID:Svensational,项目名称:TowerDefense,代码行数:7,代码来源:text.cpp

示例14: utf32_to_utf8

std::string utf32_to_utf8(const std::u32string & str_u32){
	std::string str_u8;
	str_u8.reserve(str_u32.length()); // just a guess.
	for(const uint32_t u32 : str_u32)
		str_u8.append(utf32_to_utf8(u32));
	return str_u8;
}
开发者ID:PADrend,项目名称:Util,代码行数:7,代码来源:StringUtils.cpp

示例15: GetSize

Rect FTFont::GetSize(std::u32string const& txt) const {
	int const s = Font::Default()->GetSize(txt).width;

	if (s == -1) {
		Output::Warning("Text contains invalid chars. Is the encoding correct?");

		return Rect(0, 0, pixel_size() * txt.length() / 2, pixel_size());
	} else {
		return Rect(0, 0, s, pixel_size());
	}
}
开发者ID:EasyRPG,项目名称:Player,代码行数:11,代码来源:font.cpp


注:本文中的std::u32string类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。