CalculateOffsetToFit() static public method

Calculate the character index offset required to print the end of the specified text.
static public CalculateOffsetToFit ( string text ) : int
text string
return int
Beispiel #1
0
 public int CalculateOffsetToFit(string text)
 {
     this.UpdateNGUIText();
     NGUIText.encoding    = false;
     NGUIText.symbolStyle = NGUIText.SymbolStyle.None;
     return(NGUIText.CalculateOffsetToFit(text));
 }
    static int CalculateOffsetToFit(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        string arg0 = LuaScriptMgr.GetLuaString(L, 1);
        int    o    = NGUIText.CalculateOffsetToFit(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Beispiel #3
0
    public int CalculateOffsetToFit(string text)
    {
        UpdateNGUIText();
        NGUIText.encoding    = false;
        NGUIText.symbolStyle = NGUIText.SymbolStyle.None;
        int result = NGUIText.CalculateOffsetToFit(text);

        NGUIText.bitmapFont  = null;
        NGUIText.dynamicFont = null;
        return(result);
    }
Beispiel #4
0
    /// <summary>
    /// Calculate the offset necessary to fit the specified text. Helper function.
    /// </summary>

    public int CalculateOffsetToFit(string text)
    {
        if (bitmapFont != null)
        {
            return(bitmapFont.CalculateOffsetToFit(text, fontSize, width, false, UIFont.SymbolStyle.None));
        }
#if DYNAMIC_FONT
        return(NGUIText.CalculateOffsetToFit(text, trueTypeFont, fontSize, fontStyle, width));
#else
        return(0);
#endif
    }
Beispiel #5
0
 static public int CalculateOffsetToFit_s(IntPtr l)
 {
     try {
         System.String a1;
         checkType(l, 1, out a1);
         var ret = NGUIText.CalculateOffsetToFit(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #6
0
 static int CalculateOffsetToFit(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         string arg0 = ToLua.CheckString(L, 1);
         int    o    = NGUIText.CalculateOffsetToFit(arg0);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #7
0
    /// <summary>
    /// Calculate the offset necessary to fit the specified text. Helper function.
    /// </summary>

    public int CalculateOffsetToFit(string text)
    {
        UpdateNGUIText();
        NGUIText.current.encoding    = false;
        NGUIText.current.symbolStyle = NGUIText.SymbolStyle.None;

        if (bitmapFont != null)
        {
            return(bitmapFont.CalculateOffsetToFit(text));
        }
#if DYNAMIC_FONT
        return(NGUIText.CalculateOffsetToFit(trueTypeFont, text));
#else
        return(0);
#endif
    }
Beispiel #8
0
    private static int CalculateOffsetToFit(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            string text = ToLua.CheckString(L, 1);
            int    n    = NGUIText.CalculateOffsetToFit(text);
            LuaDLL.lua_pushinteger(L, n);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Beispiel #9
0
    /// <summary>
    /// Calculate the character index offset required to print the end of the specified text.
    /// Originally contributed by MightyM: http://www.tasharen.com/forum/index.php?topic=1049.0
    /// </summary>

    public int CalculateOffsetToFit(string text, int size, int lineWidth, bool encoding, SymbolStyle symbolStyle)
    {
        if (lineWidth < 1)
        {
            return(0);
        }
        if (mReplacement != null)
        {
            return(mReplacement.CalculateOffsetToFit(text, size, lineWidth, encoding, symbolStyle));
        }

#if DYNAMIC_FONT
        if (isDynamic)
        {
            return(NGUIText.CalculateOffsetToFit(text, mDynamicFont, size, mDynamicFontStyle, lineWidth));
        }
#endif
        int     textLength            = text.Length;
        int     remainingWidth        = lineWidth;
        BMGlyph followingGlyph        = null;
        int     currentCharacterIndex = textLength;
        bool    useSymbols            = encoding && symbolStyle != SymbolStyle.None && hasSymbols;

        while (currentCharacterIndex > 0 && remainingWidth > 0)
        {
            char currentCharacter = text[--currentCharacterIndex];

            // See if there is a symbol matching this text
            BMSymbol symbol = useSymbols ? MatchSymbol(text, currentCharacterIndex, textLength) : null;

            // Calculate how wide this symbol or character is going to be
            int glyphWidth = mSpacingX;

            if (symbol != null)
            {
                glyphWidth += symbol.advance;
            }
            else
            {
                // Find the glyph for this character
                BMGlyph glyph = mFont.GetGlyph(currentCharacter);

                if (glyph != null)
                {
                    glyphWidth    += glyph.advance + ((followingGlyph == null) ? 0 : followingGlyph.GetKerning(currentCharacter));
                    followingGlyph = glyph;
                }
                else
                {
                    followingGlyph = null;
                    continue;
                }
            }

            // Remaining width after this glyph gets printed
            remainingWidth -= glyphWidth;
        }
        if (remainingWidth < 0)
        {
            ++currentCharacterIndex;
        }
        return(currentCharacterIndex);
    }