<commit_before>// @(#)root/graf:$Id: TMathText.cxx  $
// Author: <NAME>  16/10/12

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TROOT.h"
#include "TClass.h"
#include "TTF.h"
#include "TMathText.h"
#include "TMath.h"
#include "TVirtualPad.h"
#include "TVirtualPS.h"
#include "TText.h"

#include "mathtext.h"
#include "mathrender.h"

//______________________________________________________________________________
/* Begin_Html
<center><h2>TMathText : to draw LaTex Mathematical Formula</h2></center>
 
TMathText's purpose is to write mathematical equations, exactly as LaTex would
do it. The syntax is the same as LaTex's.
<p>
The following example demonstate how to use TMathText:
End_Html
Begin_Macro(source)
../../../tutorials/graphics/tmathtext.C
End_Macro
Begin_Html
<p>
The list of all available symbol is givern in the following example:
End_Html
Begin_Macro(source)
../../../tutorials/graphics/tmathtext2.C
End_Macro
Begin_Html
<p>
End_Html
*/


const Double_t kPI      = TMath::Pi();
const Int_t kLatex      = BIT(10);
const Int_t kPrintingPS = BIT(11); //set in TPad.h

class TMathTextRenderer : public TText, public TAttFill,
                          public mathtext::math_text_renderer_t {
private:
   TMathText *_parent;
   float _font_size;
   float _x0;
   float _y0;
   float _angle_degree;
   float _pad_pixel_transform[6];
   float _pad_scale;
   float _pad_scale_x;
   float _pad_scale_y;
   float _pad_scale_x_relative;
   float _pad_scale_y_relative;
   float _current_font_size[mathtext::math_text_renderer_t::NFAMILY];
   inline size_t root_face_number(
      const unsigned int family, const bool serif = false) const
   {
      static const int precision = 2;

      if (family >= mathtext::math_text_renderer_t::
         FAMILY_REGULAR &&
         family <= mathtext::math_text_renderer_t::
         FAMILY_BOLD_ITALIC) {
         const unsigned int offset = family -
            mathtext::math_text_renderer_t::FAMILY_REGULAR;
         return serif ?
            ((offset == 0 ? 13 : offset) * 10 + precision) :
            ((offset + 4) * 10 + precision);
      } else if (family >= mathtext::math_text_renderer_t::
            FAMILY_STIX_REGULAR) {
         const unsigned int offset = family -
            mathtext::math_text_renderer_t::FAMILY_STIX_REGULAR;
         return (offset + 16) * 10 + precision;
      }

      return precision;
   }
   inline bool is_cyrillic_or_cjk(const wchar_t c) const
   {
      return mathtext::math_text_renderer_t::is_cyrillic(c) ||
         mathtext::math_text_renderer_t::is_cjk(c);
   }
   inline size_t root_cjk_face_number(
      const bool serif = false) const
   {
      return (serif ? 28 : 29) * 10 + 2;
   }
protected:
   inline mathtext::affine_transform_t
   transform_logical_to_pixel(void) const
   {
      return mathtext::affine_transform_t::identity;
   }
   inline mathtext::affine_transform_t
   transform_pixel_to_logical(void) const
   {
      return mathtext::affine_transform_t::identity;
   }
public:
   inline TMathTextRenderer(TMathText *parent)
      : TText(), TAttFill(0, 1001),
        _parent(parent), _font_size(0), _angle_degree(0)
   {
   }
   inline float
   font_size(const unsigned int family = FAMILY_PLAIN) const<commit_msg>fix coverity report #47979<commit_after>// @(#)root/graf:$Id: TMathText.cxx  $
// Author: <NAME>  16/10/12

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TROOT.h"
#include "TClass.h"
#include "TTF.h"
#include "TMathText.h"
#include "TMath.h"
#include "TVirtualPad.h"
#include "TVirtualPS.h"
#include "TText.h"

#include "mathtext.h"
#include "mathrender.h"

//______________________________________________________________________________
/* Begin_Html
<center><h2>TMathText : to draw LaTex Mathematical Formula</h2></center>
 
TMathText's purpose is to write mathematical equations, exactly as LaTex would
do it. The syntax is the same as LaTex's.
<p>
The following example demonstate how to use TMathText:
End_Html
Begin_Macro(source)
../../../tutorials/graphics/tmathtext.C
End_Macro
Begin_Html
<p>
The list of all available symbol is givern in the following example:
End_Html
Begin_Macro(source)
../../../tutorials/graphics/tmathtext2.C
End_Macro
Begin_Html
<p>
End_Html
*/


const Double_t kPI      = TMath::Pi();
const Int_t kLatex      = BIT(10);
const Int_t kPrintingPS = BIT(11); //set in TPad.h

class TMathTextRenderer : public TText, public TAttFill,
                          public mathtext::math_text_renderer_t {
private:
   TMathText *_parent;
   float _font_size;
   float _x0;
   float _y0;
   float _angle_degree;
   float _pad_pixel_transform[6];
   float _pad_scale;
   float _pad_scale_x;
   float _pad_scale_y;
   float _pad_scale_x_relative;
   float _pad_scale_y_relative;
   float _current_font_size[mathtext::math_text_renderer_t::NFAMILY];
   inline size_t root_face_number(
      const unsigned int family, const bool serif = false) const
   {
      static const int precision = 2;

      if (family >= mathtext::math_text_renderer_t::
         FAMILY_REGULAR &&
         family <= mathtext::math_text_renderer_t::
         FAMILY_BOLD_ITALIC) {
         const unsigned int offset = family -
            mathtext::math_text_renderer_t::FAMILY_REGULAR;
         return serif ?
            ((offset == 0 ? 13 : offset) * 10 + precision) :
            ((offset + 4) * 10 + precision);
      } else if (family >= mathtext::math_text_renderer_t::
            FAMILY_STIX_REGULAR) {
         const unsigned int offset = family -
            mathtext::math_text_renderer_t::FAMILY_STIX_REGULAR;
         return (offset + 16) * 10 + precision;
      }

      return precision;
   }
   inline bool is_cyrillic_or_cjk(const wchar_t c) const
   {
      return mathtext::math_text_renderer_t::is_cyrillic(c) ||
         mathtext::math_text_renderer_t::is_cjk(c);
   }
   inline size_t root_cjk_face_number(
      const bool serif = false) const
   {
      return (serif ? 28 : 29) * 10 + 2;
   }
protected:
   inline mathtext::affine_transform_t
   transform_logical_to_pixel(void) const
   {
      return mathtext::affine_transform_t::identity;
   }
   inline mathtext::affine_transform_t
   transform_pixel_to_logical(void) const
   {
      return mathtext::affine_transform_t::identity;
   }
public:
   inline TMathTextRenderer(TMathText *parent)
      : TText(), TAttFill(0, 1001),
        _parent(parent), _font_size(0), _angle_degree(0)
   {
      int i;
      _font_size = 0;
      _x0 = 0;
      _y0 = 0;
      _angle_degree = 0;
      for (i = 0; i<6; i++) _pad_pixel_transform[i] = 0;
      _pad_scale = 0;
      _pad_scale_x = 0;
      _pad_scale_y = 0;
      _pad_scale_x_relative = 0;
      _pad_scale_y_relative = 0;
      for (i = 0; i < mathtext::math_text_renderer_t::NFAMILY; i++) _current_font_size[i] = 0;
   }
   inline float
   font_size(const unsigned int family = FAMILY_PLAIN) const
{'fraction_non_alphanumeric': 0.13328246216456824, 'fraction_numerical': 0.01564288439526898, 'mean_word_length': 2.8988596926127914, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1980114', 'n_tokens_mistral': 2666, 'n_tokens_neox': 2529, 'n_words': 583}