[mapserver-commits] r12972 - sandbox/sdlime/rfc-77
svn at osgeo.org
svn at osgeo.org
Wed Jan 4 23:23:37 EST 2012
Author: sdlime
Date: 2012-01-04 20:23:37 -0800 (Wed, 04 Jan 2012)
New Revision: 12972
Modified:
sandbox/sdlime/rfc-77/mapdraw.c
Log:
Mid way through msDrawLabelCache() refactoring...
Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c 2012-01-04 21:14:31 UTC (rev 12971)
+++ sandbox/sdlime/rfc-77/mapdraw.c 2012-01-05 04:23:37 UTC (rev 12972)
@@ -2285,67 +2285,24 @@
markerPtr = NULL;
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 */
- for(ll=0; ll<cachePtr->numlabels; ll++) {
-
- layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */
+ if(cachePtr->labelpath) {
labelPtr = &(cachePtr->labels[ll]);
- // if(!cachePtr->text || strlen(cachePtr->text) == 0) {
- if(!labelPtr->annotext || strlen(labelPtr->annotext) == 0) {
- if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { /* there might be a marker to be added to the image */
- /* TODO: at the moment only checks the bottom (e.g. first) marker style, perhaps should check all of them */
- cachePtr->status = MS_TRUE;
- if(msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
- return MS_FAILURE;
+ if(!labelPtr->annotext || strlen(labelPtr->annotext) == 0)
+ continue; /* skip this label, nothing to with curved labels when there is nothing to draw */
- marker_rect.minx = MS_NINT(cachePtr->point.x - .5 * marker_width);
- marker_rect.miny = MS_NINT(cachePtr->point.y - .5 * marker_height);
- marker_rect.maxx = marker_rect.minx + (marker_width-1);
- marker_rect.maxy = marker_rect.miny + (marker_height-1);
- msRectToPolygon(marker_rect, cachePtr->poly);
-
- if(!labelPtr->force)
- msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, label_buffer + map_edge_buffer, cachePtr, priority, l, label_mindistance, 0);
+ /* path-following labels *must* be 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;
- if(cachePtr->status == MS_FALSE)
- continue;
-
- /* here's where we draw the label styles - RFC 77: this should be moved to the end */
- if(cachePtr->label.numstyles > 0) {
- for(i=0; i<cachePtr->label.numstyles; i++) {
- if(cachePtr->label.styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT)
- msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), cachePtr->label.styles[i], layerPtr->scalefactor);
- else if(cachePtr->label.styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
- msDrawShadeSymbol(&map->symbolset, image, &labelPoly, cachePtr->label.styles[i], layerPtr->scalefactor);
- } else {
- /* TODO: need error msg about unsupported geomtransform */
- return MS_FAILURE;
- }
- }
- }
-
- 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);
- }
- }
- } else {
-
- 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,cachePtr->text,size,&r,NULL) != MS_SUCCESS)
- return MS_FAILURE;
-
->>>> here
- /* adjust the baseline (see #1449) */
+ if(msGetLabelSize(map, labelPtr, cachePtr->text, 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');
if(!nNewlines) {
@@ -2361,59 +2318,101 @@
}
}
- drawLabelPoly = MS_FALSE;
- for(i=0; i<labelPtr->numstyles; i++) {
- if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
- drawLabelPoly = MS_TRUE;
- break;
- }
- }
-
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 cachePtr->featuresize is set to -1, this check has been done in msPolylineLabelPath() */
- if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
- continue; /* label too large relative to the feature */
+
+ /* copy the bounds into the cache's polygon */
+ msCopyShape(&(cachePtr->labelpath->bounds), cachePtr->poly);
+ msFreeShape(&(cachePtr->labelpath->bounds));
- marker_offset_x = marker_offset_y = 0; /* assume no marker */
- if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { /* there might be a marker added to the image */
+ /* compare against image bounds, rendered labels and markers (sets cachePtr->status), if FORCE=TRUE then skip it */
+ cachePtr->status = MS_TRUE;
+ if(!labelPtr->force)
+ msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, label_buffer + map_edge_buffer, cachePtr, priority, l, label_mindistance, (r.maxx-r.minx));
+ } else {
+ int drawLabelText;
+
+ /* all other cases *could* have multiple labels defined */
+ for(ll=(cachePtr->numlabels-1); ll>=0; ll--) {
+ labelPtr = &(cachePtr->labels[ll]);
+
+ drawLabelText = MS_FALSE;
+ if(labelPtr->annotext && strlen(labelPtr->annotext) > 0) {
+ drawLabelText = MS_TRUE;
+
+ 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, cachePtr->text, size, &r, NULL) != MS_SUCCESS)
+ return MS_FAILURE;
+
+ /* adjust the baseline (see #1449) */
+ if(labelPtr->type == MS_TRUETYPE) {
+ int nNewlines = msCountChars(cachePtr->text,'\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);
+ labelPtr->offsety += (MS_NINT(((rect2.miny+rect2.maxy) + size) / 2))/scalefactor;
+ labelPtr->offsetx += (MS_NINT(rect2.minx / 2))/scalefactor;
+ free(firstLine);
+ }
+ }
- /* TODO: at the moment only checks the bottom (first) marker style, perhaps should check all of them */
- if(msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
- return MS_FAILURE;
-
- marker_offset_x = MS_NINT(marker_width/2.0);
- marker_offset_y = MS_NINT(marker_height/2.0);
-
- marker_rect.minx = MS_NINT(cachePtr->point.x - .5 * marker_width);
- marker_rect.miny = MS_NINT(cachePtr->point.y - .5 * marker_height);
- marker_rect.maxx = marker_rect.minx + (marker_width-1);
- marker_rect.maxy = marker_rect.miny + (marker_height-1);
- } else if (layerPtr->type == MS_LAYER_POINT) { /* there is a marker already in the image */
- marker_rect = markerPtr->poly->bounds;
- marker_width = marker_rect.maxx - marker_rect.minx;
- marker_height = marker_rect.maxy - marker_rect.miny;
- marker_offset_x = MS_NINT(marker_width/2.0);
- marker_offset_y = MS_NINT(marker_height/2.0);
- }
+ drawLabelPoly = MS_FALSE;
+ for(i=0; i<labelPtr->numstyles; i++) {
+ if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
+ drawLabelPoly = MS_TRUE;
+ break;
+ }
+ }
- /* handle path following labels first (position does not matter) */
- if(cachePtr->labelpath) {
- cachePtr->status = MS_TRUE;
+ 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 cachePtr->featuresize is set to -1, this check has been done in msPolylineLabelPath() */
+ if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
+ continue; /* label too large relative to the feature */
+ }
- /* Copy the bounds into the cache's polygon */
- msCopyShape(&(cachePtr->labelpath->bounds), cachePtr->poly);
- msFreeShape(&(cachePtr->labelpath->bounds));
+ /*** TODO: SEE branch-6-0 FOR CHANGES DEALING WITH LABEL STYLES ***/
+ marker_offset_x = marker_offset_y = 0; /* assume no marker */
+ if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) {
- /* Compare against image bounds, rendered labels and markers (sets cachePtr->status), if FORCE=TRUE then skip it */
- if(!labelPtr->force)
- msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, label_buffer + map_edge_buffer, cachePtr, priority, l, label_mindistance, (r.maxx-r.minx));
- } else {
+ /* 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)
+ return MS_FAILURE;
- if(labelPtr->position == MS_AUTO) {
+ marker_offset_x = MS_NINT(marker_width/2.0);
+ marker_offset_y = MS_NINT(marker_height/2.0);
+
+ marker_rect.minx = MS_NINT(cachePtr->point.x - .5 * marker_width);
+ marker_rect.miny = MS_NINT(cachePtr->point.y - .5 * marker_height);
+ marker_rect.maxx = marker_rect.minx + (marker_width-1);
+ marker_rect.maxy = marker_rect.miny + (marker_height-1);
+ } else if (layerPtr->type == MS_LAYER_POINT) { /* there is a marker already in the image */
+ marker_rect = markerPtr->poly->bounds;
+ marker_width = marker_rect.maxx - marker_rect.minx;
+ marker_height = marker_rect.maxy - marker_rect.miny;
+ marker_offset_x = MS_NINT(marker_width/2.0);
+ marker_offset_y = MS_NINT(marker_height/2.0);
+ }
+
+ if(drawLabelText && labelPtr->position == MS_AUTO) {
int positions[MS_POSITIONS_LENGTH], npositions=0;
/*
More information about the mapserver-commits
mailing list