<?php
/*
Plugin Name:  Vik Plugins TCPDF Fonts
Plugin URI:   https://vikwp.com/
Description:  Helper plugin to load extra PDF fonts for any language.
Version:      1.0
Author:       E4J s.r.l.
Author URI:   https://vikwp.com
License:      GPL2
License URI:  https://www.gnu.org/licenses/gpl-2.0.html
*/

// No direct access
defined('ABSPATH') or die('No script kiddies please!');

/**
 * Register the path from which TCPDF should be loading extra fonts.
 */
add_action('plugins_loaded', function()
{
	if (defined('K_PATH_FONTS') || defined('K_TCPDF_EXTERNAL_CONFIG'))
	{
		// do nothing, as someone else must have registered a custom path already.
		return;
	}

	define('K_TCPDF_EXTERNAL_CONFIG', 1);

	define('K_PATH_FONTS', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'TCPDF_fonts' . DIRECTORY_SEPARATOR);
});

/**
 * Filter to override the font to use for generating PDF files.
 * 
 * @param 	string 	$use_font 		the name of the font to use.
 * @param 	string 	$current_font 	the name of the font being used.
 * 
 * @return 	string 					the font name to use.
 */
add_filter('vikbooking_get_pdf_font_name', function($use_font, $current_font) {
	if (!is_null($use_font))
	{
		// font name to use has been set already
		return $use_font;
	}

	// always use the PDF font "Dejavusans"
	return 'dejavusans';
}, 10, 2);

/**
 * Filter to override the font to use for generating PDF files.
 * 
 * @param 	string 	$use_font 		the name of the font to use.
 * @param 	string 	$current_font 	the name of the font being used.
 * 
 * @return 	string 					the font name to use.
 */
add_filter('vikrentcar_get_pdf_font_name', function($use_font, $current_font) {
	if (!is_null($use_font))
	{
		// font name to use has been set already
		return $use_font;
	}

	// always use the PDF font "Dejavusans"
	return 'dejavusans';
}, 10, 2);

/**
 * Filter to override the font to use for generating PDF files.
 * 
 * @param 	string 	$use_font 		the name of the font to use.
 * @param 	string 	$current_font 	the name of the font being used.
 * 
 * @return 	string 					the font name to use.
 */
add_filter('vikrentitems_get_pdf_font_name', function($use_font, $current_font) {
	if (!is_null($use_font))
	{
		// font name to use has been set already
		return $use_font;
	}

	// always use the PDF font "Dejavusans"
	return 'dejavusans';
}, 10, 2);
