深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 448|回复: 0
打印 上一主题 下一主题

pChart写文字(drawText)

[复制链接]

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
跳转到指定楼层
楼主
发表于 2022-1-5 22:11:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
   /* Write text */
   function drawText($X,$Y,$Text,$Format="")
    {
     $R                        = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
     $G                        = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
     $B                        = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
     $Angle                = isset($Format["Angle"]) ? $Format["Angle"] : 0;
     $Align                = isset($Format["Align"]) ? $Format["Align"] : TEXT_ALIGN_BOTTOMLEFT;
     $Alpha                = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
     $FontName                = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
     $FontSize                = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
     $ShowOrigine        = isset($Format["ShowOrigine"]) ? $Format["ShowOrigine"] : FALSE;
     $TOffset                = isset($Format["TOffset"]) ? $Format["TOffset"] : 2;
     $DrawBox                = isset($Format["DrawBox"]) ? $Format["DrawBox"] : FALSE;
     $DrawBoxBorder        = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : TRUE;
     $BorderOffset        = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 6;
     $BoxRounded        = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : FALSE;
     $RoundedRadius        = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 6;
     $BoxR                = isset($Format["BoxR"]) ? $Format["BoxR"] : 255;
     $BoxG                = isset($Format["BoxG"]) ? $Format["BoxG"] : 255;
     $BoxB                = isset($Format["BoxB"]) ? $Format["BoxB"] : 255;
     $BoxAlpha                = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
     $BoxSurrounding        = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
     $BoxBorderR        = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
     $BoxBorderG        = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
     $BoxBorderB        = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
     $BoxBorderAlpha        = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
     $NoShadow                = isset($Format["NoShadow"]) ? $Format["NoShadow"] : FALSE;

     $Shadow = $this->Shadow;
     if ( $NoShadow ) { $this->Shadow = FALSE; }

     if ( $BoxSurrounding != "" ) { $BoxBorderR = $BoxR - $BoxSurrounding; $BoxBorderG = $BoxG - $BoxSurrounding; $BoxBorderB = $BoxB - $BoxSurrounding; $BoxBorderAlpha = $BoxAlpha; }

     if ( $ShowOrigine )
      {
       $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
       $this->drawRectangleMarker($X,$Y,$MyMarkerSettings);
      }

     $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text);

     if ( $DrawBox && ($Angle == 0 || $Angle == 90 || $Angle == 180 || $Angle == 270))
      {
       $T[0]["X"]=0;$T[0]["Y"]=0;$T[1]["X"]=0;$T[1]["Y"]=0;$T[2]["X"]=0;$T[2]["Y"]=0;$T[3]["X"]=0;$T[3]["Y"]=0;
       if ( $Angle == 0 ) { $T[0]["X"]=-$TOffset;$T[0]["Y"]=$TOffset;$T[1]["X"]=$TOffset;$T[1]["Y"]=$TOffset;$T[2]["X"]=$TOffset;$T[2]["Y"]=-$TOffset;$T[3]["X"]=-$TOffset;$T[3]["Y"]=-$TOffset; }

       $X1 = min($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) - $BorderOffset + 3;
       $Y1 = min($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) - $BorderOffset;
       $X2 = max($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) + $BorderOffset + 3;
       $Y2 = max($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) + $BorderOffset - 3;

       $X1 = $X1 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
       $Y1 = $Y1 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
       $X2 = $X2 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
       $Y2 = $Y2 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];

       $Settings = array("R"=>$BoxR,"G"=>$BoxG,"B"=>$BoxB,"Alpha"=>$BoxAlpha,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"BorderAlpha"=>$BoxBorderAlpha);

       if ( $BoxRounded )
        { $this->drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$RoundedRadius,$Settings); }
       else
        { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Settings); }
      }

     $X = $X - $TxtPos[$Align]["X"] + $X;
     $Y = $Y - $TxtPos[$Align]["Y"] + $Y;

     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $C_ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
       imagettftext($this->Picture,$FontSize,$Angle,$X+$this->ShadowX,$Y+$this->ShadowY,$C_ShadowColor,$FontName,$Text);
      }

     $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B,$Alpha);
     imagettftext($this->Picture,$FontSize,$Angle,$X,$Y,$C_TextColor,$FontName,$Text);

     $this->Shadow = $Shadow;

     return($TxtPos);
    }


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-4 17:53 , Processed in 0.026256 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表