Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Usa_Block_Adminhtml_Dhl_Unitofmeasure
  • Mage_Usa_Helper_Data
  • Mage_Usa_Model_Shipping_Carrier_Abstract
  • Mage_Usa_Model_Shipping_Carrier_Abstract_Source_Mode
  • Mage_Usa_Model_Shipping_Carrier_Abstract_Source_Requesttype
  • Mage_Usa_Model_Shipping_Carrier_Dhl
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Contenttype
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Abstract
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Doc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Freedoc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Freenondoc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Nondoc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Size
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Unitofmeasure
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Dutypaymenttype
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Protection_Rounding
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Protection_Value
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Shipmenttype
  • Mage_Usa_Model_Shipping_Carrier_Fedex
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Dropoff
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Packaging
  • Mage_Usa_Model_Shipping_Carrier_Ups
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Container
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_DestType
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_OriginShipment
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Pickup
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Type
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Unitofmeasure
  • Mage_Usa_Model_Shipping_Carrier_Usps
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Container
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Machinable
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Size
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Usa
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * DHL International (API v1.4) Label Creation
 29:  *
 30:  * @category Mage
 31:  * @package  Mage_Usa
 32:  * @author   Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page extends Zend_Pdf_Page
 35: {
 36:     /**
 37:      * Text align constants
 38:      */
 39:     const ALIGN_RIGHT = 'right';
 40:     const ALIGN_LEFT = 'left';
 41:     const ALIGN_CENTER = 'center';
 42: 
 43:     /**
 44:      * Dhl International Label Creation Class Pdf Page constructor
 45:      * Create/Make a copy of pdf page
 46:      *
 47:      * @param Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page|string $param1
 48:      * @param null $param2
 49:      * @param null $param3
 50:      */
 51:     public function __construct($param1, $param2 = null, $param3 = null)
 52:     {
 53:         if ($param1 instanceof Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
 54:             && $param2 === null && $param3 === null
 55:         ) {
 56:             $this->_contents = $param1->getContents();
 57:         }
 58:         parent::__construct($param1, $param2, $param3);
 59:     }
 60: 
 61:     /**
 62:      * Get PDF Page contents
 63:      *
 64:      * @return string
 65:      */
 66:     public function getContents()
 67:     {
 68:         return $this->_contents;
 69:     }
 70: 
 71:     /**
 72:      * Calculate the width of given text in points taking into account current font and font-size
 73:      *
 74:      * @param string $text
 75:      * @param Zend_Pdf_Resource_Font $font
 76:      * @param float $font_size
 77:      * @return float
 78:      */
 79:     public function getTextWidth($text, Zend_Pdf_Resource_Font $font, $font_size)
 80:     {
 81:         $drawing_text = iconv('', 'UTF-16BE', $text);
 82:         $characters = array();
 83:         for ($i = 0; $i < strlen($drawing_text); $i++) {
 84:             $characters[] = (ord($drawing_text[$i++]) << 8) | ord($drawing_text[$i]);
 85:         }
 86:         $glyphs = $font->glyphNumbersForCharacters($characters);
 87:         $widths = $font->widthsForGlyphs($glyphs);
 88:         $text_width = (array_sum($widths) / $font->getUnitsPerEm()) * $font_size;
 89:         return $text_width;
 90:     }
 91: 
 92:     /**
 93:      * Draw a line of text at the specified position.
 94:      *
 95:      * @param string $text
 96:      * @param float $x
 97:      * @param float $y
 98:      * @param string $charEncoding (optional) Character encoding of source text.
 99:      *   Defaults to current locale.
100:      * @param $align
101:      * @throws Zend_Pdf_Exception
102:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
103:      */
104:     public function drawText($text, $x, $y, $charEncoding = '', $align = self::ALIGN_LEFT)
105:     {
106:         $left = null;
107:         switch ($align) {
108:             case self::ALIGN_LEFT:
109:                 $left = $x;
110:                 break;
111: 
112:             case self::ALIGN_CENTER:
113:                 $textWidth = $this->getTextWidth($text, $this->getFont(), $this->getFontSize());
114:                 $left = $x - ($textWidth / 2);
115:                 break;
116: 
117:             case self::ALIGN_RIGHT:
118:                 $textWidth = $this->getTextWidth($text, $this->getFont(), $this->getFontSize());
119:                 $left = $x - $textWidth;
120:                 break;
121:         }
122:         return parent::drawText($text, $left, $y, $charEncoding);
123:     }
124: 
125:     /**
126:      * Draw a text paragraph taking into account the maximum number of symbols in a row.
127:      * If line is longer - spit it.
128:      *
129:      * @param array $lines
130:      * @param int $x
131:      * @param int $y
132:      * @param int $maxWidth - number of symbols
133:      * @param string $align
134:      * @throws Zend_Pdf_Exception
135:      * @return float
136:      */
137:     public function drawLines($lines, $x, $y, $maxWidth, $align = self::ALIGN_LEFT)
138:     {
139:         foreach ($lines as $line) {
140:             if (strlen($line) > $maxWidth) {
141:                 $subLines = Mage::helper('core/string')->str_split($line, $maxWidth, true, true);
142:                 $y = $this->drawLines(array_filter($subLines), $x, $y, $maxWidth, $align);
143:                 continue;
144:             }
145:             $this->drawText($line, $x, $y, null, $align);
146:             $y -= ceil($this->getFontSize());
147:         }
148:         return $y;
149:     }
150: }
151: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0