public static IComObject <T> CreateTextLayout <T>(this IDWriteFactory factory,
                                                          IDWriteTextFormat format,
                                                          string text,
                                                          int textLength  = 0,
                                                          float maxWidth  = float.MaxValue,
                                                          float maxHeight = float.MaxValue
                                                          ) where T : IDWriteTextLayout
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            textLength = textLength <= 0 ? text.Length : textLength;
            factory.CreateTextLayout(text, (uint)textLength, format, maxWidth, maxHeight, out var layout).ThrowOnError();
            return(new ComObject <T>((T)layout));
        }