Exemplo n.º 1
0
        private bool SetStyleValue(StylePropertyId id, StyleFontDefinition inlineValue, FontDefinition sharedValue)
        {
            var sv = new StyleValue();

            if (TryGetStyleValue(id, ref sv))
            {
                var font      = sv.resource.IsAllocated ? sv.resource.Target as Font : null;
                var obj       = sv.resource.Target as Object;
                var fontAsset = sv.resource.IsAllocated && TextDelegates.IsFontAssetSafe(obj) ? obj : null;
                if ((font == inlineValue.value.font && fontAsset == inlineValue.value.fontAsset) && sv.keyword == inlineValue.keyword)
                {
                    return(false);
                }

                if (sv.resource.IsAllocated)
                {
                    sv.resource.Free();
                }
            }
            else if (inlineValue.keyword == StyleKeyword.Null)
            {
                return(false);
            }

            sv.id      = id;
            sv.keyword = inlineValue.keyword;
            if (inlineValue.value.font != null)
            {
                sv.resource = GCHandle.Alloc(inlineValue.value.font);
            }
            else if (inlineValue.value.fontAsset != null)
            {
                sv.resource = GCHandle.Alloc(inlineValue.value.fontAsset);
            }
            else
            {
                sv.resource = new GCHandle();
            }

            SetStyleValue(sv);

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                if (sharedValue.font != null)
                {
                    sv.resource = GCHandle.Alloc(sharedValue.font);
                }
                else if (sharedValue.fontAsset != null)
                {
                    sv.resource = GCHandle.Alloc(sharedValue.fontAsset);
                }
                else
                {
                    sv.resource = new GCHandle();
                }
            }

            ApplyStyleValue(sv);
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a FontDefinition from <see cref="FontAsset"/>.
        /// </summary>
        /// <param name="f">The SDF font to use to display text.</param>
        /// <returns>A new FontDefinition object.</returns>
        public static FontDefinition FromSDFFont(Object f)
        {
            if (TextDelegates.IsFontAssetSafe(f))
            {
                return new FontDefinition()
                       {
                           fontAsset = f
                       }
            }
            ;

            Debug.LogError("Cannot create a FontDefinition, the type must be FontAsset");
            return(default);