Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed











































Rev Author Line No. Line
4349 Serge 1
2
"http://www.w3.org/TR/html4/loose.dtd">
3
4
5
6
FreeType-2.5.0 API Reference
7
32
33
34
 
35
[Index]
36
37
[TOC]
38

FreeType-2.5.0 API Reference

39
 
40

41
Glyph Management
42
43

Synopsis

44
45
FT_GlyphFT_OutlineGlyphRecft_glyph_bbox_xxx
46
FT_GlyphRecFT_Get_GlyphFT_Glyph_Get_CBox
47
FT_BitmapGlyphFT_Glyph_CopyFT_Glyph_To_Bitmap
48
FT_BitmapGlyphRecFT_Glyph_TransformFT_Done_Glyph
49
FT_OutlineGlyphFT_Glyph_BBox_Mode
50


51
 
52
53

This section contains definitions used to manage glyph data through generic FT_Glyph objects. Each of them can contain a bitmap, a vector outline, or even images in other formats.

54

55
56

FT_Glyph

57
58
Defined in FT_GLYPH_H (freetype/ftglyph.h).
59

60
61
 
62
  typedef struct FT_GlyphRec_*  FT_Glyph;
63
 
64

65
66

Handle to an object used to model generic glyph images. It is a pointer to the FT_GlyphRec structure and can contain a glyph bitmap or pointer.

67

68
note
69

Glyph objects are not owned by the library. You must thus release them manually (through FT_Done_Glyph) before calling FT_Done_FreeType.

70
71
72

73
[Index]
74
75
[TOC]
76
 
77
78

FT_GlyphRec

79
80
Defined in FT_GLYPH_H (freetype/ftglyph.h).
81

82
83
 
84
  typedef struct  FT_GlyphRec_
85
  {
86
    FT_Library             library;
87
    const FT_Glyph_Class*  clazz;
88
    FT_Glyph_Format        format;
89
    FT_Vector              advance;
90
 
91
  } FT_GlyphRec;
92
 
93

94
95

The root glyph structure contains a given glyph image plus its advance width in 16.16 fixed-point format.

96

97
fields
98

99
100
library
101

A handle to the FreeType library object.

102
103
clazz
104

A pointer to the glyph's class. Private.

105
106
format
107

The format of the glyph's image.

108
109
advance
110

A 16.16 vector that gives the glyph's advance width.

111
112
113
114
115

116
[Index]
117
118
[TOC]
119
 
120
121

FT_BitmapGlyph

122
123
Defined in FT_GLYPH_H (freetype/ftglyph.h).
124

125
126
 
127
  typedef struct FT_BitmapGlyphRec_*  FT_BitmapGlyph;
128
 
129

130
131

A handle to an object used to model a bitmap glyph image. This is a sub-class of FT_Glyph, and a pointer to FT_BitmapGlyphRec.

132

133
134

135
[Index]
136
137
[TOC]
138
 
139
140

FT_BitmapGlyphRec

141
142
Defined in FT_GLYPH_H (freetype/ftglyph.h).
143

144
145
 
146
  typedef struct  FT_BitmapGlyphRec_
147
  {
148
    FT_GlyphRec  root;
149
    FT_Int       left;
150
    FT_Int       top;
151
    FT_Bitmap    bitmap;
152
 
153
  } FT_BitmapGlyphRec;
154
 
155

156
157

A structure used for bitmap glyph images. This really is a ‘sub-class’ of FT_GlyphRec.

158

159
fields
160

161
162
root
163

The root FT_Glyph fields.

164
165
left
166

The left-side bearing, i.e., the horizontal distance from the current pen position to the left border of the glyph bitmap.

167
168
top
169

The top-side bearing, i.e., the vertical distance from the current pen position to the top border of the glyph bitmap. This distance is positive for upwards y!

170
171
bitmap
172

A descriptor for the bitmap.

173
174
175
176
note
177

You can typecast an FT_Glyph to FT_BitmapGlyph if you have ‘glyph->format == FT_GLYPH_FORMAT_BITMAP’. This lets you access the bitmap's contents easily.

178

The corresponding pixel buffer is always owned by FT_BitmapGlyph and is thus created and destroyed with it.

179
180
181

182
[Index]
183
184
[TOC]
185
 
186
187

FT_OutlineGlyph

188
189
Defined in FT_GLYPH_H (freetype/ftglyph.h).
190

191
192
 
193
  typedef struct FT_OutlineGlyphRec_*  FT_OutlineGlyph;
194
 
195

196
197

A handle to an object used to model an outline glyph image. This is a sub-class of FT_Glyph, and a pointer to FT_OutlineGlyphRec.

198

199
200

201
[Index]
202
203
[TOC]
204
 
205
206

FT_OutlineGlyphRec

207
208
Defined in FT_GLYPH_H (freetype/ftglyph.h).
209

210
211
 
212
  typedef struct  FT_OutlineGlyphRec_
213
  {
214
    FT_GlyphRec  root;
215
    FT_Outline   outline;
216
 
217
  } FT_OutlineGlyphRec;
218
 
219

220
221

A structure used for outline (vectorial) glyph images. This really is a ‘sub-class’ of FT_GlyphRec.

222

223
fields
224

225
226
root
227

The root FT_Glyph fields.

228
229
outline
230

A descriptor for the outline.

231
232
233
234
note
235

You can typecast an FT_Glyph to FT_OutlineGlyph if you have ‘glyph->format == FT_GLYPH_FORMAT_OUTLINE’. This lets you access the outline's content easily.

236

As the outline is extracted from a glyph slot, its coordinates are expressed normally in 26.6 pixels, unless the flag FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char().

237

The outline's tables are always owned by the object and are destroyed with it.

238
239
240

241
[Index]
242
243
[TOC]
244
 
245
246

FT_Get_Glyph

247
248
Defined in FT_GLYPH_H (freetype/ftglyph.h).
249

250
251
 
252
  FT_EXPORT( FT_Error )
253
  FT_Get_Glyph( FT_GlyphSlot  slot,
254
                FT_Glyph     *aglyph );
255
 
256

257
258

A function used to extract a glyph image from a slot. Note that the created FT_Glyph object must be released with FT_Done_Glyph.

259

260
input
261

262
263
slot
264

A handle to the source glyph slot.

265
266
267
268
output
269

270
271
aglyph
272

A handle to the glyph object.

273
274
275
276
return
277

FreeType error code. 0 means success.

278
279
280

281
[Index]
282
283
[TOC]
284
 
285
286

FT_Glyph_Copy

287
288
Defined in FT_GLYPH_H (freetype/ftglyph.h).
289

290
291
 
292
  FT_EXPORT( FT_Error )
293
  FT_Glyph_Copy( FT_Glyph   source,
294
                 FT_Glyph  *target );
295
 
296

297
298

A function used to copy a glyph image. Note that the created FT_Glyph object must be released with FT_Done_Glyph.

299

300
input
301

302
303
source
304

A handle to the source glyph object.

305
306
307
308
output
309

310
311
target
312

A handle to the target glyph object. 0 in case of error.

313
314
315
316
return
317

FreeType error code. 0 means success.

318
319
320

321
[Index]
322
323
[TOC]
324
 
325
326

FT_Glyph_Transform

327
328
Defined in FT_GLYPH_H (freetype/ftglyph.h).
329

330
331
 
332
  FT_EXPORT( FT_Error )
333
  FT_Glyph_Transform( FT_Glyph    glyph,
334
                      FT_Matrix*  matrix,
335
                      FT_Vector*  delta );
336
 
337

338
339

Transform a glyph image if its format is scalable.

340

341
inout
342

343
344
glyph
345

A handle to the target glyph object.

346
347
348
349
input
350

351
352
matrix
353

A pointer to a 2x2 matrix to apply.

354
355
delta
356

A pointer to a 2d vector to apply. Coordinates are expressed in 1/64th of a pixel.

357
358
359
360
return
361

FreeType error code (if not 0, the glyph format is not scalable).

362
363
note
364

The 2x2 transformation matrix is also applied to the glyph's advance vector.

365
366
367

368
[Index]
369
370
[TOC]
371
 
372
373

FT_Glyph_BBox_Mode

374
375
Defined in FT_GLYPH_H (freetype/ftglyph.h).
376

377
378
 
379
  typedef enum  FT_Glyph_BBox_Mode_
380
  {
381
    FT_GLYPH_BBOX_UNSCALED  = 0,
382
    FT_GLYPH_BBOX_SUBPIXELS = 0,
383
    FT_GLYPH_BBOX_GRIDFIT   = 1,
384
    FT_GLYPH_BBOX_TRUNCATE  = 2,
385
    FT_GLYPH_BBOX_PIXELS    = 3
386
 
387
  } FT_Glyph_BBox_Mode;
388
 
389

390
391

The mode how the values of FT_Glyph_Get_CBox are returned.

392

393
values
394

395
396
FT_GLYPH_BBOX_UNSCALED
397

Return unscaled font units.

398
399
FT_GLYPH_BBOX_SUBPIXELS
400
401

Return unfitted 26.6 coordinates.

402
403
FT_GLYPH_BBOX_GRIDFIT
404

Return grid-fitted 26.6 coordinates.

405
406
FT_GLYPH_BBOX_TRUNCATE
407

Return coordinates in integer pixels.

408
409
FT_GLYPH_BBOX_PIXELS
410

Return grid-fitted pixel coordinates.

411
412
413
414
415

416
[Index]
417
418
[TOC]
419
 
420
421

ft_glyph_bbox_xxx

422
423
Defined in FT_GLYPH_H (freetype/ftglyph.h).
424

425
426
 
427
#define ft_glyph_bbox_unscaled   FT_GLYPH_BBOX_UNSCALED
428
#define ft_glyph_bbox_subpixels  FT_GLYPH_BBOX_SUBPIXELS
429
#define ft_glyph_bbox_gridfit    FT_GLYPH_BBOX_GRIDFIT
430
#define ft_glyph_bbox_truncate   FT_GLYPH_BBOX_TRUNCATE
431
#define ft_glyph_bbox_pixels     FT_GLYPH_BBOX_PIXELS
432
 
433

434
435

These constants are deprecated. Use the corresponding FT_Glyph_BBox_Mode values instead.

436

437
values
438

439
440
ft_glyph_bbox_unscaled
441

See FT_GLYPH_BBOX_UNSCALED.

442
443
ft_glyph_bbox_subpixels
444
445

See FT_GLYPH_BBOX_SUBPIXELS.

446
447
ft_glyph_bbox_gridfit
448

See FT_GLYPH_BBOX_GRIDFIT.

449
450
ft_glyph_bbox_truncate
451

See FT_GLYPH_BBOX_TRUNCATE.

452
453
ft_glyph_bbox_pixels
454

See FT_GLYPH_BBOX_PIXELS.

455
456
457
458
459

460
[Index]
461
462
[TOC]
463
 
464
465

FT_Glyph_Get_CBox

466
467
Defined in FT_GLYPH_H (freetype/ftglyph.h).
468

469
470
 
471
  FT_EXPORT( void )
472
  FT_Glyph_Get_CBox( FT_Glyph  glyph,
473
                     FT_UInt   bbox_mode,
474
                     FT_BBox  *acbox );
475
 
476

477
478

Return a glyph's ‘control box’. The control box encloses all the outline's points, including Bézier control points. Though it coincides with the exact bounding box for most glyphs, it can be slightly larger in some situations (like when rotating an outline which contains Bézier outside arcs).

479

Computing the control box is very fast, while getting the bounding box can take much more time as it needs to walk over all segments and arcs in the outline. To get the latter, you can use the ‘ftbbox’ component which is dedicated to this single task.

480

481
input
482

483
484
glyph
485

A handle to the source glyph object.

486
487
mode
488

The mode which indicates how to interpret the returned bounding box values.

489
490
491
492
output
493

494
495
acbox
496

The glyph coordinate bounding box. Coordinates are expressed in 1/64th of pixels if it is grid-fitted.

497
498
499
500
note
501

Coordinates are relative to the glyph origin, using the y upwards convention.

502

If the glyph has been loaded with FT_LOAD_NO_SCALE, ‘bbox_mode’ must be set to FT_GLYPH_BBOX_UNSCALED to get unscaled font units in 26.6 pixel format. The value FT_GLYPH_BBOX_SUBPIXELS is another name for this constant.

503

If the font is tricky and the glyph has been loaded with FT_LOAD_NO_SCALE, the resulting CBox is meaningless. To get reasonable values for the CBox it is necessary to load the glyph at a large ppem value (so that the hinting instructions can properly shift and scale the subglyphs), then extracting the CBox which can be eventually converted back to font units.

504

Note that the maximum coordinates are exclusive, which means that one can compute the width and height of the glyph image (be it in integer or 26.6 pixels) as:

505
506
  width  = bbox.xMax - bbox.xMin;
507
  height = bbox.yMax - bbox.yMin;
508
509

Note also that for 26.6 coordinates, if ‘bbox_mode’ is set to FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, which corresponds to:

510
511
  bbox.xMin = FLOOR(bbox.xMin);
512
  bbox.yMin = FLOOR(bbox.yMin);
513
  bbox.xMax = CEILING(bbox.xMax);
514
  bbox.yMax = CEILING(bbox.yMax);
515
516

To get the bbox in pixel coordinates, set ‘bbox_mode’ to FT_GLYPH_BBOX_TRUNCATE.

517

To get the bbox in grid-fitted pixel coordinates, set ‘bbox_mode’ to FT_GLYPH_BBOX_PIXELS.

518
519
520

521
[Index]
522
523
[TOC]
524
 
525
526

FT_Glyph_To_Bitmap

527
528
Defined in FT_GLYPH_H (freetype/ftglyph.h).
529

530
531
 
532
  FT_EXPORT( FT_Error )
533
  FT_Glyph_To_Bitmap( FT_Glyph*       the_glyph,
534
                      FT_Render_Mode  render_mode,
535
                      FT_Vector*      origin,
536
                      FT_Bool         destroy );
537
 
538

539
540

Convert a given glyph object to a bitmap glyph object.

541

542
inout
543

544
545
the_glyph
546

A pointer to a handle to the target glyph.

547
548
549
550
input
551

552
553
render_mode
554

An enumeration that describes how the data is rendered.

555
556
origin
557

A pointer to a vector used to translate the glyph image before rendering. Can be 0 (if no translation). The origin is expressed in 26.6 pixels.

558
559
destroy
560

A boolean that indicates that the original glyph image should be destroyed by this function. It is never destroyed in case of error.

561
562
563
564
return
565

FreeType error code. 0 means success.

566
567
note
568

This function does nothing if the glyph format isn't scalable.

569

The glyph image is translated with the ‘origin’ vector before rendering.

570

The first parameter is a pointer to an FT_Glyph handle, that will be replaced by this function (with newly allocated data). Typically, you would use (omitting error handling):

571

572
573
  FT_Glyph        glyph;
574
  FT_BitmapGlyph  glyph_bitmap;
575
 
576
 
577
  // load glyph
578
  error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT );
579
 
580
  // extract glyph image
581
  error = FT_Get_Glyph( face->glyph, &glyph );
582
 
583
  // convert to a bitmap (default render mode + destroying old)
584
  if ( glyph->format != FT_GLYPH_FORMAT_BITMAP )
585
  {
586
    error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL,
587
                                0, 1 );
588
    if ( error ) // `glyph' unchanged
589
      ...
590
  }
591
 
592
  // access bitmap content by typecasting
593
  glyph_bitmap = (FT_BitmapGlyph)glyph;
594
 
595
  // do funny stuff with it, like blitting/drawing
596
  ...
597
 
598
  // discard glyph image (bitmap or not)
599
  FT_Done_Glyph( glyph );
600
601

602

Here another example, again without error handling:

603

604
605
  FT_Glyph  glyphs[MAX_GLYPHS]
606
 
607
 
608
  ...
609
 
610
  for ( idx = 0; i < MAX_GLYPHS; i++ )
611
    error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT ) ||
612
            FT_Get_Glyph ( face->glyph, &glyph[idx] );
613
 
614
  ...
615
 
616
  for ( idx = 0; i < MAX_GLYPHS; i++ )
617
  {
618
    FT_Glyph  bitmap = glyphs[idx];
619
 
620
 
621
    ...
622
 
623
    // after this call, `bitmap' no longer points into
624
    // the `glyphs' array (and the old value isn't destroyed)
625
    FT_Glyph_To_Bitmap( &bitmap, FT_RENDER_MODE_MONO, 0, 0 );
626
 
627
    ...
628
 
629
    FT_Done_Glyph( bitmap );
630
  }
631
 
632
  ...
633
 
634
  for ( idx = 0; i < MAX_GLYPHS; i++ )
635
    FT_Done_Glyph( glyphs[idx] );
636
637
638
639

640
[Index]
641
642
[TOC]
643
 
644
645

FT_Done_Glyph

646
647
Defined in FT_GLYPH_H (freetype/ftglyph.h).
648

649
650
 
651
  FT_EXPORT( void )
652
  FT_Done_Glyph( FT_Glyph  glyph );
653
 
654

655
656

Destroy a given glyph.

657

658
input
659

660
661
glyph
662

A handle to the target glyph object.

663
664
665
666
667

668
[Index]
669
670
[TOC]
671
 
672
673