Overview

Namespaces

  • MOC
    • Adapter
    • Core
      • Changelog
      • Depending
      • Drive
        • Directory
        • File
      • Error
        • Register
        • Type
      • Journal
      • Proxy
      • Template
      • Xml
    • Extension
      • Excel
      • Flot
      • Mail
      • Pdf
      • Word
      • Xml
      • YUICompressor
      • Zip
    • Generic
      • Common
      • Device
        • Extension
        • Widget
    • Module
      • Database
        • Driver
      • Drive
      • Image
        • Font
      • Installer
      • Network
        • Ftp
          • Directory
          • File
          • Transport
        • Http
        • ParcelTracker
          • Carrier
      • Office
        • Chart
          • Axis
        • Document
          • Excel
            • Cell
              • Format
              • Style
                • Border
                  • Bottom
                  • Left
                  • Right
                  • Top
                • Font
            • Close
            • Page
            • Worksheet
          • Pdf
            • Close
            • Font
            • Page
              • Margin
              • Position
            • Text
          • Xml
            • Close
        • Image
        • Mail
          • Address
          • Content
      • Packer
        • Yui
        • Zip
      • Template
    • Plugin
      • Gateway
      • Repository
      • Shared
  • PHP

Classes

  • Close
  • Filter
  • Font
  • Open
  • Resize
  • Resource
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * LICENSE (BSD)
  4:  *
  5:  * Copyright (c) 2012, Gerd Christian Kunze
  6:  * All rights reserved.
  7:  *
  8:  * Redistribution and use in source and binary forms, with or without
  9:  * modification, are permitted provided that the following conditions are
 10:  * met:
 11:  *
 12:  *  * Redistributions of source code must retain the above copyright
 13:  *    notice, this list of conditions and the following disclaimer.
 14:  *
 15:  *  * Redistributions in binary form must reproduce the above copyright
 16:  *    notice, this list of conditions and the following disclaimer in the
 17:  *    documentation and/or other materials provided with the distribution.
 18:  *
 19:  *  * Neither the name of Gerd Christian Kunze nor the names of the
 20:  *    contributors may be used to endorse or promote products derived from
 21:  *    this software without specific prior written permission.
 22:  *
 23:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 24:  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 25:  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 26:  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 27:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 28:  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 29:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 30:  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 31:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 32:  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 33:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 34:  *
 35:  * Font
 36:  * 11.02.2013 14:33
 37:  */
 38: namespace MOC\Module\Office\Image;
 39: use MOC\Api;
 40: use MOC\Generic\Device\Module;
 41: use MOC\Module\Office\Image\Resource;
 42: 
 43: /**
 44:  *
 45:  */
 46: class Font implements Module {
 47:     /**
 48:      * Get Singleton/Instance
 49:      *
 50:      * @static
 51:      * @return Font
 52:      */
 53:     public static function InterfaceInstance() {
 54:         return new Font();
 55:     }
 56: 
 57:     /**
 58:      * Get Dependencies
 59:      *
 60:      * @static
 61:      * @return \MOC\Core\Depending
 62:      */
 63:     public static function InterfaceDepending() {
 64:         return Api::Core()->Depending();
 65:     }
 66: 
 67:     /**
 68:      * Get Changelog
 69:      *
 70:      * @static
 71:      * @return \MOC\Core\Changelog
 72:      */
 73:     public static function InterfaceChangelog() {
 74:         return Api::Core()->Changelog();
 75:     }
 76: 
 77:     /** @var null|Resource $Resource */
 78:     private $Resource = null;
 79: 
 80:     /**
 81:      * @param Resource $Resource
 82:      *
 83:      * @return Font
 84:      */
 85:     public function UseResource( Resource $Resource ) {
 86:         $this->Resource = $Resource;
 87:         return $this;
 88:     }
 89: 
 90:     /**
 91:      * @param        $FontLocation
 92:      * @param        $Text
 93:      * @param int    $Size
 94:      * @param string $Color
 95:      */
 96:     public function EmbeddedImage( $FontLocation, $Text, $Size = 12, $Color = '#000000' ) {
 97:         // TODO: Implement correct ... -.-
 98:         /*
 99:         $Font = __DIR__.'/../../Style/Framework/Resource/Font/CorpoA.ttf';
100:         $Text = self::ConvertToNCR( Api::Core()->Encoding()->MixedToLatin1( $Text ) );
101:         $Color = '#777777';
102:         $Size = 35;
103: 
104:         // Fetch Font-Box
105:         $TextBox = imagettfbbox( $Size, 0, $Font, $Text );
106:         // Fetch Dimensions ( + 2 px = FIX: FontStyle )
107:         $Width = abs($TextBox[2]) + abs($TextBox[0]) + 2;
108:         $Height = abs($TextBox[7]) + abs($TextBox[1]);
109: 
110:         $Image = Api::Module()->Image()->Resource()->Create( $Width, $Height );
111: 
112:         $Color = self::ConvertHEXToRGB( $Color );
113: 
114:         imagettftext( $Image->Get(), $Size, 0, 0 , abs( $TextBox[5] ),
115:             imagecolorallocate( $Image->Get(), $Color[0],$Color[1],$Color[2] ),
116:             $Font, $Text
117:         );
118: 
119:         $ResizeWidth = $Width * 0.45;
120:         $ResizeHeight = $Height * 0.59;
121: 
122:         $ResizeImage = Api::Module()->Image()->Resource()->Create( $ResizeWidth, $ResizeHeight );
123: 
124:         imagecopyresampled( $ResizeImage->Get(), $Image->Get(), 0, 0, 0, 0, $ResizeWidth, $ResizeHeight, $Width, $Height );
125: 
126:         ob_start();
127:         imagepng( $ResizeImage->Get() );
128:         $Image = ob_get_clean();
129: 
130:         return 'data:image/png;base64,'.base64_encode( $Image );
131:         */
132:     }
133: 
134:     /**
135:      * @param $Color
136:      *
137:      * @return array
138:      */
139:     private function ConvertHEXToRGB( $Color ) {
140:         $Hex = str_split( substr( strtoupper( trim( $Color ) ), (strlen($Color)>4?-6:-3) ), (strlen($Color)>4?2:1) );
141:         foreach( (array)$Hex as $Index => $Color ){
142:             $Hex[$Index] = hexdec( str_pad( $Color, 2, $Color, STR_PAD_LEFT ) );
143:         } return $Hex;
144:     }
145: 
146:     /**
147:      * @param $Color
148:      *
149:      * @return array
150:      */
151:     /** @noinspection PhpUnusedPrivateMethodInspection */
152:     private function ConvertHEXToRGBFloat( $Color ) {
153:         $Hex = self::ConvertHEXToRGB( $Color );
154:         foreach( (array)$Hex as $Index => $Color ){
155:             $Hex[$Index] = (100 / 255 * $Color) / 100;
156:         } return $Hex;
157:     }
158: }
159: 
API documentation generated by ApiGen 2.8.0