summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2014-09-15 09:43:03 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2014-09-15 09:43:03 +0000
commit3e926073114d4f044bcc02ba243023dea4aafa97 (patch)
treed02e671c23d15b0d0ee6e1cbf4086c6c3fe4a6ad /Build/source
parentac391ad3f024072af6dbc29e6242e01626fa68e3 (diff)
texk/dvipdfm-x: General cleanup: No reason to use long for 32-bit integers
git-svn-id: svn://tug.org/texlive/trunk@35176 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r--Build/source/texk/dvipdfm-x/ChangeLog15
-rw-r--r--Build/source/texk/dvipdfm-x/dvi.c389
-rw-r--r--Build/source/texk/dvipdfm-x/dvi.h36
-rw-r--r--Build/source/texk/dvipdfm-x/dvipdfmx.c2
-rw-r--r--Build/source/texk/dvipdfm-x/jp2image.c1
-rw-r--r--Build/source/texk/dvipdfm-x/mfileio.c9
-rw-r--r--Build/source/texk/dvipdfm-x/mfileio.h9
-rw-r--r--Build/source/texk/dvipdfm-x/numbers.c147
-rw-r--r--Build/source/texk/dvipdfm-x/numbers.h43
-rw-r--r--Build/source/texk/dvipdfm-x/otl_conf.c1
-rw-r--r--Build/source/texk/dvipdfm-x/pkfont.c110
-rw-r--r--Build/source/texk/dvipdfm-x/specials.c4
-rw-r--r--Build/source/texk/dvipdfm-x/specials.h2
-rw-r--r--Build/source/texk/dvipdfm-x/tfm.c215
-rw-r--r--Build/source/texk/dvipdfm-x/tfm.h12
-rw-r--r--Build/source/texk/dvipdfm-x/vf.c37
16 files changed, 492 insertions, 540 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog
index 894f2982673..5edb6fe8bb5 100644
--- a/Build/source/texk/dvipdfm-x/ChangeLog
+++ b/Build/source/texk/dvipdfm-x/ChangeLog
@@ -1,3 +1,18 @@
+2014-09-15 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ No reason to use 'long' for 32-bit integers.
+ * dvi.[ch], pkfont.c, specials.[ch], tfm.[ch]: Use (u)int32_t
+ instead of long, UNSIGNED_QUAD, etc.
+ * dvipdfmx.c: Replace long => int.
+ * jp2image.c, otl_conf.c: Drop rewind() after file_size().
+ * mfileio.[ch]: New functions xfile_size(), xseek_absolute(),
+ xseek_relative(), xseek_end(), and xtell_position().
+ * numbers.[ch]: Replace (UN)SIGNED_BYTE => (un)signed char,
+ (UN)SIGNED_PAIR => (un)signed short, (UN)SIGNED_TRIPLE =>
+ un)signed int, (UN)SIGNED_QUAD => (u)int32_t.
+ New functions get_unsigned_num() and get_positive_quad().
+ * vf.c: Use get_positive_quad() and get_unsigned_num().
+
2014-09-01 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* vf.c: Add missing break in case X1: case X2: case X3: case X4:
diff --git a/Build/source/texk/dvipdfm-x/dvi.c b/Build/source/texk/dvipdfm-x/dvi.c
index 8bae2dddf5b..4350a1c1102 100644
--- a/Build/source/texk/dvipdfm-x/dvi.c
+++ b/Build/source/texk/dvipdfm-x/dvi.c
@@ -77,18 +77,18 @@
static FILE *dvi_file = NULL;
static char linear = 0; /* set to 1 for strict linear processing of the input */
-static unsigned long *page_loc = NULL;
-static unsigned long num_pages = 0;
+static int32_t *page_loc = NULL;
+static unsigned int num_pages = 0;
-static unsigned long dvi_file_size = 0;
+static uint32_t dvi_file_size = 0;
static struct dvi_header
{
- UNSIGNED_QUAD unit_num;
- UNSIGNED_QUAD unit_den;
- UNSIGNED_QUAD mag;
- UNSIGNED_QUAD media_width, media_height;
- UNSIGNED_PAIR stackdepth;
+ uint32_t unit_num;
+ uint32_t unit_den;
+ uint32_t mag;
+ uint32_t media_width, media_height;
+ unsigned int stackdepth;
char comment[257];
} dvi_info = {
25400000 , /* num */
@@ -114,13 +114,13 @@ double get_origin (int x)
struct dvi_lr
{
int state, font;
- unsigned long buf_index;
+ unsigned int buf_index;
};
static struct dvi_lr lr_state; /* state at start of current skimming */
static int lr_mode; /* current direction or skimming depth */
-static SIGNED_QUAD lr_width; /* total width of reflected segment */
-static SIGNED_QUAD lr_width_stack[DVI_STACK_DEPTH_MAX];
+static uint32_t lr_width; /* total width of reflected segment */
+static uint32_t lr_width_stack[DVI_STACK_DEPTH_MAX];
static unsigned lr_width_stack_depth = 0;
#define PHYSICAL 1
@@ -141,7 +141,7 @@ static struct loaded_font
spt_t size;
int source; /* Source is either DVI or VF */
#ifdef XETEX
- unsigned long rgba_color;
+ uint32_t rgba_color;
FT_Face ft_face;
int layout_dir;
float extend;
@@ -162,7 +162,7 @@ need_more_fonts (unsigned n)
static struct font_def
{
- long tex_id;
+ int32_t tex_id;
spt_t point_size;
spt_t design_size;
char *font_name;
@@ -170,8 +170,8 @@ static struct font_def
int used;
#ifdef XETEX
int native; /* boolean */
- unsigned long rgba_color; /* only used for native fonts in XeTeX */
- unsigned long face_index;
+ uint32_t rgba_color; /* only used for native fonts in XeTeX */
+ uint32_t face_index;
int layout_dir; /* 1 = vertical, 0 = horizontal */
int extend;
int slant;
@@ -192,14 +192,14 @@ static int num_def_fonts = 0, max_def_fonts = 0;
static int compute_boxes = 0, link_annot = 1;
static int verbose = 0;
-#define DVI_PAGE_BUF_CHUNK 0x10000UL /* 64K should be plenty for most pages */
+#define DVI_PAGE_BUF_CHUNK 0x10000U /* 64K should be plenty for most pages */
static unsigned char* dvi_page_buffer;
-static unsigned long dvi_page_buf_size;
-static unsigned long dvi_page_buf_index;
+static unsigned int dvi_page_buf_size;
+static unsigned int dvi_page_buf_index;
/* functions to read numbers from the dvi file and store them in dvi_page_buffer */
-static UNSIGNED_BYTE get_and_buffer_unsigned_byte (FILE *file)
+static int get_and_buffer_unsigned_byte (FILE *file)
{
int ch;
if ((ch = fgetc (file)) < 0)
@@ -209,19 +209,14 @@ static UNSIGNED_BYTE get_and_buffer_unsigned_byte (FILE *file)
dvi_page_buffer = RENEW(dvi_page_buffer, dvi_page_buf_size, unsigned char);
}
dvi_page_buffer[dvi_page_buf_index++] = ch;
- return (UNSIGNED_BYTE) ch;
+ return ch;
}
#ifdef XETEX
-static UNSIGNED_PAIR get_and_buffer_unsigned_pair (FILE *file)
+static unsigned int get_and_buffer_unsigned_pair (FILE *file)
{
- int i;
- UNSIGNED_BYTE byte;
- UNSIGNED_PAIR pair = 0;
- for (i=0; i<2; i++) {
- byte = get_and_buffer_unsigned_byte(file);
- pair = pair*0x100u + byte;
- }
+ unsigned int pair = get_and_buffer_unsigned_byte(file);
+ pair = (pair << 8) | get_and_buffer_unsigned_byte(file);
return pair;
}
#endif
@@ -239,67 +234,59 @@ static void get_and_buffer_bytes(FILE *file, unsigned int count)
/* functions to fetch values from dvi_page_buffer */
-static UNSIGNED_BYTE get_buffered_unsigned_byte (void)
+static int get_buffered_unsigned_byte (void)
{
return dvi_page_buffer[dvi_page_buf_index++];
}
#ifdef XETEX
-static UNSIGNED_PAIR get_buffered_unsigned_pair (void)
+static unsigned int get_buffered_unsigned_pair (void)
{
- int i;
- UNSIGNED_BYTE byte;
- UNSIGNED_PAIR pair = 0;
- for (i=0; i<2; i++) {
- byte = dvi_page_buffer[dvi_page_buf_index++];
- pair = pair*0x100u + byte;
- }
+ unsigned int pair = dvi_page_buffer[dvi_page_buf_index++];
+ pair = (pair << 8) | dvi_page_buffer[dvi_page_buf_index++];
return pair;
}
#endif
-static SIGNED_QUAD get_buffered_signed_quad(void)
+static int32_t get_buffered_signed_quad(void)
{
- int byte, i;
- long quad = 0;
-
+ int i;
+ int32_t quad = dvi_page_buffer[dvi_page_buf_index++];
/* Check sign on first byte before reading others */
- byte = dvi_page_buffer[dvi_page_buf_index++];
- quad = byte;
if (quad >= 0x80)
- quad = byte - 0x100;
+ quad -= 0x100;
for (i=0; i<3; i++) {
- quad = quad*0x100 + dvi_page_buffer[dvi_page_buf_index++];
+ quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
}
- return (SIGNED_QUAD) quad;
+ return quad;
}
-static SIGNED_QUAD get_buffered_signed_num(unsigned char num)
+static int32_t get_buffered_signed_num(unsigned char num)
{
- long quad = dvi_page_buffer[dvi_page_buf_index++];
+ int32_t quad = dvi_page_buffer[dvi_page_buf_index++];
if (quad > 0x7f)
quad -= 0x100;
switch (num) {
- case 3: quad = quad * 0x100 + dvi_page_buffer[dvi_page_buf_index++];
- case 2: quad = quad * 0x100 + dvi_page_buffer[dvi_page_buf_index++];
- case 1: quad = quad * 0x100 + dvi_page_buffer[dvi_page_buf_index++];
+ case 3: quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
+ case 2: quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
+ case 1: quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
default: break;
}
- return (SIGNED_QUAD) quad;
+ return quad;
}
-static UNSIGNED_QUAD get_buffered_unsigned_num(unsigned char num)
+static int32_t get_buffered_unsigned_num(unsigned char num)
{
- unsigned long quad = dvi_page_buffer[dvi_page_buf_index++];
+ int32_t quad = dvi_page_buffer[dvi_page_buf_index++];
switch (num) {
- case 3: quad = quad * 0x100u + dvi_page_buffer[dvi_page_buf_index++];
- if (quad > 0x7fff)
- WARN("Unsigned number starting with %x exceeds 0x7fffffff", quad);
- case 2: quad = quad * 0x100u + dvi_page_buffer[dvi_page_buf_index++];
- case 1: quad = quad * 0x100u + dvi_page_buffer[dvi_page_buf_index++];
+ case 3: if (quad > 0x7f)
+ quad -= 0x100;
+ quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
+ case 2: quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
+ case 1: quad = (quad << 8) | dvi_page_buffer[dvi_page_buf_index++];
default: break;
}
- return (UNSIGNED_QUAD) quad;
+ return quad;
}
#define skip_bufferd_bytes(n) dvi_page_buf_index += n
@@ -314,7 +301,7 @@ dvi_set_verbose (void)
spc_set_verbose();
}
-unsigned
+unsigned int
dvi_npages (void)
{
return num_pages;
@@ -328,20 +315,23 @@ static const char invalid_signature[] =
ERROR(invalid_signature); \
}
-static long
+static int32_t
find_post (void)
{
- long current;
+ off_t dvi_size;
+ int32_t current;
int ch;
- /* First find end of file */
- dvi_file_size = file_size(dvi_file);
- current = dvi_file_size;
+ /* First find end of file */
+ dvi_size = xfile_size (dvi_file, "DVI");
+ if (dvi_size > 0x7fffffff)
+ ERROR("DVI file size exceeds 31-bit");
+ dvi_file_size = dvi_size;
+ current = dvi_size;
/* Scan backwards through PADDING */
do {
- current--;
- seek_absolute(dvi_file, current);
+ xseek_absolute (dvi_file, --current, "DVI");
} while ((ch = fgetc(dvi_file)) == PADDING &&
current > 0);
@@ -357,13 +347,13 @@ find_post (void)
/* Make sure post_post is really there */
current = current - 5;
- seek_absolute(dvi_file, current);
+ xseek_absolute (dvi_file, current, "DVI");
if ((ch = fgetc(dvi_file)) != POST_POST) {
MESG("Found %d where post_post opcode should be\n", ch);
ERROR(invalid_signature);
}
current = get_signed_quad(dvi_file);
- seek_absolute(dvi_file, current);
+ xseek_absolute (dvi_file, current, "DVI");
if ((ch = fgetc(dvi_file)) != POST) {
MESG("Found %d where post_post opcode should be\n", ch);
ERROR(invalid_signature);
@@ -373,11 +363,11 @@ find_post (void)
}
static void
-get_page_info (long post_location)
+get_page_info (int32_t post_location)
{
int i;
- seek_absolute(dvi_file, post_location + 27);
+ xseek_absolute (dvi_file, post_location + 27, "DVI");
num_pages = get_unsigned_pair(dvi_file);
if (num_pages == 0) {
ERROR("Page count is 0!");
@@ -386,13 +376,13 @@ get_page_info (long post_location)
MESG("Page count:\t %4d\n", num_pages);
}
- page_loc = NEW(num_pages, unsigned long);
+ page_loc = NEW(num_pages, int32_t);
- seek_absolute(dvi_file, post_location + 1);
+ xseek_absolute (dvi_file, post_location + 1, "DVI");
page_loc[num_pages-1] = get_unsigned_quad(dvi_file);
range_check_loc(page_loc[num_pages-1] + 41);
for (i = num_pages - 2; i >= 0; i--) {
- seek_absolute(dvi_file, page_loc[i+1] + 41);
+ xseek_absolute (dvi_file, page_loc[i+1] + 41, "DVI");
page_loc[i] = get_unsigned_quad(dvi_file);
range_check_loc(page_loc[num_pages-1] + 41);
}
@@ -416,9 +406,9 @@ do_scales (double mag)
}
static void
-get_dvi_info (long post_location)
+get_dvi_info (int32_t post_location)
{
- seek_absolute(dvi_file, post_location + 5);
+ xseek_absolute (dvi_file, post_location + 5, "DVI");
dvi_info.unit_num = get_unsigned_quad(dvi_file);
dvi_info.unit_den = get_unsigned_quad(dvi_file);
@@ -448,7 +438,7 @@ get_dvi_info (long post_location)
static void
get_preamble_dvi_info (void)
{
- UNSIGNED_BYTE ch;
+ int ch;
ch = get_unsigned_byte(dvi_file);
if (ch != PRE) {
@@ -464,9 +454,9 @@ get_preamble_dvi_info (void)
is_xdv = ch == XDV_ID;
- dvi_info.unit_num = get_unsigned_quad(dvi_file);
- dvi_info.unit_den = get_unsigned_quad(dvi_file);
- dvi_info.mag = get_unsigned_quad(dvi_file);
+ dvi_info.unit_num = get_positive_quad(dvi_file, "DVI", "unit_num");
+ dvi_info.unit_den = get_positive_quad(dvi_file, "DVI", "unit_den");
+ dvi_info.mag = get_positive_quad(dvi_file, "DVI", "mag");
ch = get_unsigned_byte(dvi_file);
if (fread(dvi_info.comment,
@@ -485,7 +475,7 @@ get_preamble_dvi_info (void)
MESG("DVI Comment: %s\n", dvi_info.comment);
}
- num_pages = 0x7FFFFFFUL; /* for linear processing: we just keep going! */
+ num_pages = 0x7FFFFFFU; /* for linear processing: we just keep going! */
}
const char *
@@ -495,19 +485,19 @@ dvi_comment (void)
}
static void
-read_font_record (SIGNED_QUAD tex_id)
+read_font_record (int32_t tex_id)
{
- UNSIGNED_BYTE dir_length, name_length;
- UNSIGNED_QUAD point_size, design_size;
- char *directory, *font_name;
+ int dir_length, name_length;
+ uint32_t point_size, design_size;
+ char *directory, *font_name;
if (num_def_fonts >= max_def_fonts) {
max_def_fonts += TEX_FONTS_ALLOC_SIZE;
def_fonts = RENEW (def_fonts, max_def_fonts, struct font_def);
}
get_unsigned_quad(dvi_file);
- point_size = get_unsigned_quad(dvi_file);
- design_size = get_unsigned_quad(dvi_file);
+ point_size = get_positive_quad(dvi_file, "DVI", "point_size");
+ design_size = get_positive_quad(dvi_file, "DVI", "design_size");
dir_length = get_unsigned_byte(dvi_file);
name_length = get_unsigned_byte(dvi_file);
@@ -544,19 +534,19 @@ read_font_record (SIGNED_QUAD tex_id)
#ifdef XETEX
static void
-read_native_font_record (SIGNED_QUAD tex_id)
+read_native_font_record (int32_t tex_id)
{
- UNSIGNED_PAIR flags;
- UNSIGNED_QUAD point_size;
+ unsigned int flags;
+ uint32_t point_size;
char *font_name;
int len;
- unsigned long index;
+ uint32_t index;
if (num_def_fonts >= max_def_fonts) {
max_def_fonts += TEX_FONTS_ALLOC_SIZE;
def_fonts = RENEW (def_fonts, max_def_fonts, struct font_def);
}
- point_size = get_unsigned_quad(dvi_file);
+ point_size = get_positive_quad(dvi_file, "DVI", "point_size");
flags = get_unsigned_pair(dvi_file);
len = (int) get_unsigned_byte(dvi_file); /* font name length */
@@ -566,7 +556,7 @@ read_native_font_record (SIGNED_QUAD tex_id)
}
font_name[len] = '\0';
- index = get_unsigned_quad(dvi_file);
+ index = get_positive_quad(dvi_file, "DVI", "index");
def_fonts[num_def_fonts].tex_id = tex_id;
def_fonts[num_def_fonts].font_name = font_name;
@@ -604,39 +594,25 @@ read_native_font_record (SIGNED_QUAD tex_id)
#endif
static void
-get_dvi_fonts (long post_location)
+get_dvi_fonts (int32_t post_location)
{
- UNSIGNED_BYTE code;
- SIGNED_QUAD tex_id = 0;
+ int code;
- seek_absolute(dvi_file, post_location + 29);
+ xseek_absolute (dvi_file, post_location + 29, "DVI");
while ((code = get_unsigned_byte(dvi_file)) != POST_POST) {
switch (code) {
- case FNT_DEF1:
- tex_id = get_unsigned_byte(dvi_file);
- break;
- case FNT_DEF2:
- tex_id = get_unsigned_pair(dvi_file);
+ case FNT_DEF1: case FNT_DEF2: case FNT_DEF3: case FNT_DEF4:
+ read_font_record(get_unsigned_num(dvi_file, code-FNT_DEF1));
break;
- case FNT_DEF3:
- tex_id = get_unsigned_triple(dvi_file);
- break;
- case FNT_DEF4:
#ifdef XETEX
case XDV_NATIVE_FONT_DEF:
-#endif
- tex_id = get_signed_quad(dvi_file);
+ read_native_font_record(get_signed_quad(dvi_file));
break;
+#endif
default:
MESG("Unexpected op code: %3d\n", code);
ERROR(invalid_signature);
}
-#ifdef XETEX
- if (code == XDV_NATIVE_FONT_DEF)
- read_native_font_record(tex_id);
- else
-#endif
- read_font_record(tex_id);
}
if (verbose > 2) {
unsigned i;
@@ -644,7 +620,7 @@ get_dvi_fonts (long post_location)
MESG("\n");
MESG("DVI file font info\n");
for (i = 0; i < num_def_fonts; i++) {
- MESG("TeX Font: %10s loaded at ID=%5ld, ",
+ MESG("TeX Font: %10s loaded at ID=%5d, ",
def_fonts[i].font_name, def_fonts[i].tex_id);
MESG("size=%5.2fpt (scaled %4.1f%%)",
def_fonts[i].point_size * dvi2pts,
@@ -656,9 +632,9 @@ get_dvi_fonts (long post_location)
static void get_comment (void)
{
- UNSIGNED_BYTE length;
+ int length;
- seek_absolute(dvi_file, 14);
+ xseek_absolute (dvi_file, 14, "DVI");
length = get_unsigned_byte(dvi_file);
if (fread(dvi_info.comment,
1, length, dvi_file) != length) {
@@ -679,7 +655,8 @@ static void get_comment (void)
struct dvi_registers
{
- SIGNED_QUAD h, v, w, x, y, z, d;
+ int32_t h, v, w, x, y, z;
+ unsigned int d;
};
static struct dvi_registers dvi_state;
@@ -763,16 +740,11 @@ dvi_is_tracking_boxes(void)
}
void
-dvi_do_special (const void *buffer, UNSIGNED_QUAD size)
+dvi_do_special (const void *buffer, int32_t size)
{
double x_user, y_user, mag;
const char *p;
- if (size > 0x7fffffffUL) {
- WARN("Special more than %ul bytes???", size);
- return;
- }
-
graphics_mode();
p = (const char *) buffer;
@@ -781,7 +753,7 @@ dvi_do_special (const void *buffer, UNSIGNED_QUAD size)
y_user = -dvi_state.v * dvi2pts;
mag = dvi_tell_mag();
- if (spc_exec_special(p, (long) size, x_user, y_user, mag) < 0) {
+ if (spc_exec_special(p, size, x_user, y_user, mag) < 0) {
if (verbose) {
dump(p, p + size);
}
@@ -936,7 +908,7 @@ dvi_locate_font (const char *tfm_name, spt_t ptsize)
#ifdef XETEX
static int
-dvi_locate_native_font (const char *filename, unsigned long index,
+dvi_locate_native_font (const char *filename, uint32_t index,
spt_t ptsize, int layout_dir, int extend, int slant, int embolden)
{
int cur_id = -1;
@@ -950,7 +922,7 @@ dvi_locate_native_font (const char *filename, unsigned long index,
cur_id = num_loaded_fonts++;
- sprintf(fontmap_key, "%s/%lu/%c/%d/%d/%d", filename, index, layout_dir == 0 ? 'H' : 'V', extend, slant, embolden);
+ sprintf(fontmap_key, "%s/%u/%c/%d/%d/%d", filename, index, layout_dir == 0 ? 'H' : 'V', extend, slant, embolden);
mrec = pdf_lookup_fontmap_record(fontmap_key);
if (mrec == NULL) {
if (pdf_load_native_font(filename, index, layout_dir, extend, slant, embolden) == -1) {
@@ -990,14 +962,14 @@ dvi_dev_ypos (void)
return -(dvi_state.v * dvi2pts);
}
-static void do_moveto (SIGNED_QUAD x, SIGNED_QUAD y)
+static void do_moveto (int32_t x, int32_t y)
{
dvi_state.h = x;
dvi_state.v = y;
}
/* FIXME: dvi_forward() might be a better name */
-void dvi_right (SIGNED_QUAD x)
+void dvi_right (int32_t x)
{
if (lr_mode >= SKIMMING) {
lr_width += x;
@@ -1017,7 +989,7 @@ void dvi_right (SIGNED_QUAD x)
}
}
-void dvi_down (SIGNED_QUAD y)
+void dvi_down (int32_t y)
{
if (lr_mode < SKIMMING) {
switch (dvi_state.d) {
@@ -1037,7 +1009,7 @@ void dvi_down (SIGNED_QUAD y)
* is not clear.
*/
void
-dvi_set (SIGNED_QUAD ch)
+dvi_set (int32_t ch)
{
struct loaded_font *font;
spt_t width, height, depth;
@@ -1120,7 +1092,7 @@ dvi_set (SIGNED_QUAD ch)
}
void
-dvi_put (SIGNED_QUAD ch)
+dvi_put (int32_t ch)
{
struct loaded_font *font;
spt_t width, height, depth;
@@ -1193,7 +1165,7 @@ dvi_put (SIGNED_QUAD ch)
void
-dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height)
+dvi_rule (int32_t width, int32_t height)
{
if (width > 0 && height > 0) {
do_moveto(dvi_state.h, dvi_state.v);
@@ -1213,7 +1185,7 @@ dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height)
}
void
-dvi_dir (UNSIGNED_BYTE dir)
+dvi_dir (unsigned char dir)
{
if (verbose)
fprintf(stderr, " > dvi_dir %d\n", dir);
@@ -1224,7 +1196,7 @@ dvi_dir (UNSIGNED_BYTE dir)
static void
do_setrule (void)
{
- SIGNED_QUAD width, height;
+ int32_t width, height;
height = get_buffered_signed_quad();
width = get_buffered_signed_quad();
@@ -1246,7 +1218,7 @@ do_setrule (void)
static void
do_putrule (void)
{
- SIGNED_QUAD width, height;
+ int32_t width, height;
height = get_buffered_signed_quad ();
width = get_buffered_signed_quad ();
@@ -1286,7 +1258,7 @@ dvi_pop (void)
void
-dvi_w (SIGNED_QUAD ch)
+dvi_w (int32_t ch)
{
dvi_state.w = ch;
dvi_right(ch);
@@ -1299,7 +1271,7 @@ dvi_w0 (void)
}
void
-dvi_x (SIGNED_QUAD ch)
+dvi_x (int32_t ch)
{
dvi_state.x = ch;
dvi_right(ch);
@@ -1312,7 +1284,7 @@ dvi_x0 (void)
}
void
-dvi_y (SIGNED_QUAD ch)
+dvi_y (int32_t ch)
{
dvi_state.y = ch;
dvi_down(ch);
@@ -1325,7 +1297,7 @@ dvi_y0 (void)
}
void
-dvi_z (SIGNED_QUAD ch)
+dvi_z (int32_t ch)
{
dvi_state.z = ch;
dvi_down(ch);
@@ -1340,52 +1312,24 @@ dvi_z0 (void)
static void
skip_fntdef (void)
{
- int area_len, name_len, i;
+ int area_len, name_len;
- get_signed_quad(dvi_file);
- get_signed_quad(dvi_file);
- get_signed_quad(dvi_file);
+ skip_bytes(12, dvi_file);
area_len = get_unsigned_byte(dvi_file);
name_len = get_unsigned_byte(dvi_file);
- for (i = 0; i < area_len + name_len; i++) {
- get_unsigned_byte(dvi_file);
- }
+ skip_bytes(area_len + name_len, dvi_file);
}
/* when pre-scanning the page, we process fntdef
and remove the fntdef opcode from the buffer */
-#define DO_FNTDEF(f) \
- if (scanning) { \
- SIGNED_QUAD tex_id = f(dvi_file); \
- if (linear) { \
- read_font_record(tex_id); \
- } else \
- skip_fntdef(); \
- --dvi_page_buf_index; \
- }
-
-static void
-do_fntdef1 (int scanning)
-{
- DO_FNTDEF(get_unsigned_byte)
-}
-
-static void
-do_fntdef2 (int scanning)
-{
- DO_FNTDEF(get_unsigned_pair)
-}
-
static void
-do_fntdef3 (int scanning)
+do_fntdef (int32_t tex_id)
{
- DO_FNTDEF(get_unsigned_triple)
-}
-
-static void
-do_fntdef4 (int scanning)
-{
- DO_FNTDEF(get_unsigned_quad)
+ if (linear)
+ read_font_record(tex_id);
+ else
+ skip_fntdef();
+ --dvi_page_buf_index;
}
void
@@ -1395,7 +1339,7 @@ dvi_set_font (int font_id)
}
static void
-do_fnt (SIGNED_QUAD tex_id)
+do_fnt (int32_t tex_id)
{
int i;
@@ -1405,7 +1349,7 @@ do_fnt (SIGNED_QUAD tex_id)
}
if (i == num_def_fonts) {
- ERROR("Tried to select a font that hasn't been defined: id=%ld", tex_id);
+ ERROR("Tried to select a font that hasn't been defined: id=%d", tex_id);
}
if (!def_fonts[i].used) {
@@ -1436,7 +1380,7 @@ do_fnt (SIGNED_QUAD tex_id)
}
static void
-do_xxx (UNSIGNED_QUAD size)
+do_xxx (int32_t size)
{
if (lr_mode < SKIMMING)
dvi_do_special(dvi_page_buffer + dvi_page_buf_index, size);
@@ -1546,28 +1490,25 @@ dvi_end_reflect (void)
#ifdef XETEX
static void
-do_native_font_def (int scanning)
+do_native_font_def (int32_t tex_id)
{
- if (scanning) {
- SIGNED_QUAD tex_id = get_signed_quad(dvi_file);
- if (linear) {
- read_native_font_record(tex_id);
- } else {
- UNSIGNED_PAIR flags;
- int name_length, i;
-
- get_unsigned_quad(dvi_file); /* skip point size */
- flags = get_unsigned_pair(dvi_file);
- name_length = (int) get_unsigned_byte(dvi_file);
- for (i = 0; i < name_length; ++i)
- get_unsigned_byte(dvi_file);
+ if (linear) {
+ read_native_font_record(tex_id);
+ } else {
+ unsigned int flags;
+ int name_length, i;
+
+ get_unsigned_quad(dvi_file); /* skip point size */
+ flags = get_unsigned_pair(dvi_file);
+ name_length = (int) get_unsigned_byte(dvi_file);
+ for (i = 0; i < name_length; ++i)
+ get_unsigned_byte(dvi_file);
+ get_unsigned_quad(dvi_file);
+ if (flags & XDV_FLAG_COLORED) {
get_unsigned_quad(dvi_file);
- if (flags & XDV_FLAG_COLORED) {
- get_unsigned_quad(dvi_file);
- }
}
- --dvi_page_buf_index; /* don't buffer the opcode */
}
+ --dvi_page_buf_index; /* don't buffer the opcode */
}
static void
@@ -1704,7 +1645,7 @@ dvi_do_page (double page_paper_height, double hmargin, double vmargin)
* other than SET_CHAR.
*/
if (opcode >= FNT_NUM_0 && opcode <= FNT_NUM_63) {
- do_fnt(opcode - FNT_NUM_0);
+ do_fnt(opcode-FNT_NUM_0);
continue;
}
@@ -1784,18 +1725,22 @@ dvi_do_page (double page_paper_height, double hmargin, double vmargin)
dvi_z(get_buffered_signed_num(opcode-Z1)); break;
case FNT1: case FNT2: case FNT3: case FNT4:
- do_fnt((SIGNED_QUAD)get_buffered_unsigned_num(opcode-FNT1)); break;
+ do_fnt(get_buffered_unsigned_num(opcode-FNT1)); break;
/* Specials */
case XXX1: case XXX2: case XXX3: case XXX4:
- do_xxx(get_buffered_unsigned_num(opcode-XXX1)); break;
+ {
+ int32_t size = get_buffered_unsigned_num(opcode-XXX1);
+ if (size < 0)
+ WARN("DVI: Special with %d bytes???", size);
+ else
+ do_xxx(size);
+ break;
+ }
- /* Font definition - skipped except in linear mode. */
- /* actually, these should not occur! */
- case FNT_DEF1: do_fntdef1(0); break;
- case FNT_DEF2: do_fntdef2(0); break;
- case FNT_DEF3: do_fntdef3(0); break;
- case FNT_DEF4: do_fntdef4(0); break;
+ /* These should not occur - processed during pre-scanning */
+ case FNT_DEF1: case FNT_DEF2: case FNT_DEF3: case FNT_DEF4:
+ break;
/* pTeX extension */
case PTEXDIR:
@@ -1807,8 +1752,8 @@ dvi_do_page (double page_paper_height, double hmargin, double vmargin)
case XDV_GLYPHS:
do_glyphs();
break;
+ /* should not occur - processed during pre-scanning */
case XDV_NATIVE_FONT_DEF:
- do_native_font_def(0); /* should not occur - processed during pre-scanning */
break;
#endif
case BEGIN_REFLECT:
@@ -1837,7 +1782,7 @@ dvi_do_page (double page_paper_height, double hmargin, double vmargin)
double
dvi_init (char *dvi_filename, double mag)
{
- long post_location;
+ int32_t post_location;
if (!dvi_filename) { /* no filename: reading from stdin, probably a pipe */
#ifdef WIN32
@@ -2053,7 +1998,7 @@ static int
scan_special (double *wd, double *ht, double *xo, double *yo, char *lm,
unsigned *minorversion,
int *do_enc, unsigned *key_bits, unsigned *permission, char *owner_pw, char *user_pw,
- const char *buf, UNSIGNED_QUAD size)
+ const char *buf, uint32_t size)
{
char *q;
const char *p = buf, *endptr;
@@ -2211,18 +2156,18 @@ scan_special (double *wd, double *ht, double *xo, double *yo, char *lm,
void
-dvi_scan_specials (long page_no,
+dvi_scan_specials (int page_no,
double *page_width, double *page_height,
double *x_offset, double *y_offset, char *landscape,
unsigned *minorversion,
int *do_enc, unsigned *key_bits, unsigned *permission, char *owner_pw, char *user_pw)
{
FILE *fp = dvi_file;
- long offset;
+ int32_t offset;
unsigned char opcode;
- static long buffered_page = -1;
+ static int buffered_page = -1;
#if XETEX
- UNSIGNED_PAIR len;
+ unsigned int len;
#endif
if (page_no == buffered_page)
@@ -2236,7 +2181,7 @@ dvi_scan_specials (long page_no,
ERROR("Invalid page number: %u", page_no);
offset = page_loc[page_no];
- seek_absolute(fp, offset);
+ xseek_absolute (fp, offset, "DVI");
}
while ((opcode = get_and_buffer_unsigned_byte(fp)) != EOP) {
@@ -2245,7 +2190,7 @@ dvi_scan_specials (long page_no,
continue;
else if (opcode == XXX1 || opcode == XXX2 ||
opcode == XXX3 || opcode == XXX4) {
- UNSIGNED_QUAD size = get_and_buffer_unsigned_byte(fp);
+ uint32_t size = get_and_buffer_unsigned_byte(fp);
switch (opcode) {
case XXX4: size = size * 0x100u + get_and_buffer_unsigned_byte(fp);
if (size > 0x7fff)
@@ -2302,11 +2247,9 @@ dvi_scan_specials (long page_no,
get_and_buffer_bytes(fp, 8);
break;
- case FNT_DEF1: do_fntdef1(1); break;
- case FNT_DEF2: do_fntdef2(1); break;
- case FNT_DEF3: do_fntdef3(1); break;
- case FNT_DEF4: do_fntdef4(1); break;
-
+ case FNT_DEF1: case FNT_DEF2: case FNT_DEF3: case FNT_DEF4:
+ do_fntdef(get_unsigned_num(fp, opcode-FNT_DEF1));
+ break;
#ifdef XETEX
case XDV_GLYPHS:
get_and_buffer_bytes(fp, 4); /* width */
@@ -2314,7 +2257,7 @@ dvi_scan_specials (long page_no,
get_and_buffer_bytes(fp, len * 10); /* 2 bytes ID + 8 bytes x,y-location per glyph */
break;
case XDV_NATIVE_FONT_DEF:
- do_native_font_def(1);
+ do_native_font_def(get_signed_quad(dvi_file));
break;
#endif
case BEGIN_REFLECT:
diff --git a/Build/source/texk/dvipdfm-x/dvi.h b/Build/source/texk/dvipdfm-x/dvi.h
index b5a219ff453..667bc76b961 100644
--- a/Build/source/texk/dvipdfm-x/dvi.h
+++ b/Build/source/texk/dvipdfm-x/dvi.h
@@ -40,37 +40,37 @@ extern void dvi_set_verbose (void);
extern double dvi_init (char *dvi_filename, double mag); /* may append .dvi or .xdv to filename */
extern void dvi_close (void); /* Closes data structures created by dvi_open */
-extern double dvi_tell_mag (void);
-extern double dvi_unit_size (void);
-extern double dvi_dev_xpos (void);
-extern double dvi_dev_ypos (void);
-extern unsigned dvi_npages (void);
-extern const char *dvi_comment (void);
+extern double dvi_tell_mag (void);
+extern double dvi_unit_size (void);
+extern double dvi_dev_xpos (void);
+extern double dvi_dev_ypos (void);
+extern unsigned int dvi_npages (void);
+extern const char *dvi_comment (void);
extern void dvi_vf_init (int dev_font_id);
extern void dvi_vf_finish (void);
extern void dvi_set_font (int font_id);
-extern void dvi_set (SIGNED_QUAD ch);
-extern void dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height);
+extern void dvi_set (int32_t ch);
+extern void dvi_rule (int32_t width, int32_t height);
-extern void dvi_right (SIGNED_QUAD x);
-extern void dvi_put (SIGNED_QUAD ch);
+extern void dvi_right (int32_t x);
+extern void dvi_put (int32_t ch);
extern void dvi_push (void);
extern void dvi_pop (void);
extern void dvi_w0 (void);
-extern void dvi_w (SIGNED_QUAD ch);
+extern void dvi_w (int32_t ch);
extern void dvi_x0 (void);
-extern void dvi_x (SIGNED_QUAD ch);
-extern void dvi_down (SIGNED_QUAD y);
-extern void dvi_y (SIGNED_QUAD ch);
+extern void dvi_x (int32_t ch);
+extern void dvi_down (int32_t y);
+extern void dvi_y (int32_t ch);
extern void dvi_y0 (void);
-extern void dvi_z (SIGNED_QUAD ch);
+extern void dvi_z (int32_t ch);
extern void dvi_z0 (void);
-extern void dvi_dir (UNSIGNED_BYTE dir);
+extern void dvi_dir (unsigned char dir);
extern void dvi_do_page (double paper_height, double x_offset, double y_offset);
-extern void dvi_scan_specials (long page_no,
+extern void dvi_scan_specials (int page_no,
double *width, double *height,
double *x_offset, double *y_offset,
char *landscape, unsigned *minorversion,
@@ -91,7 +91,7 @@ extern void dvi_tag_depth (void);
extern void dvi_untag_depth (void);
extern void dvi_compute_boxes (int flag);
-extern void dvi_do_special (const void *buffer, UNSIGNED_QUAD size);
+extern void dvi_do_special (const void *buffer, int32_t size);
/* allow other modules (pdfdev) to ask whether we're collecting box areas */
extern int dvi_is_tracking_boxes(void);
diff --git a/Build/source/texk/dvipdfm-x/dvipdfmx.c b/Build/source/texk/dvipdfm-x/dvipdfmx.c
index 93e90ebc4d6..e3b5541f7fc 100644
--- a/Build/source/texk/dvipdfm-x/dvipdfmx.c
+++ b/Build/source/texk/dvipdfm-x/dvipdfmx.c
@@ -747,7 +747,7 @@ error_cleanup (void)
static void
do_dvi_pages (void)
{
- long page_no, page_count, i, step;
+ int page_no, page_count, i, step;
double page_width, page_height;
double init_paper_width, init_paper_height;
pdf_rect mediabox;
diff --git a/Build/source/texk/dvipdfm-x/jp2image.c b/Build/source/texk/dvipdfm-x/jp2image.c
index 891957fb27d..9086fce620c 100644
--- a/Build/source/texk/dvipdfm-x/jp2image.c
+++ b/Build/source/texk/dvipdfm-x/jp2image.c
@@ -239,7 +239,6 @@ scan_file (ximage_info *info, FILE *fp)
size = file_size(fp);
- rewind(fp);
/* Should have already been checked before. */
/* JPEG 2000 Singature box */
diff --git a/Build/source/texk/dvipdfm-x/mfileio.c b/Build/source/texk/dvipdfm-x/mfileio.c
index 56b58fe8752..766801c2b2d 100644
--- a/Build/source/texk/dvipdfm-x/mfileio.c
+++ b/Build/source/texk/dvipdfm-x/mfileio.c
@@ -116,6 +116,15 @@ long file_size (FILE *file)
return (size);
}
+off_t xfile_size (FILE *file, const char *name)
+{
+ off_t size;
+ xseek_end (file, name);
+ size = xtell_position (file, name);
+ rewind (file);
+ return size;
+}
+
/* Unlike fgets, mfgets works with \r, \n, or \r\n end of lines. */
char *mfgets (char *buffer, unsigned long length, FILE *file)
{
diff --git a/Build/source/texk/dvipdfm-x/mfileio.h b/Build/source/texk/dvipdfm-x/mfileio.h
index 70afb15482f..d45673526d1 100644
--- a/Build/source/texk/dvipdfm-x/mfileio.h
+++ b/Build/source/texk/dvipdfm-x/mfileio.h
@@ -43,8 +43,6 @@ int mfclose (FILE *file, const char *function, int line);
#define MFCLOSE(file) fclose(file)
#endif
-extern UNSIGNED_BYTE read_byte (FILE *);
-
extern void seek_absolute (FILE *file, long pos);
extern void seek_relative (FILE *file, long pos);
@@ -54,6 +52,13 @@ extern long tell_position (FILE *file);
extern long file_size (FILE *file);
+#define xseek_absolute(file, pos, name) xfseeko (file, (off_t)(pos), SEEK_SET, name)
+#define xseek_relative(file, pos, name) xfseeko (file, (off_t)(pos), SEEK_CUR, name)
+#define xseek_end(file, name) xfseeko (file, (off_t)0, SEEK_END, name)
+#define xtell_position(file, name) xftello (file, name)
+
+extern off_t xfile_size (FILE *file, const char *name);
+
extern char *mfgets (char *buffer, unsigned long size, FILE *file);
extern char work_buffer[];
diff --git a/Build/source/texk/dvipdfm-x/numbers.c b/Build/source/texk/dvipdfm-x/numbers.c
index f5c4b6112e0..37a0f3d7c30 100644
--- a/Build/source/texk/dvipdfm-x/numbers.c
+++ b/Build/source/texk/dvipdfm-x/numbers.c
@@ -29,123 +29,120 @@
#include "mfileio.h"
#include "numbers.h"
-UNSIGNED_BYTE get_unsigned_byte (FILE *file)
+unsigned char get_unsigned_byte (FILE *file)
{
int ch;
if ((ch = fgetc (file)) < 0)
ERROR ("File ended prematurely\n");
- return (UNSIGNED_BYTE) ch;
+ return (unsigned char) ch;
}
void skip_bytes (unsigned int n, FILE *file)
{
- while (n > 0) {
+ while (n-- > 0)
get_unsigned_byte(file);
- n--;
- }
}
-SIGNED_BYTE get_signed_byte (FILE *file)
+signed char get_signed_byte (FILE *file)
{
int byte;
byte = get_unsigned_byte(file);
if (byte >= 0x80)
byte -= 0x100;
- return (SIGNED_BYTE) byte;
+ return (signed char) byte;
}
-UNSIGNED_PAIR get_unsigned_pair (FILE *file)
+unsigned short get_unsigned_pair (FILE *file)
{
- int i;
- UNSIGNED_BYTE byte;
- UNSIGNED_PAIR pair = 0;
- for (i=0; i<2; i++) {
- byte = get_unsigned_byte(file);
- pair = pair*0x100u + byte;
- }
+ unsigned short pair = get_unsigned_byte(file);
+ pair = (pair << 8) | get_unsigned_byte(file);
return pair;
}
-UNSIGNED_PAIR sget_unsigned_pair (unsigned char *s)
+unsigned short sget_unsigned_pair (unsigned char *s)
{
- int i;
- UNSIGNED_BYTE byte;
- UNSIGNED_PAIR pair = 0;
- for (i=0; i<2; i++) {
- byte = *(s++);
- pair = pair*0x100u + byte;
- }
+ unsigned short pair = *(s++);
+ pair = (pair << 8) | *(s++);
return pair;
}
-SIGNED_PAIR get_signed_pair (FILE *file)
+signed short get_signed_pair (FILE *file)
{
- int i;
- long pair = 0;
- for (i=0; i<2; i++) {
- pair = pair*0x100 + get_unsigned_byte(file);
- }
- if (pair >= 0x8000) {
- pair -= 0x10000l;
- }
- return (SIGNED_PAIR) pair;
+ signed short pair = get_signed_byte(file);
+ pair = (pair << 8) | get_unsigned_byte(file);
+ return pair;
}
-UNSIGNED_TRIPLE get_unsigned_triple(FILE *file)
+unsigned int get_unsigned_triple(FILE *file)
{
int i;
- long triple = 0;
+ unsigned int triple = 0;
for (i=0; i<3; i++) {
- triple = triple*0x100u + get_unsigned_byte(file);
+ triple = (triple << 8) | get_unsigned_byte(file);
}
- return (UNSIGNED_TRIPLE) triple;
+ return triple;
}
-SIGNED_TRIPLE get_signed_triple(FILE *file)
+signed int get_signed_triple(FILE *file)
{
int i;
- long triple = 0;
- for (i=0; i<3; i++) {
- triple = triple*0x100 + get_unsigned_byte(file);
+ signed int triple = get_signed_byte(file);
+ for (i=0; i<2; i++) {
+ triple = (triple << 8) | get_unsigned_byte(file);
}
- if (triple >= 0x800000l)
- triple -= 0x1000000l;
- return (SIGNED_TRIPLE) triple;
+ return triple;
}
-SIGNED_QUAD get_signed_quad(FILE *file)
+int32_t get_signed_quad(FILE *file)
{
- int byte, i;
- long quad = 0;
-
- /* Check sign on first byte before reading others */
- byte = get_unsigned_byte(file);
- quad = byte;
- if (quad >= 0x80)
- quad = byte - 0x100;
+ int i;
+ int32_t quad = get_signed_byte(file);
for (i=0; i<3; i++) {
- quad = quad*0x100 + get_unsigned_byte(file);
+ quad = (quad << 8) | get_unsigned_byte(file);
}
- return (SIGNED_QUAD) quad;
+ return quad;
}
-UNSIGNED_QUAD get_unsigned_quad(FILE *file)
+uint32_t get_unsigned_quad(FILE *file)
{
int i;
- unsigned long quad = 0;
+ uint32_t quad = 0;
for (i=0; i<4; i++) {
- quad = quad*0x100u + get_unsigned_byte(file);
+ quad = (quad << 8) | get_unsigned_byte(file);
+ }
+ return quad;
+}
+
+int32_t get_unsigned_num (FILE *file, unsigned char num)
+{
+ int32_t val = get_unsigned_byte (file);
+ switch (num) {
+ case 3: if (val > 0x7f)
+ val -= 0x100;
+ val = (val << 8) | get_unsigned_byte (file);
+ case 2: val = (val << 8) | get_unsigned_byte (file);
+ case 1: val = (val << 8) | get_unsigned_byte (file);
+ default: break;
}
- return (UNSIGNED_QUAD) quad;
+ return val;
+}
+
+/* Compute a signed quad that must be positive */
+uint32_t get_positive_quad (FILE *file, const char *type, const char *name)
+{
+ int32_t val = get_signed_quad (file);
+ if (val < 0)
+ ERROR ("Bad %s: negative %s: %d", type, name, val);
+ return (uint32_t)val;
}
-SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw)
+int32_t sqxfw (int32_t sq, fixword fw)
{
int sign = 1;
- unsigned long a, b, c, d, ad, bd, bc, ac;
- unsigned long e, f, g, h, i, j, k;
- unsigned long result;
+ uint32_t a, b, c, d, ad, bd, bc, ac;
+ uint32_t e, f, g, h, i, j, k;
+ int32_t result;
/* Make positive. */
if (sq < 0) {
sign = -sign;
@@ -155,21 +152,21 @@ SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw)
sign = -sign;
fw = -fw;
}
- a = ((unsigned long) sq) >> 16u;
- b = ((unsigned long) sq) & 0xffffu;
- c = ((unsigned long) fw) >> 16u;
- d = ((unsigned long) fw) & 0xffffu;
+ a = ((uint32_t) sq) >> 16;
+ b = ((uint32_t) sq) & 0xffffu;
+ c = ((uint32_t) fw) >> 16;
+ d = ((uint32_t) fw) & 0xffffu;
ad = a*d; bd = b*d; bc = b*c; ac = a*c;
- e = bd >> 16u;
- f = ad >> 16u;
+ e = bd >> 16;
+ f = ad >> 16;
g = ad & 0xffffu;
- h = bc >> 16u;
+ h = bc >> 16;
i = bc & 0xffffu;
- j = ac >> 16u;
+ j = ac >> 16;
k = ac & 0xffffu;
- result = (e+g+i + (1<<3)) >> 4u; /* 1<<3 is for rounding */
- result += (f+h+k) << 12u;
- result += j << 28u;
- return (sign > 0) ? result : result * -1L;
+ result = (e+g+i + (1<<3)) >> 4; /* 1<<3 is for rounding */
+ result += (f+h+k) << 12;
+ result += j << 28;
+ return (sign > 0) ? result : -result;
}
diff --git a/Build/source/texk/dvipdfm-x/numbers.h b/Build/source/texk/dvipdfm-x/numbers.h
index 5b45fd37ade..3b7b3924f0a 100644
--- a/Build/source/texk/dvipdfm-x/numbers.h
+++ b/Build/source/texk/dvipdfm-x/numbers.h
@@ -32,6 +32,16 @@
# include <stdint.h>
#endif
+#ifndef PRId64
+# ifdef _WIN32
+# define PRId64 "I64d"
+# elif SIZEOF_LONG == 8
+# define PRId64 "ld"
+# else
+# define PRId64 "lld"
+# endif
+#endif
+
/* When reading numbers from binary files 1, 2, or 3 bytes are
interpreted as either signed or unsigned.
@@ -42,25 +52,22 @@
mostly unsigned (uint32_t) and occasionally signed (int32_t).
*/
-typedef int UNSIGNED_BYTE, SIGNED_BYTE, SIGNED_PAIR;
-typedef unsigned UNSIGNED_PAIR;
-typedef long UNSIGNED_TRIPLE, SIGNED_TRIPLE, SIGNED_QUAD;
-typedef unsigned long UNSIGNED_QUAD;
-
-extern UNSIGNED_BYTE get_unsigned_byte (FILE *);
+extern unsigned char get_unsigned_byte (FILE *);
extern void skip_bytes (unsigned int, FILE *);
-extern SIGNED_BYTE get_signed_byte (FILE *);
-extern UNSIGNED_PAIR get_unsigned_pair (FILE *);
-extern UNSIGNED_PAIR sget_unsigned_pair (unsigned char *);
-extern SIGNED_PAIR get_signed_pair (FILE *);
-extern UNSIGNED_TRIPLE get_unsigned_triple (FILE *);
-extern SIGNED_TRIPLE get_signed_triple (FILE *);
-extern SIGNED_QUAD get_signed_quad (FILE *);
-extern UNSIGNED_QUAD get_unsigned_quad (FILE *);
-
-typedef signed long fixword;
-
-extern SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw);
+extern signed char get_signed_byte (FILE *);
+extern unsigned short get_unsigned_pair (FILE *);
+extern unsigned short sget_unsigned_pair (unsigned char *);
+extern signed short get_signed_pair (FILE *);
+extern unsigned int get_unsigned_triple (FILE *);
+extern signed int get_signed_triple (FILE *);
+extern int32_t get_signed_quad (FILE *);
+extern uint32_t get_unsigned_quad (FILE *);
+extern int32_t get_unsigned_num (FILE *, unsigned char);
+extern uint32_t get_positive_quad (FILE *, const char *, const char *);
+
+typedef int32_t fixword;
+
+extern int32_t sqxfw (int32_t sq, fixword fw);
#ifndef MAX
# define MAX(a,b) ((a)>(b)?(a):(b))
diff --git a/Build/source/texk/dvipdfm-x/otl_conf.c b/Build/source/texk/dvipdfm-x/otl_conf.c
index 761ddf896e3..da57eb655dd 100644
--- a/Build/source/texk/dvipdfm-x/otl_conf.c
+++ b/Build/source/texk/dvipdfm-x/otl_conf.c
@@ -472,7 +472,6 @@ otl_read_conf (const char *conf_name)
}
size = file_size(fp);
- rewind(fp);
if (verbose > VERBOSE_LEVEL_MIN) {
MESG("\n");
diff --git a/Build/source/texk/dvipdfm-x/pkfont.c b/Build/source/texk/dvipdfm-x/pkfont.c
index 6bcb2ab1b1e..31ce9862860 100644
--- a/Build/source/texk/dvipdfm-x/pkfont.c
+++ b/Build/source/texk/dvipdfm-x/pkfont.c
@@ -143,13 +143,13 @@ pdf_font_open_pkfont (pdf_font *font)
/* We are using Mask Image. Fill black is bit clear.
* Optimizing those codes doesn't improve things.
*/
-static long
-fill_black_run (unsigned char *dp, long left, long run_count)
+static uint32_t
+fill_black_run (unsigned char *dp, uint32_t left, uint32_t run_count)
{
const static unsigned char mask[8] = {
127u, 191u, 223u, 239u, 247u, 251u, 253u, 254u
};
- long right = left + run_count - 1;
+ uint32_t right = left + run_count - 1;
for ( ; left <= right; left++) {
dp[left / 8] &= mask[left % 8];
}
@@ -157,17 +157,17 @@ fill_black_run (unsigned char *dp, long left, long run_count)
}
/* Just skip bits. See decode_packed() */
-static long
-fill_white_run (long run_count)
+static uint32_t
+fill_white_run (uint32_t run_count)
{
return run_count;
}
-static long
-pk_packed_num (long *np, int dyn_f, unsigned char *dp, long pl)
+static uint32_t
+pk_packed_num (uint32_t *np, int dyn_f, unsigned char *dp, uint32_t pl)
{
- long nmbr = 0, i = *np;
- int nyb, j;
+ uint32_t nmbr = 0, i = *np;
+ int nyb, j;
#define get_nyb() ((i % 2) ? dp[i/2] & 0x0f : (dp[i/2] >> 4) & 0x0f)
if (i / 2 == pl) {
@@ -213,17 +213,17 @@ pk_packed_num (long *np, int dyn_f, unsigned char *dp, long pl)
#if DEBUG == 2
static void
-send_out (unsigned char *rowptr, long rowbytes, long wd, pdf_obj *stream)
+send_out (unsigned char *rowptr, uint32_t rowbytes, uint32_t wd, pdf_obj *stream)
#else
static void
-send_out (unsigned char *rowptr, long rowbytes, pdf_obj *stream)
+send_out (unsigned char *rowptr, uint32_t rowbytes, pdf_obj *stream)
#endif
{
pdf_add_stream(stream, (void *)rowptr, rowbytes);
#if DEBUG == 2
{
- long i, n, len = (wd + 7) / 8;
- int c;
+ uint32_t i, n, len = (wd + 7) / 8;
+ int c;
fputc('|', stderr);
for (n = 0; n < len; n++) {
c = rowptr[n];
@@ -243,13 +243,13 @@ send_out (unsigned char *rowptr, long rowbytes, pdf_obj *stream)
}
static int
-pk_decode_packed (pdf_obj *stream, long wd, long ht,
- int dyn_f, int run_color, unsigned char *dp, long pl)
+pk_decode_packed (pdf_obj *stream, uint32_t wd, uint32_t ht,
+ int dyn_f, int run_color, unsigned char *dp, uint32_t pl)
{
unsigned char *rowptr;
- long rowbytes;
- long i, np = 0;
- long run_count = 0, repeat_count = 0;
+ uint32_t rowbytes;
+ uint32_t i, np = 0;
+ uint32_t run_count = 0, repeat_count = 0;
rowbytes = (wd + 7) / 8;
rowptr = NEW(rowbytes, unsigned char);
@@ -262,7 +262,7 @@ pk_decode_packed (pdf_obj *stream, long wd, long ht,
MESG("\npkfont>> wd: %ld, ht: %ld, dyn_f: %d\n", wd, ht, dyn_f);
#endif
for (np = 0, i = 0; i < ht; i++) {
- long rowbits_left, nbits;
+ uint32_t rowbits_left, nbits;
repeat_count = 0;
memset(rowptr, 0xff, rowbytes); /* 1 is white */
@@ -343,11 +343,11 @@ pk_decode_packed (pdf_obj *stream, long wd, long ht,
}
static int
-pk_decode_bitmap (pdf_obj *stream, long wd, long ht,
- int dyn_f, int run_color, unsigned char *dp, long pl)
+pk_decode_bitmap (pdf_obj *stream, uint32_t wd, uint32_t ht,
+ int dyn_f, int run_color, unsigned char *dp, uint32_t pl)
{
unsigned char *rowptr, c;
- long i, j, rowbytes;
+ uint32_t i, j, rowbytes;
const static unsigned char mask[8] = {
0x80u, 0x40u, 0x20u, 0x10u, 0x08u, 0x04u, 0x02u, 0x01u
};
@@ -385,24 +385,16 @@ pk_decode_bitmap (pdf_obj *stream, long wd, long ht,
}
-/* Read PK font file */
-static void
-do_skip (FILE *fp, unsigned long length)
-{
- while (length-- > 0)
- fgetc(fp);
-}
-
static void
do_preamble (FILE *fp)
{
/* Check for id byte */
if (fgetc(fp) == 89) {
/* Skip comment */
- do_skip(fp, get_unsigned_byte(fp));
+ skip_bytes(get_unsigned_byte(fp), fp);
/* Skip other header info. It's normally used for verifying this
is the file wethink it is */
- do_skip(fp, 16);
+ skip_bytes(16, fp);
} else {
ERROR("embed_pk_font: PK ID byte is incorrect. Are you sure this is a PK file?");
}
@@ -411,11 +403,12 @@ do_preamble (FILE *fp)
struct pk_header_
{
- unsigned long pkt_len;
- SIGNED_QUAD chrcode;
- SIGNED_QUAD wd, dx, dy;
- SIGNED_QUAD bm_wd, bm_ht, bm_hoff, bm_voff;
- int dyn_f, run_color;
+ uint32_t pkt_len;
+ int32_t chrcode;
+ int32_t wd, dx, dy;
+ uint32_t bm_wd, bm_ht;
+ int32_t bm_hoff, bm_voff;
+ int dyn_f, run_color;
};
static int
@@ -424,33 +417,33 @@ read_pk_char_header (struct pk_header_ *h, unsigned char opcode, FILE *fp)
ASSERT(h);
if ((opcode & 4) == 0) { /* short */
- h->pkt_len = (opcode & 3) * 0x100U + get_unsigned_byte(fp);
+ h->pkt_len = (opcode & 3) << 8 | get_unsigned_byte(fp);
h->chrcode = get_unsigned_byte(fp);
h->wd = get_unsigned_triple(fp); /* TFM width */
h->dx = get_unsigned_byte(fp) << 16; /* horizontal escapement */
- h->dy = 0L;
+ h->dy = 0;
h->bm_wd = get_unsigned_byte(fp);
h->bm_ht = get_unsigned_byte(fp);
h->bm_hoff = get_signed_byte(fp);
h->bm_voff = get_signed_byte(fp);
h->pkt_len -= 8;
} else if ((opcode & 7) == 7) { /* long */
- h->pkt_len = get_unsigned_quad(fp);
+ h->pkt_len = get_positive_quad(fp, "PK", "pkt_len");
h->chrcode = get_signed_quad(fp);
h->wd = get_signed_quad(fp);
h->dx = get_signed_quad(fp); /* 16.16 fixed point number in pixels */
h->dy = get_signed_quad(fp);
- h->bm_wd = get_signed_quad(fp);
- h->bm_ht = get_signed_quad(fp);
+ h->bm_wd = get_positive_quad(fp, "PK", "bm_wd");
+ h->bm_ht = get_positive_quad(fp, "PK", "bm_ht");
h->bm_hoff = get_signed_quad(fp);
h->bm_voff = get_signed_quad(fp);
h->pkt_len -= 28;
} else { /* extended short */
- h->pkt_len = (opcode & 3) * 0x10000UL + get_unsigned_pair(fp);
+ h->pkt_len = (opcode & 3) << 16 | get_unsigned_pair(fp);
h->chrcode = get_unsigned_byte(fp);
h->wd = get_unsigned_triple(fp);
h->dx = get_unsigned_pair(fp) << 16;
- h->dy = 0x0L;
+ h->dy = 0;
h->bm_wd = get_unsigned_pair(fp);
h->bm_ht = get_unsigned_pair(fp);
h->bm_hoff = get_signed_pair(fp);
@@ -461,7 +454,7 @@ read_pk_char_header (struct pk_header_ *h, unsigned char opcode, FILE *fp)
h->dyn_f = opcode / 16;
h->run_color = (opcode & 8) ? 1 : 0;
- if (h->chrcode > 0xff)
+ if ((uint32_t)h->chrcode > 0xff)
{
WARN("Unable to handle long characters in PK files: code=0x%04x", h->chrcode);
return -1;
@@ -474,10 +467,10 @@ read_pk_char_header (struct pk_header_ *h, unsigned char opcode, FILE *fp)
static pdf_obj *
create_pk_CharProc_stream (struct pk_header_ *pkh,
double chrwid,
- unsigned char *pkt_ptr, long pkt_len)
+ unsigned char *pkt_ptr, uint32_t pkt_len)
{
pdf_obj *stream; /* charproc */
- long llx, lly, urx, ury;
+ int llx, lly, urx, ury;
int len;
llx = -pkh->bm_hoff;
@@ -496,7 +489,7 @@ create_pk_CharProc_stream (struct pk_header_ *pkh,
* consistent with write_number() in pdfobj.c.
*/
len = pdf_sprint_number(work_buffer, chrwid);
- len += sprintf (work_buffer + len, " 0 %ld %ld %ld %ld d1\n", llx, lly, urx, ury);
+ len += sprintf (work_buffer + len, " 0 %d %d %d %d d1\n", llx, lly, urx, ury);
pdf_add_stream(stream, work_buffer, len);
/*
* Acrobat dislike transformation [0 0 0 0 dx dy].
@@ -509,9 +502,9 @@ create_pk_CharProc_stream (struct pk_header_ *pkh,
*/
if (pkh->bm_wd != 0 && pkh->bm_ht != 0 && pkt_len > 0) {
/* Scale and translate origin to lower left corner for raster data */
- len = sprintf (work_buffer, "q\n%ld 0 0 %ld %ld %ld cm\n", pkh->bm_wd, pkh->bm_ht, llx, lly);
+ len = sprintf (work_buffer, "q\n%d 0 0 %d %d %d cm\n", pkh->bm_wd, pkh->bm_ht, llx, lly);
pdf_add_stream(stream, work_buffer, len);
- len = sprintf (work_buffer, "BI\n/W %ld\n/H %ld\n/IM true\n/BPC 1\nID ", pkh->bm_wd, pkh->bm_ht);
+ len = sprintf (work_buffer, "BI\n/W %d\n/H %d\n/IM true\n/BPC 1\nID ", pkh->bm_wd, pkh->bm_ht);
pdf_add_stream(stream, work_buffer, len);
/* Add bitmap data */
if (pkh->dyn_f == 14) /* bitmap */
@@ -606,7 +599,7 @@ pdf_font_load_pkfont (pdf_font *font)
ident, pkh.chrcode);
if (!usedchars[pkh.chrcode & 0xff])
- do_skip(fp, pkh.pkt_len);
+ skip_bytes(pkh.pkt_len, fp);
else {
char *charname;
pdf_obj *charproc;
@@ -656,11 +649,16 @@ pdf_font_load_pkfont (pdf_font *font)
} else { /* A command byte */
switch (opcode) {
case PK_NO_OP: break;
- case PK_XXX1: do_skip(fp, get_unsigned_byte(fp)); break;
- case PK_XXX2: do_skip(fp, get_unsigned_pair(fp)); break;
- case PK_XXX3: do_skip(fp, get_unsigned_triple(fp)); break;
- case PK_XXX4: do_skip(fp, get_unsigned_quad(fp)); break;
- case PK_YYY: do_skip(fp, 4); break;
+ case PK_XXX1: case PK_XXX2: case PK_XXX3: case PK_XXX4:
+ {
+ int32_t len = get_unsigned_num(fp, opcode-PK_XXX1);
+ if (len < 0)
+ WARN("PK: Special with %d bytes???", len);
+ else
+ skip_bytes(len, fp);
+ break;
+ }
+ case PK_YYY: skip_bytes(4, fp); break;
case PK_PRE: do_preamble(fp); break;
}
}
diff --git a/Build/source/texk/dvipdfm-x/specials.c b/Build/source/texk/dvipdfm-x/specials.c
index b853f7e88d4..3d173011b0a 100644
--- a/Build/source/texk/dvipdfm-x/specials.c
+++ b/Build/source/texk/dvipdfm-x/specials.c
@@ -319,7 +319,7 @@ static void
init_special (struct spc_handler *special,
struct spc_env *spe,
struct spc_arg *args,
- const char *p, long size,
+ const char *p, uint32_t size,
double x_user, double y_user, double mag)
{
@@ -552,7 +552,7 @@ print_error (const char *name, struct spc_env *spe, struct spc_arg *ap)
}
int
-spc_exec_special (const char *buffer, long size,
+spc_exec_special (const char *buffer, int32_t size,
double x_user, double y_user, double mag)
{
int error = -1;
diff --git a/Build/source/texk/dvipdfm-x/specials.h b/Build/source/texk/dvipdfm-x/specials.h
index c0b95ecc9e6..c748280156d 100644
--- a/Build/source/texk/dvipdfm-x/specials.h
+++ b/Build/source/texk/dvipdfm-x/specials.h
@@ -70,7 +70,7 @@ extern int spc_exec_at_end_page (void);
extern int spc_exec_at_begin_document (void);
extern int spc_exec_at_end_document (void);
-extern int spc_exec_special (const char *p, long size,
+extern int spc_exec_special (const char *p, int32_t size,
double x_user, double y_user, double mag);
#endif /* _SPECIALS_H_ */
diff --git a/Build/source/texk/dvipdfm-x/tfm.c b/Build/source/texk/dvipdfm-x/tfm.c
index f7334d413ce..706abcd4fbd 100644
--- a/Build/source/texk/dvipdfm-x/tfm.c
+++ b/Build/source/texk/dvipdfm-x/tfm.c
@@ -65,33 +65,33 @@ static int verbose = 0;
struct tfm_font
{
#ifndef WITHOUT_ASCII_PTEX
- UNSIGNED_BYTE id;
- UNSIGNED_BYTE nt;
+ int id;
+ int nt;
#endif /* !WITHOUT_ASCII_PTEX */
#ifndef WITHOUT_OMEGA
- SIGNED_QUAD level;
+ int32_t level;
#endif /* !WITHOUT_OMEGA */
- UNSIGNED_QUAD wlenfile;
- UNSIGNED_QUAD wlenheader;
- UNSIGNED_QUAD bc, ec;
- UNSIGNED_QUAD nwidths, nheights, ndepths;
- UNSIGNED_QUAD nitcor, nlig, nkern, nextens;
- UNSIGNED_QUAD nfonparm;
+ uint32_t wlenfile;
+ uint32_t wlenheader;
+ uint32_t bc, ec;
+ uint32_t nwidths, nheights, ndepths;
+ uint32_t nitcor, nlig, nkern, nextens;
+ uint32_t nfonparm;
#ifndef WITHOUT_OMEGA
- UNSIGNED_QUAD fontdir;
- UNSIGNED_QUAD nco, ncw, npc;
+ uint32_t fontdir;
+ uint32_t nco, ncw, npc;
#endif /* !WITHOUT_OMEGA */
- SIGNED_QUAD *header;
+ fixword *header;
#ifndef WITHOUT_ASCII_PTEX
- UNSIGNED_PAIR *chartypes;
+ unsigned short *chartypes;
#endif /* !WITHOUT_ASCII_PTEX */
- UNSIGNED_QUAD *char_info;
- UNSIGNED_PAIR *width_index;
- UNSIGNED_BYTE *height_index;
- UNSIGNED_BYTE *depth_index;
- SIGNED_QUAD *width;
- SIGNED_QUAD *height;
- SIGNED_QUAD *depth;
+ uint32_t *char_info;
+ unsigned short *width_index;
+ unsigned char *height_index;
+ unsigned char *depth_index;
+ fixword *width;
+ fixword *height;
+ fixword *depth;
};
static void
@@ -163,8 +163,8 @@ tfm_font_clear (struct tfm_font *tfm)
struct coverage
{
- long first_char;
- long num_chars;
+ int first_char;
+ int num_chars;
};
/*
@@ -205,8 +205,8 @@ release_range_map (struct range_map *map)
RELEASE(map);
}
-static long
-lookup_char (const struct char_map *map, long charcode)
+static int
+lookup_char (const struct char_map *map, int charcode)
{
if (charcode >= map->coverage.first_char &&
charcode <= map->coverage.first_char + map->coverage.num_chars)
@@ -215,10 +215,10 @@ lookup_char (const struct char_map *map, long charcode)
return -1;
}
-static long
-lookup_range (const struct range_map *map, long charcode)
+static int
+lookup_range (const struct range_map *map, int charcode)
{
- long idx;
+ int idx;
for (idx = map->num_coverages - 1; idx >= 0 &&
charcode >= map->coverages[idx].first_char; idx--) {
@@ -248,7 +248,7 @@ struct font_metric
char *codingscheme;
int fontdir;
- long firstchar, lastchar;
+ int firstchar, lastchar;
fixword *widths;
fixword *heights;
@@ -331,10 +331,10 @@ tfm_set_verbose (void)
}
-static long
-fread_fwords (SIGNED_QUAD *words, SIGNED_QUAD nmemb, FILE *fp)
+static int
+fread_fwords (fixword *words, int32_t nmemb, FILE *fp)
{
- long i;
+ int i;
for (i = 0; i < nmemb; i++)
words[i] = get_signed_quad(fp);
@@ -342,10 +342,10 @@ fread_fwords (SIGNED_QUAD *words, SIGNED_QUAD nmemb, FILE *fp)
return nmemb*4;
}
-static long
-fread_uquads (UNSIGNED_QUAD *quads, SIGNED_QUAD nmemb, FILE *fp)
+static int
+fread_uquads (uint32_t *quads, int32_t nmemb, FILE *fp)
{
- long i;
+ int i;
for (i = 0; i < nmemb; i++) {
quads[i] = get_unsigned_quad(fp);
@@ -358,9 +358,9 @@ fread_uquads (UNSIGNED_QUAD *quads, SIGNED_QUAD nmemb, FILE *fp)
* TFM and JFM
*/
static void
-tfm_check_size (struct tfm_font *tfm, SIGNED_QUAD tfm_file_size)
+tfm_check_size (struct tfm_font *tfm, off_t tfm_file_size)
{
- UNSIGNED_QUAD expected_size = 6;
+ uint32_t expected_size = 6;
/* Removed the warning message caused by EC TFM metric files.
*
@@ -374,7 +374,7 @@ tfm_check_size (struct tfm_font *tfm, SIGNED_QUAD tfm_file_size)
}
}
*/
- if (tfm_file_size < tfm->wlenfile * 4) {
+ if ((int64_t)tfm_file_size < (int64_t)tfm->wlenfile * 4) {
ERROR("Can't proceed...");
}
@@ -394,9 +394,9 @@ tfm_check_size (struct tfm_font *tfm, SIGNED_QUAD tfm_file_size)
}
#endif /* !WITHOUT_ASCII_PTEX */
if (expected_size != tfm->wlenfile) {
- WARN("TFM file size is expected to be %ld bytes but it says it is %ld bytes!",
- expected_size * 4, tfm->wlenfile * 4);
- if (tfm_file_size > expected_size *4) {
+ WARN("TFM file size is expected to be %" PRId64 " bytes but it says it is %" PRId64 "bytes!",
+ (int64_t)expected_size * 4, (int64_t)tfm->wlenfile * 4);
+ if ((int64_t)tfm_file_size > (int64_t)expected_size *4) {
WARN("Proceeding nervously...");
} else {
ERROR("Can't proceed...");
@@ -405,11 +405,11 @@ tfm_check_size (struct tfm_font *tfm, SIGNED_QUAD tfm_file_size)
}
static void
-tfm_get_sizes (FILE *tfm_file, SIGNED_QUAD tfm_file_size, struct tfm_font *tfm)
+tfm_get_sizes (FILE *tfm_file, off_t tfm_file_size, struct tfm_font *tfm)
{
#ifndef WITHOUT_ASCII_PTEX
{
- UNSIGNED_PAIR first_hword;
+ unsigned short first_hword;
/*
* The first half word of TFM/JFM is TFM ID for JFM or size of
@@ -454,11 +454,11 @@ tfm_get_sizes (FILE *tfm_file, SIGNED_QUAD tfm_file_size, struct tfm_font *tfm)
static void
jfm_do_char_type_array (FILE *tfm_file, struct tfm_font *tfm)
{
- UNSIGNED_PAIR charcode;
- UNSIGNED_PAIR chartype;
- long i;
+ unsigned short charcode;
+ unsigned short chartype;
+ int i;
- tfm->chartypes = NEW(65536, UNSIGNED_PAIR);
+ tfm->chartypes = NEW(65536, unsigned short);
for (i = 0; i < 65536; i++) {
tfm->chartypes[i] = 0;
}
@@ -474,7 +474,7 @@ jfm_make_charmap (struct font_metric *fm, struct tfm_font *tfm)
{
if (tfm->nt > 1) {
struct char_map *map;
- long code;
+ int code;
fm->charmap.type = MAPTYPE_CHAR;
fm->charmap.data = map = NEW(1, struct char_map);
@@ -513,8 +513,9 @@ jfm_make_charmap (struct font_metric *fm, struct tfm_font *tfm)
static void
tfm_unpack_arrays (struct font_metric *fm, struct tfm_font *tfm)
{
- UNSIGNED_QUAD charinfo;
- UNSIGNED_PAIR width_index, height_index, depth_index;
+ uint32_t charinfo;
+ unsigned short width_index;
+ unsigned char height_index, depth_index;
int i;
fm->widths = NEW(256, fixword);
@@ -528,9 +529,9 @@ tfm_unpack_arrays (struct font_metric *fm, struct tfm_font *tfm)
for (i = tfm->bc; i <= tfm->ec; i++ ) {
charinfo = tfm->char_info[i - tfm->bc];
- width_index = (charinfo / 16777216ul);
- height_index = (charinfo / 0x100000ul) & 0xf;
- depth_index = (charinfo / 0x10000ul) & 0xf;
+ width_index = (charinfo >> 24);
+ height_index = (charinfo >> 20) & 0xf;
+ depth_index = (charinfo >> 16) & 0xf;
fm->widths [i] = tfm->width [width_index];
fm->heights[i] = tfm->height[height_index];
fm->depths [i] = tfm->depth [depth_index];
@@ -540,7 +541,7 @@ tfm_unpack_arrays (struct font_metric *fm, struct tfm_font *tfm)
}
static int
-sput_bigendian (char *s, SIGNED_QUAD v, int n)
+sput_bigendian (char *s, int32_t v, int n)
{
int i;
@@ -583,9 +584,9 @@ tfm_unpack_header (struct font_metric *fm, struct tfm_font *tfm)
#ifndef WITHOUT_OMEGA
static void
-ofm_check_size_one (struct tfm_font *tfm, SIGNED_QUAD ofm_file_size)
+ofm_check_size_one (struct tfm_font *tfm, off_t ofm_file_size)
{
- UNSIGNED_QUAD ofm_size = 14;
+ uint32_t ofm_size = 14;
ofm_size += 2*(tfm->ec - tfm->bc + 1);
ofm_size += tfm->wlenheader;
@@ -604,36 +605,36 @@ ofm_check_size_one (struct tfm_font *tfm, SIGNED_QUAD ofm_file_size)
}
static void
-ofm_get_sizes (FILE *ofm_file, UNSIGNED_QUAD ofm_file_size, struct tfm_font *tfm)
+ofm_get_sizes (FILE *ofm_file, off_t ofm_file_size, struct tfm_font *tfm)
{
tfm->level = get_signed_quad(ofm_file);
- tfm->wlenfile = get_signed_quad(ofm_file);
- tfm->wlenheader = get_signed_quad(ofm_file);
- tfm->bc = get_signed_quad(ofm_file);
- tfm->ec = get_signed_quad(ofm_file);
+ tfm->wlenfile = get_positive_quad(ofm_file, "OFM", "wlenfile");
+ tfm->wlenheader = get_positive_quad(ofm_file, "OFM", "wlenheader");
+ tfm->bc = get_positive_quad(ofm_file, "OFM", "bc");
+ tfm->ec = get_positive_quad(ofm_file, "OFM", "ec");
if (tfm->ec < tfm->bc) {
ERROR("OFM file error: ec(%u) < bc(%u) ???", tfm->ec, tfm->bc);
}
- tfm->nwidths = get_signed_quad(ofm_file);
- tfm->nheights = get_signed_quad(ofm_file);
- tfm->ndepths = get_signed_quad(ofm_file);
- tfm->nitcor = get_signed_quad(ofm_file);
- tfm->nlig = get_signed_quad(ofm_file);
- tfm->nkern = get_signed_quad(ofm_file);
- tfm->nextens = get_signed_quad(ofm_file);
- tfm->nfonparm = get_signed_quad(ofm_file);
- tfm->fontdir = get_signed_quad(ofm_file);
+ tfm->nwidths = get_positive_quad(ofm_file, "OFM", "nwidths");
+ tfm->nheights = get_positive_quad(ofm_file, "OFM", "nheights");
+ tfm->ndepths = get_positive_quad(ofm_file, "OFM", "ndepths");
+ tfm->nitcor = get_positive_quad(ofm_file, "OFM", "nitcor");
+ tfm->nlig = get_positive_quad(ofm_file, "OFM", "nlig");
+ tfm->nkern = get_positive_quad(ofm_file, "OFM", "nkern");
+ tfm->nextens = get_positive_quad(ofm_file, "OFM", "nextens");
+ tfm->nfonparm = get_positive_quad(ofm_file, "OFM", "nfonparm");
+ tfm->fontdir = get_positive_quad(ofm_file, "OFM", "fontdir");
if (tfm->fontdir) {
WARN("I may be interpreting a font direction incorrectly.");
}
if (tfm->level == 0) {
ofm_check_size_one(tfm, ofm_file_size);
} else if (tfm->level == 1) {
- tfm->nco = get_signed_quad(ofm_file);
- tfm->ncw = get_signed_quad(ofm_file);
- tfm->npc = get_signed_quad(ofm_file);
- seek_absolute(ofm_file, 4*(tfm->nco - tfm->wlenheader));
+ tfm->nco = get_positive_quad(ofm_file, "OFM", "nco");
+ tfm->ncw = get_positive_quad(ofm_file, "OFM", "nco");
+ tfm->npc = get_positive_quad(ofm_file, "OFM", "npc");
+ xseek_absolute(ofm_file, 4*(off_t)(tfm->nco - tfm->wlenheader), "OFM");
} else {
ERROR("Can't handle OFM files with level > 1");
}
@@ -644,21 +645,21 @@ ofm_get_sizes (FILE *ofm_file, UNSIGNED_QUAD ofm_file_size, struct tfm_font *tfm
static void
ofm_do_char_info_zero (FILE *tfm_file, struct tfm_font *tfm)
{
- UNSIGNED_QUAD num_chars;
+ uint32_t num_chars;
num_chars = tfm->ec - tfm->bc + 1;
if (num_chars != 0) {
- UNSIGNED_QUAD i;
+ uint32_t i;
- tfm->width_index = NEW(num_chars, UNSIGNED_PAIR);
- tfm->height_index = NEW(num_chars, UNSIGNED_BYTE);
- tfm->depth_index = NEW(num_chars, UNSIGNED_BYTE);
+ tfm->width_index = NEW(num_chars, unsigned short);
+ tfm->height_index = NEW(num_chars, unsigned char);
+ tfm->depth_index = NEW(num_chars, unsigned char);
for (i = 0; i < num_chars; i++) {
tfm->width_index [i] = get_unsigned_pair(tfm_file);
tfm->height_index[i] = get_unsigned_byte(tfm_file);
tfm->depth_index [i] = get_unsigned_byte(tfm_file);
/* Ignore remaining quad */
- get_unsigned_quad(tfm_file);
+ skip_bytes(4, tfm_file);
}
}
}
@@ -666,19 +667,19 @@ ofm_do_char_info_zero (FILE *tfm_file, struct tfm_font *tfm)
static void
ofm_do_char_info_one (FILE *tfm_file, struct tfm_font *tfm)
{
- UNSIGNED_QUAD num_char_infos;
- UNSIGNED_QUAD num_chars;
+ uint32_t num_char_infos;
+ uint32_t num_chars;
num_char_infos = tfm->ncw / (3 + (tfm->npc / 2));
num_chars = tfm->ec - tfm ->bc + 1;
if (num_chars != 0) {
- UNSIGNED_QUAD i;
- UNSIGNED_QUAD char_infos_read;
+ uint32_t i;
+ uint32_t char_infos_read;
- tfm->width_index = NEW(num_chars, UNSIGNED_PAIR);
- tfm->height_index = NEW(num_chars, UNSIGNED_BYTE);
- tfm->depth_index = NEW(num_chars, UNSIGNED_BYTE);
+ tfm->width_index = NEW(num_chars, unsigned short);
+ tfm->height_index = NEW(num_chars, unsigned char);
+ tfm->depth_index = NEW(num_chars, unsigned char);
char_infos_read = 0;
for (i = 0; i < num_chars &&
char_infos_read < num_char_infos; i++) {
@@ -688,7 +689,7 @@ ofm_do_char_info_one (FILE *tfm_file, struct tfm_font *tfm)
tfm->height_index[i] = get_unsigned_byte(tfm_file);
tfm->depth_index [i] = get_unsigned_byte(tfm_file);
/* Ignore next quad */
- get_unsigned_quad(tfm_file);
+ skip_bytes(4, tfm_file);
repeats = get_unsigned_pair(tfm_file);
/* Skip params */
for (j = 0; j < tfm->npc; j++) {
@@ -715,9 +716,9 @@ ofm_do_char_info_one (FILE *tfm_file, struct tfm_font *tfm)
static void
ofm_unpack_arrays (struct font_metric *fm,
- struct tfm_font *tfm, UNSIGNED_QUAD num_chars)
+ struct tfm_font *tfm, uint32_t num_chars)
{
- long i;
+ int i;
fm->widths = NEW(tfm->bc + num_chars, fixword);
fm->heights = NEW(tfm->bc + num_chars, fixword);
@@ -730,7 +731,7 @@ ofm_unpack_arrays (struct font_metric *fm,
}
static void
-read_ofm (struct font_metric *fm, FILE *ofm_file, UNSIGNED_QUAD ofm_file_size)
+read_ofm (struct font_metric *fm, FILE *ofm_file, off_t ofm_file_size)
{
struct tfm_font tfm;
@@ -776,7 +777,7 @@ read_ofm (struct font_metric *fm, FILE *ofm_file, UNSIGNED_QUAD ofm_file_size)
#endif /* !WITHOUT_OMEGA */
static void
-read_tfm (struct font_metric *fm, FILE *tfm_file, UNSIGNED_QUAD tfm_file_size)
+read_tfm (struct font_metric *fm, FILE *tfm_file, off_t tfm_file_size)
{
struct tfm_font tfm;
@@ -800,7 +801,7 @@ read_tfm (struct font_metric *fm, FILE *tfm_file, UNSIGNED_QUAD tfm_file_size)
}
#endif /* !WITHOUT_ASCII_PTEX */
if (tfm.ec - tfm.bc + 1 > 0) {
- tfm.char_info = NEW(tfm.ec - tfm.bc + 1, UNSIGNED_QUAD);
+ tfm.char_info = NEW(tfm.ec - tfm.bc + 1, uint32_t);
fread_uquads(tfm.char_info, tfm.ec - tfm.bc + 1, tfm_file);
}
if (tfm.nwidths > 0) {
@@ -828,7 +829,7 @@ tfm_open (const char *tfm_name, int must_exist)
{
FILE *tfm_file;
int i, format = TFM_FORMAT;
- UNSIGNED_QUAD tfm_file_size;
+ off_t tfm_file_size;
char *file_name = NULL;
for (i = 0; i < numfms; i++) {
@@ -918,7 +919,9 @@ tfm_open (const char *tfm_name, int must_exist)
RELEASE(file_name);
- tfm_file_size = file_size(tfm_file);
+ tfm_file_size = xfile_size (tfm_file, "TFM/OFM");
+ if (tfm_file_size > 0x1ffffffff)
+ ERROR("TFM/OFM file size exceeds 33-bit");
if (tfm_file_size < 24) {
ERROR("TFM/OFM file too small to be a valid file.");
}
@@ -965,10 +968,10 @@ tfm_close_all (void)
} while (0)
fixword
-tfm_get_fw_width (int font_id, SIGNED_QUAD ch)
+tfm_get_fw_width (int font_id, int32_t ch)
{
struct font_metric *fm;
- long idx = 0;
+ int idx = 0;
CHECK_ID(font_id);
@@ -996,10 +999,10 @@ tfm_get_fw_width (int font_id, SIGNED_QUAD ch)
}
fixword
-tfm_get_fw_height (int font_id, SIGNED_QUAD ch)
+tfm_get_fw_height (int font_id, int32_t ch)
{
struct font_metric *fm;
- long idx = 0;
+ int idx = 0;
CHECK_ID(font_id);
@@ -1027,10 +1030,10 @@ tfm_get_fw_height (int font_id, SIGNED_QUAD ch)
}
fixword
-tfm_get_fw_depth (int font_id, SIGNED_QUAD ch)
+tfm_get_fw_depth (int font_id, int32_t ch)
{
struct font_metric *fm;
- long idx = 0;
+ int idx = 0;
CHECK_ID(font_id);
@@ -1063,20 +1066,20 @@ tfm_get_fw_depth (int font_id, SIGNED_QUAD ch)
* as a (double) fraction of the design size.
*/
double
-tfm_get_width (int font_id, SIGNED_QUAD ch)
+tfm_get_width (int font_id, int32_t ch)
{
return ((double) tfm_get_fw_width(font_id, ch)/FWBASE);
}
#if 0
double
-tfm_get_height (int font_id, SIGNED_QUAD ch)
+tfm_get_height (int font_id, int32_t ch)
{
return ((double) tfm_get_fw_height(font_id, ch)/FWBASE);
}
double
-tfm_get_depth (int font_id, SIGNED_QUAD ch)
+tfm_get_depth (int font_id, Sint32_t ch)
{
return ((double) tfm_get_fw_depth(font_id, ch)/FWBASE);
}
@@ -1096,7 +1099,7 @@ tfm_string_width (int font_id, const unsigned char *s, unsigned len)
#ifndef WITHOUT_ASCII_PTEX
if (fm->source == SOURCE_TYPE_JFM) {
for (i = 0; i < len/2; i++) {
- SIGNED_QUAD ch;
+ int32_t ch;
ch = (s[2*i] << 8)|s[2*i+1];
result += tfm_get_fw_width(font_id, ch);
@@ -1123,7 +1126,7 @@ tfm_string_depth (int font_id, const unsigned char *s, unsigned len)
#ifndef WITHOUT_ASCII_PTEX
if (fm->source == SOURCE_TYPE_JFM) {
for (i = 0; i < len/2; i++) {
- SIGNED_QUAD ch;
+ int32_t ch;
ch = (s[2*i] << 8)|s[2*i+1];
result += tfm_get_fw_depth(font_id, ch);
@@ -1150,7 +1153,7 @@ tfm_string_height (int font_id, const unsigned char *s, unsigned len)
#ifndef WITHOUT_ASCII_PTEX
if (fm->source == SOURCE_TYPE_JFM) {
for (i = 0; i < len/2; i++) {
- SIGNED_QUAD ch;
+ int32_t ch;
ch = (s[2*i] << 8)|s[2*i+1];
result += tfm_get_fw_height(font_id, ch);
diff --git a/Build/source/texk/dvipdfm-x/tfm.h b/Build/source/texk/dvipdfm-x/tfm.h
index 5c393ad20ed..7ce1a688ab1 100644
--- a/Build/source/texk/dvipdfm-x/tfm.h
+++ b/Build/source/texk/dvipdfm-x/tfm.h
@@ -30,15 +30,15 @@ extern void tfm_set_verbose (void);
extern int tfm_open (const char * tex_name, int must_exist);
extern void tfm_close_all (void);
-extern double tfm_get_width (int font_id, SIGNED_QUAD ch);
+extern double tfm_get_width (int font_id, int32_t ch);
#if 0
-extern double tfm_get_height (int font_id, SIGNED_QUAD ch);
-extern double tfm_get_depth (int font_id, SIGNED_QUAD ch);
+extern double tfm_get_height (int font_id, int32_t ch);
+extern double tfm_get_depth (int font_id, int32_t ch);
#endif
-extern fixword tfm_get_fw_width (int font_id, SIGNED_QUAD ch);
-extern fixword tfm_get_fw_height (int font_id, SIGNED_QUAD ch);
-extern fixword tfm_get_fw_depth (int font_id, SIGNED_QUAD ch);
+extern fixword tfm_get_fw_width (int font_id, int32_t ch);
+extern fixword tfm_get_fw_height (int font_id, int32_t ch);
+extern fixword tfm_get_fw_depth (int font_id, int32_t ch);
extern fixword tfm_string_width (int font_id, const unsigned char *s, unsigned len);
extern fixword tfm_string_depth (int font_id, const unsigned char *s, unsigned len);
diff --git a/Build/source/texk/dvipdfm-x/vf.c b/Build/source/texk/dvipdfm-x/vf.c
index 151f8ed707d..14c3b9ef663 100644
--- a/Build/source/texk/dvipdfm-x/vf.c
+++ b/Build/source/texk/dvipdfm-x/vf.c
@@ -77,15 +77,6 @@ struct vf
struct vf *vf_fonts = NULL;
int num_vf_fonts = 0, max_vf_fonts = 0;
-/* Set NAME to a signed quad that must be positive */
-static uint32_t get_positive_quad (FILE *vf_file, const char *name)
-{
- int32_t val = get_signed_quad (vf_file);
- if (val < 0)
- ERROR ("Bad VF: negative %s: %d", name, val);
- return (uint32_t)val;
-}
-
static void read_header(FILE *vf_file, int thisfont)
{
/* Check for usual signature */
@@ -100,7 +91,7 @@ static void read_header(FILE *vf_file, int thisfont)
/* Skip checksum */
skip_bytes (4, vf_file);
- vf_fonts[thisfont].design_size = get_positive_quad(vf_file, "design_size");
+ vf_fonts[thisfont].design_size = get_positive_quad(vf_file, "VF", "design_size");
} else { /* Try to fail gracefully and return an error to caller */
fprintf (stderr, "VF file may be corrupt\n");
}
@@ -177,8 +168,8 @@ static void read_a_font_def(FILE *vf_file, int32_t font_id, int thisfont)
vf_fonts[thisfont].num_dev_fonts;
dev_font -> font_id = font_id;
dev_font -> checksum = get_unsigned_quad (vf_file);
- dev_font -> size = get_positive_quad (vf_file, "font_size");
- dev_font -> design_size = get_positive_quad (vf_file, "font_design_size");
+ dev_font -> size = get_positive_quad (vf_file, "VF", "font_size");
+ dev_font -> design_size = get_positive_quad (vf_file, "VF", "font_design_size");
dir_length = get_unsigned_byte (vf_file);
name_length = get_unsigned_byte (vf_file);
dev_font -> directory = NEW (dir_length+1, char);
@@ -199,20 +190,6 @@ static void read_a_font_def(FILE *vf_file, int32_t font_id, int thisfont)
return;
}
-static int32_t get_vf_unsigned_num (FILE *vf_file, unsigned char num)
-{
- int32_t val = get_unsigned_byte (vf_file);
- switch (num) {
- case 3: if (val > 0x7f)
- val -= 0x100;
- val = (val << 8) | get_unsigned_byte (vf_file);
- case 2: val = (val << 8) | get_unsigned_byte (vf_file);
- case 1: val = (val << 8) | get_unsigned_byte (vf_file);
- default: break;
- }
- return val;
-}
-
static void process_vf_file (FILE *vf_file, int thisfont)
{
int eof = 0, code;
@@ -221,7 +198,7 @@ static void process_vf_file (FILE *vf_file, int thisfont)
code = get_unsigned_byte (vf_file);
switch (code) {
case FNT_DEF1: case FNT_DEF2: case FNT_DEF3: case FNT_DEF4:
- font_id = get_vf_unsigned_num (vf_file, code-FNT_DEF1);
+ font_id = get_unsigned_num (vf_file, code-FNT_DEF1);
read_a_font_def (vf_file, font_id, thisfont);
break;
default:
@@ -234,7 +211,7 @@ static void process_vf_file (FILE *vf_file, int thisfont)
break;
}
if (code == 242) {
- uint32_t pkt_len = get_positive_quad (vf_file, "pkt_len");
+ uint32_t pkt_len = get_positive_quad (vf_file, "VF", "pkt_len");
uint32_t ch = get_unsigned_quad (vf_file);
/* Skip over TFM width since we already know it */
skip_bytes (4, vf_file);
@@ -384,7 +361,7 @@ static void vf_setrule (unsigned char **start, unsigned char *end, spt_t ptsize)
dvi_right (s_width);
}
-static void vf_fnt (int32_t font_id, unsigned long vf_font)
+static void vf_fnt (int32_t font_id, int vf_font)
{
int i;
for (i=0; i<vf_fonts[vf_font].num_dev_fonts; i++) {
@@ -551,7 +528,7 @@ void vf_set_char(int32_t ch, int vf_font)
void vf_close_all_fonts(void)
{
- unsigned long i;
+ int i;
int j;
struct font_def *one_font;
for (i=0; i<num_vf_fonts; i++) {