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

CRM: Updating core Noto Sans fonts and adding new CJK fonts #36962

Merged
merged 17 commits into from
Apr 22, 2024

Conversation

coder-karen
Copy link
Contributor

@coder-karen coder-karen commented Apr 17, 2024

Fixes https://github.com/Automattic/zero-bs-crm/issues/1782

Proposed changes:

  • This PR updates the $font_json variable with the five new CJK fonts:
    • NotoSansJP (now NotoSansJapanese) -> Japanese
    • NotoSansKR (now NotoSansKorean) -> Korean
    • NotoSansSC (now NotoSansSimplifiedChinese) -> Simplified Chinese
    • NotoSansTC (now NotoSansTaiwan)-> Traditional Chinese - Taiwan
    • NotoSansHK (now NotoSansHongKong) -> Traditional Chinese - Hong Kong
  • It also updates the pdffonts.zip file with new core Noto Sans font versions, which apart from updating several-year-old files also means that the two new currencies added in this PR will be viewable on PDF as well: CRM: Add several new currencies to the CRM currency dropdown #36897

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

https://github.com/Automattic/zero-bs-crm/issues/1782

p1713366111446779-slack-CTXBP902X

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • To test, check out this PR or create a JN site using this PR via the beta tester plugin.
  • Via the locale settings page - wp-admin/admin.php?page=zerobscrm-plugin-settings&tab=locale - set your currency to be the Azerbaijan Manat ('₼', 'AZN'), or the Kazakhstani Tenge ('₸', 'KZT').
  • Then, at the bottom of the page re-install the default fonts using the 'refresh' icon.
  • On an invoice, select to download the PDF. The new currency should now be visible.
  • In trunk, you won't see the currency on the PDF, only a blank square.
  • To test CJK, you can test if you are able to add Korean, Chinese, or Japanese characters to (for example) an invoice description, after installing the relevant font.
  • To see the font via PDF, modify the template with the new font added to the CSS styles, as per this link.

@coder-karen coder-karen self-assigned this Apr 17, 2024
@github-actions github-actions bot added the [Plugin] CRM Issues about the Jetpack CRM plugin label Apr 17, 2024
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@coder-karen coder-karen marked this pull request as ready for review April 17, 2024 19:34
@github-actions github-actions bot added the Admin Page React-powered dashboard under the Jetpack menu label Apr 18, 2024
@tbradsha
Copy link
Contributor

image

Comment on lines 530 to 538
$large_font_files = array( 'NotoSansSimplifiedChinese.zip', 'NotoSerifDisplay.zip', 'NotoSans.zip', 'NotoSansDisplay.zip', 'NotoSansTaiwan.zip', 'NotoSansHongKong.zip', 'NotoSansJapanese.zip', 'NooSansKorean.zip', 'NotoSansMono.zip' );
// Several large font files may timeout when downloading. Increase the timeout for these files.
foreach ( $large_font_files as $file ) {
if ( str_ends_with( $url, $file ) ) {

add_filter( 'http_request_timeout', 'custom_large_font_timeout' );
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works. Did you consider moving this into retrieve_and_install_specific_font(), though? I think it'd work better here:

if ( !zeroBSCRM_retrieveFile( $zbs->urls['extdlfonts'] . $remote_zip_name, $temp_path ) ) {

This would mean you no longer need str_ends_with() (or even a loop), as you have the actual filename already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not consider that, I made an assumption the timeout filter needed to be in the same function but I can see it doesn't! Thank you.

Comment on lines 583 to 591
/**
* Increase the timeout for large font files.
* The timeout is increased to 60 seconds (the default is 5), for large font files.
* @return int The timeout in seconds.
*/
function custom_large_font_timeout() {
return 60;
}

Copy link
Contributor

@tbradsha tbradsha Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the above comment, I'd move this into the jpcrm-fonts.php file.

Copy link
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this works, and it's a huge deal! Great job!

I've left a few small comments. One other thing to consider is how the new CJK fonts show in the dropdown. Right now Japanese makes sense, but "Hong Kong", and "Taiwan" aren't scripts. I'd recommend instead doing something like:

  • Chinese (Traditional, Hong Kong)
  • Chinese (Traditional, Taiwan)
  • Chinese (Simplified)

It looks like there's a cleaned_alphabetical section of list_all_available() that supports display manipulation already.

@@ -380,7 +380,7 @@
sprintf(
/* translators: %s is the URL of the CRM support doc explaining how to add styles to pdf templates. */
__( 'Once a new font is installed, <a href="%s" target="_blank">learn more about using the custom fonts in CRM PDFs here</a>.', 'zero-bs-crm' ),
esc_url( 'https://kb.jetpackcrm.com/knowledge-base/using-custom-fonts-in-crm-pdfs-e-g-invoice-templates' )
esc_url( $zbs->urls['kb-pdf-custom-fonts'] )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@coder-karen
Copy link
Contributor Author

Overall this works, and it's a huge deal! Great job!

Thanks!

It looks like there's a cleaned_alphabetical section of list_all_available() that supports display manipulation already.

Yes, you're right. I unnecessarily modified the file names (zip names, etc) to make the display more readable, but I think that is ok to leave them now that they are changed.
I've modified the UI now.

Only one thing I've spotted isn't working ideally - the new support doc link isn't opening in a new tab for me. I am not seeing what is causing this just now, so may need to come back to this.

@tbradsha
Copy link
Contributor

Note that I was getting PHP notices when installing some of the CJK fonts due to certain variants not being present:

Deprecated: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated in /includes/jpcrm-fonts.php on line 587
Deprecated: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated in /includes/jpcrm-fonts.php on line 588

Resolved in 9be0b73 by flipping the null check with the file_exists check.

@tbradsha
Copy link
Contributor

I unnecessarily modified the file names (zip names, etc) to make the display more readable, but I think that is ok to leave them now that they are changed.

Indeed:
image

This is less important in my opinion, though, as at least they can now easily discover the font to add.

the new support doc link isn't opening in a new tab for me

Looks like target wasn't an allowed attribute. I've added it here: 836aa2f

tbradsha
tbradsha previously approved these changes Apr 19, 2024
@coder-karen coder-karen merged commit 48c697d into trunk Apr 22, 2024
53 checks passed
@coder-karen coder-karen deleted the add/crm/new-cjk-fonts-plus-update-core branch April 22, 2024 12:59
@github-actions github-actions bot added this to the crm/6.4.3 milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [Plugin] CRM Issues about the Jetpack CRM plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants