Skip to content

Commit

Permalink
font: add family and char set APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Feb 4, 2025
1 parent 14f1351 commit 4aa4731
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
34 changes: 32 additions & 2 deletions include/xlsxwriter/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,38 @@ void format_set_font_strikeout(lxw_format *format);
*/
void format_set_font_script(lxw_format *format, uint8_t style);

/**
* @brief Set the Format font family property.
*
* @param format Pointer to a Format instance.
* @param value The font family index.
*
* Set the font family. This is usually an integer in the range 1-4. This
* function is implemented for completeness but is rarely used in practice.
*
* @code
* format_set_font_family(format, 178);
* @endcode
*
*/
void format_set_font_family(lxw_format *format, uint8_t value);

/**
* @brief Set the Format font character set property.
*
* @param format Pointer to a Format instance.
* @param value The font character set.
*
* Set the font character set property. This function is implemented for
* completeness but is rarely used in practice.
*
* @code
* format_set_font_charset(format, 178);
* @endcode
*
*/
void format_set_font_charset(lxw_format *format, uint8_t value);

/**
* @brief Set the number format for a cell.
*
Expand Down Expand Up @@ -1303,8 +1335,6 @@ void format_set_quote_prefix(lxw_format *format);

void format_set_font_outline(lxw_format *format);
void format_set_font_shadow(lxw_format *format);
void format_set_font_family(lxw_format *format, uint8_t value);
void format_set_font_charset(lxw_format *format, uint8_t value);
void format_set_font_scheme(lxw_format *format, const char *font_scheme);
void format_set_font_condense(lxw_format *format);
void format_set_font_extend(lxw_format *format);
Expand Down
20 changes: 20 additions & 0 deletions src/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,23 @@ _write_font_family(lxw_styles *self, uint8_t font_family)
LXW_FREE_ATTRIBUTES();
}

/*
* Write the <charset> element.
*/
STATIC void
_write_font_charset(lxw_styles *self, uint8_t font_charset)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;

LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_INT("val", font_charset);

lxw_xml_empty_tag(self->file, "charset", &attributes);

LXW_FREE_ATTRIBUTES();
}

/*
* Write the <scheme> element.
*/
Expand Down Expand Up @@ -527,6 +544,9 @@ _write_font(lxw_styles *self, lxw_format *format, uint8_t is_dxf,
_write_font_name(self, format->font_name, is_rich_string);
_write_font_family(self, format->font_family);

if (format->font_charset)
_write_font_charset(self, format->font_charset);

/* Only write the scheme element for the default font type if it
* is a hyperlink. */
if ((!*format->font_name
Expand Down

0 comments on commit 4aa4731

Please sign in to comment.