Debian Codegraph @

texk/xdvipsk/otflib/numbers.h

raw
1 /* This is xdvipsk, an eXtended version of dvips(k) by Tomas Rokicki.
2
3 Copyright (C) 2016 by VTeX Ltd (www.vtex.lt),
4 the xdvipsk project team - Sigitas Tolusis and Arunas Povilaitis.
5
6 Program original code copyright (C) 2007-2014 by Jin-Hwan Cho and
7 Shunsaku Hirata, the dvipdfmx project team.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 */
23
24 #ifndef _NUMBERS_H_
25 #define _NUMBERS_H_
26
27 #include <stdio.h>
28 #include <math.h>
29 #ifdef HAVE_INTTYPES_H
30 # include <inttypes.h>
31 #endif
32 #ifdef HAVE_STDINT_H
33 # include <stdint.h>
34 #endif
35
36 #ifndef PRId64
37 # ifdef _WIN32
38 # define PRId64 "I64d"
39 # elif SIZEOF_LONG == 8
40 # define PRId64 "ld"
41 # else
42 # define PRId64 "lld"
43 # endif
44 #endif
45
46 /* When reading numbers from binary files 1, 2, or 3 bytes are
47 interpreted as either signed or unsigned.
48
49 Four bytes from DVI, PK, TFM, or VF files always yield a signed
50 32-bit integer (int32_t), but some of them must not be negative.
51
52 Four byte numbers from JPEG2000, OpenType, or TrueType files are
53 mostly unsigned (uint32_t) and occasionally signed (int32_t).
54 */
55
56 extern unsigned char get_unsigned_byte (FILE *);
57 extern void skip_bytes (unsigned int, FILE *);
58 extern signed char get_signed_byte (FILE *);
59 extern unsigned short get_unsigned_pair (FILE *);
60 extern unsigned short sget_unsigned_pair (unsigned char *);
61 extern signed short get_signed_pair (FILE *);
62 extern unsigned int get_unsigned_triple (FILE *);
63 extern signed int get_signed_triple (FILE *);
64 extern int32_t get_signed_quad (FILE *);
65 extern uint32_t get_unsigned_quad (FILE *);
66 extern int32_t get_unsigned_num (FILE *, unsigned char);
67 extern uint32_t get_positive_quad (FILE *, const char *, const char *);
68
69 typedef int32_t fixword;
70
71 extern int32_t sqxfw (int32_t sq, fixword fw);
72
73 #ifndef MAX
74 # define MAX(a,b) ((a)>(b)?(a):(b))
75 #endif
76 #ifndef MIN
77 # define MIN(a,b) ((a)<(b)?(a):(b))
78 #endif
79 #define ISODD(n) (((n)/2)*2!=(n))
80 #define ISEVEN(n) (((n)/2)*2==(n))
81
82 #ifndef M_PI
83 # define M_PI (4.0*atan(1.0))
84 #endif
85
86 #define ROUND(n,acc) (floor(((double)n)/(acc)+0.5)*(acc))
87
88 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
89 # define __C99__
90 #endif
91
92 #ifndef __C99__
93 # ifndef round
94 # define round(v) (floor((v) + 0.5))
95 # endif
96 # ifndef trunc
97 # define trunc(v) ((v) > 0.0 ? floor((v)) : ceil((v)))
98 # endif
99 #endif
100 #define round_at(v,acc) (round(((double)(v))/(acc))*(acc))
101
102 #endif /* _NUMBERS_H_ */