Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format_set_font_name does not work for Persian font. #468

Open
mehranj73 opened this issue Feb 4, 2025 · 12 comments
Open

format_set_font_name does not work for Persian font. #468

mehranj73 opened this issue Feb 4, 2025 · 12 comments
Assignees
Labels

Comments

@mehranj73
Copy link

mehranj73 commented Feb 4, 2025

My problem also happend in Rust lang and setting font_charset to 178 and font_family to 0 fix my problem. I don't know how to do the same thing in your library. I'm using "B Nazanin" and "B titr" fonts.
jmcnamara/rust_xlsxwriter#125

@jmcnamara
Copy link
Owner

The APIs you need are

void format_set_font_family(lxw_format *format, uint8_t value);
void format_set_font_charset(lxw_format *format, uint8_t value);

They are public, just not documented because they are rarely required.

@jmcnamara jmcnamara self-assigned this Feb 4, 2025
@mehranj73
Copy link
Author

Thanks for replying. I actually tried these two methods and didn't work. I also open the excel file as a zip file and didn't see the changes to charset and font family.

@jmcnamara
Copy link
Owner

My bad. I hadn't added the code to use font_charset. I've pushed it to main so you can try it.

Here is an example:

#include "xlsxwriter.h"

int main()
{

    lxw_workbook *workbook = workbook_new("gh468.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Set the cell size for clarity. */
    worksheet_set_column(worksheet, 0, 0, 60, NULL);
    worksheet_set_row(worksheet, 0, 100, NULL);

    /* Add a format with a font that supports Persian. */
    lxw_format *format = workbook_add_format(workbook);

    format_set_font_name(format, "B Titr");
    format_set_font_size(format, 72);
    format_set_font_charset(format, 178);
    format_set_font_family(format, 0);
    format_set_bold(format);
    format_set_align(format, LXW_ALIGN_CENTER);
    format_set_align(format, LXW_ALIGN_VERTICAL_CENTER);

    /* Write a test string. */
    worksheet_write_string(worksheet, 0, 0, "سلام 100000", format);

    workbook_close(workbook);

    return 0;
}

Output:

Image

Does that look correct?

@mehranj73
Copy link
Author

I'm a newbie. Would it work if I download the library using vcpkg ?

@jmcnamara
Copy link
Owner

I can wrap it up into a vcpkg but it will take a few days.

@mehranj73
Copy link
Author

Is version 1.1.9 has the new changes in vcpkg?

@jmcnamara
Copy link
Owner

No. Not yet.

@mehranj73
Copy link
Author

mehranj73 commented Feb 10, 2025

I have been trying "Using CMake for Microsoft Visual Studio" in this tutorial for a week and I always get "No package 'zlib' found" error.

@jmcnamara
Copy link
Owner

I have submitted a request to include the updated version, v1.2.0, in vcpkg: microsoft/vcpkg#43758

@jmcnamara
Copy link
Owner

These changes are now upstream in vcpkg libxlsxwriter package version 1.2.0.

Could you test that and let me know if is fixed. Thanks.

@mehranj73
Copy link
Author

The last version still is 1.1.9 in vcpkg.

@jmcnamara
Copy link
Owner

I don't know how long it takes to become available. The upgrade patch was merged upstream yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants