revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / freetype2 / kerning.c
blobae8d0696511a98512a5ad791dfc0a14e7e11fe9f
1 /*
2 * Based on the code from the ft2.library from MorphOS and the ttf.library by
3 * Richard Griffith
4 */
5 #include "kerning.h"
6 #include "glyph.h"
8 //#define DEBUG 1
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));
22 if (list == NULL)
23 return;
25 work_node = (struct GlyphWidthEntry *)(list->mlh_Head);
26 while ((next_node =
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)
38 struct MinList *gw;
39 struct GlyphWidthEntry *node;
40 ULONG howwide;
41 int hold_start, c_start, c_stop, i, j;
42 ULONG units_per_em;
43 FT_Glyph_Metrics *metrics;
45 if (ge->instance_changed)
47 /* reset everything first */
48 if(SetInstance(ge)!=OTERR_Success)
49 return NULL;
51 /*if(ge->cmap_index==NO_CMAP_SET)
53 //if(ChooseEncoding(ge)!=0)
54 return(NULL);
55 }*/
57 gw = (struct MinList *) AllocMem(sizeof(struct MinList), MEMF_CLEAR);
59 if(gw==NULL)
61 D(bug("GetWidthList - AllocMem for list failed\n"));
62 set_last_error(ge,OTERR_NoMemory);
63 return NULL;
65 NewList((struct List *)gw);
67 #if 0
68 units_per_em=ge->properties.header->Units_Per_EM;
69 int yMin,yMax;
71 yMin=ge->properties.header->yMin; if(yMin>0) yMin = 0-yMin;
72 yMax=ge->properties.header->yMax;
73 units_per_em=yMax-yMin;
74 #endif
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;
81 if(c_start>c_stop)
83 /* just in case */
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++)
91 ge->request_char=i;
92 j=UnicodeToGlyphIndex(ge);
94 if(j==0)
96 D(bug("GetWidthList - no glyph %ld i=%ld p=%ld e=%ld\n"
97 ,i, ge->cmap_index,ge->platform, ge->encoding));
98 continue;
101 if(FT_Load_Glyph(ge->face,j,FT_LOAD_DEFAULT))
103 D(bug("Error loading glyph %ld.\n",(LONG)j));
104 howwide=0;
106 else
108 //FT_Get_Glyph_Metrics( ge->glyph, &ge->metrics );
109 metrics = &ge->face->glyph->metrics;
111 #if 0
112 howwide=((metrics->horiAdvance)<<16)/units_per_em;
113 #else
114 howwide = (metrics->horiAdvance << 10) /
115 (( ge->face->size->metrics.x_ppem * units_per_em) / ge->face->units_per_EM);
116 #endif
119 node = AllocMem(sizeof(struct GlyphWidthEntry), MEMF_CLEAR);
120 if(node==NULL)
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;
126 return NULL;
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;
140 return gw;
144 int get_kerning_dir(FT_GlyphEngine *ge)
146 //FT_Kern_Subtable *k;
147 //FT_Kern_0_Pair *p; /* a table of nPairs 'pairs' */
149 //int i,kern_value;
150 FT_Vector kerning;
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)
158 return 0;
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))
167 return 0;
169 return (-kerning.x << 16) / ge->corrected_upem;