font_cache_filename; $legacy_cache_file = trailingslashit( $path ) . 'dompdf_font_family_cache.php'; // Dompdf <2.0 if ( is_readable( $cache_file ) ) { $json_data = file_get_contents( $cache_file ); $font_data = json_decode( $json_data, true ); } elseif ( is_readable( $legacy_cache_file ) ) { $font_data = include $legacy_cache_file; @unlink( $legacy_cache_file ); } else { $font_data = array(); } // if include fails it returns false - we'll log an error in that case if ( $font_data === false ) { wcpdf_log_error( sprintf( "Could not read font cache file (%s)", $cache_file ), 'critical' ); } // dompdf 1.1.X uses a closure to return the fonts, instead of a plain array (1.0.X and older) if ( ! is_array( $font_data ) && is_callable( $font_data ) ) { $font_data = $font_data( $fontDir, $rootDir ); } return is_array( $font_data ) ? $this->normalize_font_paths( $font_data ) : array(); } /** * Get all fonts included in dompdf * * @return array */ public function get_dompdf_fonts() { $fonts = $this->dompdf->getFontMetrics()->getFontFamilies(); return $this->normalize_font_paths( $fonts ); } /** * Get all fonts from the plugin (excluding base path!) * * @return array */ public function get_plugin_fonts() { return array ( 'open sans' => array ( 'normal' => 'OpenSans-Normal', 'bold' => 'OpenSans-Bold', 'italic' => 'OpenSans-Italic', 'bold_italic' => 'OpenSans-BoldItalic', ), 'segoe' => array ( 'normal' => 'Segoe-Normal', 'bold' => 'Segoe-Bold', 'italic' => 'Segoe-Italic', 'bold_italic' => 'Segoe-BoldItalic', ), 'roboto slab' => array ( 'normal' => 'RobotoSlab-Normal', 'bold' => 'RobotoSlab-Bold', 'italic' => 'RobotoSlab-Italic', 'bold_italic' => 'RobotoSlab-BoldItalic', ), 'currencies' => array ( 'normal' => 'currencies', 'bold' => 'currencies', 'italic' => 'currencies', 'bold_italic' => 'currencies', ), ); } /** * Normalize a filesystem path. * * @param string $path Path to normalize. * @return string Normalized path. */ public function normalize_path( $path ) { return function_exists( 'wp_normalize_path' ) ? wp_normalize_path( $path ) : str_replace('\\','/', $path ); } /** * Apply path normalization to a font list * * @param array $fonts array of font entries * @return array Normalized array of font entries */ public function normalize_font_paths( $fonts ) { foreach( $fonts as $font_name => $filenames ) { if ( ! is_array( $filenames ) ) { continue; } foreach ( $filenames as $variant => $filename ) { $fonts[$font_name][$variant] = $this->normalize_path( $filename ); } } return $fonts; } } endif; // class_exists