@@ -50,7 +50,7 @@ static utfpix32 UTF_WATER = utfpix32(32);
50
50
51
51
#define utfitem (c ) utfpix32(c)
52
52
53
- struct shapeData
53
+ struct shapeData
54
54
{
55
55
char *datavalues;
56
56
char *itemvalue;
@@ -71,7 +71,7 @@ class lookupTable {
71
71
counter = 0 ;
72
72
}
73
73
74
- ~lookupTable ()
74
+ ~lookupTable ()
75
75
{
76
76
int i;
77
77
@@ -82,7 +82,7 @@ class lookupTable {
82
82
if (table[i].itemvalue )
83
83
msFree (table[i].itemvalue );
84
84
}
85
- msFree (table);
85
+ msFree (table);
86
86
}
87
87
88
88
shapeData *table;
@@ -96,12 +96,12 @@ class lookupTable {
96
96
class polygon_adaptor_utf :public polygon_adaptor
97
97
{
98
98
public:
99
- polygon_adaptor_utf (shapeObj *shape,int utfres_in):polygon_adaptor(shape)
99
+ polygon_adaptor_utf (shapeObj *shape,int utfres_in):polygon_adaptor(shape)
100
100
{
101
101
utfresolution = utfres_in;
102
102
}
103
103
104
- virtual unsigned vertex (double * x, double * y)
104
+ virtual unsigned vertex (double * x, double * y)
105
105
{
106
106
if (m_point < m_pend) {
107
107
bool first = m_point == m_line->point ;
@@ -125,7 +125,7 @@ class polygon_adaptor_utf:public polygon_adaptor
125
125
}
126
126
return mapserver::path_cmd_stop;
127
127
}
128
-
128
+
129
129
private:
130
130
int utfresolution;
131
131
};
@@ -136,7 +136,7 @@ class polygon_adaptor_utf:public polygon_adaptor
136
136
class line_adaptor_utf :public line_adaptor
137
137
{
138
138
public:
139
- line_adaptor_utf (shapeObj *shape,int utfres_in):line_adaptor(shape)
139
+ line_adaptor_utf (shapeObj *shape,int utfres_in):line_adaptor(shape)
140
140
{
141
141
utfresolution = utfres_in;
142
142
}
@@ -152,8 +152,8 @@ class line_adaptor_utf:public line_adaptor
152
152
}
153
153
m_line++;
154
154
*x = *y = 0.0 ;
155
- if (m_line>=m_lend)
156
- return mapserver::path_cmd_stop;
155
+ if (m_line>=m_lend)
156
+ return mapserver::path_cmd_stop;
157
157
158
158
m_point=m_line->point ;
159
159
m_pend=&(m_line->point [m_line->numpoints ]);
@@ -217,6 +217,24 @@ unsigned int encodeForRendering(unsigned int toencode)
217
217
return encoded;
218
218
}
219
219
220
+ /*
221
+ * Decode value to have the initial one
222
+ */
223
+ unsigned int decodeRendered (unsigned int todecode)
224
+ {
225
+ unsigned int decoded;
226
+
227
+ if (todecode >= 92 )
228
+ todecode --;
229
+
230
+ if (todecode >= 34 )
231
+ todecode --;
232
+
233
+ decoded = todecode-32 ;
234
+
235
+ return decoded;
236
+ }
237
+
220
238
/*
221
239
* Allocate more memory to the table if necessary.
222
240
*/
@@ -285,8 +303,8 @@ band_type addToTable(UTFGridRenderer *r, shapeObj *p)
285
303
/*
286
304
* Use AGG to render any path.
287
305
*/
288
- template <class vertex_source >
289
- int utfgridRenderPath (imageObj *img, vertex_source &path)
306
+ template <class vertex_source >
307
+ int utfgridRenderPath (imageObj *img, vertex_source &path)
290
308
{
291
309
UTFGridRenderer *r = UTFGRID_RENDERER (img);
292
310
r->m_rasterizer .reset ();
@@ -359,6 +377,91 @@ int utfgridFreeImage(imageObj *img)
359
377
return MS_SUCCESS;
360
378
}
361
379
380
+ /*
381
+ * Update a character in the utfgrid.
382
+ */
383
+
384
+ int utfgridUpdateChar (imageObj *img, band_type oldChar, band_type newChar)
385
+ {
386
+ UTFGridRenderer *r = UTFGRID_RENDERER (img);
387
+ int i,bufferLength;
388
+
389
+ bufferLength = (img->height /r->utfresolution ) * (img->width /r->utfresolution );
390
+
391
+ for (i=0 ;i<bufferLength;i++){
392
+ if (r->buffer [i] == oldChar)
393
+ r->buffer [i] = newChar;
394
+ }
395
+
396
+ return MS_SUCCESS;
397
+ }
398
+
399
+ /*
400
+ * Remove unnecessary data that didn't made it to the final grid.
401
+ */
402
+
403
+ int utfgridCleanData (imageObj *img)
404
+ {
405
+ UTFGridRenderer *r = UTFGRID_RENDERER (img);
406
+ unsigned char * usedChar;
407
+ int i,bufferLength,itemFound,dataCounter;
408
+ shapeData* updatedData;
409
+ band_type utfvalue;
410
+
411
+ bufferLength = (img->height /r->utfresolution ) * (img->width /r->utfresolution );
412
+
413
+ usedChar =(unsigned char *) msSmallMalloc (r->data ->counter *sizeof (unsigned char ));
414
+
415
+ for (i=0 ;i<r->data ->counter ;i++){
416
+ usedChar[i]=0 ;
417
+ }
418
+
419
+ itemFound=0 ;
420
+
421
+ for (i=0 ;i<bufferLength;i++)
422
+ {
423
+ if (decodeRendered (r->buffer [i]) != 0 && usedChar[decodeRendered (r->buffer [i])-1 ]==0 )
424
+ {
425
+ itemFound++;
426
+ usedChar[decodeRendered (r->buffer [i])-1 ] = 1 ;
427
+ }
428
+ }
429
+
430
+ updatedData = (shapeData*) msSmallMalloc (itemFound * sizeof (shapeData));
431
+ dataCounter = 0 ;
432
+
433
+ for (i=0 ; i< r->data ->counter ; i++){
434
+ if (usedChar[decodeRendered (r->data ->table [i].utfvalue )-1 ]==1 ){
435
+ updatedData[dataCounter] = r->data ->table [i];
436
+
437
+ updatedData[dataCounter].serialid =dataCounter+1 ;
438
+
439
+ utfvalue=encodeForRendering (dataCounter+1 );
440
+
441
+ utfgridUpdateChar (img,updatedData[dataCounter].utfvalue ,utfvalue);
442
+ updatedData[dataCounter].utfvalue = utfvalue;
443
+
444
+ dataCounter++;
445
+ }
446
+ else {
447
+ if (r->data ->table [i].datavalues )
448
+ msFree (r->data ->table [i].datavalues );
449
+ if (r->data ->table [i].itemvalue )
450
+ msFree (r->data ->table [i].itemvalue );
451
+ }
452
+ }
453
+
454
+ msFree (usedChar);
455
+
456
+ msFree (r->data ->table );
457
+
458
+ r->data ->table = updatedData;
459
+ r->data ->counter = dataCounter;
460
+ r->data ->size = dataCounter;
461
+
462
+ return MS_SUCCESS;
463
+ }
464
+
362
465
/*
363
466
* Print the renderer datas as a JSON.
364
467
*/
@@ -367,20 +470,22 @@ int utfgridSaveImage(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *form
367
470
int row, col, i, imgheight, imgwidth;
368
471
band_type pixelid;
369
472
char * pszEscaped;
370
-
473
+
474
+ utfgridCleanData (img);
475
+
371
476
UTFGridRenderer *renderer = UTFGRID_RENDERER (img);
372
477
373
478
if (renderer->layerwatch >1 )
374
- return MS_FAILURE;
479
+ return MS_FAILURE;
375
480
376
481
imgheight = img->height /renderer->utfresolution ;
377
482
imgwidth = img->width /renderer->utfresolution ;
378
483
379
484
fprintf (fp," {\" grid\" :[" );
380
485
381
- /* Print the buffer, also */
486
+ /* Print the buffer, also */
382
487
for (row=0 ; row<imgheight; row++) {
383
-
488
+
384
489
wchar_t *string = (wchar_t *) msSmallMalloc ((imgwidth + 1 ) * sizeof (wchar_t ));
385
490
wchar_t *stringptr;
386
491
stringptr = string;
@@ -393,11 +498,11 @@ int utfgridSaveImage(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *form
393
498
pixelid = renderer->buffer [(row*imgwidth)+col];
394
499
395
500
*stringptr = pixelid;
396
- stringptr++;
501
+ stringptr++;
397
502
}
398
503
399
504
/* Convertion to UTF-8 encoding */
400
- *stringptr = ' \0 ' ;
505
+ *stringptr = ' \0 ' ;
401
506
char * utf8;
402
507
utf8 = msConvertWideStringToUTF8 (string, " UCS-4LE" );
403
508
fprintf (fp," %s" , utf8);
@@ -409,7 +514,7 @@ int utfgridSaveImage(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *form
409
514
fprintf (fp," ],\" keys\" :[\"\" " );
410
515
411
516
/* Prints the key specified */
412
- for (i=0 ;i<renderer->data ->counter ;i++) {
517
+ for (i=0 ;i<renderer->data ->counter ;i++) {
413
518
fprintf (fp," ," );
414
519
415
520
if (renderer->useutfitem )
@@ -504,11 +609,11 @@ int utfgridEndLayer(imageObj *img, mapObj *map, layerObj *layer)
504
609
* Do the table operations on the shapes. Allow multiple type of data to be rendered.
505
610
*/
506
611
int utfgridStartShape (imageObj *img, shapeObj *shape)
507
- {
612
+ {
508
613
UTFGridRenderer *r = UTFGRID_RENDERER (img);
509
614
510
615
if (!r->renderlayer )
511
- return MS_FAILURE;
616
+ return MS_FAILURE;
512
617
513
618
/* Table operations */
514
619
r->utfvalue = addToTable (r, shape);
@@ -521,7 +626,7 @@ int utfgridStartShape(imageObj *img, shapeObj *shape)
521
626
*/
522
627
int utfgridEndShape (imageObj *img, shapeObj *shape)
523
628
{
524
- UTFGridRenderer *r = UTFGRID_RENDERER (img);
629
+ UTFGridRenderer *r = UTFGRID_RENDERER (img);
525
630
526
631
r->utfvalue = 0 ;
527
632
return MS_SUCCESS;
@@ -547,7 +652,7 @@ int utfgridRenderPolygon(imageObj *img, shapeObj *polygonshape, colorObj *color)
547
652
}
548
653
549
654
/*
550
- * Function that render lines into UTFGrid. Starts by looking if the line is a polygon
655
+ * Function that render lines into UTFGrid. Starts by looking if the line is a polygon
551
656
* outline. Then draw it if it's not.
552
657
*/
553
658
int utfgridRenderLine (imageObj *img, shapeObj *lineshape, strokeStyleObj *linestyle)
@@ -567,7 +672,7 @@ int utfgridRenderLine(imageObj *img, shapeObj *lineshape, strokeStyleObj *linest
567
672
} else {
568
673
r->stroke ->attach (lines);
569
674
}
570
- r->stroke ->width (linestyle->width /r->utfresolution );
675
+ r->stroke ->width (linestyle->width /r->utfresolution );
571
676
utfgridRenderPath (img, *r->stroke );
572
677
573
678
return MS_SUCCESS;
@@ -585,7 +690,7 @@ int utfgridRenderVectorSymbol(imageObj *img, double x, double y, symbolObj *symb
585
690
/* utfvalue is set to 0 if the shape isn't in the table. */
586
691
if (r->utfvalue == 0 ) {
587
692
return MS_FAILURE;
588
- }
693
+ }
589
694
590
695
/* Pathing the symbol */
591
696
mapserver::path_storage path = imageVectorSymbol (symbol);
@@ -615,12 +720,12 @@ int utfgridRenderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symb
615
720
/* utfvalue is set to 0 if the shape isn't in the table. */
616
721
if (r->utfvalue == 0 ) {
617
722
return MS_FAILURE;
618
- }
723
+ }
619
724
620
725
/* Pathing the symbol BBox */
621
726
mapserver::path_storage pixmap_bbox;
622
727
double w, h;
623
- w = pixmap->width *style->scale /(2.0 );
728
+ w = pixmap->width *style->scale /(2.0 );
624
729
h= pixmap->height *style->scale /(2.0 );
625
730
pixmap_bbox.move_to ((x-w)/r->utfresolution ,(y-h)/r->utfresolution );
626
731
pixmap_bbox.line_to ((x+w)/r->utfresolution ,(y-h)/r->utfresolution );
@@ -643,13 +748,13 @@ int utfgridRenderEllipseSymbol(imageObj *img, double x, double y, symbolObj *sym
643
748
/* utfvalue is set to 0 if the shape isn't in the table. */
644
749
if (r->utfvalue == 0 ) {
645
750
return MS_FAILURE;
646
- }
751
+ }
647
752
648
753
/* Pathing the symbol. */
649
754
mapserver::path_storage path;
650
755
mapserver::ellipse ellipse (x/r->utfresolution ,y/r->utfresolution ,symbol->sizex *style->scale /2 /r->utfresolution ,symbol->sizey *style->scale /2 /r->utfresolution );
651
756
path.concat_path (ellipse);
652
-
757
+
653
758
/* Rotation if necessary. */
654
759
if ( style->rotation != 0 ) {
655
760
mapserver::trans_affine mtx;
@@ -686,7 +791,7 @@ int msPopulateRendererVTableUTFGrid( rendererVTableObj *renderer )
686
791
renderer->saveImage = &utfgridSaveImage;
687
792
688
793
renderer->startLayer = &utfgridStartLayer;
689
- renderer->endLayer = &utfgridEndLayer;
794
+ renderer->endLayer = &utfgridEndLayer;
690
795
691
796
renderer->startShape = &utfgridStartShape;
692
797
renderer->endShape = &utfgridEndShape;
0 commit comments