Smrt.Utils.Clipboard¶
Assembly:
ExtractionFragmentUtilsLib
Namespace: ExtractionFragmentUtilsLib¶
ClipboardFragment¶
Represents a clipboard fragment (text, image, or file metadata).
Propertys¶
Content¶
Fragment payload; plain text for text fragments or base64 PNG content for images.
Extension¶
Detected file extension when available.
Hash¶
SHA-256 hash recorded when the source path is accessible.
LastModifiedUtc¶
Last modified timestamp in UTC for document fragments.
OriginalName¶
Original filename as presented by the clipboard source.
Path¶
Absolute path emitted for file fragments.
SizeBytes¶
File size in bytes for document fragments.
TextLikely¶
Optional hint indicating the fragment likely contains text for downstream processing prioritization.
Type¶
Normalized fragment type (e.g., text or image).
ExtractionFragmentUtils¶
Provides utilities for extracting clipboard fragments (text, image, HTML with , and CF_HDROP files).
Methods¶
ExtractFragmentsFromClipboardAsync(Threading.CancellationToken ct)¶
Extracts clipboard fragments (text, image, CF_HDROP file metadata, HTML with ) from the current clipboard.
Parameters
ct— Cancellation token that halts extraction when clipboard content changes rapidly.
Returns: List of normalized clipboard fragments (text, image, and file descriptors).
FetchImageAsBase64(string src)¶
Fetches an image from a data URL, local file path, or remote URL and returns it as a base64 PNG string. Supports data: URLs, file:// scheme, HTTP/HTTPS URLs, and local file paths.
Parameters
src— Image source URI or path.
Returns: Base64 encoded PNG representation of the source image, or empty string if unavailable.
FetchLocalImageAsBase64(string filePath)¶
Fetches an image from a local file path.
Parameters
filePath— Absolute or relative file path to the image.
Returns: Base64 encoded PNG string.
FetchRemoteImageAsBase64(Uri uri)¶
Fetches an image from a remote HTTP/HTTPS URL.
Parameters
uri— Remote image URI.
Returns: Base64 encoded PNG string.
GetImageHash(Drawing.Image img)¶
Computes a hash of an image for change detection.
Parameters
img— Image to hash.
Returns: Base64 encoded SHA-256 hash of the PNG representation.
ImageLikelyHasText(Drawing.Image img)¶
Applies an edge-detection heuristic to determine whether an image likely contains text. Downscales the input to a fixed size for speed.
Parameters
img— Source image to evaluate.
Returns: when the heuristic indicates text is likely present; otherwise .
ImageToBase64(Drawing.Image img)¶
Converts an Image to a base64 PNG string.
Parameters
img— Image instance to serialize.
Returns: Base64 encoded PNG.
ParseHtmlClipboard(string html)¶
Parses HTML clipboard content and returns ordered fragments (explicit types only).
Parameters
html— Raw HTML markup from the clipboard.
Returns: List of explicit text/image fragments discovered within the markup.
ParseNodeFragments(HtmlAgilityPack.HtmlNode node)¶
Recursively parses a node for explicit fragment types only.
Parameters
node— HTML node to inspect.
Returns: Collection of text/image fragments represented by the node.
OcrHintOptions¶
Configurable settings for the OCR hint feature. Host apps can set these at startup (e.g., from Smrt.Config) via Configure().
Propertys¶
Enabled¶
Enable or disable the OCR hint feature globally.
LanguageTag¶
Optional preferred language (BCP-47), e.g., "en-US".
MaxEdgePx¶
Max image edge (pixels) for the quick hint pass. Images are downscaled to this edge.
Timeout¶
Timeout for the quick hint.
OcrHintSettings¶
Provides access to the current OCR hint configuration and allows host applications to override defaults.
Methods¶
Configure(ExtractionFragmentUtilsLib.OcrHintOptions options)¶
Configure the OCR hint options (call once at app startup).
Parameters
options— Options object providing enabled flag, timeout, max edge, and language tag.
Propertys¶
Current¶
Live view of the OCR hint options used by ExtractionFragmentUtilsLib.WindowsOcrHintService.
WindowsOcrHintDiagnosticsSnapshot¶
Immutable diagnostic projection of ExtractionFragmentUtilsLib.WindowsOcrHintService state, suitable for logging or tests.
Methods¶
WindowsOcrHintDiagnosticsSnapshot(bool? WindowsOcrRuntimeAvailable, int TotalHints, int WindowsOcrHints, int HeuristicHints, int Timeouts, int Cancels, int ConsecutiveFailures, DateTime BackoffUntilUtc)¶
Immutable diagnostic projection of ExtractionFragmentUtilsLib.WindowsOcrHintService state, suitable for logging or tests.
Parameters
WindowsOcrRuntimeAvailable— Cached result of the WinOCR runtime probe.TotalHints— Total quick-hint attempts since process start or last reset.WindowsOcrHints— Number of hints served via Windows OCR.HeuristicHints— Number of heuristic fallbacks served.Timeouts— Number of timeout occurrences during WinOCR attempts.Cancels— Number of hints canceled due to clipboard churn.ConsecutiveFailures— Current streak of WinOCR failures feeding backoff.BackoffUntilUtc— UTC timestamp when WinOCR retries may resume.
Propertys¶
BackoffUntilUtc¶
UTC timestamp when WinOCR retries may resume.
Cancels¶
Number of hints canceled due to clipboard churn.
ConsecutiveFailures¶
Current streak of WinOCR failures feeding backoff.
HeuristicHints¶
Number of heuristic fallbacks served.
Timeouts¶
Number of timeout occurrences during WinOCR attempts.
TotalHints¶
Total quick-hint attempts since process start or last reset.
WindowsOcrHints¶
Number of hints served via Windows OCR.
WindowsOcrRuntimeAvailable¶
Cached result of the WinOCR runtime probe.
WindowsOcrHintService¶
Windows OCR quick-hint service. - Uses runtime (late-bound) Windows OCR if available in the host process. - Falls back to the existing edge-based heuristic when OCR isn't available or times out. - No compile-time dependency on Windows SDK; safe for net8.0-windows without TFM changes.
Methods¶
DownscaleForHint(Drawing.Image img)¶
Returns a downscaled bitmap bounded by ExtractionFragmentUtilsLib.OcrHintOptions.MaxEdgePx to speed up hint processing.
Parameters
img— Original image.
Returns: Bitmap suitable for quick OCR analysis.
GetDiagnosticsSnapshot()¶
Provides a thread-safe snapshot of recent hint metrics for diagnostics, support bundles, and tests.
IsWindowsOcrRuntimeAvailable()¶
Checks once per process whether Windows.Media.Ocr appears available at runtime.
QuickDetectTextAsync(Drawing.Image img, TimeSpan timeout, Threading.CancellationToken ct, string languageTag)¶
Quick "has text?" hint for images. Attempts Windows OCR via runtime activation with a tight timeout; if unavailable or slow, falls back to heuristic.
Parameters
img— Source image to analyze (downscaled internally when required).timeout— Maximum duration to spend on the Windows OCR attempt.ct— Cancellation token that aborts hint work when clipboard content changes.languageTag— Optional BCP-47 language tag to bias Windows OCR (for exampleen-US).
Returns: when the hint indicates text is likely present; otherwise.
ResetDiagnostics()¶
Resets internal counters and probes so deterministic tests and diagnostics can start from a clean slate. Safe to call at runtime; callers typically use it in automated tests or when cycling hint state.
TryWindowsOcrHintAsync(Drawing.Image img, TimeSpan timeout, Threading.CancellationToken ct, string languageTag)¶
Attempt a very fast Windows OCR pass via runtime binding. Returns: - true: text likely present - false: text likely absent - null: couldn't run WinOCR (unavailable or error)
Parameters
img— Source image to evaluate.timeout— Maximum time budget for the WinOCR call.ct— Cancellation token to abort work promptly.languageTag— Optional language tag.
Returns: Nullable boolean indicating hint result, or when WinOCR is unavailable.