2 * Based on the code from the ft2.library from MorphOS and the ttf.library by
9 #include <aros/debug.h>
10 #include <exec/memory.h>
11 #include <diskfont/oterrors.h>
12 #include <diskfont/glyph.h>
14 #include <proto/exec.h>
15 #include <proto/alib.h>
17 void FreeWidthList(FT_GlyphEngine
*ge
,struct MinList
*list
)
19 struct GlyphWidthEntry
*work_node
, *next_node
;
21 //D(bug("FreeWidthList at %lx\n",list));
25 work_node
= (struct GlyphWidthEntry
*)(list
->mlh_Head
);
27 (struct GlyphWidthEntry
*)(work_node
->gwe_Node
.mln_Succ
)))
29 FreeMem(work_node
, sizeof(struct GlyphWidthEntry
));
30 work_node
= next_node
;
32 FreeMem(list
, sizeof(struct MinList
));
36 struct MinList
*GetWidthList(FT_GlyphEngine
*ge
)
39 struct GlyphWidthEntry
*node
;
41 int hold_start
, c_start
, c_stop
, i
, j
;
43 FT_Glyph_Metrics
*metrics
;
45 if (ge
->instance_changed
)
47 /* reset everything first */
48 if(SetInstance(ge
)!=OTERR_Success
)
51 /*if(ge->cmap_index==NO_CMAP_SET)
53 //if(ChooseEncoding(ge)!=0)
57 gw
= (struct MinList
*) AllocMem(sizeof(struct MinList
), MEMF_CLEAR
);
61 D(bug("GetWidthList - AllocMem for list failed\n"));
62 set_last_error(ge
,OTERR_NoMemory
);
65 NewList((struct List
*)gw
);
68 units_per_em
=ge
->properties
.header
->Units_Per_EM
;
71 yMin
=ge
->properties
.header
->yMin
; if(yMin
>0) yMin
= 0-yMin
;
72 yMax
=ge
->properties
.header
->yMax
;
73 units_per_em
=yMax
-yMin
;
76 units_per_em
= ge
->corrected_upem
;
78 hold_start
=ge
->request_char
;
79 c_start
=ge
->request_char
;
80 c_stop
=ge
->request_char2
;
84 c_start
=ge
->request_char2
;
85 c_stop
=ge
->request_char
;
87 D(bug("GetWidthList - from %ld to %ld\n",c_start
,c_stop
));
89 for(i
=c_start
;i
<=c_stop
;i
++)
92 j
=UnicodeToGlyphIndex(ge
);
96 D(bug("GetWidthList - no glyph %ld i=%ld p=%ld e=%ld\n"
97 ,i
, ge
->cmap_index
,ge
->platform
, ge
->encoding
));
101 if(FT_Load_Glyph(ge
->face
,j
,FT_LOAD_DEFAULT
))
103 D(bug("Error loading glyph %ld.\n",(LONG
)j
));
108 //FT_Get_Glyph_Metrics( ge->glyph, &ge->metrics );
109 metrics
= &ge
->face
->glyph
->metrics
;
112 howwide
=((metrics
->horiAdvance
)<<16)/units_per_em
;
114 howwide
= (metrics
->horiAdvance
<< 10) /
115 (( ge
->face
->size
->metrics
.x_ppem
* units_per_em
) / ge
->face
->units_per_EM
);
119 node
= AllocMem(sizeof(struct GlyphWidthEntry
), MEMF_CLEAR
);
122 D(bug("GetWidthList - AllocMem for %ld failed\n",i
));
123 FreeWidthList(ge
,gw
);
124 set_last_error(ge
,OTERR_NoMemory
);
125 ge
->request_char
=hold_start
;
129 node
->gwe_Code
= i
; /* amiga char */
130 /* character advance, as fraction of em width */
131 node
->gwe_Width
= howwide
;
133 // D(bug("GetWidthList - glyph %ld width %lx\n",
134 // node->gwe_Code, node->gwe_Width ));
136 AddTail( (struct List
*)gw
, (struct Node
*)node
);
139 ge
->request_char
=hold_start
;
144 int get_kerning_dir(FT_GlyphEngine
*ge
)
146 //FT_Kern_Subtable *k;
147 //FT_Kern_0_Pair *p; /* a table of nPairs 'pairs' */
151 FT_UShort l
,r
; /* left and right indexes */
153 /* instance change may be irrelevant, but just in case */
154 if (ge
->instance_changed
)
156 /* reset everything first */
157 if(SetInstance(ge
)!=OTERR_Success
)
161 /* get left and right glyph indexes */
162 l
=char_to_glyph(ge
,ge
->request_char
);
163 r
=char_to_glyph(ge
,ge
->request_char2
);
164 if(l
==0 || r
==0) return(0); /* no chance */
166 if (FT_Get_Kerning(ge
->face
, l
, r
, ft_kerning_unscaled
, &kerning
))
169 return (-kerning
.x
<< 16) / ge
->corrected_upem
;