[mapserver-commits] r12988 - sandbox/sdlime/rfc-77
svn at osgeo.org
svn at osgeo.org
Mon Jan 16 13:04:55 EST 2012
Author: sdlime
Date: 2012-01-16 10:04:54 -0800 (Mon, 16 Jan 2012)
New Revision: 12988
Modified:
sandbox/sdlime/rfc-77/mapdraw.c
sandbox/sdlime/rfc-77/mapfile.c
sandbox/sdlime/rfc-77/maplabel.c
sandbox/sdlime/rfc-77/mapserver.h
Log:
Multiple labels rendering for points. Still need to work on within group collisions and other stuff but it's progress.
Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c 2012-01-16 16:09:43 UTC (rev 12987)
+++ sandbox/sdlime/rfc-77/mapdraw.c 2012-01-16 18:04:54 UTC (rev 12988)
@@ -1423,7 +1423,7 @@
double r; /* circle radius */
int csz; /* clip over size */
double buffer;
- int minfeaturesize;
+ int minfeaturesize=-1;
int numpaths = 1, numpoints = 1, numRegularLines = 0;
shapeObj *annoshape = NULL; /* holds the version of the shape to be labeled- may be clipped or may not */
@@ -2279,12 +2279,12 @@
if(map->debug) msDebug("msDrawLabelCache(): labelcache_map_edge_buffer = %d\n", map_edge_buffer);
}
- fprintf(stderr, " map_edge_buffer=%d\n", map_edge_buffer);
-
for(priority=MS_MAX_LABEL_PRIORITY-1; priority>=0; priority--) {
labelCacheSlotObj *cacheslot;
cacheslot = &(map->labelcache.slots[priority]);
+ fprintf(stderr, " priority=%d has %d labels\n", priority, cacheslot->numlabels);
+
for(l=cacheslot->numlabels-1; l>=0; l--) {
double scalefactor,size;
cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */
@@ -2293,9 +2293,11 @@
if(cachePtr->markerid != -1) markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right sport in the marker cache (if available) */
layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */
- if(cachePtr->labelpath) {
- labelPtr = &(cachePtr->labels[ll]);
+ fprintf(stderr, " working on label %d which has %d labelObj's, first bit of text='%s'\n", l, cachePtr->numlabels, cachePtr->labels[0].annotext);
+ if(cachePtr->labelpath) { /* path-based label */
+ labelPtr = &(cachePtr->labels[0]);
+
if(!labelPtr->annotext || strlen(labelPtr->annotext) == 0)
continue; /* skip this label, nothing to with curved labels when there is nothing to draw */
@@ -2305,19 +2307,19 @@
size = MS_MIN(size, labelPtr->maxsize*image->resolutionfactor);
scalefactor = size / labelPtr->size;
- if(msGetLabelSize(map, labelPtr, cachePtr->text, size, &r, NULL) != MS_SUCCESS)
+ if(msGetLabelSize(map, labelPtr, labelPtr->annotext, size, &r, NULL) != MS_SUCCESS)
return MS_FAILURE;
/* adjust the baseline (see #1449) (RFC 77 TODO - is this relevant for path following labels?) */
if(labelPtr->type == MS_TRUETYPE) {
- int nNewlines = msCountChars(cachePtr->text,'\n');
+ int nNewlines = msCountChars(labelPtr->annotext,'\n');
if(!nNewlines) {
labelPtr->offsety += MS_NINT((((r.miny + r.maxy) + size) / 2.0)/scalefactor);
labelPtr->offsetx += MS_NINT((r.minx / 2)/scalefactor);
} else {
rectObj rect2; /* bbox of first line only */
- char *firstLine = msGetFirstLine(cachePtr->text);
- msGetLabelSize(map,labelPtr,firstLine,size,&rect2,NULL);
+ char *firstLine = msGetFirstLine(labelPtr->annotext);
+ msGetLabelSize(map, labelPtr, firstLine, size, &rect2, NULL);
labelPtr->offsety += (MS_NINT(((rect2.miny+rect2.maxy) + size) / 2))/scalefactor;
labelPtr->offsetx += (MS_NINT(rect2.minx / 2))/scalefactor;
free(firstLine);
@@ -2343,17 +2345,60 @@
msDrawTextLine(image, cachePtr->text, labelPtr, cachePtr->labelpath, &(map->fontset), layerPtr->scalefactor); /* Draw the curved label */
- } else {
+ } else { /* point-based label */
int drawLabelText=MS_TRUE; // not used yet
/* all other cases *could* have multiple labels defined */
for(ll=(cachePtr->numlabels-1); ll>=0; ll--) {
labelPtr = &(cachePtr->labels[ll]);
+ // start missing section...
+ if(!labelPtr->annotext || strlen(labelPtr->annotext) == 0)
+ continue; /* skip this label (RFC 77 TODO: ok to bail here?) */
+
+ // RFC 77 TODO: account for raster fonts
+ if(labelPtr->type == MS_TRUETYPE) {
+ size = labelPtr->size * layerPtr->scalefactor;
+ size = MS_MAX(size, labelPtr->minsize*image->resolutionfactor);
+ size = MS_MIN(size, labelPtr->maxsize*image->resolutionfactor);
+ scalefactor = size / labelPtr->size;
+ } else {
+ size = labelPtr->size;
+ scalefactor = 1;
+ }
+ if(msGetLabelSize(map, labelPtr, labelPtr->annotext, size, &r, NULL) != MS_SUCCESS)
+ return MS_FAILURE;
+
+ /* adjust the baseline (see #1449) */
+ if(labelPtr->type == MS_TRUETYPE) {
+ int nNewlines = msCountChars(labelPtr->annotext,'\n');
+ if(!nNewlines) {
+ labelPtr->offsety += MS_NINT((((r.miny + r.maxy) + size) / 2.0)/scalefactor);
+ labelPtr->offsetx += MS_NINT((r.minx / 2)/scalefactor);
+ } else {
+ rectObj rect2; /* bbox of first line only */
+ char *firstLine = msGetFirstLine(labelPtr->annotext);
+ msGetLabelSize(map, labelPtr, firstLine, size, &rect2, NULL);
+ labelPtr->offsety += (MS_NINT(((rect2.miny+rect2.maxy) + size) / 2))/scalefactor;
+ labelPtr->offsetx += (MS_NINT(rect2.minx / 2))/scalefactor;
+ free(firstLine);
+ }
+ }
+
+ label_offset_x = labelPtr->offsetx*scalefactor;
+ label_offset_y = labelPtr->offsety*scalefactor;
+ label_buffer = MS_NINT(labelPtr->buffer*image->resolutionfactor);
+ label_mindistance = MS_NINT(labelPtr->mindistance*image->resolutionfactor);
+
+ if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
+ continue; /* label too large relative to the feature */
+ // end missing section
+
+ fprintf(stderr, " got label size\n");
+
marker_offset_x = marker_offset_y = 0; /* assume no marker */
marker_width = marker_height = 0;
if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) {
-
/* TODO: at the moment only checks the bottom (first) marker style since it *should* be the
largest, perhaps we should check all of them and build a composite size */
if(msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
@@ -2398,7 +2443,7 @@
marker_rect.maxx = MS_NINT(cachePtr->point.x + .5 * marker_width) + labelPtr->buffer; // marker_rect.minx + (marker_width-1) + labelPtr->buffer;
marker_rect.maxy = MS_NINT(cachePtr->point.y + .5 * marker_height) + labelPtr->buffer; // marker_rect.miny + (marker_height-1) + labelPtr->buffer;
}
- }
+ }
if(drawLabelText && labelPtr->position == MS_AUTO) {
int positions[MS_POSITIONS_LENGTH], npositions=0;
@@ -2422,7 +2467,7 @@
msFreeShape(cachePtr->poly);
cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
- p = get_metrics(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, cachePtr->poly);
+ labelPtr->annopoint = get_metrics(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, cachePtr->poly);
if(marker_width > 0 && marker_height > 0)
msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon (TODO: could do this once!) */
@@ -2447,11 +2492,13 @@
} else { /* explicit position */
cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
+ fprintf(stderr, " explicit position case (ll=%d)\n", ll);
+
if(labelPtr->position == MS_CC) { /* don't need the marker_offset */
- p = get_metrics(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, label_buffer, cachePtr->poly);
+ labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, label_buffer, cachePtr->poly);
if(drawLabelPoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, 1, labelPoly.line);
} else {
- p = get_metrics(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, cachePtr->poly);
+ labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, cachePtr->poly);
if(drawLabelPoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPoly.line);
}
@@ -2467,6 +2514,8 @@
if(!cachePtr->status)
continue; /* next label */
+ fprintf(stderr, " label can be drawn!\n");
+
if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { /* need to draw a marker */
for(i=0; i<cachePtr->numstyles; i++)
msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), &(cachePtr->styles[i]), layerPtr->scalefactor);
@@ -2489,7 +2538,7 @@
}
}
- msDrawText(image, p, cachePtr->text, labelPtr, &(map->fontset), layerPtr->scalefactor); /* actually draw the label */
+ msDrawText(image, labelPtr->annopoint, labelPtr->annotext, labelPtr, &(map->fontset), layerPtr->scalefactor); /* actually draw the label */
}
}
} /* next label */
Modified: sandbox/sdlime/rfc-77/mapfile.c
===================================================================
--- sandbox/sdlime/rfc-77/mapfile.c 2012-01-16 16:09:43 UTC (rev 12987)
+++ sandbox/sdlime/rfc-77/mapfile.c 2012-01-16 18:04:54 UTC (rev 12988)
@@ -2833,13 +2833,13 @@
* to msGrowClassStyles()
*/
class->numstyles = class->maxstyles = 0;
- class->styles = NULL;
+ class->styles = NULL;
// RFC-77 REMOVE
// initLabel(&(class->label));
// class->label.size = -1; /* no default */
class->numlabels = class->maxlabels = 0;
- class->labels = NULL;
+ class->labels = NULL;
class->keyimage = NULL;
@@ -3030,7 +3030,9 @@
}
labelObj *msGrowClassLabels( classObj *class ) {
- /* Do we need to increase the size of labels[] by MS_LABEL_ALLOCSIZE?
+ fprintf(stderr, "in msGrowClassLabels, numlabels=%d\n", class->numlabels);
+
+ /* Do we need to increase the size of labels[] by MS_LABEL_ALLOCSIZE?
*/
if (class->numlabels == class->maxlabels) {
labelObj **newLabelPtr;
@@ -3114,6 +3116,7 @@
initLabel(class->labels[class->numlabels]);
class->labels[class->numlabels]->size = MS_MEDIUM; /* only set a default if the LABEL section is present */
if(loadLabel(class->labels[class->numlabels]) == -1) return(-1);
+ class->numlabels++;
break;
case(MAXSCALE):
case(MAXSCALEDENOM):
Modified: sandbox/sdlime/rfc-77/maplabel.c
===================================================================
--- sandbox/sdlime/rfc-77/maplabel.c 2012-01-16 16:09:43 UTC (rev 12987)
+++ sandbox/sdlime/rfc-77/maplabel.c 2012-01-16 18:04:54 UTC (rev 12988)
@@ -319,7 +319,7 @@
/* if the number of labels is 1 then call msAddLabel() accordingly */
if(classPtr->numlabels == 1) {
- msAddLabel(map, classPtr->labels[0], layerindex, classindex, shape, point, NULL, featuresize);
+ return msAddLabel(map, classPtr->labels[0], layerindex, classindex, shape, point, NULL, featuresize);
}
// if( label == NULL )
@@ -340,6 +340,8 @@
else if (priority > MS_MAX_LABEL_PRIORITY)
priority = MS_MAX_LABEL_PRIORITY;
+ fprintf(stderr, " priority=%d\n", priority);
+
cacheslot = &(map->labelcache.slots[priority-1]);
if(cacheslot->numlabels == cacheslot->cachesize) { /* just add it to the end */
@@ -353,6 +355,8 @@
cachePtr->layerindex = layerindex; /* so we can get back to this *raw* data if necessary */
cachePtr->classindex = classindex;
+ fprintf(stderr, " assigned indexes\n");
+
if(shape) {
cachePtr->tileindex = shape->tileindex;
cachePtr->shapeindex = shape->index;
@@ -368,6 +372,8 @@
cachePtr->point.y = MS_NINT(cachePtr->point.y);
cachePtr->labelpath = NULL;
+ fprintf(stderr, " stored label point (%g,%g)\n", point->x, point->y);
+
// cachePtr->text = msStrdup(string); /* the actual text */
/* TODO: perhaps we can get rid of this next section and just store a marker size? Why do we cache the styles for a point layer? */
@@ -389,14 +395,18 @@
}
/*
- ** copy the labels:
+ ** copy the labels (we are guaranteed to have more than one):
** we cannot simply keep refs because the rendering code alters some members of the style objects
*/
cachePtr->numlabels = classPtr->numlabels;
- cachePtr->labels = (labelObj *) msSmallMalloc(sizeof(labelObj)*cachePtr->numlabels);
- for(i=0; i<cachePtr->numlabels; i++)
+ cachePtr->labels = (labelObj *) msSmallMalloc(sizeof(labelObj)*classPtr->numlabels);
+ for(i=0; i<classPtr->numlabels; i++) {
+ initLabel(&(cachePtr->labels[i]));
msCopyLabel(&(cachePtr->labels[i]), classPtr->labels[i]);
+ }
+ fprintf(stderr, " copied %d labels\n", classPtr->numlabels);
+
cachePtr->markerid = -1;
cachePtr->featuresize = featuresize;
Modified: sandbox/sdlime/rfc-77/mapserver.h
===================================================================
--- sandbox/sdlime/rfc-77/mapserver.h 2012-01-16 16:09:43 UTC (rev 12987)
+++ sandbox/sdlime/rfc-77/mapserver.h 2012-01-16 18:04:54 UTC (rev 12988)
@@ -225,7 +225,7 @@
#define MS_LAYER_ALLOCSIZE 64
#define MS_CLASS_ALLOCSIZE 8
#define MS_STYLE_ALLOCSIZE 4
-#define MS_LABEL_ALLOCSIZE 1 /* not too common */
+#define MS_LABEL_ALLOCSIZE 2 /* not too common */
#define MS_MAX_LABEL_PRIORITY 10
#define MS_DEFAULT_LABEL_PRIORITY 1
@@ -974,6 +974,7 @@
/* book keeping variable- used on a feature-by-feature basis (similar to bindings) */
char *annotext;
+ pointObj annopoint;
shapeObj *annopoly;
#endif
} labelObj;
More information about the mapserver-commits
mailing list