Skip to content

Commit

Permalink
implemented configurable colours
Browse files Browse the repository at this point in the history
  • Loading branch information
sprankhub committed Oct 14, 2017
1 parent 9cf8a75 commit dc0c25a
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 15 deletions.
52 changes: 52 additions & 0 deletions src/app/code/community/FireGento/Pdf/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class FireGento_Pdf_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_SALES_PDF_CREDITMEMO_FILENAME_EXPORT_PATTERN_FOR_MULTIPLE_DOCUMENTS = 'sales_pdf/creditmemo/filename_export_pattern_for_multiple_documents';
const XML_PATH_SALES_PDF_FIREGENTO_PDF_PAGE_SIZE = 'sales_pdf/firegento_pdf/page_size';

const XML_PATH_COLOR_TEXT = 'sales_pdf/firegento_pdf_colors/text';
const XML_PATH_COLOR_LABELS = 'sales_pdf/firegento_pdf_colors/labels';
const XML_PATH_COLOR_TABLE_HEADER = 'sales_pdf/firegento_pdf_colors/table_header';
const XML_PATH_COLOR_FOOTER = 'sales_pdf/firegento_pdf_colors/footer';

const XML_PATH_REGULAR_FONT = 'sales_pdf/firegento_pdf_fonts/regular_font';
const XML_PATH_BOLD_FONT = 'sales_pdf/firegento_pdf_fonts/bold_font';
const XML_PATH_ITALIC_FONT = 'sales_pdf/firegento_pdf_fonts/italic_font';
Expand Down Expand Up @@ -412,4 +417,51 @@ public function getPageSizeConfigPath()
{
return Mage::getStoreConfig(self::XML_PATH_SALES_PDF_FIREGENTO_PDF_PAGE_SIZE);
}

/**
* Get configured PDF color
*
* @param string $path System config path
* @return Zend_Pdf_Color_Html
*/
protected function getColor($path)
{
return new Zend_Pdf_Color_Html('#' . trim($path), '#');
}
/**
* Get text color
*
* @return Zend_Pdf_Color_Html
*/
public function getTextColor()
{
return $this->getColor(Mage::getStoreConfig(self::XML_PATH_COLOR_TEXT));
}
/**
* Get table header color
*
* @return Zend_Pdf_Color_Html
*/
public function getHeaderColor()
{
return $this->getColor(Mage::getStoreConfig(self::XML_PATH_COLOR_TABLE_HEADER));
}
/**
* Get footer color
*
* @return Zend_Pdf_Color_Html
*/
public function getFooterColor()
{
return $this->getColor(Mage::getStoreConfig(self::XML_PATH_COLOR_FOOTER));
}
/**
* Get label color
*
* @return Zend_Pdf_Color_Html
*/
public function getLabelColor()
{
return $this->getColor(Mage::getStoreConfig(self::XML_PATH_COLOR_LABELS));
}
}
43 changes: 40 additions & 3 deletions src/app/code/community/FireGento/Pdf/Model/Engine/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public function __construct()
$this->colors['black'] = new Zend_Pdf_Color_GrayScale(0);
$this->colors['grey1'] = new Zend_Pdf_Color_GrayScale(0.9);

$helper = Mage::helper('firegento_pdf');

$this->colors['text'] = $helper->getTextColor();
$this->colors['labels'] = $helper->getLabelColor();
$this->colors['header'] = $helper->getHeaderColor();
$this->colors['footer'] = $helper->getFooterColor();

// get the default imprint
$this->_imprint = Mage::getStoreConfig('general/imprint');
}
Expand Down Expand Up @@ -163,7 +170,11 @@ public function drawLineBlocks(
}
break;
}
if (isset($column['color'])) {
$page->setFillColor($column['color']);
}
$page->drawText($part, $feed, $this->y - $top, 'UTF-8');
$page->setFillColor($this->colors['text']);
$top += $lineSpacing;
}

Expand Down Expand Up @@ -225,11 +236,13 @@ protected function _insertSenderAddessBar(&$page)
!= ''
) {
$this->_setFontRegular($page, 6);
$page->setFillColor($this->colors['labels']);
$page->drawText(
trim(Mage::getStoreConfig('sales_pdf/firegento_pdf/sender_address_bar')),
$this->margin['left'] + $this->getHeaderblockOffset(),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
}
}

Expand Down Expand Up @@ -467,7 +480,7 @@ protected function getHeaderblockOffset()
*/
protected function insertHeader(&$page, $order, $document)
{
$page->setFillColor($this->colors['black']);
$page->setFillColor($this->colors['text']);

$mode = $this->getMode();

Expand Down Expand Up @@ -502,11 +515,13 @@ protected function insertHeader(&$page, $order, $document)
} else {
$numberTitle = 'Creditmemo number:';
}
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__($numberTitle),
($this->margin['right'] - $labelRightOffset), $this->y,
$this->encoding
);
$page->setFillColor($this->colors['text']);

$incrementId = $document->getIncrementId();
$page->drawText(
Expand All @@ -521,11 +536,13 @@ protected function insertHeader(&$page, $order, $document)
// Order Number
$putOrderId = $this->_putOrderId($order);
if ($putOrderId) {
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('Order number:'),
($this->margin['right'] - $labelRightOffset),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
$page->drawText(
$putOrderId, ($this->margin['right'] - $valueRightOffset
- $this->widthForStringUsingFontSize(
Expand All @@ -540,11 +557,13 @@ protected function insertHeader(&$page, $order, $document)
if ($this->_showCustomerNumber($order->getStore())) {
$guestorderCustomerNo = $this->_getGuestorderCustomerNo($order->getStore());
if ($order->getCustomerId() != '' || $guestorderCustomerNo != '') {
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('Customer number:'),
($this->margin['right'] - $labelRightOffset),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
$numberOfLines++;
}

Expand Down Expand Up @@ -585,7 +604,7 @@ protected function insertHeader(&$page, $order, $document)
$numberOfLines++;
} elseif ($guestorderCustomerNo != '') {
$page->drawText(
$guestorderCustomerNo,
'-',
($this->margin['right'] - $valueRightOffset
- $this->widthForStringUsingFontSize('-', $font, 10)),
$this->y, $this->encoding
Expand All @@ -597,11 +616,13 @@ protected function insertHeader(&$page, $order, $document)

/** print VAT ID */
if ($this->_showCustomerVATNumber($order->getStore())) {
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('VAT-ID:'),
($this->margin['right'] - $labelRightOffset),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
if ($order->getBillingAddress()->getVatId()) {
$customerVatId = $order->getBillingAddress()->getVatId();
} elseif ($order->getCustomerTaxvat()) {
Expand All @@ -625,11 +646,13 @@ protected function insertHeader(&$page, $order, $document)
if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip',
$order->getStoreId())
) {
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('Customer IP:'),
($this->margin['right'] - $labelRightOffset),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
$customerIP = $order->getData('remote_ip');
$font = $this->_setFontRegular($page, 10);
$page->drawText(
Expand All @@ -642,12 +665,14 @@ protected function insertHeader(&$page, $order, $document)
$numberOfLines++;
}

$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__(($mode == 'invoice')
? 'Invoice date:' : 'Date:'),
($this->margin['right'] - $labelRightOffset), $this->y,
$this->encoding
);
$page->setFillColor($this->colors['text']);
$documentDate = Mage::helper('core')
->formatDate($document->getCreatedAtDate(), 'medium', false);
$page->drawText(
Expand All @@ -665,11 +690,13 @@ protected function insertHeader(&$page, $order, $document)
&& Mage::getStoreConfig('sales_pdf/invoice/payment_method_position')
== FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER);
if ($putPaymentMethod) {
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('Payment method:'),
($this->margin['right'] - $labelRightOffset),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
$paymentMethodArray = $this->_prepareText(
$order->getPayment()->getMethodInstance()->getTitle(), $page,
$font, 10, $width
Expand Down Expand Up @@ -704,11 +731,13 @@ protected function insertHeader(&$page, $order, $document)
== FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER);

if ($putShippingMethod && $order->getIsNotVirtual()) {
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('Shipping method:'),
($this->margin['right'] - $labelRightOffset),
$this->y, $this->encoding
);
$page->setFillColor($this->colors['text']);
$shippingMethodArray
= $this->_prepareText($order->getShippingDescription(), $page,
$font, 10, $width);
Expand All @@ -734,6 +763,8 @@ protected function insertHeader(&$page, $order, $document)

}
$this->y -= ($numberOfLines * 2);

$page->setFillColor($this->colors['text']);
}

/**
Expand Down Expand Up @@ -1068,7 +1099,8 @@ protected function _addFooter(&$page, $store = null)
*/
protected function _insertFooter(&$page)
{
$page->setLineColor($this->colors['black']);
$page->setLineColor($this->colors['footer']);
$page->setFillColor($this->colors['footer']);
$page->setLineWidth(0.5);
$page->drawLine($this->margin['left'] - 20, $this->y - 5,
$this->margin['right'] + 30, $this->y - 5);
Expand Down Expand Up @@ -1112,6 +1144,9 @@ protected function _insertFooter(&$page)
);
$this->_insertFooterBlock($page, $fields, 365, 60,
$this->margin['right'] - 375 - 10);

$page->setLineColor($this->colors['black']);
$page->setFillColor($this->colors['text']);
}

/**
Expand Down Expand Up @@ -1234,6 +1269,7 @@ protected function _insertFooterAddress(&$page, $store = null)
protected function _insertPageCounter(&$page)
{
$font = $this->_setFontRegular($page, 9);
$page->setFillColor($this->colors['labels']);
$page->drawText(
Mage::helper('firegento_pdf')->__('Page') . ' '
. $this->pagecounter,
Expand All @@ -1242,6 +1278,7 @@ protected function _insertPageCounter(&$page)
$this->y,
$this->encoding
);
$page->setFillColor($this->colors['text']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function getPdf($creditmemos = array())
*/
protected function _drawHeader(Zend_Pdf_Page $page)
{
$page->setFillColor($this->colors['grey1']);
$page->setLineColor($this->colors['grey1']);
$page->setFillColor($this->colors['header']);
$page->setLineColor($this->colors['header']);
$page->setLineWidth(1);
$page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public function getPdf($invoices = array())
*/
protected function insertTableHeader(&$page)
{
$page->setFillColor($this->colors['grey1']);
$page->setLineColor($this->colors['grey1']);
$page->setFillColor($this->colors['header']);
$page->setLineColor($this->colors['header']);
$page->setLineWidth(1);
$page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ protected function _insertCustomerAddress(&$page, $order)
*/
protected function insertTableHeader($page)
{
$page->setFillColor($this->colors['grey1']);
$page->setLineColor($this->colors['grey1']);
$page->setFillColor($this->colors['header']);
$page->setLineColor($this->colors['header']);
$page->setLineWidth(1);
$page->drawRectangle($this->margin['left'], $this->y,
$this->margin['right'] - 10, $this->y - 15);
Expand Down Expand Up @@ -214,15 +214,16 @@ protected function _printShipmentTracks($page, $order, $shipment)
return $page;
}
$this->y -= 20;
$page->setFillColor($this->colors['grey1']);
$page->setLineColor($this->colors['grey1']);
$page->setFillColor($this->colors['header']);
$page->setLineColor($this->colors['header']);
$page->setLineWidth(1);
$page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'] - 10, $this->y - 15);
$page->setFillColor($this->colors['black']);
$this->_setFontRegular($page, 9);
$this->y -= 11;
$page->drawText(Mage::helper('sales')->__('Carrier'), $this->margin['left'], $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Number'), 290, $this->y, 'UTF-8');
$page->setFillColor($this->colors['text']);
$this->y -= 18;
foreach ($tracks as $track) {
$maxTitleLen = 45;
Expand Down
6 changes: 4 additions & 2 deletions src/app/code/community/FireGento/Pdf/Model/Items/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function draw($position = 1)
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$helper = Mage::helper('firegento_pdf');
$lines = array();

$fontSize = 9;
Expand Down Expand Up @@ -78,8 +79,9 @@ public function draw($position = 1)
}
$optionArray = $pdf->_prepareText($optionTxt, $page, $pdf->getFontRegular(), $fontSize, 215);
$lines[][] = array(
'text' => $optionArray,
'feed' => $pdf->margin['left'] + 135
'text' => $optionArray,
'feed' => $pdf->margin['left'] + 135,
'color' => $helper->getLabelColor(),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function draw($position = 1)
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$helper = Mage::helper('firegento_pdf');
$lines = array();

$fontSize = 9;
Expand Down Expand Up @@ -83,8 +84,9 @@ public function draw($position = 1)
$optionArray = $pdf->_prepareText($optionTxt, $page,
$pdf->getFontRegular(), $fontSize, 215);
$lines[][] = array(
'text' => $optionArray,
'feed' => $pdf->margin['left'] + 135
'text' => $optionArray,
'feed' => $pdf->margin['left'] + 135,
'color' => $helper->getLabelColor(),
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/app/code/community/FireGento/Pdf/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@
<bold_font/>
<italic_font/>
</firegento_pdf_fonts>
<firegento_pdf_colors>
<text>000000</text>
<labels>666666</labels>
<table_header>eeeeee</table_header>
<footer>888888</footer>
</firegento_pdf_colors>
<invoice>
<engine>firegento_pdf/engine_invoice_default</engine>
<show_customer_number>1</show_customer_number>
Expand Down
Loading

0 comments on commit dc0c25a

Please sign in to comment.