Пример #1
0
        //static protected void GetNormalTitle(XElement element, XamlDomObject domObject)
        //{
        //    GetAndSetValue(element, domObject, "IBUINormalTitle", domObject.Type.ContentProperty);
        ////}

        //private void GetText(XElement element, XamlDomObject domObject)
        //{
        //    GetAndSetValue(element, domObject, "IBUIText", domObject.Type.ContentProperty);
        //}

        protected static void GetAndSetValue(XElement element, XamlDomObject domObject, string key, XamlMember member)
        {
            var valueElement = GetElementWithMatchingAttribute(element, "key", key);

            if (valueElement != null && !string.IsNullOrEmpty(valueElement.Value))
            {
                var attr      = valueElement.Attribute(XName.Get("type"));
                var textValue = valueElement.Value;
                if (attr != null)
                {
                    if (attr.Value.Equals("base64-UTF8", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var sb       = new StringBuilder();
                        var newlines = textValue.Split('\n');
                        foreach (var line in newlines)
                        {
                            sb.Append(XamlLegacyXibReader.DecodeFromBase64(line));
                        }
                        textValue = sb.ToString();
                    }
                }
                domObject.SetMemberValue(member, textValue);
            }
        }
Пример #2
0
        protected static void SetColor(XamlDomObject domObject, XElement color, XamlMember colorMember)
        {
            var colorType = color.Attribute(XName.Get("key")).Value;

            //XamlMember colorMember = GetColorMember(domObject.Type, colorType);

            //Image doesn't have a background but the XIB file allows setting it
            if (colorMember == null && domObject.Type.UnderlyingType == typeof(Image))
            {
                return;
            }

            var    colorSpace = int.Parse(GetElementWithMatchingAttribute(color, "key", "NSColorSpace").Value);
            string value      = null;

            switch (colorSpace)
            {
            case 1:     //NSRGB
            {
                var values =
                    XamlLegacyXibReader.DecodeFromBase64(GetElementWithMatchingAttribute(color, "key", "NSRGB").Value)
                    .Split(' ');

                var color2 = Color.FromRgb((byte)(double.Parse(values[0]) * 255),
                                           (byte)(double.Parse(values[1]) * 255),
                                           (byte)(double.Parse(values[2]) * 255));
                value = color2.ToString();
            }
            break;

            case 2:
            case 3:
            {
                var searchKey          = colorSpace == 2 ? "NSRGB" : "NSWhite";
                var asciiDecodedString =
                    XamlLegacyXibReader.DecodeFromBase64(GetElementWithMatchingAttribute(color, "key", searchKey).Value)
                    .Replace("\0", "");
                var values = asciiDecodedString.Split(' ');

                var doubleValues = colorSpace == 2 ? new double[4] : new double[3];
                if (values.Length >= 1)
                {
                    doubleValues[0] = double.Parse(values[0]);
                }
                if (values.Length >= 2)
                {
                    doubleValues[1] = double.Parse(values[1]);
                }
                if (values.Length >= 3)
                {
                    doubleValues[2] = double.Parse(values[2]);
                }
                if (colorSpace == 2)
                {
                    if (values.Length == 4)
                    {
                        doubleValues[3] = double.Parse(values[3]);
                    }
                    Debug.Assert(values.Length <= 4);
                }
                else
                {
                    Debug.Assert(values.Length <= 3);
                }

                byte[] rgbValues = null;
                if (colorSpace == 2)
                {
                    rgbValues = ColorConverters.CMYKtoRGB(doubleValues[0], doubleValues[1], doubleValues[2],
                                                          doubleValues[3]);
                }
                else if (colorSpace == 3)
                {
                    rgbValues = ColorConverters.LabToRGB(doubleValues[0], doubleValues[1], doubleValues[2]);
                }

                var color2 = Color.FromRgb(rgbValues[0], rgbValues[1], rgbValues[2]);

                value = color2.ToString();
            }
            break;

            default:
                throw new NotImplementedException("Doesn't suppor colorspace: " + colorSpace);
            }
            Debug.Assert(value != null);
            domObject.SetMemberValue(colorMember, value);
        }