Skip to content

Add imgproc TrueType text rendering: FontFace + FontFace-based PutText/GetTextSize - #1929

Merged
shimat merged 1 commit into
5.xfrom
feature/imgproc-fontface
Jun 24, 2026
Merged

shimat merged 1 commit into
5.xfrom
feature/imgproc-fontface

Conversation

@shimat

@shimat shimat commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

Wraps the OpenCV 5 built-in STB TrueType text renderer (which replaces the contrib freetype module) — from #1924.

New API

  • FontFace class: default font, embedded fonts ("sans", "italic", "uni"), or a custom font path. Exposes Set, Name, and SetInstance / GetInstance for variable-font axes (e.g. wght, slnt).
  • Cv2.PutText / Cv2.GetTextSize overloads taking a FontFace (font size, weight, PutTextFlags, optional wrap Range). PutText returns the continuation point; GetTextSize returns the bounding Rect.
  • PutTextFlags enum (align / origin / wrap).

Text is marshaled as UTF-8, so full Unicode renders correctly (unlike the legacy Hershey PutText, which is ANSI).

Native bridge

  • New imgproc_FontFace.h (included from imgproc.cpp).
  • Font path/name strings use the Windows/NotWindows marshaling split; text content uses UTF-8.

Test

FontFaceTest:

  • FontFace creation: default + embedded (sans, uni).
  • GetTextSize returns a positive-sized rect.
  • PutText draws pixels and advances the cursor (ASCII).
  • PutText with a Unicode string (Greek + Cyrillic) using the uni font draws pixels.
  • SetInstance / GetInstance round-trip wiring.

Rebuilt OpenCvSharpExtern locally; full ImgProc suite green (142 passed).

Refs #1924.

🤖 Generated with Claude Code

…t/GetTextSize

Wraps the OpenCV 5 built-in STB TrueType renderer (replacing the contrib
freetype module):
- FontFace class: default / embedded ("sans", "italic", "uni") / custom-path
  fonts, plus Set, Name, SetInstance / GetInstance (variable-font axes).
- Cv2.PutText and Cv2.GetTextSize overloads taking a FontFace (size, weight,
  PutTextFlags, optional wrap Range). Text is marshaled as UTF-8 so full
  Unicode renders correctly.
- PutTextFlags enum (align / origin / wrap).

Native entry points in a new imgproc_FontFace.h; font path/name strings use
the Windows/NotWindows marshaling split while text content uses UTF-8.

Tests: FontFace creation (default + embedded), GetTextSize, ASCII + Unicode
PutText pixel checks, and SetInstance/GetInstance. Full ImgProc suite green
(142 passed).

Refs #1924.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shimat shimat self-assigned this Jun 24, 2026
@shimat
shimat merged commit 59e3e8d into 5.x Jun 24, 2026
11 checks passed
@shimat
shimat deleted the feature/imgproc-fontface branch June 24, 2026 15:06
@shimat shimat added the enhancement New feature or improvement to OpenCvSharp label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to OpenCvSharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant