/src/libxlsxwriter/src/format.c
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * format - A library for creating Excel XLSX format files. |
3 | | * |
4 | | * Used in conjunction with the libxlsxwriter library. |
5 | | * |
6 | | * SPDX-License-Identifier: BSD-2-Clause |
7 | | * Copyright 2014-2025, John McNamara, jmcnamara@cpan.org. |
8 | | * |
9 | | */ |
10 | | |
11 | | #include "xlsxwriter/xmlwriter.h" |
12 | | #include "xlsxwriter/format.h" |
13 | | #include "xlsxwriter/utility.h" |
14 | | |
15 | | /***************************************************************************** |
16 | | * |
17 | | * Private functions. |
18 | | * |
19 | | ****************************************************************************/ |
20 | | |
21 | | /* |
22 | | * Create a new format object. |
23 | | */ |
24 | | lxw_format * |
25 | | lxw_format_new(void) |
26 | 4.11k | { |
27 | 4.11k | lxw_format *format = calloc(1, sizeof(lxw_format)); |
28 | 4.11k | GOTO_LABEL_ON_MEM_ERROR(format, mem_error); |
29 | | |
30 | 4.11k | format->xf_format_indices = NULL; |
31 | 4.11k | format->dxf_format_indices = NULL; |
32 | | |
33 | 4.11k | format->xf_index = LXW_PROPERTY_UNSET; |
34 | 4.11k | format->dxf_index = LXW_PROPERTY_UNSET; |
35 | 4.11k | format->xf_id = 0; |
36 | | |
37 | 4.11k | format->font_name[0] = '\0'; |
38 | 4.11k | format->font_scheme[0] = '\0'; |
39 | 4.11k | format->num_format[0] = '\0'; |
40 | 4.11k | format->num_format_index = 0; |
41 | 4.11k | format->font_index = 0; |
42 | 4.11k | format->has_font = LXW_FALSE; |
43 | 4.11k | format->has_dxf_font = LXW_FALSE; |
44 | 4.11k | format->font_size = 11.0; |
45 | 4.11k | format->bold = LXW_FALSE; |
46 | 4.11k | format->italic = LXW_FALSE; |
47 | 4.11k | format->font_color = LXW_COLOR_UNSET; |
48 | 4.11k | format->underline = LXW_UNDERLINE_NONE; |
49 | 4.11k | format->font_strikeout = LXW_FALSE; |
50 | 4.11k | format->font_outline = LXW_FALSE; |
51 | 4.11k | format->font_shadow = LXW_FALSE; |
52 | 4.11k | format->font_script = LXW_FALSE; |
53 | 4.11k | format->font_family = LXW_DEFAULT_FONT_FAMILY; |
54 | 4.11k | format->font_charset = LXW_FALSE; |
55 | 4.11k | format->font_condense = LXW_FALSE; |
56 | 4.11k | format->font_extend = LXW_FALSE; |
57 | 4.11k | format->theme = 0; |
58 | 4.11k | format->hyperlink = LXW_FALSE; |
59 | | |
60 | 4.11k | format->hidden = LXW_FALSE; |
61 | 4.11k | format->locked = LXW_TRUE; |
62 | | |
63 | 4.11k | format->text_h_align = LXW_ALIGN_NONE; |
64 | 4.11k | format->text_wrap = LXW_FALSE; |
65 | 4.11k | format->text_v_align = LXW_ALIGN_NONE; |
66 | 4.11k | format->text_justlast = LXW_FALSE; |
67 | 4.11k | format->rotation = 0; |
68 | | |
69 | 4.11k | format->fg_color = LXW_COLOR_UNSET; |
70 | 4.11k | format->bg_color = LXW_COLOR_UNSET; |
71 | 4.11k | format->pattern = LXW_PATTERN_NONE; |
72 | 4.11k | format->has_fill = LXW_FALSE; |
73 | 4.11k | format->has_dxf_fill = LXW_FALSE; |
74 | 4.11k | format->fill_index = 0; |
75 | 4.11k | format->fill_count = 0; |
76 | | |
77 | 4.11k | format->border_index = 0; |
78 | 4.11k | format->has_border = LXW_FALSE; |
79 | 4.11k | format->has_dxf_border = LXW_FALSE; |
80 | 4.11k | format->border_count = 0; |
81 | | |
82 | 4.11k | format->bottom = LXW_BORDER_NONE; |
83 | 4.11k | format->left = LXW_BORDER_NONE; |
84 | 4.11k | format->right = LXW_BORDER_NONE; |
85 | 4.11k | format->top = LXW_BORDER_NONE; |
86 | 4.11k | format->diag_border = LXW_BORDER_NONE; |
87 | 4.11k | format->diag_type = LXW_BORDER_NONE; |
88 | 4.11k | format->bottom_color = LXW_COLOR_UNSET; |
89 | 4.11k | format->left_color = LXW_COLOR_UNSET; |
90 | 4.11k | format->right_color = LXW_COLOR_UNSET; |
91 | 4.11k | format->top_color = LXW_COLOR_UNSET; |
92 | 4.11k | format->diag_color = LXW_COLOR_UNSET; |
93 | | |
94 | 4.11k | format->indent = 0; |
95 | 4.11k | format->shrink = LXW_FALSE; |
96 | 4.11k | format->merge_range = LXW_FALSE; |
97 | 4.11k | format->reading_order = 0; |
98 | 4.11k | format->just_distrib = LXW_FALSE; |
99 | 4.11k | format->color_indexed = LXW_FALSE; |
100 | 4.11k | format->font_only = LXW_FALSE; |
101 | | |
102 | 4.11k | format->quote_prefix = LXW_FALSE; |
103 | | |
104 | 4.11k | return format; |
105 | | |
106 | 0 | mem_error: |
107 | 0 | lxw_format_free(format); |
108 | 0 | return NULL; |
109 | 4.11k | } |
110 | | |
111 | | /* |
112 | | * Free a format object. |
113 | | */ |
114 | | void |
115 | | lxw_format_free(lxw_format *format) |
116 | 2.74k | { |
117 | 2.74k | if (!format) |
118 | 0 | return; |
119 | | |
120 | 2.74k | free(format); |
121 | 2.74k | format = NULL; |
122 | 2.74k | } |
123 | | |
124 | | /* |
125 | | * Check a user input border. |
126 | | */ |
127 | | STATIC uint8_t |
128 | | _check_border(uint8_t border) |
129 | 0 | { |
130 | 0 | if (border >= LXW_BORDER_THIN && border <= LXW_BORDER_SLANT_DASH_DOT) |
131 | 0 | return border; |
132 | 0 | else |
133 | 0 | return LXW_BORDER_NONE; |
134 | 0 | } |
135 | | |
136 | | /***************************************************************************** |
137 | | * |
138 | | * Public functions. |
139 | | * |
140 | | ****************************************************************************/ |
141 | | |
142 | | /* |
143 | | * Returns a format struct suitable for hashing as a lookup key. This is |
144 | | * mainly a memcpy with any pointer members set to NULL. |
145 | | */ |
146 | | STATIC lxw_format * |
147 | | _get_format_key(lxw_format *self) |
148 | 1.37k | { |
149 | 1.37k | lxw_format *key = calloc(1, sizeof(lxw_format)); |
150 | 1.37k | GOTO_LABEL_ON_MEM_ERROR(key, mem_error); |
151 | | |
152 | 1.37k | memcpy(key, self, sizeof(lxw_format)); |
153 | | |
154 | | /* Set pointer members to NULL since they aren't part of the comparison. */ |
155 | 1.37k | key->xf_format_indices = NULL; |
156 | 1.37k | key->dxf_format_indices = NULL; |
157 | 1.37k | key->num_xf_formats = NULL; |
158 | 1.37k | key->num_dxf_formats = NULL; |
159 | 1.37k | key->list_pointers.stqe_next = NULL; |
160 | | |
161 | 1.37k | return key; |
162 | | |
163 | 0 | mem_error: |
164 | 0 | return NULL; |
165 | 1.37k | } |
166 | | |
167 | | /* |
168 | | * Returns a font struct suitable for hashing as a lookup key. |
169 | | */ |
170 | | lxw_font * |
171 | | lxw_format_get_font_key(lxw_format *self) |
172 | 1.37k | { |
173 | 1.37k | lxw_font *key = calloc(1, sizeof(lxw_font)); |
174 | 1.37k | GOTO_LABEL_ON_MEM_ERROR(key, mem_error); |
175 | | |
176 | 1.37k | LXW_FORMAT_FIELD_COPY(key->font_name, self->font_name); |
177 | 1.37k | key->font_size = self->font_size; |
178 | 1.37k | key->bold = self->bold; |
179 | 1.37k | key->italic = self->italic; |
180 | 1.37k | key->underline = self->underline; |
181 | 1.37k | key->theme = self->theme; |
182 | 1.37k | key->font_color = self->font_color; |
183 | 1.37k | key->font_strikeout = self->font_strikeout; |
184 | 1.37k | key->font_outline = self->font_outline; |
185 | 1.37k | key->font_shadow = self->font_shadow; |
186 | 1.37k | key->font_script = self->font_script; |
187 | 1.37k | key->font_family = self->font_family; |
188 | 1.37k | key->font_charset = self->font_charset; |
189 | 1.37k | key->font_condense = self->font_condense; |
190 | 1.37k | key->font_extend = self->font_extend; |
191 | | |
192 | 1.37k | return key; |
193 | | |
194 | 0 | mem_error: |
195 | 0 | return NULL; |
196 | 1.37k | } |
197 | | |
198 | | /* |
199 | | * Returns a border struct suitable for hashing as a lookup key. |
200 | | */ |
201 | | lxw_border * |
202 | | lxw_format_get_border_key(lxw_format *self) |
203 | 1.37k | { |
204 | 1.37k | lxw_border *key = calloc(1, sizeof(lxw_border)); |
205 | 1.37k | GOTO_LABEL_ON_MEM_ERROR(key, mem_error); |
206 | | |
207 | 1.37k | key->bottom = self->bottom; |
208 | 1.37k | key->left = self->left; |
209 | 1.37k | key->right = self->right; |
210 | 1.37k | key->top = self->top; |
211 | 1.37k | key->diag_border = self->diag_border; |
212 | 1.37k | key->diag_type = self->diag_type; |
213 | 1.37k | key->bottom_color = self->bottom_color; |
214 | 1.37k | key->left_color = self->left_color; |
215 | 1.37k | key->right_color = self->right_color; |
216 | 1.37k | key->top_color = self->top_color; |
217 | 1.37k | key->diag_color = self->diag_color; |
218 | | |
219 | 1.37k | return key; |
220 | | |
221 | 0 | mem_error: |
222 | 0 | return NULL; |
223 | 1.37k | } |
224 | | |
225 | | /* |
226 | | * Returns a pattern fill struct suitable for hashing as a lookup key. |
227 | | */ |
228 | | lxw_fill * |
229 | | lxw_format_get_fill_key(lxw_format *self) |
230 | 1.37k | { |
231 | 1.37k | lxw_fill *key = calloc(1, sizeof(lxw_fill)); |
232 | 1.37k | GOTO_LABEL_ON_MEM_ERROR(key, mem_error); |
233 | | |
234 | 1.37k | key->fg_color = self->fg_color; |
235 | 1.37k | key->bg_color = self->bg_color; |
236 | 1.37k | key->pattern = self->pattern; |
237 | | |
238 | 1.37k | return key; |
239 | | |
240 | 0 | mem_error: |
241 | 0 | return NULL; |
242 | 1.37k | } |
243 | | |
244 | | /* |
245 | | * Returns the XF index number used by Excel to identify a format. |
246 | | */ |
247 | | int32_t |
248 | | lxw_format_get_xf_index(lxw_format *self) |
249 | 1.37k | { |
250 | 1.37k | lxw_format *format_key; |
251 | 1.37k | lxw_format *existing_format; |
252 | 1.37k | lxw_hash_element *hash_element; |
253 | 1.37k | lxw_hash_table *formats_hash_table = self->xf_format_indices; |
254 | 1.37k | int32_t index; |
255 | | |
256 | | /* Note: The formats_hash_table/xf_format_indices contains the unique and |
257 | | * more importantly the *used* formats in the workbook. |
258 | | */ |
259 | | |
260 | | /* Format already has an index number so return it. */ |
261 | 1.37k | if (self->xf_index != LXW_PROPERTY_UNSET) { |
262 | 0 | return self->xf_index; |
263 | 0 | } |
264 | | |
265 | | /* Otherwise, the format doesn't have an index number so we assign one. |
266 | | * First generate a unique key to identify the format in the hash table. |
267 | | */ |
268 | 1.37k | format_key = _get_format_key(self); |
269 | | |
270 | | /* Return the default format index if the key generation failed. */ |
271 | 1.37k | if (!format_key) |
272 | 0 | return 0; |
273 | | |
274 | | /* Look up the format in the hash table. */ |
275 | 1.37k | hash_element = |
276 | 1.37k | lxw_hash_key_exists(formats_hash_table, format_key, |
277 | 1.37k | sizeof(lxw_format)); |
278 | | |
279 | 1.37k | if (hash_element) { |
280 | | /* Format matches existing format with an index. */ |
281 | 0 | free(format_key); |
282 | 0 | existing_format = hash_element->value; |
283 | 0 | return existing_format->xf_index; |
284 | 0 | } |
285 | 1.37k | else { |
286 | | /* New format requiring an index. */ |
287 | 1.37k | index = formats_hash_table->unique_count; |
288 | 1.37k | self->xf_index = index; |
289 | 1.37k | lxw_insert_hash_element(formats_hash_table, format_key, self, |
290 | 1.37k | sizeof(lxw_format)); |
291 | 1.37k | return index; |
292 | 1.37k | } |
293 | 1.37k | } |
294 | | |
295 | | /* |
296 | | * Returns the DXF index number used by Excel to identify a format. |
297 | | */ |
298 | | int32_t |
299 | | lxw_format_get_dxf_index(lxw_format *self) |
300 | 0 | { |
301 | 0 | lxw_format *format_key; |
302 | 0 | lxw_format *existing_format; |
303 | 0 | lxw_hash_element *hash_element; |
304 | 0 | lxw_hash_table *formats_hash_table = self->dxf_format_indices; |
305 | 0 | int32_t index; |
306 | | |
307 | | /* Note: The formats_hash_table/dxf_format_indices contains the unique and |
308 | | * more importantly the *used* formats in the workbook. |
309 | | */ |
310 | | |
311 | | /* Format already has an index number so return it. */ |
312 | 0 | if (self->dxf_index != LXW_PROPERTY_UNSET) { |
313 | 0 | return self->dxf_index; |
314 | 0 | } |
315 | | |
316 | | /* Otherwise, the format doesn't have an index number so we assign one. |
317 | | * First generate a unique key to identify the format in the hash table. |
318 | | */ |
319 | 0 | format_key = _get_format_key(self); |
320 | | |
321 | | /* Return the default format index if the key generation failed. */ |
322 | 0 | if (!format_key) |
323 | 0 | return 0; |
324 | | |
325 | | /* Look up the format in the hash table. */ |
326 | 0 | hash_element = |
327 | 0 | lxw_hash_key_exists(formats_hash_table, format_key, |
328 | 0 | sizeof(lxw_format)); |
329 | |
|
330 | 0 | if (hash_element) { |
331 | | /* Format matches existing format with an index. */ |
332 | 0 | free(format_key); |
333 | 0 | existing_format = hash_element->value; |
334 | 0 | return existing_format->dxf_index; |
335 | 0 | } |
336 | 0 | else { |
337 | | /* New format requiring an index. */ |
338 | 0 | index = formats_hash_table->unique_count; |
339 | 0 | self->dxf_index = index; |
340 | 0 | lxw_insert_hash_element(formats_hash_table, format_key, self, |
341 | 0 | sizeof(lxw_format)); |
342 | 0 | return index; |
343 | 0 | } |
344 | 0 | } |
345 | | |
346 | | /* |
347 | | * Set the font_name property. |
348 | | */ |
349 | | void |
350 | | format_set_font_name(lxw_format *self, const char *font_name) |
351 | 0 | { |
352 | 0 | LXW_FORMAT_FIELD_COPY(self->font_name, font_name); |
353 | 0 | } |
354 | | |
355 | | /* |
356 | | * Set the font_size property. |
357 | | */ |
358 | | void |
359 | | format_set_font_size(lxw_format *self, double size) |
360 | 0 | { |
361 | |
|
362 | 0 | if (size >= LXW_MIN_FONT_SIZE && size <= LXW_MAX_FONT_SIZE) |
363 | 0 | self->font_size = size; |
364 | 0 | } |
365 | | |
366 | | /* |
367 | | * Set the font_color property. |
368 | | */ |
369 | | void |
370 | | format_set_font_color(lxw_format *self, lxw_color_t color) |
371 | 0 | { |
372 | 0 | self->font_color = color; |
373 | 0 | } |
374 | | |
375 | | /* |
376 | | * Set the bold property. |
377 | | */ |
378 | | void |
379 | | format_set_bold(lxw_format *self) |
380 | 0 | { |
381 | 0 | self->bold = LXW_TRUE; |
382 | 0 | } |
383 | | |
384 | | /* |
385 | | * Set the italic property. |
386 | | */ |
387 | | |
388 | | void |
389 | | format_set_italic(lxw_format *self) |
390 | 0 | { |
391 | 0 | self->italic = LXW_TRUE; |
392 | 0 | } |
393 | | |
394 | | /* |
395 | | * Set the underline property. |
396 | | */ |
397 | | void |
398 | | format_set_underline(lxw_format *self, uint8_t style) |
399 | 0 | { |
400 | 0 | if (style >= LXW_UNDERLINE_SINGLE |
401 | 0 | && style <= LXW_UNDERLINE_DOUBLE_ACCOUNTING) |
402 | 0 | self->underline = style; |
403 | 0 | } |
404 | | |
405 | | /* |
406 | | * Set the font_strikeout property. |
407 | | */ |
408 | | void |
409 | | format_set_font_strikeout(lxw_format *self) |
410 | 0 | { |
411 | 0 | self->font_strikeout = LXW_TRUE; |
412 | 0 | } |
413 | | |
414 | | /* |
415 | | * Set the font_script property. |
416 | | */ |
417 | | void |
418 | | format_set_font_script(lxw_format *self, uint8_t style) |
419 | 0 | { |
420 | 0 | if (style >= LXW_FONT_SUPERSCRIPT && style <= LXW_FONT_SUBSCRIPT) |
421 | 0 | self->font_script = style; |
422 | 0 | } |
423 | | |
424 | | /* |
425 | | * Set the font_outline property. |
426 | | */ |
427 | | void |
428 | | format_set_font_outline(lxw_format *self) |
429 | 0 | { |
430 | 0 | self->font_outline = LXW_TRUE; |
431 | 0 | } |
432 | | |
433 | | /* |
434 | | * Set the font_shadow property. |
435 | | */ |
436 | | void |
437 | | format_set_font_shadow(lxw_format *self) |
438 | 0 | { |
439 | 0 | self->font_shadow = LXW_TRUE; |
440 | 0 | } |
441 | | |
442 | | /* |
443 | | * Set the num_format property. |
444 | | */ |
445 | | void |
446 | | format_set_num_format(lxw_format *self, const char *num_format) |
447 | 0 | { |
448 | 0 | LXW_FORMAT_FIELD_COPY(self->num_format, num_format); |
449 | 0 | } |
450 | | |
451 | | /* |
452 | | * Set the unlocked property. |
453 | | */ |
454 | | void |
455 | | format_set_unlocked(lxw_format *self) |
456 | 0 | { |
457 | 0 | self->locked = LXW_FALSE; |
458 | 0 | } |
459 | | |
460 | | /* |
461 | | * Set the hidden property. |
462 | | */ |
463 | | void |
464 | | format_set_hidden(lxw_format *self) |
465 | 0 | { |
466 | 0 | self->hidden = LXW_TRUE; |
467 | 0 | } |
468 | | |
469 | | /* |
470 | | * Set the align property. |
471 | | */ |
472 | | void |
473 | | format_set_align(lxw_format *self, uint8_t value) |
474 | 0 | { |
475 | 0 | if (value >= LXW_ALIGN_LEFT && value <= LXW_ALIGN_DISTRIBUTED) { |
476 | 0 | self->text_h_align = value; |
477 | 0 | } |
478 | |
|
479 | 0 | if (value >= LXW_ALIGN_VERTICAL_TOP |
480 | 0 | && value <= LXW_ALIGN_VERTICAL_DISTRIBUTED) { |
481 | 0 | self->text_v_align = value; |
482 | 0 | } |
483 | 0 | } |
484 | | |
485 | | /* |
486 | | * Set the text_wrap property. |
487 | | */ |
488 | | void |
489 | | format_set_text_wrap(lxw_format *self) |
490 | 0 | { |
491 | 0 | self->text_wrap = LXW_TRUE; |
492 | 0 | } |
493 | | |
494 | | /* |
495 | | * Set the rotation property. |
496 | | */ |
497 | | void |
498 | | format_set_rotation(lxw_format *self, int16_t angle) |
499 | 0 | { |
500 | | /* Convert user angle to Excel angle. */ |
501 | 0 | if (angle == 270) { |
502 | 0 | self->rotation = 255; |
503 | 0 | } |
504 | 0 | else if (angle >= -90 && angle <= 90) { |
505 | 0 | if (angle < 0) |
506 | 0 | angle = -angle + 90; |
507 | |
|
508 | 0 | self->rotation = angle; |
509 | 0 | } |
510 | 0 | else { |
511 | 0 | LXW_WARN("Rotation rotation outside range: -90 <= angle <= 90."); |
512 | 0 | self->rotation = 0; |
513 | 0 | } |
514 | 0 | } |
515 | | |
516 | | /* |
517 | | * Set the indent property. |
518 | | */ |
519 | | void |
520 | | format_set_indent(lxw_format *self, uint8_t value) |
521 | 0 | { |
522 | 0 | self->indent = value; |
523 | 0 | } |
524 | | |
525 | | /* |
526 | | * Set the shrink property. |
527 | | */ |
528 | | void |
529 | | format_set_shrink(lxw_format *self) |
530 | 0 | { |
531 | 0 | self->shrink = LXW_TRUE; |
532 | 0 | } |
533 | | |
534 | | /* |
535 | | * Set the text_justlast property. |
536 | | */ |
537 | | void |
538 | | format_set_text_justlast(lxw_format *self) |
539 | 0 | { |
540 | 0 | self->text_justlast = LXW_TRUE; |
541 | 0 | } |
542 | | |
543 | | /* |
544 | | * Set the pattern property. |
545 | | */ |
546 | | void |
547 | | format_set_pattern(lxw_format *self, uint8_t value) |
548 | 0 | { |
549 | 0 | self->pattern = value; |
550 | 0 | } |
551 | | |
552 | | /* |
553 | | * Set the bg_color property. |
554 | | */ |
555 | | void |
556 | | format_set_bg_color(lxw_format *self, lxw_color_t color) |
557 | 0 | { |
558 | 0 | self->bg_color = color; |
559 | 0 | } |
560 | | |
561 | | /* |
562 | | * Set the fg_color property. |
563 | | */ |
564 | | void |
565 | | format_set_fg_color(lxw_format *self, lxw_color_t color) |
566 | 0 | { |
567 | 0 | self->fg_color = color; |
568 | 0 | } |
569 | | |
570 | | /* |
571 | | * Set the border property. |
572 | | */ |
573 | | void |
574 | | format_set_border(lxw_format *self, uint8_t style) |
575 | 0 | { |
576 | 0 | style = _check_border(style); |
577 | 0 | self->bottom = style; |
578 | 0 | self->top = style; |
579 | 0 | self->left = style; |
580 | 0 | self->right = style; |
581 | 0 | } |
582 | | |
583 | | /* |
584 | | * Set the border_color property. |
585 | | */ |
586 | | void |
587 | | format_set_border_color(lxw_format *self, lxw_color_t color) |
588 | 0 | { |
589 | 0 | self->bottom_color = color; |
590 | 0 | self->top_color = color; |
591 | 0 | self->left_color = color; |
592 | 0 | self->right_color = color; |
593 | 0 | } |
594 | | |
595 | | /* |
596 | | * Set the bottom property. |
597 | | */ |
598 | | void |
599 | | format_set_bottom(lxw_format *self, uint8_t style) |
600 | 0 | { |
601 | 0 | self->bottom = _check_border(style); |
602 | 0 | } |
603 | | |
604 | | /* |
605 | | * Set the bottom_color property. |
606 | | */ |
607 | | void |
608 | | format_set_bottom_color(lxw_format *self, lxw_color_t color) |
609 | 0 | { |
610 | 0 | self->bottom_color = color; |
611 | 0 | } |
612 | | |
613 | | /* |
614 | | * Set the left property. |
615 | | */ |
616 | | void |
617 | | format_set_left(lxw_format *self, uint8_t style) |
618 | 0 | { |
619 | 0 | self->left = _check_border(style); |
620 | 0 | } |
621 | | |
622 | | /* |
623 | | * Set the left_color property. |
624 | | */ |
625 | | void |
626 | | format_set_left_color(lxw_format *self, lxw_color_t color) |
627 | 0 | { |
628 | 0 | self->left_color = color; |
629 | 0 | } |
630 | | |
631 | | /* |
632 | | * Set the right property. |
633 | | */ |
634 | | void |
635 | | format_set_right(lxw_format *self, uint8_t style) |
636 | 0 | { |
637 | 0 | self->right = _check_border(style); |
638 | 0 | } |
639 | | |
640 | | /* |
641 | | * Set the right_color property. |
642 | | */ |
643 | | void |
644 | | format_set_right_color(lxw_format *self, lxw_color_t color) |
645 | 0 | { |
646 | 0 | self->right_color = color; |
647 | 0 | } |
648 | | |
649 | | /* |
650 | | * Set the top property. |
651 | | */ |
652 | | void |
653 | | format_set_top(lxw_format *self, uint8_t style) |
654 | 0 | { |
655 | 0 | self->top = _check_border(style); |
656 | 0 | } |
657 | | |
658 | | /* |
659 | | * Set the top_color property. |
660 | | */ |
661 | | void |
662 | | format_set_top_color(lxw_format *self, lxw_color_t color) |
663 | 0 | { |
664 | 0 | self->top_color = color; |
665 | 0 | } |
666 | | |
667 | | /* |
668 | | * Set the diag_type property. |
669 | | */ |
670 | | void |
671 | | format_set_diag_type(lxw_format *self, uint8_t type) |
672 | 0 | { |
673 | 0 | if (type >= LXW_DIAGONAL_BORDER_UP && type <= LXW_DIAGONAL_BORDER_UP_DOWN) |
674 | 0 | self->diag_type = type; |
675 | 0 | } |
676 | | |
677 | | /* |
678 | | * Set the diag_color property. |
679 | | */ |
680 | | void |
681 | | format_set_diag_color(lxw_format *self, lxw_color_t color) |
682 | 0 | { |
683 | 0 | self->diag_color = color; |
684 | 0 | } |
685 | | |
686 | | /* |
687 | | * Set the diag_border property. |
688 | | */ |
689 | | void |
690 | | format_set_diag_border(lxw_format *self, uint8_t style) |
691 | 0 | { |
692 | 0 | self->diag_border = style; |
693 | 0 | } |
694 | | |
695 | | /* |
696 | | * Set the num_format_index property. |
697 | | */ |
698 | | void |
699 | | format_set_num_format_index(lxw_format *self, uint8_t value) |
700 | 0 | { |
701 | 0 | self->num_format_index = value; |
702 | 0 | } |
703 | | |
704 | | /* |
705 | | * Set the valign property. |
706 | | */ |
707 | | void |
708 | | format_set_valign(lxw_format *self, uint8_t value) |
709 | 0 | { |
710 | 0 | self->text_v_align = value; |
711 | 0 | } |
712 | | |
713 | | /* |
714 | | * Set the reading_order property. |
715 | | */ |
716 | | void |
717 | | format_set_reading_order(lxw_format *self, uint8_t value) |
718 | 0 | { |
719 | 0 | self->reading_order = value; |
720 | 0 | } |
721 | | |
722 | | /* |
723 | | * Set the font_family property. |
724 | | */ |
725 | | void |
726 | | format_set_font_family(lxw_format *self, uint8_t value) |
727 | 0 | { |
728 | 0 | self->font_family = value; |
729 | 0 | } |
730 | | |
731 | | /* |
732 | | * Set the font_charset property. |
733 | | */ |
734 | | void |
735 | | format_set_font_charset(lxw_format *self, uint8_t value) |
736 | 0 | { |
737 | 0 | self->font_charset = value; |
738 | 0 | } |
739 | | |
740 | | /* |
741 | | * Set the font_scheme property. |
742 | | */ |
743 | | void |
744 | | format_set_font_scheme(lxw_format *self, const char *font_scheme) |
745 | 0 | { |
746 | 0 | LXW_FORMAT_FIELD_COPY(self->font_scheme, font_scheme); |
747 | 0 | } |
748 | | |
749 | | /* |
750 | | * Set the font_condense property. |
751 | | */ |
752 | | void |
753 | | format_set_font_condense(lxw_format *self) |
754 | 0 | { |
755 | 0 | self->font_condense = LXW_TRUE; |
756 | 0 | } |
757 | | |
758 | | /* |
759 | | * Set the font_extend property. |
760 | | */ |
761 | | void |
762 | | format_set_font_extend(lxw_format *self) |
763 | 0 | { |
764 | 0 | self->font_extend = LXW_TRUE; |
765 | 0 | } |
766 | | |
767 | | /* |
768 | | * Set the theme property. |
769 | | */ |
770 | | void |
771 | | format_set_theme(lxw_format *self, uint8_t value) |
772 | 0 | { |
773 | 0 | self->theme = value; |
774 | 0 | } |
775 | | |
776 | | /* |
777 | | * Set the color_indexed property. |
778 | | */ |
779 | | void |
780 | | format_set_color_indexed(lxw_format *self, uint8_t value) |
781 | 0 | { |
782 | 0 | self->color_indexed = value; |
783 | 0 | } |
784 | | |
785 | | /* |
786 | | * Set the font_only property. |
787 | | */ |
788 | | void |
789 | | format_set_font_only(lxw_format *self) |
790 | 0 | { |
791 | 0 | self->font_only = LXW_TRUE; |
792 | 0 | } |
793 | | |
794 | | /* |
795 | | * Set the theme property. |
796 | | */ |
797 | | void |
798 | | format_set_hyperlink(lxw_format *self) |
799 | 1.37k | { |
800 | 1.37k | self->hyperlink = LXW_TRUE; |
801 | 1.37k | self->xf_id = 1; |
802 | 1.37k | self->underline = LXW_UNDERLINE_SINGLE; |
803 | 1.37k | self->theme = 10; |
804 | 1.37k | } |
805 | | |
806 | | /* |
807 | | * Set the quote_prefix property. |
808 | | */ |
809 | | void |
810 | | format_set_quote_prefix(lxw_format *self) |
811 | 0 | { |
812 | 0 | self->quote_prefix = LXW_TRUE; |
813 | 0 | } |