27
27
******************************************************************************
29
29
* $Log: mapscale.c,v $
30
* Revision 1.49.2.1 2006/03/27 05:50:52 sdlime
30
* Revision 1.52 2006/08/26 22:04:13 novak
31
* Enable support for TrueType fonts (bug 1882)
33
* Revision 1.51 2006/03/27 05:48:03 sdlime
31
34
* Fixed symbol initialization error with embedded scalebars and legends. (bug 1725)
36
* Revision 1.50 2006/02/18 20:59:13 sdlime
37
* Initial code for curved labels. (bug 1620)
33
39
* Revision 1.49 2005/09/27 15:27:18 sean
34
40
* Fixed typo to prevent extra scalebar layer creation (bug 1480)
177
183
int isx, sx, sy, ox, oy, state, dsx;
185
gdFontPtr fontPtr = NULL;
180
186
imageObj *image = NULL;
181
187
outputFormatObj *format = NULL;
183
190
if(map->units == -1) {
184
191
msSetError(MS_MISCERR, "Map units not set.", "msDrawScalebar()");
188
fontPtr = msGetBitmapFont(map->scalebar.label.size);
195
* Allow scalebars to use TrueType fonts for labels (jnovak@novacell.com)
197
* A string containing the ten decimal digits is rendered to compute an average cell size
198
* for each number, which is used later to place labels on the scalebar.
200
if( map->scalebar.label.type == MS_TRUETYPE )
206
char szTestString[] = "0123456789";
208
fontPtr = (gdFontPtr) malloc( sizeof( gdFont ) );
211
msSetError(MS_TTFERR, "fontPtr allocation failed.", "msDrawScalebar()");
215
if(! map->fontset.filename ) {
216
msSetError(MS_TTFERR, "No fontset defined.", "msDrawScalebar()");
221
if(! map->scalebar.label.font) {
222
msSetError(MS_TTFERR, "No TrueType font defined.", "msDrawScalebar()");
227
font = msLookupHashTable(&(map->fontset.fonts), map->scalebar.label.font);
229
msSetError(MS_TTFERR, "Requested font (%s) not found.", "msDrawScalebar()", map->scalebar.label.font);
234
error = gdImageStringFT( NULL, bbox, map->scalebar.label.outlinecolor.pen, font, map->scalebar.label.size, 0, 0, 0, szTestString );
237
msSetError(MS_TTFERR, "gdImageStringFT returned error %d.", "msDrawScalebar()", error );
243
fontPtr->w = (bbox[2] - bbox[0]) / strlen( szTestString );
244
fontPtr->h = (bbox[3] - bbox[5]);
246
msSetError(MS_TTFERR, "TrueType font support required.", "msDrawScalebar()");
251
fontPtr = msGetBitmapFont(map->scalebar.label.size);
189
253
if(!fontPtr) return(NULL);
191
255
map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
192
256
status = msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scale);
193
if(status != MS_SUCCESS) return(NULL);
257
if(status != MS_SUCCESS)
259
if( iFreeGDFont ) free( fontPtr );
195
262
dsx = map->scalebar.width - 2*HMARGIN;
197
264
msx = (map->cellsize * dsx)/(msInchesPerUnit(map->scalebar.units,0)/msInchesPerUnit(map->units,0));
404
479
msDrawMarkerSymbolGD(&map->symbolset, img, &point, &(map->layers[l].class[0].styles[0]), 1.0);
407
msAddLabel(map, l, 0, -1, -1, &point, " ", 1.0, NULL);
482
msAddLabel(map, l, 0, -1, -1, &point, NULL, " ", 1.0, NULL);
409
484
/* Mark layer as deleted so that it doesn't interfere with html legends or */
410
485
/* with saving maps */