예제 #1
0
        /// <summary>
        /// Try to pack the given glyph into the given texture width and height.
        /// </summary>
        /// <param name="glyph">The glyph to try to pack.</param>
        /// <param name="padding">The padding between this glyph and other glyphs.</param>
        /// <param name="packingMode">The packing algorithm used to pack the glyphs.</param>
        /// <param name="renderMode">The glyph rendering mode.</param>
        /// <param name="width">The width of the target atlas texture.</param>
        /// <param name="height">The height of the target atlas texture.</param>
        /// <param name="freeGlyphRects">List of GlyphRects representing the available space in the atlas.</param>
        /// <param name="usedGlyphRects">List of GlyphRects representing the occupied space in the atlas.</param>
        /// <returns></returns>
        internal static bool TryPackGlyphInAtlas(Glyph glyph, int padding, GlyphPackingMode packingMode, GlyphRenderMode renderMode, int width, int height, List <GlyphRect> freeGlyphRects, List <GlyphRect> usedGlyphRects)
        {
            GlyphMarshallingStruct glyphStruct = new GlyphMarshallingStruct(glyph);

            int freeGlyphRectCount = freeGlyphRects.Count;
            int usedGlyphRectCount = usedGlyphRects.Count;
            int totalGlyphRects    = freeGlyphRectCount + usedGlyphRectCount;

            // Make sure marshalling arrays allocations are appropriate.
            if (s_FreeGlyphRects.Length < totalGlyphRects || s_UsedGlyphRects.Length < totalGlyphRects)
            {
                int newSize = Mathf.NextPowerOfTwo(totalGlyphRects + 1);
                s_FreeGlyphRects = new GlyphRect[newSize];
                s_UsedGlyphRects = new GlyphRect[newSize];
            }

            // Copy glyph rect data to marshalling arrays.
            int glyphRectCount = Mathf.Max(freeGlyphRectCount, usedGlyphRectCount);

            for (int i = 0; i < glyphRectCount; i++)
            {
                if (i < freeGlyphRectCount)
                {
                    s_FreeGlyphRects[i] = freeGlyphRects[i];
                }

                if (i < usedGlyphRectCount)
                {
                    s_UsedGlyphRects[i] = usedGlyphRects[i];
                }
            }

            if (TryPackGlyphInAtlas_Internal(ref glyphStruct, padding, packingMode, renderMode, width, height, s_FreeGlyphRects, ref freeGlyphRectCount, s_UsedGlyphRects, ref usedGlyphRectCount))
            {
                // Copy new glyph position to source glyph.
                glyph.glyphRect = glyphStruct.glyphRect;

                freeGlyphRects.Clear();
                usedGlyphRects.Clear();

                // Copy marshalled glyph rect data
                glyphRectCount = Mathf.Max(freeGlyphRectCount, usedGlyphRectCount);
                for (int i = 0; i < glyphRectCount; i++)
                {
                    if (i < freeGlyphRectCount)
                    {
                        freeGlyphRects.Add(s_FreeGlyphRects[i]);
                    }

                    if (i < usedGlyphRectCount)
                    {
                        usedGlyphRects.Add(s_UsedGlyphRects[i]);
                    }
                }

                return(true);
            }

            return(false);
        }
예제 #2
0
        internal static bool TryPackGlyphInAtlas(Glyph glyph, int padding, GlyphPackingMode packingMode, GlyphRenderMode renderMode, int width, int height, List <GlyphRect> freeGlyphRects, List <GlyphRect> usedGlyphRects)
        {
            GlyphMarshallingStruct glyphMarshallingStruct = new GlyphMarshallingStruct(glyph);
            int  count  = freeGlyphRects.Count;
            int  count2 = usedGlyphRects.Count;
            int  num    = count + count2;
            bool flag   = FontEngine.s_FreeGlyphRects.Length < num || FontEngine.s_UsedGlyphRects.Length < num;

            if (flag)
            {
                int num2 = Mathf.NextPowerOfTwo(num + 1);
                FontEngine.s_FreeGlyphRects = new GlyphRect[num2];
                FontEngine.s_UsedGlyphRects = new GlyphRect[num2];
            }
            int num3 = Mathf.Max(count, count2);

            for (int i = 0; i < num3; i++)
            {
                bool flag2 = i < count;
                if (flag2)
                {
                    FontEngine.s_FreeGlyphRects[i] = freeGlyphRects[i];
                }
                bool flag3 = i < count2;
                if (flag3)
                {
                    FontEngine.s_UsedGlyphRects[i] = usedGlyphRects[i];
                }
            }
            bool flag4 = FontEngine.TryPackGlyphInAtlas_Internal(ref glyphMarshallingStruct, padding, packingMode, renderMode, width, height, FontEngine.s_FreeGlyphRects, ref count, FontEngine.s_UsedGlyphRects, ref count2);
            bool result;

            if (flag4)
            {
                glyph.glyphRect = glyphMarshallingStruct.glyphRect;
                freeGlyphRects.Clear();
                usedGlyphRects.Clear();
                num3 = Mathf.Max(count, count2);
                for (int j = 0; j < num3; j++)
                {
                    bool flag5 = j < count;
                    if (flag5)
                    {
                        freeGlyphRects.Add(FontEngine.s_FreeGlyphRects[j]);
                    }
                    bool flag6 = j < count2;
                    if (flag6)
                    {
                        usedGlyphRects.Add(FontEngine.s_UsedGlyphRects[j]);
                    }
                }
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Try loading the glyph for the given index value and if available populate the glyph.
        /// </summary>
        /// <param name="glyphIndex">The index of the glyph that should be loaded.</param>
        /// <param name="flags">The Load Flags.</param>
        /// <param name="glyph">The glyph using the provided index or the .notdef glyph (index 0) if no glyph was found at that index.</param>
        /// <returns>Returns true if a glyph exists at the given index. Otherwise returns false.</returns>
        public static bool TryGetGlyphWithIndexValue(uint glyphIndex, GlyphLoadFlags flags, out Glyph glyph)
        {
            GlyphMarshallingStruct glyphStruct = new GlyphMarshallingStruct();

            if (TryGetGlyphWithIndexValue_Internal(glyphIndex, flags, ref glyphStruct))
            {
                glyph = new Glyph(glyphStruct);

                return(true);
            }

            // Set glyph to null if no glyph exists for the given unicode value.
            glyph = null;

            return(false);
        }
예제 #4
0
        public static bool TryGetGlyphWithIndexValue(uint glyphIndex, GlyphLoadFlags flags, out Glyph glyph)
        {
            GlyphMarshallingStruct glyphStruct = default(GlyphMarshallingStruct);
            bool flag = FontEngine.TryGetGlyphWithIndexValue_Internal(glyphIndex, flags, ref glyphStruct);
            bool result;

            if (flag)
            {
                glyph  = new Glyph(glyphStruct);
                result = true;
            }
            else
            {
                glyph  = null;
                result = false;
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Internal function used to render and add glyphs to the cached shared texture data from outside the main thread.
        /// It is necessary to use SetSharedTextureData(texture) prior to calling this function.
        /// </summary>
        /// <param name="glyphs">The list of glyphs to be added into the provided texture.</param>
        /// <param name="padding">The padding value around the glyphs.</param>
        /// <param name="renderMode">The rendering mode used to rasterize the glyphs.</param>
        /// <returns></returns>
        internal static FontEngineError RenderGlyphsToSharedTexture(List <Glyph> glyphs, int padding, GlyphRenderMode renderMode)
        {
            int glyphCount = glyphs.Count;

            // Make sure marshaling arrays allocations are appropriate.
            if (s_GlyphMarshallingStruct_IN.Length < glyphCount)
            {
                int newSize = Mathf.NextPowerOfTwo(glyphCount + 1);
                s_GlyphMarshallingStruct_IN = new GlyphMarshallingStruct[newSize];
            }

            // Copy data to marshalling buffers
            for (int i = 0; i < glyphCount; i++)
            {
                s_GlyphMarshallingStruct_IN[i] = new GlyphMarshallingStruct(glyphs[i]);
            }

            int error = RenderGlyphsToSharedTexture_Internal(s_GlyphMarshallingStruct_IN, glyphCount, padding, renderMode);

            return((FontEngineError)error);
        }
예제 #6
0
 extern static bool TryAddGlyphToTexture_Internal(uint glyphIndex, int padding,
                                                  GlyphPackingMode packingMode, [Out] GlyphRect[] freeGlyphRects, ref int freeGlyphRectCount, [Out] GlyphRect[] usedGlyphRects, ref int usedGlyphRectCount,
                                                  GlyphRenderMode renderMode, Texture2D texture, out GlyphMarshallingStruct glyph);
예제 #7
0
 extern static int RenderGlyphToTexture_Internal(GlyphMarshallingStruct glyphStruct, int padding, GlyphRenderMode renderMode, Texture2D texture);
예제 #8
0
        /// <summary>
        /// Render and add glyph to the provided texture.
        /// </summary>
        /// <param name="glyph">The Glyph that should be added into the provided texture.</param>
        /// <param name="padding">The padding value around the glyph.</param>
        /// <param name="renderMode">The Rendering Mode for the Glyph.</param>
        /// <param name="texture">The Texture to which the glyph should be added.</param>
        /// <returns>Returns a value of zero if the glyph was successfully added to the texture.</returns>
        internal static FontEngineError RenderGlyphToTexture(Glyph glyph, int padding, GlyphRenderMode renderMode, Texture2D texture)
        {
            GlyphMarshallingStruct glyphStruct = new GlyphMarshallingStruct(glyph);

            return((FontEngineError)RenderGlyphToTexture_Internal(glyphStruct, padding, renderMode, texture));
        }
예제 #9
0
        /// <summary>
        /// Pack glyphs in the given atlas size.
        /// </summary>
        /// <param name="glyphsToAdd">Glyphs to pack in atlas.</param>
        /// <param name="glyphsAdded">Glyphs packed in atlas.</param>
        /// <param name="padding">The padding between glyphs.</param>
        /// <param name="packingMode">The packing algorithm used to pack the glyphs.</param>
        /// <param name="renderMode">The glyph rendering mode.</param>
        /// <param name="width">The width of the target atlas texture.</param>
        /// <param name="height">The height of the target atlas texture.</param>
        /// <param name="freeGlyphRects">List of GlyphRects representing the available space in the atlas.</param>
        /// <param name="usedGlyphRects">List of GlyphRects representing the occupied space in the atlas.</param>
        /// <returns></returns>
        internal static bool TryPackGlyphsInAtlas(List <Glyph> glyphsToAdd, List <Glyph> glyphsAdded, int padding, GlyphPackingMode packingMode, GlyphRenderMode renderMode, int width, int height, List <GlyphRect> freeGlyphRects, List <GlyphRect> usedGlyphRects)
        {
            // Determine potential total allocations required for glyphs and glyph rectangles.
            int glyphsToAddCount   = glyphsToAdd.Count;
            int glyphsAddedCount   = glyphsAdded.Count;
            int freeGlyphRectCount = freeGlyphRects.Count;
            int usedGlyphRectCount = usedGlyphRects.Count;
            int totalCount         = glyphsToAddCount + glyphsAddedCount + freeGlyphRectCount + usedGlyphRectCount;

            // Make sure marshaling arrays allocations are appropriate.
            if (s_GlyphMarshallingStruct_IN.Length < totalCount || s_GlyphMarshallingStruct_OUT.Length < totalCount || s_FreeGlyphRects.Length < totalCount || s_UsedGlyphRects.Length < totalCount)
            {
                int newSize = Mathf.NextPowerOfTwo(totalCount + 1);
                s_GlyphMarshallingStruct_IN  = new GlyphMarshallingStruct[newSize];
                s_GlyphMarshallingStruct_OUT = new GlyphMarshallingStruct[newSize];
                s_FreeGlyphRects             = new GlyphRect[newSize];
                s_UsedGlyphRects             = new GlyphRect[newSize];
            }

            s_GlyphLookupDictionary.Clear();

            // Copy glyph data into appropriate marshaling array.
            for (int i = 0; i < totalCount; i++)
            {
                if (i < glyphsToAddCount)
                {
                    GlyphMarshallingStruct glyphStruct = new GlyphMarshallingStruct(glyphsToAdd[i]);

                    s_GlyphMarshallingStruct_IN[i] = glyphStruct;

                    // Add reference to glyph in lookup dictionary
                    if (s_GlyphLookupDictionary.ContainsKey(glyphStruct.index) == false)
                    {
                        s_GlyphLookupDictionary.Add(glyphStruct.index, glyphsToAdd[i]);
                    }
                }

                if (i < glyphsAddedCount)
                {
                    GlyphMarshallingStruct glyphStruct = new GlyphMarshallingStruct(glyphsAdded[i]);

                    s_GlyphMarshallingStruct_OUT[i] = glyphStruct;

                    // Add reference to glyph in lookup dictionary
                    if (s_GlyphLookupDictionary.ContainsKey(glyphStruct.index) == false)
                    {
                        s_GlyphLookupDictionary.Add(glyphStruct.index, glyphsAdded[i]);
                    }
                }

                if (i < freeGlyphRectCount)
                {
                    s_FreeGlyphRects[i] = freeGlyphRects[i];
                }

                if (i < usedGlyphRectCount)
                {
                    s_UsedGlyphRects[i] = usedGlyphRects[i];
                }
            }

            bool allGlyphsIncluded = TryPackGlyphsInAtlas_Internal(s_GlyphMarshallingStruct_IN, ref glyphsToAddCount, s_GlyphMarshallingStruct_OUT, ref glyphsAddedCount,
                                                                   padding, packingMode, renderMode, width, height,
                                                                   s_FreeGlyphRects, ref freeGlyphRectCount, s_UsedGlyphRects, ref usedGlyphRectCount);

            // Clear lists and / or re-allocate arrays.
            glyphsToAdd.Clear();
            glyphsAdded.Clear();
            freeGlyphRects.Clear();
            usedGlyphRects.Clear();

            // Copy marshaled glyph data back into the appropriate lists.
            for (int i = 0; i < totalCount; i++)
            {
                if (i < glyphsToAddCount)
                {
                    GlyphMarshallingStruct glyphStruct = s_GlyphMarshallingStruct_IN[i];
                    Glyph glyph = s_GlyphLookupDictionary[glyphStruct.index];

                    // Note: In theory, only new glyphRect x and y need to be copied.
                    glyph.metrics    = glyphStruct.metrics;
                    glyph.glyphRect  = glyphStruct.glyphRect;
                    glyph.scale      = glyphStruct.scale;
                    glyph.atlasIndex = glyphStruct.atlasIndex;

                    glyphsToAdd.Add(glyph);
                }

                if (i < glyphsAddedCount)
                {
                    GlyphMarshallingStruct glyphStruct = s_GlyphMarshallingStruct_OUT[i];
                    Glyph glyph = s_GlyphLookupDictionary[glyphStruct.index];

                    glyph.metrics    = glyphStruct.metrics;
                    glyph.glyphRect  = glyphStruct.glyphRect;
                    glyph.scale      = glyphStruct.scale;
                    glyph.atlasIndex = glyphStruct.atlasIndex;

                    glyphsAdded.Add(glyph);
                }

                if (i < freeGlyphRectCount)
                {
                    freeGlyphRects.Add(s_FreeGlyphRects[i]);
                }

                if (i < usedGlyphRectCount)
                {
                    usedGlyphRects.Add(s_UsedGlyphRects[i]);
                }
            }

            return(allGlyphsIncluded);
        }
예제 #10
0
 extern static bool TryPackGlyphInAtlas_Internal(ref GlyphMarshallingStruct glyph, int padding, GlyphPackingMode packingMode, GlyphRenderMode renderMode, int width, int height,
                                                 [Out] GlyphRect[] freeGlyphRects, ref int freeGlyphRectCount, [Out] GlyphRect[] usedGlyphRects, ref int usedGlyphRectCount);
예제 #11
0
 static extern bool TryGetGlyphWithIndexValue_Internal(uint glyphIndex, GlyphLoadFlags loadFlags, ref GlyphMarshallingStruct glyphStruct);
예제 #12
0
 static extern bool TryGetGlyphWithUnicodeValue_Internal(uint unicode, GlyphLoadFlags loadFlags, ref GlyphMarshallingStruct glyphStruct);
예제 #13
0
 private static extern int RenderGlyphToTexture_Internal_Injected(ref GlyphMarshallingStruct glyphStruct, int padding, GlyphRenderMode renderMode, Texture2D texture);
예제 #14
0
 private static int RenderGlyphToTexture_Internal(GlyphMarshallingStruct glyphStruct, int padding, GlyphRenderMode renderMode, Texture2D texture)
 {
     return(FontEngine.RenderGlyphToTexture_Internal_Injected(ref glyphStruct, padding, renderMode, texture));
 }
예제 #15
0
        internal static bool TryPackGlyphsInAtlas(List <Glyph> glyphsToAdd, List <Glyph> glyphsAdded, int padding, GlyphPackingMode packingMode, GlyphRenderMode renderMode, int width, int height, List <GlyphRect> freeGlyphRects, List <GlyphRect> usedGlyphRects)
        {
            int  count  = glyphsToAdd.Count;
            int  count2 = glyphsAdded.Count;
            int  count3 = freeGlyphRects.Count;
            int  count4 = usedGlyphRects.Count;
            int  num    = count + count2 + count3 + count4;
            bool flag   = FontEngine.s_GlyphMarshallingStruct_IN.Length < num || FontEngine.s_GlyphMarshallingStruct_OUT.Length < num || FontEngine.s_FreeGlyphRects.Length < num || FontEngine.s_UsedGlyphRects.Length < num;

            if (flag)
            {
                int num2 = Mathf.NextPowerOfTwo(num + 1);
                FontEngine.s_GlyphMarshallingStruct_IN  = new GlyphMarshallingStruct[num2];
                FontEngine.s_GlyphMarshallingStruct_OUT = new GlyphMarshallingStruct[num2];
                FontEngine.s_FreeGlyphRects             = new GlyphRect[num2];
                FontEngine.s_UsedGlyphRects             = new GlyphRect[num2];
            }
            FontEngine.s_GlyphLookupDictionary.Clear();
            for (int i = 0; i < num; i++)
            {
                bool flag2 = i < count;
                if (flag2)
                {
                    GlyphMarshallingStruct glyphMarshallingStruct = new GlyphMarshallingStruct(glyphsToAdd[i]);
                    FontEngine.s_GlyphMarshallingStruct_IN[i] = glyphMarshallingStruct;
                    bool flag3 = !FontEngine.s_GlyphLookupDictionary.ContainsKey(glyphMarshallingStruct.index);
                    if (flag3)
                    {
                        FontEngine.s_GlyphLookupDictionary.Add(glyphMarshallingStruct.index, glyphsToAdd[i]);
                    }
                }
                bool flag4 = i < count2;
                if (flag4)
                {
                    GlyphMarshallingStruct glyphMarshallingStruct2 = new GlyphMarshallingStruct(glyphsAdded[i]);
                    FontEngine.s_GlyphMarshallingStruct_OUT[i] = glyphMarshallingStruct2;
                    bool flag5 = !FontEngine.s_GlyphLookupDictionary.ContainsKey(glyphMarshallingStruct2.index);
                    if (flag5)
                    {
                        FontEngine.s_GlyphLookupDictionary.Add(glyphMarshallingStruct2.index, glyphsAdded[i]);
                    }
                }
                bool flag6 = i < count3;
                if (flag6)
                {
                    FontEngine.s_FreeGlyphRects[i] = freeGlyphRects[i];
                }
                bool flag7 = i < count4;
                if (flag7)
                {
                    FontEngine.s_UsedGlyphRects[i] = usedGlyphRects[i];
                }
            }
            bool result = FontEngine.TryPackGlyphsInAtlas_Internal(FontEngine.s_GlyphMarshallingStruct_IN, ref count, FontEngine.s_GlyphMarshallingStruct_OUT, ref count2, padding, packingMode, renderMode, width, height, FontEngine.s_FreeGlyphRects, ref count3, FontEngine.s_UsedGlyphRects, ref count4);

            glyphsToAdd.Clear();
            glyphsAdded.Clear();
            freeGlyphRects.Clear();
            usedGlyphRects.Clear();
            for (int j = 0; j < num; j++)
            {
                bool flag8 = j < count;
                if (flag8)
                {
                    GlyphMarshallingStruct glyphMarshallingStruct3 = FontEngine.s_GlyphMarshallingStruct_IN[j];
                    Glyph glyph = FontEngine.s_GlyphLookupDictionary[glyphMarshallingStruct3.index];
                    glyph.metrics    = glyphMarshallingStruct3.metrics;
                    glyph.glyphRect  = glyphMarshallingStruct3.glyphRect;
                    glyph.scale      = glyphMarshallingStruct3.scale;
                    glyph.atlasIndex = glyphMarshallingStruct3.atlasIndex;
                    glyphsToAdd.Add(glyph);
                }
                bool flag9 = j < count2;
                if (flag9)
                {
                    GlyphMarshallingStruct glyphMarshallingStruct4 = FontEngine.s_GlyphMarshallingStruct_OUT[j];
                    Glyph glyph2 = FontEngine.s_GlyphLookupDictionary[glyphMarshallingStruct4.index];
                    glyph2.metrics    = glyphMarshallingStruct4.metrics;
                    glyph2.glyphRect  = glyphMarshallingStruct4.glyphRect;
                    glyph2.scale      = glyphMarshallingStruct4.scale;
                    glyph2.atlasIndex = glyphMarshallingStruct4.atlasIndex;
                    glyphsAdded.Add(glyph2);
                }
                bool flag10 = j < count3;
                if (flag10)
                {
                    freeGlyphRects.Add(FontEngine.s_FreeGlyphRects[j]);
                }
                bool flag11 = j < count4;
                if (flag11)
                {
                    usedGlyphRects.Add(FontEngine.s_UsedGlyphRects[j]);
                }
            }
            return(result);
        }