Skip to content

Commit 5ffa2f2

Browse files
committed
msOGRUpdateStyle(): split it in 4 subfunctions. No functional change
1 parent 18ef92d commit 5ffa2f2

File tree

1 file changed

+75
-24
lines changed

1 file changed

+75
-24
lines changed

mapogr.cpp

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,17 @@ static int msOGRGetSymbolId(symbolSetObj *symbolset, const char *pszSymbolId,
28872887
}
28882888
#endif
28892889

2890+
#ifdef USE_OGR
2891+
2892+
static int msOGRUpdateStyleParseLabel(mapObj *map, layerObj *layer, classObj *c,
2893+
OGRStyleToolH hLabelStyle);
2894+
static int msOGRUpdateStyleParsePen(mapObj *map, layerObj *layer, classObj *c,
2895+
OGRStyleToolH hPenStyle, int bIsBrush);
2896+
static int msOGRUpdateStyleParseBrush(mapObj *map, layerObj *layer, classObj *c,
2897+
OGRStyleToolH hBrushStyle, int* pbIsBrush);
2898+
static int msOGRUpdateStyleParseSymbol(mapObj *map, layerObj *layer, classObj *c,
2899+
OGRStyleToolH hSymbolStyle);
2900+
28902901
/**********************************************************************
28912902
* msOGRUpdateStyle()
28922903
*
@@ -2895,13 +2906,9 @@ static int msOGRGetSymbolId(symbolSetObj *symbolset, const char *pszSymbolId,
28952906
* msOGRUpdateStyleFromString
28962907
**********************************************************************/
28972908

2898-
#ifdef USE_OGR
28992909
static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer, classObj *c)
29002910
{
2901-
GBool bIsNull, bIsBrush=MS_FALSE;
2902-
int r=0,g=0,b=0,t=0;
2903-
double dfTmp;
2904-
int try_addimage_if_notfound = MS_FALSE;
2911+
GBool bIsBrush=MS_FALSE;
29052912
int numParts = OGR_SM_GetPartCount(hStyleMgr, NULL);
29062913

29072914
/* ------------------------------------------------------------------
@@ -2928,7 +2935,34 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
29282935
OGR_ST_SetUnit(hStylePart, OGRSTUPixel, map->cellsize*72.0*39.37);
29292936

29302937
if (eStylePartType == OGRSTCLabel) {
2931-
OGRStyleToolH hLabelStyle = hStylePart;
2938+
int ret = msOGRUpdateStyleParseLabel(map, layer, c, hStylePart);
2939+
if( ret != MS_SUCCESS )
2940+
return ret;
2941+
} else if (eStylePartType == OGRSTCPen) {
2942+
int ret = msOGRUpdateStyleParsePen(map, layer, c, hStylePart, bIsBrush);
2943+
if( ret != MS_SUCCESS )
2944+
return ret;
2945+
} else if (eStylePartType == OGRSTCBrush) {
2946+
int ret = msOGRUpdateStyleParseBrush(map, layer, c, hStylePart, &bIsBrush);
2947+
if( ret != MS_SUCCESS )
2948+
return ret;
2949+
} else if (eStylePartType == OGRSTCSymbol) {
2950+
int ret = msOGRUpdateStyleParseSymbol(map, layer, c, hStylePart);
2951+
if( ret != MS_SUCCESS )
2952+
return ret;
2953+
}
2954+
2955+
OGR_ST_Destroy(hStylePart);
2956+
2957+
}
2958+
return MS_SUCCESS;
2959+
}
2960+
2961+
static int msOGRUpdateStyleParseLabel(mapObj *map, layerObj *layer, classObj *c,
2962+
OGRStyleToolH hLabelStyle)
2963+
{
2964+
GBool bIsNull;
2965+
int r=0,g=0,b=0,t=0;
29322966

29332967
// Enclose the text string inside quotes to make sure it is seen
29342968
// as a string by the parser inside loadExpression(). (bug185)
@@ -3073,8 +3107,15 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
30733107
if (!bFont) {
30743108
c->labels[0]->size = MS_MEDIUM;
30753109
}
3076-
} else if (eStylePartType == OGRSTCPen) {
3077-
OGRStyleToolH hPenStyle = hStylePart;
3110+
3111+
return MS_SUCCESS;
3112+
}
3113+
3114+
static int msOGRUpdateStyleParsePen(mapObj *map, layerObj *layer, classObj *c,
3115+
OGRStyleToolH hPenStyle, int bIsBrush)
3116+
{
3117+
GBool bIsNull;
3118+
int r=0,g=0,b=0,t=0;
30783119

30793120
const char *pszPenName, *pszPattern, *pszCap, *pszJoin;
30803121
colorObj oPenColor;
@@ -3201,7 +3242,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
32013242
// This is a multipart symbology, so pen defn goes in the
32023243
// overlaysymbol params
32033244
if (msMaybeAllocateClassStyle(c, 1)) {
3204-
OGR_ST_Destroy(hStylePart);
3245+
OGR_ST_Destroy(hPenStyle);
32053246
return(MS_FAILURE);
32063247
}
32073248

@@ -3219,7 +3260,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
32193260
} else {
32203261
// Single part symbology
32213262
if (msMaybeAllocateClassStyle(c, 0)) {
3222-
OGR_ST_Destroy(hStylePart);
3263+
OGR_ST_Destroy(hPenStyle);
32233264
return(MS_FAILURE);
32243265
}
32253266

@@ -3240,8 +3281,14 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
32403281
memcpy(c->styles[0]->pattern, pattern, sizeof(double) * patternlength);
32413282
}
32423283

3243-
} else if (eStylePartType == OGRSTCBrush) {
3244-
OGRStyleToolH hBrushStyle = hStylePart;
3284+
return MS_SUCCESS;
3285+
}
3286+
3287+
static int msOGRUpdateStyleParseBrush(mapObj *map, layerObj *layer, classObj *c,
3288+
OGRStyleToolH hBrushStyle, int* pbIsBrush)
3289+
{
3290+
GBool bIsNull;
3291+
int r=0,g=0,b=0,t=0;
32453292

32463293
const char *pszBrushName = OGR_ST_GetParamStr(hBrushStyle,
32473294
OGRSTBrushId,
@@ -3250,7 +3297,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
32503297

32513298
/* We need 1 style */
32523299
if (msMaybeAllocateClassStyle(c, 0)) {
3253-
OGR_ST_Destroy(hStylePart);
3300+
OGR_ST_Destroy(hBrushStyle);
32543301
return(MS_FAILURE);
32553302
}
32563303

@@ -3259,7 +3306,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
32593306
if (pszBrushName && strstr(pszBrushName, "ogr-brush-1") != NULL) {
32603307
MS_INIT_COLOR(c->styles[0]->color, -1, -1, -1, 255);
32613308
} else {
3262-
bIsBrush = TRUE;
3309+
*pbIsBrush = TRUE;
32633310
const char *pszColor = OGR_ST_GetParamStr(hBrushStyle,
32643311
OGRSTBrushFColor,
32653312
&bIsNull);
@@ -3312,12 +3359,19 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
33123359
}
33133360
}
33143361
}
3315-
} else if (eStylePartType == OGRSTCSymbol) {
3316-
OGRStyleToolH hSymbolStyle = hStylePart;
3362+
3363+
return MS_SUCCESS;
3364+
}
3365+
3366+
static int msOGRUpdateStyleParseSymbol(mapObj *map, layerObj *layer, classObj *c,
3367+
OGRStyleToolH hSymbolStyle)
3368+
{
3369+
GBool bIsNull;
3370+
int r=0,g=0,b=0,t=0;
33173371

33183372
/* We need 1 style */
33193373
if (msMaybeAllocateClassStyle(c, 0)) {
3320-
OGR_ST_Destroy(hStylePart);
3374+
OGR_ST_Destroy(hSymbolStyle);
33213375
return(MS_FAILURE);
33223376
}
33233377

@@ -3343,7 +3397,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
33433397
c->styles[0]->angle = OGR_ST_GetParamNum(hSymbolStyle,
33443398
OGRSTSymbolAngle,
33453399
&bIsNull);
3346-
dfTmp = OGR_ST_GetParamNum(hSymbolStyle, OGRSTSymbolSize, &bIsNull);
3400+
double dfTmp = OGR_ST_GetParamNum(hSymbolStyle, OGRSTSymbolSize, &bIsNull);
33473401
if (!bIsNull)
33483402
c->styles[0]->size = dfTmp;
33493403

@@ -3357,7 +3411,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
33573411
if (bIsNull)
33583412
pszName = NULL;
33593413

3360-
try_addimage_if_notfound = MS_FALSE;
3414+
int try_addimage_if_notfound = MS_FALSE;
33613415
#ifdef USE_CURL
33623416
if (pszName && strncasecmp(pszName, "http", 4) == 0)
33633417
try_addimage_if_notfound =MS_TRUE;
@@ -3366,13 +3420,10 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
33663420
c->styles[0]->symbol = msOGRGetSymbolId(&(map->symbolset),
33673421
pszName,
33683422
"default-marker", try_addimage_if_notfound);
3369-
}
33703423

3371-
OGR_ST_Destroy(hStylePart);
3372-
3373-
}
3374-
return MS_SUCCESS;
3424+
return MS_SUCCESS;
33753425
}
3426+
33763427
#endif /* USE_OGR */
33773428

33783429

0 commit comments

Comments
 (0)