25#include "../../../graf2d/mathtext/inc/mathtext.h"
26#include "../../../graf2d/mathtext/inc/mathrender.h"
56 public mathtext::math_text_renderer_t {
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;
80 ((offset == 0 ? 13 : offset) * 10 + precision) :
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;
93 return mathtext::math_text_renderer_t::is_cyrillic(
c) ||
94 mathtext::math_text_renderer_t::is_cjk(
c);
97 const bool serif =
false)
const
99 return (serif ? 28 : 29) * 10 + 2;
102 inline mathtext::affine_transform_t
105 return mathtext::affine_transform_t::identity;
107 inline mathtext::affine_transform_t
110 return mathtext::affine_transform_t::identity;
121 for (
int i = 0; i<6; i++)
126 for (
int i = 0; i < mathtext::math_text_renderer_t::NFAMILY; i++)
130 font_size(
const unsigned int family = FAMILY_PLAIN)
const override
135 point(
const float ,
const float )
override
156 const float angle_degree)
182 const float x,
const float y)
const
202 bounding_box_0.left(),
203 bounding_box_0.bottom());
205 bounding_box_0.right(),
206 bounding_box_0.bottom());
208 bounding_box_0.right(),
209 bounding_box_0.top());
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)
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),
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 =
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 =
275 ret =
ret.merge(position + glyph_bounding_box);
281 const std::wstring
string,
282 const unsigned int family = FAMILY_PLAIN)
override
290 for (
auto character :
string) {
303 gPad->PaintText(xt, yt, buf);
312 const unsigned int )
override
315 using mathtext::math_text_renderer_t::bounding_box;
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,
"");
569 gPad->GetPainter()->SetTextAngle(angle);
570 gPad->PaintText(
x,
y, text1);
585 if (newText.
Length() == 0)
return;
608 while (newText.
Contains(
"\\frac")) {
610 i1 = newText.
Index(
"\\frac");
611 str = newText(i1,len).
Data();
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");
623 str = newText(i1,len).
Data();
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
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).
bool Bool_t
Boolean (0=false, 1=true) (bool).
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).
void Copy(TAttFill &attfill) const
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
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.
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.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
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.
virtual void SetTextSize(Float_t tsize=1)
Set the text 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)
void set_font_size(const float size, const unsigned int family) override
float _current_font_size[mathtext::math_text_renderer_t::NFAMILY]
void text_raw(const float x, const float y, const std::wstring string, const unsigned int family=FAMILY_PLAIN) override
void text_with_bounding_box(const float, const float, const std::wstring, const unsigned int) override
float _pad_pixel_transform[6]
mathtext::bounding_box_t bounding_box(const std::wstring string, const unsigned int family=FAMILY_PLAIN) override
TMathTextRenderer(TMathText *parent)
float font_size(const unsigned int family=FAMILY_PLAIN) const override
mathtext::affine_transform_t transform_pixel_to_logical(void) const override
size_t root_cjk_face_number(const bool serif=false) const
bool is_cyrillic_or_cjk(const wchar_t c) const
size_t root_face_number(const unsigned int family, const bool serif=false) const
mathtext::bounding_box_t bounding_box_char(const wchar_t character, float ¤t_x, const unsigned int family)
void reset_font_size(const unsigned int) override
void point(const float, const float) override
void rectangle(const mathtext::bounding_box_t &) override
void transform_pad(double &xt, double &yt, const float x, const float y) const
void set_parameter(const float x, const float y, const float size, const float angle_degree)
mathtext::affine_transform_t transform_logical_to_pixel(void) const override
void filled_rectangle(const mathtext::bounding_box_t &bounding_box_0) override
To draw TeX Mathematical Formula.
friend class TMathTextRenderer
void Paint(Option_t *option="") override
Paint text.
Double_t GetYsize()
Get Y size.
TMathText & operator=(const TMathText &)
Assignment operator.
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)
Get the text bounding box.
void GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle=kFALSE) override
Get the text width and height.
TMathTextRenderer * fRenderer
!TMathText Painter
Double_t GetXsize()
Get X size.
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)
Alignment.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save 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)
Render the text.
~TMathText() override
Destructor.
TMathText * DrawMathText(Double_t x, Double_t y, const char *text)
Make a copy of this object with the new parameters and copy object attributes.
TMathText()
Default constructor.
virtual void PaintMathText(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Paint text (used by Paint()).
void Copy(TObject &text) const override
Copy.
const char * GetTitle() const override
Returns title of object.
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.
TObject()
TObject constructor.
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
Dynamic handle to work with freetype 2 library.
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..).
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.