- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/lib/component/userprofile/stresslevel/img.php
- Класс: BitrixIntranetComponentUserProfileStressLevelImg
- Вызов: Img::drawImageRectangle
protected function drawImageRectangle(array $params = [])
{
$result = false;
$type = (
isset($params['type'])
? $params['type']
: false
);
$value = (
isset($params['value'])
? intval($params['value'])
: 0
);
$canvas = (
isset($params['canvas'])
? $params['canvas']
: false
);
$factor = $this->factor;
if (
!$canvas
|| !$type
|| $type == ''
)
{
return $result;
}
$textTypeValue = StressLevel::getTypeDescription($type, $value);
if ($textTypeValue <> '')
{
$textType = new ImagickDraw();
$fontPath = $this->getImagePartsPath().'/OpenSans-Semibold.ttf';
if (!file_exists($fontPath))
{
return false;
}
$textType->setFont($fontPath);
$textType->setFillColor('white');
$textType->setStrokeAntialias(true);
$textType->setTextAntialias(true);
$textType->setFontSize($factor*12);
$error = "";
if (LANG_CHARSET != "UTF-8")
{
$textTypeValue = BitrixMainTextEncoding::convertEncoding($textTypeValue, LANG_CHARSET, "UTF-8", $error);
if (
!$textTypeValue
&& !empty($error)
)
{
$this->errorCollection[] = new Error('CONVERT_CHARSET_ERROR');
return null;
}
}
$textMetrics = $canvas->queryFontMetrics($textType, $textTypeValue);
$rectangleWidth = $textMetrics['textWidth']/$factor + 40;
if ($rectangleWidth < 100)
{
$rectangleWidth = 100;
}
elseif ($rectangleWidth > 160)
{
$rectangleWidth = 160;
}
}
if (!$rectangleWidth)
{
return false;
}
$fillColor = '#c8cbce';
switch($type)
{
case 'red':
$fillColor = '#ff5752';
break;
case 'green':
$fillColor = '#9dcf00';
break;
case 'yellow':
$fillColor = '#f7a700';
break;
case 'unknown':
$fillColor = '#c8cbce';
break;
default:
}
$rectangle = new ImagickDraw();
$rectangle->setFillColor($fillColor);
$rectangleLeft = 148;
$rectangleRight = $rectangleLeft + $rectangleWidth;
$rectangle->roundRectangle($factor*$rectangleLeft, $factor*17, $factor*$rectangleRight, $factor*37, $factor*11, $factor*11);
$canvas->drawImage($rectangle);
if ($textType)
{
$textType->setTextAlignment(Imagick::ALIGN_CENTER);
$textType->annotation($factor*($rectangleLeft + $rectangleWidth/2), $factor*32, $textTypeValue);
$canvas->drawImage($textType);
}
return true;
}