Re: [Freetype-devel] Re: GSOC - Distance Fields

2020-08-06 Thread Anuj Verma
Hello Alexei,

> Can you describe discontinuities with the same sign if I overlook them?

So, I found there are two types of discontinuities due to overlapping
contours:

A) Discontinuity in sign. (i.e. there is a sudden jump from negative to
positive)
B) Discontinuity in distances. (i.e. the points that should be at
infinity/spread have smaller distances)

Here is an example of a SDF generated from glyph with overlaps:
https://i.imgur.com/3pqHZWd.png
In that image the right side is correct (generated from bitmap), and the
left side has both A and B
types of  discontinuities.

What you are saying about detecting sudden jump from large negative to large
positive can work for discontinuities in sign. I tried that and here is an
example: https://i.imgur.com/unRB23Z.png
(ignore the weird lines in the image, that can be fixed). But even after
fixing the
sign there are pixels inside the outline which have shortest distance to
the curves
inside the outline. (basically the pixels around the overlap points to the
overlapping
curve, which causes discontinuous distances). Moreover they interpolate
smoothly
so there is no way to find the actual distance which will be to some curve
at the border
of the outline instead of inside the outline.

Also, I looked at a library (msdfgen) which handles overlapping contours
without
removing the overlaps. It works well, but it doesn't work for
self-intersecting contours,
that is why I'm not sure whether it's worth implementing.

Finally, I can find and fix signs such that all points inside a shape are
positive and
all points outside are negative. But I don't know how I can fix the
incorrect distances
caused by the overlaps. Here is one final example:
https://i.imgur.com/jiaqiBS.png
In this the point `P' has a positive sign and it points to a line inside
the shape, which
is not correct, instead it should point to the corner. Moreover there is no
corner in the
shape because they are two separate contours, so I think removing the
overlaps is
the best way to handle this.

Thanks,
Anuj


Re: [Freetype-devel] Re: GSOC - Distance Fields

2020-08-06 Thread Alexei Podtelezhnikov
Hi Anuj,

> > If I understand correctly, overlaps cause unexpected discontinuity in
> > SDF, which otherwise should not have any. I doubt that detecting and
> > removing contour overlaps is productive. I would rather deal with the
> > discontinuity directly. Perhaps there is a clever way to ignore
> > smaller distances that unexpectedly have an opposite sign. The
> > distance cannot change by more than the grid size. If it does, ignore
> > the offending value.
>
> Yes, overlaps cause discontinuity in both sign and distances. Detecting
> unexpected opposite sign is possible, but the sign may not be opposite.
> In many cases the sign is not flipped (there is no unexpected change
> in sign) and the distances interpolate smoothly, in those cases it becomes
> hard to find the true distances of the point.

I still think that it should be possible to ignore distances that
result in discontinuities. The distance field has to be continuous
from edge to edge, from clamped "infinity" to clamped "infinity", with
continuity defined as not changing by more than a grid size. The signs
are allowed to flip only then crossing line segments (i.e. scanning
the line neighborhood, rather than overriding a previous value). As
you scan a neighborhood for a line and encounter a previously recorded
(not "infinite") value you should override only if it has the same
sign and smaller magnitude.

Can you describe discontinuities with the same sign if I overlook them?

Thank you
Alexei



Re: [PATCH] [truetype] Retain OVERLAP_SIMPLE and OVERLAP_COMPOUND.

2020-08-06 Thread Werner LEMBERG

Sorry for being late :-)

> Please review the patch if you agree with the placement of the flag
> retention code.

Looks good – and thanks for committing!


Werner