/
text_symbolizer.cpp
459 lines (367 loc) · 11.2 KB
/
text_symbolizer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id$
//mapnik
#include <mapnik/text_symbolizer.hpp>
// boost
#include <boost/scoped_ptr.hpp>
#include <mapnik/text_processing.hpp>
namespace mapnik
{
static const char * label_placement_strings[] = {
"point",
"line",
"vertex",
"interior",
""
};
IMPLEMENT_ENUM( label_placement_e, label_placement_strings )
static const char * vertical_alignment_strings[] = {
"top",
"middle",
"bottom",
"auto",
""
};
IMPLEMENT_ENUM( vertical_alignment_e, vertical_alignment_strings )
static const char * horizontal_alignment_strings[] = {
"left",
"middle",
"right",
"auto",
""
};
IMPLEMENT_ENUM( horizontal_alignment_e, horizontal_alignment_strings )
static const char * justify_alignment_strings[] = {
"left",
"center",
"right",
""
};
IMPLEMENT_ENUM( justify_alignment_e, justify_alignment_strings )
static const char * text_transform_strings[] = {
"none",
"uppercase",
"lowercase",
"capitalize",
""
};
IMPLEMENT_ENUM( text_transform_e, text_transform_strings )
text_symbolizer::text_symbolizer(text_placements_ptr placements)
: symbolizer_base(),
placement_options_(placements)
{
}
text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_name,
float size, color const& fill,
text_placements_ptr placements)
: symbolizer_base(),
placement_options_(placements)
{
set_name(name);
set_face_name(face_name);
set_text_size(size);
set_fill(fill);
}
text_symbolizer::text_symbolizer(expression_ptr name, float size, color const& fill,
text_placements_ptr placements)
: symbolizer_base(),
placement_options_(placements)
{
set_name(name);
set_text_size(size);
set_fill(fill);
}
text_symbolizer::text_symbolizer(text_symbolizer const& rhs)
: symbolizer_base(rhs),
placement_options_(rhs.placement_options_) /*TODO: Copy options! */
{
}
text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other)
{
if (this == &other)
return *this;
placement_options_ = other.placement_options_; /*TODO: Copy options? */
std::clog << "TODO: Metawriter (text_symbolizer::operator=)\n";
return *this;
}
expression_ptr text_symbolizer::get_name() const
{
return expression_ptr();
}
void text_symbolizer::set_name(expression_ptr name)
{
placement_options_->properties.set_old_style_expression(name);
}
expression_ptr text_symbolizer::get_orientation() const
{
return placement_options_->properties.orientation;
}
void text_symbolizer::set_orientation(expression_ptr orientation)
{
placement_options_->properties.orientation = orientation;
}
std::string const& text_symbolizer::get_face_name() const
{
return placement_options_->properties.default_format.face_name;
}
void text_symbolizer::set_face_name(std::string face_name)
{
placement_options_->properties.default_format.face_name = face_name;
}
void text_symbolizer::set_fontset(font_set const& fontset)
{
placement_options_->properties.default_format.fontset = fontset;
}
font_set const& text_symbolizer::get_fontset() const
{
return placement_options_->properties.default_format.fontset;
}
unsigned text_symbolizer::get_text_ratio() const
{
return placement_options_->properties.text_ratio;
}
void text_symbolizer::set_text_ratio(unsigned ratio)
{
placement_options_->properties.text_ratio = ratio;
}
unsigned text_symbolizer::get_wrap_width() const
{
return placement_options_->properties.wrap_width;
}
void text_symbolizer::set_wrap_width(unsigned width)
{
placement_options_->properties.wrap_width = width;
}
bool text_symbolizer::get_wrap_before() const
{
return placement_options_->properties.default_format.wrap_before;
}
void text_symbolizer::set_wrap_before(bool wrap_before)
{
placement_options_->properties.default_format.wrap_before = wrap_before;
}
unsigned char text_symbolizer::get_wrap_char() const
{
return placement_options_->properties.default_format.wrap_char;
}
std::string text_symbolizer::get_wrap_char_string() const
{
return std::string(1, placement_options_->properties.default_format.wrap_char);
}
void text_symbolizer::set_wrap_char(unsigned char character)
{
placement_options_->properties.default_format.wrap_char = character;
}
void text_symbolizer::set_wrap_char_from_string(std::string const& character)
{
placement_options_->properties.default_format.wrap_char = (character)[0];
}
text_transform_e text_symbolizer::get_text_transform() const
{
return placement_options_->properties.default_format.text_transform;
}
void text_symbolizer::set_text_transform(text_transform_e convert)
{
placement_options_->properties.default_format.text_transform = convert;
}
unsigned text_symbolizer::get_line_spacing() const
{
return placement_options_->properties.default_format.line_spacing;
}
void text_symbolizer::set_line_spacing(unsigned spacing)
{
placement_options_->properties.default_format.line_spacing = spacing;
}
unsigned text_symbolizer::get_character_spacing() const
{
return placement_options_->properties.default_format.character_spacing;
}
void text_symbolizer::set_character_spacing(unsigned spacing)
{
placement_options_->properties.default_format.character_spacing = spacing;
}
unsigned text_symbolizer::get_label_spacing() const
{
return placement_options_->properties.label_spacing;
}
void text_symbolizer::set_label_spacing(unsigned spacing)
{
placement_options_->properties.label_spacing = spacing;
}
unsigned text_symbolizer::get_label_position_tolerance() const
{
return placement_options_->properties.label_position_tolerance;
}
void text_symbolizer::set_label_position_tolerance(unsigned tolerance)
{
placement_options_->properties.label_position_tolerance = tolerance;
}
bool text_symbolizer::get_force_odd_labels() const
{
return placement_options_->properties.force_odd_labels;
}
void text_symbolizer::set_force_odd_labels(bool force)
{
placement_options_->properties.force_odd_labels = force;
}
double text_symbolizer::get_max_char_angle_delta() const
{
return placement_options_->properties.max_char_angle_delta;
}
void text_symbolizer::set_max_char_angle_delta(double angle)
{
placement_options_->properties.max_char_angle_delta = angle;
}
void text_symbolizer::set_text_size(float size)
{
placement_options_->properties.default_format.text_size = size;
}
float text_symbolizer::get_text_size() const
{
return placement_options_->properties.default_format.text_size;
}
void text_symbolizer::set_fill(color const& fill)
{
placement_options_->properties.default_format.fill = fill;
}
color const& text_symbolizer::get_fill() const
{
return placement_options_->properties.default_format.fill;
}
void text_symbolizer::set_halo_fill(color const& fill)
{
placement_options_->properties.default_format.halo_fill = fill;
}
color const& text_symbolizer::get_halo_fill() const
{
return placement_options_->properties.default_format.halo_fill;
}
void text_symbolizer::set_halo_radius(double radius)
{
placement_options_->properties.default_format.halo_radius = radius;
}
double text_symbolizer::get_halo_radius() const
{
return placement_options_->properties.default_format.halo_radius;
}
void text_symbolizer::set_label_placement(label_placement_e label_p)
{
placement_options_->properties.label_placement = label_p;
}
label_placement_e text_symbolizer::get_label_placement() const
{
return placement_options_->properties.label_placement;
}
void text_symbolizer::set_displacement(double x, double y)
{
placement_options_->properties.displacement = std::make_pair(x,y);
}
void text_symbolizer::set_displacement(position const& p)
{
placement_options_->properties.displacement = p;
}
position const& text_symbolizer::get_displacement() const
{
return placement_options_->properties.displacement;
}
bool text_symbolizer::get_avoid_edges() const
{
return placement_options_->properties.avoid_edges;
}
void text_symbolizer::set_avoid_edges(bool avoid)
{
placement_options_->properties.avoid_edges = avoid;
}
double text_symbolizer::get_minimum_distance() const
{
return placement_options_->properties.minimum_distance;
}
void text_symbolizer::set_minimum_distance(double distance)
{
placement_options_->properties.minimum_distance = distance;
}
double text_symbolizer::get_minimum_padding() const
{
return placement_options_->properties.minimum_padding;
}
void text_symbolizer::set_minimum_padding(double distance)
{
placement_options_->properties.minimum_padding = distance;
}
double text_symbolizer::get_minimum_path_length() const
{
return placement_options_->properties.minimum_path_length;
}
void text_symbolizer::set_minimum_path_length(double size)
{
placement_options_->properties.minimum_path_length = size;
}
void text_symbolizer::set_allow_overlap(bool overlap)
{
placement_options_->properties.allow_overlap = overlap;
}
bool text_symbolizer::get_allow_overlap() const
{
return placement_options_->properties.allow_overlap;
}
void text_symbolizer::set_text_opacity(double text_opacity)
{
placement_options_->properties.default_format.text_opacity = text_opacity;
}
double text_symbolizer::get_text_opacity() const
{
return placement_options_->properties.default_format.text_opacity;
}
void text_symbolizer::set_vertical_alignment(vertical_alignment_e valign)
{
placement_options_->properties.valign = valign;
}
vertical_alignment_e text_symbolizer::get_vertical_alignment() const
{
return placement_options_->properties.valign;
}
void text_symbolizer::set_horizontal_alignment(horizontal_alignment_e halign)
{
placement_options_->properties.halign = halign;
}
horizontal_alignment_e text_symbolizer::get_horizontal_alignment() const
{
return placement_options_->properties.halign;
}
void text_symbolizer::set_justify_alignment(justify_alignment_e jalign)
{
placement_options_->properties.jalign = jalign;
}
justify_alignment_e text_symbolizer::get_justify_alignment() const
{
return placement_options_->properties.jalign;
}
text_placements_ptr text_symbolizer::get_placement_options() const
{
return placement_options_;
}
void text_symbolizer::set_placement_options(text_placements_ptr placement_options)
{
placement_options_ = placement_options;
}
}