Link to home
Create AccountLog in
Microsoft Word

Microsoft Word

--

Questions

--

Followers

Top Experts

Avatar of chopin34
chopin34

Draw letters with colored accent diacritics via WPF, WinForms or any other technology
The Hebrew and Arabic versions of Microsoft Word allow the user to select a color for the language's diacritics. The letters may still be in black color, while diacritics appear, for instance, in red. Visually, these diacritics doesn't occupy horizontal space. They appear above or below a letter.

I would like to be able to do the same thing inside a text control which handles formatted text – like WPF RichTextBox or WinForms' RichTextBox, or others.

I have tried to do it with WinForms' RichTextBox. One can select a portion of text using the rich box Select method. Then, the color of the selected text can be changed with SelectionColor property. However, when selecting only a diacritic, its color cannot be changed. I.e, assigning a value to SelectionColor will do nothing. On the other hand, we can select only the letter which stands below the diacritic. But then, assigning a value to SelectionColor will changes both the color of the letter and the color of its diacritic to the assigned value. Therefore, it is not possible to get a letter with one color and its diacritic with other.

I've also tried with WPF RichTextBox. The following XAML code works fine:

<RichTextBox>
    <FlowDocument>
        <Paragraph FontFamily="Lucida Sans Unicode">

            <!—-Draw the letter "a" with a red macron above it-->

            <Run>a</Run><Run Foreground="red">&#x306;</Run>
        </Paragraph>
    </FlowDocument>
</RichTextBox>

However, this code works with some fonts (Lucida Unicode, Tahoma and more) and doesn't work with others (DejaVu, Doulos Sil and more). With these other fonts, a diacritic always appears with the same color of the letter to which it is attached.

As far as I know, a color of a glyph is not a feature of a font. So changing a diacritic's color should be independent of a font qualities. It should be a feature of the software which renders the font.

One question is weather .Net technologies like WinForms and WPF have a specific, in advance intent capability, for the discussed purpose. If not, maybe there is a stable, consistent workaround to achieve this within .Net. If only direct usage of GDI+ can achieve this, it may be possible to use win-api calls from .Net for that purpose.

Again, since Microsoft Word have this ability, it is possible for sure. I prefer achieving this via .Net technology - either WinForms or WPF.  XAML / VB code will be great. C# is welcome as well.

Thanks in advance

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of lwebberlwebber

Hmmm. Just as an experiment, if you create the desired text in Word, can you copy and paste it into the RichTextBox at run-time? I presume that copying and pasting from one Word doc to another preserves the dual colors. Does the same thing happen when you paste into your desired control?

Avatar of chopin34chopin34

ASKER

lwebber: good idea. I have done it, and it did not preserve the dual color. The pasted text was in black only. That was the case with both WPF RichTextBox and WinFomrs' RichTextBox. Also, pasting the text to OpenOffice results the same (no dual color).

That experiment (thanks to your comment) + some googling gave me new prespective on my issue. I have just noticed that in MS Word, you can't apply one diacritics' color to some portion of text, and another color to the diacritics of other portion. The diacritics color is a global setting which apply not only to a whole document, but to all open documents  at once. And therefore, when you save a document with some diacritics, the info regarding theirs color is not encoded in the document, not even as a kind of meta data. You may open Word options menu and select to use other color for diacritics, then the diacritics of any document you open will be rendered with the color you have selected.

When posting my question I didn't know that. Still, it my be possible to achieve this through markup with WPF or with the WinForms' RichTextBox. So the question I have posted is still relevant for me as it is. I'm also posting a new question resulted form the new info.

ASKER CERTIFIED SOLUTION
Avatar of lwebberlwebber

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Ingeborg Hawighorst (Microsoft MVP / EE MVE)Ingeborg Hawighorst (Microsoft MVP / EE MVE)🇳🇿

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft Word

Microsoft Word

--

Questions

--

Followers

Top Experts

Microsoft Word is a commercial document editing program that is part of the Microsoft Office suite. It features numerous text-editing tools for creating richly formatted documents, along with tools for the use of macros in Word documents. Word's native file formats are denoted either by a .doc or .docx file extension. Plugins permitting the Windows versions of Word to read and write formats it does not natively support, such as the OpenDocument format (ODF) are available. Word can import and display images in common bitmap formats such as JPG and GIF. It can also be used to create and display simple line-art.