Skip to content

Commit

Permalink
Modify renderGlyphs() virtual method to pass the full textSymbolObj, …
Browse files Browse the repository at this point in the history
…and adapt KML renderer to it (fixes #6174)
  • Loading branch information
rouault committed Aug 11, 2021
1 parent 3def5fc commit 345170c
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 20 deletions.
3 changes: 2 additions & 1 deletion mapagg.cpp
Expand Up @@ -527,8 +527,9 @@ int agg2RenderPolygonTiled(imageObj *img, shapeObj *p, imageObj * tile)
return MS_SUCCESS;
}

int agg2RenderGlyphsPath(imageObj *img, textPathObj *tp, colorObj *c, colorObj *oc, int ow, int /*isMarker*/) {
int agg2RenderGlyphsPath(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow, int /*isMarker*/) {

const textPathObj *tp = ts->textpath;
mapserver::path_storage glyphs;
mapserver::trans_affine trans;
AGG2Renderer *r = AGG_RENDERER(img);
Expand Down
3 changes: 2 additions & 1 deletion mapcairo.c
Expand Up @@ -407,7 +407,8 @@ int renderTileCairo(imageObj *img, imageObj *tile, double x, double y)
return MS_SUCCESS;
}

int renderGlyphs2Cairo(imageObj *img, textPathObj *tp, colorObj *c, colorObj *oc, int ow, int isMarker) {
int renderGlyphs2Cairo(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow, int isMarker) {
const textPathObj *tp = ts->textpath;
cairo_renderer *r = CAIRO_RENDERER(img);
cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img);
cairoFaceCache *cairo_face = NULL;
Expand Down
6 changes: 3 additions & 3 deletions mapkml.cpp
Expand Up @@ -86,10 +86,10 @@ extern "C" {
return MS_SUCCESS;
}

int msRenderGlyphsKml(imageObj *img, pointObj *labelpnt, char *text, double angle, colorObj *clr, colorObj *olcolor, int olwidth)
int msRenderGlyphsKml(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow, int /*isMarker*/)
{
KmlRenderer* renderer = getKmlRenderer(img);
renderer->renderGlyphs(img, labelpnt, text, angle, clr, olcolor, olwidth);
renderer->renderGlyphs(img, ts, c, oc, ow);
return MS_SUCCESS;
}

Expand Down Expand Up @@ -225,7 +225,7 @@ int msPopulateRendererVTableKML( rendererVTableObj *renderer )
renderer->createImage=&msCreateImageKml;
renderer->saveImage=&msSaveImageKml;
renderer->renderPolygon=&msRenderPolygonKml;
renderer->renderText=&msRenderGlyphsKml;
renderer->renderGlyphs=&msRenderGlyphsKml;
renderer->renderEllipseSymbol = &msRenderEllipseSymbolKml;
renderer->renderVectorSymbol = &msRenderVectorSymbolKml;
renderer->renderPixmapSymbol = &msRenderPixmapSymbolKml;
Expand Down
13 changes: 7 additions & 6 deletions mapkmlrenderer.cpp
Expand Up @@ -666,9 +666,10 @@ void KmlRenderer::addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts
xmlNodeAddContent(coordsNode, BAD_CAST "\t");
}

void KmlRenderer::renderGlyphs(imageObj *, pointObj *labelpnt, char *text, double /*angle*/, colorObj *clr, colorObj * /*olcolor*/, int /*olwidth*/)
void KmlRenderer::renderGlyphs(imageObj *, const textSymbolObj *ts, colorObj *clr, colorObj * /*oc*/, int /*ow*/)
{
xmlNodePtr node;
if( ts->annotext == NULL || ts->textpath->numglyphs == 0 )
return;

if (PlacemarkNode == NULL)
PlacemarkNode = createPlacemarkNode(LayerNode, NULL);
Expand All @@ -680,12 +681,12 @@ void KmlRenderer::renderGlyphs(imageObj *, pointObj *labelpnt, char *text, doubl
SymbologyFlag[Label] = 1;

/*there is alaws a default name (layer.shapeid). Replace it*/
for (node = PlacemarkNode->children; node; node = node->next) {
for (xmlNodePtr node = PlacemarkNode->children; node; node = node->next) {
if (node->type != XML_ELEMENT_NODE)
continue;

if (strcmp((char *)node->name, "name") == 0) {
xmlNodeSetContent(node, BAD_CAST text);
xmlNodeSetContent(node, BAD_CAST ts->annotext);
break;
}
}
Expand All @@ -696,8 +697,8 @@ void KmlRenderer::renderGlyphs(imageObj *, pointObj *labelpnt, char *text, doubl
addAddRenderingSpecifications(geomNode);

pointObj pt;
pt.x = labelpnt->x;
pt.y = labelpnt->y;
pt.x = ts->textpath->glyphs[0].pnt.x;
pt.y = ts->textpath->glyphs[0].pnt.y;
addCoordsNode(geomNode, &pt, 1);
}

Expand Down
3 changes: 1 addition & 2 deletions mapkmlrenderer.h
Expand Up @@ -133,7 +133,6 @@ class KmlRenderer

void renderLineVector(imageObj *img, shapeObj *p, strokeStyleObj *style);
void renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color);
void renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text);

const char* lookupPlacemarkStyle();
void flushPlacemark();
Expand All @@ -160,7 +159,7 @@ class KmlRenderer
void renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style);
void renderPolygon(imageObj *img, shapeObj *p, colorObj *color);

void renderGlyphs(imageObj *img, pointObj *labelpnt, char *text, double angle, colorObj *clr, colorObj *olcolor, int olwidth);
void renderGlyphs(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow);

// Symbols
void renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
Expand Down
11 changes: 7 additions & 4 deletions maprendering.c
Expand Up @@ -179,7 +179,7 @@ tileCacheObj *addTileCache(imageObj *img,
}

/* helper function to center glyph on the desired point */
int WARN_UNUSED drawGlyphMarker(imageObj *img, face_element *face, glyph_element *glyphc, double px, double py, int size, double rotation,
static int drawGlyphMarker(imageObj *img, face_element *face, glyph_element *glyphc, double px, double py, int size, double rotation,
colorObj *clr, colorObj *oclr, int olwidth)
{
double ox, oy;
Expand Down Expand Up @@ -210,7 +210,10 @@ int WARN_UNUSED drawGlyphMarker(imageObj *img, face_element *face, glyph_element
glyph.pnt.x = px - ox;
glyph.pnt.y = py + oy;
}
return renderer->renderGlyphs(img, &path, clr, oclr, olwidth, MS_TRUE);
textSymbolObj ts;
memset(&ts, 0, sizeof(ts));
ts.textpath = &path;
return renderer->renderGlyphs(img, &ts, clr, oclr, olwidth, MS_TRUE);
}


Expand Down Expand Up @@ -1045,7 +1048,7 @@ int msDrawTextSymbol(mapObj *map, imageObj *image, pointObj labelPnt, textSymbol
ts_shadow->textpath->glyphs[g].pnt.y += oy;
}

ret = renderer->renderGlyphs(image,ts_shadow->textpath,&ts->label->shadowcolor,NULL,0, MS_FALSE);
ret = renderer->renderGlyphs(image,ts_shadow,&ts->label->shadowcolor,NULL,0, MS_FALSE);
freeTextSymbol(ts_shadow);
msFree(ts_shadow);
if( ret != MS_SUCCESS )
Expand All @@ -1057,7 +1060,7 @@ int msDrawTextSymbol(mapObj *map, imageObj *image, pointObj labelPnt, textSymbol
if(MS_VALID_COLOR(ts->label->outlinecolor))
oc = &ts->label->outlinecolor;
ow = MS_NINT((double)ts->label->outlinewidth * ((double)ts->textpath->glyph_size / (double)ts->label->size));
return renderer->renderGlyphs(image,ts->textpath,c,oc,ow, MS_FALSE);
return renderer->renderGlyphs(image,ts,c,oc,ow, MS_FALSE);

}

Expand Down
4 changes: 2 additions & 2 deletions mapserver.h
Expand Up @@ -3211,8 +3211,8 @@ extern "C" {
int WARN_UNUSED (*renderPolygonTiled)(imageObj *img, shapeObj *p, imageObj *tile);
int WARN_UNUSED (*renderLineTiled)(imageObj *img, shapeObj *p, imageObj *tile);

int WARN_UNUSED (*renderGlyphs)(imageObj *img, textPathObj *tp, colorObj *clr, colorObj *olcolor, int olwidth, int isMarker);
int WARN_UNUSED (*renderText)(imageObj *img, pointObj *labelpnt, char *text, double angle, colorObj *clr, colorObj *olcolor, int olwidth);
/* only ts->textpath is guaranteed to be populated. Other fields might be 0/NULL */
int WARN_UNUSED (*renderGlyphs)(imageObj *img, const textSymbolObj *ts, colorObj *clr, colorObj *olcolor, int olwidth, int isMarker);

int WARN_UNUSED (*renderVectorSymbol)(imageObj *img, double x, double y,
symbolObj *symbol, symbolStyleObj *style);
Expand Down
3 changes: 2 additions & 1 deletion maputfgrid.cpp
Expand Up @@ -688,8 +688,9 @@ int utfgridRenderEllipseSymbol(imageObj *img, double x, double y, symbolObj *sym
}

static
int utfgridRenderGlyphs(imageObj *img, textPathObj *tp, colorObj * /*c*/, colorObj * /*oc*/, int /*ow*/, int isMarker) {
int utfgridRenderGlyphs(imageObj *img, const textSymbolObj *ts, colorObj * /*c*/, colorObj * /*oc*/, int /*ow*/, int isMarker) {

const textPathObj *tp = ts->textpath;
const UTFGridRenderer *r = UTFGRID_RENDERER(img);

/* If it's not a marker then it's a label or other thing and we dont
Expand Down

0 comments on commit 345170c

Please sign in to comment.