Continued:
[core.git] / framework / main / classes / images / class_BaseImage.php
index e83375f9953c95608efa99ef07d3638f89c05cb5..a6f8faa5ef64b30a446a2da7119f70af8fded6a5 100644 (file)
@@ -5,13 +5,14 @@ namespace Org\Mxchange\CoreFramework\Image;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait;
 
 /**
  * A general image class
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -29,6 +30,9 @@ use Org\Mxchange\CoreFramework\Registry\Registerable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
+       // Load traits
+       use CompileableTemplateTrait;
+
        /**
         * Image type
         */
@@ -37,23 +41,23 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
        /**
         * Width of the image
         */
-       private $width = '';
+       private $width = 0;
 
        /**
         * Height of the image
         */
-       private $height = '';
+       private $height = 0;
 
        /**
         * X/Y
         */
-       private $x = '';
-       private $y = '';
+       private $x = 0;
+       private $y = 0;
 
        /**
         * Font size
         */
-       private $fontSize = '';
+       private $fontSize = 0;
 
        /**
         * Image string
@@ -63,20 +67,20 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
        /**
         * Background color in RGB
         */
-       private $backgroundColor = array(
+       private $backgroundColor = [
                'red'   => '',
                'green' => '',
                'blue'  => ''
-       );
+       ];
 
        /**
         * Foreground color in RGB
         */
-       private $foregroundColor = array(
+       private $foregroundColor = [
                'red'   => '',
                'green' => '',
                'blue'  => ''
-       );
+       ];
 
        /**
         * Current choosen color array
@@ -109,7 +113,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
        }
@@ -121,7 +125,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $colorChannel   Red, green or blue channel?
         * @param       $colorValue             Value to set
         */
-       private final function setColor ($colorMode, $colorChannel, $colorValue) {
+       private final function setColor (string $colorMode, string $colorChannel, $colorValue) {
                // Construct the eval() command
                $eval = sprintf("\$this->%s['%s'] = \"%s\";",
                        $colorMode,
@@ -140,7 +144,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $width  Width of the image
         * @return      void
         */
-       public final function setWidth ($width) {
+       public final function setWidth (int $width) {
                $this->width = $width;
        }
 
@@ -159,7 +163,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $height Height of the image
         * @return      void
         */
-       public final function setHeight ($height) {
+       public final function setHeight (int $height) {
                $this->height = $height;
        }
 
@@ -267,7 +271,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @return      void
         * @todo        Find something usefull for this method.
         */
-       public function initImageString ($groupable = 'single') {
+       public function initImageString (string $groupable = 'single') {
                $this->groupable = $groupable;
        }
 
@@ -288,11 +292,8 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @return      void
         */
        public final function setRed ($red) {
-               // Get array name
-               $arrayName = $this->colorMode;
-
                // Set image color
-               $this->setColor($arrayName, 'red', $red);
+               $this->setColor($this->colorMode, 'red', $red);
        }
 
        /**
@@ -302,11 +303,8 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @return      void
         */
        public final function setGreen ($green) {
-               // Get array name
-               $arrayName = $this->colorMode;
-
                // Set image color
-               $this->setColor($arrayName, 'green', $green);
+               $this->setColor($this->colorMode, 'green', $green);
        }
 
        /**
@@ -316,11 +314,8 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @return      void
         */
        public final function setBlue ($blue) {
-               // Get array name
-               $arrayName = $this->colorMode;
-
                // Set image color
-               $this->setColor($arrayName, 'blue', $blue);
+               $this->setColor($this->colorMode, 'blue', $blue);
        }
 
        /**
@@ -329,8 +324,8 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $string         String to set in image
         * @return      void
         */
-       public final function setString ($string) {
-               $this->imageString = (string) $string;
+       public final function setString (string $string) {
+               $this->imageString = $string;
        }
 
        /**
@@ -348,8 +343,8 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $imageType              Type to set in image
         * @return      void
         */
-       protected final function setImageType ($imageType) {
-               $this->imageType = (string) $imageType;
+       protected final function setImageType (string $imageType) {
+               $this->imageType = $imageType;
        }
 
        /**
@@ -367,8 +362,8 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $name   Name of the image
         * @return      void
         */
-       public final function setImageName ($name) {
-               $this->imageName = (string) $name;
+       public final function setImageName (string $name) {
+               $this->imageName = $name;
        }
 
        /**
@@ -395,7 +390,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $x      X coordinate
         * @return      void
         */
-       public final function setX ($x) {
+       public final function setX (int $x) {
                $this->x = $x;
        }
 
@@ -414,7 +409,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $y      Y coordinate
         * @return      void
         */
-       public final function setY ($y) {
+       public final function setY (int $y) {
                $this->y = $y;
        }
 
@@ -433,7 +428,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $fontSize       Font size for strings
         * @return      void
         */
-       public final function setFontSize ($fontSize) {
+       public final function setFontSize (int $fontSize) {
                $this->fontSize = $fontSize;
        }
 
@@ -452,7 +447,7 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @param       $stringName             String name to set
         * @return      void
         */
-       public final function setStringName($stringName) {
+       public final function setStringName(string $stringName) {
                $this->stringName = $stringName;
        }
 
@@ -462,12 +457,9 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
         * @return      void
         */
        public function finishImage () {
-               // Get template instance
-               $templateInstance = $this->getTemplateInstance();
-
                // Compile width and height
-               $width = $templateInstance->compileRawCode($this->getWidth());
-               $height = $templateInstance->compileRawCode($this->getHeight());
+               $width = $this->getTemplateInstance()->compileRawCode($this->getWidth());
+               $height = $this->getTemplateInstance()->compileRawCode($this->getHeight());
 
                // Set both again
                $this->setWidth($width);
@@ -477,9 +469,9 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
                $this->imageResource = imagecreatetruecolor($width, $height);
 
                // Compile background colors
-               $red   = $templateInstance->compileRawCode($this->backgroundColor['red']);
-               $green = $templateInstance->compileRawCode($this->backgroundColor['green']);
-               $blue  = $templateInstance->compileRawCode($this->backgroundColor['blue']);
+               $red   = $this->getTemplateInstance()->compileRawCode($this->backgroundColor['red']);
+               $green = $this->getTemplateInstance()->compileRawCode($this->backgroundColor['green']);
+               $blue  = $this->getTemplateInstance()->compileRawCode($this->backgroundColor['blue']);
 
                // Set all back
                $this->initBackgroundColor();
@@ -494,9 +486,9 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
                imagefill($this->getImageResource(), 0, 0, $backColor);
 
                // Compile foreground colors
-               $red   = $templateInstance->compileRawCode($this->foregroundColor['red']);
-               $green = $templateInstance->compileRawCode($this->foregroundColor['green']);
-               $blue  = $templateInstance->compileRawCode($this->foregroundColor['blue']);
+               $red   = $this->getTemplateInstance()->compileRawCode($this->foregroundColor['red']);
+               $green = $this->getTemplateInstance()->compileRawCode($this->foregroundColor['green']);
+               $blue  = $this->getTemplateInstance()->compileRawCode($this->foregroundColor['blue']);
 
                // Set all fore
                $this->initForegroundColor();
@@ -510,15 +502,15 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
                switch ($this->groupable) {
                        case 'single': // Single image string
                                // Compile image string
-                               $imageString = $templateInstance->compileRawCode($this->getString());
+                               $imageString = $this->getTemplateInstance()->compileRawCode($this->getString());
 
                                // Set it back
                                $this->setString($imageString);
 
                                // Compile X/Y coordinates and font size
-                               $x    = $templateInstance->compileRawCode($this->getX());
-                               $y    = $templateInstance->compileRawCode($this->getY());
-                               $size = $templateInstance->compileRawCode($this->getFontSize());
+                               $x    = $this->getTemplateInstance()->compileRawCode($this->getX());
+                               $y    = $this->getTemplateInstance()->compileRawCode($this->getY());
+                               $size = $this->getTemplateInstance()->compileRawCode($this->getFontSize());
 
                                // Set the image string
                                imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor);
@@ -526,22 +518,22 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable {
 
                        case 'groupable': // More than one string allowed
                                // Walk through all groups
-                               foreach ($templateInstance->getVariableGroups() as $group => $set) {
+                               foreach ($this->getTemplateInstance()->getVariableGroups() as $group => $set) {
                                        // Set the group
-                                       $templateInstance->setVariableGroup($group, false);
+                                       $this->getTemplateInstance()->setVariableGroup($group, false);
 
                                        // Compile image string
-                                       $imageString = $templateInstance->compileRawCode($this->getString());
+                                       $imageString = $this->getTemplateInstance()->compileRawCode($this->getString());
 
                                        // Compile X/Y coordinates and font size
-                                       $x    = $templateInstance->compileRawCode($this->getX());
-                                       $y    = $templateInstance->compileRawCode($this->getY());
-                                       $size = $templateInstance->compileRawCode($this->getFontSize());
+                                       $x    = $this->getTemplateInstance()->compileRawCode($this->getX());
+                                       $y    = $this->getTemplateInstance()->compileRawCode($this->getY());
+                                       $size = $this->getTemplateInstance()->compileRawCode($this->getFontSize());
 
                                        // Set the image string
                                        //* DEBUG: */ print __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}<br />\n";
                                        imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor);
-                               } // END - foreach
+                               }
                                break;
                }