#include <algorithm>
#include <limits>
#include <cmath>
#include <string>
#include <functional>
#include "inc/Collider.h"
#include "inc/Segment.h"
#include "inc/Slot.h"
#include "inc/GlyphCache.h"
#include "inc/Sparse.h"
#define ISQRT2 …
usingnamespacegraphite2;
bool ShiftCollider::initSlot(Segment *seg, Slot *aSlot, const Rect &limit, float margin, float marginWeight,
const Position &currShift, const Position &currOffset, int dir, GR_MAYBE_UNUSED json * const dbgout)
{ … }
template <class O>
float sdm(float vi, float va, float mx, float my, O op)
{ … }
void ShiftCollider::addBox_slope(bool isx, const Rect &box, const BBox &bb, const SlantBox &sb, const Position &org, float weight, float m, bool minright, int axis)
{ … }
inline void ShiftCollider::removeBox(const Rect &box, const BBox &bb, const SlantBox &sb, const Position &org, int axis)
{ … }
bool ShiftCollider::mergeSlot(Segment *seg, Slot *slot, const SlotCollision *cslot, const Position &currShift,
bool isAfter,
bool sameCluster, bool &hasCol, bool isExclusion,
GR_MAYBE_UNUSED json * const dbgout )
{ … }
Position ShiftCollider::resolve(GR_MAYBE_UNUSED Segment *seg, bool &isCol, GR_MAYBE_UNUSED json * const dbgout)
{ … }
#if !defined GRAPHITE2_NTRACING
void ShiftCollider::outputJsonDbg(json * const dbgout, Segment *seg, int axis)
{
int axisMax = axis;
if (axis < 0)
{
*dbgout << "gid" << _target->gid()
<< "limit" << _limit
<< "target" << json::object
<< "origin" << _target->origin()
<< "margin" << _margin
<< "bbox" << seg->theGlyphBBoxTemporary(_target->gid())
<< "slantbox" << seg->getFace()->glyphs().slant(_target->gid())
<< json::close;
*dbgout << "ranges" << json::array;
axis = 0;
axisMax = 3;
}
for (int iAxis = axis; iAxis <= axisMax; ++iAxis)
{
*dbgout << json::flat << json::array << _ranges[iAxis].position();
for (Zones::const_iterator s = _ranges[iAxis].begin(), e = _ranges[iAxis].end(); s != e; ++s)
*dbgout << json::flat << json::array
<< Position(s->x, s->xm) << s->sm << s->smx << s->c
<< json::close;
*dbgout << json::close;
}
if (axis < axisMax)
*dbgout << json::close;
}
void ShiftCollider::outputJsonDbgStartSlot(json * const dbgout, Segment *seg)
{
*dbgout << json::object
<< "slot" << objectid(dslot(seg, _target))
<< "gid" << _target->gid()
<< "limit" << _limit
<< "target" << json::object
<< "origin" << _origin
<< "currShift" << _currShift
<< "currOffset" << seg->collisionInfo(_target)->offset()
<< "bbox" << seg->theGlyphBBoxTemporary(_target->gid())
<< "slantBox" << seg->getFace()->glyphs().slant(_target->gid())
<< "fix" << "shift";
*dbgout << json::close;
}
void ShiftCollider::outputJsonDbgEndSlot(GR_MAYBE_UNUSED json * const dbgout,
Position resultPos, int bestAxis, bool isCol)
{
*dbgout << json::close
<< "result" << resultPos
<< "bestAxis" << bestAxis
<< "stillBad" << isCol
<< json::close;
}
void ShiftCollider::outputJsonDbgOneVector(json * const dbgout, Segment *seg, int axis,
float tleft, float bestCost, float bestVal)
{
const char * label;
switch (axis)
{
case 0: label = "x"; break;
case 1: label = "y"; break;
case 2: label = "sum (NE-SW)"; break;
case 3: label = "diff (NW-SE)"; break;
default: label = "???"; break;
}
*dbgout << json::object
<< "direction" << label
<< "targetMin" << tleft;
outputJsonDbgRemovals(dbgout, axis, seg);
*dbgout << "ranges";
outputJsonDbg(dbgout, seg, axis);
*dbgout << "bestCost" << bestCost
<< "bestVal" << bestVal + tleft
<< json::close;
}
void ShiftCollider::outputJsonDbgRemovals(json * const dbgout, int axis, Segment *seg)
{
*dbgout << "removals" << json::array;
_ranges[axis].jsonDbgOut(seg);
*dbgout << json::close;
}
#endif
inline
static float localmax (float al, float au, float bl, float bu, float x)
{ … }
inline
static float localmin(float al, float au, float bl, float bu, float x)
{ … }
static float get_edge(Segment *seg, const Slot *s, const Position &shift, float y, float width, float margin, bool isRight)
{ … }
bool KernCollider::initSlot(Segment *seg, Slot *aSlot, const Rect &limit, float margin,
const Position &currShift, const Position &offsetPrev, int dir,
float ymin, float ymax, GR_MAYBE_UNUSED json * const dbgout)
{ … }
bool KernCollider::mergeSlot(Segment *seg, Slot *slot, const Position &currShift, float currSpace, int dir, GR_MAYBE_UNUSED json * const dbgout)
{ … }
Position KernCollider::resolve(GR_MAYBE_UNUSED Segment *seg, GR_MAYBE_UNUSED Slot *slot,
int dir, GR_MAYBE_UNUSED json * const dbgout)
{ … }
void KernCollider::shift(const Position &mv, int dir)
{ … }
SlotCollision::SlotCollision(Segment *seg, Slot *slot)
{ … }
void SlotCollision::initFromSlot(Segment *seg, Slot *slot)
{ … }
float SlotCollision::getKern(int dir) const
{ … }
bool SlotCollision::ignore() const
{ … }