Welcome to D-Type
Font Engine And Scalable Graphics Library
D-Type Logo

Zoom OutZoom In
Home
About D-Type
Font Engine
Rasterizer
PowerDoc Engine
PowerDoc For ASP/.NET
D-Type Portable Unicode Text Module
Text Layout
PowerDoc Editor
Download
Evaluate
Contact Us
FAQs



Featured Product
NEW
D-Type Portable Unicode Text Module

Powerful, versatile, compact, super fast, feature rich and remarkably simple to use module to lay out, render and edit high-quality Unicode text on any platform, device or operating system.

Table of Contents

 

Overview

D-Type Portable Unicode Text Module is a portable library for laying out, rendering and editing high-quality Unicode text. It is designed to be powerful, fast, flexible, elegant and above all extremely easy to use. With only 4 key functions, it allows you to easily create, format, lay out and render text in virtually any script and language. And with only 3 auxiliary functions, it allows you to handle cursor positioning, selection highlighting and text editing. It requires minimum effort to be used and can be incorporated in no time into any application.

Animation that serves as a demonstration of D-Type Portable Unicode Text Module features

Availability

Windows Mac OS Linux

D-Type Portable Unicode Text Module is written in industry standard C++ and is portable to virtually any hardware or operating system environment. The module can be purchased in the binary form that is suitable for quick deployment on Windows (as a dynamic link library), Linux and Mac OS X (as a shared library or object code). Although D-Type Portable Unicode Text Module is written entirely in C++, it features a C-style public API (Aplication Programming Interface). This is to ensure that the library's functions can be called from a variety of programming languages and development frameworks in use today.

D-Type Portable Unicode Text Module is a completely self-contained library, which means that it does not require any other third party libraries or fonts to be installed in order to function properly.

Features

General
  • Super fast. Written in industry standard C++.
  • Scalable vector based text output. Text can be zoomed in/out and smoothly displayed at any size or screen resolution.
  • Ultra-high quality rendering with anti-aliasing and sub-pixel precision.
  • Available for any platform. Immediately deployable on Windows, Linux and Mac OS X.
  • Produces identical results on all platforms.
  • Self-contained. Does not require any other third party libraries or fonts.
  • Comes with a basic set of Unicode fonts. Supports all industry standard font formats (TrueType, OpenType, Type 1, CFF, D-Type).
Layout and Formatting
  • Implicit bidirectional analysis and reordering.
  • Support for left-to-right scripts and right-to-left scripts such as Arabic or Hebrew.
  • Automatically handles cursor positioning and movement, selection highlighting and text editing.
  • Automatically displays selection highlights.
  • A rich set of text styling/formatting attributes (bold, italic, underline, outline, strike-out, superscript, subscript, compression, expansion, soft shadows, blur, emboss, glow, transparency, custom defined styles).
  • Standard text layout capabilities (e.g. letter and line spacing, kerning, justification).
  • Advanced typography and shaping engine for complex scripts (e.g. Arabic, Thai, Indic).
  • Advanced text rendering algorithms for enhanced glyph positioning and text legibility.
Advanced
  • Automatic text flow across multiple linked textflow areas.
  • A full 3x3 transformation matrix can be applied to any textflow area independently. This includes 2D perspective transformations and affine transformations such as scaling, skewing, rotation.
  • Support for both horizontal and vertical writing direction with either horizontal or vertical glyph orientation.
  • Horizontal and Vertical text writing progression. Sixteen different types of text progression are supported (e.g. Letf-to-Right & Top-to-Bottom, Top-to-Bottom & Left-to-Right, Top-to-Bottom & Right-to-Left etc.)

Why To Use It?

Text layout and rendering that incorporates advanced styling and formatting, bidirectional text support, font handling, various Unicode algorithms, contextual shaping, cursor handling, selection highlighting and automatic text flow is a very complex task. Most programmers don't have the necessary skills, knowledge, know-how and time to develop and maintain their own text composition engines. D-Type Portable Unicode Text Module is currently the only product of this kind available on the market. No other library can match the performance, quality, flexibility, portability, reliability, technical elegance and simplicity of D-Type Portable Unicode Text Module.

How To Use It?

D-Type Portable Unicode Text Module is designed to depend on D-Type Power Engine, which acts as the rendering engine. This means that before we can access any of its functions, we need to initialize D-Type Power Engine.

To initialize D-Type Power Engine engine, we call the pdEngineIni function. This is usually done only once, at the beginning of the application's initialization routine. Here is how we do this:

if (pdEngineIni(&Engine, NULL, NULL)==0) return;

Assuming that the initialization was successful, our rendering engine will be represented by the Engine pointer variable. We can now proceed to Step 1.

Step 1: Make Text Document

Once we have initialized the rendering engine, we are ready to create a new Unicode text document (or as many of them as we need). Here is one way to do this:

if (txTextIniViaFile(&TextDoc, Engine,
                     TX_AUTO, "C:\\TextFiles\\Sample.txt",
                     TX_IMPORT_UNICODE_BIDI|TX_IMPORT_UNICODE_SCRIPT,
                     NULL, NULL, NULL)<0) return;

Basically, we simply call the txTextIniViaFile function which creates for us a sample text document (represented by the TextDoc pointer variable) by importing plain UTF-8 text stored in the Sample.txt file on our hard disk. We typically pass the TX_IMPORT_UNICODE_BIDI and TX_IMPORT_UNICODE_SCRIPT flags to indicate that we want to apply Unicode's implicit bidirectional reordering algorithm and auto-detect Unicode scripts (such as Latin, Arabic, Thai etc.) so that complex scripts can be shaped properly.

The above is not the only way to create a new text document. We can do this by getting plain text from memory:

if (txTextIniViaMemory(&TextDoc, Engine,
                       TX_UTF8, (DT_UBYTE*)"Saturn is the most distant
                       of the five planets known to ancient stargazers.
                       In 1610, Italian Galileo Galilei was the first
                       astronomer to gaze at Saturn.", 152,
                       TX_IMPORT_UNICODE_BIDI|TX_IMPORT_UNICODE_SCRIPT,
                       NULL, NULL, NULL)<0) return;

or by loading it from a web server (for which we need to specify its URL):

if (txTextIniViaUrl(&TextDoc, Engine,
                    TX_AUTO, "http://www.d-type.com/text/sample.txt",
                    TX_IMPORT_UNICODE_BIDI|TX_IMPORT_UNICODE_SCRIPT,
                    NULL, NULL, NULL)<0) return;

At this point, the engine has already performed the bidirectional analysis and reordering, gathered the necessary fonts, processed complex scripts and completed the necessary layout calculations. So it has everything it needs to generate the output. Actually, we could already jump to Step 4 and render our text.

Note: In the above sample code, we used either TX_UTF8 or TX_AUTO to specify the type of text file. These are not the only options. Presently the following types of text are supported:

TX_AUTO      /* Auto-detect */
TX_ANSI      /* Ansi */
TX_UCS2_LE   /* UCS-2 Big Endian */
TX_UCS2_BE   /* UCS-2 Little Endian */
TX_UTF8      /* UTF-8 */

Step 2 (Optional): Text Styling/Formatting

Once our text document has been created, we may want to style it and/or format it. This is an optional step because not all types of applications need to do this. For example, applications that only display plain text (e.g. terminal programs or database applications) can completely skip this step. However, if we want to render rich text, this step is something we will do often.

So, let's say that we want to underline the fragment "There are 12 pages in this document." from our Sample.txt file. This fragment begins at character position 166 and ends at character position 202. To apply the underline style, we simply call the txTextSetAttribs function and pass the predefined attrUnderline style to this character range:

txTextSetAttribs(TextDoc, 166, 202, attrUnderline, 0);

The result will be as illustrated below:

Result of Step 2: Underlined text

Similarly, if we want to apply synthetic bold to the words "Previous", "Next Page", "C++", "Sample.txt" and "TextFiles/UNICODE_UTF-8/", we apply the predefined attrBold style:

txTextSetAttribs(TextDoc, 211, 219, attrBold, 0); /* "Previous" */
txTextSetAttribs(TextDoc, 224, 233, attrBold, 0); /* "Next Page" */
txTextSetAttribs(TextDoc, 325, 328, attrBold, 0); /* "C++" */
txTextSetAttribs(TextDoc, 463, 473, attrBold, 0); /* "Sample.txt" */
txTextSetAttribs(TextDoc, 490, 514, attrBold, 0); /* "TextFiles/..." */

The result of this is shown below:

Result of Step 2: Emboldened text

But what if we want to apply a completely unique style? For example, let's say that we want to style the tile of our document using our own font, colour and a nice soft drop shadow? No problem, we just create this style ourselves, and then apply it to the title (between character positions 0 and 60) using the same txTextSetAttribs function. Here is one way to do this:

const DT_TX_ATTRIBS myattr_GentiumBigRedWithShadow[] =
{
   {TX_ATTR_FONT_UNIQUEID, "S001N_GENTIR001A" /* Gentium font id */ },
   {TX_ATTR_FONT_WIDTH,    "55" /* size in doc units */ },
   {TX_ATTR_FONT_HEIGHT,   "55" /* size in doc units */ },
   {TX_ATTR_BODY_RGBT,     "A0000000"},
   {TX_ATTR_SHADOW_RGBT,   "CCCCCC00"},
   {TX_ATTR_SHADOW_DX,     "5" /* dx offset in doc units */ },
   {TX_ATTR_SHADOW_DY,     "5" /* dy offset in doc units */ },
   {TX_ATTR_SHADOW_EP,     "0308" /* effect=03, parameter=08 */ },
   {TX_ATTR_END,           "" /* mandatory end-of-array */}
};

txTextSetAttribs(TextDoc, 0, 60, myattr_GentiumBigRedWithShadow, 0);

The result:

Result of Step 2: Custom style applied to title

The choice of the style name is entirely up to us. In the above example, we decided to call it myattr_GentiumBigRedWithShadow but we could have also selected a name that is more appropriate for our application (for example myattr_MainTitle or myattr_HeaderLevel1).

Let's just say that we use the txTextSetAttribs function whenever we need to style or format a run of text. This is true regardless of what style/format we wish to apply or how long the text run is. For example, if we want to justify our entire document (which begins at character position 0 and ends at position 7711), we will proceed in the same way.

txTextSetAttribs(TextDoc, 0, 7711, attrJustified, 0);

Finally, the result:

Result of Step 2: Justified text

Notice how all the paragraphs are now justified. Also, notice that applying one style (or format) over another existing style (or format) does not destroy that previously applied style (or format). The effect is cumulative.

Step 3 (Optional): Automatic Text Flow

This step establishes an automatic text flow across linked textflow areas. This is a truly optional step. Not all applications will need or want to do this. However, applications that want to use more than a single textflow area may find this step useful.

The idea here is that a single text document may span multiple textflow areas. The flow of text from one area to another is then handled automatically by D-Type Portable Unicode Text Module. Additionally, each textflow area can have its own independent position, size and even 2D perspective transformation matrix.

The list of textflow areas is defined by creating an array of DT_TX_TEXTFLOW_AREA structures. Each structure represents one textflow area and contains parameters such as the area's (x,y) location (in document units), width and height (in document units), type (rectangular, circular, diamond-like etc.), row spacing calculation method (e.g. typographical or mathematical), text progression method (e.g. Letf-to-Right & Top-to-Bottom, Top-to-Bottom & Left-to-Right, Top-to-Bottom & Right-to-Left etc.), device mode (e.g. device dependent, device independent, mixed) and, optionally, a transformation matrix (affine or 2D perspective).

For brevity, we will not describe each of the above parameters in details. These details are available in D-Type technical documentation. Instead, here is some sample code to illustrate the technique. We start by creating a few transformation matrices...

/* affine transform matrix A */
DT_FLOAT tm_2x2_a[4] = {1.0, -0.3, 0.0, 1.4};
/* affine transform matrix B */
DT_FLOAT tm_2x2_b[4] = {1.3, 0.1, -0.4, 0.9};
/* 2D perspective transform matrix A */
DT_FLOAT tm_3x3_a[9] = {  0.4, -0.006, -155.0,
                          0.0,  0.555, -120.0,
                          0.0, -0.001,    1.0};
/* 2D perspective transform matrix B */
DT_FLOAT tm_3x3_b[9] = {  2.3,  0.0,  0.0,
                          0.0,  1.9,  0.0,
                        0.002,  0.0,  1.0};

...and then we create an array of DT_TX_TEXTFLOW_AREA structures:


DT_TX_TEXTFLOW_AREA textflow_areas[6]=
{
   { 10, 10, 800,850,  TX_RECT,  TX_TYPOROW,0,0,TX_LAY_DEVICE_B,  TX_TM0,NULL},
   {200, 10, 650,630,  TX_RECT,  TX_TYPOROW,0,0,TX_LAY_DEVICE_B,  TX_TM2,tm_2x2_a},
   { 10, 10, 880,880,  TX_CIRC,  TX_TYPOROW,0,0,TX_LAY_DEVICE_B,  TX_TM0,NULL},
   { 10,280, 600,690,  TX_RECT,  TX_TYPOROW,0,0,TX_LAY_DEVICE_B,  TX_TM2,tm_2x2_b},
   {430,130, 800,630,  TX_RECT,  TX_TYPOROW,0,0,TX_LAY_DEVICE_B,  TX_TM3,tm_3x3_a},
   { 10, 10,1400,480,  TX_RECT,  TX_TYPOROW,0,0,TX_LAY_DEVICE_B,  TX_TM3,tm_3x3_b},
};

Once this is done, we simply call the txTextSetFlow function to pass our array to the D-Type Portable Unicode Text Module:

txTextSetFlow(TextDoc, 6, textflow_areas, 0);

And that's it. The result is 6 linked textflow areas with text flowing from one area to another. The following 6 illustrations demonstrate this:

Textflow Area #0Textflow Area #1
Textflow Area #0Textflow Area #1
  
Textflow Area #2Textflow Area #3
Textflow Area #2Textflow Area #3
  
Textflow Area #4Textflow Area #5
Textflow Area #4Textflow Area #5

Step 4: Rendering (Output)

This is the final step. To draw a textflow area, we simply call the txTextDraw function and specify a few parameters: Area which is the index of the textflow area, Zoom, X and Y offset of the textflow area on the screen and Format and Subformat which identify the type of the memory surface we are rendering to (e.g. grayscale, RGB, RGBA etc.)

DT_MDC dc_mem; /* memory surface to render to */

dc_mem.w=490;  /* surface width in pixels */
dc_mem.h=490,  /* surface height in pixels */
dc_mem.m=NULL; /* txTextDraw will allocate bitmap's memory for us */

txTextDraw(TextDoc, Area, Zoom,X,Y, Format,Subformat,&dc_mem, NULL, 1);

Alternatively, we can render to a raw bitmap file or, even better, a BMP or PNG image. For example:

txTextDrawToFile(TextDoc, Area, Zoom, X, Y, 490,490,TX_BITMAP_PNG_RGB,
                 "output.png", NULL, 0);

This will create an RGB image in the PNG format with dimensions of 490x490 pixels. (View the output.png file.)

We can also save our text document in the D-Type PowerDoc format. This then allows us to open our document in D-Type PowerDoc Editor, which is very useful for troubleshooting and inspection:

txTextSaveToFile(TextDoc, 0, "text_doc.pdc");

Extra: Cursor Positioning, Selection Highlighting

In the above example, when we called txTextDraw, we set the last parameter to 1.

txTextDraw(TextDoc, area,zoom,x,y, format,subformat,&dc_mem, NULL, 1);

This means that in addition to rendering the text, we also want to render the cursor and any highlighted text selections. For example, if a portion of the first paragraph had been selected while performing a text edit operation, the highlighted selection might have appeared as in this illustration:

Highlighted text selection

That's nice, but how do we enable text edit operations? It's quite simple actually. D-Type Portable Unicode Text Module provides a few functions to process mouse actions and text commands. For example, we can call the txTextHit function when the user clicks inside (or outside) a textflow area.

txTextHit(TextDoc, HitType, X, Y, &Extent, Flags);

The X and Y parameters represent the (x,y) location of the mouse on the screen. HitType is the type of mouse action and can be one of the following:

TX_HIT_RELEASE   /* Mouse button released */
TX_HIT_MOVE      /* Mouse move */
TX_HIT_NORMAL    /* Normal mouse button click */
TX_HIT_DOUBLE    /* Double mouse button click */
TX_HIT_SHIFT     /* Mouse button click with Shift Key */
TX_HIT_CTRL      /* Mouse button click with Ctrl Key */

When called, the txTextHit function will interpret the action as required. This may result in a cursor movement, selection highlighting or any other text edit operation that a mouse action can invoke. However, the developer does not need to know what operation, if any, was invoked.

The only thing that the txTextHit function returns is the Extent parameter. This is a rectangle that describes the smallest enclosing box of the screen area that needs to be repainted following a text edit operation. After that, we can call txTextDraw again and repaint the area defined by Extent. It's that simple.

Now, txTextHit is not the only function that can invoke text edit operations. We also have txTextCommand and txTextSetSelect. The first one, txTextCommand, allows us to send various text commands to the D-Type Portable Unicode Text Module and looks as follows:

txTextCommand(TextDoc, Command, &Extent, Flags);

Here the Command parameter identifies the text command we wish to send and presently can be one of the following:

TX_CMD_RESET         /* Deselect all text and remove cursor */
TX_CMD_SELECTALL     /* Select all text */
TX_CMD_LEFT          /* Left Key pressed */
TX_CMD_RIGHT         /* Right Key pressed */
TX_CMD_UP            /* Up Key pressed */
TX_CMD_DOWN          /* Down Key pressed */
TX_CMD_SHIFT_LEFT    /* Shift + Left Key pressed */
TX_CMD_SHIFT_RIGHT   /* Shift + Right Key pressed */
TX_CMD_SHIFT_UP      /* Shift + Up Key pressed */
TX_CMD_SHIFT_DOWN    /* Shift + Down Key pressed */

As before, the Extent parameter is a rectangle that describes the smallest enclosing box of the screen area that needs to be repainted.

The second function, txTextSetSelect, is a little bit more explicit. This function allows us to set a text selection. The function is as follows:

txTextSetSelect(TextDoc,FirstChar[],LastChar[],ArrayLen,&Extent,Flags);

Here FirstChar and LastChar is an array of start and end positions of the selected character range(s) while Extent has the same meaning as before.

Finally, we have two more functions: txTextGetSelect and txTextCopy. The txTextGetSelect function allows us to retrieve an array of start and end positions of the currently selected character range(s) and looks as follows:

txTextGetSelect(TextDoc, FirstChar[],LastChar[],MaxArrayLen);

The txTextCopy function allows us to extract plain text from the currently selected character range(s) and copy it to a user-supplied buffer. The function looks as follows:

txTextCopy(TextDoc, Buffer, MaxBufferLen, BufferFormat);

And finally the txTextPaste function allows us to paste another Unicode text document into the currently selected character range. This function looks as follows:

txTextPaste(TextDoc, TextDoc2, Flags);

Here TextDoc is the destination text document and TextDoc2 is the source text document.

How Much Does It Cost?

The price of the D-Type Portable Unicode Text Module when licensed for a single end-user application in the binary form on Windows, Macintosh or Linux is US$955. To purchase now, click here. For licensing and pricing on other platforms, please contact us.

What About Support and Future Releases?

Every D-Type Portable Unicode Text Module license includes up to three technical support incidents free of charge. These support incidents are valid within the first three months following the purchase date. After that, several low cost support options are available. Contact Us for details. Future releases and updates are available to all users of D-Type Portable Unicode Text Module absolutely free of charge.

More Information

More information on the D-Type Portable Unicode Text Module can be found in the technical documentation that comes with the 30-Day Trial Version.



Copyright © 1996-2007 D-Type Solutions. All scalable images on this web site are rendered by D-Type Font Engine, D-Type Rasterizer and/or D-Type PowerDoc Engine. Reproduction, copying, or redistribution for commercial purposes of any materials, images or design elements of this website is prohibited without the prior written consent of D-Type Solutions. All trademarks are the property of their respective holders and are mentioned for identification purposes only.

Last updated on May 18, 2008