Coverage Report

Created: 2025-11-16 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrfeaturestyle.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  Feature Representation string API
5
 * Author:   Stephane Villeneuve, stephane.v@videotron.ca
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2000-2001, Stephane Villeneuve
9
 * Copyright (c) 2008-2010, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#include "cpl_port.h"
15
#include "ogr_featurestyle.h"
16
17
#include <cstddef>
18
#include <cstdio>
19
#include <cstdlib>
20
#include <cstring>
21
22
#include <string>
23
24
#include "cpl_conv.h"
25
#include "cpl_error.h"
26
#include "cpl_string.h"
27
#include "cpl_vsi.h"
28
#include "ogr_api.h"
29
#include "ogr_core.h"
30
#include "ogr_feature.h"
31
32
/****************************************************************************/
33
/*                Class Parameter (used in the String)                      */
34
/*                                                                          */
35
/*      The order of all parameter MUST be the same than in the definition. */
36
/****************************************************************************/
37
static const OGRStyleParamId asStylePen[] = {
38
    {OGRSTPenColor, "c", FALSE, OGRSTypeString},
39
    {OGRSTPenWidth, "w", TRUE, OGRSTypeDouble},
40
    // Georefed, but multiple times.
41
    {OGRSTPenPattern, "p", FALSE, OGRSTypeString},
42
    {OGRSTPenId, "id", FALSE, OGRSTypeString},
43
    {OGRSTPenPerOffset, "dp", TRUE, OGRSTypeDouble},
44
    {OGRSTPenCap, "cap", FALSE, OGRSTypeString},
45
    {OGRSTPenJoin, "j", FALSE, OGRSTypeString},
46
    {OGRSTPenPriority, "l", FALSE, OGRSTypeInteger}};
47
48
static const OGRStyleParamId asStyleBrush[] = {
49
    {OGRSTBrushFColor, "fc", FALSE, OGRSTypeString},
50
    {OGRSTBrushBColor, "bc", FALSE, OGRSTypeString},
51
    {OGRSTBrushId, "id", FALSE, OGRSTypeString},
52
    {OGRSTBrushAngle, "a", FALSE, OGRSTypeDouble},
53
    {OGRSTBrushSize, "s", TRUE, OGRSTypeDouble},
54
    {OGRSTBrushDx, "dx", TRUE, OGRSTypeDouble},
55
    {OGRSTBrushDy, "dy", TRUE, OGRSTypeDouble},
56
    {OGRSTBrushPriority, "l", FALSE, OGRSTypeInteger}};
57
58
static const OGRStyleParamId asStyleSymbol[] = {
59
    {OGRSTSymbolId, "id", FALSE, OGRSTypeString},
60
    {OGRSTSymbolAngle, "a", FALSE, OGRSTypeDouble},
61
    {OGRSTSymbolColor, "c", FALSE, OGRSTypeString},
62
    {OGRSTSymbolSize, "s", TRUE, OGRSTypeDouble},
63
    {OGRSTSymbolDx, "dx", TRUE, OGRSTypeDouble},
64
    {OGRSTSymbolDy, "dy", TRUE, OGRSTypeDouble},
65
    {OGRSTSymbolStep, "ds", TRUE, OGRSTypeDouble},
66
    {OGRSTSymbolPerp, "dp", TRUE, OGRSTypeDouble},
67
    {OGRSTSymbolOffset, "di", TRUE, OGRSTypeDouble},
68
    {OGRSTSymbolPriority, "l", FALSE, OGRSTypeInteger},
69
    {OGRSTSymbolFontName, "f", FALSE, OGRSTypeString},
70
    {OGRSTSymbolOColor, "o", FALSE, OGRSTypeString}};
71
72
static const OGRStyleParamId asStyleLabel[] = {
73
    {OGRSTLabelFontName, "f", FALSE, OGRSTypeString},
74
    {OGRSTLabelSize, "s", TRUE, OGRSTypeDouble},
75
    {OGRSTLabelTextString, "t", FALSE, OGRSTypeString},
76
    {OGRSTLabelAngle, "a", FALSE, OGRSTypeDouble},
77
    {OGRSTLabelFColor, "c", FALSE, OGRSTypeString},
78
    {OGRSTLabelBColor, "b", FALSE, OGRSTypeString},
79
    {OGRSTLabelPlacement, "m", FALSE, OGRSTypeString},
80
    {OGRSTLabelAnchor, "p", FALSE, OGRSTypeInteger},
81
    {OGRSTLabelDx, "dx", TRUE, OGRSTypeDouble},
82
    {OGRSTLabelDy, "dy", TRUE, OGRSTypeDouble},
83
    {OGRSTLabelPerp, "dp", TRUE, OGRSTypeDouble},
84
    {OGRSTLabelBold, "bo", FALSE, OGRSTypeBoolean},
85
    {OGRSTLabelItalic, "it", FALSE, OGRSTypeBoolean},
86
    {OGRSTLabelUnderline, "un", FALSE, OGRSTypeBoolean},
87
    {OGRSTLabelPriority, "l", FALSE, OGRSTypeInteger},
88
    {OGRSTLabelStrikeout, "st", FALSE, OGRSTypeBoolean},
89
    {OGRSTLabelStretch, "w", FALSE, OGRSTypeDouble},
90
    {-1, nullptr, FALSE, OGRSTypeUnused},  // was OGRSTLabelAdjHor
91
    {-1, nullptr, FALSE, OGRSTypeUnused},  // was OGRSTLabelAdjVert
92
    {OGRSTLabelHColor, "h", FALSE, OGRSTypeString},
93
    {OGRSTLabelOColor, "o", FALSE, OGRSTypeString}};
94
95
/* ======================================================================== */
96
/* OGRStyleMgr                                                              */
97
/* ======================================================================== */
98
99
/****************************************************************************/
100
/*             OGRStyleMgr::OGRStyleMgr(OGRStyleTable *poDataSetStyleTable) */
101
/*                                                                          */
102
/****************************************************************************/
103
/**
104
 * \brief Constructor.
105
 *
106
 * This method is the same as the C function OGR_SM_Create()
107
 *
108
 * @param poDataSetStyleTable (currently unused, reserved for future use),
109
 * pointer to OGRStyleTable. Pass NULL for now.
110
 */
111
OGRStyleMgr::OGRStyleMgr(OGRStyleTable *poDataSetStyleTable)
112
0
    : m_poDataSetStyleTable(poDataSetStyleTable)
113
0
{
114
0
}
115
116
/************************************************************************/
117
/*                            OGR_SM_Create()                           */
118
/************************************************************************/
119
/**
120
 * \brief OGRStyleMgr factory.
121
 *
122
 * This function is the same as the C++ method OGRStyleMgr::OGRStyleMgr().
123
 *
124
 * @param hStyleTable pointer to OGRStyleTable or NULL if not working with
125
 *  a style table.
126
 *
127
 * @return a handle to the new style manager object.
128
 */
129
130
OGRStyleMgrH OGR_SM_Create(OGRStyleTableH hStyleTable)
131
132
0
{
133
0
    return reinterpret_cast<OGRStyleMgrH>(
134
0
        new OGRStyleMgr(reinterpret_cast<OGRStyleTable *>(hStyleTable)));
135
0
}
136
137
/****************************************************************************/
138
/*             OGRStyleMgr::~OGRStyleMgr()                                  */
139
/*                                                                          */
140
/****************************************************************************/
141
/**
142
 * \brief Destructor.
143
 *
144
 * This method is the same as the C function OGR_SM_Destroy()
145
 */
146
OGRStyleMgr::~OGRStyleMgr()
147
0
{
148
0
    CPLFree(m_pszStyleString);
149
0
}
150
151
/************************************************************************/
152
/*                           OGR_SM_Destroy()                            */
153
/************************************************************************/
154
/**
155
 * \brief Destroy Style Manager
156
 *
157
 * This function is the same as the C++ method OGRStyleMgr::~OGRStyleMgr().
158
 *
159
 * @param hSM handle to the style manager to destroy.
160
 */
161
162
void OGR_SM_Destroy(OGRStyleMgrH hSM)
163
164
0
{
165
0
    delete reinterpret_cast<OGRStyleMgr *>(hSM);
166
0
}
167
168
/****************************************************************************/
169
/*      GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature,     */
170
/*                                       char *pszStyleString,              */
171
/*                                       GBool bNoMatching)                 */
172
/*      Set the given representation to the feature,                        */
173
/*      if bNoMatching == TRUE, don't try to find it in the styletable      */
174
/*      otherwise, we will use the name defined in the styletable.          */
175
/****************************************************************************/
176
177
/**
178
 * \brief Set a style in a feature
179
 *
180
 * @param poFeature       the feature object to store the style in
181
 * @param pszStyleString  the style to store
182
 * @param bNoMatching     TRUE to lookup the style in the style table and
183
 *  add the name to the feature
184
 *
185
 * @return TRUE on success, FALSE on error.
186
 */
187
188
GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature,
189
                                         const char *pszStyleString,
190
                                         GBool bNoMatching)
191
0
{
192
0
    if (poFeature == nullptr)
193
0
        return FALSE;
194
195
0
    const char *pszName = nullptr;
196
197
0
    if (pszStyleString == nullptr)
198
0
        poFeature->SetStyleString("");
199
0
    else if (bNoMatching == TRUE)
200
0
        poFeature->SetStyleString(pszStyleString);
201
0
    else if ((pszName = GetStyleName(pszStyleString)) != nullptr)
202
0
        poFeature->SetStyleString(pszName);
203
0
    else
204
0
        poFeature->SetStyleString(pszStyleString);
205
206
0
    return TRUE;
207
0
}
208
209
/****************************************************************************/
210
/*            const char *OGRStyleMgr::InitFromFeature(OGRFeature *)        */
211
/*                                                                          */
212
/****************************************************************************/
213
214
/**
215
 * \brief Initialize style manager from the style string of a feature.
216
 *
217
 * This method is the same as the C function OGR_SM_InitFromFeature().
218
 *
219
 * @param poFeature feature object from which to read the style.
220
 *
221
 * @return a reference to the style string read from the feature, or NULL
222
 * in case of error..
223
 */
224
225
const char *OGRStyleMgr::InitFromFeature(OGRFeature *poFeature)
226
0
{
227
0
    CPLFree(m_pszStyleString);
228
0
    m_pszStyleString = nullptr;
229
230
0
    if (poFeature)
231
0
        InitStyleString(poFeature->GetStyleString());
232
0
    else
233
0
        m_pszStyleString = nullptr;
234
235
0
    return m_pszStyleString;
236
0
}
237
238
/************************************************************************/
239
/*                     OGR_SM_InitFromFeature()                         */
240
/************************************************************************/
241
242
/**
243
 * \brief Initialize style manager from the style string of a feature.
244
 *
245
 * This function is the same as the C++ method
246
 * OGRStyleMgr::InitFromFeature().
247
 *
248
 * @param hSM handle to the style manager.
249
 * @param hFeat handle to the new feature from which to read the style.
250
 *
251
 * @return a reference to the style string read from the feature, or NULL
252
 * in case of error.
253
 */
254
255
const char *OGR_SM_InitFromFeature(OGRStyleMgrH hSM, OGRFeatureH hFeat)
256
257
0
{
258
0
    VALIDATE_POINTER1(hSM, "OGR_SM_InitFromFeature", nullptr);
259
0
    VALIDATE_POINTER1(hFeat, "OGR_SM_InitFromFeature", nullptr);
260
261
0
    return reinterpret_cast<OGRStyleMgr *>(hSM)->InitFromFeature(
262
0
        reinterpret_cast<OGRFeature *>(hFeat));
263
0
}
264
265
/****************************************************************************/
266
/*            GBool OGRStyleMgr::InitStyleString(char *pszStyleString)      */
267
/*                                                                          */
268
/****************************************************************************/
269
270
/**
271
 * \brief Initialize style manager from the style string.
272
 *
273
 * Style string can be an expanded style string (e.g. "PEN(c:#FF0000,w:5px)"),
274
 * or (starting with GDAL 3.5.1), a reference to a style name starting with @
275
 * (e.g. "@my_style") registered in the associated style table.
276
 *
277
 * This method is the same as the C function OGR_SM_InitStyleString().
278
 *
279
 * @param pszStyleString the style string to use (can be NULL).
280
 *
281
 * @return TRUE on success, FALSE on errors.
282
 */
283
GBool OGRStyleMgr::InitStyleString(const char *pszStyleString)
284
0
{
285
0
    CPLFree(m_pszStyleString);
286
0
    m_pszStyleString = nullptr;
287
288
0
    if (pszStyleString && pszStyleString[0] == '@')
289
0
    {
290
0
        const char *pszStyleStringFromName = GetStyleByName(pszStyleString + 1);
291
0
        if (pszStyleStringFromName == nullptr)
292
0
            return FALSE;
293
0
        m_pszStyleString = CPLStrdup(pszStyleStringFromName);
294
0
    }
295
0
    else if (pszStyleString)
296
0
        m_pszStyleString = CPLStrdup(pszStyleString);
297
298
0
    return TRUE;
299
0
}
300
301
/************************************************************************/
302
/*                     OGR_SM_InitStyleString()                         */
303
/************************************************************************/
304
305
/**
306
 * \brief Initialize style manager from the style string.
307
 *
308
 * Style string can be an expanded style string (e.g. "PEN(c:#FF0000,w:5px)"),
309
 * or (starting with GDAL 3.5.1), a reference to a style name starting with @
310
 * (e.g. "@my_style") registered in the associated style table.
311
 *
312
 * This function is the same as the C++ method OGRStyleMgr::InitStyleString().
313
 *
314
 * @param hSM handle to the style manager.
315
 * @param pszStyleString the style string to use (can be NULL).
316
 *
317
 * @return TRUE on success, FALSE on errors.
318
 */
319
320
int OGR_SM_InitStyleString(OGRStyleMgrH hSM, const char *pszStyleString)
321
322
0
{
323
0
    VALIDATE_POINTER1(hSM, "OGR_SM_InitStyleString", FALSE);
324
325
0
    return reinterpret_cast<OGRStyleMgr *>(hSM)->InitStyleString(
326
0
        pszStyleString);
327
0
}
328
329
/****************************************************************************/
330
/*      const char *OGRStyleMgr::GetStyleName(const char *pszStyleString)   */
331
/****************************************************************************/
332
333
/**
334
 * \brief Get the name of a style from the style table.
335
 *
336
 * @param pszStyleString the style to search for, or NULL to use the style
337
 *   currently stored in the manager.
338
 *
339
 * @return The name if found, or NULL on error.
340
 */
341
342
const char *OGRStyleMgr::GetStyleName(const char *pszStyleString)
343
0
{
344
    // SECURITY: The unit and the value for all parameter should be the same,
345
    // a text comparison is executed.
346
347
0
    const char *pszStyle = pszStyleString ? pszStyleString : m_pszStyleString;
348
349
0
    if (pszStyle)
350
0
    {
351
0
        if (m_poDataSetStyleTable)
352
0
            return m_poDataSetStyleTable->GetStyleName(pszStyle);
353
0
    }
354
0
    return nullptr;
355
0
}
356
357
/****************************************************************************/
358
/*      const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName)   */
359
/*                                                                          */
360
/****************************************************************************/
361
362
/**
363
 * \brief find a style in the current style table.
364
 *
365
 *
366
 * @param pszStyleName the name of the style to add.
367
 *
368
 * @return the style string matching the name or NULL if not found or error.
369
 */
370
const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName)
371
0
{
372
0
    if (m_poDataSetStyleTable)
373
0
    {
374
0
        return m_poDataSetStyleTable->Find(pszStyleName);
375
0
    }
376
0
    return nullptr;
377
0
}
378
379
/****************************************************************************/
380
/*            GBool OGRStyleMgr::AddStyle(char *pszStyleName,               */
381
/*                                   char *pszStyleString)                  */
382
/*                                                                          */
383
/****************************************************************************/
384
385
/**
386
 * \brief Add a style to the current style table.
387
 *
388
 * This method is the same as the C function OGR_SM_AddStyle().
389
 *
390
 * @param pszStyleName the name of the style to add.
391
 * @param pszStyleString the style string to use, or NULL to use the style
392
 *                       stored in the manager.
393
 *
394
 * @return TRUE on success, FALSE on errors.
395
 */
396
397
GBool OGRStyleMgr::AddStyle(const char *pszStyleName,
398
                            const char *pszStyleString)
399
0
{
400
0
    const char *pszStyle = pszStyleString ? pszStyleString : m_pszStyleString;
401
402
0
    if (m_poDataSetStyleTable)
403
0
    {
404
0
        return m_poDataSetStyleTable->AddStyle(pszStyleName, pszStyle);
405
0
    }
406
0
    return FALSE;
407
0
}
408
409
/************************************************************************/
410
/*                     OGR_SM_AddStyle()                         */
411
/************************************************************************/
412
413
/**
414
 * \brief Add a style to the current style table.
415
 *
416
 * This function is the same as the C++ method OGRStyleMgr::AddStyle().
417
 *
418
 * @param hSM handle to the style manager.
419
 * @param pszStyleName the name of the style to add.
420
 * @param pszStyleString the style string to use, or NULL to use the style
421
 *                       stored in the manager.
422
 *
423
 * @return TRUE on success, FALSE on errors.
424
 */
425
426
int OGR_SM_AddStyle(OGRStyleMgrH hSM, const char *pszStyleName,
427
                    const char *pszStyleString)
428
0
{
429
0
    VALIDATE_POINTER1(hSM, "OGR_SM_AddStyle", FALSE);
430
0
    VALIDATE_POINTER1(pszStyleName, "OGR_SM_AddStyle", FALSE);
431
432
0
    return reinterpret_cast<OGRStyleMgr *>(hSM)->AddStyle(pszStyleName,
433
0
                                                          pszStyleString);
434
0
}
435
436
/****************************************************************************/
437
/*            const char *OGRStyleMgr::GetStyleString(OGRFeature *)         */
438
/*                                                                          */
439
/****************************************************************************/
440
441
/**
442
 * \brief Get the style string from the style manager.
443
 *
444
 * @param poFeature feature object from which to read the style or NULL to
445
 *                  get the style string stored in the manager.
446
 *
447
 * @return the style string stored in the feature or the style string stored
448
 *          in the style manager if poFeature is NULL
449
 *
450
 * NOTE: this method will call OGRStyleMgr::InitFromFeature() if poFeature is
451
 *       not NULL and replace the style string stored in the style manager
452
 */
453
454
const char *OGRStyleMgr::GetStyleString(OGRFeature *poFeature)
455
0
{
456
0
    if (poFeature == nullptr)
457
0
        return m_pszStyleString;
458
459
0
    return InitFromFeature(poFeature);
460
0
}
461
462
/****************************************************************************/
463
/*            GBool OGRStyleMgr::AddPart(const char *pszPart)               */
464
/*            Add a new part in the current style                           */
465
/****************************************************************************/
466
467
/**
468
 * \brief Add a part (style string) to the current style.
469
 *
470
 * @param pszPart the style string defining the part to add.
471
 *
472
 * @return TRUE on success, FALSE on errors.
473
 */
474
475
GBool OGRStyleMgr::AddPart(const char *pszPart)
476
0
{
477
0
    if (pszPart == nullptr)
478
0
        return FALSE;
479
480
0
    if (m_pszStyleString)
481
0
    {
482
0
        char *pszTmp =
483
0
            CPLStrdup(CPLString().Printf("%s;%s", m_pszStyleString, pszPart));
484
0
        CPLFree(m_pszStyleString);
485
0
        m_pszStyleString = pszTmp;
486
0
    }
487
0
    else
488
0
    {
489
0
        char *pszTmp = CPLStrdup(CPLString().Printf("%s", pszPart));
490
0
        CPLFree(m_pszStyleString);
491
0
        m_pszStyleString = pszTmp;
492
0
    }
493
0
    return TRUE;
494
0
}
495
496
/****************************************************************************/
497
/*            GBool OGRStyleMgr::AddPart(OGRStyleTool *)                    */
498
/*            Add a new part in the current style                           */
499
/****************************************************************************/
500
501
/**
502
 * \brief Add a part (style tool) to the current style.
503
 *
504
 * This method is the same as the C function OGR_SM_AddPart().
505
 *
506
 * @param poStyleTool the style tool defining the part to add.
507
 *
508
 * @return TRUE on success, FALSE on errors.
509
 */
510
511
GBool OGRStyleMgr::AddPart(OGRStyleTool *poStyleTool)
512
0
{
513
0
    if (poStyleTool == nullptr || !poStyleTool->GetStyleString())
514
0
        return FALSE;
515
516
0
    if (m_pszStyleString)
517
0
    {
518
0
        char *pszTmp = CPLStrdup(CPLString().Printf(
519
0
            "%s;%s", m_pszStyleString, poStyleTool->GetStyleString()));
520
0
        CPLFree(m_pszStyleString);
521
0
        m_pszStyleString = pszTmp;
522
0
    }
523
0
    else
524
0
    {
525
0
        char *pszTmp =
526
0
            CPLStrdup(CPLString().Printf("%s", poStyleTool->GetStyleString()));
527
0
        CPLFree(m_pszStyleString);
528
0
        m_pszStyleString = pszTmp;
529
0
    }
530
0
    return TRUE;
531
0
}
532
533
/************************************************************************/
534
/*                     OGR_SM_AddPart()                                 */
535
/************************************************************************/
536
537
/**
538
 * \brief Add a part (style tool) to the current style.
539
 *
540
 * This function is the same as the C++ method OGRStyleMgr::AddPart().
541
 *
542
 * @param hSM handle to the style manager.
543
 * @param hST the style tool defining the part to add.
544
 *
545
 * @return TRUE on success, FALSE on errors.
546
 */
547
548
int OGR_SM_AddPart(OGRStyleMgrH hSM, OGRStyleToolH hST)
549
550
0
{
551
0
    VALIDATE_POINTER1(hSM, "OGR_SM_InitStyleString", FALSE);
552
0
    VALIDATE_POINTER1(hST, "OGR_SM_InitStyleString", FALSE);
553
554
0
    return reinterpret_cast<OGRStyleMgr *>(hSM)->AddPart(
555
0
        reinterpret_cast<OGRStyleTool *>(hST));
556
0
}
557
558
/****************************************************************************/
559
/*            int OGRStyleMgr::GetPartCount(const char *pszStyleString)     */
560
/*            return the number of part in the stylestring                  */
561
/* FIXME: this function should actually parse style string instead of simple*/
562
/*        semicolon counting, we should not count broken and empty parts.   */
563
/****************************************************************************/
564
565
/**
566
 * \brief Get the number of parts in a style.
567
 *
568
 * This method is the same as the C function OGR_SM_GetPartCount().
569
 *
570
 * @param pszStyleString (optional) the style string on which to operate.
571
 * If NULL then the current style string stored in the style manager is used.
572
 *
573
 * @return the number of parts (style tools) in the style.
574
 */
575
576
int OGRStyleMgr::GetPartCount(const char *pszStyleString)
577
0
{
578
0
    const char *pszString =
579
0
        pszStyleString != nullptr ? pszStyleString : m_pszStyleString;
580
581
0
    if (pszString == nullptr)
582
0
        return 0;
583
584
0
    int nPartCount = 1;
585
0
    const char *pszStrTmp = pszString;
586
    // Search for parts separated by semicolons not counting the possible
587
    // semicolon at the and of string.
588
0
    const char *pszPart = nullptr;
589
0
    while ((pszPart = strstr(pszStrTmp, ";")) != nullptr && pszPart[1] != '\0')
590
0
    {
591
0
        pszStrTmp = &pszPart[1];
592
0
        nPartCount++;
593
0
    }
594
0
    return nPartCount;
595
0
}
596
597
/************************************************************************/
598
/*                     OGR_SM_GetPartCount()                            */
599
/************************************************************************/
600
601
/**
602
 * \brief Get the number of parts in a style.
603
 *
604
 * This function is the same as the C++ method OGRStyleMgr::GetPartCount().
605
 *
606
 * @param hSM handle to the style manager.
607
 * @param pszStyleString (optional) the style string on which to operate.
608
 * If NULL then the current style string stored in the style manager is used.
609
 *
610
 * @return the number of parts (style tools) in the style.
611
 */
612
613
int OGR_SM_GetPartCount(OGRStyleMgrH hSM, const char *pszStyleString)
614
615
0
{
616
0
    VALIDATE_POINTER1(hSM, "OGR_SM_InitStyleString", FALSE);
617
618
0
    return reinterpret_cast<OGRStyleMgr *>(hSM)->GetPartCount(pszStyleString);
619
0
}
620
621
/****************************************************************************/
622
/*            OGRStyleTool *OGRStyleMgr::GetPart(int nPartId,               */
623
/*                                 const char *pszStyleString)              */
624
/*                                                                          */
625
/*     Return a StyleTool of the type of the wanted part, could return NULL */
626
/****************************************************************************/
627
628
/**
629
 * \brief Fetch a part (style tool) from the current style.
630
 *
631
 * This method is the same as the C function OGR_SM_GetPart().
632
 *
633
 * This method instantiates a new object that should be freed with
634
 * OGR_ST_Destroy().
635
 *
636
 * @param nPartId the part number (0-based index).
637
 * @param pszStyleString (optional) the style string on which to operate.
638
 * If NULL then the current style string stored in the style manager is used.
639
 *
640
 * @return OGRStyleTool of the requested part (style tools) or NULL on error.
641
 */
642
643
OGRStyleTool *OGRStyleMgr::GetPart(int nPartId, const char *pszStyleString)
644
0
{
645
0
    const char *pszStyle = pszStyleString ? pszStyleString : m_pszStyleString;
646
647
0
    if (pszStyle == nullptr)
648
0
        return nullptr;
649
650
0
    char **papszStyleString = CSLTokenizeString2(
651
0
        pszStyle, ";",
652
0
        CSLT_HONOURSTRINGS | CSLT_PRESERVEQUOTES | CSLT_PRESERVEESCAPES);
653
654
0
    const char *pszString = CSLGetField(papszStyleString, nPartId);
655
656
0
    OGRStyleTool *poStyleTool = nullptr;
657
0
    if (strlen(pszString) > 0)
658
0
    {
659
0
        poStyleTool = CreateStyleToolFromStyleString(pszString);
660
0
        if (poStyleTool)
661
0
            poStyleTool->SetStyleString(pszString);
662
0
    }
663
664
0
    CSLDestroy(papszStyleString);
665
666
0
    return poStyleTool;
667
0
}
668
669
/************************************************************************/
670
/*                     OGR_SM_GetPart()                                 */
671
/************************************************************************/
672
673
/**
674
 * \brief Fetch a part (style tool) from the current style.
675
 *
676
 * This function is the same as the C++ method OGRStyleMgr::GetPart().
677
 *
678
 * This function instantiates a new object that should be freed with
679
 * OGR_ST_Destroy().
680
 *
681
 * @param hSM handle to the style manager.
682
 * @param nPartId the part number (0-based index).
683
 * @param pszStyleString (optional) the style string on which to operate.
684
 * If NULL then the current style string stored in the style manager is used.
685
 *
686
 * @return OGRStyleToolH of the requested part (style tools) or NULL on error.
687
 */
688
689
OGRStyleToolH OGR_SM_GetPart(OGRStyleMgrH hSM, int nPartId,
690
                             const char *pszStyleString)
691
692
0
{
693
0
    VALIDATE_POINTER1(hSM, "OGR_SM_InitStyleString", nullptr);
694
695
0
    return reinterpret_cast<OGRStyleToolH>(
696
0
        reinterpret_cast<OGRStyleMgr *>(hSM)->GetPart(nPartId, pszStyleString));
697
0
}
698
699
/****************************************************************************/
700
/* OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString) */
701
/*                                                                          */
702
/* create a Style tool from the given StyleString, it should contain only a */
703
/* part of a StyleString.                                                    */
704
/****************************************************************************/
705
706
//! @cond Doxygen_Suppress
707
OGRStyleTool *
708
OGRStyleMgr::CreateStyleToolFromStyleString(const char *pszStyleString)
709
0
{
710
0
    char **papszToken = CSLTokenizeString2(
711
0
        pszStyleString, "();",
712
0
        CSLT_HONOURSTRINGS | CSLT_PRESERVEQUOTES | CSLT_PRESERVEESCAPES);
713
0
    OGRStyleTool *poStyleTool = nullptr;
714
715
0
    if (CSLCount(papszToken) < 2)
716
0
        poStyleTool = nullptr;
717
0
    else if (EQUAL(papszToken[0], "PEN"))
718
0
        poStyleTool = new OGRStylePen();
719
0
    else if (EQUAL(papszToken[0], "BRUSH"))
720
0
        poStyleTool = new OGRStyleBrush();
721
0
    else if (EQUAL(papszToken[0], "SYMBOL"))
722
0
        poStyleTool = new OGRStyleSymbol();
723
0
    else if (EQUAL(papszToken[0], "LABEL"))
724
0
        poStyleTool = new OGRStyleLabel();
725
0
    else
726
0
        poStyleTool = nullptr;
727
728
0
    CSLDestroy(papszToken);
729
730
0
    return poStyleTool;
731
0
}
732
733
//! @endcond
734
735
/* ======================================================================== */
736
/*                OGRStyleTable                                             */
737
/*     Object Used to manage and store a styletable                         */
738
/* ======================================================================== */
739
740
/****************************************************************************/
741
/*              OGRStyleTable::OGRStyleTable()                              */
742
/*                                                                          */
743
/****************************************************************************/
744
OGRStyleTable::OGRStyleTable()
745
0
{
746
0
    m_papszStyleTable = nullptr;
747
0
    iNextStyle = 0;
748
0
}
749
750
/************************************************************************/
751
/*                            OGR_STBL_Create()                           */
752
/************************************************************************/
753
/**
754
 * \brief OGRStyleTable factory.
755
 *
756
 * This function is the same as the C++ method OGRStyleTable::OGRStyleTable().
757
 *
758
 *
759
 * @return a handle to the new style table object.
760
 */
761
762
OGRStyleTableH OGR_STBL_Create(void)
763
764
0
{
765
0
    return reinterpret_cast<OGRStyleTableH>(new OGRStyleTable());
766
0
}
767
768
/****************************************************************************/
769
/*                void OGRStyleTable::Clear()                               */
770
/*                                                                          */
771
/****************************************************************************/
772
773
/**
774
 * \brief Clear a style table.
775
 *
776
 */
777
778
void OGRStyleTable::Clear()
779
0
{
780
0
    if (m_papszStyleTable)
781
0
        CSLDestroy(m_papszStyleTable);
782
0
    m_papszStyleTable = nullptr;
783
0
}
784
785
/****************************************************************************/
786
/*          OGRStyleTable::~OGRStyleTable()                                 */
787
/*                                                                          */
788
/****************************************************************************/
789
OGRStyleTable::~OGRStyleTable()
790
0
{
791
0
    Clear();
792
0
}
793
794
/************************************************************************/
795
/*                           OGR_STBL_Destroy()                            */
796
/************************************************************************/
797
/**
798
 * \brief Destroy Style Table
799
 *
800
 * @param hSTBL handle to the style table to destroy.
801
 */
802
803
void OGR_STBL_Destroy(OGRStyleTableH hSTBL)
804
805
0
{
806
0
    delete reinterpret_cast<OGRStyleTable *>(hSTBL);
807
0
}
808
809
/****************************************************************************/
810
/*    const char *OGRStyleTable::GetStyleName(const char *pszStyleString)   */
811
/*                                                                          */
812
/*    return the Name of a given stylestring otherwise NULL.                */
813
/****************************************************************************/
814
815
/**
816
 * \brief Get style name by style string.
817
 *
818
 * @param pszStyleString the style string to look up.
819
 *
820
 * @return the Name of the matching style string or NULL on error.
821
 */
822
823
const char *OGRStyleTable::GetStyleName(const char *pszStyleString)
824
0
{
825
0
    for (int i = 0; i < CSLCount(m_papszStyleTable); i++)
826
0
    {
827
0
        const char *pszStyleStringBegin = strstr(m_papszStyleTable[i], ":");
828
829
0
        if (pszStyleStringBegin &&
830
0
            EQUAL(&pszStyleStringBegin[1], pszStyleString))
831
0
        {
832
0
            osLastRequestedStyleName = m_papszStyleTable[i];
833
0
            const size_t nColon = osLastRequestedStyleName.find(':');
834
0
            if (nColon != std::string::npos)
835
0
                osLastRequestedStyleName =
836
0
                    osLastRequestedStyleName.substr(0, nColon);
837
838
0
            return osLastRequestedStyleName;
839
0
        }
840
0
    }
841
842
0
    return nullptr;
843
0
}
844
845
/****************************************************************************/
846
/*            GBool OGRStyleTable::AddStyle(char *pszName,                  */
847
/*                                          char *pszStyleString)           */
848
/*                                                                          */
849
/*   Add a new style in the table, no comparison will be done on the        */
850
/*   Style string, only on the name, TRUE success, FALSE error              */
851
/****************************************************************************/
852
853
/**
854
 * \brief Add a new style in the table.
855
 * No comparison will be done on the
856
 * Style string, only on the name.
857
 *
858
 * @param pszName the name the style to add.
859
 * @param pszStyleString the style string to add.
860
 *
861
 * @return TRUE on success, FALSE on error
862
 */
863
864
GBool OGRStyleTable::AddStyle(const char *pszName, const char *pszStyleString)
865
0
{
866
0
    if (pszName == nullptr || pszStyleString == nullptr)
867
0
        return FALSE;
868
869
0
    const int nPos = IsExist(pszName);
870
0
    if (nPos != -1)
871
0
        return FALSE;
872
873
0
    m_papszStyleTable =
874
0
        CSLAddString(m_papszStyleTable,
875
0
                     CPLString().Printf("%s:%s", pszName, pszStyleString));
876
0
    return TRUE;
877
0
}
878
879
/************************************************************************/
880
/*                       OGR_STBL_AddStyle()                            */
881
/************************************************************************/
882
883
/**
884
 * \brief Add a new style in the table.
885
 * No comparison will be done on the
886
 * Style string, only on the name.
887
 * This function is the same as the C++ method OGRStyleTable::AddStyle().
888
 *
889
 * @param hStyleTable handle to the style table.
890
 * @param pszName the name the style to add.
891
 * @param pszStyleString the style string to add.
892
 *
893
 * @return TRUE on success, FALSE on error
894
 */
895
896
int OGR_STBL_AddStyle(OGRStyleTableH hStyleTable, const char *pszName,
897
                      const char *pszStyleString)
898
0
{
899
0
    VALIDATE_POINTER1(hStyleTable, "OGR_STBL_AddStyle", FALSE);
900
901
0
    return reinterpret_cast<OGRStyleTable *>(hStyleTable)
902
0
        ->AddStyle(pszName, pszStyleString);
903
0
}
904
905
/****************************************************************************/
906
/*            GBool OGRStyleTable::RemoveStyle(char *pszName)               */
907
/*                                                                          */
908
/*    Remove the given style in the table based on the name, return TRUE    */
909
/*    on success otherwise FALSE.                                           */
910
/****************************************************************************/
911
912
/**
913
 * \brief Remove a style in the table by its name.
914
 *
915
 * @param pszName the name of the style to remove.
916
 *
917
 * @return TRUE on success, FALSE on error
918
 */
919
920
GBool OGRStyleTable::RemoveStyle(const char *pszName)
921
0
{
922
0
    const int nPos = IsExist(pszName);
923
0
    if (nPos == -1)
924
0
        return FALSE;
925
926
0
    m_papszStyleTable = CSLRemoveStrings(m_papszStyleTable, nPos, 1, nullptr);
927
0
    return TRUE;
928
0
}
929
930
/****************************************************************************/
931
/*            GBool OGRStyleTable::ModifyStyle(char *pszName,               */
932
/*                                             char *pszStyleString)        */
933
/*                                                                          */
934
/*    Modify the given style, if the style doesn't exist, it will be added  */
935
/*    return TRUE on success otherwise return FALSE.                        */
936
/****************************************************************************/
937
938
/**
939
 * \brief Modify a style in the table by its name
940
 * If the style does not exist, it will be added.
941
 *
942
 * @param pszName the name of the style to modify.
943
 * @param pszStyleString the style string.
944
 *
945
 * @return TRUE on success, FALSE on error
946
 */
947
948
GBool OGRStyleTable::ModifyStyle(const char *pszName,
949
                                 const char *pszStyleString)
950
0
{
951
0
    if (pszName == nullptr || pszStyleString == nullptr)
952
0
        return FALSE;
953
954
0
    RemoveStyle(pszName);
955
0
    return AddStyle(pszName, pszStyleString);
956
0
}
957
958
/****************************************************************************/
959
/*            GBool OGRStyleTable::SaveStyleTable(char *)                   */
960
/*                                                                          */
961
/*    Save the StyleTable in the given file, return TRUE on success         */
962
/*    otherwise return FALSE.                                               */
963
/****************************************************************************/
964
965
/**
966
 * \brief Save a style table to a file.
967
 *
968
 * @param pszFilename the name of the file to save to.
969
 *
970
 * @return TRUE on success, FALSE on error
971
 */
972
973
GBool OGRStyleTable::SaveStyleTable(const char *pszFilename)
974
0
{
975
0
    if (pszFilename == nullptr)
976
0
        return FALSE;
977
978
0
    if (CSLSave(m_papszStyleTable, pszFilename) == 0)
979
0
        return FALSE;
980
981
0
    return TRUE;
982
0
}
983
984
/************************************************************************/
985
/*                     OGR_STBL_SaveStyleTable()                        */
986
/************************************************************************/
987
988
/**
989
 * \brief Save a style table to a file.
990
 *
991
 * This function is the same as the C++ method OGRStyleTable::SaveStyleTable().
992
 *
993
 * @param hStyleTable handle to the style table.
994
 * @param pszFilename the name of the file to save to.
995
 *
996
 * @return TRUE on success, FALSE on error
997
 */
998
999
int OGR_STBL_SaveStyleTable(OGRStyleTableH hStyleTable, const char *pszFilename)
1000
0
{
1001
0
    VALIDATE_POINTER1(hStyleTable, "OGR_STBL_SaveStyleTable", FALSE);
1002
0
    VALIDATE_POINTER1(pszFilename, "OGR_STBL_SaveStyleTable", FALSE);
1003
1004
0
    return reinterpret_cast<OGRStyleTable *>(hStyleTable)
1005
0
        ->SaveStyleTable(pszFilename);
1006
0
}
1007
1008
/****************************************************************************/
1009
/*            GBool OGRStyleTable::LoadStyleTable(char *)                   */
1010
/*                                                                          */
1011
/*            Read the Style table from a file, return TRUE on success      */
1012
/*            otherwise return FALSE                                        */
1013
/****************************************************************************/
1014
1015
/**
1016
 * \brief Load a style table from a file.
1017
 *
1018
 * @param pszFilename the name of the file to load from.
1019
 *
1020
 * @return TRUE on success, FALSE on error
1021
 */
1022
1023
GBool OGRStyleTable::LoadStyleTable(const char *pszFilename)
1024
0
{
1025
0
    if (pszFilename == nullptr)
1026
0
        return FALSE;
1027
1028
0
    CSLDestroy(m_papszStyleTable);
1029
1030
0
    m_papszStyleTable = CSLLoad(pszFilename);
1031
1032
0
    return m_papszStyleTable != nullptr;
1033
0
}
1034
1035
/************************************************************************/
1036
/*                     OGR_STBL_LoadStyleTable()                        */
1037
/************************************************************************/
1038
1039
/**
1040
 * \brief Load a style table from a file.
1041
 *
1042
 * This function is the same as the C++ method OGRStyleTable::LoadStyleTable().
1043
 *
1044
 * @param hStyleTable handle to the style table.
1045
 * @param pszFilename the name of the file to load from.
1046
 *
1047
 * @return TRUE on success, FALSE on error
1048
 */
1049
1050
int OGR_STBL_LoadStyleTable(OGRStyleTableH hStyleTable, const char *pszFilename)
1051
0
{
1052
0
    VALIDATE_POINTER1(hStyleTable, "OGR_STBL_LoadStyleTable", FALSE);
1053
0
    VALIDATE_POINTER1(pszFilename, "OGR_STBL_LoadStyleTable", FALSE);
1054
1055
0
    return reinterpret_cast<OGRStyleTable *>(hStyleTable)
1056
0
        ->LoadStyleTable(pszFilename);
1057
0
}
1058
1059
/****************************************************************************/
1060
/*             const char *OGRStyleTable::Find(const char *pszName)         */
1061
/*                                                                          */
1062
/*             return the StyleString based on the given name,              */
1063
/*             otherwise return NULL.                                       */
1064
/****************************************************************************/
1065
1066
/**
1067
 * \brief Get a style string by name.
1068
 *
1069
 * @param pszName the name of the style string to find.
1070
 *
1071
 * @return the style string matching the name, NULL if not found or error.
1072
 */
1073
1074
const char *OGRStyleTable::Find(const char *pszName)
1075
0
{
1076
0
    const int nPos = IsExist(pszName);
1077
0
    if (nPos == -1)
1078
0
        return nullptr;
1079
1080
0
    const char *pszOutput = CSLGetField(m_papszStyleTable, nPos);
1081
1082
0
    const char *pszDash = strstr(pszOutput, ":");
1083
1084
0
    if (pszDash == nullptr)
1085
0
        return nullptr;
1086
1087
0
    return &pszDash[1];
1088
0
}
1089
1090
/************************************************************************/
1091
/*                     OGR_STBL_Find()                                  */
1092
/************************************************************************/
1093
1094
/**
1095
 * \brief Get a style string by name.
1096
 *
1097
 * This function is the same as the C++ method OGRStyleTable::Find().
1098
 *
1099
 * @param hStyleTable handle to the style table.
1100
 * @param pszName the name of the style string to find.
1101
 *
1102
 * @return the style string matching the name or NULL if not found or error.
1103
 */
1104
1105
const char *OGR_STBL_Find(OGRStyleTableH hStyleTable, const char *pszName)
1106
0
{
1107
0
    VALIDATE_POINTER1(hStyleTable, "OGR_STBL_Find", nullptr);
1108
0
    VALIDATE_POINTER1(pszName, "OGR_STBL_Find", nullptr);
1109
1110
0
    return reinterpret_cast<OGRStyleTable *>(hStyleTable)->Find(pszName);
1111
0
}
1112
1113
/****************************************************************************/
1114
/*              OGRStyleTable::Print(FILE *fpOut)                           */
1115
/*                                                                          */
1116
/****************************************************************************/
1117
1118
/**
1119
 * \brief Print a style table to a FILE pointer.
1120
 *
1121
 * @param fpOut the FILE pointer to print to.
1122
 *
1123
 */
1124
1125
void OGRStyleTable::Print(FILE *fpOut)
1126
0
{
1127
1128
0
    CPL_IGNORE_RET_VAL(VSIFPrintf(fpOut, "#OFS-Version: 1.0\n"));
1129
0
    CPL_IGNORE_RET_VAL(VSIFPrintf(fpOut, "#StyleField: style\n"));
1130
0
    if (m_papszStyleTable)
1131
0
    {
1132
0
        CSLPrint(m_papszStyleTable, fpOut);
1133
0
    }
1134
0
}
1135
1136
/****************************************************************************/
1137
/*             int OGRStyleTable::IsExist(const char *pszName)              */
1138
/*                                                                          */
1139
/*   return a index of the style in the table otherwise return -1           */
1140
/****************************************************************************/
1141
1142
/**
1143
 * \brief Get the index of a style in the table by its name.
1144
 *
1145
 * @param pszName the name to look for.
1146
 *
1147
 * @return The index of the style if found, -1 if not found or error.
1148
 */
1149
1150
int OGRStyleTable::IsExist(const char *pszName)
1151
0
{
1152
0
    if (pszName == nullptr)
1153
0
        return -1;
1154
1155
0
    const int nCount = CSLCount(m_papszStyleTable);
1156
0
    const char *pszNewString = CPLSPrintf("%s:", pszName);
1157
1158
0
    for (int i = 0; i < nCount; i++)
1159
0
    {
1160
0
        if (strstr(m_papszStyleTable[i], pszNewString) != nullptr)
1161
0
        {
1162
0
            return i;
1163
0
        }
1164
0
    }
1165
1166
0
    return -1;
1167
0
}
1168
1169
/************************************************************************/
1170
/*                               Clone()                                */
1171
/************************************************************************/
1172
1173
/**
1174
 * \brief Duplicate style table.
1175
 *
1176
 * The newly created style table is owned by the caller, and will have its
1177
 * own reference to the OGRStyleTable.
1178
 *
1179
 * @return new style table, exactly matching this style table.
1180
 */
1181
1182
OGRStyleTable *OGRStyleTable::Clone()
1183
1184
0
{
1185
0
    OGRStyleTable *poNew = new OGRStyleTable();
1186
1187
0
    poNew->m_papszStyleTable = CSLDuplicate(m_papszStyleTable);
1188
1189
0
    return poNew;
1190
0
}
1191
1192
/************************************************************************/
1193
/*                            ResetStyleStringReading()                 */
1194
/************************************************************************/
1195
1196
/** Reset the next style pointer to 0 */
1197
void OGRStyleTable::ResetStyleStringReading()
1198
1199
0
{
1200
0
    iNextStyle = 0;
1201
0
}
1202
1203
/************************************************************************/
1204
/*                     OGR_STBL_ResetStyleStringReading()               */
1205
/************************************************************************/
1206
1207
/**
1208
 * \brief Reset the next style pointer to 0
1209
 *
1210
 * This function is the same as the C++ method
1211
 * OGRStyleTable::ResetStyleStringReading().
1212
 *
1213
 * @param hStyleTable handle to the style table.
1214
 *
1215
 */
1216
1217
void OGR_STBL_ResetStyleStringReading(OGRStyleTableH hStyleTable)
1218
0
{
1219
0
    VALIDATE_POINTER0(hStyleTable, "OGR_STBL_ResetStyleStringReading");
1220
1221
0
    reinterpret_cast<OGRStyleTable *>(hStyleTable)->ResetStyleStringReading();
1222
0
}
1223
1224
/************************************************************************/
1225
/*                           GetNextStyle()                             */
1226
/************************************************************************/
1227
1228
/**
1229
 * \brief Get the next style string from the table.
1230
 *
1231
 * @return the next style string or NULL on error.
1232
 */
1233
1234
const char *OGRStyleTable::GetNextStyle()
1235
0
{
1236
0
    while (iNextStyle < CSLCount(m_papszStyleTable))
1237
0
    {
1238
0
        const char *pszOutput = CSLGetField(m_papszStyleTable, iNextStyle++);
1239
0
        if (pszOutput == nullptr)
1240
0
            continue;
1241
1242
0
        const char *pszDash = strstr(pszOutput, ":");
1243
1244
0
        osLastRequestedStyleName = pszOutput;
1245
0
        const size_t nColon = osLastRequestedStyleName.find(':');
1246
0
        if (nColon != std::string::npos)
1247
0
            osLastRequestedStyleName =
1248
0
                osLastRequestedStyleName.substr(0, nColon);
1249
1250
0
        if (pszDash)
1251
0
            return pszDash + 1;
1252
0
    }
1253
0
    return nullptr;
1254
0
}
1255
1256
/************************************************************************/
1257
/*                     OGR_STBL_GetNextStyle()                          */
1258
/************************************************************************/
1259
1260
/**
1261
 * \brief Get the next style string from the table.
1262
 *
1263
 * This function is the same as the C++ method OGRStyleTable::GetNextStyle().
1264
 *
1265
 * @param hStyleTable handle to the style table.
1266
 *
1267
 * @return the next style string or NULL on error.
1268
 */
1269
1270
const char *OGR_STBL_GetNextStyle(OGRStyleTableH hStyleTable)
1271
0
{
1272
0
    VALIDATE_POINTER1(hStyleTable, "OGR_STBL_GetNextStyle", nullptr);
1273
1274
0
    return reinterpret_cast<OGRStyleTable *>(hStyleTable)->GetNextStyle();
1275
0
}
1276
1277
/************************************************************************/
1278
/*                           GetLastStyleName()                         */
1279
/************************************************************************/
1280
1281
/**
1282
 * Get the style name of the last style string fetched with
1283
 * OGR_STBL_GetNextStyle.
1284
 *
1285
 * @return the Name of the last style string or NULL on error.
1286
 */
1287
1288
const char *OGRStyleTable::GetLastStyleName()
1289
0
{
1290
0
    return osLastRequestedStyleName;
1291
0
}
1292
1293
/************************************************************************/
1294
/*                     OGR_STBL_GetLastStyleName()                      */
1295
/************************************************************************/
1296
1297
/**
1298
 * Get the style name of the last style string fetched with
1299
 * OGR_STBL_GetNextStyle.
1300
 *
1301
 * This function is the same as the C++ method OGRStyleTable::GetStyleName().
1302
 *
1303
 * @param hStyleTable handle to the style table.
1304
 *
1305
 * @return the Name of the last style string or NULL on error.
1306
 */
1307
1308
const char *OGR_STBL_GetLastStyleName(OGRStyleTableH hStyleTable)
1309
0
{
1310
0
    VALIDATE_POINTER1(hStyleTable, "OGR_STBL_GetLastStyleName", nullptr);
1311
1312
0
    return reinterpret_cast<OGRStyleTable *>(hStyleTable)->GetLastStyleName();
1313
0
}
1314
1315
/****************************************************************************/
1316
/*                          OGRStyleTool::OGRStyleTool()                    */
1317
/*                                                                          */
1318
/****************************************************************************/
1319
1320
/** Constructor */
1321
0
OGRStyleTool::OGRStyleTool(OGRSTClassId eClassId) : m_eClassId(eClassId)
1322
0
{
1323
0
}
1324
1325
/************************************************************************/
1326
/*                            OGR_ST_Create()                           */
1327
/************************************************************************/
1328
/**
1329
 * \brief OGRStyleTool factory.
1330
 *
1331
 * This function is a constructor for OGRStyleTool derived classes.
1332
 *
1333
 * @param eClassId subclass of style tool to create. One of OGRSTCPen (1),
1334
 * OGRSTCBrush (2), OGRSTCSymbol (3) or OGRSTCLabel (4).
1335
 *
1336
 * @return a handle to the new style tool object or NULL if the creation
1337
 * failed.
1338
 */
1339
1340
OGRStyleToolH OGR_ST_Create(OGRSTClassId eClassId)
1341
1342
0
{
1343
0
    switch (eClassId)
1344
0
    {
1345
0
        case OGRSTCPen:
1346
0
            return reinterpret_cast<OGRStyleToolH>(new OGRStylePen());
1347
0
        case OGRSTCBrush:
1348
0
            return reinterpret_cast<OGRStyleToolH>(new OGRStyleBrush());
1349
0
        case OGRSTCSymbol:
1350
0
            return reinterpret_cast<OGRStyleToolH>(new OGRStyleSymbol());
1351
0
        case OGRSTCLabel:
1352
0
            return reinterpret_cast<OGRStyleToolH>(new OGRStyleLabel());
1353
0
        default:
1354
0
            return nullptr;
1355
0
    }
1356
0
}
1357
1358
/****************************************************************************/
1359
/*                       OGRStyleTool::~OGRStyleTool()                      */
1360
/*                                                                          */
1361
/****************************************************************************/
1362
OGRStyleTool::~OGRStyleTool()
1363
0
{
1364
0
    CPLFree(m_pszStyleString);
1365
0
}
1366
1367
/************************************************************************/
1368
/*                           OGR_ST_Destroy()                            */
1369
/************************************************************************/
1370
/**
1371
 * \brief Destroy Style Tool
1372
 *
1373
 * @param hST handle to the style tool to destroy.
1374
 */
1375
1376
void OGR_ST_Destroy(OGRStyleToolH hST)
1377
1378
0
{
1379
0
    delete reinterpret_cast<OGRStyleTool *>(hST);
1380
0
}
1381
1382
/****************************************************************************/
1383
/*      void OGRStyleTool::SetStyleString(const char *pszStyleString)       */
1384
/*                                                                          */
1385
/****************************************************************************/
1386
1387
/** Undocumented
1388
 * @param pszStyleString undocumented.
1389
 */
1390
void OGRStyleTool::SetStyleString(const char *pszStyleString)
1391
0
{
1392
0
    m_pszStyleString = CPLStrdup(pszStyleString);
1393
0
}
1394
1395
/****************************************************************************/
1396
/*const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam, */
1397
/*                          OGRStyleValue *pasStyleValue, int nSize)        */
1398
/*                                                                          */
1399
/****************************************************************************/
1400
1401
/** Undocumented
1402
 * @param pasStyleParam undocumented.
1403
 * @param pasStyleValue undocumented.
1404
 * @param nSize undocumented.
1405
 * @return undocumented.
1406
 */
1407
const char *OGRStyleTool::GetStyleString(const OGRStyleParamId *pasStyleParam,
1408
                                         OGRStyleValue *pasStyleValue,
1409
                                         int nSize)
1410
0
{
1411
0
    if (IsStyleModified())
1412
0
    {
1413
0
        CPLFree(m_pszStyleString);
1414
1415
0
        const char *pszClass = nullptr;
1416
0
        switch (GetType())
1417
0
        {
1418
0
            case OGRSTCPen:
1419
0
                pszClass = "PEN(";
1420
0
                break;
1421
0
            case OGRSTCBrush:
1422
0
                pszClass = "BRUSH(";
1423
0
                break;
1424
0
            case OGRSTCSymbol:
1425
0
                pszClass = "SYMBOL(";
1426
0
                break;
1427
0
            case OGRSTCLabel:
1428
0
                pszClass = "LABEL(";
1429
0
                break;
1430
0
            default:
1431
0
                pszClass = "UNKNOWN(";
1432
0
        }
1433
1434
0
        CPLString osCurrent = pszClass;
1435
1436
0
        bool bFound = false;
1437
0
        for (int i = 0; i < nSize; i++)
1438
0
        {
1439
0
            if (!pasStyleValue[i].bValid ||
1440
0
                pasStyleParam[i].eType == OGRSTypeUnused)
1441
0
            {
1442
0
                continue;
1443
0
            }
1444
1445
0
            if (bFound)
1446
0
                osCurrent += ",";
1447
0
            bFound = true;
1448
1449
0
            osCurrent += pasStyleParam[i].pszToken;
1450
0
            switch (pasStyleParam[i].eType)
1451
0
            {
1452
0
                case OGRSTypeString:
1453
0
                    osCurrent += ":";
1454
0
                    osCurrent += pasStyleValue[i].pszValue;
1455
0
                    break;
1456
0
                case OGRSTypeDouble:
1457
0
                    osCurrent +=
1458
0
                        CPLString().Printf(":%f", pasStyleValue[i].dfValue);
1459
0
                    break;
1460
0
                case OGRSTypeInteger:
1461
0
                    osCurrent +=
1462
0
                        CPLString().Printf(":%d", pasStyleValue[i].nValue);
1463
0
                    break;
1464
0
                case OGRSTypeBoolean:
1465
0
                    osCurrent +=
1466
0
                        CPLString().Printf(":%d", pasStyleValue[i].nValue != 0);
1467
0
                    break;
1468
0
                default:
1469
0
                    break;
1470
0
            }
1471
0
            if (pasStyleParam[i].bGeoref)
1472
0
                switch (pasStyleValue[i].eUnit)
1473
0
                {
1474
0
                    case OGRSTUGround:
1475
0
                        osCurrent += "g";
1476
0
                        break;
1477
0
                    case OGRSTUPixel:
1478
0
                        osCurrent += "px";
1479
0
                        break;
1480
0
                    case OGRSTUPoints:
1481
0
                        osCurrent += "pt";
1482
0
                        break;
1483
0
                    case OGRSTUCM:
1484
0
                        osCurrent += "cm";
1485
0
                        break;
1486
0
                    case OGRSTUInches:
1487
0
                        osCurrent += "in";
1488
0
                        break;
1489
0
                    case OGRSTUMM:
1490
                        // osCurrent += "mm";
1491
0
                    default:
1492
0
                        break;  // imp
1493
0
                }
1494
0
        }
1495
0
        osCurrent += ")";
1496
1497
0
        m_pszStyleString = CPLStrdup(osCurrent);
1498
1499
0
        m_bModified = FALSE;
1500
0
    }
1501
1502
0
    return m_pszStyleString;
1503
0
}
1504
1505
/************************************************************************/
1506
/*                          GetRGBFromString()                          */
1507
/************************************************************************/
1508
/**
1509
 * \brief Return the r,g,b,a components of a color encoded in \#RRGGBB[AA]
1510
 * format.
1511
 *
1512
 * Maps to OGRStyleTool::GetRGBFromString().
1513
 *
1514
 * @param pszColor the color to parse
1515
 * @param nRed reference to an int in which the red value will be returned.
1516
 * @param nGreen reference to an int in which the green value will be returned.
1517
 * @param nBlue reference to an int in which the blue value will be returned.
1518
 * @param nTransparance reference to an int in which the (optional) alpha value
1519
 * will be returned.
1520
 *
1521
 * @return TRUE if the color could be successfully parsed, or FALSE in case of
1522
 * errors.
1523
 */
1524
GBool OGRStyleTool::GetRGBFromString(const char *pszColor, int &nRed,
1525
                                     int &nGreen, int &nBlue,
1526
                                     int &nTransparance)
1527
0
{
1528
0
    int nCount = 0;
1529
1530
0
    nTransparance = 255;
1531
1532
    // FIXME: should we really use sscanf here?
1533
0
    unsigned int unRed = 0;
1534
0
    unsigned int unGreen = 0;
1535
0
    unsigned int unBlue = 0;
1536
0
    unsigned int unTransparance = 0;
1537
0
    if (pszColor)
1538
0
        nCount = sscanf(pszColor, "#%2x%2x%2x%2x", &unRed, &unGreen, &unBlue,
1539
0
                        &unTransparance);
1540
0
    nRed = static_cast<int>(unRed);
1541
0
    nGreen = static_cast<int>(unGreen);
1542
0
    nBlue = static_cast<int>(unBlue);
1543
0
    if (nCount == 4)
1544
0
        nTransparance = static_cast<int>(unTransparance);
1545
0
    return nCount >= 3;
1546
0
}
1547
1548
/************************************************************************/
1549
/*                           GetSpecificId()                            */
1550
/*                                                                      */
1551
/*      return -1, if the wanted type is not found, ex:                 */
1552
/*      if you want ogr-pen value, pszWanted should be ogr-pen(case     */
1553
/*      sensitive)                                                      */
1554
/************************************************************************/
1555
1556
/** Undocumented
1557
 * @param pszId Undocumented
1558
 * @param pszWanted Undocumented
1559
 * @return Undocumented
1560
 */
1561
int OGRStyleTool::GetSpecificId(const char *pszId, const char *pszWanted)
1562
0
{
1563
0
    const char *pszRealWanted = pszWanted;
1564
1565
0
    if (pszWanted == nullptr || strlen(pszWanted) == 0)
1566
0
        pszRealWanted = "ogr-pen";
1567
1568
0
    if (pszId == nullptr)
1569
0
        return -1;
1570
1571
0
    int nValue = -1;
1572
0
    const char *pszFound = strstr(pszId, pszRealWanted);
1573
0
    if (pszFound != nullptr)
1574
0
    {
1575
        // We found the string, it could be no value after it, use default one.
1576
0
        nValue = 0;
1577
1578
0
        if (pszFound[strlen(pszRealWanted)] == '-')
1579
0
            nValue = atoi(&pszFound[strlen(pszRealWanted) + 1]);
1580
0
    }
1581
1582
0
    return nValue;
1583
0
}
1584
1585
/************************************************************************/
1586
/*                              GetType()                               */
1587
/************************************************************************/
1588
1589
/**
1590
 * \brief Determine type of Style Tool
1591
 *
1592
 * @return the style tool type, one of OGRSTCPen (1), OGRSTCBrush (2),
1593
 * OGRSTCSymbol (3) or OGRSTCLabel (4). Returns OGRSTCNone (0) if the
1594
 * OGRStyleToolH is invalid.
1595
 */
1596
OGRSTClassId OGRStyleTool::GetType()
1597
0
{
1598
0
    return m_eClassId;
1599
0
}
1600
1601
/************************************************************************/
1602
/*                           OGR_ST_GetType()                           */
1603
/************************************************************************/
1604
/**
1605
 * \brief Determine type of Style Tool
1606
 *
1607
 * @param hST handle to the style tool.
1608
 *
1609
 * @return the style tool type, one of OGRSTCPen (1), OGRSTCBrush (2),
1610
 * OGRSTCSymbol (3) or OGRSTCLabel (4). Returns OGRSTCNone (0) if the
1611
 * OGRStyleToolH is invalid.
1612
 */
1613
1614
OGRSTClassId OGR_ST_GetType(OGRStyleToolH hST)
1615
1616
0
{
1617
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetType", OGRSTCNone);
1618
0
    return reinterpret_cast<OGRStyleTool *>(hST)->GetType();
1619
0
}
1620
1621
/************************************************************************/
1622
/*                           OGR_ST_GetUnit()                           */
1623
/************************************************************************/
1624
1625
/**
1626
 * \fn OGRStyleTool::GetUnit()
1627
 * \brief Get Style Tool units
1628
 *
1629
 * @return the style tool units.
1630
 */
1631
1632
/**
1633
 * \brief Get Style Tool units
1634
 *
1635
 * @param hST handle to the style tool.
1636
 *
1637
 * @return the style tool units.
1638
 */
1639
1640
OGRSTUnitId OGR_ST_GetUnit(OGRStyleToolH hST)
1641
1642
0
{
1643
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetUnit", OGRSTUGround);
1644
0
    return reinterpret_cast<OGRStyleTool *>(hST)->GetUnit();
1645
0
}
1646
1647
/************************************************************************/
1648
/*                              SetUnit()                               */
1649
/************************************************************************/
1650
1651
/**
1652
 * \brief Set Style Tool units
1653
 *
1654
 * @param eUnit the new unit.
1655
 * @param dfGroundPaperScale ground to paper scale factor.
1656
 *
1657
 */
1658
void OGRStyleTool::SetUnit(OGRSTUnitId eUnit, double dfGroundPaperScale)
1659
0
{
1660
0
    m_eUnit = eUnit;
1661
0
    m_dfScale = dfGroundPaperScale;
1662
0
}
1663
1664
/************************************************************************/
1665
/*                           OGR_ST_SetUnit()                           */
1666
/************************************************************************/
1667
/**
1668
 * \brief Set Style Tool units
1669
 *
1670
 * This function is the same as OGRStyleTool::SetUnit()
1671
 *
1672
 * @param hST handle to the style tool.
1673
 * @param eUnit the new unit.
1674
 * @param dfGroundPaperScale ground to paper scale factor.
1675
 *
1676
 */
1677
1678
void OGR_ST_SetUnit(OGRStyleToolH hST, OGRSTUnitId eUnit,
1679
                    double dfGroundPaperScale)
1680
1681
0
{
1682
0
    VALIDATE_POINTER0(hST, "OGR_ST_SetUnit");
1683
0
    reinterpret_cast<OGRStyleTool *>(hST)->SetUnit(eUnit, dfGroundPaperScale);
1684
0
}
1685
1686
/************************************************************************/
1687
/*                               Parse()                                */
1688
/************************************************************************/
1689
1690
//! @cond Doxygen_Suppress
1691
GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle,
1692
                          OGRStyleValue *pasValue, int nCount)
1693
0
{
1694
0
    if (IsStyleParsed())
1695
0
        return TRUE;
1696
1697
0
    StyleParsed();
1698
1699
0
    if (m_pszStyleString == nullptr)
1700
0
        return FALSE;
1701
1702
    // Token to contains StyleString Type and content.
1703
    // Tokenize the String to get the Type and the content
1704
    // Example: Type(elem1:val2,elem2:val2)
1705
0
    char **papszToken = CSLTokenizeString2(
1706
0
        m_pszStyleString, "()",
1707
0
        CSLT_HONOURSTRINGS | CSLT_PRESERVEQUOTES | CSLT_PRESERVEESCAPES);
1708
1709
0
    if (CSLCount(papszToken) > 2 || CSLCount(papszToken) == 0)
1710
0
    {
1711
0
        CSLDestroy(papszToken);
1712
0
        CPLError(CE_Failure, CPLE_AppDefined,
1713
0
                 "Error in the format of the StyleTool %s", m_pszStyleString);
1714
0
        return FALSE;
1715
0
    }
1716
1717
    // Token that will contains StyleString elements.
1718
    // Tokenize the content of the StyleString to get paired components in it.
1719
0
    char **papszToken2 = CSLTokenizeString2(
1720
0
        papszToken[1], ",",
1721
0
        CSLT_HONOURSTRINGS | CSLT_PRESERVEQUOTES | CSLT_PRESERVEESCAPES);
1722
1723
    // Valid that we have the right StyleString for this feature type.
1724
0
    switch (GetType())
1725
0
    {
1726
0
        case OGRSTCPen:
1727
0
            if (!EQUAL(papszToken[0], "PEN"))
1728
0
            {
1729
0
                CPLError(
1730
0
                    CE_Failure, CPLE_AppDefined,
1731
0
                    "Error in the Type of StyleTool %s should be a PEN Type",
1732
0
                    papszToken[0]);
1733
0
                CSLDestroy(papszToken);
1734
0
                CSLDestroy(papszToken2);
1735
0
                return FALSE;
1736
0
            }
1737
0
            break;
1738
0
        case OGRSTCBrush:
1739
0
            if (!EQUAL(papszToken[0], "BRUSH"))
1740
0
            {
1741
0
                CPLError(
1742
0
                    CE_Failure, CPLE_AppDefined,
1743
0
                    "Error in the Type of StyleTool %s should be a BRUSH Type",
1744
0
                    papszToken[0]);
1745
0
                CSLDestroy(papszToken);
1746
0
                CSLDestroy(papszToken2);
1747
0
                return FALSE;
1748
0
            }
1749
0
            break;
1750
0
        case OGRSTCSymbol:
1751
0
            if (!EQUAL(papszToken[0], "SYMBOL"))
1752
0
            {
1753
0
                CPLError(CE_Failure, CPLE_AppDefined,
1754
0
                         "Error in the Type of StyleTool %s should be "
1755
0
                         "a SYMBOL Type",
1756
0
                         papszToken[0]);
1757
0
                CSLDestroy(papszToken);
1758
0
                CSLDestroy(papszToken2);
1759
0
                return FALSE;
1760
0
            }
1761
0
            break;
1762
0
        case OGRSTCLabel:
1763
0
            if (!EQUAL(papszToken[0], "LABEL"))
1764
0
            {
1765
0
                CPLError(
1766
0
                    CE_Failure, CPLE_AppDefined,
1767
0
                    "Error in the Type of StyleTool %s should be a LABEL Type",
1768
0
                    papszToken[0]);
1769
0
                CSLDestroy(papszToken);
1770
0
                CSLDestroy(papszToken2);
1771
0
                return FALSE;
1772
0
            }
1773
0
            break;
1774
0
        default:
1775
0
            CPLError(CE_Failure, CPLE_AppDefined,
1776
0
                     "Error in the Type of StyleTool, Type undetermined");
1777
0
            CSLDestroy(papszToken);
1778
0
            CSLDestroy(papszToken2);
1779
0
            return FALSE;
1780
0
    }
1781
1782
    ////////////////////////////////////////////////////////////////////////
1783
    // Here we will loop on each element in the StyleString. If it is
1784
    // a valid element, we will add it in the StyleTool with
1785
    // SetParamStr().
1786
    //
1787
    // It is important to note that the SetInternalUnit...() is use to update
1788
    // the unit of the StyleTool param (m_eUnit).
1789
    // See OGRStyleTool::SetParamStr().
1790
    // There's a StyleTool unit (m_eUnit), which is the output unit, and each
1791
    // parameter of the style have its own unit value (the input unit). Here we
1792
    // set m_eUnit to the input unit and in SetParamStr(), we will use this
1793
    // value to set the input unit. Then after the loop we will reset m_eUnit
1794
    // to its original value. (Yes it is a side effect / black magic)
1795
    //
1796
    // The pasStyle variable is a global variable passed in argument to the
1797
    // function. See at the top of this file the four OGRStyleParamId
1798
    // variable. They are used to register the valid parameter of each
1799
    // StyleTool.
1800
    ////////////////////////////////////////////////////////////////////////
1801
1802
    // Save Scale and output Units because the parsing code will alter
1803
    // the values.
1804
0
    OGRSTUnitId eLastUnit = m_eUnit;
1805
0
    double dSavedScale = m_dfScale;
1806
0
    const int nElements = CSLCount(papszToken2);
1807
1808
0
    for (int i = 0; i < nElements; i++)
1809
0
    {
1810
0
        char **papszStylePair =
1811
0
            CSLTokenizeString2(papszToken2[i], ":",
1812
0
                               CSLT_HONOURSTRINGS | CSLT_STRIPLEADSPACES |
1813
0
                                   CSLT_STRIPENDSPACES | CSLT_ALLOWEMPTYTOKENS);
1814
1815
0
        const int nTokens = CSLCount(papszStylePair);
1816
1817
0
        if (nTokens < 1 || nTokens > 2)
1818
0
        {
1819
0
            CPLError(CE_Warning, CPLE_AppDefined,
1820
0
                     "Error in the StyleTool String %s", m_pszStyleString);
1821
0
            CPLError(CE_Warning, CPLE_AppDefined,
1822
0
                     "Malformed element #%d (\"%s\") skipped", i,
1823
0
                     papszToken2[i]);
1824
0
            CSLDestroy(papszStylePair);
1825
0
            continue;
1826
0
        }
1827
1828
0
        for (int j = 0; j < nCount; j++)
1829
0
        {
1830
0
            if (pasStyle[j].pszToken &&
1831
0
                EQUAL(pasStyle[j].pszToken, papszStylePair[0]))
1832
0
            {
1833
0
                if (papszStylePair[1] != nullptr && pasStyle[j].bGeoref == TRUE)
1834
0
                    SetInternalInputUnitFromParam(papszStylePair[1]);
1835
1836
                // Set either the actual value of style parameter or "1"
1837
                // for boolean parameters which do not have values (legacy
1838
                // behavior).
1839
0
                OGRStyleTool::SetParamStr(
1840
0
                    pasStyle[j], pasValue[j],
1841
0
                    papszStylePair[1] != nullptr ? papszStylePair[1] : "1");
1842
1843
0
                break;
1844
0
            }
1845
0
        }
1846
1847
0
        CSLDestroy(papszStylePair);
1848
0
    }
1849
1850
0
    m_eUnit = eLastUnit;
1851
0
    m_dfScale = dSavedScale;
1852
1853
0
    CSLDestroy(papszToken2);
1854
0
    CSLDestroy(papszToken);
1855
1856
0
    return TRUE;
1857
0
}
1858
1859
//! @endcond
1860
1861
/************************************************************************/
1862
/*                   SetInternalInputUnitFromParam()                    */
1863
/************************************************************************/
1864
1865
//! @cond Doxygen_Suppress
1866
void OGRStyleTool::SetInternalInputUnitFromParam(char *pszString)
1867
0
{
1868
0
    if (pszString == nullptr)
1869
0
        return;
1870
1871
0
    char *pszUnit = strstr(pszString, "g");
1872
0
    if (pszUnit)
1873
0
    {
1874
0
        SetUnit(OGRSTUGround);
1875
0
        pszUnit[0] = '\0';
1876
0
        return;
1877
0
    }
1878
0
    pszUnit = strstr(pszString, "px");
1879
0
    if (pszUnit)
1880
0
    {
1881
0
        SetUnit(OGRSTUPixel);
1882
0
        pszUnit[0] = '\0';
1883
0
        return;
1884
0
    }
1885
0
    pszUnit = strstr(pszString, "pt");
1886
0
    if (pszUnit)
1887
0
    {
1888
0
        SetUnit(OGRSTUPoints);
1889
0
        pszUnit[0] = '\0';
1890
0
        return;
1891
0
    }
1892
0
    pszUnit = strstr(pszString, "mm");
1893
0
    if (pszUnit)
1894
0
    {
1895
0
        SetUnit(OGRSTUMM);
1896
0
        pszUnit[0] = '\0';
1897
0
        return;
1898
0
    }
1899
0
    pszUnit = strstr(pszString, "cm");
1900
0
    if (pszUnit)
1901
0
    {
1902
0
        SetUnit(OGRSTUCM);
1903
0
        pszUnit[0] = '\0';
1904
0
        return;
1905
0
    }
1906
0
    pszUnit = strstr(pszString, "in");
1907
0
    if (pszUnit)
1908
0
    {
1909
0
        SetUnit(OGRSTUInches);
1910
0
        pszUnit[0] = '\0';
1911
0
        return;
1912
0
    }
1913
1914
0
    SetUnit(OGRSTUMM);
1915
0
}
1916
1917
/************************************************************************/
1918
/*                          ComputeWithUnit()                           */
1919
/************************************************************************/
1920
double OGRStyleTool::ComputeWithUnit(double dfValue, OGRSTUnitId eInputUnit)
1921
0
{
1922
0
    OGRSTUnitId eOutputUnit = GetUnit();
1923
1924
0
    double dfNewValue = dfValue;  // dfValue in meters;
1925
1926
0
    if (eOutputUnit == eInputUnit)
1927
0
        return dfValue;
1928
1929
0
    switch (eInputUnit)
1930
0
    {
1931
0
        case OGRSTUGround:
1932
0
            dfNewValue = dfValue / m_dfScale;
1933
0
            break;
1934
0
        case OGRSTUPixel:
1935
0
            dfNewValue = dfValue / (72.0 * 39.37);
1936
0
            break;
1937
0
        case OGRSTUPoints:
1938
0
            dfNewValue = dfValue / (72.0 * 39.37);
1939
0
            break;
1940
0
        case OGRSTUMM:
1941
0
            dfNewValue = 0.001 * dfValue;
1942
0
            break;
1943
0
        case OGRSTUCM:
1944
0
            dfNewValue = 0.01 * dfValue;
1945
0
            break;
1946
0
        case OGRSTUInches:
1947
0
            dfNewValue = dfValue / 39.37;
1948
0
            break;
1949
0
        default:
1950
0
            break;  // imp.
1951
0
    }
1952
1953
0
    switch (eOutputUnit)
1954
0
    {
1955
0
        case OGRSTUGround:
1956
0
            dfNewValue *= m_dfScale;
1957
0
            break;
1958
0
        case OGRSTUPixel:
1959
0
            dfNewValue *= 72.0 * 39.37;
1960
0
            break;
1961
0
        case OGRSTUPoints:
1962
0
            dfNewValue *= 72.0 * 39.37;
1963
0
            break;
1964
0
        case OGRSTUMM:
1965
0
            dfNewValue *= 1000.0;
1966
0
            break;
1967
0
        case OGRSTUCM:
1968
0
            dfNewValue *= 100.0;
1969
0
            break;
1970
0
        case OGRSTUInches:
1971
0
            dfNewValue *= 39.37;
1972
0
            break;
1973
0
        default:
1974
0
            break;  // imp.
1975
0
    }
1976
0
    return dfNewValue;
1977
0
}
1978
1979
/************************************************************************/
1980
/*                          ComputeWithUnit()                           */
1981
/************************************************************************/
1982
int OGRStyleTool::ComputeWithUnit(int nValue, OGRSTUnitId eUnit)
1983
0
{
1984
0
    return static_cast<int>(
1985
0
        ComputeWithUnit(static_cast<double>(nValue), eUnit));
1986
0
}
1987
1988
//! @endcond
1989
1990
/************************************************************************/
1991
/*                            GetParamStr()                             */
1992
/************************************************************************/
1993
1994
/** Undocumented
1995
 * @param sStyleParam undocumented.
1996
 * @param sStyleValue undocumented.
1997
 * @param bValueIsNull undocumented.
1998
 * @return Undocumented.
1999
 */
2000
const char *OGRStyleTool::GetParamStr(const OGRStyleParamId &sStyleParam,
2001
                                      const OGRStyleValue &sStyleValue,
2002
                                      GBool &bValueIsNull)
2003
0
{
2004
0
    if (!Parse())
2005
0
    {
2006
0
        bValueIsNull = TRUE;
2007
0
        return nullptr;
2008
0
    }
2009
2010
0
    bValueIsNull = !sStyleValue.bValid;
2011
2012
0
    if (bValueIsNull == TRUE)
2013
0
        return nullptr;
2014
2015
0
    switch (sStyleParam.eType)
2016
0
    {
2017
        // If sStyleParam.bGeoref == TRUE, need to convert to output value.
2018
0
        case OGRSTypeString:
2019
0
            return sStyleValue.pszValue;
2020
0
        case OGRSTypeDouble:
2021
0
            if (sStyleParam.bGeoref)
2022
0
                return CPLSPrintf("%f", ComputeWithUnit(sStyleValue.dfValue,
2023
0
                                                        sStyleValue.eUnit));
2024
0
            else
2025
0
                return CPLSPrintf("%f", sStyleValue.dfValue);
2026
2027
0
        case OGRSTypeInteger:
2028
0
            if (sStyleParam.bGeoref)
2029
0
                return CPLSPrintf("%d", ComputeWithUnit(sStyleValue.nValue,
2030
0
                                                        sStyleValue.eUnit));
2031
0
            else
2032
0
                return CPLSPrintf("%d", sStyleValue.nValue);
2033
0
        case OGRSTypeBoolean:
2034
0
            return CPLSPrintf("%d", sStyleValue.nValue != 0);
2035
0
        default:
2036
0
            bValueIsNull = TRUE;
2037
0
            return nullptr;
2038
0
    }
2039
0
}
2040
2041
/****************************************************************************/
2042
/*    int OGRStyleTool::GetParamNum(OGRStyleParamId sStyleParam ,           */
2043
/*                               OGRStyleValue sStyleValue,                 */
2044
/*                               GBool &bValueIsNull)                       */
2045
/*                                                                          */
2046
/****************************************************************************/
2047
2048
/** Undocumented
2049
 * @param sStyleParam undocumented.
2050
 * @param sStyleValue undocumented.
2051
 * @param bValueIsNull undocumented.
2052
 * @return Undocumented.
2053
 */
2054
int OGRStyleTool::GetParamNum(const OGRStyleParamId &sStyleParam,
2055
                              const OGRStyleValue &sStyleValue,
2056
                              GBool &bValueIsNull)
2057
0
{
2058
0
    return static_cast<int>(
2059
0
        GetParamDbl(sStyleParam, sStyleValue, bValueIsNull));
2060
0
}
2061
2062
/****************************************************************************/
2063
/*       double OGRStyleTool::GetParamDbl(OGRStyleParamId sStyleParam ,     */
2064
/*                               OGRStyleValue sStyleValue,                 */
2065
/*                               GBool &bValueIsNull)                       */
2066
/*                                                                          */
2067
/****************************************************************************/
2068
2069
/** Undocumented
2070
 * @param sStyleParam undocumented.
2071
 * @param sStyleValue undocumented.
2072
 * @param bValueIsNull undocumented.
2073
 * @return Undocumented.
2074
 */
2075
double OGRStyleTool::GetParamDbl(const OGRStyleParamId &sStyleParam,
2076
                                 const OGRStyleValue &sStyleValue,
2077
                                 GBool &bValueIsNull)
2078
0
{
2079
0
    if (!Parse())
2080
0
    {
2081
0
        bValueIsNull = TRUE;
2082
0
        return 0.0;
2083
0
    }
2084
2085
0
    bValueIsNull = !sStyleValue.bValid;
2086
2087
0
    if (bValueIsNull == TRUE)
2088
0
        return 0.0;
2089
2090
0
    switch (sStyleParam.eType)
2091
0
    {
2092
        // if sStyleParam.bGeoref == TRUE, need to convert to output value.
2093
0
        case OGRSTypeString:
2094
0
            if (sStyleParam.bGeoref)
2095
0
                return ComputeWithUnit(CPLAtof(sStyleValue.pszValue),
2096
0
                                       sStyleValue.eUnit);
2097
0
            else
2098
0
                return CPLAtof(sStyleValue.pszValue);
2099
0
        case OGRSTypeDouble:
2100
0
            if (sStyleParam.bGeoref)
2101
0
                return ComputeWithUnit(sStyleValue.dfValue, sStyleValue.eUnit);
2102
0
            else
2103
0
                return sStyleValue.dfValue;
2104
0
        case OGRSTypeInteger:
2105
0
            if (sStyleParam.bGeoref)
2106
0
                return static_cast<double>(
2107
0
                    ComputeWithUnit(sStyleValue.nValue, sStyleValue.eUnit));
2108
0
            else
2109
0
                return static_cast<double>(sStyleValue.nValue);
2110
0
        case OGRSTypeBoolean:
2111
0
            return static_cast<double>(sStyleValue.nValue != 0);
2112
0
        default:
2113
0
            bValueIsNull = TRUE;
2114
0
            return 0.0;
2115
0
    }
2116
0
}
2117
2118
/****************************************************************************/
2119
/*                           GetRawParamDbl()                               */
2120
/****************************************************************************/
2121
2122
/** Return the raw value of a parameter of type double.
2123
 *
2124
 * @param sStyleParam Identifier of the parameter.
2125
 * @param sStyleValue Value of the parameter.
2126
 * @param[out] eRawUnit Raw unit
2127
 * @param[out] bValueIsNull if the value is null
2128
 * @return the raw value.
2129
 */
2130
double OGRStyleTool::GetRawParamDbl(const OGRStyleParamId &sStyleParam,
2131
                                    const OGRStyleValue &sStyleValue,
2132
                                    OGRSTUnitId &eRawUnit, GBool &bValueIsNull)
2133
0
{
2134
0
    eRawUnit = OGRSTUGround;
2135
0
    if (!Parse())
2136
0
    {
2137
0
        bValueIsNull = TRUE;
2138
0
        return 0.0;
2139
0
    }
2140
2141
0
    bValueIsNull = !sStyleValue.bValid;
2142
2143
0
    if (bValueIsNull == TRUE)
2144
0
        return 0.0;
2145
2146
0
    switch (sStyleParam.eType)
2147
0
    {
2148
0
        case OGRSTypeDouble:
2149
0
            eRawUnit = sStyleValue.eUnit;
2150
0
            return sStyleValue.dfValue;
2151
2152
0
        default:
2153
0
            bValueIsNull = TRUE;
2154
0
            return 0.0;
2155
0
    }
2156
0
}
2157
2158
/****************************************************************************/
2159
/*      void OGRStyleTool::SetParamStr(OGRStyleParamId &sStyleParam ,       */
2160
/*                             OGRStyleValue &sStyleValue,                  */
2161
/*                             const char *pszParamString)                  */
2162
/*                                                                          */
2163
/****************************************************************************/
2164
2165
/** Undocumented
2166
 * @param sStyleParam undocumented.
2167
 * @param sStyleValue undocumented.
2168
 * @param pszParamString undocumented.
2169
 */
2170
void OGRStyleTool::SetParamStr(const OGRStyleParamId &sStyleParam,
2171
                               OGRStyleValue &sStyleValue,
2172
                               const char *pszParamString)
2173
0
{
2174
0
    Parse();
2175
0
    StyleModified();
2176
0
    sStyleValue.bValid = TRUE;
2177
0
    sStyleValue.eUnit = GetUnit();
2178
0
    switch (sStyleParam.eType)
2179
0
    {
2180
        // If sStyleParam.bGeoref == TRUE, need to convert to output value;
2181
0
        case OGRSTypeString:
2182
0
            sStyleValue.pszValue = CPLStrdup(pszParamString);
2183
0
            break;
2184
0
        case OGRSTypeDouble:
2185
0
            sStyleValue.dfValue = CPLAtof(pszParamString);
2186
0
            break;
2187
0
        case OGRSTypeInteger:
2188
0
            sStyleValue.nValue = atoi(pszParamString);
2189
0
            break;
2190
0
        case OGRSTypeBoolean:
2191
0
            sStyleValue.nValue = atoi(pszParamString) != 0;
2192
0
            break;
2193
0
        default:
2194
0
            sStyleValue.bValid = FALSE;
2195
0
            break;
2196
0
    }
2197
0
}
2198
2199
/****************************************************************************/
2200
/*    void OGRStyleTool::SetParamNum(OGRStyleParamId &sStyleParam ,         */
2201
/*                             OGRStyleValue &sStyleValue,                  */
2202
/*                             int nParam)                                  */
2203
/*                                                                          */
2204
/****************************************************************************/
2205
2206
/** Undocumented
2207
 * @param sStyleParam undocumented.
2208
 * @param sStyleValue undocumented.
2209
 * @param nParam undocumented.
2210
 */
2211
void OGRStyleTool::SetParamNum(const OGRStyleParamId &sStyleParam,
2212
                               OGRStyleValue &sStyleValue, int nParam)
2213
0
{
2214
0
    Parse();
2215
0
    StyleModified();
2216
0
    sStyleValue.bValid = TRUE;
2217
0
    sStyleValue.eUnit = GetUnit();
2218
0
    switch (sStyleParam.eType)
2219
0
    {
2220
2221
        // If sStyleParam.bGeoref == TRUE, need to convert to output value;
2222
0
        case OGRSTypeString:
2223
0
            sStyleValue.pszValue = CPLStrdup(CPLString().Printf("%d", nParam));
2224
0
            break;
2225
0
        case OGRSTypeDouble:
2226
0
            sStyleValue.dfValue = static_cast<double>(nParam);
2227
0
            break;
2228
0
        case OGRSTypeInteger:
2229
0
            sStyleValue.nValue = nParam;
2230
0
            break;
2231
0
        case OGRSTypeBoolean:
2232
0
            sStyleValue.nValue = nParam != 0;
2233
0
            break;
2234
0
        default:
2235
0
            sStyleValue.bValid = FALSE;
2236
0
            break;
2237
0
    }
2238
0
}
2239
2240
/****************************************************************************/
2241
/*      void OGRStyleTool::SetParamDbl(OGRStyleParamId &sStyleParam ,       */
2242
/*                             OGRStyleValue &sStyleValue,                  */
2243
/*                             double dfParam)                              */
2244
/*                                                                          */
2245
/****************************************************************************/
2246
2247
/** Undocumented
2248
 * @param sStyleParam undocumented.
2249
 * @param sStyleValue undocumented.
2250
 * @param dfParam undocumented.
2251
 */
2252
void OGRStyleTool::SetParamDbl(const OGRStyleParamId &sStyleParam,
2253
                               OGRStyleValue &sStyleValue, double dfParam)
2254
0
{
2255
0
    Parse();
2256
0
    StyleModified();
2257
0
    sStyleValue.bValid = TRUE;
2258
0
    sStyleValue.eUnit = GetUnit();
2259
0
    switch (sStyleParam.eType)
2260
0
    {
2261
        // If sStyleParam.bGeoref == TRUE, need to convert to output value;
2262
0
        case OGRSTypeString:
2263
0
            sStyleValue.pszValue = CPLStrdup(CPLString().Printf("%f", dfParam));
2264
0
            break;
2265
0
        case OGRSTypeDouble:
2266
0
            sStyleValue.dfValue = dfParam;
2267
0
            break;
2268
0
        case OGRSTypeInteger:
2269
0
            sStyleValue.nValue = static_cast<int>(dfParam);
2270
0
            break;
2271
0
        case OGRSTypeBoolean:
2272
0
            sStyleValue.nValue = static_cast<int>(dfParam) != 0;
2273
0
            break;
2274
0
        default:
2275
0
            sStyleValue.bValid = FALSE;
2276
0
            break;
2277
0
    }
2278
0
}
2279
2280
/************************************************************************/
2281
/*                           OGR_ST_GetParamStr()                       */
2282
/************************************************************************/
2283
/**
2284
 * \brief Get Style Tool parameter value as string
2285
 *
2286
 * Maps to the OGRStyleTool subclasses' GetParamStr() methods.
2287
 *
2288
 * @param hST handle to the style tool.
2289
 * @param eParam the parameter id from the enumeration corresponding to the
2290
 * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam,
2291
 * OGRSTSymbolParam or OGRSTLabelParam enumerations)
2292
 * @param bValueIsNull pointer to an integer that will be set to TRUE or FALSE
2293
 * to indicate whether the parameter value is NULL.
2294
 *
2295
 * @return the parameter value as string and sets bValueIsNull.
2296
 */
2297
2298
const char *OGR_ST_GetParamStr(OGRStyleToolH hST, int eParam, int *bValueIsNull)
2299
0
{
2300
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetParamStr", "");
2301
0
    VALIDATE_POINTER1(bValueIsNull, "OGR_ST_GetParamStr", "");
2302
2303
0
    GBool bIsNull = TRUE;
2304
0
    const char *pszVal = "";
2305
2306
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2307
0
    {
2308
0
        case OGRSTCPen:
2309
0
            pszVal = reinterpret_cast<OGRStylePen *>(hST)->GetParamStr(
2310
0
                static_cast<OGRSTPenParam>(eParam), bIsNull);
2311
0
            break;
2312
0
        case OGRSTCBrush:
2313
0
            pszVal = reinterpret_cast<OGRStyleBrush *>(hST)->GetParamStr(
2314
0
                static_cast<OGRSTBrushParam>(eParam), bIsNull);
2315
0
            break;
2316
0
        case OGRSTCSymbol:
2317
0
            pszVal = reinterpret_cast<OGRStyleSymbol *>(hST)->GetParamStr(
2318
0
                static_cast<OGRSTSymbolParam>(eParam), bIsNull);
2319
0
            break;
2320
0
        case OGRSTCLabel:
2321
0
            pszVal = reinterpret_cast<OGRStyleLabel *>(hST)->GetParamStr(
2322
0
                static_cast<OGRSTLabelParam>(eParam), bIsNull);
2323
0
            break;
2324
0
        default:
2325
0
            break;
2326
0
    }
2327
2328
0
    *bValueIsNull = bIsNull;
2329
0
    return pszVal;
2330
0
}
2331
2332
/************************************************************************/
2333
/*                           OGR_ST_GetParamNum()                       */
2334
/************************************************************************/
2335
/**
2336
 * \brief Get Style Tool parameter value as an integer
2337
 *
2338
 * Maps to the OGRStyleTool subclasses' GetParamNum() methods.
2339
 *
2340
 * @param hST handle to the style tool.
2341
 * @param eParam the parameter id from the enumeration corresponding to the
2342
 * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam,
2343
 * OGRSTSymbolParam or OGRSTLabelParam enumerations)
2344
 * @param bValueIsNull pointer to an integer that will be set to TRUE or FALSE
2345
 * to indicate whether the parameter value is NULL.
2346
 *
2347
 * @return the parameter value as integer and sets bValueIsNull.
2348
 */
2349
2350
int OGR_ST_GetParamNum(OGRStyleToolH hST, int eParam, int *bValueIsNull)
2351
0
{
2352
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetParamNum", 0);
2353
0
    VALIDATE_POINTER1(bValueIsNull, "OGR_ST_GetParamNum", 0);
2354
2355
0
    GBool bIsNull = TRUE;
2356
0
    int nVal = 0;
2357
2358
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2359
0
    {
2360
0
        case OGRSTCPen:
2361
0
            nVal = reinterpret_cast<OGRStylePen *>(hST)->GetParamNum(
2362
0
                static_cast<OGRSTPenParam>(eParam), bIsNull);
2363
0
            break;
2364
0
        case OGRSTCBrush:
2365
0
            nVal = reinterpret_cast<OGRStyleBrush *>(hST)->GetParamNum(
2366
0
                static_cast<OGRSTBrushParam>(eParam), bIsNull);
2367
0
            break;
2368
0
        case OGRSTCSymbol:
2369
0
            nVal = reinterpret_cast<OGRStyleSymbol *>(hST)->GetParamNum(
2370
0
                static_cast<OGRSTSymbolParam>(eParam), bIsNull);
2371
0
            break;
2372
0
        case OGRSTCLabel:
2373
0
            nVal = reinterpret_cast<OGRStyleLabel *>(hST)->GetParamNum(
2374
0
                static_cast<OGRSTLabelParam>(eParam), bIsNull);
2375
0
            break;
2376
0
        default:
2377
0
            break;
2378
0
    }
2379
2380
0
    *bValueIsNull = bIsNull;
2381
0
    return nVal;
2382
0
}
2383
2384
/************************************************************************/
2385
/*                           OGR_ST_GetParamDbl()                       */
2386
/************************************************************************/
2387
/**
2388
 * \brief Get Style Tool parameter value as a double
2389
 *
2390
 * Maps to the OGRStyleTool subclasses' GetParamDbl() methods.
2391
 *
2392
 * @param hST handle to the style tool.
2393
 * @param eParam the parameter id from the enumeration corresponding to the
2394
 * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam,
2395
 * OGRSTSymbolParam or OGRSTLabelParam enumerations)
2396
 * @param bValueIsNull pointer to an integer that will be set to TRUE or FALSE
2397
 * to indicate whether the parameter value is NULL.
2398
 *
2399
 * @return the parameter value as double and sets bValueIsNull.
2400
 */
2401
2402
double OGR_ST_GetParamDbl(OGRStyleToolH hST, int eParam, int *bValueIsNull)
2403
0
{
2404
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetParamDbl", 0.0);
2405
0
    VALIDATE_POINTER1(bValueIsNull, "OGR_ST_GetParamDbl", 0.0);
2406
2407
0
    GBool bIsNull = TRUE;
2408
0
    double dfVal = 0.0;
2409
2410
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2411
0
    {
2412
0
        case OGRSTCPen:
2413
0
            dfVal = reinterpret_cast<OGRStylePen *>(hST)->GetParamDbl(
2414
0
                static_cast<OGRSTPenParam>(eParam), bIsNull);
2415
0
            break;
2416
0
        case OGRSTCBrush:
2417
0
            dfVal = reinterpret_cast<OGRStyleBrush *>(hST)->GetParamDbl(
2418
0
                static_cast<OGRSTBrushParam>(eParam), bIsNull);
2419
0
            break;
2420
0
        case OGRSTCSymbol:
2421
0
            dfVal = reinterpret_cast<OGRStyleSymbol *>(hST)->GetParamDbl(
2422
0
                static_cast<OGRSTSymbolParam>(eParam), bIsNull);
2423
0
            break;
2424
0
        case OGRSTCLabel:
2425
0
            dfVal = reinterpret_cast<OGRStyleLabel *>(hST)->GetParamDbl(
2426
0
                static_cast<OGRSTLabelParam>(eParam), bIsNull);
2427
0
            break;
2428
0
        default:
2429
0
            break;
2430
0
    }
2431
2432
0
    *bValueIsNull = bIsNull;
2433
0
    return dfVal;
2434
0
}
2435
2436
/************************************************************************/
2437
/*                           OGR_ST_SetParamStr()                       */
2438
/************************************************************************/
2439
/**
2440
 * \brief Set Style Tool parameter value from a string
2441
 *
2442
 * Maps to the OGRStyleTool subclasses' SetParamStr() methods.
2443
 *
2444
 * @param hST handle to the style tool.
2445
 * @param eParam the parameter id from the enumeration corresponding to the
2446
 * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam,
2447
 * OGRSTSymbolParam or OGRSTLabelParam enumerations)
2448
 * @param pszValue the new parameter value
2449
 *
2450
 */
2451
2452
void OGR_ST_SetParamStr(OGRStyleToolH hST, int eParam, const char *pszValue)
2453
0
{
2454
0
    VALIDATE_POINTER0(hST, "OGR_ST_SetParamStr");
2455
0
    VALIDATE_POINTER0(pszValue, "OGR_ST_SetParamStr");
2456
2457
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2458
0
    {
2459
0
        case OGRSTCPen:
2460
0
            reinterpret_cast<OGRStylePen *>(hST)->SetParamStr(
2461
0
                static_cast<OGRSTPenParam>(eParam), pszValue);
2462
0
            break;
2463
0
        case OGRSTCBrush:
2464
0
            reinterpret_cast<OGRStyleBrush *>(hST)->SetParamStr(
2465
0
                static_cast<OGRSTBrushParam>(eParam), pszValue);
2466
0
            break;
2467
0
        case OGRSTCSymbol:
2468
0
            reinterpret_cast<OGRStyleSymbol *>(hST)->SetParamStr(
2469
0
                static_cast<OGRSTSymbolParam>(eParam), pszValue);
2470
0
            break;
2471
0
        case OGRSTCLabel:
2472
0
            reinterpret_cast<OGRStyleLabel *>(hST)->SetParamStr(
2473
0
                static_cast<OGRSTLabelParam>(eParam), pszValue);
2474
0
            break;
2475
0
        default:
2476
0
            break;
2477
0
    }
2478
0
}
2479
2480
/************************************************************************/
2481
/*                           OGR_ST_SetParamNum()                       */
2482
/************************************************************************/
2483
/**
2484
 * \brief Set Style Tool parameter value from an integer
2485
 *
2486
 * Maps to the OGRStyleTool subclasses' SetParamNum() methods.
2487
 *
2488
 * @param hST handle to the style tool.
2489
 * @param eParam the parameter id from the enumeration corresponding to the
2490
 * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam,
2491
 * OGRSTSymbolParam or OGRSTLabelParam enumerations)
2492
 * @param nValue the new parameter value
2493
 *
2494
 */
2495
2496
void OGR_ST_SetParamNum(OGRStyleToolH hST, int eParam, int nValue)
2497
0
{
2498
0
    VALIDATE_POINTER0(hST, "OGR_ST_SetParamNum");
2499
2500
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2501
0
    {
2502
0
        case OGRSTCPen:
2503
0
            reinterpret_cast<OGRStylePen *>(hST)->SetParamNum(
2504
0
                static_cast<OGRSTPenParam>(eParam), nValue);
2505
0
            break;
2506
0
        case OGRSTCBrush:
2507
0
            reinterpret_cast<OGRStyleBrush *>(hST)->SetParamNum(
2508
0
                static_cast<OGRSTBrushParam>(eParam), nValue);
2509
0
            break;
2510
0
        case OGRSTCSymbol:
2511
0
            reinterpret_cast<OGRStyleSymbol *>(hST)->SetParamNum(
2512
0
                static_cast<OGRSTSymbolParam>(eParam), nValue);
2513
0
            break;
2514
0
        case OGRSTCLabel:
2515
0
            reinterpret_cast<OGRStyleLabel *>(hST)->SetParamNum(
2516
0
                static_cast<OGRSTLabelParam>(eParam), nValue);
2517
0
            break;
2518
0
        default:
2519
0
            break;
2520
0
    }
2521
0
}
2522
2523
/************************************************************************/
2524
/*                           OGR_ST_SetParamDbl()                       */
2525
/************************************************************************/
2526
/**
2527
 * \brief Set Style Tool parameter value from a double
2528
 *
2529
 * Maps to the OGRStyleTool subclasses' SetParamDbl() methods.
2530
 *
2531
 * @param hST handle to the style tool.
2532
 * @param eParam the parameter id from the enumeration corresponding to the
2533
 * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam,
2534
 * OGRSTSymbolParam or OGRSTLabelParam enumerations)
2535
 * @param dfValue the new parameter value
2536
 *
2537
 */
2538
2539
void OGR_ST_SetParamDbl(OGRStyleToolH hST, int eParam, double dfValue)
2540
0
{
2541
0
    VALIDATE_POINTER0(hST, "OGR_ST_SetParamDbl");
2542
2543
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2544
0
    {
2545
0
        case OGRSTCPen:
2546
0
            reinterpret_cast<OGRStylePen *>(hST)->SetParamDbl(
2547
0
                static_cast<OGRSTPenParam>(eParam), dfValue);
2548
0
            break;
2549
0
        case OGRSTCBrush:
2550
0
            reinterpret_cast<OGRStyleBrush *>(hST)->SetParamDbl(
2551
0
                static_cast<OGRSTBrushParam>(eParam), dfValue);
2552
0
            break;
2553
0
        case OGRSTCSymbol:
2554
0
            reinterpret_cast<OGRStyleSymbol *>(hST)->SetParamDbl(
2555
0
                static_cast<OGRSTSymbolParam>(eParam), dfValue);
2556
0
            break;
2557
0
        case OGRSTCLabel:
2558
0
            reinterpret_cast<OGRStyleLabel *>(hST)->SetParamDbl(
2559
0
                static_cast<OGRSTLabelParam>(eParam), dfValue);
2560
0
            break;
2561
0
        default:
2562
0
            break;
2563
0
    }
2564
0
}
2565
2566
/************************************************************************/
2567
/*                           OGR_ST_GetStyleString()                    */
2568
/************************************************************************/
2569
2570
/**
2571
 * \fn OGRStyleTool::GetStyleString()
2572
 * \brief Get the style string for this Style Tool
2573
 *
2574
 * Maps to the OGRStyleTool subclasses' GetStyleString() methods.
2575
 *
2576
 * @return the style string for this style tool or "" if the hST is invalid.
2577
 */
2578
2579
/**
2580
 * \brief Get the style string for this Style Tool
2581
 *
2582
 * Maps to the OGRStyleTool subclasses' GetStyleString() methods.
2583
 *
2584
 * @param hST handle to the style tool.
2585
 *
2586
 * @return the style string for this style tool or "" if the hST is invalid.
2587
 */
2588
2589
const char *OGR_ST_GetStyleString(OGRStyleToolH hST)
2590
0
{
2591
0
    const char *pszVal = "";
2592
2593
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetStyleString", "");
2594
2595
0
    switch (reinterpret_cast<OGRStyleTool *>(hST)->GetType())
2596
0
    {
2597
0
        case OGRSTCPen:
2598
0
            pszVal = reinterpret_cast<OGRStylePen *>(hST)->GetStyleString();
2599
0
            break;
2600
0
        case OGRSTCBrush:
2601
0
            pszVal = reinterpret_cast<OGRStyleBrush *>(hST)->GetStyleString();
2602
0
            break;
2603
0
        case OGRSTCSymbol:
2604
0
            pszVal = reinterpret_cast<OGRStyleSymbol *>(hST)->GetStyleString();
2605
0
            break;
2606
0
        case OGRSTCLabel:
2607
0
            pszVal = reinterpret_cast<OGRStyleLabel *>(hST)->GetStyleString();
2608
0
            break;
2609
0
        default:
2610
0
            break;
2611
0
    }
2612
2613
0
    return pszVal;
2614
0
}
2615
2616
/************************************************************************/
2617
/*                           OGR_ST_GetRGBFromString()                  */
2618
/************************************************************************/
2619
/**
2620
 * \brief Return the r,g,b,a components of a color encoded in \#RRGGBB[AA]
2621
 * format.
2622
 *
2623
 * Maps to OGRStyleTool::GetRGBFromString().
2624
 *
2625
 * @param hST handle to the style tool.
2626
 * @param pszColor the color to parse
2627
 * @param pnRed pointer to an int in which the red value will be returned
2628
 * @param pnGreen pointer to an int in which the green value will be returned
2629
 * @param pnBlue pointer to an int in which the blue value will be returned
2630
 * @param pnAlpha pointer to an int in which the (optional) alpha value will
2631
 * be returned
2632
 *
2633
 * @return TRUE if the color could be successfully parsed, or FALSE in case of
2634
 * errors.
2635
 */
2636
2637
int OGR_ST_GetRGBFromString(OGRStyleToolH hST, const char *pszColor, int *pnRed,
2638
                            int *pnGreen, int *pnBlue, int *pnAlpha)
2639
0
{
2640
2641
0
    VALIDATE_POINTER1(hST, "OGR_ST_GetRGBFromString", FALSE);
2642
0
    VALIDATE_POINTER1(pnRed, "OGR_ST_GetRGBFromString", FALSE);
2643
0
    VALIDATE_POINTER1(pnGreen, "OGR_ST_GetRGBFromString", FALSE);
2644
0
    VALIDATE_POINTER1(pnBlue, "OGR_ST_GetRGBFromString", FALSE);
2645
0
    VALIDATE_POINTER1(pnAlpha, "OGR_ST_GetRGBFromString", FALSE);
2646
2647
0
    return reinterpret_cast<OGRStyleTool *>(hST)->GetRGBFromString(
2648
0
        pszColor, *pnRed, *pnGreen, *pnBlue, *pnAlpha);
2649
0
}
2650
2651
//! @cond Doxygen_Suppress
2652
/* ======================================================================== */
2653
/*                OGRStylePen                                               */
2654
/*       Specific parameter (Set/Get) for the StylePen                      */
2655
/* ======================================================================== */
2656
2657
/****************************************************************************/
2658
/*                      OGRStylePen::OGRStylePen()                          */
2659
/*                                                                          */
2660
/****************************************************************************/
2661
OGRStylePen::OGRStylePen()
2662
0
    : OGRStyleTool(OGRSTCPen),
2663
0
      m_pasStyleValue(static_cast<OGRStyleValue *>(
2664
0
          CPLCalloc(OGRSTPenLast, sizeof(OGRStyleValue))))
2665
0
{
2666
0
}
2667
2668
/****************************************************************************/
2669
/*                      OGRStylePen::~OGRStylePen()                         */
2670
/*                                                                          */
2671
/****************************************************************************/
2672
OGRStylePen::~OGRStylePen()
2673
0
{
2674
0
    for (int i = 0; i < OGRSTPenLast; i++)
2675
0
    {
2676
0
        if (m_pasStyleValue[i].pszValue != nullptr)
2677
0
        {
2678
0
            CPLFree(m_pasStyleValue[i].pszValue);
2679
0
            m_pasStyleValue[i].pszValue = nullptr;
2680
0
        }
2681
0
    }
2682
2683
0
    CPLFree(m_pasStyleValue);
2684
0
}
2685
2686
/************************************************************************/
2687
/*                         OGRStylePen::Parse()                         */
2688
/************************************************************************/
2689
GBool OGRStylePen::Parse()
2690
2691
0
{
2692
0
    return OGRStyleTool::Parse(asStylePen, m_pasStyleValue,
2693
0
                               static_cast<int>(OGRSTPenLast));
2694
0
}
2695
2696
/************************************************************************/
2697
/*                            GetParamStr()                             */
2698
/************************************************************************/
2699
const char *OGRStylePen::GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull)
2700
0
{
2701
0
    return OGRStyleTool::GetParamStr(asStylePen[eParam],
2702
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2703
0
}
2704
2705
/************************************************************************/
2706
/*                            GetParamNum()                             */
2707
/************************************************************************/
2708
int OGRStylePen::GetParamNum(OGRSTPenParam eParam, GBool &bValueIsNull)
2709
0
{
2710
0
    return OGRStyleTool::GetParamNum(asStylePen[eParam],
2711
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2712
0
}
2713
2714
/************************************************************************/
2715
/*                            GetParamDbl()                             */
2716
/************************************************************************/
2717
double OGRStylePen::GetParamDbl(OGRSTPenParam eParam, GBool &bValueIsNull)
2718
0
{
2719
0
    return OGRStyleTool::GetParamDbl(asStylePen[eParam],
2720
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2721
0
}
2722
2723
/************************************************************************/
2724
/*                           GetRawParamDbl()                           */
2725
/************************************************************************/
2726
double OGRStylePen::GetRawParamDbl(OGRSTPenParam eParam, OGRSTUnitId &eRawUnit,
2727
                                   GBool &bValueIsNull)
2728
0
{
2729
0
    return OGRStyleTool::GetRawParamDbl(
2730
0
        asStylePen[eParam], m_pasStyleValue[eParam], eRawUnit, bValueIsNull);
2731
0
}
2732
2733
/************************************************************************/
2734
/*                            SetParamStr()                             */
2735
/************************************************************************/
2736
2737
void OGRStylePen::SetParamStr(OGRSTPenParam eParam, const char *pszParamString)
2738
0
{
2739
0
    OGRStyleTool::SetParamStr(asStylePen[eParam], m_pasStyleValue[eParam],
2740
0
                              pszParamString);
2741
0
}
2742
2743
/************************************************************************/
2744
/*                            SetParamNum()                             */
2745
/************************************************************************/
2746
void OGRStylePen::SetParamNum(OGRSTPenParam eParam, int nParam)
2747
0
{
2748
0
    OGRStyleTool::SetParamNum(asStylePen[eParam], m_pasStyleValue[eParam],
2749
0
                              nParam);
2750
0
}
2751
2752
/************************************************************************/
2753
/*                            SetParamDbl()                             */
2754
/************************************************************************/
2755
void OGRStylePen::SetParamDbl(OGRSTPenParam eParam, double dfParam)
2756
0
{
2757
0
    OGRStyleTool::SetParamDbl(asStylePen[eParam], m_pasStyleValue[eParam],
2758
0
                              dfParam);
2759
0
}
2760
2761
/************************************************************************/
2762
/*                           GetStyleString()                           */
2763
/************************************************************************/
2764
const char *OGRStylePen::GetStyleString()
2765
0
{
2766
0
    return OGRStyleTool::GetStyleString(asStylePen, m_pasStyleValue,
2767
0
                                        static_cast<int>(OGRSTPenLast));
2768
0
}
2769
2770
/****************************************************************************/
2771
/*                      OGRStyleBrush::OGRStyleBrush()                      */
2772
/*                                                                          */
2773
/****************************************************************************/
2774
OGRStyleBrush::OGRStyleBrush()
2775
0
    : OGRStyleTool(OGRSTCBrush),
2776
0
      m_pasStyleValue(static_cast<OGRStyleValue *>(
2777
0
          CPLCalloc(OGRSTBrushLast, sizeof(OGRStyleValue))))
2778
0
{
2779
0
}
2780
2781
/****************************************************************************/
2782
/*                      OGRStyleBrush::~OGRStyleBrush()                     */
2783
/*                                                                          */
2784
/****************************************************************************/
2785
OGRStyleBrush::~OGRStyleBrush()
2786
0
{
2787
0
    for (int i = 0; i < OGRSTBrushLast; i++)
2788
0
    {
2789
0
        if (m_pasStyleValue[i].pszValue != nullptr)
2790
0
        {
2791
0
            CPLFree(m_pasStyleValue[i].pszValue);
2792
0
            m_pasStyleValue[i].pszValue = nullptr;
2793
0
        }
2794
0
    }
2795
2796
0
    CPLFree(m_pasStyleValue);
2797
0
}
2798
2799
/************************************************************************/
2800
/*                               Parse()                                */
2801
/************************************************************************/
2802
GBool OGRStyleBrush::Parse()
2803
0
{
2804
0
    return OGRStyleTool::Parse(asStyleBrush, m_pasStyleValue,
2805
0
                               static_cast<int>(OGRSTBrushLast));
2806
0
}
2807
2808
/************************************************************************/
2809
/*                            GetParamStr()                             */
2810
/************************************************************************/
2811
const char *OGRStyleBrush::GetParamStr(OGRSTBrushParam eParam,
2812
                                       GBool &bValueIsNull)
2813
0
{
2814
0
    return OGRStyleTool::GetParamStr(asStyleBrush[eParam],
2815
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2816
0
}
2817
2818
/************************************************************************/
2819
/*                            GetParamNum()                             */
2820
/************************************************************************/
2821
int OGRStyleBrush::GetParamNum(OGRSTBrushParam eParam, GBool &bValueIsNull)
2822
0
{
2823
0
    return OGRStyleTool::GetParamNum(asStyleBrush[eParam],
2824
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2825
0
}
2826
2827
/************************************************************************/
2828
/*                            GetParamDbl()                             */
2829
/************************************************************************/
2830
double OGRStyleBrush::GetParamDbl(OGRSTBrushParam eParam, GBool &bValueIsNull)
2831
0
{
2832
0
    return OGRStyleTool::GetParamDbl(asStyleBrush[eParam],
2833
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2834
0
}
2835
2836
/************************************************************************/
2837
/*                            SetParamStr()                             */
2838
/************************************************************************/
2839
void OGRStyleBrush::SetParamStr(OGRSTBrushParam eParam,
2840
                                const char *pszParamString)
2841
0
{
2842
0
    OGRStyleTool::SetParamStr(asStyleBrush[eParam], m_pasStyleValue[eParam],
2843
0
                              pszParamString);
2844
0
}
2845
2846
/************************************************************************/
2847
/*                            SetParamNum()                             */
2848
/************************************************************************/
2849
void OGRStyleBrush::SetParamNum(OGRSTBrushParam eParam, int nParam)
2850
0
{
2851
0
    OGRStyleTool::SetParamNum(asStyleBrush[eParam], m_pasStyleValue[eParam],
2852
0
                              nParam);
2853
0
}
2854
2855
/************************************************************************/
2856
/*                            SetParamDbl()                             */
2857
/************************************************************************/
2858
void OGRStyleBrush::SetParamDbl(OGRSTBrushParam eParam, double dfParam)
2859
0
{
2860
0
    OGRStyleTool::SetParamDbl(asStyleBrush[eParam], m_pasStyleValue[eParam],
2861
0
                              dfParam);
2862
0
}
2863
2864
/************************************************************************/
2865
/*                           GetStyleString()                           */
2866
/************************************************************************/
2867
const char *OGRStyleBrush::GetStyleString()
2868
0
{
2869
0
    return OGRStyleTool::GetStyleString(asStyleBrush, m_pasStyleValue,
2870
0
                                        static_cast<int>(OGRSTBrushLast));
2871
0
}
2872
2873
/****************************************************************************/
2874
/*                      OGRStyleSymbol::OGRStyleSymbol()                    */
2875
/****************************************************************************/
2876
OGRStyleSymbol::OGRStyleSymbol()
2877
0
    : OGRStyleTool(OGRSTCSymbol),
2878
0
      m_pasStyleValue(static_cast<OGRStyleValue *>(
2879
0
          CPLCalloc(OGRSTSymbolLast, sizeof(OGRStyleValue))))
2880
0
{
2881
0
}
2882
2883
/****************************************************************************/
2884
/*                      OGRStyleSymbol::~OGRStyleSymbol()                   */
2885
/*                                                                          */
2886
/****************************************************************************/
2887
OGRStyleSymbol::~OGRStyleSymbol()
2888
0
{
2889
0
    for (int i = 0; i < OGRSTSymbolLast; i++)
2890
0
    {
2891
0
        if (m_pasStyleValue[i].pszValue != nullptr)
2892
0
        {
2893
0
            CPLFree(m_pasStyleValue[i].pszValue);
2894
0
            m_pasStyleValue[i].pszValue = nullptr;
2895
0
        }
2896
0
    }
2897
2898
0
    CPLFree(m_pasStyleValue);
2899
0
}
2900
2901
/************************************************************************/
2902
/*                               Parse()                                */
2903
/************************************************************************/
2904
GBool OGRStyleSymbol::Parse()
2905
0
{
2906
0
    return OGRStyleTool::Parse(asStyleSymbol, m_pasStyleValue,
2907
0
                               static_cast<int>(OGRSTSymbolLast));
2908
0
}
2909
2910
/************************************************************************/
2911
/*                            GetParamStr()                             */
2912
/************************************************************************/
2913
const char *OGRStyleSymbol::GetParamStr(OGRSTSymbolParam eParam,
2914
                                        GBool &bValueIsNull)
2915
0
{
2916
0
    return OGRStyleTool::GetParamStr(asStyleSymbol[eParam],
2917
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2918
0
}
2919
2920
/************************************************************************/
2921
/*                            GetParamNum()                             */
2922
/************************************************************************/
2923
int OGRStyleSymbol::GetParamNum(OGRSTSymbolParam eParam, GBool &bValueIsNull)
2924
0
{
2925
0
    return OGRStyleTool::GetParamNum(asStyleSymbol[eParam],
2926
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2927
0
}
2928
2929
/************************************************************************/
2930
/*                            GetParamDbl()                             */
2931
/************************************************************************/
2932
double OGRStyleSymbol::GetParamDbl(OGRSTSymbolParam eParam, GBool &bValueIsNull)
2933
0
{
2934
0
    return OGRStyleTool::GetParamDbl(asStyleSymbol[eParam],
2935
0
                                     m_pasStyleValue[eParam], bValueIsNull);
2936
0
}
2937
2938
/************************************************************************/
2939
/*                            SetParamStr()                             */
2940
/************************************************************************/
2941
void OGRStyleSymbol::SetParamStr(OGRSTSymbolParam eParam,
2942
                                 const char *pszParamString)
2943
0
{
2944
0
    OGRStyleTool::SetParamStr(asStyleSymbol[eParam], m_pasStyleValue[eParam],
2945
0
                              pszParamString);
2946
0
}
2947
2948
/************************************************************************/
2949
/*                            SetParamNum()                             */
2950
/************************************************************************/
2951
void OGRStyleSymbol::SetParamNum(OGRSTSymbolParam eParam, int nParam)
2952
0
{
2953
0
    OGRStyleTool::SetParamNum(asStyleSymbol[eParam], m_pasStyleValue[eParam],
2954
0
                              nParam);
2955
0
}
2956
2957
/************************************************************************/
2958
/*                            SetParamDbl()                             */
2959
/************************************************************************/
2960
void OGRStyleSymbol::SetParamDbl(OGRSTSymbolParam eParam, double dfParam)
2961
0
{
2962
0
    OGRStyleTool::SetParamDbl(asStyleSymbol[eParam], m_pasStyleValue[eParam],
2963
0
                              dfParam);
2964
0
}
2965
2966
/************************************************************************/
2967
/*                           GetStyleString()                           */
2968
/************************************************************************/
2969
const char *OGRStyleSymbol::GetStyleString()
2970
0
{
2971
0
    return OGRStyleTool::GetStyleString(asStyleSymbol, m_pasStyleValue,
2972
0
                                        static_cast<int>(OGRSTSymbolLast));
2973
0
}
2974
2975
/****************************************************************************/
2976
/*                      OGRStyleLabel::OGRStyleLabel()                      */
2977
/*                                                                          */
2978
/****************************************************************************/
2979
OGRStyleLabel::OGRStyleLabel()
2980
0
    : OGRStyleTool(OGRSTCLabel),
2981
0
      m_pasStyleValue(static_cast<OGRStyleValue *>(
2982
0
          CPLCalloc(OGRSTLabelLast, sizeof(OGRStyleValue))))
2983
0
{
2984
0
}
2985
2986
/****************************************************************************/
2987
/*                      OGRStyleLabel::~OGRStyleLabel()                     */
2988
/*                                                                          */
2989
/****************************************************************************/
2990
OGRStyleLabel::~OGRStyleLabel()
2991
0
{
2992
0
    for (int i = 0; i < OGRSTLabelLast; i++)
2993
0
    {
2994
0
        if (m_pasStyleValue[i].pszValue != nullptr)
2995
0
        {
2996
0
            CPLFree(m_pasStyleValue[i].pszValue);
2997
0
            m_pasStyleValue[i].pszValue = nullptr;
2998
0
        }
2999
0
    }
3000
3001
0
    CPLFree(m_pasStyleValue);
3002
0
}
3003
3004
/************************************************************************/
3005
/*                               Parse()                                */
3006
/************************************************************************/
3007
GBool OGRStyleLabel::Parse()
3008
0
{
3009
0
    return OGRStyleTool::Parse(asStyleLabel, m_pasStyleValue,
3010
0
                               static_cast<int>(OGRSTLabelLast));
3011
0
}
3012
3013
/************************************************************************/
3014
/*                            GetParamStr()                             */
3015
/************************************************************************/
3016
const char *OGRStyleLabel::GetParamStr(OGRSTLabelParam eParam,
3017
                                       GBool &bValueIsNull)
3018
0
{
3019
0
    return OGRStyleTool::GetParamStr(asStyleLabel[eParam],
3020
0
                                     m_pasStyleValue[eParam], bValueIsNull);
3021
0
}
3022
3023
/************************************************************************/
3024
/*                            GetParamNum()                             */
3025
/************************************************************************/
3026
int OGRStyleLabel::GetParamNum(OGRSTLabelParam eParam, GBool &bValueIsNull)
3027
0
{
3028
0
    return OGRStyleTool::GetParamNum(asStyleLabel[eParam],
3029
0
                                     m_pasStyleValue[eParam], bValueIsNull);
3030
0
}
3031
3032
/************************************************************************/
3033
/*                            GetParamDbl()                             */
3034
/************************************************************************/
3035
double OGRStyleLabel::GetParamDbl(OGRSTLabelParam eParam, GBool &bValueIsNull)
3036
0
{
3037
0
    return OGRStyleTool::GetParamDbl(asStyleLabel[eParam],
3038
0
                                     m_pasStyleValue[eParam], bValueIsNull);
3039
0
}
3040
3041
/************************************************************************/
3042
/*                            SetParamStr()                             */
3043
/************************************************************************/
3044
void OGRStyleLabel::SetParamStr(OGRSTLabelParam eParam,
3045
                                const char *pszParamString)
3046
0
{
3047
0
    OGRStyleTool::SetParamStr(asStyleLabel[eParam], m_pasStyleValue[eParam],
3048
0
                              pszParamString);
3049
0
}
3050
3051
/************************************************************************/
3052
/*                            SetParamNum()                             */
3053
/************************************************************************/
3054
void OGRStyleLabel::SetParamNum(OGRSTLabelParam eParam, int nParam)
3055
0
{
3056
0
    OGRStyleTool::SetParamNum(asStyleLabel[eParam], m_pasStyleValue[eParam],
3057
0
                              nParam);
3058
0
}
3059
3060
/************************************************************************/
3061
/*                            SetParamDbl()                             */
3062
/************************************************************************/
3063
void OGRStyleLabel::SetParamDbl(OGRSTLabelParam eParam, double dfParam)
3064
0
{
3065
0
    OGRStyleTool::SetParamDbl(asStyleLabel[eParam], m_pasStyleValue[eParam],
3066
0
                              dfParam);
3067
0
}
3068
3069
/************************************************************************/
3070
/*                           GetStyleString()                           */
3071
/************************************************************************/
3072
const char *OGRStyleLabel::GetStyleString()
3073
0
{
3074
0
    return OGRStyleTool::GetStyleString(asStyleLabel, m_pasStyleValue,
3075
0
                                        static_cast<int>(OGRSTLabelLast));
3076
0
}
3077
3078
//! @endcond