File: txscaled.h

package info (click to toggle)
tralics 2.14.4-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 17,152 kB
  • ctags: 8,260
  • sloc: cpp: 49,403; xml: 18,145; sh: 140; makefile: 118
file content (203 lines) | stat: -rw-r--r-- 7,162 bytes parent folder | download
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// -*- C++ -*-
// $Id: txscaled.h,v 2.14 2008/11/12 09:43:57 grimm Exp $
// TRALICS, copyright (C)  INRIA/apics (Jose' Grimm) 2006, 2007,2008

// This software is governed by the CeCILL license under French law and
// abiding by the rules of distribution of free software.  You can  use, 
// modify and/ or redistribute the software under the terms of the CeCILL
// license as circulated by CEA, CNRS and INRIA at the following URL
// "http://www.cecill.info". 
// (See the file COPYING in the main directory for details)

// This defines the classes: ScaledInt, Glue, RealNumber,
// SthInternal ScanSlot TexRule

// this is a wrapper around an int
class ScaledInt {
  int value; // the integer, considered as a scaled number
 public:
  ScaledInt() : value(0) {}
  void set_value(int i) { value = i; }
  ScaledInt (int v): value (v) {}
  int get_value() const { return value; }
  ScaledInt operator-()const { return ScaledInt(-value); }
  void operator += (ScaledInt X) {value += X.value; }
  void add_dim(ScaledInt x);
  bool null() const { return value == 0; }
  void neg() { value = - value; }
  void divide(int);
  void quotient(int);
  void scale(int,int,int);
  bool scale(int,int,int,int,bool&);
  void mult_scaled(int);
  void mult_integer(int);
  void times_10_18();
  void times_18_10();
  void ovf30();
  void ovf31();
};

inline bool operator==(const ScaledInt& a, const ScaledInt&b)
{
  return a.get_value() == b.get_value();
}


// a glue like \hskip=2.3pt plus 4.5pt minus 6.7fill
// the three ints should be ScaledInt.
class Glue {
  ScaledInt width; // natural width (2.3)
  ScaledInt shrink; // shrink (6.7)
  ScaledInt stretch; // stretch (4.5)
  glue_spec shrink_order; // fill, symbolically
  glue_spec stretch_order; // pt, symbolically
 public:
  Glue(): shrink_order(glue_spec_pt), stretch_order(glue_spec_pt) {}
  ScaledInt get_width()const  { return width; }
  ScaledInt get_shrink()const { return shrink; }
  ScaledInt get_stretch()const { return stretch; }
  glue_spec get_shrink_order()const { return shrink_order; }
  glue_spec get_stretch_order()const { return stretch_order; }
  void set_width(ScaledInt x)  { width = x; }
  void set_shrink(ScaledInt x) { shrink = x; }
  void set_stretch(ScaledInt x) { stretch = x; }
  void set_shrink_order(glue_spec x) { shrink_order = x; }
  void set_stretch_order(glue_spec x) { stretch_order = x; }
  void kill();
  void normalise();
  void negate();
  void add(const Glue &x);
  void multiply(int v);
  void divide(int v);
  void incr_width(int x) { width += x; }
  void scale(int n, int f);
  void quotient(int f);
  void check_overflow();
  void expr_mul(int f);
  void add_ovf(const Glue&);
  void zdv();
};


// The value of the number is sign*(i+f/2^16);
class RealNumber {
  bool negative; // true if negative
  int ipart;     // fractional part
  int fpart;     // integer part, is <2^16
 public:
  void convert_decimal_part(int k, int*table);
  void set_ipart(int x) { ipart = x; }
  void set_fpart(int x) { fpart = x; }
  int get_ipart()const  { return ipart; }
  int get_fpart()const  { return fpart; }
  void change_sign() { negative = !negative; }
  void set_negative(bool x) { negative = x; }
  RealNumber() : negative(false), ipart(0), fpart(0) {}
  void set_neg() { negative = true ; }
  void change_sign_i() { ipart = -ipart; }
  bool get_negative() { return negative; };
  void from_int(int x);
};

// This is a union of different things
// it contains the result of scan_something_internal
class SthInternal {
  Glue glue_val;  // value if it is a glue
  ScaledInt int_val;    // value if it is a dimension or an integer
  TokenList token_val; // value if it is a token list
  internal_type type; // this says what the object is.
 public:
  SthInternal(): int_val(0), type(it_int) {}
  bool is_int()const { return type == it_int; }
  bool is_mu()const { return type == it_mu; }
  bool is_glue()const { return type == it_glue; }
  bool is_dimen()const { return type == it_dimen; }
  internal_type get_type()const { return type; }
  void kill() { int_val = 0; glue_val.kill(); type=it_int; }
  void set_type(internal_type X) { type=X; }
  int get_int_val()const { return int_val.get_value(); } 
  ScaledInt get_dim_val()const { return int_val; } 
  ScaledInt& get_scaled() { return int_val; } 
  TokenList get_token_val()const { return token_val; } 
  void set_int_val(int k) { int_val = k; } 
  void set_scaled_val(ScaledInt k) { int_val = k; } 
  const Glue& get_glue_val()const { return glue_val; } 
  int get_glue_width()const { return glue_val.get_width().get_value(); } 
  void initialise(internal_type t);
  void copy(const SthInternal& x);
  void negate(){
    if(type==it_glue||type==it_mu) glue_val.negate(); else int_val=-int_val;
  }
  void fast_negate() { int_val=-int_val; }
  void attach_fraction(RealNumber f);
  void attach_sign(bool negative);
  void set_int(int a) { int_val = a; type = it_int;}
  void set_dim(int a) { int_val = a; type = it_dimen;}
  void set_dim(ScaledInt a) { int_val = a.get_value(); type = it_dimen;}
  void set_glue(Glue a) { glue_val = a; type = it_glue;}
  void set_mu(Glue a) { glue_val = a; type = it_mu;}
  void set_toks(TokenList a) { token_val = a; type = it_tok;}
  void change_level(internal_type);
  void glue_to_mu(){if(type>=it_glue) int_val=glue_val.get_width().get_value();}
  void add(const SthInternal&);
  void incr_int(int x) { int_val += x; }
  void incr_dim(ScaledInt x) { int_val += x.get_value(); }
  void incr_glue(Glue x) { glue_val.add(x); }
  void glue_multiply(int v) { glue_val.multiply(v); }
  void glue_divide(int v) { glue_val.divide(v);  } 
  void set_glue_val(Glue x) { glue_val = x; }
  void cv_dim_to_mu();
  void cv_mu_to_glue();
  void cv_glue_to_mu();
  void get_info(subtypes);
  void scale(int,int);
  void quotient(int);
  void check_overflow(scan_expr_t t);
  void normalise();
  void expr_mul(int f);
  void add_ovf(const SthInternal &r);
};


class ScanSlot
{
public:
  internal_type expr_type;
  SthInternal expr_so_far;
  SthInternal term_so_far;  
  scan_expr_t expr_state;
  scan_expr_t term_state;
  int numerator;
public:
  ScanSlot(internal_type L, SthInternal E,SthInternal T, 
	    scan_expr_t R,scan_expr_t S, int N): 
    expr_type(L), expr_so_far(E),term_so_far(T),expr_state(R), term_state(S),
    numerator(N) {}
  ScanSlot(): expr_type(it_int), expr_state(se_none), term_state(se_none),
    numerator(0){}
  internal_type get_next_type() const 
  { return term_state==se_none ? expr_type: it_int; }
  void kill();
  void compute_term(scan_expr_t& next_state, SthInternal f,char&);
  void add_or_sub(scan_expr_t& next_state, SthInternal f,char&);
};


namespace arith_ns {
  int nx_plus_y(int n, int x, int y);
  ScaledInt n_times_x(int n, ScaledInt x);
  void scaled_div(ScaledInt& x, int n);
  int xn_over_d(int x, int n, int d, int& remainder);
  int quotient(int n, int d);
  int add_ovf(ScaledInt x, ScaledInt y);
};

 class TexRule {
public:
  ScaledInt rule_w, rule_h,rule_d;
  void reset();
  void convert(AttList&);
  void init_vrule() { rule_w = 26214; }
  void init_hrule() { rule_h = 26214; rule_d = 0; }
  void adjust() { rule_h += rule_d; rule_d.neg(); }
};