--- prestashop/classes/PDF.php.orig 2008-02-15 16:42:00.000000000 +0100 +++ prestashop/classes/PDF.php 2008-02-19 19:25:00.000000000 +0100 @@ -23,6 +23,13 @@ private static $currency = NULL; private static $_iso; + /** @var array Special PDF params such encoding and font */ + private static $_pdfparams = array ( + 'CS' => array( + 'encoding' => 'cp1250', + 'font' => 'ArialMT', + ) + ); /** @var array Translations chosen for display invoice */ private static $_translations = array ( 'FR' => array( @@ -62,25 +69,75 @@ 'Total with Tax' => 'Total TTC', 'PHONE:' => 'Tel. :', 'Origin:' => 'Origine :', + ), + 'CS' => array( + 'INVOICE #' => 'FAKTURA ', + 'Invoice' => 'Faktura', + 'from' => 'ze dne', + 'An electronic version of this invoice is kept in Your Account. To access it, log in to the website' => 'Elektronickou verzi faktury můžete stáhnout po přihlášení ke svému účtu', + 'using your e-mail address and password (which you created while placing your first order).' => '', + 'Product' => 'Položka', + 'Products' => 'Položky', + 'Description' => 'Popis', + 'Qty' => 'Počet', + 'Reference' => 'Kód', + 'Tax' => 'DPH', + 'Price' => 'Cena bez DPH', + 'U. price' => 'Cena za kus', + 'Discount:' => 'Sleva :', + 'Total' => 'Cena s DPH', + 'Total products TI' => 'Celkem s DPH', + 'Total discounts' => 'Sleva', + 'Total shipping' => 'Dopravné', + 'Delivery' => 'Dodací adresa', + 'Invoicing' => 'Odběratel', + 'Order date:' => 'Datum objednávky :', + 'Shipping date:' => 'Datum expedice :', + 'Payment method:' => 'Způsob platby :', + 'Carrier:' => 'Doprava :', + 'Headquarters:' => '', + 'RCS:' => 'IČO :', + 'SIRET:' => 'DIČ :', + 'Tax detail' => 'Položka', + 'Tax %' => 'DPH %', + 'Pre-Tax Total' => 'Cena bez DPH', + 'Total Tax' => 'DPH', + 'Total with Tax' => 'Celkem s DPH', + 'PHONE:' => 'Tel. :', + 'Origin:' => 'Země původu :', ) ); /** + * Constructor + */ + function PDF($orientation='P',$unit='mm',$format='A4') + { + FPDF::FPDF($orientation, $unit, $format); + + $font = self::embedfont(); + if($font) { + $this->AddFont($font); + $this->AddFont($font, 'B'); + } + } + + /** * Invoice header */ function Header() { $conf = Configuration::getMultiple(array('PS_SHOP_NAME', 'PS_SHOP_ADDR1', 'PS_SHOP_CODE', 'PS_SHOP_CITY', 'PS_SHOP_COUNTRY')); - $conf['PS_SHOP_NAME'] = isset($conf['PS_SHOP_NAME']) ? utf8_decode($conf['PS_SHOP_NAME']) : 'Your company'; - $conf['PS_SHOP_ADDR1'] = isset($conf['PS_SHOP_ADDR1']) ? utf8_decode($conf['PS_SHOP_ADDR1']) : 'Your company'; - $conf['PS_SHOP_CODE'] = isset($conf['PS_SHOP_CODE']) ? utf8_decode($conf['PS_SHOP_CODE']) : 'Postcode'; - $conf['PS_SHOP_CITY'] = isset($conf['PS_SHOP_CITY']) ? utf8_decode($conf['PS_SHOP_CITY']) : 'City'; - $conf['PS_SHOP_COUNTRY'] = isset($conf['PS_SHOP_COUNTRY']) ? utf8_decode($conf['PS_SHOP_COUNTRY']) : 'Country'; + $conf['PS_SHOP_NAME'] = isset($conf['PS_SHOP_NAME']) ? iconv('utf-8', self::encoding(), $conf['PS_SHOP_NAME']) : 'Your company'; + $conf['PS_SHOP_ADDR1'] = isset($conf['PS_SHOP_ADDR1']) ? iconv('utf-8', self::encoding(), $conf['PS_SHOP_ADDR1']) : 'Your company'; + $conf['PS_SHOP_CODE'] = isset($conf['PS_SHOP_CODE']) ? iconv('utf-8', self::encoding(), $conf['PS_SHOP_CODE']) : 'Postcode'; + $conf['PS_SHOP_CITY'] = isset($conf['PS_SHOP_CITY']) ? iconv('utf-8', self::encoding(), $conf['PS_SHOP_CITY']) : 'City'; + $conf['PS_SHOP_COUNTRY'] = isset($conf['PS_SHOP_COUNTRY']) ? iconv('utf-8', self::encoding(), $conf['PS_SHOP_COUNTRY']) : 'Country'; if (file_exists(_PS_IMG_DIR_.'/logo.jpg')) $this->Image(_PS_IMG_DIR_.'/logo.jpg', 10, 8, 0, 15); - $this->SetFont('Arial', 'B', 15); + $this->SetFont(self::fontname(), 'B', 15); $this->Cell(115); $this->Cell(80, 10, self::l('INVOICE #').sprintf('%06d', self::$order->id), 0, 0, 'C'); } @@ -95,21 +152,21 @@ /* * Display a message for customer */ - $this->SetFont('Arial', '', 8); + $this->SetFont(self::fontname(), '', 8); $this->Cell(0, 10, self::l('An electronic version of this invoice is kept in Your Account. To access it, log in to the website'), 0, 0, 'C', 0, 'http://'.$_SERVER['SERVER_NAME'].__PS_BASE_URI__.'history.php'); $this->Ln(4); - $this->Cell(0, 10, utf8_decode(Configuration::get('PS_SHOP_NAME')).' '.self::l('using your e-mail address and password (which you created while placing your first order).'), 0, 0, 'C', 0, 'http://'.$_SERVER['SERVER_NAME'].__PS_BASE_URI__.'history.php'); + $this->Cell(0, 10, iconv('utf-8', self::encoding(), Configuration::get('PS_SHOP_NAME')).' '.self::l('using your e-mail address and password (which you created while placing your first order).'), 0, 0, 'C', 0, 'http://'.$_SERVER['SERVER_NAME'].__PS_BASE_URI__.'history.php'); $this->Ln(9); $arrayConf = array('PS_SHOP_NAME', 'PS_SHOP_ADDR1', 'PS_SHOP_CODE', 'PS_SHOP_CITY', 'PS_SHOP_COUNTRY', 'PS_SHOP_RCS', 'PS_SHOP_PHONE', 'PS_SHOP_SIRET'); $conf = Configuration::getMultiple($arrayConf); - $conf = array_map('utf8_decode', $conf); + foreach($conf as $key => $value) $conf[$key] = iconv('utf-8', self::encoding(), $value); foreach ($arrayConf as $key) if (!isset($conf[$key])) $conf[$key] = ''; $this->SetFillColor(240, 240, 240); $this->SetTextColor(0, 0, 0); - $this->SetFont('Arial', '', 8); + $this->SetFont(self::fontname(), '', 8); $this->Cell(0, 5, strtoupper($conf['PS_SHOP_NAME']). (!empty($conf['PS_SHOP_ADDR1']) ? ' - '.self::l('Headquarters:').' '.$conf['PS_SHOP_ADDR1'].(!empty($conf['PS_SHOP_ADDR2']) ? ' '.$conf['PS_SHOP_ADDR2'] : '').' '.$conf['PS_SHOP_CODE'].' '.$conf['PS_SHOP_CITY'].' '.$conf['PS_SHOP_COUNTRY'] : ''), 0, 1, 'C', 1); $this->Cell(0, 5, @@ -146,35 +203,35 @@ $pdf->SetX(10); $pdf->SetY(25); - $pdf->SetFont('Arial', '', 12); + $pdf->SetFont(self::fontname(), '', 12); $pdf->Cell($width, 10, self::l('Delivery'), 0, 'L'); $pdf->Cell($width, 10, self::l('Invoicing'), 0, 'L'); $pdf->Ln(5); - $pdf->SetFont('Arial', '', 9); + $pdf->SetFont(self::fontname(), '', 9); if (!empty($delivery_address->company) OR !empty($invoice_address->company)) { - $pdf->Cell($width, 10, utf8_decode($delivery_address->company), 0, 'L'); - $pdf->Cell($width, 10, utf8_decode($invoice_address->company), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $delivery_address->company), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $invoice_address->company), 0, 'L'); $pdf->Ln(5); } - $pdf->Cell($width, 10, utf8_decode($delivery_address->surname).' '.utf8_decode($delivery_address->name), 0, 'L'); - $pdf->Cell($width, 10, utf8_decode($invoice_address->surname).' '.utf8_decode($invoice_address->name), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $delivery_address->surname).' '.iconv('utf-8', self::encoding(), $delivery_address->name), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $invoice_address->surname).' '.iconv('utf-8', self::encoding(), $invoice_address->name), 0, 'L'); $pdf->Ln(5); - $pdf->Cell($width, 10, utf8_decode($delivery_address->address1), 0, 'L'); - $pdf->Cell($width, 10, utf8_decode($invoice_address->address1), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $delivery_address->address1), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $invoice_address->address1), 0, 'L'); $pdf->Ln(5); if (!empty($invoice_address->address2) OR !empty($delivery_address->address2)) { - $pdf->Cell($width, 10, utf8_decode($delivery_address->address2), 0, 'L'); - $pdf->Cell($width, 10, utf8_decode($invoice_address->address2), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $delivery_address->address2), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $invoice_address->address2), 0, 'L'); $pdf->Ln(5); } - $pdf->Cell($width, 10, $delivery_address->postcode.' '.utf8_decode($delivery_address->city), 0, 'L'); - $pdf->Cell($width, 10, $invoice_address->postcode.' '.utf8_decode($invoice_address->city), 0, 'L'); + $pdf->Cell($width, 10, $delivery_address->postcode.' '.iconv('utf-8', self::encoding(), $delivery_address->city), 0, 'L'); + $pdf->Cell($width, 10, $invoice_address->postcode.' '.iconv('utf-8', self::encoding(), $invoice_address->city), 0, 'L'); $pdf->Ln(5); - $pdf->Cell($width, 10, utf8_decode($delivery_address->country), 0, 'L'); - $pdf->Cell($width, 10, utf8_decode($invoice_address->country), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $delivery_address->country), 0, 'L'); + $pdf->Cell($width, 10, iconv('utf-8', self::encoding(), $invoice_address->country), 0, 'L'); $pdf->Ln(5); $pdf->Cell($width, 10, $delivery_address->phone, 0, 'L'); if (!empty($delivery_address->phone_mobile)) @@ -194,14 +251,14 @@ $pdf->Ln(12); $pdf->SetFillColor(240, 240, 240); $pdf->SetTextColor(0, 0, 0); - $pdf->SetFont('Arial', '', 9); + $pdf->SetFont(self::fontname(), '', 9); $pdf->Cell(0, 6, self::l('INVOICE #').sprintf('%06d', self::$order->id).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->date_upd, self::$order->id_lang), 1, 2, 'L', 1); $pdf->Cell(75, 6, self::l('Order date:').' '.Tools::displayDate(self::$order->date_add, self::$order->id_lang), 'L', 0); - $pdf->Cell(50, 6, self::l('Carrier:').' '.utf8_decode($carrier->name), 'L'); - $pdf->Cell(0, 6, self::l('Payment method:').' '.utf8_decode($order->payment), 'LR'); + $pdf->Cell(50, 6, self::l('Carrier:').' '.iconv('utf-8', self::encoding(), $carrier->name), 'L'); + $pdf->Cell(0, 6, self::l('Payment method:').' '.iconv('utf-8', self::encoding(), $order->payment), 'LR'); $pdf->Ln(5); $pdf->Cell(75, 6, (isset($shipping_date) ? self::l('Shipping date:').' '.Tools::displayDate($shipping_date, self::$order->id_lang) : ' '), 'LB', 0); - $pdf->Cell(50, 6, ($shop_country ? self::l('Origin:').' '.utf8_decode($shop_country) : ' '), 'LRB'); + $pdf->Cell(50, 6, ($shop_country ? self::l('Origin:').' '.iconv('utf-8', self::encoding(), $shop_country) : ' '), 'LRB'); $pdf->Cell(0, 6, ' ', 'LRB'); $pdf->Ln(15); $pdf->ProdTab(); @@ -211,7 +268,7 @@ * Display price summation */ $pdf->Ln(5); - $pdf->SetFont('Arial', 'B', 8); + $pdf->SetFont(self::fontname(), 'B', 8); $width = 165; $pdf->Cell($width, 0, self::l('Total products TI').' : ', 0, 0, 'R'); $pdf->Cell(0, 0, self::euro(Tools::displayPrice(self::$order->getTotalProductsWithTaxes(), self::$currency, true)), 0, 0, 'R'); @@ -251,12 +308,12 @@ array(self::l('Total'), 'R') ); $w = array(90, 15, 25, 10, 25, 25); - $this->SetFont('Arial', 'B', 8); + $this->SetFont(self::fontname(), 'B', 8); $this->SetFillColor(240, 240, 240); for($i = 0; $i < count($header); $i++) $this->Cell($w[$i], 5, $header[$i][0], 'T', 0, $header[$i][1], 1); $this->Ln(); - $this->SetFont('Arial', '', 7); + $this->SetFont(self::fontname(), '', 7); $products = self::$order->getProducts(); foreach($products AS $product) @@ -266,7 +323,7 @@ $total_with_tax = $product['total_wt']; $before = $this->GetY(); - $this->MultiCell($w[0], 5, utf8_decode($product['product_name']), 'B'); + $this->MultiCell($w[0], 5, iconv('utf-8', self::encoding(), $product['product_name']), 'B'); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0], $this->GetY() - $lineSize); $this->Cell($w[1], $lineSize, $product['product_reference'], 'B'); @@ -287,7 +344,7 @@ function DiscTab() { $w = array(90, 25, 15, 10, 25, 25); - $this->SetFont('Arial', 'B', 7); + $this->SetFont(self::fontname(), 'B', 7); $discounts = self::$order->getDiscounts(); foreach($discounts AS $discount) { @@ -311,14 +368,14 @@ { $header = array(self::l('Tax detail'), self::l('Tax %'), self::l('Pre-Tax Total'), self::l('Total Tax'), self::l('Total with Tax')); $w = array(60, 30, 40, 30, 30); - $this->SetFont('Arial', 'B', 8); + $this->SetFont(self::fontname(), 'B', 8); for($i = 0; $i < count($header); $i++) { $this->Cell($w[$i], 5, $header[$i], 0, 0, 'R'); } $this->Ln(); - $this->SetFont('Arial', '', 7); + $this->SetFont(self::fontname(), '', 7); $products = self::$order->getProducts(); $total_with_tax = array(); @@ -381,7 +438,21 @@ static private function l($key) { - return (utf8_decode(Tools::historyc_l($key, self::$_translations))); + return (iconv('utf-8', self::encoding(), Tools::historyc_l($key, self::$_translations))); + } + + static private function encoding() { + return is_array(self::$_pdfparams[self::$_iso]) && self::$_pdfparams[self::$_iso]['encoding'] ? self::$_pdfparams[self::$_iso]['encoding'] : 'iso-8859-1'; + } + + static private function embedfont() { + return is_array(self::$_pdfparams[self::$_iso]) && self::$_pdfparams[self::$_iso]['font'] ? self::$_pdfparams[self::$_iso]['font'] : false; + } + + static private function fontname() { + $font = self::embedfont(); + + return $font ? $font : 'Arial'; } }