1 /***************************************************************************/
5 /* OpenType font driver implementation (body). */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
19 #include <freetype/freetype.h>
20 #include <freetype/internal/ftdebug.h>
21 #include <freetype/internal/ftstream.h>
22 #include <freetype/internal/sfnt.h>
23 #include <freetype/ttnameid.h>
25 #include <freetype/internal/t2errors.h>
28 #ifdef FT_FLAT_COMPILE
35 #include <cff/t2driver.h>
36 #include <cff/t2gload.h>
41 /*************************************************************************/
43 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
44 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
45 /* messages during execution. */
48 #define FT_COMPONENT trace_t2driver
51 /*************************************************************************/
52 /*************************************************************************/
53 /*************************************************************************/
59 /*************************************************************************/
60 /*************************************************************************/
61 /*************************************************************************/
65 #define PAIR_TAG( left, right ) ( ( (FT_ULong)left << 16 ) | \
69 /*************************************************************************/
75 /* A driver method used to return the kerning vector between two */
76 /* glyphs of the same face. */
79 /* face :: A handle to the source face object. */
81 /* left_glyph :: The index of the left glyph in the kern pair. */
83 /* right_glyph :: The index of the right glyph in the kern pair. */
86 /* kerning :: The kerning vector. This is in font units for */
87 /* scalable formats, and in pixels for fixed-sizes */
91 /* FreeType error code. 0 means success. */
94 /* Only horizontal layouts (left-to-right & right-to-left) are */
95 /* supported by this function. Other layouts, or more sophisticated */
96 /* kernings, are out of scope of this method (the basic driver */
97 /* interface is meant to be simple). */
99 /* They can be implemented by format-specific interfaces. */
102 FT_Error
Get_Kerning( TT_Face face
,
107 TT_Kern_0_Pair
* pair
;
111 return T2_Err_Invalid_Face_Handle
;
116 if ( face
->kern_pairs
)
118 /* there are some kerning pairs in this font file! */
119 FT_ULong search_tag
= PAIR_TAG( left_glyph
, right_glyph
);
124 right
= face
->num_kern_pairs
- 1;
126 while ( left
<= right
)
128 FT_Int middle
= left
+ ( ( right
- left
) >> 1 );
132 pair
= face
->kern_pairs
+ middle
;
133 cur_pair
= PAIR_TAG( pair
->left
, pair
->right
);
135 if ( cur_pair
== search_tag
)
138 if ( cur_pair
< search_tag
)
149 kerning
->x
= pair
->value
;
157 /*************************************************************************/
163 /* A driver method used to load a glyph within a given glyph slot. */
166 /* slot :: A handle to the target slot object where the glyph */
167 /* will be loaded. */
169 /* size :: A handle to the source face size at which the glyph */
170 /* must be scaled, loaded, etc. */
172 /* glyph_index :: The index of the glyph in the font file. */
174 /* load_flags :: A flag indicating what to load for this glyph. The */
175 /* FTLOAD_??? constants can be used to control the */
176 /* glyph loading process (e.g., whether the outline */
177 /* should be scaled, whether to load bitmaps or not, */
178 /* whether to hint the outline, etc). */
181 /* FreeType error code. 0 means success. */
184 FT_Error
Load_Glyph( T2_GlyphSlot slot
,
186 FT_UShort glyph_index
,
193 return T2_Err_Invalid_Glyph_Handle
;
195 /* check whether we want a scaled outline or bitmap */
197 load_flags
|= FT_LOAD_NO_SCALE
| FT_LOAD_NO_HINTING
;
199 if ( load_flags
& FT_LOAD_NO_SCALE
)
202 /* reset the size object if necessary */
205 /* these two object must have the same parent */
206 if ( size
->face
!= slot
->root
.face
)
207 return T2_Err_Invalid_Face_Handle
;
210 /* now load the glyph outline if necessary */
211 error
= T2_Load_Glyph( slot
, size
, glyph_index
, load_flags
);
213 /* force drop-out mode to 2 - irrelevant now */
214 /* slot->outline.dropout_mode = 2; */
220 /*************************************************************************/
221 /*************************************************************************/
222 /*************************************************************************/
225 /**** C H A R A C T E R M A P P I N G S ****/
228 /*************************************************************************/
229 /*************************************************************************/
230 /*************************************************************************/
232 /*************************************************************************/
238 /* Uses a charmap to return a given character code's glyph index. */
241 /* charmap :: A handle to the source charmap object. */
242 /* charcode :: The character code. */
245 /* Glyph index. 0 means `undefined character code'. */
248 FT_UInt
t2_get_char_index( TT_CharMap charmap
,
256 cmap
= &charmap
->cmap
;
257 face
= (T2_Face
)charmap
->root
.face
;
259 /* Load table if needed */
262 SFNT_Interface
* sfnt
= (SFNT_Interface
*)face
->sfnt
;
265 error
= sfnt
->load_charmap( face
, cmap
, face
->root
.stream
);
272 return ( cmap
->get_index
? cmap
->get_index( cmap
, charcode
) : 0 );
276 /*************************************************************************/
277 /*************************************************************************/
278 /*************************************************************************/
281 /**** D R I V E R I N T E R F A C E ****/
284 /*************************************************************************/
285 /*************************************************************************/
286 /*************************************************************************/
290 FT_Module_Interface
t2_get_interface( T2_Driver driver
,
291 const char* interface
)
296 /* we simply pass our request to the `sfnt' module */
297 sfnt
= FT_Get_Module( driver
->root
.root
.library
, "sfnt" );
299 return sfnt
? sfnt
->clazz
->get_interface( sfnt
, interface
) : 0;
303 /* The FT_DriverInterface structure is defined in ftdriver.h. */
305 const FT_Driver_Class cff_driver_class
=
307 /* begin with the FT_Module_Class fields */
309 ft_module_font_driver
| ft_module_driver_scalable
,
310 sizeof( T2_DriverRec
),
315 0, /* module-specific interface */
317 (FT_Module_Constructor
)T2_Init_Driver
,
318 (FT_Module_Destructor
) T2_Done_Driver
,
319 (FT_Module_Requester
) t2_get_interface
,
322 /* now the specific driver fields */
323 sizeof( TT_FaceRec
),
324 sizeof( FT_SizeRec
),
325 sizeof( T2_GlyphSlotRec
),
327 (FTDriver_initFace
) T2_Init_Face
,
328 (FTDriver_doneFace
) T2_Done_Face
,
329 (FTDriver_initSize
) 0,
330 (FTDriver_doneSize
) 0,
331 (FTDriver_initGlyphSlot
)0,
332 (FTDriver_doneGlyphSlot
)0,
334 (FTDriver_setCharSizes
) 0,
335 (FTDriver_setPixelSizes
)0,
337 (FTDriver_loadGlyph
) Load_Glyph
,
338 (FTDriver_getCharIndex
) t2_get_char_index
,
340 (FTDriver_getKerning
) Get_Kerning
,
341 (FTDriver_attachFile
) 0,
342 (FTDriver_getAdvances
) 0
346 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
349 /*************************************************************************/
355 /* This function is used when compiling the TrueType driver as a */
356 /* shared library (`.DLL' or `.so'). It will be used by the */
357 /* high-level library of FreeType to retrieve the address of the */
358 /* driver's generic interface. */
360 /* It shouldn't be implemented in a static build, as each driver must */
361 /* have the same function as an exported entry point. */
364 /* The address of the TrueType's driver generic interface. The */
365 /* format-specific interface can then be retrieved through the method */
366 /* interface->get_format_interface. */
368 EXPORT_FUNC( FT_Driver_Class
* ) getDriverClass( void )
370 return &cff_driver_class
;
374 #endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */