Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

- [PDF Generator Add-on](https://renstillmann.github.io/super-forms/#/pdf-generator-add-on)

## Unreleased - Version 6.4.010-beta

- **Fix:** The PDF Generator font script for non-Latin languages is now attached to the `super-common` script, so it always runs after `super_common_i18n` is defined, even when a JavaScript optimization plugin reorders scripts. If `super-common` was already printed, it is still printed in the footer.

## 2026-10-09 - Version 6.4.009-beta

- **Fix:** Date submissions use the default `dd-mm-yy` pattern when the saved format, or selected custom format, is missing or empty, while preserving explicit formats and strict date validation.
Expand Down
26 changes: 22 additions & 4 deletions src/includes/class-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6886,13 +6886,15 @@ public static function super_form_func( $atts, $elements_only=false ) {
file_put_contents($font_file, $font_data);
}
// ponytail: without the fonts the browser falls back to the default PDF font path.
if( $fonts_ready ) add_action('wp_footer', function($arguments) use ($language) {
if( $fonts_ready ) {
$link = SUPER_PLUGIN_FILE . 'includes/extensions/pdf-generator/fonts/'.$language;
add_action('wp_footer', function($arguments) use ($link) {
?><style>.super-form:after {font-family: 'SF-Unicode'!important; content:'.'!important; visibility:hidden!important; position:absolute!important; bottom:0px!important; left:0px!important; z-index:-999999!important;}
@font-face {font-family:'SF-Unicode';src:url('<?php echo $link; ?>.woff') format('woff');}
@font-face {font-family:'SF-Unicode';src:url('<?php echo $link; ?>.woff2') format('woff2');}</style>
<script>super_common_i18n.fonts = {link: '<?php echo $link; ?>'};</script><?php
}, 100, 1);
@font-face {font-family:'SF-Unicode';src:url('<?php echo $link; ?>.woff2') format('woff2');}</style><?php
}, 100, 1);
self::add_pdf_font_script('super_common_i18n.fonts = ' . wp_json_encode(array('link'=>$link)) . ';');
}
}
}
}
Expand All @@ -6901,6 +6903,22 @@ public static function super_form_func( $atts, $elements_only=false ) {
return do_shortcode( $result );
}

/**
* Attach the PDF font script to `super-common` so it always runs after the localized
* `super_common_i18n`, even when an optimization plugin moves scripts around.
* When `super-common` was already printed (e.g. in the head), WordPress would never output
* the inline data, so fall back to the footer.
*/
private static function add_pdf_font_script( $js ) {
if( !wp_script_is('super-common', 'done') ) {
wp_add_inline_script('super-common', $js, 'after');
return;
}
add_action('wp_footer', function() use ($js) {
echo '<script>' . $js . '</script>';
}, 100);
}

}

endif;
78 changes: 78 additions & 0 deletions tests/test-pdf-font-inline-script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
require_once __DIR__ . '/test-security-upload-00-base.php';

/** The PDF font script must run after the localized `super_common_i18n`, even when optimizers reorder scripts. */
class Test_Pdf_Font_Inline_Script extends Super_Forms_Upload_Security_Test_Case {
private $created_font_files = array();
private $original_wp_scripts;

public function set_up() {
parent::set_up();
$this->original_wp_scripts = isset($GLOBALS['wp_scripts']) ? $GLOBALS['wp_scripts'] : null;
$GLOBALS['wp_scripts'] = new WP_Scripts();
$font_dir = SUPER_PLUGIN_DIR . '/includes/extensions/pdf-generator/fonts/';
if( !is_dir($font_dir) ) wp_mkdir_p($font_dir);
// Existing non-empty files are reused so nothing is downloaded; only files this test creates are removed.
foreach( array('json' => '{"regular":"x"}', 'woff' => 'x', 'woff2' => 'x') as $ext => $content ) {
$file = $font_dir . 'cyrillic.' . $ext;
if( file_exists($file) && filesize($file)>0 ) continue;
file_put_contents($file, $content);
$this->created_font_files[] = $file;
}
}

public function tear_down() {
foreach( $this->created_font_files as $file ) {
if( file_exists($file) ) unlink($file);
}
$this->created_font_files = array();
$GLOBALS['wp_scripts'] = $this->original_wp_scripts;
parent::tear_down();
}

private function render_cyrillic_pdf_form() {
// Build `_pdf` the way the plugin does, so super_form_func finds every key it reads.
$pdf = SUPER_PDF_Generator::get_default_pdf_settings( array(
'generate' => 'true',
'textRendering' => 'true',
'language' => 'cyrillic',
) );
$form_id = $this->create_form( 'publish', array(), array( '_pdf' => $pdf ) );
return SUPER_Shortcodes::super_form_func( array( 'id' => (string) $form_id ) );
}

public function test_fonts_attach_to_super_common_after_block() {
$this->render_cyrillic_pdf_form();
$after = wp_scripts()->get_data( 'super-common', 'after' );
$this->assertIsArray( $after );
$this->assertStringContainsString( 'super_common_i18n.fonts', implode( "\n", $after ) );
$this->assertStringContainsString( 'pdf-generator', implode( "\n", $after ) );
}

public function test_fonts_print_after_localized_var() {
$this->render_cyrillic_pdf_form();
ob_start();
wp_print_scripts( array( 'super-common' ) );
$out = ob_get_clean();
$var_pos = strpos( $out, 'var super_common_i18n' );
$fonts_pos = strpos( $out, 'super_common_i18n.fonts' );
$after_pos = strpos( $out, 'id="super-common-js-after"' );
$this->assertNotFalse( $var_pos, $out );
$this->assertNotFalse( $fonts_pos, $out );
$this->assertNotFalse( $after_pos, $out );
$this->assertLessThan( $fonts_pos, $var_pos );
$this->assertLessThan( $fonts_pos, $after_pos );
}

public function test_fonts_fall_back_to_footer_when_super_common_already_printed() {
wp_scripts()->done[] = 'super-common';
$this->render_cyrillic_pdf_form();
// Core's deprecated skip-link footer callback is unrelated; the test hooks are restored after each test.
remove_action( 'wp_footer', 'the_block_template_skip_link' );
ob_start();
do_action( 'wp_footer' );
$out = ob_get_clean();
$this->assertStringContainsString( 'super_common_i18n.fonts', $out );
$this->assertStringContainsString( "font-family:'SF-Unicode'", $out );
}
}
Loading