Skip to content

Repository files navigation

TextCore.Native — UI-agnostic Cross-Platform Core Text APIs

TextCore.Native offers a small, stable set of CoreText/IME primitives editor hosts can use to implement platform text input and IME support without depending on Uno Platform, WPF, or any other UI framework. It exposes a managed CoreText* API surface and uses different approaches for platform integration:

  • On Windows, it uses the Win32 IME APIs (user32/imm32) via P/Invoke.
  • On macOS, it includes a tiny native macOS helper (libTextCoreNativeMacInput.dylib) used to surface AppKit text input callbacks to managed code.
  • On Linux, it uses libX11 via P/Invoke for X11 calls and communicates with IBus over D-Bus using a built-in managed DBus-over-socket implementation (no libibus/libdbus P/Invoke).

Quick start

  • Install the NuGet package:
dotnet add package LeXtudio.UI.Text.Core
  • Or add a PackageReference to your project file:
<PackageReference Include="LeXtudio.UI.Text.Core" Version="1.*" />

For advanced workflows (consuming from source, building the native macOS helper, or producing packages) see CONTRIBUTING.md.

API overview

  • CoreTextServicesManager.GetForCurrentView() — factory; call CreateEditContext() to get a CoreTextEditContext.
  • CoreTextEditContext — central event hub. Important events:
    • TextRequested
    • TextUpdating
    • SelectionRequested
    • SelectionUpdating
    • LayoutRequested
    • CompositionStarted / CompositionCompleted / FocusRemoved
    • CommandReceived — receives platform command selectors (e.g. AppKit doCommandBySelector: strings).

Lifecycle methods:

  • bool AttachToWindowHandle(nint windowHandle, nint displayHandle = 0) — attach to a native window. On macOS pass an NSWindow*; on Windows pass an HWND; on Linux/X11 pass the X11 Window id and the X11 Display pointer.
  • void NotifyCaretRectChanged(double x, double y, double width, double height).
  • void NotifyFocusEnter() / void NotifyFocusLeave().
  • void Dispose().

Minimal usage example

var manager = CoreTextServicesManager.GetForCurrentView();
var ctx = manager.CreateEditContext();

ctx.TextRequested += (s, e) => e.Request.Text = GetDocumentText();
ctx.TextUpdating += (s, e) => ApplyEdit(e.NewText);
ctx.CommandReceived += (s, e) => {
  if (e.Command == "deleteBackward:") { Backspace(); e.Handled = true; }
};

ctx.AttachToWindowHandle(hwnd);
ctx.NotifyCaretRectChanged(x, y, w, h);
// ...
ctx.Dispose();

License

This project is licensed under the MIT License. See the LICENSE file for details.

Copyright

(c) 2026 LeXtudio Inc. All rights reserved.

About

Core Text APIs for Uno Platform

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages