Пример #1
0
        public CTParagraphStyle(CTParagraphStyleSettings settings)
        {
            handle = settings == null
                                ? CTParagraphStyleCreate(null, 0)
                                : CreateFromSettings(settings);

            if (handle == IntPtr.Zero)
            {
                throw ConstructorError.Unknown(this);
            }
        }
        static unsafe IntPtr CreateFromSettings(CTParagraphStyleSettings s)
        {
            var handle = IntPtr.Zero;

            var specifiers = s.GetSpecifiers();

            var settings = new CTParagraphStyleSetting [specifiers.Count];
            var values   = new CTParagraphStyleSettingValue [specifiers.Count];

            int i = 0;

            foreach (var e in specifiers)
            {
                e.WriteValue(values, i);
                settings [i].spec      = e.Spec;
                settings [i].valueSize = (uint)e.ValueSize;
                ++i;
            }

            fixed(CTParagraphStyleSettingValue *pv = values)
            {
                for (i = 0; i < settings.Length; ++i)
                {
                    // TODO: is this safe on the ARM?
                    byte *p = &pv[i].int8;
                    settings[i].value = (IntPtr)p;
                }
                handle = CTParagraphStyleCreate(settings, settings.Length);
            }

            // Yes this weird Dispose implementation is correct, this bugzilla
            // comment explains more about it. TL;DR: check CTParagraphStyleSpecifierIntPtrsValue
            // https://bugzilla.xamarin.com/show_bug.cgi?id=54148#c4
            i = 0;
            foreach (var e in specifiers)
            {
                e.Dispose(values, i);
            }

            return(handle);
        }