[gs-cvs] gs/src
Igor Melichev
igor at ghostscript.com
Wed Nov 19 23:53:17 PST 2003
Update of /cvs/ghostscript/gs/src
In directory casper:/tmp/cvs-serv26660/gs/src
Modified Files:
gzspotan.c
Log Message:
Implementing a True Type grid fitting, step 3.
DETAILS :
The new code is disabled with TT_GRID_FITTING 0 in gx.h .
This patch improves the stem recognizer and fixes the "#if DEBUG" error.
EXPECTED DIFFERENCES :
None.
Index: gzspotan.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gzspotan.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gzspotan.c 18 Nov 2003 13:24:49 -0000 1.2
+++ gzspotan.c 20 Nov 2003 07:53:15 -0000 1.3
@@ -306,7 +306,7 @@
private inline void
check_band_list(const gx_san_trap *list)
{
-#if DEBUG
+#ifdef DEBUG
if (list != NULL) {
const gx_san_trap *t = list;
@@ -354,6 +354,15 @@
return (double)(t->xrbot - t->xlbot + t->xrtop - t->xltop) * (t->ytop - t->ybot) / 2;
}
+private inline double
+trap_axis_length(gx_san_trap *t)
+{
+ double xbot = (t->xlbot + t->xrbot) / 2.0;
+ double xtop = (t->xltop + t->xrtop) / 2.0;
+
+ return hypot(xtop - xbot, t->ytop - t->ybot);
+}
+
private inline bool
is_stem_boundaries(gx_san_trap *t)
{
@@ -361,7 +370,7 @@
double dx = t->xltop - t->xlbot;
double norm = hypot(dx, dy);
double cosine = dx / norm;
- double cosine_threshold = 0.5; /* Arbitrary */
+ double cosine_threshold = 0.9; /* Arbitrary */
if (any_abs(cosine) > cosine_threshold)
return false;
@@ -521,31 +530,36 @@
if (is_stem_boundaries(t0)) {
gx_san_trap_contact *cont = t0->upper;
gx_san_trap *t1 = t0, *t;
- double area = 0, height = 0, ave_width;
+ double area = 0, length = 0, ave_width;
while(cont != NULL && cont->next == cont /* <= 1 descendent. */) {
- if (!is_stem_boundaries(cont->upper)) {
- cont->lower->visited = true;
+ gx_san_trap *t = cont->upper;
+
+ if (!is_stem_boundaries(t)) {
+ t->visited = true;
break;
}
- if (cont->upper->fork > 1)
+ if (t->fork > 1)
break; /* > 1 accendents. */
- t1 = cont->upper;
+ if (t1->xltop != t->xlbot || t1->xrtop != t->xrbot)
+ break; /* Not a contigouos boundary. */
+ t1 = t;
cont = t1->upper;
t1->visited = true;
}
- /* We've got a stem suspection from t to t1. */
+ /* We've got a stem suspection from t0 to t1. */
vd_quad(t0->xlbot, t0->ybot, t0->xrbot, t0->ybot,
t1->xrtop, t1->ytop, t1->xltop, t1->ytop, 1, VD_STEM_COLOR);
for (t = t0; ; t = t->upper->upper) {
- height += t->ytop - t->ybot;
+ /* height += t->ytop - t->ybot; */
+ length += trap_axis_length(t);
area += trap_area(t);
if (t == t1)
break;
}
- ave_width = area / height;
- if (height > ave_width / ( 2.0 /* arbitrary */)) {
- /* We've got a stem from t to t1. */
+ ave_width = area / length;
+ if (length > ave_width / ( 2.0 /* arbitrary */)) {
+ /* We've got a stem from t0 to t1. */
double w, wd, best_width_diff = ave_width * 10;
gx_san_trap *best_trap = NULL;
bool at_top = false;
@@ -570,7 +584,7 @@
at_top = true;
}
if (best_trap != NULL) {
- /* Make a stem section hint at_top of test_trap : */
+ /* Make a stem section hint at_top of best_trap : */
sect.y = at_top ? best_trap->ytop : best_trap->ybot;
sect.xl = at_top ? best_trap->xltop : best_trap->xlbot;
sect.xr = at_top ? best_trap->xrtop : best_trap->xrbot;
More information about the gs-cvs
mailing list