Exemple #1
0
        public static bool TryGetValue(this ID2D1Properties properties, int index, out D2D1_PROPERTY_TYPE type, out byte[] data)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            data = null;
            type = properties.GetType(index);
            if (type == D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN)
            {
                return(false);
            }

            var size = properties.GetValueSize(index);

            if (size < 0)
            {
                return(false);
            }

            var bytes = new byte[size];
            var hr    = properties.GetValue(index, type, bytes, bytes.Length);

            if (hr.IsError)
            {
                return(false);
            }

            data = bytes;
            return(true);
        }
        public static bool TryGetProperty(this ID2D1Properties properties, uint index, out object value)
        {
            if (properties == null)
            {
                value = null;
                return(false);
            }

            var size = properties.GetValueSize(index);

            if (size == 0)
            {
                value = null;
                return(false);
            }

            var data = new byte[size];

            if (properties.GetValue(index, D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, data, data.Length).IsError)
            {
                value = null;
                return(false);
            }

            var type = properties.GetType(index);

            value = D2D1Property.GetValue(type, data);
            return(true);
        }
Exemple #3
0
        public static int GetValueSize(this ID2D1Properties properties, int index)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            return(properties.GetValueSize(index));
        }
        public static D2D1Property GetProperty(this ID2D1Properties properties, uint index)
        {
            if (properties == null)
            {
                return(null);
            }

            var prop = new D2D1Property();

            prop.Type = properties.GetType(index);

            var len = properties.GetPropertyNameLength(index);

            if (len > 0)
            {
                var name = new string('\0', (int)len);
                properties.GetPropertyName(index, name, len + 1);
                prop.Name = name;
            }

            var size = properties.GetValueSize(index);

            if (size > 0)
            {
                var data = new byte[size];
                if (properties.GetValue(index, D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, data, data.Length).IsSuccess)
                {
                    prop.ValueBytes = data;
                }
            }

            if (prop.Type == D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN && prop.Name == null)
            {
                return(null);
            }

            return(prop);
        }
        public static IReadOnlyList <D2D1Property> GetProperties(this ID2D1Properties properties)
        {
            if (properties == null)
            {
                return(new D2D1Property[0]);
            }

            var list = new List <D2D1Property>();

            for (uint i = 0; i < properties.GetPropertyCount(); i++)
            {
                var len  = properties.GetPropertyNameLength(i);
                var name = new string('\0', (int)len);
                properties.GetPropertyName(i, name, len + 1).ThrowOnError();
                var property = new D2D1Property();
                property.Name = name;
                property.Type = properties.GetType(i);

                var size = properties.GetValueSize(i);
                if (size > 0)
                {
                    var data = new byte[size];
                    properties.GetValue(i, property.Type, data, data.Length).ThrowOnError();
                    property.ValueBytes = data;
                }

                properties.GetSubProperties(i, out var sub);
                property.SubProperties = GetProperties(sub);
                list.Add(property);
            }

            var prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_AUTHOR));

            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_CATEGORY));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_DESCRIPTION));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_DISPLAYNAME));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_CLSID));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_INPUTS));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_MIN_INPUTS));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_MAX_INPUTS));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED));
            if (prop != null)
            {
                list.Add(prop);
            }

            prop = GetProperty(properties, unchecked ((uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION));
            if (prop != null)
            {
                list.Add(prop);
            }
            return(list);
        }