25#include "../../../graf2d/mathtext/inc/mathtext.h"
26#include "../../../graf2d/mathtext/inc/mathrender.h"
56 public mathtext::math_text_renderer_t {
63 float _pad_pixel_transform[6];
67 float _current_font_size[mathtext::math_text_renderer_t::NFAMILY];
68 inline size_t root_face_number(
69 const unsigned int family,
const bool serif =
false)
const
71 static const int precision = 2;
73 if (family >= mathtext::math_text_renderer_t::
75 family <= mathtext::math_text_renderer_t::
77 const unsigned int offset = family -
78 mathtext::math_text_renderer_t::FAMILY_REGULAR;
81 ((
offset + 4) * 10 + precision);
82 }
else if (family >= mathtext::math_text_renderer_t::
83 FAMILY_STIX_REGULAR) {
84 const unsigned int offset = family -
85 mathtext::math_text_renderer_t::FAMILY_STIX_REGULAR;
86 return (
offset + 16) * 10 + precision;
91 inline bool is_cyrillic_or_cjk(
const wchar_t c)
const
93 return mathtext::math_text_renderer_t::is_cyrillic(
c) ||
94 mathtext::math_text_renderer_t::is_cjk(
c);
96 inline size_t root_cjk_face_number(
97 const bool serif =
false)
const
99 return (serif ? 28 : 29) * 10 + 2;
102 inline mathtext::affine_transform_t
103 transform_logical_to_pixel(
void)
const override
105 return mathtext::affine_transform_t::identity;
107 inline mathtext::affine_transform_t
108 transform_pixel_to_logical(
void)
const override
110 return mathtext::affine_transform_t::identity;
113 inline TMathTextRenderer(TMathText *parent)
114 : TText(), TAttFill(0, 1001),
115 _parent(parent), _font_size(0), _angle_degree(0)
121 for (
int i = 0; i<6; i++)
122 _pad_pixel_transform[i] = 0;
126 for (
int i = 0; i < mathtext::math_text_renderer_t::NFAMILY; i++)
127 _current_font_size[i] = 0;
130 font_size(
const unsigned int family = FAMILY_PLAIN)
const override
132 return _current_font_size[family];
135 point(
const float ,
const float )
override
139 set_font_size(
const float size,
const unsigned int family)
override
141 _current_font_size[family] =
size;
144 set_font_size(
const float size)
override
147 std::fill(_current_font_size,
148 _current_font_size + NFAMILY,
size);
151 reset_font_size(
const unsigned int )
override
155 set_parameter(
const float x,
const float y,
const float size,
156 const float angle_degree)
158 _x0 =
gPad->XtoAbsPixel(
x);
159 _y0 =
gPad->YtoAbsPixel(
y);
160 _pad_scale_x =
gPad->GetPadWidth();
161 _pad_scale_y =
gPad->GetPadHeight();
162 _pad_scale = std::min(_pad_scale_x, _pad_scale_y);
164 _angle_degree = angle_degree;
166 const float angle_radiant = _angle_degree * (
kPI / 180.0);
169 _pad_pixel_transform[0] = _pad_scale * cosf(angle_radiant);
170 _pad_pixel_transform[1] = -_pad_scale * sinf(angle_radiant);
171 _pad_pixel_transform[2] = _x0;
172 _pad_pixel_transform[3] = _pad_pixel_transform[1];
173 _pad_pixel_transform[4] = -_pad_pixel_transform[0];
174 _pad_pixel_transform[5] = _y0;
181 transform_pad(
double &xt,
double &yt,
182 const float x,
const float y)
const
185 x * _pad_pixel_transform[0] +
186 y * _pad_pixel_transform[1] + _pad_pixel_transform[2]));
188 x * _pad_pixel_transform[3] +
189 y * _pad_pixel_transform[4] + _pad_pixel_transform[5]));
192 filled_rectangle(
const mathtext::bounding_box_t &bounding_box_0)
override
201 transform_pad(xt[0], yt[0],
202 bounding_box_0.left(),
203 bounding_box_0.bottom());
204 transform_pad(xt[1], yt[1],
205 bounding_box_0.right(),
206 bounding_box_0.bottom());
207 transform_pad(xt[2], yt[2],
208 bounding_box_0.right(),
209 bounding_box_0.top());
210 transform_pad(xt[3], yt[3],
211 bounding_box_0.left(),
212 bounding_box_0.top());
213 gPad->PaintFillArea(4, xt, yt);
216 rectangle(
const mathtext::bounding_box_t &)
override
219 inline mathtext::bounding_box_t
220 bounding_box_char(
const wchar_t character,
float ¤t_x,
const unsigned int family)
223 h.SetTextFont(is_cyrillic_or_cjk(character) ? root_cjk_face_number() : root_face_number(family));
224 h.SetTextSize(_current_font_size[family] * _pad_scale);
226 auto font_face =
h.GetFontFace();
227 if (!font_face || font_face->units_per_EM == 0)
228 return mathtext::bounding_box_t(0, 0, 0, 0, 0, 0);
232 FT_Get_Char_Index(font_face, character),
235 const float scale = _current_font_size[family] / font_face->units_per_EM;
236 const FT_Glyph_Metrics metrics = font_face->glyph->metrics;
237 const float lower_left_x = metrics.horiBearingX;
238 const float lower_left_y =
239 metrics.horiBearingY - metrics.height;
240 const float upper_right_x =
241 metrics.horiBearingX + metrics.width;
242 const float upper_right_y = metrics.horiBearingY;
243 const float advance = metrics.horiAdvance;
244 const float margin = std::max(0.0F, lower_left_x);
245 const float italic_correction =
246 upper_right_x <= advance ? 0.0F :
247 std::max(0.0F, upper_right_x + margin - advance);
248 const mathtext::bounding_box_t
ret =
249 mathtext::bounding_box_t(
250 lower_left_x, lower_left_y,
251 upper_right_x, upper_right_y,
252 advance, italic_correction) * scale;
254 current_x +=
ret.advance();
258 inline mathtext::bounding_box_t
259 bounding_box(
const std::wstring
string,
const unsigned int family = FAMILY_PLAIN)
override
262 return mathtext::bounding_box_t(0, 0, 0, 0, 0, 0);
264 std::wstring::const_iterator iterator =
string.begin();
266 mathtext::bounding_box_t
ret =
267 bounding_box_char(*iterator, current_x, family);
270 for (; iterator !=
string.end(); ++iterator) {
271 const mathtext::point_t position =
272 mathtext::point_t(current_x, 0);
273 const mathtext::bounding_box_t glyph_bounding_box =
274 bounding_box_char(*iterator, current_x, family);
275 ret =
ret.merge(position + glyph_bounding_box);
280 void text_raw(
const float x,
const float y,
281 const std::wstring
string,
282 const unsigned int family = FAMILY_PLAIN)
override
290 for (
auto character :
string) {
292 const bool cyrillic_or_cjk = is_cyrillic_or_cjk(character);
300 transform_pad(xt, yt,
x + current_x,
y);
303 gPad->PaintText(xt, yt, buf);
306 bounding_box_char(character, current_x, family);
310 text_with_bounding_box(
const float ,
const float ,
312 const unsigned int )
override
315 using mathtext::math_text_renderer_t::bounding_box;
325 fRenderer =
new TMathTextRenderer(
this);
334 fRenderer =
new TMathTextRenderer(
this);
351 fRenderer =
new TMathTextRenderer(
this);
361 TAttFill::operator=(rhs);
387 const mathtext::math_text_t math_text(t);
400 const mathtext::math_text_t math_text(t);
404 const mathtext::bounding_box_t bounding_box =
fRenderer->bounding_box(math_text);
407 fRenderer->transform_pad(
x[0],
y[0], bounding_box.left(), bounding_box.bottom());
408 fRenderer->transform_pad(
x[1],
y[1], bounding_box.right(), bounding_box.bottom());
409 fRenderer->transform_pad(
x[2],
y[2], bounding_box.right(), bounding_box.top());
410 fRenderer->transform_pad(
x[3],
y[3], bounding_box.left(), bounding_box.top());
412 x0 = std::min(std::min(
x[0],
x[1]), std::min(
x[2],
x[3]));
413 y0 = std::min(std::min(
y[0],
y[1]), std::min(
y[2],
y[3]));
414 x1 = std::max(std::max(
x[0],
x[1]), std::max(
x[2],
x[3]));
415 y1 = std::max(std::max(
y[0],
y[1]), std::max(
y[2],
y[3]));
426 const mathtext::math_text_t math_text(t);
430 const mathtext::bounding_box_t bounding_box =
fRenderer->bounding_box(math_text);
434 Short_t valign = align - 10 * halign;
437 case 0:
x = bounding_box.left();
break;
438 case 1:
x = 0;
break;
439 case 2:
x = bounding_box.horizontal_center();
break;
440 case 3:
x = bounding_box.right();
break;
443 case 0:
y = bounding_box.bottom();
break;
444 case 1:
y = 0;
break;
445 case 2:
y = bounding_box.vertical_center();
break;
446 case 3:
y = bounding_box.top();
break;
563 if (
auto ps =
gPad->GetPainter()->GetPS()) {
564 if (ps->InheritsFrom(
"TImageDump"))
gPad->PaintText(0, 0,
"");
570 gPad->PaintText(
x,
y, text1);
583 TString newText = text1;
585 if (newText.
Length() == 0)
return;
608 while (newText.
Contains(
"\\frac")) {
610 i1 = newText.
Index(
"\\frac");
612 i2 = str.
Index(
"}{");
613 newText.
Replace(i1+i2,2,
" \\over ");
617 if (newText.
Contains(
"\\splitline")) {
620 while (newText.
Contains(
"\\splitline")) {
622 i1 = newText.
Index(
"\\splitline");
624 i2 = str.
Index(
"}{");
625 newText.
Replace(i1+i2,2,
" \\atop ");
649 out,
Class(),
"mathtex",
653 out <<
" mathtex->SetNDC();\n";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool).
int Int_t
Signed integer 4 bytes (int).
char Char_t
Character 1 byte (char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
short Font_t
Font number (short).
short Short_t
Signed Short integer 2 bytes (short).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
Option_t Option_t SetFillStyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void w
Option_t Option_t SetTextSize
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t SetTextFont
Option_t Option_t TPoint TPoint angle
Option_t Option_t SetFillColor
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
void Copy(TAttFill &attfill) const
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
virtual Float_t GetTextSize() const
Return the text size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Color_t fTextColor
Text color.
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
virtual Float_t GetTextAngle() const
Return the text angle.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Font_t fTextFont
Text font.
virtual void ModifyOn(TVirtualPad &pad)
virtual Float_t GetTextSizePercent(Float_t size)
Return the text in percent of the pad size.
Short_t fTextAlign
Text alignment.
void Copy(TAttText &atttext) const
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
friend class TMathTextRenderer
void Paint(Option_t *option="") override
This method must be overridden if a class wants to paint itself.
TMathText & operator=(const TMathText &)
void GetSize(Double_t &x0, Double_t &y0, Double_t &x1, Double_t &y1, const Double_t size, const Double_t angle, const Char_t *t, const Int_t length)
void GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle=kFALSE) override
virtual void PaintMathText(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
TMathTextRenderer * fRenderer
!TMathText Painter
void GetAlignPoint(Double_t &x0, Double_t &y0, const Double_t size, const Double_t angle, const Char_t *t, const Int_t length, const Short_t align)
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
void Render(const Double_t x, const Double_t y, const Double_t size, const Double_t angle, const Char_t *t, const Int_t length)
TMathText * DrawMathText(Double_t x, Double_t y, const char *text)
void Copy(TObject &text) const override
Copy this to obj.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
Bool_t TestBit(UInt_t f) const
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
@ kCanDelete
if object in a list can be deleted
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
TString & Remove(Ssiz_t pos)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Double_t fY
Y position of text (left,center,etc..).
void Copy(TObject &text) const override
Copy this to obj.
TText & operator=(const TText &src)
virtual void SetNDC(Bool_t isNDC=kTRUE)
Double_t fX
X position of text (left,center,etc..).
RooArgList L(Args_t &&... args)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.