Example #1
0
bool TextLayouter::LayoutSingleLineText(List<Share<BaseFontMesh>>& outMeshes, List<TextureAtlasPage*>& outPages,
                                        Size2F& outSize,
                                        IFont& font,
                                        const WStringRef& text,
                                        Alignment alignment/*=Alignment::LeftBottom*/,
                                        const Size2F& restrictSize/*=Size2F::Zero*/,
                                        ILabel* label/*=nullptr*/,
                                        bool isStatic/*=false*/)
{
    RETURN_FALSE_IF_EMPTY(text);
    outSize = restrictSize;
    WHeapString outString;
    ExpandSingleLine(font, text, outString, outSize.Width);
    outSize.Height = (float)font.LineHeight();

    ReserveMesh(outMeshes, text);

    auto maxOrigin= LayoutSingleLineMesh(outMeshes,outPages, font, outSize, outSize.Width, outString, alignment, restrictSize, label);
    outSize = GetBoundingSize(restrictSize.Width,(float)font.LineHeight(),maxOrigin, alignment, restrictSize);
    ShrinkMesh(outMeshes);
    return true;
}
Example #2
0
bool TextLayouter::LayoutMultipleLineText(List<Share<BaseFontMesh>>& outMeshes, List<TextureAtlasPage*>& outPages, Size2F& outSize,
        IFont& font,
        const WStringRef& text,
        Alignment alignment/*=Alignment::LeftBottom*/,
        const Size2F& restrictSize/*==Size2F::Zero*/,
        ILabel* label/*=nullptr*/,
        bool isStatic/*=false*/)
{
    RETURN_FALSE_IF_EMPTY(text);
    outSize = restrictSize;

    List<WHeapString> outLines;
    List<float> outLineWidths;

    if (restrictSize.Width != 0)
    {
        if (!WordWrapWithWidth(outLines, outLineWidths, outSize.Width, font, text, restrictSize.Width))
        {
            Log::Error("Invalid layout");
            return false;
        }
    }
    else
    {
        if (!WordWrap(outLines, outLineWidths, outSize.Width, font, text))
        {
            Log::Error("Invalid layout");
            return false;
        }
    }
    outSize.Height = static_cast<float>(outLineWidths.Count()*font.LineHeight());
    ReserveMesh(outMeshes, text);

    auto maxOrigin= LayoutMultipleLineMesh(outMeshes,outPages, font, outSize, outLineWidths, outLines, alignment, restrictSize, label);
    outSize = GetBoundingSize(restrictSize.Width,outSize.Height,maxOrigin, alignment, restrictSize);

    ShrinkMesh(outMeshes);
    return true;

}