The lack of Uniscribe samples

by Michael S. Kaplan, published on 2005/12/06 11:31 -08:00, original URI: http://blogs.msdn.com/michkap/archive/2005/12/06/500485.aspx


A while ago (way back in March of 2005), Ian Treleaven asked in the suggestion box:

There seem to be very few, possibly only one sample application showing how to use Uniscribe and its set of APIs. The 1060 page book, Developing International Software (MS Press) has only six high-level pages on the topic.

Do you have any experience with this API and any hints on how to use it? Any insight would be great.

Ian is correct, in general there are really only two samples I know of:

Beyond that, samples seem to be pretty scarce.

It used to trouble me a lot more than it does now, but this has more to do with the fact that almost nobody really needs to deal with the complexity of Uniscribe in their daily development work; they just need language support to simply work, the way it does when you use the regular Win32 API to build applications and it hooks into Uniscribe for you rather than forcing you to do the complex work to render the text.

Of course there are exceptions to this rule -- the people who work on the GIFT team to create new shaping engines for scripts to be supported obviously need that understanding, and the work done in Crystal Reports and in the Visual Studio environment is very impressive and without that work the script support in these applications would be much poorer for it.

Just this last month, Lloyd Dupont asked in the newsgroups:

I have written m own "RichTextView" using Uniscribe. Now I see there is a new text rendering class: SWF.TextRenderer.

I haven't tested it out yet but it seems interesting.

However I see a couple of issues with it:

  1. It doesn't gives me bidi "run" layout information so I have to call uniscribe to get that
  2. It only gives me string width, if I want to wrap my text around some boundary I have either to call MeasureText repitively or I have to use Uniscribe again
  3. It doesn't gives me cluster boundary for caret placement
  4. If I render unsuported char/glyph I don't know which kind of font fall back mechanism it uses so I'm not sure my measurement (which I should do with Uniscribe for reason 1,2,3) will fit the new drawing.

Is there any plan to improve these issues?

Clearly there is no specific reason to add full Uniscribe support in the TextRenderer class since its intent is not to provide such support, and if someone already has a Uniscribe wrapper then they should definitely use it.

I am sure some of the people who read this blog may also be exceptions to this rule, but I will push back to the extent of wanting more scenario-based questions rather than open-ended requests for samples. Since most people don't need to directly do complex script processing, it only makes sense to be sure that this is a road that needs to be travelled....

 

This post brought to you by "≈" (U+2248, a.k.a. ALMOST EQUAL TO)


# Mike on Tuesday, December 06, 2005 2:33 PM:

How about a deep dive session on Uniscribe at the GDDC 2006? (i.e not just Powerpoint slides but real technical walkthoughs)

# Michael S. Kaplan on Tuesday, December 06, 2005 3:29 PM:

Ah, but that takes the conversation the same way -- technical walkthroughs that do what, exactly? If there are no sensible scenarios to base things on, then there is nothing to present on that will hold interest....

# Lonnie McCullough on Tuesday, December 06, 2005 5:20 PM:

I actually used the first sample you mentioned to implement full Uniscribe support in one of our applications. Our situation is a little different because our company implements full screen UIs on top of Direct3D and it doesn't have any good layout support in its font classes so we rolled our own. The first sample contains everything you need to implement Uniscribe in your apps and to do so robustly. I imlpemented the solution in C# so it was doubly difficult, but ultimately worth it.

# Mike on Tuesday, December 06, 2005 11:15 PM:

Technical walkthroughs that do what - well, I'll leave that up to someone who actually knows how to use Uniscribe.

I think that's the main problem - we hear often in the newsgroups - don't use GetCharacterPlacement, use Uniscribe. Or don't do xxxxx, use Uniscribe. Every question that you can answer with "use Uniscribe instead" would make a good technical walkthrough.

# Simon Cooke on Thursday, December 08, 2005 2:20 PM:

What I'd like to see is a simple example of an editor, where you can type a few rows of text and mark some of that text as bold.

The biggest issues I've seen so far with Uniscribe is:
1. How do you safely break text into runs of different styles, and wrap that text across lines?

2. Do you have to reflow everything at the paragraph level? Or can you do it at the run level after it has been broken?

3. How do you safely break lines when you need to wrap them?

# Michael S. Kaplan on Thursday, December 08, 2005 3:16 PM:

Of course a sample like that can be huge (look at how big the Wordpad sample on MSDN is -- it is nearly impossible to suss out individual function usage techniques from such samples!).

# Simon Cooke on Friday, December 09, 2005 2:09 PM:

True, but the thing is, without such a sample, Uniscribe is useless to developers unless they're writing single-line, single-format, single-font text. For which you may as well use a static text control, as it does it all for you.

I'm trying to write script-editing software that handles all languages, not just latin ones. If I wasn't hell-bent on doing it the right way, I could just force ASCII on everyone and say screw it.

Heck, I'd settle for simple examples of things like:

What do you do when you have to break a line because someone typed over a line's worth of random characters?

You know, edge cases like that.

Or even just simple answers to the second two questions.

# Michael S. Kaplan on Monday, December 12, 2005 10:26 AM:

Hmmm..... well, the existing sample covers a great deal of that sort of thing, right?

# Stephanie Legault on Monday, December 19, 2005 6:06 PM:

I think more Uniscribe samples are an excellent idea. For one, I didn't even *know* about Uniscribe until one of my co-workers told me about it. And even then, at first we didn't realize that it could provide the functionality that we needed.

I have to write a UI for doing spell checking in multiple types of editors in our product. We support multiple spell check languages (through Proximity). This requires complex, multi-lingual word break functionality (to parse words, to spell check them.) Because I played around with the CRichEditCtrl to start, I've found that the FindWordBreak() functionality does not provide the control and information I need.

To whit, I need an API to provide detailed information on individual characters (are they word breaks, line breaks, etc.) The Uniscribe library seems to provide this through ScriptBreak(). I'm still in the process of trying out the APIs because these APIs are complicated to call. Thus the need for examples. You have to pass in outputs of other functions, sometimes multiple structures, etc. Fairly complex. An example would have saved me what will probably take several hours to produce, and I'll probably end up with 10 lines of code, at most.

I don't need a full text editor as an example. I just wish that each function had an associated example of how to call the function and maybe how to use its output.

My two cents.

# John Daggett on Thursday, October 18, 2007 9:31 PM:

Buried in the bowels of Mozilla code is code that handles complex script rendering code using Uniscribe:

http://lxr.mozilla.org/seamonkey/source/gfx/thebes/src/gfxWindowsFonts.cpp#1566

There's also additional code that scans the list of fonts in the system and reads the cmap tables of each font:

http://lxr.mozilla.org/seamonkey/source/gfx/thebes/src/gfxWindowsPlatform.cpp

Should be fairly useful to someone looking at how Uniscribe is used in practice.

The "CVS Blame" link at the top of the page provides a way to see the checkin history per-line.  Hovering over the checkin number will show the bug number related to the change.  Looking through these bugs can also provide a lot of insight into specific problems encountered, especially obscure problems with complex scripts.


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2008/08/28 A technology is worth: $0; A sample showing how to use it: $0; A debug-able sample: Priceless!

2007/07/05 Those Uniscribe samples from 'the hardest working ISV in complex scripts'

2007/03/30 Determining if a font is gonna get it done

2006/03/11 Was someone still looking for Uniscribe samples?

2006/02/15 Mixing MLang and Uniscribe

go to newer or older post, or back to index or month or day