how to calculate the textsize of TLatex in CernRoot

these code can be used in the SetTextSize(TextSizeValue(textsize0, cc, gPad)), where cc is a pointer of TCanvas;

double pad_width_for_textSizeValue0;
double pad_height_for_textSizeValue0;
double pad_width_for_textSizeValue;
double pad_height_for_textSizeValue;
double rel_charheight_for_textSizeValue0;
double rel_charheight_for_textSizeValue;
double ans_for_textSizeValue;
double TextSizeValue(double textsize0, TPad * pad0, TPad * pad)
{
    pad_width_for_textSizeValue0 = pad0->XtoPixel(pad0->GetX2());
    pad_height_for_textSizeValue0 = pad0->YtoPixel(pad0->GetY1());
    if(pad_width_for_textSizeValue0 < pad_height_for_textSizeValue0)
        rel_charheight_for_textSizeValue0 = pad_width_for_textSizeValue0;
    else
        rel_charheight_for_textSizeValue0 = pad_height_for_textSizeValue0;
    pad_width_for_textSizeValue = pad->XtoPixel(pad->GetX2());
    pad_height_for_textSizeValue = pad->YtoPixel(pad->GetY1());
    if(pad_width_for_textSizeValue < pad_height_for_textSizeValue)
        rel_charheight_for_textSizeValue = pad_width_for_textSizeValue;
    else
        rel_charheight_for_textSizeValue = pad_height_for_textSizeValue;
    ans_for_textSizeValue = (rel_charheight_for_textSizeValue0 * textsize0)
                            / rel_charheight_for_textSizeValue;
    return ans_for_textSizeValue;
}


ref: https://root.cern.ch/doc/master/classTAttText.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章