WPF GlyphRuns and context-dependent characters - wpf

I am trying to render Arabic text in WPF at Glyph level, on a character-by-character basis. Rendering Latin text was easy, each character simply translates to a Unicode codepoint and I used GlyphTypeface's CharacterToGlyphMap dictionary to retrieve a GlyphRun for each character.
With Arabic (and other languages) it seems that things are a lot more complicated: characters use different glyphs depending on the characters that surround them and on their position in a word. I suppose these contextual character forms all have their own Unicode codepoints too.
My questions are:
- How would I get these context-dependendent codepoints? A TextBlock displays Arabic text correctly (I suppose), how does it know which glyphs to use?
- Would that character-after-character approach even work for Arabic or is there more that I should know?

Related

How to display non printable characters (ASCII codes 0 - 32) in WPF

I want to display and edit serial data (e.g. NULL, STX, ETX, ENQ, etc. characters) in the text box in WPF. It should be displayed same like Notepad++ as shown here.
I have tried using textbox, RichTextBox in WPF, but only printable characters are shown. Non printable characters (e.g. NULL, STX, ETX, ENQ, etc. characters) are not shown.
Will you please guide me how can I display this?

Best framework for new application which handle text(fonts,characters)

I need to create application, using which user can handle text in graphical interface.
User can move text objects inside parent panel/canvas or something, change fonts, change size of characters (height, width), spacing between characters and so on.
Target of application:
in the end of handling text (or while handling) user will get a position of every character, height and width of characters, distance between characters (spacing). And all those measures must be in same unit of measure (pixels, points).
So question is: What kind of framework (.NET, Silverlight, XNA, Flash, Java, HTML 5, Javascript and so on) can be used for this.
I am “sold my soul” to Microsoft (worked before only with .NET), but have some experience in Flash, HTML, Javascript, Java. So all proposals are welcome
Trying to approach with Silverlight, but only problem was with spacing (dynamically change), when trying used Glyphs it worked in some way,
only problem was: when with Glyphs spacing was changed(same for all characters), in visual spacing was different for all characters. So spacing problem is biggest for right now.
Another approach can be a handle text as a collection of characters, and calculate by myself distance between characters. But in application every user can use own custom fonts (here my knowledge not enough). So i afraid that we will need to create (draw) every character of font before can use custom fonts.
I found in Internet some applications which doing almost same thing (done in Javascript), but before start want to get more information about other possibilities.
With nobody give some advices about this,I decide to answer own question, because found already a solution how will approach to this project.
So I found a new(for me at least) version of Silverlight hav a new Property CharachterSpacing for Elements which handling with text(TextBox, Label and so on). Using this property I can change dynamically a text spacing.
Documents tell us that this property use as a unit integer which is 1000s of font's em unit. About em:
"Em size is a typographical measure that specifies the approximate width of the capital letter "M" in the Roman alphabet, measured in the units that are prevalent in a particular technology. Silverlight em sizes are given in pixels. The apparent visual size of the em size varies per font.”
So this give a very good basement for counting a real distance between charachters.

Access opentype glyph names from WPF

Is there a way to access opentype glyph names in Windows Presentation Foundation? I want to display a glyph on a canvas, but the glyph is a special glyph in a special font, so there is no standard codepoint (of course there IS a codepoint, but I don't want to remember it for dozens of special glyphs).
The font has names for each glyphs which I want to use (such as "custom.specialsign"). Is it possible to get the character by glyph name?

Convert restricted RTF subset to plaintext with HTML formatting tags

I'm looking to take the output of a WPF RichTextBox which is locked down to only allow certain formatting commands (Bold, Underlined and Italic), and parse it to be plaintext with HTML tags denoting the formatting. This is so that the formatting information can be picked up and parsed by an Oracle Publishing interface.
All other information such as font sizes, colors etc are not important, as they will be handled the Publishing template further down the line.
Ideally then we would have something like the following, stripping out all other rtf tags:
This is <b>some bold text, with <i>this bit</i> italic as well</b>
Is there a relatively easy way to do this? I've seen some Regex strings, but they always seem to let unwanted rtf material through. I don't want to use a commercial solution really, as its quite a small problem.
Any ideas?
You should parse RTF and replace necessary control codes with HTML tags. Considering complexity of RTF, I don't think Regex will be enough.
Rich Text Format (RTF) Specification, version 1.6. Syntax is relatively easy, you just need to process control codes like \b for bold etc., I think.
NRTFTree - A class library for RTF processing in C#. Its SAX parser is probably what you need.

Font graphics routines

How do you do your own fonts? I don't want a heavyweight algorithm (freetype, truetype, adobe, etc) and would be fine with pre-rendered bitmap fonts.
I do want anti-aliasing, and would like proportional fonts if possible.
I've heard I can use Gimp to do the rendering (with some post processing?)
I'm developing for an embedded device with an LCD. It's got a 32 bit processor, but I don't want to run Linux (overkill - too much code/data space for too little functionality that I would use)
C. C++ if necessary, but C is preferred. Algorithms and ideas/concepts are fine in any language...
-Adam
In my old demo-scene days I often drew all characters in the font in one big bitmap image. In the code, I stored the (X,Y) coordinates of each character in the font, as well as the width of each character. The height was usually constant throughout the font. If space isn't an issue, you can put all characters in a grid, that is - have a constant distance between the top-left corner of each character.
Rendering the text then becomes a matter of copying one letter at a time to the destination position. At that time, I usually reserved one color as being the "transparent" color, but you could definitely use an alpha-channel for this today.
A simpler approach, that can be used for small b/w fonts, is to define the characters directly in code:
LetterA db 01111100b
db 11000110b
db 11000110b
db 11111110b
db 11000110b
db 11000110b
The XPM file format is actually a file format with C syntax that can be used as a hybrid solution for storing the characters.
Pre-rendered bitmap fonts are probably the way to go. Render your font using whatever, arrange the characters in a grid, and save the image in a simple uncompressed format like PPM, BMP or TGA. If you want antialiasing, make sure to use a format that supports transparency (BMP and TGA do; PPM does not).
In order to support proportional widths, you'll need to extract the widths of each character from the grid. There's no simple way to do this, it depends on how you generate the grid. You could probably write some short little program to analyze each character and find the minimal bounding box. Once you have the width data, you put it in an auxiliary file which contains the coordinates and sizes of each character.
Finally, to render a string, you look up each character and bitblit its rectangle from the font bitmap onto your frame buffer, advancing the raster position by the width of the character.
We have successfully used the SRGP package for fonts. We did use fixed-pitch fonts, so I'm not sure if it can proportional fonts.
We're using bitmap fonts generated by anglecode#s bitmap font generator :
http://www.angelcode.com/products/bmfont/
This is very usable as it has XML output which will be easy to convert to any data format you need.
Angel Code's bmfont also adds kerning and better packing to the old alternative that was MudFont.

Resources