| 1 |
/* |
| 2 |
|
| 3 |
Copyright 2006-2013 Taco Hoekwater <[email protected]> |
| 4 |
|
| 5 |
This file is part of LuaTeX. |
| 6 |
|
| 7 |
LuaTeX is free software; you can redistribute it and/or modify it under |
| 8 |
the terms of the GNU General Public License as published by the Free |
| 9 |
Software Foundation; either version 2 of the License, or (at your |
| 10 |
option) any later version. |
| 11 |
|
| 12 |
LuaTeX is distributed in the hope that it will be useful, but WITHOUT |
| 13 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 15 |
License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License along |
| 18 |
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
*/ |
| 21 |
|
| 22 |
/*tex |
| 23 |
|
| 24 |
Here is the main font API implementation for the original pascal parts. Stuff |
| 25 |
to watch out for: |
| 26 |
|
| 27 |
\startitemize |
| 28 |
|
| 29 |
\startitem |
| 30 |
Knuth had a |'null_character'| that was used when a character could |
| 31 |
not be found by the |fetch()| routine, to signal an error. This has |
| 32 |
been deleted, but it may mean that the output of luatex is |
| 33 |
incompatible with TeX after |fetch()| has detected an error |
| 34 |
condition. |
| 35 |
\stopitem |
| 36 |
|
| 37 |
\startitem |
| 38 |
Knuth also had a |font_glue()| optimization. I've removed that |
| 39 |
because it was a bit of dirty programming and it also was problematic |
| 40 |
|if 0 != null|. |
| 41 |
\stopitem |
| 42 |
|
| 43 |
\stopitemize |
| 44 |
|
| 45 |
*/ |
| 46 |
|
| 47 |
#include "ptexlib.h" |
| 48 |
#include "lua/luatex-api.h" |
| 49 |
|
| 50 |
#define noDEBUG |
| 51 |
|
| 52 |
#define proper_char_index(c) (c<=font_ec(f) && c>=font_bc(f)) |
| 53 |
#define do_realloc(a,b,d) a = xrealloc(a,(unsigned)((unsigned)(b)*sizeof(d))) |
| 54 |
|
| 55 |
texfont **font_tables = NULL; |
| 56 |
|
| 57 |
static int font_arr_max = 0; |
| 58 |
static int font_id_maxval = 0; |
| 59 |
|
| 60 |
static void grow_font_table(int id) |
| 61 |
{ |
| 62 |
int j; |
| 63 |
if (id >= font_arr_max) { |
| 64 |
font_bytes += |
| 65 |
(int) (((id + 8 - font_arr_max) * (int) sizeof(texfont *))); |
| 66 |
font_tables = |
| 67 |
xrealloc(font_tables, |
| 68 |
(unsigned) (((unsigned) id + 8) * sizeof(texfont *))); |
| 69 |
j = 8; |
| 70 |
while (j--) { |
| 71 |
font_tables[id + j] = NULL; |
| 72 |
} |
| 73 |
font_arr_max = id + 8; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
int new_font_id(void) |
| 78 |
{ |
| 79 |
int i; |
| 80 |
for (i = 0; i < font_arr_max; i++) { |
| 81 |
if (font_tables[i] == NULL) { |
| 82 |
break; |
| 83 |
} |
| 84 |
} |
| 85 |
if (i >= font_arr_max) |
| 86 |
grow_font_table(i); |
| 87 |
if (i > font_id_maxval) |
| 88 |
font_id_maxval = i; |
| 89 |
return i; |
| 90 |
} |
| 91 |
|
| 92 |
int max_font_id(void) |
| 93 |
{ |
| 94 |
return font_id_maxval; |
| 95 |
} |
| 96 |
|
| 97 |
void set_max_font_id(int i) |
| 98 |
{ |
| 99 |
font_id_maxval = i; |
| 100 |
} |
| 101 |
|
| 102 |
int new_font(void) |
| 103 |
{ |
| 104 |
int k; |
| 105 |
int id; |
| 106 |
charinfo *ci; |
| 107 |
sa_tree_item sa_value = { 0 }; |
| 108 |
id = new_font_id(); |
| 109 |
font_bytes += (int) sizeof(texfont); |
| 110 |
/*tex Most stuff is zero */ |
| 111 |
font_tables[id] = xcalloc(1, sizeof(texfont)); |
| 112 |
font_tables[id]->_font_name = NULL; |
| 113 |
font_tables[id]->_font_area = NULL; |
| 114 |
font_tables[id]->_font_filename = NULL; |
| 115 |
font_tables[id]->_font_fullname = NULL; |
| 116 |
font_tables[id]->_font_psname = NULL; |
| 117 |
font_tables[id]->_font_encodingname = NULL; |
| 118 |
font_tables[id]->_font_cidregistry = NULL; |
| 119 |
font_tables[id]->_font_cidordering = NULL; |
| 120 |
font_tables[id]->_left_boundary = NULL; |
| 121 |
font_tables[id]->_right_boundary = NULL; |
| 122 |
font_tables[id]->_param_base = NULL; |
| 123 |
font_tables[id]->_math_param_base = NULL; |
| 124 |
/*tex |ec = 0| */ |
| 125 |
set_font_bc(id, 1); |
| 126 |
set_font_writingmode(id, 0); |
| 127 |
set_font_identity(id, 0); |
| 128 |
/* set_font_encoding_bytes(id,1) */ /* ? */ |
| 129 |
set_font_subfont(id, 0); |
| 130 |
set_hyphen_char(id, '-'); |
| 131 |
set_skew_char(id, -1); |
| 132 |
/*tex vertical */ |
| 133 |
font_slant(id) = 0; |
| 134 |
/*tex normal width */ |
| 135 |
font_extend(id) = 1000; |
| 136 |
/*tex normal height */ |
| 137 |
font_squeeze(id) = 1000; |
| 138 |
font_width(id) = 0; |
| 139 |
font_mode(id) = 0; |
| 140 |
/*tex allocate eight values including 0 */ |
| 141 |
set_font_params(id, 7); |
| 142 |
for (k = 0; k <= 7; k++) { |
| 143 |
set_font_param(id, k, 0); |
| 144 |
} |
| 145 |
/*tex character info zero is reserved for |notdef|. The stack size 1, default item value 0. */ |
| 146 |
font_tables[id]->_characters = new_sa_tree(1, 1, sa_value); |
| 147 |
ci = xcalloc(1, sizeof(charinfo)); |
| 148 |
set_charinfo_name(ci, xstrdup(".notdef")); |
| 149 |
font_tables[id]->_charinfo = ci; |
| 150 |
font_tables[id]->_charinfo_size = 1; |
| 151 |
return id; |
| 152 |
} |
| 153 |
|
| 154 |
void font_malloc_charinfo(internal_font_number f, int num) |
| 155 |
{ |
| 156 |
int glyph = font_tables[f]->_charinfo_size; |
| 157 |
font_bytes += (int) (num * (int) sizeof(charinfo)); |
| 158 |
do_realloc(font_tables[f]->_charinfo, (unsigned) (glyph + num), charinfo); |
| 159 |
memset(&(font_tables[f]->_charinfo[glyph]), 0, (size_t) (num * (int) sizeof(charinfo))); |
| 160 |
font_tables[f]->_charinfo_size += num; |
| 161 |
} |
| 162 |
|
| 163 |
#define find_charinfo_id(f,c) (get_sa_item(font_tables[f]->_characters,c).int_value) |
| 164 |
|
| 165 |
charinfo *get_charinfo(internal_font_number f, int c) |
| 166 |
{ |
| 167 |
int glyph; |
| 168 |
charinfo *ci; |
| 169 |
if (proper_char_index(c)) { |
| 170 |
glyph = get_sa_item(font_tables[f]->_characters, c).int_value; |
| 171 |
if (!glyph) { |
| 172 |
sa_tree_item sa_value = { 0 }; |
| 173 |
int tglyph = ++font_tables[f]->_charinfo_count; |
| 174 |
if (tglyph >= font_tables[f]->_charinfo_size) { |
| 175 |
font_malloc_charinfo(f, 256); |
| 176 |
} |
| 177 |
font_tables[f]->_charinfo[tglyph].ef = 1000; |
| 178 |
sa_value.int_value = tglyph; |
| 179 |
/*tex 1 means global */ |
| 180 |
set_sa_item(font_tables[f]->_characters, c, sa_value, 1); |
| 181 |
glyph = tglyph; |
| 182 |
} |
| 183 |
return &(font_tables[f]->_charinfo[glyph]); |
| 184 |
} else if (c == left_boundarychar) { |
| 185 |
if (left_boundary(f) == NULL) { |
| 186 |
ci = xcalloc(1, sizeof(charinfo)); |
| 187 |
font_bytes += (int) sizeof(charinfo); |
| 188 |
set_left_boundary(f, ci); |
| 189 |
} |
| 190 |
return left_boundary(f); |
| 191 |
} else if (c == right_boundarychar) { |
| 192 |
if (right_boundary(f) == NULL) { |
| 193 |
ci = xcalloc(1, sizeof(charinfo)); |
| 194 |
font_bytes += (int) sizeof(charinfo); |
| 195 |
set_right_boundary(f, ci); |
| 196 |
} |
| 197 |
return right_boundary(f); |
| 198 |
} |
| 199 |
return &(font_tables[f]->_charinfo[0]); |
| 200 |
} |
| 201 |
|
| 202 |
static void set_charinfo(internal_font_number f, int c, charinfo * ci) |
| 203 |
{ |
| 204 |
int glyph; |
| 205 |
if (proper_char_index(c)) { |
| 206 |
glyph = get_sa_item(font_tables[f]->_characters, c).int_value; |
| 207 |
if (glyph) { |
| 208 |
font_tables[f]->_charinfo[glyph] = *ci; |
| 209 |
} else { |
| 210 |
normal_error("font","character insertion failed"); |
| 211 |
} |
| 212 |
} else if (c == left_boundarychar) { |
| 213 |
set_left_boundary(f, ci); |
| 214 |
} else if (c == right_boundarychar) { |
| 215 |
set_right_boundary(f, ci); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
charinfo *copy_charinfo(charinfo * ci) |
| 220 |
{ |
| 221 |
int x, k; |
| 222 |
kerninfo *kern; |
| 223 |
liginfo *lig; |
| 224 |
eight_bits *packet; |
| 225 |
charinfo *co = NULL; |
| 226 |
if (ci == NULL) |
| 227 |
return NULL; |
| 228 |
co = xmalloc(sizeof(charinfo)); |
| 229 |
memcpy(co, ci, sizeof(charinfo)); |
| 230 |
set_charinfo_used(co, false); |
| 231 |
co->name = NULL; |
| 232 |
co->tounicode = NULL; |
| 233 |
co->packets = NULL; |
| 234 |
co->ligatures = NULL; |
| 235 |
co->kerns = NULL; |
| 236 |
co->vert_variants = NULL; |
| 237 |
co->hor_variants = NULL; |
| 238 |
if (ci->name != NULL) { |
| 239 |
co->name = xstrdup(ci->name); |
| 240 |
} |
| 241 |
if (ci->tounicode != NULL) { |
| 242 |
co->tounicode = xstrdup(ci->tounicode); |
| 243 |
} |
| 244 |
/*tex Kerns */ |
| 245 |
if ((kern = get_charinfo_kerns(ci)) != NULL) { |
| 246 |
x = 0; |
| 247 |
while (!kern_end(kern[x])) { |
| 248 |
x++; |
| 249 |
} |
| 250 |
x++; |
| 251 |
co->kerns = xmalloc((unsigned) (x * (int) sizeof(kerninfo))); |
| 252 |
memcpy(co->kerns, ci->kerns, (size_t) (x * (int) sizeof(kerninfo))); |
| 253 |
} |
| 254 |
/*tex Ligatures */ |
| 255 |
if ((lig = get_charinfo_ligatures(ci)) != NULL) { |
| 256 |
x = 0; |
| 257 |
while (!lig_end(lig[x])) { |
| 258 |
x++; |
| 259 |
} |
| 260 |
x++; |
| 261 |
co->ligatures = xmalloc((unsigned) (x * (int) sizeof(liginfo))); |
| 262 |
memcpy(co->ligatures, ci->ligatures, |
| 263 |
(size_t) (x * (int) sizeof(liginfo))); |
| 264 |
} |
| 265 |
/*tex Packets */ |
| 266 |
if ((packet = get_charinfo_packets(ci)) != NULL) { |
| 267 |
x = vf_packet_bytes(ci); |
| 268 |
co->packets = xmalloc((unsigned) x); |
| 269 |
memcpy(co->packets, ci->packets, (size_t) x); |
| 270 |
} |
| 271 |
/*tex Horizontal and vertical extenders */ |
| 272 |
if (get_charinfo_vert_variants(ci) != NULL) { |
| 273 |
set_charinfo_vert_variants(co, copy_variants(get_charinfo_vert_variants(ci))); |
| 274 |
} |
| 275 |
if (get_charinfo_hor_variants(ci) != NULL) { |
| 276 |
set_charinfo_hor_variants(co, copy_variants(get_charinfo_hor_variants(ci))); |
| 277 |
} |
| 278 |
x = ci->top_left_math_kerns; |
| 279 |
co->top_left_math_kerns = x; |
| 280 |
if (x > 0) { |
| 281 |
co->top_left_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 282 |
for (k = 0; k < co->top_left_math_kerns; k++) { |
| 283 |
co->top_left_math_kern_array[(2 * k)] = ci->top_left_math_kern_array[(2 * k)]; |
| 284 |
co->top_left_math_kern_array[(2 * k) + 1] = ci->top_left_math_kern_array[(2 * k) + 1]; |
| 285 |
} |
| 286 |
} |
| 287 |
x = ci->bottom_left_math_kerns; |
| 288 |
co->bottom_left_math_kerns = x; |
| 289 |
if (x > 0) { |
| 290 |
co->bottom_left_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 291 |
for (k = 0; k < co->bottom_left_math_kerns; k++) { |
| 292 |
co->bottom_left_math_kern_array[(2 * k)] = ci->bottom_left_math_kern_array[(2 * k)]; |
| 293 |
co->bottom_left_math_kern_array[(2 * k) + 1] = ci->bottom_left_math_kern_array[(2 * k) + 1]; |
| 294 |
} |
| 295 |
} |
| 296 |
x = ci->top_right_math_kerns; |
| 297 |
co->top_right_math_kerns = x; |
| 298 |
if (x > 0) { |
| 299 |
co->top_right_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 300 |
for (k = 0; k < co->top_right_math_kerns; k++) { |
| 301 |
co->top_right_math_kern_array[(2 * k)] = ci->top_right_math_kern_array[(2 * k)]; |
| 302 |
co->top_right_math_kern_array[(2 * k) + 1] = ci->top_right_math_kern_array[(2 * k) + 1]; |
| 303 |
} |
| 304 |
} |
| 305 |
x = ci->bottom_right_math_kerns; |
| 306 |
co->bottom_right_math_kerns = x; |
| 307 |
if (x > 0) { |
| 308 |
co->bottom_right_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 309 |
for (k = 0; k < co->bottom_right_math_kerns; k++) { |
| 310 |
co->bottom_right_math_kern_array[(2 * k)] = ci->bottom_right_math_kern_array[(2 * k)]; |
| 311 |
co->bottom_right_math_kern_array[(2 * k) + 1] = ci->bottom_right_math_kern_array[(2 * k) + 1]; |
| 312 |
} |
| 313 |
} |
| 314 |
return co; |
| 315 |
} |
| 316 |
|
| 317 |
charinfo *char_info(internal_font_number f, int c) |
| 318 |
{ |
| 319 |
if (f > font_id_maxval) |
| 320 |
return 0; |
| 321 |
if (proper_char_index(c)) { |
| 322 |
register int glyph = (int) find_charinfo_id(f, c); |
| 323 |
return &(font_tables[f]->_charinfo[glyph]); |
| 324 |
} else if (c == left_boundarychar && left_boundary(f) != NULL) { |
| 325 |
return left_boundary(f); |
| 326 |
} else if (c == right_boundarychar && right_boundary(f) != NULL) { |
| 327 |
return right_boundary(f); |
| 328 |
} |
| 329 |
return &(font_tables[f]->_charinfo[0]); |
| 330 |
} |
| 331 |
|
| 332 |
scaled_whd get_charinfo_whd(internal_font_number f, int c) |
| 333 |
{ |
| 334 |
scaled_whd s; |
| 335 |
charinfo *i; |
| 336 |
i = char_info(f, c); |
| 337 |
s.wd = i->width; |
| 338 |
s.dp = i->depth; |
| 339 |
s.ht = i->height; |
| 340 |
return s; |
| 341 |
} |
| 342 |
|
| 343 |
int char_exists(internal_font_number f, int c) |
| 344 |
{ |
| 345 |
if (f > font_id_maxval) |
| 346 |
return 0; |
| 347 |
if (proper_char_index(c)) { |
| 348 |
return (int) find_charinfo_id(f, c); |
| 349 |
} else if ((c == left_boundarychar) && has_left_boundary(f)) { |
| 350 |
return 1; |
| 351 |
} else if ((c == right_boundarychar) && has_right_boundary(f)) { |
| 352 |
return 1; |
| 353 |
} |
| 354 |
return 0; |
| 355 |
} |
| 356 |
|
| 357 |
int lua_glyph_not_found_callback(internal_font_number f, int c) |
| 358 |
{ |
| 359 |
int callback_id; |
| 360 |
int ret = 0; |
| 361 |
int top, i; |
| 362 |
callback_id = callback_defined(glyph_not_found_callback); |
| 363 |
if (callback_id != 0) { |
| 364 |
top = lua_gettop(Luas); |
| 365 |
if (!get_callback(Luas, callback_id)) { |
| 366 |
lua_settop(Luas, top); |
| 367 |
return 0; |
| 368 |
} |
| 369 |
lua_pushinteger(Luas, f); |
| 370 |
lua_pushinteger(Luas, c); |
| 371 |
if ((i=lua_pcall(Luas, 2, 1, 0)) != 0) { |
| 372 |
formatted_warning ("glyph not found", "error: %s", lua_tostring(Luas, -1)); |
| 373 |
lua_settop(Luas, top); |
| 374 |
luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1)); |
| 375 |
} else { |
| 376 |
ret = lua_toboolean(Luas, -1); |
| 377 |
} |
| 378 |
lua_settop(Luas, top); |
| 379 |
} else { |
| 380 |
char_warning(f,c); |
| 381 |
} |
| 382 |
return ret; |
| 383 |
} |
| 384 |
|
| 385 |
extinfo *new_variant(int glyph, int startconnect, int endconnect, int advance, int repeater) |
| 386 |
{ |
| 387 |
extinfo *ext; |
| 388 |
ext = xmalloc(sizeof(extinfo)); |
| 389 |
ext->next = NULL; |
| 390 |
ext->glyph = glyph; |
| 391 |
ext->start_overlap = startconnect; |
| 392 |
ext->end_overlap = endconnect; |
| 393 |
ext->advance = advance; |
| 394 |
ext->extender = repeater; |
| 395 |
return ext; |
| 396 |
} |
| 397 |
|
| 398 |
static extinfo *copy_variant(extinfo * old) |
| 399 |
{ |
| 400 |
extinfo *ext; |
| 401 |
ext = xmalloc(sizeof(extinfo)); |
| 402 |
ext->next = NULL; |
| 403 |
ext->glyph = old->glyph; |
| 404 |
ext->start_overlap = old->start_overlap; |
| 405 |
ext->end_overlap = old->end_overlap; |
| 406 |
ext->advance = old->advance; |
| 407 |
ext->extender = old->extender; |
| 408 |
return ext; |
| 409 |
} |
| 410 |
|
| 411 |
static void dump_variant(extinfo * ext) |
| 412 |
{ |
| 413 |
dump_int(ext->glyph); |
| 414 |
dump_int(ext->start_overlap); |
| 415 |
dump_int(ext->end_overlap); |
| 416 |
dump_int(ext->advance); |
| 417 |
dump_int(ext->extender); |
| 418 |
return; |
| 419 |
} |
| 420 |
|
| 421 |
static extinfo *undump_variant(void) |
| 422 |
{ |
| 423 |
int x; |
| 424 |
extinfo *ext; |
| 425 |
undump_int(x); |
| 426 |
if (x == 0) |
| 427 |
return NULL; |
| 428 |
ext = xmalloc(sizeof(extinfo)); |
| 429 |
ext->next = NULL; |
| 430 |
ext->glyph = x; |
| 431 |
undump_int(x); |
| 432 |
ext->start_overlap = x; |
| 433 |
undump_int(x); |
| 434 |
ext->end_overlap = x; |
| 435 |
undump_int(x); |
| 436 |
ext->advance = x; |
| 437 |
undump_int(x); |
| 438 |
ext->extender = x; |
| 439 |
return ext; |
| 440 |
} |
| 441 |
|
| 442 |
void add_charinfo_vert_variant(charinfo * ci, extinfo * ext) |
| 443 |
{ |
| 444 |
if (ci->vert_variants == NULL) { |
| 445 |
ci->vert_variants = ext; |
| 446 |
} else { |
| 447 |
extinfo *lst = ci->vert_variants; |
| 448 |
while (lst->next != NULL) |
| 449 |
lst = lst->next; |
| 450 |
lst->next = ext; |
| 451 |
} |
| 452 |
|
| 453 |
} |
| 454 |
|
| 455 |
void add_charinfo_hor_variant(charinfo * ci, extinfo * ext) |
| 456 |
{ |
| 457 |
if (ci->hor_variants == NULL) { |
| 458 |
ci->hor_variants = ext; |
| 459 |
} else { |
| 460 |
extinfo *lst = ci->hor_variants; |
| 461 |
while (lst->next != NULL) |
| 462 |
lst = lst->next; |
| 463 |
lst->next = ext; |
| 464 |
} |
| 465 |
|
| 466 |
} |
| 467 |
|
| 468 |
extinfo *copy_variants(extinfo * o) |
| 469 |
{ |
| 470 |
extinfo *c, *t = NULL, *h = NULL; |
| 471 |
while (o != NULL) { |
| 472 |
c = copy_variant(o); |
| 473 |
if (h == null) |
| 474 |
h = c; |
| 475 |
else |
| 476 |
t->next = c; |
| 477 |
t = c; |
| 478 |
o = o->next; |
| 479 |
} |
| 480 |
|
| 481 |
return h; |
| 482 |
} |
| 483 |
|
| 484 |
static void dump_charinfo_variants(extinfo * o) |
| 485 |
{ |
| 486 |
while (o != NULL) { |
| 487 |
dump_variant(o); |
| 488 |
o = o->next; |
| 489 |
} |
| 490 |
dump_int(0); |
| 491 |
return; |
| 492 |
} |
| 493 |
|
| 494 |
static extinfo *undump_charinfo_variants(void) |
| 495 |
{ |
| 496 |
extinfo *c, *t = NULL, *h = NULL; |
| 497 |
c = undump_variant(); |
| 498 |
while (c != NULL) { |
| 499 |
if (h == null) |
| 500 |
h = c; |
| 501 |
else |
| 502 |
t->next = c; |
| 503 |
t = c; |
| 504 |
c = undump_variant(); |
| 505 |
} |
| 506 |
return h; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
/*tex |
| 511 |
|
| 512 |
Note that many more small things like this are implemented as macros in the |
| 513 |
header file. |
| 514 |
*/ |
| 515 |
|
| 516 |
void set_charinfo_width(charinfo * ci, scaled val) |
| 517 |
{ |
| 518 |
ci->width = val; |
| 519 |
} |
| 520 |
|
| 521 |
void set_charinfo_height(charinfo * ci, scaled val) |
| 522 |
{ |
| 523 |
ci->height = val; |
| 524 |
} |
| 525 |
|
| 526 |
void set_charinfo_depth(charinfo * ci, scaled val) |
| 527 |
{ |
| 528 |
ci->depth = val; |
| 529 |
} |
| 530 |
|
| 531 |
void set_charinfo_italic(charinfo * ci, scaled val) |
| 532 |
{ |
| 533 |
ci->italic = val; |
| 534 |
} |
| 535 |
|
| 536 |
void set_charinfo_vert_italic(charinfo * ci, scaled val) |
| 537 |
{ |
| 538 |
ci->vert_italic = val; |
| 539 |
} |
| 540 |
|
| 541 |
void set_charinfo_top_accent(charinfo * ci, scaled val) |
| 542 |
{ |
| 543 |
ci->top_accent = val; |
| 544 |
} |
| 545 |
|
| 546 |
void set_charinfo_bot_accent(charinfo * ci, scaled val) |
| 547 |
{ |
| 548 |
ci->bot_accent = val; |
| 549 |
} |
| 550 |
|
| 551 |
void set_charinfo_tag(charinfo * ci, scaled val) |
| 552 |
{ |
| 553 |
ci->tag = (char) val; |
| 554 |
} |
| 555 |
|
| 556 |
void set_charinfo_remainder(charinfo * ci, scaled val) |
| 557 |
{ |
| 558 |
ci->remainder = val; |
| 559 |
} |
| 560 |
|
| 561 |
void set_charinfo_used(charinfo * ci, scaled val) |
| 562 |
{ |
| 563 |
ci->used = (char) val; |
| 564 |
} |
| 565 |
|
| 566 |
void set_charinfo_index(charinfo * ci, scaled val) |
| 567 |
{ |
| 568 |
ci->index = (unsigned short) val; |
| 569 |
} |
| 570 |
|
| 571 |
void set_charinfo_name(charinfo * ci, char *val) |
| 572 |
{ |
| 573 |
xfree(ci->name); |
| 574 |
ci->name = val; |
| 575 |
} |
| 576 |
|
| 577 |
void set_charinfo_tounicode(charinfo * ci, char *val) |
| 578 |
{ |
| 579 |
xfree(ci->tounicode); |
| 580 |
ci->tounicode = val; |
| 581 |
} |
| 582 |
|
| 583 |
void set_charinfo_ligatures(charinfo * ci, liginfo * val) |
| 584 |
{ |
| 585 |
dxfree(ci->ligatures, val); |
| 586 |
} |
| 587 |
|
| 588 |
void set_charinfo_kerns(charinfo * ci, kerninfo * val) |
| 589 |
{ |
| 590 |
dxfree(ci->kerns, val); |
| 591 |
} |
| 592 |
|
| 593 |
void set_charinfo_packets(charinfo * ci, eight_bits * val) |
| 594 |
{ |
| 595 |
dxfree(ci->packets, val); |
| 596 |
} |
| 597 |
|
| 598 |
void set_charinfo_ef(charinfo * ci, scaled val) |
| 599 |
{ |
| 600 |
ci->ef = val; |
| 601 |
} |
| 602 |
|
| 603 |
void set_charinfo_lp(charinfo * ci, scaled val) |
| 604 |
{ |
| 605 |
ci->lp = val; |
| 606 |
} |
| 607 |
|
| 608 |
void set_charinfo_rp(charinfo * ci, scaled val) |
| 609 |
{ |
| 610 |
ci->rp = val; |
| 611 |
} |
| 612 |
|
| 613 |
void set_charinfo_vert_variants(charinfo * ci, extinfo * ext) |
| 614 |
{ |
| 615 |
extinfo *c, *lst; |
| 616 |
if (ci->vert_variants != NULL) { |
| 617 |
lst = ci->vert_variants; |
| 618 |
while (lst != NULL) { |
| 619 |
c = lst->next; |
| 620 |
free(lst); |
| 621 |
lst = c; |
| 622 |
} |
| 623 |
} |
| 624 |
ci->vert_variants = ext; |
| 625 |
} |
| 626 |
|
| 627 |
void set_charinfo_hor_variants(charinfo * ci, extinfo * ext) |
| 628 |
{ |
| 629 |
extinfo *c, *lst; |
| 630 |
if (ci->hor_variants != NULL) { |
| 631 |
lst = ci->hor_variants; |
| 632 |
while (lst != NULL) { |
| 633 |
c = lst->next; |
| 634 |
free(lst); |
| 635 |
lst = c; |
| 636 |
} |
| 637 |
} |
| 638 |
ci->hor_variants = ext; |
| 639 |
|
| 640 |
} |
| 641 |
|
| 642 |
int get_charinfo_math_kerns(charinfo * ci, int id) |
| 643 |
{ |
| 644 |
/*tex All callers check for |result>0|. */ |
| 645 |
int k = 0; |
| 646 |
if (id == top_left_kern) { |
| 647 |
k = ci->top_left_math_kerns; |
| 648 |
} else if (id == bottom_left_kern) { |
| 649 |
k = ci->bottom_left_math_kerns; |
| 650 |
} else if (id == top_right_kern) { |
| 651 |
k = ci->top_right_math_kerns; |
| 652 |
} else if (id == bottom_right_kern) { |
| 653 |
k = ci->bottom_right_math_kerns; |
| 654 |
} else { |
| 655 |
confusion("get_charinfo_math_kerns"); |
| 656 |
} |
| 657 |
return k; |
| 658 |
} |
| 659 |
|
| 660 |
void add_charinfo_math_kern(charinfo * ci, int id, scaled ht, scaled krn) |
| 661 |
{ |
| 662 |
int k; |
| 663 |
if (id == top_left_kern) { |
| 664 |
k = ci->top_left_math_kerns; |
| 665 |
do_realloc(ci->top_left_math_kern_array, ((k + 1) * 2), sizeof(scaled)); |
| 666 |
ci->top_left_math_kern_array[(2 * (k))] = ht; |
| 667 |
ci->top_left_math_kern_array[((2 * (k)) + 1)] = krn; |
| 668 |
ci->top_left_math_kerns++; |
| 669 |
} else if (id == bottom_left_kern) { |
| 670 |
k = ci->bottom_left_math_kerns; |
| 671 |
do_realloc(ci->bottom_left_math_kern_array, ((k + 1) * 2), sizeof(scaled)); |
| 672 |
ci->bottom_left_math_kern_array[(2 * (k))] = ht; |
| 673 |
ci->bottom_left_math_kern_array[(2 * (k)) + 1] = krn; |
| 674 |
ci->bottom_left_math_kerns++; |
| 675 |
} else if (id == top_right_kern) { |
| 676 |
k = ci->top_right_math_kerns; |
| 677 |
do_realloc(ci->top_right_math_kern_array, ((k + 1) * 2), sizeof(scaled)); |
| 678 |
ci->top_right_math_kern_array[(2 * (k))] = ht; |
| 679 |
ci->top_right_math_kern_array[(2 * (k)) + 1] = krn; |
| 680 |
ci->top_right_math_kerns++; |
| 681 |
} else if (id == bottom_right_kern) { |
| 682 |
k = ci->bottom_right_math_kerns; |
| 683 |
do_realloc(ci->bottom_right_math_kern_array, ((k + 1) * 2), sizeof(scaled)); |
| 684 |
ci->bottom_right_math_kern_array[(2 * (k))] = ht; |
| 685 |
ci->bottom_right_math_kern_array[(2 * (k)) + 1] = krn; |
| 686 |
ci->bottom_right_math_kerns++; |
| 687 |
} else { |
| 688 |
confusion("add_charinfo_math_kern"); |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
static void dump_math_kerns(charinfo * ci) |
| 693 |
{ |
| 694 |
int k, l; |
| 695 |
l = ci->top_left_math_kerns; |
| 696 |
dump_int(l); |
| 697 |
for (k = 0; k < l; k++) { |
| 698 |
dump_int(ci->top_left_math_kern_array[(2 * k)]); |
| 699 |
dump_int(ci->top_left_math_kern_array[(2 * k) + 1]); |
| 700 |
} |
| 701 |
l = ci->bottom_left_math_kerns; |
| 702 |
dump_int(l); |
| 703 |
for (k = 0; k < l; k++) { |
| 704 |
dump_int(ci->bottom_left_math_kern_array[(2 * k)]); |
| 705 |
dump_int(ci->bottom_left_math_kern_array[(2 * k) + 1]); |
| 706 |
} |
| 707 |
l = ci->top_right_math_kerns; |
| 708 |
dump_int(l); |
| 709 |
for (k = 0; k < l; k++) { |
| 710 |
dump_int(ci->top_right_math_kern_array[(2 * k)]); |
| 711 |
dump_int(ci->top_right_math_kern_array[(2 * k) + 1]); |
| 712 |
} |
| 713 |
l = ci->bottom_right_math_kerns; |
| 714 |
dump_int(l); |
| 715 |
for (k = 0; k < l; k++) { |
| 716 |
dump_int(ci->bottom_right_math_kern_array[(2 * k)]); |
| 717 |
dump_int(ci->bottom_right_math_kern_array[(2 * k) + 1]); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
static void undump_math_kerns(charinfo * ci) |
| 722 |
{ |
| 723 |
int k, x; |
| 724 |
undump_int(x); |
| 725 |
ci->top_left_math_kerns = x; |
| 726 |
if (x > 0) |
| 727 |
ci->top_left_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 728 |
for (k = 0; k < ci->top_left_math_kerns; k++) { |
| 729 |
undump_int(x); |
| 730 |
ci->top_left_math_kern_array[(2 * k)] = (scaled) x; |
| 731 |
undump_int(x); |
| 732 |
ci->top_left_math_kern_array[(2 * k) + 1] = (scaled) x; |
| 733 |
} |
| 734 |
undump_int(x); |
| 735 |
ci->bottom_left_math_kerns = x; |
| 736 |
if (x > 0) |
| 737 |
ci->bottom_left_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 738 |
for (k = 0; k < ci->bottom_left_math_kerns; k++) { |
| 739 |
undump_int(x); |
| 740 |
ci->bottom_left_math_kern_array[(2 * k)] = (scaled) x; |
| 741 |
undump_int(x); |
| 742 |
ci->bottom_left_math_kern_array[(2 * k) + 1] = (scaled) x; |
| 743 |
} |
| 744 |
undump_int(x); |
| 745 |
ci->top_right_math_kerns = x; |
| 746 |
if (x > 0) |
| 747 |
ci->top_right_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 748 |
for (k = 0; k < ci->top_right_math_kerns; k++) { |
| 749 |
undump_int(x); |
| 750 |
ci->top_right_math_kern_array[(2 * k)] = (scaled) x; |
| 751 |
undump_int(x); |
| 752 |
ci->top_right_math_kern_array[(2 * k) + 1] = (scaled) x; |
| 753 |
} |
| 754 |
undump_int(x); |
| 755 |
ci->bottom_right_math_kerns = x; |
| 756 |
if (x > 0) |
| 757 |
ci->bottom_right_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); |
| 758 |
for (k = 0; k < ci->bottom_right_math_kerns; k++) { |
| 759 |
undump_int(x); |
| 760 |
ci->bottom_right_math_kern_array[(2 * k)] = (scaled) x; |
| 761 |
undump_int(x); |
| 762 |
ci->bottom_right_math_kern_array[(2 * k) + 1] = (scaled) x; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
/*tex |
| 767 |
|
| 768 |
In TeX, extensibles were fairly simple things. This function squeezes a TFM |
| 769 |
extensible into the vertical extender structures. |advance==0| is a special |
| 770 |
case for TFM fonts, because finding the proper advance width during tfm |
| 771 |
reading can be tricky. |
| 772 |
|
| 773 |
A small complication arises if |rep| is the only non-zero: it needs to be |
| 774 |
doubled as a non-repeatable to avoid mayhem. |
| 775 |
|
| 776 |
*/ |
| 777 |
|
| 778 |
void set_charinfo_extensible(charinfo * ci, int top, int bot, int mid, int rep) |
| 779 |
{ |
| 780 |
extinfo *ext; |
| 781 |
/*tex Clear old data: */ |
| 782 |
set_charinfo_vert_variants(ci, NULL); |
| 783 |
if (bot == 0 && top == 0 && mid == 0 && rep != 0) { |
| 784 |
ext = new_variant(rep, 0, 0, 0, EXT_NORMAL); |
| 785 |
add_charinfo_vert_variant(ci, ext); |
| 786 |
ext = new_variant(rep, 0, 0, 0, EXT_REPEAT); |
| 787 |
add_charinfo_vert_variant(ci, ext); |
| 788 |
return; |
| 789 |
} |
| 790 |
if (bot != 0) { |
| 791 |
ext = new_variant(bot, 0, 0, 0, EXT_NORMAL); |
| 792 |
add_charinfo_vert_variant(ci, ext); |
| 793 |
} |
| 794 |
if (rep != 0) { |
| 795 |
ext = new_variant(rep, 0, 0, 0, EXT_REPEAT); |
| 796 |
add_charinfo_vert_variant(ci, ext); |
| 797 |
} |
| 798 |
if (mid != 0) { |
| 799 |
ext = new_variant(mid, 0, 0, 0, EXT_NORMAL); |
| 800 |
add_charinfo_vert_variant(ci, ext); |
| 801 |
if (rep != 0) { |
| 802 |
ext = new_variant(rep, 0, 0, 0, EXT_REPEAT); |
| 803 |
add_charinfo_vert_variant(ci, ext); |
| 804 |
} |
| 805 |
} |
| 806 |
if (top != 0) { |
| 807 |
ext = new_variant(top, 0, 0, 0, EXT_NORMAL); |
| 808 |
add_charinfo_vert_variant(ci, ext); |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
/*tex |
| 813 |
|
| 814 |
Note that many more simple things like this are implemented as macros in the |
| 815 |
header file. |
| 816 |
|
| 817 |
*/ |
| 818 |
|
| 819 |
scaled get_charinfo_width(charinfo * ci) |
| 820 |
{ |
| 821 |
return ci->width; |
| 822 |
} |
| 823 |
|
| 824 |
scaled get_charinfo_height(charinfo * ci) |
| 825 |
{ |
| 826 |
return ci->height; |
| 827 |
} |
| 828 |
|
| 829 |
scaled get_charinfo_depth(charinfo * ci) |
| 830 |
{ |
| 831 |
return ci->depth; |
| 832 |
} |
| 833 |
|
| 834 |
scaled get_charinfo_italic(charinfo * ci) |
| 835 |
{ |
| 836 |
return ci->italic; |
| 837 |
} |
| 838 |
|
| 839 |
scaled get_charinfo_vert_italic(charinfo * ci) |
| 840 |
{ |
| 841 |
return ci->vert_italic; |
| 842 |
} |
| 843 |
|
| 844 |
scaled get_charinfo_top_accent(charinfo * ci) |
| 845 |
{ |
| 846 |
return ci->top_accent; |
| 847 |
} |
| 848 |
|
| 849 |
scaled get_charinfo_bot_accent(charinfo * ci) |
| 850 |
{ |
| 851 |
return ci->bot_accent; |
| 852 |
} |
| 853 |
|
| 854 |
char get_charinfo_tag(charinfo * ci) |
| 855 |
{ |
| 856 |
return ci->tag; |
| 857 |
} |
| 858 |
|
| 859 |
int get_charinfo_remainder(charinfo * ci) |
| 860 |
{ |
| 861 |
return ci->remainder; |
| 862 |
} |
| 863 |
|
| 864 |
char get_charinfo_used(charinfo * ci) |
| 865 |
{ |
| 866 |
return ci->used; |
| 867 |
} |
| 868 |
|
| 869 |
int get_charinfo_index(charinfo * ci) |
| 870 |
{ |
| 871 |
return ci->index; |
| 872 |
} |
| 873 |
|
| 874 |
char *get_charinfo_name(charinfo * ci) |
| 875 |
{ |
| 876 |
return ci->name; |
| 877 |
} |
| 878 |
|
| 879 |
char *get_charinfo_tounicode(charinfo * ci) |
| 880 |
{ |
| 881 |
return ci->tounicode; |
| 882 |
} |
| 883 |
|
| 884 |
liginfo *get_charinfo_ligatures(charinfo * ci) |
| 885 |
{ |
| 886 |
return ci->ligatures; |
| 887 |
} |
| 888 |
|
| 889 |
kerninfo *get_charinfo_kerns(charinfo * ci) |
| 890 |
{ |
| 891 |
return ci->kerns; |
| 892 |
} |
| 893 |
|
| 894 |
eight_bits *get_charinfo_packets(charinfo * ci) |
| 895 |
{ |
| 896 |
return ci->packets; |
| 897 |
} |
| 898 |
|
| 899 |
int get_charinfo_ef(charinfo * ci) |
| 900 |
{ |
| 901 |
return ci->ef; |
| 902 |
} |
| 903 |
|
| 904 |
int get_charinfo_rp(charinfo * ci) |
| 905 |
{ |
| 906 |
return ci->rp; |
| 907 |
} |
| 908 |
|
| 909 |
int get_charinfo_lp(charinfo * ci) |
| 910 |
{ |
| 911 |
return ci->lp; |
| 912 |
} |
| 913 |
|
| 914 |
extinfo *get_charinfo_vert_variants(charinfo * ci) |
| 915 |
{ |
| 916 |
extinfo *w = NULL; |
| 917 |
if (ci->vert_variants != NULL) |
| 918 |
w = ci->vert_variants; |
| 919 |
return w; |
| 920 |
} |
| 921 |
|
| 922 |
extinfo *get_charinfo_hor_variants(charinfo * ci) |
| 923 |
{ |
| 924 |
extinfo *w = NULL; |
| 925 |
if (ci->hor_variants != NULL) |
| 926 |
w = ci->hor_variants; |
| 927 |
return w; |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
scaled char_width(internal_font_number f, int c) |
| 932 |
{ |
| 933 |
charinfo *ci = char_info(f, c); |
| 934 |
scaled w = get_charinfo_width(ci); |
| 935 |
return w; |
| 936 |
} |
| 937 |
|
| 938 |
scaled calc_char_width(internal_font_number f, int c, int ex) |
| 939 |
{ |
| 940 |
charinfo *ci = char_info(f, c); |
| 941 |
scaled w = get_charinfo_width(ci); |
| 942 |
if (ex != 0) |
| 943 |
w = round_xn_over_d(w, 1000 + ex, 1000); |
| 944 |
return w; |
| 945 |
} |
| 946 |
|
| 947 |
scaled char_depth(internal_font_number f, int c) |
| 948 |
{ |
| 949 |
charinfo *ci = char_info(f, c); |
| 950 |
scaled d = get_charinfo_depth(ci); |
| 951 |
return d; |
| 952 |
} |
| 953 |
|
| 954 |
scaled char_height(internal_font_number f, int c) |
| 955 |
{ |
| 956 |
charinfo *ci = char_info(f, c); |
| 957 |
scaled h = get_charinfo_height(ci); |
| 958 |
return h; |
| 959 |
} |
| 960 |
|
| 961 |
scaled char_italic(internal_font_number f, int c) |
| 962 |
{ |
| 963 |
charinfo *ci = char_info(f, c); |
| 964 |
scaled i = get_charinfo_italic(ci); |
| 965 |
return i; |
| 966 |
} |
| 967 |
|
| 968 |
scaled char_vert_italic(internal_font_number f, int c) |
| 969 |
{ |
| 970 |
charinfo *ci = char_info(f, c); |
| 971 |
scaled i = get_charinfo_vert_italic(ci); |
| 972 |
return i; |
| 973 |
} |
| 974 |
|
| 975 |
scaled char_top_accent(internal_font_number f, int c) |
| 976 |
{ |
| 977 |
charinfo *ci = char_info(f, c); |
| 978 |
return get_charinfo_top_accent(ci); |
| 979 |
} |
| 980 |
|
| 981 |
scaled char_bot_accent(internal_font_number f, int c) |
| 982 |
{ |
| 983 |
charinfo *ci = char_info(f, c); |
| 984 |
return get_charinfo_bot_accent(ci); |
| 985 |
} |
| 986 |
|
| 987 |
int char_remainder(internal_font_number f, int c) |
| 988 |
{ |
| 989 |
charinfo *ci = char_info(f, c); |
| 990 |
return get_charinfo_remainder(ci); |
| 991 |
} |
| 992 |
|
| 993 |
char char_tag(internal_font_number f, int c) |
| 994 |
{ |
| 995 |
charinfo *ci = char_info(f, c); |
| 996 |
return get_charinfo_tag(ci); |
| 997 |
} |
| 998 |
|
| 999 |
char char_used(internal_font_number f, int c) |
| 1000 |
{ |
| 1001 |
charinfo *ci = char_info(f, c); |
| 1002 |
return get_charinfo_used(ci); |
| 1003 |
} |
| 1004 |
|
| 1005 |
char *char_name(internal_font_number f, int c) |
| 1006 |
{ |
| 1007 |
charinfo *ci = char_info(f, c); |
| 1008 |
return get_charinfo_name(ci); |
| 1009 |
} |
| 1010 |
|
| 1011 |
int char_index(internal_font_number f, int c) |
| 1012 |
{ |
| 1013 |
charinfo *ci = char_info(f, c); |
| 1014 |
return get_charinfo_index(ci); |
| 1015 |
} |
| 1016 |
|
| 1017 |
liginfo *char_ligatures(internal_font_number f, int c) |
| 1018 |
{ |
| 1019 |
charinfo *ci = char_info(f, c); |
| 1020 |
return get_charinfo_ligatures(ci); |
| 1021 |
} |
| 1022 |
|
| 1023 |
kerninfo *char_kerns(internal_font_number f, int c) |
| 1024 |
{ |
| 1025 |
charinfo *ci = char_info(f, c); |
| 1026 |
return get_charinfo_kerns(ci); |
| 1027 |
} |
| 1028 |
|
| 1029 |
eight_bits *char_packets(internal_font_number f, int c) |
| 1030 |
{ |
| 1031 |
charinfo *ci = char_info(f, c); |
| 1032 |
return get_charinfo_packets(ci); |
| 1033 |
} |
| 1034 |
|
| 1035 |
void set_font_params(internal_font_number f, int b) |
| 1036 |
{ |
| 1037 |
int i; |
| 1038 |
i = font_params(f); |
| 1039 |
if (i != b) { |
| 1040 |
font_bytes += (int) ((b - (int) font_params(f) + 1) * (int) sizeof(scaled)); |
| 1041 |
do_realloc(param_base(f), (b + 2), int); |
| 1042 |
font_params(f) = b; |
| 1043 |
if (b > i) { |
| 1044 |
while (i < b) { |
| 1045 |
font_param(f, ++i) = 0; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
void set_font_math_params(internal_font_number f, int b) |
| 1052 |
{ |
| 1053 |
int i; |
| 1054 |
i = font_math_params(f); |
| 1055 |
if (i != b) { |
| 1056 |
font_bytes += ((b - (int) font_math_params(f) + 1) * (int) sizeof(scaled)); |
| 1057 |
do_realloc(math_param_base(f), (b + 2), int); |
| 1058 |
font_math_params(f) = b; |
| 1059 |
if (b > i) { |
| 1060 |
while (i < b) { |
| 1061 |
font_math_param(f,++i) = undefined_math_parameter; |
| 1062 |
} |
| 1063 |
} |
| 1064 |
} |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
int copy_font(int f) |
| 1069 |
{ |
| 1070 |
int i, ci_cnt, ci_size; |
| 1071 |
charinfo *ci; |
| 1072 |
int k = new_font(); |
| 1073 |
{ |
| 1074 |
ci = font_tables[k]->_charinfo; |
| 1075 |
ci_cnt = font_tables[k]->_charinfo_count; |
| 1076 |
ci_size = font_tables[k]->_charinfo_size; |
| 1077 |
memcpy(font_tables[k], font_tables[f], sizeof(texfont)); |
| 1078 |
font_tables[k]->_charinfo = ci; |
| 1079 |
font_tables[k]->_charinfo_count = ci_cnt; |
| 1080 |
font_tables[k]->_charinfo_size = ci_size; |
| 1081 |
} |
| 1082 |
font_malloc_charinfo(k, font_tables[f]->_charinfo_count); |
| 1083 |
set_font_cache_id(k, 0); |
| 1084 |
set_font_used(k, 0); |
| 1085 |
set_font_touched(k, 0); |
| 1086 |
font_tables[k]->_font_name = NULL; |
| 1087 |
font_tables[k]->_font_filename = NULL; |
| 1088 |
font_tables[k]->_font_fullname = NULL; |
| 1089 |
font_tables[k]->_font_psname = NULL; |
| 1090 |
font_tables[k]->_font_encodingname = NULL; |
| 1091 |
font_tables[k]->_font_area = NULL; |
| 1092 |
font_tables[k]->_font_cidregistry = NULL; |
| 1093 |
font_tables[k]->_font_cidordering = NULL; |
| 1094 |
font_tables[k]->_left_boundary = NULL; |
| 1095 |
font_tables[k]->_right_boundary = NULL; |
| 1096 |
set_font_name(k, xstrdup(font_name(f))); |
| 1097 |
if (font_filename(f) != NULL) |
| 1098 |
set_font_filename(k, xstrdup(font_filename(f))); |
| 1099 |
if (font_fullname(f) != NULL) |
| 1100 |
set_font_fullname(k, xstrdup(font_fullname(f))); |
| 1101 |
if (font_psname(f) != NULL) |
| 1102 |
set_font_psname(k, xstrdup(font_psname(f))); |
| 1103 |
if (font_encodingname(f) != NULL) |
| 1104 |
set_font_encodingname(k, xstrdup(font_encodingname(f))); |
| 1105 |
if (font_area(f) != NULL) |
| 1106 |
set_font_area(k, xstrdup(font_area(f))); |
| 1107 |
if (font_cidregistry(f) != NULL) |
| 1108 |
set_font_cidregistry(k, xstrdup(font_cidregistry(f))); |
| 1109 |
if (font_cidordering(f) != NULL) |
| 1110 |
set_font_cidordering(k, xstrdup(font_cidordering(f))); |
| 1111 |
set_font_encodingbytes(k,font_encodingbytes(f)); |
| 1112 |
set_font_subfont(k,font_subfont(f)); |
| 1113 |
i = (int) (sizeof(*param_base(f)) * (unsigned) (font_params(f)+1)); |
| 1114 |
font_bytes += i; |
| 1115 |
param_base(k) = xmalloc((unsigned) (i+1)); |
| 1116 |
memcpy(param_base(k), param_base(f), (size_t) (i)); |
| 1117 |
if (font_math_params(f) > 0) { |
| 1118 |
i = (int) (sizeof(*math_param_base(f)) * |
| 1119 |
(unsigned) font_math_params(f)); |
| 1120 |
font_bytes += i; |
| 1121 |
math_param_base(k) = xmalloc((unsigned) i); |
| 1122 |
memcpy(math_param_base(k), math_param_base(f), (size_t) i); |
| 1123 |
} |
| 1124 |
for (i = 0; i <= font_tables[f]->_charinfo_count; i++) { |
| 1125 |
ci = copy_charinfo(&font_tables[f]->_charinfo[i]); |
| 1126 |
font_tables[k]->_charinfo[i] = *ci; |
| 1127 |
} |
| 1128 |
if (left_boundary(f) != NULL) { |
| 1129 |
ci = copy_charinfo(left_boundary(f)); |
| 1130 |
set_charinfo(k, left_boundarychar, ci); |
| 1131 |
} |
| 1132 |
if (right_boundary(f) != NULL) { |
| 1133 |
ci = copy_charinfo(right_boundary(f)); |
| 1134 |
set_charinfo(k, right_boundarychar, ci); |
| 1135 |
} |
| 1136 |
/*tex Not updated yet: */ |
| 1137 |
font_tables[k]->_charinfo_count = font_tables[f]->_charinfo_count; |
| 1138 |
return k; |
| 1139 |
} |
| 1140 |
|
| 1141 |
void delete_font(int f) |
| 1142 |
{ |
| 1143 |
int i; |
| 1144 |
charinfo *co; |
| 1145 |
assert(f > 0); |
| 1146 |
if (font_tables[f] != NULL) { |
| 1147 |
set_font_name(f, NULL); |
| 1148 |
set_font_filename(f, NULL); |
| 1149 |
set_font_fullname(f, NULL); |
| 1150 |
set_font_psname(f, NULL); |
| 1151 |
set_font_encodingname(f, NULL); |
| 1152 |
set_font_area(f, NULL); |
| 1153 |
set_font_cidregistry(f, NULL); |
| 1154 |
set_font_cidordering(f, NULL); |
| 1155 |
set_left_boundary(f, NULL); |
| 1156 |
set_right_boundary(f, NULL); |
| 1157 |
for (i = font_bc(f); i <= font_ec(f); i++) { |
| 1158 |
if (quick_char_exists(f, i)) { |
| 1159 |
co = char_info(f, i); |
| 1160 |
set_charinfo_name(co, NULL); |
| 1161 |
set_charinfo_tounicode(co, NULL); |
| 1162 |
set_charinfo_packets(co, NULL); |
| 1163 |
set_charinfo_ligatures(co, NULL); |
| 1164 |
set_charinfo_kerns(co, NULL); |
| 1165 |
set_charinfo_vert_variants(co, NULL); |
| 1166 |
set_charinfo_hor_variants(co, NULL); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
/*tex free |notdef| */ |
| 1170 |
set_charinfo_name(font_tables[f]->_charinfo + 0, NULL); |
| 1171 |
free(font_tables[f]->_charinfo); |
| 1172 |
destroy_sa_tree(font_tables[f]->_characters); |
| 1173 |
free(param_base(f)); |
| 1174 |
if (math_param_base(f) != NULL) |
| 1175 |
free(math_param_base(f)); |
| 1176 |
free(font_tables[f]); |
| 1177 |
font_tables[f] = NULL; |
| 1178 |
if (font_id_maxval == f) { |
| 1179 |
font_id_maxval--; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
} |
| 1183 |
|
| 1184 |
void create_null_font(void) |
| 1185 |
{ |
| 1186 |
int i = new_font(); |
| 1187 |
assert(i == 0); |
| 1188 |
set_font_name(i, xstrdup("nullfont")); |
| 1189 |
set_font_area(i, xstrdup("")); |
| 1190 |
set_font_touched(i, 1); |
| 1191 |
} |
| 1192 |
|
| 1193 |
boolean is_valid_font(int id) |
| 1194 |
{ |
| 1195 |
int ret = 0; |
| 1196 |
if (id >= 0 && id <= font_id_maxval && font_tables[id] != NULL) |
| 1197 |
ret = 1; |
| 1198 |
return ret; |
| 1199 |
} |
| 1200 |
|
| 1201 |
boolean cmp_font_area(int id, str_number t) |
| 1202 |
{ |
| 1203 |
char *tt = NULL; |
| 1204 |
char *tid = font_area(id); |
| 1205 |
if (t == 0) { |
| 1206 |
if (tid == NULL || strlen(tid) == 0) |
| 1207 |
return 1; |
| 1208 |
else |
| 1209 |
return 0; |
| 1210 |
} |
| 1211 |
tt = makecstring(t); |
| 1212 |
if ((tt == NULL || strlen(tt) == 0) && (tid == NULL || strlen(tid) == 0)) |
| 1213 |
return 1; |
| 1214 |
if (tt == NULL || strcmp(tid, tt) != 0) |
| 1215 |
return 0; |
| 1216 |
free(tt); |
| 1217 |
return 1; |
| 1218 |
} |
| 1219 |
|
| 1220 |
/*tex |
| 1221 |
|
| 1222 |
Here come some subroutines to deal with expanded fonts for HZ-algorithm. |
| 1223 |
returning 1 means that they are identical. |
| 1224 |
|
| 1225 |
*/ |
| 1226 |
|
| 1227 |
static boolean cmp_font_name(int id, char *tt) |
| 1228 |
{ |
| 1229 |
char *tid; |
| 1230 |
if (!is_valid_font(id)) |
| 1231 |
return 0; |
| 1232 |
tid = font_name(id); |
| 1233 |
if (tt == NULL && tid == NULL) |
| 1234 |
return 1; |
| 1235 |
if (tt == NULL || tid == NULL || strcmp(tid, tt) != 0) |
| 1236 |
return 0; |
| 1237 |
return 1; |
| 1238 |
} |
| 1239 |
|
| 1240 |
int test_no_ligatures(internal_font_number f) |
| 1241 |
{ |
| 1242 |
int c; |
| 1243 |
for (c = font_bc(f); c <= font_ec(f); c++) { |
| 1244 |
if (has_lig(f, c)) |
| 1245 |
return 0; |
| 1246 |
} |
| 1247 |
return 1; |
| 1248 |
} |
| 1249 |
|
| 1250 |
int get_tag_code(internal_font_number f, int c) |
| 1251 |
{ |
| 1252 |
small_number i; |
| 1253 |
if (char_exists(f, c)) { |
| 1254 |
i = char_tag(f, c); |
| 1255 |
if (i == lig_tag) |
| 1256 |
return 1; |
| 1257 |
else if (i == list_tag) |
| 1258 |
return 2; |
| 1259 |
else if (i == ext_tag) |
| 1260 |
return 4; |
| 1261 |
else |
| 1262 |
return 0; |
| 1263 |
} |
| 1264 |
return -1; |
| 1265 |
} |
| 1266 |
|
| 1267 |
int get_lp_code(internal_font_number f, int c) |
| 1268 |
{ |
| 1269 |
charinfo *ci = char_info(f, c); |
| 1270 |
return get_charinfo_lp(ci); |
| 1271 |
} |
| 1272 |
|
| 1273 |
int get_rp_code(internal_font_number f, int c) |
| 1274 |
{ |
| 1275 |
charinfo *ci = char_info(f, c); |
| 1276 |
return get_charinfo_rp(ci); |
| 1277 |
} |
| 1278 |
|
| 1279 |
int get_ef_code(internal_font_number f, int c) |
| 1280 |
{ |
| 1281 |
charinfo *ci = char_info(f, c); |
| 1282 |
return get_charinfo_ef(ci); |
| 1283 |
} |
| 1284 |
|
| 1285 |
void set_tag_code(internal_font_number f, int c, int i) |
| 1286 |
{ |
| 1287 |
int fixedi; |
| 1288 |
charinfo *co; |
| 1289 |
if (char_exists(f, c)) { |
| 1290 |
fixedi = -(i < -7 ? -7 : (i > 0 ? 0 : i)); |
| 1291 |
co = char_info(f, c); |
| 1292 |
if (fixedi >= 4) { |
| 1293 |
if (char_tag(f, c) == ext_tag) |
| 1294 |
set_charinfo_tag(co, (char_tag(f, c) - ext_tag)); |
| 1295 |
fixedi = fixedi - 4; |
| 1296 |
} |
| 1297 |
if (fixedi >= 2) { |
| 1298 |
if (char_tag(f, c) == list_tag) |
| 1299 |
set_charinfo_tag(co, (char_tag(f, c) - list_tag)); |
| 1300 |
fixedi = fixedi - 2; |
| 1301 |
}; |
| 1302 |
if (fixedi >= 1) { |
| 1303 |
if (has_lig(f, c)) |
| 1304 |
set_charinfo_ligatures(co, NULL); |
| 1305 |
if (has_kern(f, c)) |
| 1306 |
set_charinfo_kerns(co, NULL); |
| 1307 |
} |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
void set_lp_code(internal_font_number f, int c, int i) |
| 1312 |
{ |
| 1313 |
charinfo *co; |
| 1314 |
if (char_exists(f, c)) { |
| 1315 |
co = char_info(f, c); |
| 1316 |
set_charinfo_lp(co, i); |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
void set_rp_code(internal_font_number f, int c, int i) |
| 1321 |
{ |
| 1322 |
charinfo *co; |
| 1323 |
if (char_exists(f, c)) { |
| 1324 |
co = char_info(f, c); |
| 1325 |
set_charinfo_rp(co, i); |
| 1326 |
} |
| 1327 |
} |
| 1328 |
|
| 1329 |
void set_ef_code(internal_font_number f, int c, int i) |
| 1330 |
{ |
| 1331 |
charinfo *co; |
| 1332 |
if (char_exists(f, c)) { |
| 1333 |
co = char_info(f, c); |
| 1334 |
set_charinfo_ef(co, i); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
|
| 1338 |
void set_no_ligatures(internal_font_number f) |
| 1339 |
{ |
| 1340 |
int c; |
| 1341 |
charinfo *co; |
| 1342 |
if (font_tables[f]->_ligatures_disabled) |
| 1343 |
return; |
| 1344 |
co = char_info(f, left_boundarychar); |
| 1345 |
set_charinfo_ligatures(co, NULL); |
| 1346 |
co = char_info(f, right_boundarychar); |
| 1347 |
set_charinfo_ligatures(co, NULL); |
| 1348 |
for (c = 0; c < font_tables[f]->_charinfo_count; c++) { |
| 1349 |
co = font_tables[f]->_charinfo + c; |
| 1350 |
set_charinfo_ligatures(co, NULL); |
| 1351 |
} |
| 1352 |
font_tables[f]->_ligatures_disabled = 1; |
| 1353 |
} |
| 1354 |
|
| 1355 |
liginfo get_ligature(internal_font_number f, int lc, int rc) |
| 1356 |
{ |
| 1357 |
int k = 0; |
| 1358 |
liginfo t, u; |
| 1359 |
charinfo *co; |
| 1360 |
t.lig = 0; |
| 1361 |
t.type = 0; |
| 1362 |
t.adj = 0; |
| 1363 |
if (lc == non_boundarychar || rc == non_boundarychar || (!has_lig(f, lc))) |
| 1364 |
return t; |
| 1365 |
co = char_info(f, lc); |
| 1366 |
while (1) { |
| 1367 |
u = charinfo_ligature(co, k); |
| 1368 |
if (lig_end(u)) |
| 1369 |
break; |
| 1370 |
if (lig_char(u) == rc) { |
| 1371 |
if (lig_disabled(u)) { |
| 1372 |
return t; |
| 1373 |
} else { |
| 1374 |
return u; |
| 1375 |
} |
| 1376 |
} |
| 1377 |
k++; |
| 1378 |
} |
| 1379 |
return t; |
| 1380 |
} |
| 1381 |
|
| 1382 |
scaled raw_get_kern(internal_font_number f, int lc, int rc) |
| 1383 |
{ |
| 1384 |
int k = 0; |
| 1385 |
kerninfo u; |
| 1386 |
charinfo *co; |
| 1387 |
if (lc == non_boundarychar || rc == non_boundarychar) |
| 1388 |
return 0; |
| 1389 |
co = char_info(f, lc); |
| 1390 |
while (1) { |
| 1391 |
u = charinfo_kern(co, k); |
| 1392 |
if (kern_end(u)) |
| 1393 |
break; |
| 1394 |
if (kern_char(u) == rc) { |
| 1395 |
if (kern_disabled(u)) |
| 1396 |
return 0; |
| 1397 |
else |
| 1398 |
return kern_kern(u); |
| 1399 |
} |
| 1400 |
k++; |
| 1401 |
} |
| 1402 |
return 0; |
| 1403 |
} |
| 1404 |
|
| 1405 |
scaled get_kern(internal_font_number f, int lc, int rc) |
| 1406 |
{ |
| 1407 |
if (lc == non_boundarychar || rc == non_boundarychar || (!has_kern(f, lc))) |
| 1408 |
return 0; |
| 1409 |
return raw_get_kern(f, lc, rc); |
| 1410 |
} |
| 1411 |
|
| 1412 |
|
| 1413 |
/*tex Dumping and undumping fonts. */ |
| 1414 |
|
| 1415 |
#define dump_string(a) \ |
| 1416 |
if (a!=NULL) { \ |
| 1417 |
x = (int)(strlen(a)+1); \ |
| 1418 |
dump_int(x); dump_things(*a, x); \ |
| 1419 |
} else { \ |
| 1420 |
x = 0; dump_int(x); \ |
| 1421 |
} |
| 1422 |
|
| 1423 |
static void dump_charinfo(int f, int c) |
| 1424 |
{ |
| 1425 |
charinfo *co; |
| 1426 |
int x; |
| 1427 |
liginfo *lig; |
| 1428 |
kerninfo *kern; |
| 1429 |
dump_int(c); |
| 1430 |
co = char_info(f, c); |
| 1431 |
set_charinfo_used(co, 0); |
| 1432 |
dump_int(get_charinfo_width(co)); |
| 1433 |
dump_int(get_charinfo_height(co)); |
| 1434 |
dump_int(get_charinfo_depth(co)); |
| 1435 |
dump_int(get_charinfo_italic(co)); |
| 1436 |
dump_int(get_charinfo_vert_italic(co)); |
| 1437 |
dump_int(get_charinfo_top_accent(co)); |
| 1438 |
dump_int(get_charinfo_bot_accent(co)); |
| 1439 |
dump_int(get_charinfo_tag(co)); |
| 1440 |
dump_int(get_charinfo_ef(co)); |
| 1441 |
dump_int(get_charinfo_rp(co)); |
| 1442 |
dump_int(get_charinfo_lp(co)); |
| 1443 |
dump_int(get_charinfo_remainder(co)); |
| 1444 |
dump_int(get_charinfo_used(co)); |
| 1445 |
dump_int(get_charinfo_index(co)); |
| 1446 |
dump_string(get_charinfo_name(co)); |
| 1447 |
dump_string(get_charinfo_tounicode(co)); |
| 1448 |
/*tex Ligatures */ |
| 1449 |
x = 0; |
| 1450 |
if ((lig = get_charinfo_ligatures(co)) != NULL) { |
| 1451 |
while (!lig_end(lig[x])) { |
| 1452 |
x++; |
| 1453 |
} |
| 1454 |
x++; |
| 1455 |
dump_int(x); |
| 1456 |
dump_things(*lig, x); |
| 1457 |
} else { |
| 1458 |
dump_int(x); |
| 1459 |
} |
| 1460 |
/*tex Kerns */ |
| 1461 |
x = 0; |
| 1462 |
if ((kern = get_charinfo_kerns(co)) != NULL) { |
| 1463 |
while (!kern_end(kern[x])) { |
| 1464 |
x++; |
| 1465 |
} |
| 1466 |
x++; |
| 1467 |
dump_int(x); |
| 1468 |
dump_things(*kern, x); |
| 1469 |
} else { |
| 1470 |
dump_int(x); |
| 1471 |
} |
| 1472 |
/*tex Packets */ |
| 1473 |
x = vf_packet_bytes(co); |
| 1474 |
dump_int(x); |
| 1475 |
if (x > 0) { |
| 1476 |
dump_things(*get_charinfo_packets(co), x); |
| 1477 |
} |
| 1478 |
if (get_charinfo_tag(co) == ext_tag) { |
| 1479 |
dump_charinfo_variants(get_charinfo_vert_variants(co)); |
| 1480 |
dump_charinfo_variants(get_charinfo_hor_variants(co)); |
| 1481 |
} |
| 1482 |
dump_math_kerns(co); |
| 1483 |
} |
| 1484 |
|
| 1485 |
static void dump_font_entry(texfont * f) |
| 1486 |
{ |
| 1487 |
int x; |
| 1488 |
dump_int(f->_font_size); |
| 1489 |
dump_int(f->_font_dsize); |
| 1490 |
dump_int(f->_font_cidversion); |
| 1491 |
dump_int(f->_font_cidsupplement); |
| 1492 |
dump_int(f->_font_ec); |
| 1493 |
x = (int) f->_font_checksum; |
| 1494 |
dump_int(x); |
| 1495 |
dump_int(f->_font_used); |
| 1496 |
dump_int(f->_font_touched); |
| 1497 |
dump_int(f->_font_cache_id); |
| 1498 |
dump_int(f->_font_encodingbytes); |
| 1499 |
dump_int(f->_font_subfont); |
| 1500 |
dump_int(f->_font_oldmath); |
| 1501 |
dump_int(f->_font_slant); |
| 1502 |
dump_int(f->_font_extend); |
| 1503 |
dump_int(f->_font_squeeze); |
| 1504 |
dump_int(f->_font_mode); |
| 1505 |
dump_int(f->_font_width); |
| 1506 |
dump_int(f->_font_max_shrink); |
| 1507 |
dump_int(f->_font_max_stretch); |
| 1508 |
dump_int(f->_font_step); |
| 1509 |
dump_int(f->_font_tounicode); |
| 1510 |
dump_int(f->_font_type); |
| 1511 |
dump_int(f->_font_format); |
| 1512 |
dump_int(f->_font_writingmode); |
| 1513 |
dump_int(f->_font_identity); |
| 1514 |
dump_int(f->_font_embedding); |
| 1515 |
dump_int(f->_font_streamprovider); |
| 1516 |
dump_int(f->_font_bc); |
| 1517 |
dump_int(f->_hyphen_char); |
| 1518 |
dump_int(f->_skew_char); |
| 1519 |
dump_int(f->_font_natural_dir); |
| 1520 |
dump_int(f->_font_params); |
| 1521 |
dump_int(f->_font_math_params); |
| 1522 |
dump_int(f->_ligatures_disabled); |
| 1523 |
dump_int(f->_pdf_font_num); |
| 1524 |
dump_int(f->_pdf_font_attr); |
| 1525 |
} |
| 1526 |
|
| 1527 |
void dump_font(int f) |
| 1528 |
{ |
| 1529 |
int i, x; |
| 1530 |
set_font_used(f, 0); |
| 1531 |
dump_font_entry(font_tables[f]); |
| 1532 |
dump_string(font_name(f)); |
| 1533 |
dump_string(font_area(f)); |
| 1534 |
dump_string(font_filename(f)); |
| 1535 |
dump_string(font_fullname(f)); |
| 1536 |
dump_string(font_psname(f)); |
| 1537 |
dump_string(font_encodingname(f)); |
| 1538 |
dump_string(font_cidregistry(f)); |
| 1539 |
dump_string(font_cidordering(f)); |
| 1540 |
dump_things(*param_base(f), (font_params(f) + 1)); |
| 1541 |
if (font_math_params(f) > 0) { |
| 1542 |
dump_things(*math_param_base(f), (font_math_params(f) + 1 )); |
| 1543 |
} |
| 1544 |
if (has_left_boundary(f)) { |
| 1545 |
dump_int(1); |
| 1546 |
dump_charinfo(f, left_boundarychar); |
| 1547 |
} else { |
| 1548 |
dump_int(0); |
| 1549 |
} |
| 1550 |
if (has_right_boundary(f)) { |
| 1551 |
dump_int(1); |
| 1552 |
dump_charinfo(f, right_boundarychar); |
| 1553 |
} else { |
| 1554 |
dump_int(0); |
| 1555 |
} |
| 1556 |
for (i = font_bc(f); i <= font_ec(f); i++) { |
| 1557 |
if (quick_char_exists(f, i)) { |
| 1558 |
dump_charinfo(f, i); |
| 1559 |
} |
| 1560 |
} |
| 1561 |
} |
| 1562 |
|
| 1563 |
static int undump_charinfo(int f) |
| 1564 |
{ |
| 1565 |
charinfo *co; |
| 1566 |
int x, i; |
| 1567 |
char *s = NULL; |
| 1568 |
liginfo *lig = NULL; |
| 1569 |
kerninfo *kern = NULL; |
| 1570 |
eight_bits *packet = NULL; |
| 1571 |
undump_int(i); |
| 1572 |
co = get_charinfo(f, i); |
| 1573 |
undump_int(x); |
| 1574 |
set_charinfo_width(co, x); |
| 1575 |
undump_int(x); |
| 1576 |
set_charinfo_height(co, x); |
| 1577 |
undump_int(x); |
| 1578 |
set_charinfo_depth(co, x); |
| 1579 |
undump_int(x); |
| 1580 |
set_charinfo_italic(co, x); |
| 1581 |
undump_int(x); |
| 1582 |
set_charinfo_vert_italic(co, x); |
| 1583 |
undump_int(x); |
| 1584 |
set_charinfo_top_accent(co, x); |
| 1585 |
undump_int(x); |
| 1586 |
set_charinfo_bot_accent(co, x); |
| 1587 |
undump_int(x); |
| 1588 |
set_charinfo_tag(co, x); |
| 1589 |
undump_int(x); |
| 1590 |
set_charinfo_ef(co, x); |
| 1591 |
undump_int(x); |
| 1592 |
set_charinfo_rp(co, x); |
| 1593 |
undump_int(x); |
| 1594 |
set_charinfo_lp(co, x); |
| 1595 |
undump_int(x); |
| 1596 |
set_charinfo_remainder(co, x); |
| 1597 |
undump_int(x); |
| 1598 |
set_charinfo_used(co, x); |
| 1599 |
undump_int(x); |
| 1600 |
set_charinfo_index(co, x); |
| 1601 |
/*tex Name */ |
| 1602 |
undump_int(x); |
| 1603 |
if (x > 0) { |
| 1604 |
font_bytes += x; |
| 1605 |
s = xmalloc((unsigned) x); |
| 1606 |
undump_things(*s, x); |
| 1607 |
} |
| 1608 |
set_charinfo_name(co, s); |
| 1609 |
/*tex Tounicode */ |
| 1610 |
undump_int(x); |
| 1611 |
if (x > 0) { |
| 1612 |
font_bytes += x; |
| 1613 |
s = xmalloc((unsigned) x); |
| 1614 |
undump_things(*s, x); |
| 1615 |
} |
| 1616 |
set_charinfo_tounicode(co, s); |
| 1617 |
/*tex Ligatures */ |
| 1618 |
undump_int(x); |
| 1619 |
if (x > 0) { |
| 1620 |
font_bytes += (int) ((unsigned) x * sizeof(liginfo)); |
| 1621 |
lig = xmalloc((unsigned) ((unsigned) x * sizeof(liginfo))); |
| 1622 |
undump_things(*lig, x); |
| 1623 |
} |
| 1624 |
set_charinfo_ligatures(co, lig); |
| 1625 |
/*tex Kerns */ |
| 1626 |
undump_int(x); |
| 1627 |
if (x > 0) { |
| 1628 |
font_bytes += (int) ((unsigned) x * sizeof(kerninfo)); |
| 1629 |
kern = xmalloc((unsigned) ((unsigned) x * sizeof(kerninfo))); |
| 1630 |
undump_things(*kern, x); |
| 1631 |
} |
| 1632 |
set_charinfo_kerns(co, kern); |
| 1633 |
|
| 1634 |
/*tex Packets */ |
| 1635 |
undump_int(x); |
| 1636 |
if (x > 0) { |
| 1637 |
font_bytes += x; |
| 1638 |
packet = xmalloc((unsigned) x); |
| 1639 |
undump_things(*packet, x); |
| 1640 |
} |
| 1641 |
set_charinfo_packets(co, packet); |
| 1642 |
if (get_charinfo_tag(co) == ext_tag) { |
| 1643 |
set_charinfo_vert_variants(co, undump_charinfo_variants()); |
| 1644 |
set_charinfo_hor_variants(co, undump_charinfo_variants()); |
| 1645 |
} |
| 1646 |
undump_math_kerns(co); |
| 1647 |
return i; |
| 1648 |
} |
| 1649 |
|
| 1650 |
#define undump_font_string(a) \ |
| 1651 |
undump_int (x); \ |
| 1652 |
if (x>0) { \ |
| 1653 |
font_bytes += x; \ |
| 1654 |
s = xmalloc((unsigned)x); \ |
| 1655 |
undump_things(*s,x); \ |
| 1656 |
a(f,s); \ |
| 1657 |
} |
| 1658 |
|
| 1659 |
static void undump_font_entry(texfont * f) |
| 1660 |
{ |
| 1661 |
int x = 0; |
| 1662 |
undump_int(x); f->_font_size = x; |
| 1663 |
undump_int(x); f->_font_dsize = x; |
| 1664 |
undump_int(x); f->_font_cidversion = x; |
| 1665 |
undump_int(x); f->_font_cidsupplement = x; |
| 1666 |
undump_int(x); f->_font_ec = x; |
| 1667 |
undump_int(x); f->_font_checksum = (unsigned)x; |
| 1668 |
undump_int(x); f->_font_used = (char)x; |
| 1669 |
undump_int(x); f->_font_touched = (char)x; |
| 1670 |
undump_int(x); f->_font_cache_id = x; |
| 1671 |
undump_int(x); f->_font_encodingbytes = (char)x; |
| 1672 |
undump_int(x); f->_font_subfont = x; |
| 1673 |
undump_int(x); f->_font_oldmath = x; |
| 1674 |
undump_int(x); f->_font_slant = x; |
| 1675 |
undump_int(x); f->_font_extend = x; |
| 1676 |
undump_int(x); f->_font_squeeze = x; |
| 1677 |
undump_int(x); f->_font_mode = x; |
| 1678 |
undump_int(x); f->_font_width = x; |
| 1679 |
undump_int(x); f->_font_max_shrink = x; |
| 1680 |
undump_int(x); f->_font_max_stretch = x; |
| 1681 |
undump_int(x); f->_font_step = x; |
| 1682 |
undump_int(x); f->_font_tounicode = (char)x; |
| 1683 |
undump_int(x); f->_font_type = x; |
| 1684 |
undump_int(x); f->_font_format = x; |
| 1685 |
undump_int(x); f->_font_writingmode = x; |
| 1686 |
undump_int(x); f->_font_identity = x; |
| 1687 |
undump_int(x); f->_font_embedding = x; |
| 1688 |
undump_int(x); f->_font_streamprovider = x; |
| 1689 |
undump_int(x); f->_font_bc = x; |
| 1690 |
undump_int(x); f->_hyphen_char = x; |
| 1691 |
undump_int(x); f->_skew_char = x; |
| 1692 |
undump_int(x); f->_font_natural_dir = x; |
| 1693 |
undump_int(x); f->_font_params = x; |
| 1694 |
undump_int(x); f->_font_math_params = x; |
| 1695 |
undump_int(x); f->_ligatures_disabled = x; |
| 1696 |
undump_int(x); f->_pdf_font_num = x; |
| 1697 |
undump_int(x); f->_pdf_font_attr = x; |
| 1698 |
} |
| 1699 |
|
| 1700 |
void undump_font(int f) |
| 1701 |
{ |
| 1702 |
int x, i; |
| 1703 |
texfont *tt; |
| 1704 |
charinfo *ci; |
| 1705 |
char *s; |
| 1706 |
sa_tree_item sa_value = { 0 }; |
| 1707 |
grow_font_table(f); |
| 1708 |
tt = xmalloc(sizeof(texfont)); |
| 1709 |
memset(tt, 0, sizeof(texfont)); |
| 1710 |
font_bytes += (int) sizeof(texfont); |
| 1711 |
undump_font_entry(tt); |
| 1712 |
font_tables[f] = tt; |
| 1713 |
undump_font_string(set_font_name); |
| 1714 |
undump_font_string(set_font_area); |
| 1715 |
undump_font_string(set_font_filename); |
| 1716 |
undump_font_string(set_font_fullname); |
| 1717 |
undump_font_string(set_font_psname); |
| 1718 |
undump_font_string(set_font_encodingname); |
| 1719 |
undump_font_string(set_font_cidregistry); |
| 1720 |
undump_font_string(set_font_cidordering); |
| 1721 |
i = (int) (sizeof(*param_base(f)) * ((unsigned) font_params(f) + 1)); |
| 1722 |
font_bytes += i; |
| 1723 |
param_base(f) = xmalloc((unsigned) i); |
| 1724 |
undump_things(*param_base(f), (font_params(f) + 1)); |
| 1725 |
if (font_math_params(f) > 0) { |
| 1726 |
i = (int) (sizeof(*math_param_base(f)) * |
| 1727 |
((unsigned) font_math_params(f) + 1)); |
| 1728 |
font_bytes += i; |
| 1729 |
math_param_base(f) = xmalloc((unsigned) i); |
| 1730 |
undump_things(*math_param_base(f), (font_math_params(f) + 1)); |
| 1731 |
} |
| 1732 |
/*tex stack size 1, default item value 0 */ |
| 1733 |
font_tables[f]->_characters = new_sa_tree(1, 1, sa_value); |
| 1734 |
ci = xcalloc(1, sizeof(charinfo)); |
| 1735 |
set_charinfo_name(ci, xstrdup(".notdef")); |
| 1736 |
font_tables[f]->_charinfo = ci; |
| 1737 |
undump_int(x); |
| 1738 |
if (x) { |
| 1739 |
/*tex left boundary */ |
| 1740 |
i = undump_charinfo(f); |
| 1741 |
} |
| 1742 |
undump_int(x); |
| 1743 |
if (x) { |
| 1744 |
/*tex right boundary */ |
| 1745 |
i = undump_charinfo(f); |
| 1746 |
} |
| 1747 |
i = font_bc(f); |
| 1748 |
while (i < font_ec(f)) { |
| 1749 |
i = undump_charinfo(f); |
| 1750 |
} |
| 1751 |
} |
| 1752 |
|
| 1753 |
/* The \PK\ pixel density value from |texmf.cnf| */ |
| 1754 |
|
| 1755 |
int pk_dpi; |
| 1756 |
|
| 1757 |
/*tex |
| 1758 |
|
| 1759 |
This one looks up the font for a \TFM\ with name |s| loaded at |fs| size and |
| 1760 |
if found then flushes |s|. |
| 1761 |
|
| 1762 |
*/ |
| 1763 |
|
| 1764 |
internal_font_number tfm_lookup(char *s, scaled fs) |
| 1765 |
{ |
| 1766 |
internal_font_number k; |
| 1767 |
if (fs != 0) { |
| 1768 |
for (k = 1; k <= max_font_id(); k++) { |
| 1769 |
if (cmp_font_name(k, s) && font_size(k) == fs) { |
| 1770 |
return k; |
| 1771 |
} |
| 1772 |
} |
| 1773 |
} else { |
| 1774 |
for (k = 1; k <= max_font_id(); k++) { |
| 1775 |
if (cmp_font_name(k, s)) { |
| 1776 |
return k; |
| 1777 |
} |
| 1778 |
} |
| 1779 |
} |
| 1780 |
return null_font; |
| 1781 |
} |
| 1782 |
|
| 1783 |
/*tex |
| 1784 |
|
| 1785 |
This returns the multiple of |font_step(f)| that is nearest to |e|. |
| 1786 |
|
| 1787 |
*/ |
| 1788 |
|
| 1789 |
int fix_expand_value(internal_font_number f, int e) |
| 1790 |
{ |
| 1791 |
int step; |
| 1792 |
int max_expand; |
| 1793 |
boolean neg; |
| 1794 |
if (e == 0) |
| 1795 |
return 0; |
| 1796 |
if (e < 0) { |
| 1797 |
e = -e; |
| 1798 |
neg = true; |
| 1799 |
max_expand = font_max_shrink(f); |
| 1800 |
} else { |
| 1801 |
neg = false; |
| 1802 |
max_expand = font_max_stretch(f); |
| 1803 |
} |
| 1804 |
if (e > max_expand) { |
| 1805 |
e = max_expand; |
| 1806 |
} else { |
| 1807 |
step = font_step(f); |
| 1808 |
if (e % step > 0) |
| 1809 |
e = step * round_xn_over_d(e, 1, step); |
| 1810 |
} |
| 1811 |
if (neg) |
| 1812 |
e = -e; |
| 1813 |
return e; |
| 1814 |
} |
| 1815 |
|
| 1816 |
void set_expand_params(internal_font_number f, int stretch_limit, int shrink_limit, int font_step) |
| 1817 |
{ |
| 1818 |
set_font_step(f, font_step); |
| 1819 |
set_font_max_shrink(f, shrink_limit); |
| 1820 |
set_font_max_stretch(f, stretch_limit); |
| 1821 |
} |
| 1822 |
|
| 1823 |
/*tex |
| 1824 |
|
| 1825 |
This reads font expansion spec and load expanded font. |
| 1826 |
|
| 1827 |
*/ |
| 1828 |
|
| 1829 |
void read_expand_font(void) |
| 1830 |
{ |
| 1831 |
int shrink_limit, stretch_limit, font_step; |
| 1832 |
internal_font_number f; |
| 1833 |
scan_font_ident(); |
| 1834 |
f = cur_val; |
| 1835 |
if (f == null_font) |
| 1836 |
normal_error("font expansion", "invalid font identifier"); |
| 1837 |
scan_optional_equals(); |
| 1838 |
scan_int(); |
| 1839 |
stretch_limit = fix_int(cur_val, 0, 1000); |
| 1840 |
scan_int(); |
| 1841 |
shrink_limit = fix_int(cur_val, 0, 500); |
| 1842 |
scan_int(); |
| 1843 |
font_step = fix_int(cur_val, 0, 100); |
| 1844 |
if (font_step == 0) |
| 1845 |
normal_error("font expansion", "invalid step"); |
| 1846 |
stretch_limit = stretch_limit - stretch_limit % font_step; |
| 1847 |
if (stretch_limit < 0) |
| 1848 |
stretch_limit = 0; |
| 1849 |
shrink_limit = shrink_limit - shrink_limit % font_step; |
| 1850 |
if (shrink_limit < 0) |
| 1851 |
shrink_limit = 0; |
| 1852 |
if ((stretch_limit == 0) && (shrink_limit == 0)) |
| 1853 |
normal_error("font expansion", "invalid limit(s)"); |
| 1854 |
if (scan_keyword("autoexpand")) { |
| 1855 |
normal_warning("font expansion", "autoexpand not supported"); |
| 1856 |
/*tex scan an optional space */ |
| 1857 |
get_x_token(); |
| 1858 |
if (cur_cmd != spacer_cmd) |
| 1859 |
back_input(); |
| 1860 |
} |
| 1861 |
if (font_step(f) != 0) { |
| 1862 |
/*tex This font has been expanded, ensure the expansion parameters are identical. */ |
| 1863 |
if (font_step(f) != font_step) |
| 1864 |
normal_error("font expansion","font has been expanded with different expansion step"); |
| 1865 |
if (((font_max_stretch(f) == 0) && (stretch_limit != 0)) || |
| 1866 |
((font_max_stretch(f) > 0) && (font_max_stretch(f) != stretch_limit))) |
| 1867 |
normal_error("font expansion","font has been expanded with different stretch limit"); |
| 1868 |
|
| 1869 |
if (((font_max_shrink(f) == 0) && (shrink_limit != 0)) || |
| 1870 |
((font_max_shrink(f) > 0) && (font_max_shrink(f) != shrink_limit))) |
| 1871 |
normal_error("font expansion","font has been expanded with different shrink limit"); |
| 1872 |
} else { |
| 1873 |
if (font_used(f)) |
| 1874 |
normal_warning("font expansion", "font should be expanded before its first use"); |
| 1875 |
set_expand_params(f, stretch_limit, shrink_limit, font_step); |
| 1876 |
} |
| 1877 |
} |
| 1878 |
|
| 1879 |
/*tex |
| 1880 |
|
| 1881 |
Here's an old (sort of obsolete) letterspace-a-font helper. It does so by |
| 1882 |
creating a virtual font. |
| 1883 |
|
| 1884 |
*/ |
| 1885 |
|
| 1886 |
void new_letterspaced_font(small_number a) |
| 1887 |
{ |
| 1888 |
pointer u; |
| 1889 |
str_number t; |
| 1890 |
internal_font_number f, k; |
| 1891 |
boolean nolig = false; |
| 1892 |
get_r_token(); |
| 1893 |
u = cur_cs; |
| 1894 |
if (u >= hash_base) |
| 1895 |
t = cs_text(u); |
| 1896 |
else |
| 1897 |
t = maketexstring("FONT"); |
| 1898 |
define(u, set_font_cmd, null_font); |
| 1899 |
scan_optional_equals(); |
| 1900 |
scan_font_ident(); |
| 1901 |
k = cur_val; |
| 1902 |
scan_int(); |
| 1903 |
if (scan_keyword("nolig")) |
| 1904 |
nolig=true; |
| 1905 |
f = letter_space_font(k, fix_int(cur_val, -1000, 1000), nolig); |
| 1906 |
equiv(u) = f; |
| 1907 |
eqtb[font_id_base + f] = eqtb[u]; |
| 1908 |
font_id_text(f) = t; |
| 1909 |
} |
| 1910 |
|
| 1911 |
/*tex |
| 1912 |
|
| 1913 |
This makes a font copy for further use with font expansion. Again a |
| 1914 |
traditional font related helper. |
| 1915 |
|
| 1916 |
*/ |
| 1917 |
|
| 1918 |
void make_font_copy(small_number a) |
| 1919 |
{ |
| 1920 |
pointer u; |
| 1921 |
str_number t; |
| 1922 |
internal_font_number f, k; |
| 1923 |
get_r_token(); |
| 1924 |
u = cur_cs; |
| 1925 |
if (u >= hash_base) |
| 1926 |
t = cs_text(u); |
| 1927 |
else |
| 1928 |
t = maketexstring("FONT"); |
| 1929 |
define(u, set_font_cmd, null_font); |
| 1930 |
scan_optional_equals(); |
| 1931 |
scan_font_ident(); |
| 1932 |
k = cur_val; |
| 1933 |
f = copy_font_info(k); |
| 1934 |
equiv(u) = f; |
| 1935 |
eqtb[font_id_base + f] = eqtb[u]; |
| 1936 |
font_id_text(f) = t; |
| 1937 |
} |
| 1938 |
|
| 1939 |
void glyph_to_unicode(void) |
| 1940 |
{ |
| 1941 |
str_number s1, s2; |
| 1942 |
scan_toks(false, true); |
| 1943 |
s1 = tokens_to_string(def_ref); |
| 1944 |
delete_token_ref(def_ref); |
| 1945 |
scan_toks(false, true); |
| 1946 |
s2 = tokens_to_string(def_ref); |
| 1947 |
delete_token_ref(def_ref); |
| 1948 |
def_tounicode(s1, s2); |
| 1949 |
flush_str(s2); |
| 1950 |
flush_str(s1); |
| 1951 |
} |