Beispiel #1
0
        public void Shape(Buffer buffer, IReadOnlyList <Feature> features, IReadOnlyList <string> shapers)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            var featuresPtr = features == null || features.Count == 0 ? IntPtr.Zero : StructureArrayToPtr(features);
            var shapersPtr  = shapers == null || shapers.Count == 0 ? IntPtr.Zero : StructureArrayToPtr(shapers);

            HarfBuzzApi.hb_shape_full(
                Handle,
                buffer.Handle,
                featuresPtr,
                featuresPtr != IntPtr.Zero ? features.Count : 0,
                shapersPtr);

            if (featuresPtr != IntPtr.Zero)
            {
                Marshal.FreeCoTaskMem(featuresPtr);
            }

            if (shapersPtr != IntPtr.Zero)
            {
                Marshal.FreeCoTaskMem(shapersPtr);
            }
        }
Beispiel #2
0
        public void Shape(Buffer buffer, IReadOnlyList <Feature> features, IReadOnlyList <string> shapers)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (buffer.Direction == Direction.Invalid)
            {
                throw new InvalidOperationException("Buffer's Direction must be valid.");
            }

            if (buffer.ContentType != ContentType.Unicode)
            {
                throw new InvalidOperationException("Buffer's ContentType must of type Unicode.");
            }

            void *[] shapersPtrs = null;
            if (shapers?.Count > 0)
            {
                shapersPtrs = new void *[shapers.Count + 1];
                int i;
                for (i = 0; i < shapers.Count; i++)
                {
                    shapersPtrs[i] = (void *)Marshal.StringToHGlobalAnsi(shapers[i]);
                }
                shapersPtrs[i] = null;
            }

            var featuresArray = features?.ToArray();

            fixed(Feature *fPtr = featuresArray)
            fixed(void **sPtr = shapersPtrs)
            {
                HarfBuzzApi.hb_shape_full(
                    Handle,
                    buffer.Handle,
                    fPtr,
                    (uint)(features?.Count ?? 0),
                    sPtr);
            }

            if (shapersPtrs != null)
            {
                for (var i = 0; i < shapersPtrs.Length; i++)
                {
                    if (shapersPtrs[i] != null)
                    {
                        Marshal.FreeHGlobal((IntPtr)shapersPtrs[i]);
                    }
                }
            }
        }
Beispiel #3
0
        public void Shape(Buffer buffer, IReadOnlyList <Feature> features, IReadOnlyList <string> shapers)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (buffer.Direction == Direction.Invalid)
            {
                throw new InvalidOperationException("Buffer's Direction must be valid.");
            }

            if (buffer.ContentType != ContentType.Unicode)
            {
                throw new InvalidOperationException("Buffer's ContentType must of type Unicode.");
            }

            var featuresPtr = features == null || features.Count == 0 ? IntPtr.Zero : StructureArrayToPtr(features);
            var shapersPtr  = shapers == null || shapers.Count == 0 ? IntPtr.Zero : StructureArrayToPtr(shapers);

            HarfBuzzApi.hb_shape_full(
                Handle,
                buffer.Handle,
                featuresPtr,
                features?.Count ?? 0,
                shapersPtr);

            if (featuresPtr != IntPtr.Zero)
            {
                Marshal.FreeCoTaskMem(featuresPtr);
            }
            if (shapersPtr != IntPtr.Zero)
            {
                Marshal.FreeCoTaskMem(shapersPtr);
            }
        }