public unsafe NativeTextLayout CreateTextLayout(ref NativeParagraphStyle paragraphStyle,
                                                    ref NativeTextStyle textStyle,
                                                    ReadOnlySpan <char> text,
                                                    float maxWidth,
                                                    float maxHeight)
    {
        // This is to avoid a null-pointer which is rejected by DirectWrite, even though length 0
        // is acceptable
        if (text.IsEmpty)
        {
            text = EmptyText;
        }

        fixed(char *textPtr = text)
        {
            if (!DrawingEngine_CreateTextLayout(
                    _native,
                    ref paragraphStyle,
                    ref textStyle,
                    textPtr,
                    text.Length,
                    maxWidth,
                    maxHeight,
                    out var textLayoutNative,
                    out var error
                    ))
            {
                throw new InvalidOperationException("Failed to create TextLayout: " + error);
            }

            return(new NativeTextLayout(textLayoutNative));
        }
    }
예제 #2
0
 public void SetStyle(int start, int length, NativeTextStyleProperty properties, ref NativeTextStyle style)
 {
     if (!TextLayout_SetStyle(NativePointer, (uint)start, (uint)length, properties, ref style, out var error))
     {
         throw new InvalidOperationException("Couldn't set text style: " + error);
     }
 }
예제 #3
0
 private static extern bool TextLayout_SetStyle(IntPtr textLayout,
                                                uint start,
                                                uint length,
                                                NativeTextStyleProperty properties,
                                                ref NativeTextStyle style,
                                                [MarshalAs(UnmanagedType.LPWStr)]
                                                out string error
                                                );
 private static extern unsafe bool DrawingEngine_CreateTextLayout(
     IntPtr drawingEngine,
     [In]
     ref NativeParagraphStyle paragraphStyle,
     [In]
     ref NativeTextStyle textStyle,
     char *text,
     int textLength,
     float maxWidth,
     float maxHeight,
     out IntPtr textLayout,
     [MarshalAs(UnmanagedType.LPWStr)]
     out string error
     );