コード例 #1
0
ファイル: Language.php プロジェクト: mykitty/jyotish
 /**
  * Convert translit symbol to html code.
  * 
  * @param string $tr
  * @return string
  * @throws Exception\InvalidArgumentException
  */
 protected static function trToHtml($tr)
 {
     if (in_array($tr, self::$notTranslit)) {
         return $tr;
     }
     if (defined('static::' . $tr)) {
         return Utility::unicodeToHtml(constant('static::' . $tr));
     } else {
         throw new Exception\InvalidArgumentException("Transliteration '{$tr}' is not defined.");
     }
 }
コード例 #2
0
ファイル: Svg.php プロジェクト: mykitty/jyotish
 public function drawText($text, $x = 0, $y = 0, array $options = null)
 {
     if (isset($options)) {
         $this->setOptions($options);
     }
     $colorRgb = Utility::htmlToRgb($this->options['fontColor']);
     $color = 'rgb(' . implode(', ', $colorRgb) . ')';
     $attributes['x'] = $x;
     $attributes['y'] = $y;
     $attributes['fill'] = $color;
     $attributes['font-size'] = $this->options['fontSize'] * 1.2;
     switch ($this->options['textAlign']) {
         case 'center':
             $textAnchor = 'middle';
             break;
         case 'right':
             $textAnchor = 'end';
             break;
         case 'left':
         default:
             $textAnchor = 'start';
             break;
     }
     switch ($this->options['textValign']) {
         case 'top':
             $attributes['y'] += $this->options['fontSize'];
             break;
         case 'middle':
             $attributes['y'] += $this->options['fontSize'] / 2;
             break;
         case 'bottom':
         default:
             $attributes['y'] += 0;
             break;
     }
     $attributes['style'] = 'text-anchor: ' . $textAnchor;
     $attributes['transform'] = 'rotate(' . -$this->options['textOrientation'] . ', ' . $x . ', ' . $y . ')';
     $this->appendRootElement('text', $attributes, html_entity_decode($text, ENT_COMPAT | ENT_HTML5, 'UTF-8'));
 }
コード例 #3
0
ファイル: Renderer.php プロジェクト: mykitty/jyotish
 /**
  * Return body label.
  * 
  * @param string $body
  * @param array $options
  * @return string
  */
 protected function getBodyLabel($body, array $options)
 {
     switch ($options['labelGrahaType']) {
         case 0:
             $label = $body;
             break;
         case 1:
             if (array_key_exists($body, Graha::$graha)) {
                 $grahaObject = Graha::getInstance($body);
                 $label = Utility::unicodeToHtml($grahaObject->grahaUnicode);
             } else {
                 $label = $body;
             }
             break;
         case 2:
             $label = call_user_func($options['labelGrahaCallback'], $body);
             break;
         default:
             $label = $body;
             break;
     }
     $data = $this->Data->getData();
     if (array_key_exists($body, Graha::listGraha(Graha::LIST_SAPTA))) {
         $vakraCheshta = $data['graha'][$body]['speed'] < 0 ? true : false;
     } else {
         $vakraCheshta = false;
     }
     $grahaLabel = $vakraCheshta ? '(' . $label . ')' : $label;
     return $grahaLabel;
 }
コード例 #4
0
ファイル: Image.php プロジェクト: kunjara/jyotish-draw
 /**
  * Draw text string.
  * 
  * @param string $text Text for drawing
  * @param int $x x-coordinate
  * @param int $y y-coordinate
  * @param array $options
  * @throws Exception\RuntimeException
  */
 public function drawText($text, $x = 0, $y = 0, array $options = null)
 {
     $this->setOptions($options);
     $colorRgb = Utility::htmlToRgb($this->optionFontColor);
     $color = $this->allocateColor($this->Resource, $colorRgb['r'], $colorRgb['g'], $colorRgb['b']);
     if ($this->optionFontName == null) {
         $this->optionFontName = 3;
     }
     if (is_numeric($this->optionFontName)) {
         if ($this->optionTextOrientation) {
             throw new Exception\RuntimeException('No orientation possible with GD internal font.');
         }
         $fontWidth = imagefontwidth($this->optionFontName);
         $fontHeight = imagefontheight($this->optionFontName);
         switch ($this->optionTextAlign) {
             case 'left':
                 $positionX = $x;
                 break;
             case 'center':
                 $positionX = $x - ceil($fontWidth * strlen($text) / 2);
                 break;
             case 'right':
                 $positionX = $x - $fontWidth * strlen($text);
                 break;
         }
         switch ($this->optionTextValign) {
             case 'top':
                 $positionY = $y;
                 break;
             case 'middle':
                 $positionY = $y - $fontHeight / 2;
                 break;
             case 'bottom':
                 $positionY = $y - $fontHeight + 1;
                 break;
         }
         imagestring($this->Resource, $this->optionFontName, $positionX, $positionY, $text, $color);
     } else {
         if (!function_exists('imagettfbbox')) {
             throw new Exception\RuntimeException('A font was provided, but this instance of PHP does not have TTF (FreeType) support');
         }
         $box = imagettfbbox($this->optionFontSize, 0, $this->optionFontName, $text);
         switch ($this->optionTextAlign) {
             case 'center':
                 $width = ($box[2] - $box[0]) / 2;
                 break;
             case 'right':
                 $width = $box[2] - $box[0];
                 break;
             case 'left':
             default:
                 $width = 0;
                 break;
         }
         switch ($this->optionTextValign) {
             case 'top':
                 $height = $box[1] - $box[7];
                 break;
             case 'middle':
                 $height = ($box[1] - $box[7]) / 2;
                 break;
             case 'bottom':
             default:
                 $height = 0;
                 break;
         }
         imagettftext($this->Resource, $this->optionFontSize, $this->optionTextOrientation, $x - $width * cos(pi() * $this->optionTextOrientation / 180) + $height * sin(pi() * $this->optionTextOrientation / 180), $y + $height * cos(pi() * $this->optionTextOrientation / 180) + $width * sin(pi() * $this->optionTextOrientation / 180), $color, $this->optionFontName, $text);
     }
 }