How To: Determine which character ranges are supported by a font - c#

When working with different fonts, some might support, say, arabic characters where another might not.
Is there a way in C# to figure out what character ranges are supported by a specific font?

You would need to P/Invoke GetFontUnicodeRanges(). Not easy to do because the font needs to be selected in the device context, that requires more p/invoke.
But most of all, it isn't the right thing to do. You should rely on Windows' automatic font linking, it finds another font if necessary to supply the glyph. The feature is described in this article.

Related

Live screen capture of text to OCR implementation ideas? (Image to machine readable, Live)

I am trying to create a software in (preferably) .Net where I can set a fixed area on my screen where text appears and then convert that data into machine readable code using some sort of OCR. I would like to do this on a live basis, meaning when the text changes, I would like my program to be instantly notified of the change and also what it has changed to.
The good thing is that the text is of standard font, color and fixed area.
How should I best implement this? Any third party software recommended for both the snapshotting and OCR?
for OCR try tesseract. .net wrappers are also available.

Is MS UIAutomation useless against text? How to set font weight, get caret pos, insert text, etc?

I am researching the Microsoft UIAutomation for controlling text, but am finding it useless. I need to do things like:
Get caret position
This article implies to me that I need to track the caret, which will not work if I do not know it's original position....
Insert text in a specific location
Only found the ability to overwrite the entire field using ValuePattern's SetValue
Set font weight
I can read the font weight, but cannot set it
etc
I have read a number of articles by this point, and none point to the possibility of these. This SO question was helpful to get me started, however when I tried to dig deeper I kept running into more questions than answers. Is my only option to go to MS Accessibility Automation, which does not play well with WPF virtualization among other things.
If anybody can point me to a useful article or provide examples for the above shortcomings, that would be great. However, I am not hopeful at this point as it all seems to lead to ways to get information, but not update information.
EDIT
I have even tried to dig into the UIAutomationClient.dll and it seems that there is, indeed no support for this. It seems UIA is primarily for pulling cursory information and clicking around. No real text support
Here is another SO question...relatively similar to this one...it seems to verify that UIA is useless for my needs..
Hacky Workaround
The workaround we have is to get the general context using UIA and then using AutoIt SendKeys
The article you're pointing to describes how applications that want to support TextPattern for UI Automation need to work, not how clients that want to retrieve information using TextPattern need to work. In particular, implementers need to track the caret; clients do not.
That being said, TextPattern is designed to retrieve info, not to set it; having worked extensively with Text Services Framework, which is designed to insert text, I can understand why. (Many applications aren't designed to allow arbitrary unsolicited manipulations of their data structures; allowing applications to dictate when they can be manipulated severely contorts the design of the text service.)
The first two items are pretty straightforward. You can get the selected text using IUIAutomationTextPattern::GetSelection; this returns a collection of text ranges that you can extract the location of, etc.
While you can't directly manipulate the contents of a text range, you can select it and then generate input using SendKeys, et al.

Portable way of determining font properties (mono and standard .net)

Does anyone know a way to determine if a font is monospace and the width and height of a single character (only relevant if it is monospace).
The important requirement is that it works with mono and microsoft implementations of .net .
Thanks
First thing you need to choose which GUI Toolkit you are targeting.
Fonts aren't abstracted in a toolkit-independent way, AFAIK.
For WinForms, TextRenderer.MeasureText method used with "iii" and "www" strings can help you guess if the font is monospaced and which is the probable 'fixed' width of a char cell, bu it may not work right for very small point sizes...

FNT font file in C#

I would like to know if I can use FNT font file in c# .net.
FNTs are not windows font file.
If such fonts are available, can you please tell me how to load it and change windows form font to FNT?
I use .Net GDI+ technology, but please let me know if WPF is better for this.
Thanks,
Those are device fonts, a relic from the Windows 3.0 days before TrueType became available. They contain bitmaps of (typically) 256 glyphs in a certain character set at fixed pre-selected point sizes. They are not scalable beyond those fixed sizes.
Nope, neither GDI+ nor WPF supports them. You'd have to fall back to raw GDI to still use them. The file format isn't complicated, it would be technically possible to lift the bitmaps out of the file. I'm not aware of existing code, although I'm sure somebody did. Some kind of legacy font editor for example.
.NET uses either GDI+ (in WinForms) or WPF for its text handling and rendering.
So depending on what .NET technology you are using will determine what is supported.

Squares-for-linebreaks missing in List view control. Why? .NET

This is not particularly a programming question, but I was hoping someone here may know the answer.
We have in-house written application in C#. It's uses ListView control (i believe) to display a list of items - items/text that contains line breaks (newline chars). On most PCs (WinXP) the line breaks are displayed as two square characters. But on one particular PC the boxes are not displayed at all, and two lines are concatenated together without any visual separation..
Does anyone knows why would that be?
Is that controlled by some setting in OS?
Thanks in advance.
I would check default font on that machine. If you need to see how to check or change default font, read Fonts - Change Default article.
Update:
You can also try to restore default font. I just found this this article that explains how to restore default Windows XP Fonts.

Categories