Index

Examples

Example 1: Layout Without Caching Subsystem

The following code fragment illustrates how to lay out and display a line of Unicode text without using D-Type Layout Extension's built-in caching subsystem.

DT_LXLAYOUT layout; /* layout instance */ 
DT_DTENGINE engine; /* standard engine instance */ 
DT_ID_SWORD font_index; /* font index */ 

/* set script_code to Devanagari script */ 
DT_ID_SLONG script_code = devaScriptCode;
/* Devanagari is a left-to-right script */ 
DT_ID_UBYTE direction = 0;
/* sample Devanagari text */ 
DT_ID_UWORD chars[] = {0x0939, 0x093F, 0x0928, 0x094D, 0x0926, 0x0940};
DT_SLONG nr_of_chars = 6;

/* output array for positioned glyphs */ 
/* (here the array is static; in a real application it would be dynamically allocated) */ 
LX_GLYPH glyph_arr[20];
/* size of the array */ 
DT_SLONG max_glyphs = 20;

/* the actual number of positioned glyphs to lay out text */ 
DT_SLONG n;

/* factors to scale font units to pixels (see D-Type FAQ: Q-2-5) */ 
DT_FLOAT fx, fy;


/*
   before we can use D-Type Text Layout extension, we must:
   - initialize D-Type Font Engine and get engine
   - open font(s) and obtain font_index
   - set Output (surface, style) and Typesetter (type)
*/ 
/* ... */ 


/* create layout instance */ 
if (lxLayoutIni(&layout, engine, font_index, script_code) == 1)
{
  /* apply layout instance */ 
  n = lxLayoutApply(layout, chars, nr_of_chars, direction, glyph_arr, max_glyphs);

  /* calculate fx and fy (see D-Type FAQ: Q-2-5) */ 
  /* ... */ 

  /* now display glyphs */ 
  for (DT_SLONG i = 0; i < n; i++)
  {
    dtGlyphDoOutput(engine, glyph_arr[i].glyph_index, fx * glyph_arr[i].x, fy * glyph_arr[i].y, 0, DV_NULL);
  }

  /* destroy layout instance */ 
  lxLayoutExt(layout);
}


/* deinitialize D-Type Font Engine */ 
/* ... */ 

Note: In this simplified example, the return value of the lxLayoutApply function is not checked and no attempt is made to deal with the situation when the output array for positioned glyphs is not large enough to accept all the glyphs.

Example 2: Layout With Caching Subsystem

The following code fragment illustrates how to lay out and display a line of Unicode text using D-Type Layout Extension's built-in caching subsystem.

DT_LXLAYOUT layout; /* layout instance */ 
DT_LXCACHE layout_cache; /* layout cache */ 
DT_DTENGINE engine; /* standard engine instance */ 
DT_ID_SWORD font_index; /* font index */ 

/* set script_code to Devanagari script */ 
DT_ID_SLONG script_code = devaScriptCode;
/* Devanagari is a left-to-right script */ 
DT_ID_UBYTE direction = 0;
/* sample Devanagari text */ 
DT_ID_UWORD chars[] = {0x0939, 0x093F, 0x0928, 0x094D, 0x0926, 0x0940};
DT_SLONG nr_of_chars = 6;

/* output array for positioned glyphs */ 
/* (here the array is static; in a real application it would be dynamically allocated) */ 
LX_GLYPH glyph_arr[20];
/* size of the array */ 
DT_SLONG max_glyphs = 20;

/* the actual number of positioned glyphs to lay out text */ 
DT_SLONG n;

/* factors to scale font units to pixels (see D-Type Units and D-Type FAQ: Q-2-5) */ 
DT_FLOAT fx, fy;


/*
   before we can use D-Type Text Layout extension, we must:
   - initialize D-Type Font Engine and get engine
   - open font(s) and obtain font_index
   - set Output (surface, style) and Typesetter (type)
*/ 
/* ... */ 


/* create the layout cache */ 
if (lxCacheIni(&layout_cache, engine, 0) != 1)
{
  /* deal with the error */ 
  /* ... */ 
}


/* obtain layout instance from the layout cache */ 
if (lxCacheObtainLayout(layout_cache, font_index, script_code, &layout) == 1)
{
  /* apply layout instance */ 
  n = lxLayoutApply(layout, chars, nr_of_chars, direction, glyph_arr, max_glyphs);

  /* calculate fx and fy (see D-Type Units and D-Type FAQ: Q-2-5) */ 
  /* ... */ 

  /* now display glyphs */ 
  for (DT_SLONG i = 0; i < n; i++)
  {
    dtGlyphDoOutput(engine, glyph_arr[i].glyph_index, fx * glyph_arr[i].x, fy * glyph_arr[i].y, 0, DV_NULL);
  }
}


/* destroy the layout cache */ 
lxCacheExt(layout_cache);


/* deinitialize D-Type Font Engine */ 
/* ... */ 

Note: In this simplified example, the return value of the lxLayoutApply function is not checked and no attempt is made to deal with the situation when the output array for positioned glyphs is not large enough to accept all the glyphs.

 

Index