[GH-ISSUE #494] Feature: allow non-theme Calibri font #385

Open
opened 2026-05-05 12:14:15 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @wangjinyin7136 on GitHub (Nov 4, 2025).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/494

Description:
In src/styles.c, the logic controlling whether to write the <font><scheme> element seems inconsistent with the comment above it.

/* Only write the scheme element for the default font type if it
 * is a hyperlink. */
if ((!*format->font_name
     || strcmp(LXW_DEFAULT_FONT_NAME, format->font_name) == 0)
    && !format->hyperlink) {
    _write_font_scheme(self, format->font_scheme);
}

According to the comment, the <scheme> element should only be written when the format is a hyperlink, but the actual condition writes it when it's not a hyperlink (&& !format->hyperlink).

This looks like a logical inversion between the comment and the code.

Expected behavior:
If the intent is to include <scheme> only for hyperlink fonts (as the comment says), the condition should be:

if ((!*format->font_name
     || strcmp(LXW_DEFAULT_FONT_NAME, format->font_name) == 0)
    && format->hyperlink) {
    _write_font_scheme(self, format->font_scheme);
}

Actual behavior:
Currently, _write_font_scheme() is called for non-hyperlink formats using the default font.

Impact:
This can result in incorrect <font><scheme> behavior — e.g., fonts that should use explicit names like "Arial" or "Calibri" may end up using theme-dependent fonts unintentionally. In some cases, Excel may render them differently depending on theme settings.

Environment:

  • libxlsxwriter version: (1.1.9)
  • OS: (Ubuntu 22.04)

Suggested fix:
Reverse the hyperlink condition or clarify the intended logic in the comment.

Originally created by @wangjinyin7136 on GitHub (Nov 4, 2025). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/494 **Description:** In `src/styles.c`, the logic controlling whether to write the `<font><scheme>` element seems inconsistent with the comment above it. ```c /* Only write the scheme element for the default font type if it * is a hyperlink. */ if ((!*format->font_name || strcmp(LXW_DEFAULT_FONT_NAME, format->font_name) == 0) && !format->hyperlink) { _write_font_scheme(self, format->font_scheme); } ``` According to the comment, the `<scheme>` element should **only** be written when the format **is a hyperlink**, but the actual condition writes it **when it's *not* a hyperlink** (`&& !format->hyperlink`). This looks like a logical inversion between the comment and the code. **Expected behavior:** If the intent is to include `<scheme>` only for hyperlink fonts (as the comment says), the condition should be: ```c if ((!*format->font_name || strcmp(LXW_DEFAULT_FONT_NAME, format->font_name) == 0) && format->hyperlink) { _write_font_scheme(self, format->font_scheme); } ``` **Actual behavior:** Currently, `_write_font_scheme()` is called for *non-hyperlink* formats using the default font. **Impact:** This can result in incorrect `<font><scheme>` behavior — e.g., fonts that should use explicit names like `"Arial"` or `"Calibri"` may end up using theme-dependent fonts unintentionally. In some cases, Excel may render them differently depending on theme settings. **Environment:** * libxlsxwriter version: (1.1.9) * OS: (Ubuntu 22.04) **Suggested fix:** Reverse the `hyperlink` condition or clarify the intended logic in the comment.
Author
Owner

@jmcnamara commented on GitHub (Nov 4, 2025):

Thanks for the question.

The comment is wrong, It should read:

Only write the scheme element for the default font type if it isn't a hyperlink.

<!-- gh-comment-id:3484200929 --> @jmcnamara commented on GitHub (Nov 4, 2025): Thanks for the question. The comment is wrong, It should read: Only write the scheme element for the default font type if it **isn't** a hyperlink.
Author
Owner

@wangjinyin7136 commented on GitHub (Nov 4, 2025):

Thanks! Just to confirm — if the user explicitly sets format_set_font_name(format, "Calibri"),
should it still write or use instead?
Right now it treats "Calibri" as default and writes , which makes the font follow the theme instead of staying fixed.
Would it make sense to only write when no font name is set?

<!-- gh-comment-id:3484298091 --> @wangjinyin7136 commented on GitHub (Nov 4, 2025): Thanks! Just to confirm — if the user explicitly sets format_set_font_name(format, "Calibri"), should it still write <scheme> or use <name val="Calibri"/> instead? Right now it treats "Calibri" as default and writes <scheme>, which makes the font follow the theme instead of staying fixed. Would it make sense to only write <scheme> when no font name is set?
Author
Owner

@jmcnamara commented on GitHub (Nov 4, 2025):

What issue are you having or what are you trying to achieve?

<!-- gh-comment-id:3484327338 --> @jmcnamara commented on GitHub (Nov 4, 2025): What issue are you having or what are you trying to achieve?
Author
Owner

@wangjinyin7136 commented on GitHub (Nov 4, 2025):

I’m trying to ensure that when explicitly setting the font name ("Calibri"), the generated XLSX should use a fixed font instead of following the theme.
Currently, libxlsxwriter still writes for "Calibri", which causes Excel to treat it as a themed font instead of a literal "Calibri" font.

<!-- gh-comment-id:3484333996 --> @wangjinyin7136 commented on GitHub (Nov 4, 2025): I’m trying to ensure that when explicitly setting the font name ("Calibri"), the generated XLSX should use a fixed font instead of following the theme. Currently, libxlsxwriter still writes <scheme> for "Calibri", which causes Excel to treat it as a themed font instead of a literal "Calibri" font.
Author
Owner

@jmcnamara commented on GitHub (Nov 4, 2025):

which causes Excel to treat it as a themed font instead of a literal "Calibri" font.

Which means that any user defined "Calibri" fonts change when the theme changes. Is that the issue?

<!-- gh-comment-id:3484402602 --> @jmcnamara commented on GitHub (Nov 4, 2025): > which causes Excel to treat it as a themed font instead of a literal "Calibri" font. Which means that any user defined "Calibri" fonts change when the theme changes. Is that the issue?
Author
Owner

@wangjinyin7136 commented on GitHub (Nov 4, 2025):

Yes, exactly — that’s the issue.

<!-- gh-comment-id:3484439756 --> @wangjinyin7136 commented on GitHub (Nov 4, 2025): Yes, exactly — that’s the issue.
Author
Owner

@jmcnamara commented on GitHub (Nov 4, 2025):

Ok. I am currently reworking some of the default font handling in the Rust version so I will look into it.

See also: https://github.com/jmcnamara/rust_xlsxwriter/issues/158

<!-- gh-comment-id:3484471786 --> @jmcnamara commented on GitHub (Nov 4, 2025): Ok. I am currently reworking some of the default font handling in the Rust version so I will look into it. See also: https://github.com/jmcnamara/rust_xlsxwriter/issues/158
Author
Owner

@wangjinyin7136 commented on GitHub (Nov 4, 2025):

Thanks for checking it!

<!-- gh-comment-id:3484554777 --> @wangjinyin7136 commented on GitHub (Nov 4, 2025): Thanks for checking it!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#385
No description provided.