尝试向现有的PHP库中添加功能

时间:2018-08-13 05:23:28

标签: php

我正在尝试向已存在的php lib(不再维护)中添加一个函数。

我要实现的目标是能够使文本居中对齐/对齐/左对齐/右对齐。

这是该库的git链接。

https://github.com/armagedan/thaana_text_render_php

这是我到目前为止所去的地方。

//Creating property
//So by default, this will be centered

private $textAlign = 'center';


public function __construct($fontPath=NULL, $fontName=NULL, $fontSize=NULL, $textColor=NULL, $textAlpha=NULL, $textLineSpacing=NULL, $bgColor=NULL, $bgAlpha=NULL, $shadowOffset=NULL, $shadowColor=NULL, $shadowAlpha=NULL, $textAlign =NULL)
    {
        // Initialize with specified defaults:
        if (!empty($fontPath)) $this->setFontPath($fontPath);
        if (!empty($fontName)) $this->setFont($fontName);
        if (!empty($fontSize)) $this->setFontSize($fontSize);
        if (!empty($textColor)) $this->setTextColor($textColor, $textAlpha);
        if (!empty($textLineSpacing)) $this->setTextLineSpacing($textLineSpacing);
        if (!empty($bgColor)) $this->setBgColor($bgColor, $bgAlpha);
        if (!empty($shadowOffset)) $this->setShadow($shadowOffset, $shadowColor, $shadowAlpha);

        //This one I added
        if (!empty($textAlign )) $this->setAlignment($textAlign);
    }

这是函数:

public function setAlignment($textAlign=NULL)
    {
        //What to do here?
        //So basically if the $textAlignment is null, then use the default one correct? Else use the user defined one?
    }

所以我想做的是添加一个名为setAlignment的函数,该函数会将文本的对齐方式设置为左/中/右等...类似于Microsoft Word等。但是我不知道从这里继续。我希望构造函数的最后一个参数具有对齐选项。

0 个答案:

没有答案
相关问题