w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ttfaux.c
Go to the documentation of this file.
1 /*
2  * ttfaux.c
3  *
4  * This file is part of the ttf2pk package.
5  *
6  * Copyright 1997-1999, 2000, 2002, 2003 by
7  * Frederic Loyer <loyer@ensta.fr>
8  * Werner Lemberg <wl@gnu.org>
9  */
10 
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14 
15 #include <string.h>
16 #include <stdlib.h>
17 
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 #include FT_OUTLINE_H
21 #include FT_BBOX_H
22 
23 #include "ttf2tfm.h"
24 #include "newobj.h"
25 #include "ligkern.h"
26 #include "ttfenc.h"
27 #include "tfmaux.h"
28 #include "errormsg.h"
29 #include "ttfaux.h"
30 #include "filesrch.h"
31 #include "ftlib.h"
32 
33 
35 
37 
39 
40 
41 static void
43 {
44  kern *nk;
45  ttfinfo *ti, *tj;
47  FT_Vector akerning;
48 
49  for (ti = fnt->charlist; ti; ti = ti->next)
50  {
51  kern head;
52  kern *tail = &head;
53  head.next = NULL;
54  for (tj = fnt->charlist; tj; tj = tj->next)
55  {
56  if ((error = FT_Get_Kerning(face, ti->glyphindex, tj->glyphindex,
57  FT_KERNING_UNSCALED, &akerning)))
58  oops("Cannot get kerning vector (error code = 0x%x).", error);
59 
60  if (akerning.x)
61  {
62  nk = newkern();
63  nk->succ = tj->adobename;
64  nk->delta = transform(akerning.x * 1000 / fnt->units_per_em, 0,
65  fnt->efactor, fnt->slant);
66 #if 0
67  nk->next = ti->kerns;
68  ti->kerns = nk;
69 #else
70  /* We append the new kern to reproduce the old .vpl file */
71  tail->next = nk;
72  tail = nk;
73 #endif
74  }
75  }
76  ti->kerns = head.next;
77  }
78 }
79 
80 
81 void
83 {
85  ttfinfo *ti, *Ti;
86  long Num, index;
87  unsigned int i, j;
88  long k, max_k;
89  int index_array[257];
90 
91  static Boolean initialized = False;
92 
93 
94  /*
95  * We allocate a placeholder boundary and the `.notdef' character.
96  */
97 
98  if (!only_range)
99  {
100  ti = newchar(fnt);
101  ti->charcode = -1;
102  ti->adobename = ".notdef";
103 
104  ti = newchar(fnt);
105  ti->charcode = -1;
106  ti->adobename = "||"; /* boundary character name */
107  }
108 
109  /*
110  * Initialize FreeType engine.
111  */
112 
113  if (!initialized)
114  {
115  /*
116  * We use a dummy glyph size of 10pt.
117  */
118  dpi = 92;
119  ptsize = 10 * 64;
120 
121  real_ttfname = TeX_search_ttf_file(&(fnt->ttfname));
122  if (!real_ttfname)
123  oops("Cannot find `%s'.", fnt->ttfname);
124 
126 
127  initialized = True;
128  }
129 
130  if (!quiet)
131  {
132  if (only_range)
133  printf("\n\n%s:\n", fnt->fullname);
134  printf("\n");
135  printf("Glyph Code Glyph Name ");
136  printf("Width llx lly urx ury\n");
137  printf("----------------------------------------");
138  printf("---------------------------------\n");
139  }
140 
141  /*
142  * We load only glyphs with a valid cmap entry. Nevertheless, for
143  * the default mapping, we use the first 256 glyphs addressed by
144  * ascending code points, followed by glyphs not in the cmap.
145  *
146  * If we compute a range, we take the character codes given in
147  * the fnt->sf_code array.
148  *
149  * If the -N flag is set, no cmap is used at all. Instead, the
150  * first 256 glyphs (with a valid PS name) are used for the default
151  * mapping.
152  */
153 
154  if (!only_range)
155  for (i = 0; i < 257; i++)
156  index_array[i] = 0;
157  else
158  for (i = 0; i < 256; i++)
159  fnt->inencptrs[i] = 0;
160 
161  j = 0;
162  if (fnt->PSnames == Only)
163  max_k = face->num_glyphs - 1;
164  else
165  max_k = only_range ? 0xFF : 0x16FFFF;
166 
167  for (k = 0; k <= max_k; k++)
168  {
169  char buff[128];
170  const char *an;
171 
172 
173  if (fnt->PSnames != Only)
174  {
175  if (only_range)
176  {
177  index = fnt->sf_code[k];
178  if (index < 0)
179  continue;
180  j = k;
181  }
182  else
183  index = k;
184 
186 
187  /* now we try to get a vertical glyph form */
188  if (has_gsub)
189  Num = Get_Vert(Num);
190 
191  if (Num < 0)
192  oops("Failure on cmap mapping from %s.", fnt->ttfname);
193  if (Num == 0)
194  continue;
195  if (!only_range)
196  if (Num <= 256)
197  index_array[Num] = 1;
198  }
199  else
200  {
201  Num = k;
202  index = 0;
203  }
204 
206  if (!error)
207  {
208  if (fnt->efactor != 1.0 || fnt->slant != 0.0 )
210  if (fnt->rotate)
212  error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); /* we need the non-
213  grid-fitted bbox */
214  }
215  if (!error)
216  {
217  if (fnt->PSnames)
218  {
220  an = newstring(buff);
221  }
222  else
223  an = code_to_adobename(index);
224 
225  /* ignore characters not usable for typesetting with TeX */
226 
227  if (strcmp(an, ".notdef") == 0)
228  continue;
229  if (strcmp(an, ".null") == 0)
230  continue;
231  if (strcmp(an, "nonmarkingreturn") == 0)
232  continue;
233 
234  ti = newchar(fnt);
235  ti->charcode = index;
236  ti->glyphindex = Num;
237  ti->adobename = an;
238  ti->llx = bbox.xMin * 1000 / fnt->units_per_em;
239  ti->lly = bbox.yMin * 1000 / fnt->units_per_em;
240  ti->urx = bbox.xMax * 1000 / fnt->units_per_em;
241  ti->ury = bbox.yMax * 1000 / fnt->units_per_em;
242 
243  ti->fntnum = fnt->subfont_num;
244 
245  /*
246  * We must now shift the rotated character both horizontally
247  * and vertically. The vertical amount is 25% by default.
248  */
249 
250  if (fnt->rotate)
251  {
252  ti->llx += (face->glyph->metrics.vertBearingY - bbox.xMin) *
253  1000 / fnt->units_per_em;
254  ti->lly -= 1000 * fnt->y_offset;
255  ti->urx += (face->glyph->metrics.vertBearingY - bbox.xMin) *
256  1000 / fnt->units_per_em;
257  ti->ury -= 1000 * fnt->y_offset;
258  }
259 
260  /*
261  * We need to avoid negative heights or depths. They break accents
262  * in math mode, among other things.
263  */
264 
265  if (ti->lly > 0)
266  ti->lly = 0;
267  if (ti->ury < 0)
268  ti->ury = 0;
269  if (fnt->rotate)
270  ti->width = face->glyph->metrics.vertAdvance * 1000 / fnt->units_per_em;
271  else
272  ti->width = transform(face->glyph->metrics.horiAdvance * 1000 / fnt->units_per_em,
273  0, fnt->efactor, fnt->slant);
274 
275  if (!quiet)
276  printf("%5ld %05lx %-25s %5d % 5d,% 5d -- % 5d,% 5d\n",
277  Num, index, ti->adobename,
278  ti->width,
279  ti->llx, ti->lly, ti->urx, ti->ury);
280 
281  if (j < 256)
282  {
283  fnt->inencptrs[j] = ti;
284  ti->incode = j;
285  }
286  j++;
287  }
288  }
289 
290  /*
291  * Now we load glyphs without a cmap entry, provided some slots are
292  * still free -- we skip this if we have to compute a range or use
293  * PS names.
294  */
295 
296  if (!only_range && !fnt->PSnames)
297  {
298  for (i = 1; i <= face->num_glyphs; i++)
299  {
300  const char *an;
301 
302 
303  if (index_array[i] == 0)
304  {
306  if (!error)
308  if (!error)
309  {
310  an = code_to_adobename(i | 0x1000000);
311 
312  ti = newchar(fnt);
313  ti->charcode = i | 0x1000000;
314  ti->glyphindex = i;
315  ti->adobename = an;
316  ti->llx = bbox.xMin * 1000 / fnt->units_per_em;
317  ti->lly = bbox.yMin * 1000 / fnt->units_per_em;
318  ti->urx = bbox.xMax * 1000 / fnt->units_per_em;
319  ti->ury = bbox.yMax * 1000 / fnt->units_per_em;
320 
321  if (ti->lly > 0)
322  ti->lly = 0;
323  if (ti->ury < 0)
324  ti->ury = 0;
325  ti->width = transform(face->glyph->metrics.horiAdvance*1000 / fnt->units_per_em,
326  0, fnt->efactor, fnt->slant);
327 
328  if (!quiet)
329  printf("%5d %-25s %5d % 5d,% 5d -- % 5d,% 5d\n",
330  i, ti->adobename,
331  ti->width,
332  ti->llx, ti->lly, ti->urx, ti->ury);
333 
334  if (j < 256)
335  {
336  fnt->inencptrs[j] = ti;
337  ti->incode = j;
338  }
339  else
340  break;
341  j++;
342  }
343  }
344  }
345  }
346 
347  /* Finally, we construct a `Germandbls' glyph if necessary */
348 
349  if (!only_range)
350  {
351  if (NULL == findadobe("Germandbls", fnt->charlist) &&
352  NULL != (Ti = findadobe("S", fnt->charlist)))
353  {
354  pcc *np, *nq;
355 
356 
357  ti = newchar(fnt);
358  ti->charcode = face->num_glyphs | 0x1000000;
359  ti->glyphindex = face->num_glyphs;
360  ti->adobename = "Germandbls";
361  ti->width = Ti->width << 1;
362  ti->llx = Ti->llx;
363  ti->lly = Ti->lly;
364  ti->urx = Ti->width + Ti->urx;
365  ti->ury = Ti->ury;
366  ti->kerns = Ti->kerns;
367 
368  np = newpcc();
369  np->partname = "S";
370  nq = newpcc();
371  nq->partname = "S";
372  nq->xoffset = Ti->width;
373  np->next = nq;
374  ti->pccs = np;
375  ti->constructed = True;
376 
377  if (!quiet)
378  printf("* %-25s %5d % 5d,% 5d -- % 5d,% 5d\n",
379  ti->adobename,
380  ti->width,
381  ti->llx, ti->lly, ti->urx, ti->ury);
382  }
383  }
384 
385  /* kerning between subfonts isn't available */
386  if (!only_range)
387  readttf_kern(fnt);
388 }
389 
390 
391 /* end */
static struct kern * newkern(void)
Definition: afm2pl.c:670
static struct adobeinfo * findadobe(const char *p)
Definition: afm2pl.c:305
static struct adobeinfo * newchar(void)
Definition: afm2pl.c:648
static char * newstring(const char *s)
Definition: afm2pl.c:282
static struct pcc * newpcc(void)
Definition: afm2tfm.c:438
int nk
Definition: afm2tfm.c:885
#define head
Definition: aptex-macros.h:513
#define tail
Definition: aptex-macros.h:514
Definition: Font.hpp:55
op_table fnt
Definition: dt2dv.c:217
static int np
Definition: bifont.c:64
int strcmp()
Definition: coll.cpp:143
int printf()
#define error(a)
Definition: dviinfo.c:48
char * TeX_search_ttf_file(char **name)
Definition: filesrch.c:485
static void
Definition: fpif.c:118
int Get_Vert(int Num)
Definition: ftlib.c:825
void FTopen(char *filename, Font *fnt, Boolean do_tfm, Boolean quiet)
Definition: ftlib.c:662
int ptsize
Definition: ftlib.c:46
Boolean has_gsub
Definition: ftlib.c:48
FT_Matrix matrix1
Definition: ftlib.c:44
FT_Matrix matrix2
Definition: ftlib.c:44
static char buff[2 *10240]
Definition: genind.c:46
static BROTLI_INLINE uint16_t *FN() Num(void *extra)
FT_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
Definition: ftobjs.c:796
#define FT_LOAD_NO_SCALE
Definition: freetype.h:3022
FT_Get_Char_Index(FT_Face face, FT_ULong charcode)
Definition: ftobjs.c:3731
#define FT_LOAD_DEFAULT
Definition: freetype.h:3021
FT_Get_Glyph_Name(FT_Face face, FT_UInt glyph_index, FT_Pointer buffer, FT_UInt buffer_max)
Definition: ftobjs.c:4110
FT_Get_Kerning(FT_Face face, FT_UInt left_glyph, FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector *akerning)
Definition: ftobjs.c:3411
@ FT_KERNING_UNSCALED
Definition: freetype.h:3408
FT_BEGIN_HEADER FT_Outline_Get_BBox(FT_Outline *outline, FT_BBox *abbox)
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:706
int FT_Error
Definition: fttypes.h:299
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
FT_Face face
Definition: cffdrivr.c:659
static GBool quiet
Definition: pdfimages.cc:38
#define transform(xusr, yusr, xdev, ydev)
Definition: type1.c:1420
int k
Definition: otp-parser.c:70
static int dpi
Definition: pbmtolj.c:33
int Boolean
Definition: pgmcrater.c:64
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
#define index(s, c)
Definition: plain2.h:351
int Ti
Definition: rate.c:101
void oops(const char *message,...)
Definition: stackenv.c:90
FT_Long num_glyphs
Definition: freetype.h:1036
FT_GlyphSlot glyph
Definition: freetype.h:1065
FT_Outline outline
Definition: freetype.h:1890
FT_Glyph_Metrics metrics
Definition: freetype.h:1879
FT_Pos vertAdvance
Definition: freetype.h:311
FT_Pos vertBearingY
Definition: freetype.h:310
FT_Pos horiAdvance
Definition: freetype.h:307
FT_Pos x
Definition: ftimage.h:77
Definition: nsfix.c:44
Definition: ttf.h:354
Definition: mendex.h:20
Definition: afm2pl.c:145
Definition: afm2tfm.c:210
int xoffset
Definition: afm2tfm.c:213
const char * partname
Definition: afm2tfm.c:212
Definition: ttf.h:76
int j
Definition: t4ht.c:1589
@ True
Definition: ttf2tfm.h:20
@ False
Definition: ttf2tfm.h:19
@ Only
Definition: ttf2tfm.h:28
int flags
Definition: ttfaux.c:36
char * real_ttfname
Definition: ttfaux.c:34
FT_BBox bbox
Definition: ttfaux.c:38
static void readttf_kern(Font *fnt)
Definition: ttfaux.c:42
void readttf(Font *fnt, Boolean quiet, Boolean only_range)
Definition: ttfaux.c:82
const char * code_to_adobename(long code)
Definition: ttfenc.c:1052