duanca3415 2018-08-13 05:23
浏览 17

尝试将函数添加到现有的PHP库中

I am trying to add a function to an already existing php lib (which is not maintained anymore).

What I am trying to achieve is to be able to align the text to center/justify/left/right align.

Here is the git link of the library.

https://github.com/armagedan/thaana_text_render_php

Here is where I went so far.

//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);
    }

And here is the function:

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?
    }

So what I am trying to do is add a function called setAlignment which will set the alignment of the text to left/center/right etc... Like microsoft word and so on. But I do not know where to continue from here. I want the last parameter of the Constructor to have the alignment options.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c