w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Collider.h
Go to the documentation of this file.
1 /* GRAPHITE2 LICENSING
2 
3  Copyright 2010, SIL International
4  All rights reserved.
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation; either version 2.1 of License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should also have received a copy of the GNU Lesser General Public
17  License along with this library in the file named "LICENSE".
18  If not, write to the Free Software Foundation, 51 Franklin Street,
19  Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20  internet at http://www.fsf.org/licenses/lgpl.html.
21 
22 Alternatively, the contents of this file may be used under the terms of the
23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 License, as published by the Free Software Foundation, either version 2
25 of the License or (at your option) any later version.
26 */
27 #pragma once
28 
29 #include "inc/List.h"
30 #include "inc/Position.h"
31 #include "inc/Intervals.h"
32 #include "inc/debug.h"
33 
34 namespace graphite2 {
35 
36 class json;
37 class Slot;
38 class Segment;
39 
40 #define SLOTCOLSETUINTPROP(x, y) uint16 x() const { return _ ##x; } void y (uint16 v) { _ ##x = v; }
41 #define SLOTCOLSETINTPROP(x, y) int16 x() const { return _ ##x; } void y (int16 v) { _ ##x = v; }
42 #define SLOTCOLSETPOSITIONPROP(x, y) const Position &x() const { return _ ##x; } void y (const Position &v) { _ ##x = v; }
43 
44 // Slot attributes related to collision-fixing
45 class SlotCollision
46 {
47 public:
48  enum {
49  // COLL_TESTONLY = 0, // default - test other glyphs for collision with this one, but don't move this one
50  COLL_FIX = 1, // fix collisions involving this glyph
51  COLL_IGNORE = 2, // ignore this glyph altogether
52  COLL_START = 4, // start of range of possible collisions
53  COLL_END = 8, // end of range of possible collisions
54  COLL_KERN = 16, // collisions with this glyph are fixed by adding kerning space after it
55  COLL_ISCOL = 32, // this glyph has a collision
56  COLL_KNOWN = 64, // we've figured out what's happening with this glyph
57  COLL_ISSPACE = 128, // treat this glyph as a space with regard to kerning
58  COLL_TEMPLOCK = 256, // Lock glyphs that have been given priority positioning
59  ////COLL_JUMPABLE = 128, // moving glyphs may jump this stationary glyph in any direction - DELETE
60  ////COLL_OVERLAP = 256, // use maxoverlap to restrict - DELETE
61  };
62 
63  // Behavior for the collision.order attribute. To GDL this is an enum, to us it's a bitfield, with only 1 bit set
64  // Allows for easier inversion.
65  enum {
70  SEQ_ORDER_NOLEFT = 16,
72  };
73 
76 
77  const Rect &limit() const { return _limit; }
78  void setLimit(const Rect &r) { _limit = r; }
95 
96  float getKern(int dir) const;
97  bool ignore() const;
98 
99 private:
100  Rect _limit;
101  Position _shift; // adjustment within the given pass
102  Position _offset; // total adjustment for collisions
104  uint16 _margin;
106  uint16 _flags;
117 
118 }; // end of class SlotColllision
119 
120 struct BBox;
121 struct SlantBox;
122 
123 class ShiftCollider
124 {
125 public:
126  typedef std::pair<float, float> fpair;
129 
130  ShiftCollider(json *dbgout);
131  ~ShiftCollider() throw() { };
132 
133  bool initSlot(Segment *seg, Slot *aSlot, const Rect &constraint,
134  float margin, float marginMin, const Position &currShift,
135  const Position &currOffset, int dir, GR_MAYBE_UNUSED json * const dbgout);
136  bool mergeSlot(Segment *seg, Slot *slot, const SlotCollision *cinfo, const Position &currShift, bool isAfter,
137  bool sameCluster, bool &hasCol, bool isExclusion, GR_MAYBE_UNUSED json * const dbgout);
138  Position resolve(Segment *seg, bool &isCol, GR_MAYBE_UNUSED json * const dbgout);
139  void addBox_slope(bool isx, const Rect &box, const BBox &bb, const SlantBox &sb, const Position &org, float weight, float m, bool minright, int mode);
140  void removeBox(const Rect &box, const BBox &bb, const SlantBox &sb, const Position &org, int mode);
141  const Position &origin() const { return _origin; }
142 
143 #if !defined GRAPHITE2_NTRACING
144  void outputJsonDbg(json * const dbgout, Segment *seg, int axis);
145  void outputJsonDbgStartSlot(json * const dbgout, Segment *seg);
146  void outputJsonDbgEndSlot(json * const dbgout, Position resultPos, int bestAxis, bool isCol);
147  void outputJsonDbgOneVector(json * const dbgout, Segment *seg, int axis, float tleft, float bestCost, float bestVal);
148  void outputJsonDbgRawRanges(json * const dbgout, int axis);
149  void outputJsonDbgRemovals(json * const dbgout, int axis, Segment *seg);
150 #endif
151 
153 
154 protected:
155  Zones _ranges[4]; // possible movements in 4 directions (horizontally, vertically, diagonally);
156  Slot * _target; // the glyph to fix
157  Rect _limit;
158  Position _currShift;
159  Position _currOffset;
160  Position _origin; // Base for all relative calculations
161  float _margin;
162  float _marginWt;
163  float _len[4];
167 
168  //bool _scraping[4];
169 
170 }; // end of class ShiftCollider
171 
172 inline
174 : _target(0),
175  _margin(0.0),
176  _marginWt(0.0),
177  _seqClass(0),
178  _seqProxClass(0),
179  _seqOrder(0)
180 {
181 #if !defined GRAPHITE2_NTRACING
182  for (int i = 0; i < 4; ++i)
183  _ranges[i].setdebug(dbgout);
184 #endif
185 }
186 
187 class KernCollider
188 {
189 public:
191  ~KernCollider() throw() { };
192  bool initSlot(Segment *seg, Slot *aSlot, const Rect &constraint, float margin,
193  const Position &currShift, const Position &offsetPrev, int dir,
194  float ymin, float ymax, json * const dbgout);
195  bool mergeSlot(Segment *seg, Slot *slot, const Position &currShift, float currSpace, int dir, json * const dbgout);
196  Position resolve(Segment *seg, Slot *slot, int dir, json * const dbgout);
197  void shift(const Position &mv, int dir);
198 
200 
201 private:
202  Slot * _target; // the glyph to fix
203  Rect _limit;
204  float _margin;
205  Position _offsetPrev; // kern from a previous pass
206  Position _currShift; // NOT USED??
207  float _miny; // y-coordinates offset by global slot position
208  float _maxy;
209  Vector<float> _edges; // edges of horizontal slices
210  float _sliceWidth; // width of each slice
211  float _mingap;
212  float _xbound; // max or min edge
213  bool _hit;
214 
215 #if !defined GRAPHITE2_NTRACING
216  // Debugging
217  Segment * _seg;
218  Vector<float> _nearEdges; // closest potential collision in each slice
220 #endif
221 }; // end of class KernCollider
222 
223 
224 inline
225 float sqr(float x) {
226  return x * x;
227 }
228 
229 inline
231 : _target(0),
232  _margin(0.0f),
233  _miny(-1e38f),
234  _maxy(1e38f),
235  _sliceWidth(0.0f),
236  _mingap(0.0f),
237  _xbound(0.0),
238  _hit(false)
239 {
240 #if !defined GRAPHITE2_NTRACING
241  _seg = 0;
242 #endif
243 };
244 
245 }; // end of namespace graphite2
#define mode
Definition: aptex-macros.h:510
Position resolve(Segment *seg, Slot *slot, int dir, json *const dbgout)
Vector< float > _edges
Definition: Collider.h:209
bool initSlot(Segment *seg, Slot *aSlot, const Rect &constraint, float margin, const Position &currShift, const Position &offsetPrev, int dir, float ymin, float ymax, json *const dbgout)
bool mergeSlot(Segment *seg, Slot *slot, const Position &currShift, float currSpace, int dir, json *const dbgout)
Vector< Slot * > _slotNear
Definition: Collider.h:219
Vector< float > _nearEdges
Definition: Collider.h:218
void shift(const Position &mv, int dir)
void outputJsonDbgOneVector(json *const dbgout, Segment *seg, int axis, float tleft, float bestCost, float bestVal)
void outputJsonDbgRemovals(json *const dbgout, int axis, Segment *seg)
void addBox_slope(bool isx, const Rect &box, const BBox &bb, const SlantBox &sb, const Position &org, float weight, float m, bool minright, int mode)
void outputJsonDbgStartSlot(json *const dbgout, Segment *seg)
void outputJsonDbgRawRanges(json *const dbgout, int axis)
void outputJsonDbgEndSlot(json *const dbgout, Position resultPos, int bestAxis, bool isCol)
const Position & origin() const
Definition: Collider.h:141
void outputJsonDbg(json *const dbgout, Segment *seg, int axis)
vfpairs::iterator ivfpairs
Definition: Collider.h:128
Position resolve(Segment *seg, bool &isCol, GR_MAYBE_UNUSED json *const dbgout)
Vector< fpair > vfpairs
Definition: Collider.h:127
bool initSlot(Segment *seg, Slot *aSlot, const Rect &constraint, float margin, float marginMin, const Position &currShift, const Position &currOffset, int dir, GR_MAYBE_UNUSED json *const dbgout)
ShiftCollider(json *dbgout)
void removeBox(const Rect &box, const BBox &bb, const SlantBox &sb, const Position &org, int mode)
std::pair< float, float > fpair
Definition: Collider.h:126
bool mergeSlot(Segment *seg, Slot *slot, const SlotCollision *cinfo, const Position &currShift, bool isAfter, bool sameCluster, bool &hasCol, bool isExclusion, GR_MAYBE_UNUSED json *const dbgout)
uint16 marginWt() const
Definition: Collider.h:83
const Rect & limit() const
Definition: Collider.h:77
int16 seqBelowXlim() const
Definition: Collider.h:91
void setSeqOrder(uint16 v)
Definition: Collider.h:88
void setExclOffset(const Position &v)
Definition: Collider.h:81
const Position & shift() const
Definition: Collider.h:79
const Position & exclOffset() const
Definition: Collider.h:81
void setFlags(uint16 v)
Definition: Collider.h:84
void setSeqValignHt(uint16 v)
Definition: Collider.h:93
void setSeqValignWt(uint16 v)
Definition: Collider.h:94
uint16 margin() const
Definition: Collider.h:82
void setExclGlyph(uint16 v)
Definition: Collider.h:85
void setSeqAboveXoff(int16 v)
Definition: Collider.h:89
void setSeqBelowXlim(int16 v)
Definition: Collider.h:91
uint16 seqValignHt() const
Definition: Collider.h:93
float getKern(int dir) const
Definition: Collider.cpp:1104
uint16 exclGlyph() const
Definition: Collider.h:85
uint16 seqProxClass() const
Definition: Collider.h:87
void setSeqBelowWt(uint16 v)
Definition: Collider.h:92
void setOffset(const Position &v)
Definition: Collider.h:80
void setShift(const Position &v)
Definition: Collider.h:79
uint16 seqBelowWt() const
Definition: Collider.h:92
uint16 seqValignWt() const
Definition: Collider.h:94
uint16 seqOrder() const
Definition: Collider.h:88
uint16 flags() const
Definition: Collider.h:84
void setSeqAboveWt(uint16 v)
Definition: Collider.h:90
uint16 seqAboveWt() const
Definition: Collider.h:90
void setLimit(const Rect &r)
Definition: Collider.h:78
void initFromSlot(Segment *seg, Slot *slot)
void setMargin(uint16 v)
Definition: Collider.h:82
void setSeqClass(uint16 v)
Definition: Collider.h:86
const Position & offset() const
Definition: Collider.h:80
int16 seqAboveXoff() const
Definition: Collider.h:89
uint16 seqClass() const
Definition: Collider.h:86
void setSeqProxClass(uint16 v)
Definition: Collider.h:87
void setMarginWt(uint16 v)
Definition: Collider.h:83
SlotCollision(Segment *seg, Slot *slot)
T * iterator
Definition: List.h:53
small capitals from c petite p scientific i
Definition: afcover.h:80
#define const
Definition: ftzconf.h:91
#define false
Definition: ftrandom.c:52
float x
Definition: cordic.py:15
Definition: bits.h:30
gr_int16 int16
Definition: Main.h:43
float sqr(float x)
Definition: Collider.h:225
gr_uint16 uint16
Definition: Main.h:40
int r
Definition: ppmqvga.c:68
int margin
Definition: ppmtosixel.c:32
#define dir
#define GR_MAYBE_UNUSED
Definition: Main.h:172
#define CLASS_NEW_DELETE
Definition: Main.h:159
slotref slot
Definition: opcodes.h:237
#define SLOTCOLSETUINTPROP(x, y)
Definition: Collider.h:40
#define SLOTCOLSETPOSITIONPROP(x, y)
Definition: Collider.h:42
#define SLOTCOLSETINTPROP(x, y)
Definition: Collider.h:41
Definition: jquant2.c:258
Definition: psfont.h:67
Definition: gd.c:2418
m
Definition: tex4ht.c:3990
static int _margin
Definition: psearch.c:343
Bool__ isAfter(const Transition t, int64_t thresh)
Definition: tz2icu.cpp:1194