summaryrefslogtreecommitdiff
path: root/src/vf/vflib.c
blob: 987ff6473f9c0f69f8b3f36d04bc9da458fb13b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/****************************************************************************
 *
 * vflib.c
 *
 *   FreeType font driver for TeX's VF FONT files.
 *
 * Copyright 1996-2018 by
 * David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 * This file is part of the FreeType project, and may only be used,
 * modified, and distributed under the terms of the FreeType project
 * license, LICENSE.TXT.  By continuing to use, modify, or distribute
 * this file you indicate that you have read the license and
 * understand and accept it fully.
 *
 */

#include <ft2build.h>

#include FT_FREETYPE_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SYSTEM_H
#include FT_CONFIG_CONFIG_H
#include FT_ERRORS_H
#include FT_TYPES_H

#include "vf.h"
#include "vfdrivr.h"
#include "vferror.h"


  /**************************************************************************
   *
   * The macro FT_COMPONENT is used in trace mode.  It is an implicit
   * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
   * messages during execution.
   */
#undef  FT_COMPONENT
#define FT_COMPONENT  trace_vflib

  /**************************************************************************
   *
   * VF font utility functions.
   *
   */

     FT_Long     vf_read_intn( FT_Stream, FT_Int );
     FT_ULong    vf_read_uintn( FT_Stream, FT_Int );
     FT_Long     vf_get_intn( FT_Byte*, FT_Int );
     FT_ULong    vf_get_uintn( FT_Byte*, FT_Int );

#define READ_UINT1( stream )    (FT_Byte)vf_read_uintn( stream, 1 )
#define READ_UINT2( stream )    (FT_Byte)vf_read_uintn( stream, 2 )
#define READ_UINT3( stream )    (FT_Byte)vf_read_uintn( stream, 3 )
#define READ_UINT4( stream )    (FT_Byte)vf_read_uintn( stream, 4 )
#define READ_UINTN( stream, n ) (FT_ULong)vf_read_uintn( stream, n )
#define READ_INT1( stream )    (FT_String)vf_read_intn( stream, 1 )
#define READ_INT4( stream )    (FT_Long)vf_read_intn( stream, 4 )

#define GET_INT1(p)      (FT_Char)vf_get_intn((p), 1)
#define GET_UINT1(p)     (FT_Byte)vf_get_uintn((p), 1)
#define GET_INT2(p)      (FT_Int)vf_get_intn((p), 2)
#define GET_UINT2(p)     (FT_UInt)vf_get_uintn((p), 2)
#define GET_INT3(p)      (FT_Long)vf_get_intn((p), 3)
#define GET_UINT3(p)     (FT_ULong)vf_get_uintn((p), 3)
#define GET_INT4(p)      (FT_Long)vf_get_intn((p), 4)
#define GET_UINT4(p)     (FT_ULong)vf_get_uintn((p), 4)
#define GET_INTN(p,n)    (FT_Long)vf_get_intn((p), (n))
#define GET_UINTN(p,n)   (FT_ULong)vf_get_uintn((p), (n))

/*
 * Reading a Number from file
 */

  FT_ULong
  vf_read_uintn( FT_Stream stream,
		 FT_Int size )
  {
    FT_ULong  v,k;
    FT_Error  error;
    FT_Byte   tp;

    v = 0L;

    while ( size >= 1 )
    {
      if ( FT_READ_BYTE(tp) )
        return 0;
      k = (FT_ULong) tp;
      v = v*256L + k;
      --size;
    }
    return v;
  }


  FT_Long
  vf_read_intn( FT_Stream stream,
		FT_Int size )
  {
    FT_Long   v;
    FT_Byte   tp;
    FT_Error  error;
    FT_ULong  z;

    if ( FT_READ_BYTE(tp) )
      return 0;
    z = (FT_ULong) tp;
    v = (FT_Long) z & 0xffL;

    if( v & 0x80L )
      v = v - 256L;
    --size;

    while ( size >= 1 )
    {
      if ( FT_READ_BYTE(tp) )
        return 0;
      z = (FT_ULong) tp;
      v = v*256L + z;
      --size;
    }
    return v;
  }


  FT_ULong
  vf_get_uintn( FT_Byte *p,
                FT_Int  size )
  {
    FT_ULong v;

    v = 0L;
    while (size >= 1)
    {
      v = v*256L + (FT_ULong) *(p++);
      --size;
    }

    return v;
  }

  FT_Long
  vf_get_intn( FT_Byte *p,
                   FT_Int  size )
  {
    FT_Long v;

    v = (FT_Long)*(p++) & 0xffL;
    if (v & 0x80L)
      v = v - 256L;
    --size;
    while (size >= 1)
    {
      v = v*256L + (FT_ULong) *(p++);
      --size;
    }

    return v;
  }


  /**************************************************************************
   *
   * API.
   *
   */

   /* TO-DO */

/* END */