Sindbad~EG File Manager

Current Path : /home/beeson/ThreeBody/ThreeBodyProblem/
Upload File :
Current File : //home/beeson/ThreeBody/ThreeBodyProblem/textwidth3.c

//  textwidth.c
//  MathXpert Calculus Assistant
//
//  Created by Michael Beeson on 12/23/23.
// 12.29.23 changed width of EIGHTPOINT atoms
// 1.11.24  changed width of atoms
// 6.15.24  increased functor_width of ERF
// 6.30.24  added APPROXEQSTR
// 2.16.25  removed charcode.h and code for Windows fonts
// 2.17.25  made INFINITYSTR  10 instead of 8
// 3.16.25  made a copy for THREEBODY project, commented out get_textwidth call
//

#include <string.h>
#include <assert.h>
#include "textwidth.h"
#include "charstr.h"
#include "symbols2.h"

/*______________________________________________________________*/
long svg_text_width(char *x, short pointsize)
/* pointsize is EIGHTPOINT or TENPOINT */
/* public because it's called in lbreak.c */
/* This is called by bblock to measure the width of text strings.
The return value is in papyrus coordinates, 16 units for an
em-space for TENPOINT, regardless of the actual size of fontsize that
will be used for display.
*/
/* This function is public, since it's called in bblock.c   */

{
  long ans;
  if (pointsize != TENPOINT && pointsize != EIGHTPOINT)
     assert(0);
  char c = x[0];
  if(x[1] == '\0' && ('a' <= c && c <= 'z'))
     { switch(c)
         { case 'm':  // fall through
           case 'w':    return pointsize == TENPOINT ? 12:8;
           case 'i':   // fall through
           case 'j':
           case 't':    return pointsize == TENPOINT? 6:4;
           case 's':    return pointsize == TENPOINT? 7:5;
           case 'l':    return pointsize == TENPOINT? 8:4;
           case 'r':    // fall through
           case 'c':
           case 'f':   return pointsize == TENPOINT? 10: 5;
           default:
              return pointsize == TENPOINT? 8: 6;
         }
     }
  if(x[1] == '\0' && ('A' <= c && c <= 'Z'))
     { switch(c)
         { case 'M':   // fall through
           case 'W':  return pointsize == TENPOINT ? 14:10;
           case 'B':  return pointsize == TENPOINT? 10:7;
           case 'A': return pointsize == TENPOINT? 10:8;
           case 'L': return pointsize == TENPOINT? 10:7;
           case 'T':  return pointsize == TENPOINT? 10:8;
           case 'J':  return pointsize == TENPOINT ? 8: 4;
           case 'I':  return pointsize == TENPOINT ? 8: 4;
           case 'C':  // fall through
           case 'F':
           case 'P':
           case 'E':
           case 'K':
           case 'N':
           case 'O':
           case 'Q':
           case 'R':
           case 'U':
           case 'Y':
           case 'X':
           case 'D':
           case 'H':
           case 'G':
           case 'Z':
           case 'V':  return pointsize == TENPOINT ? 12:8;
           case 'S':  return pointsize == TENPOINT ? 10: 7;
           default:
              return pointsize == TENPOINT? 12: 10;
         }
     }
  if(x[1] == '\0' && '0' <= c && c <= '9')
     { /* a digit */
       ans = 7;    //  1 gets the saame as 2
       if(pointsize == EIGHTPOINT)
         {
           ans = (int)((ans/16.0) * 13 + 0.5);
         }
       return ans;
     }
  if(x[1] == '\0')  /* it's a symbol */
     { // for example, '<',  or maybe a one-byte UTF-8 ?
       // all text is now UTF-8, so it won't be a Windows-font character
       // once upon a time there was code here for those characters.
       // harmless to treat it as UTF-8 character won't have x[1] = '\0'
       ans = 8;
       if(pointsize == EIGHTPOINT)
          {   ans = (int)((ans/16.0) * 13 + 0.5);
          }
       return ans;
     }
  if(strlen(x) == 2 )
     { // two-byte UTF-8
       if (!strcmp(x,ALPHASTR))   /*    α alpha           */
          return 8;
       if (!strcmp(x,BETASTR))   /*    β beta             */
          return 8;
      if (!strcmp(x,BIGGAMMASTR))   /*  Γ uppercase gamma */
          return 8;
       if (!strcmp(x,LITTLEGAMMASTR))   /*    β beta             */
          return 8;
       if (!strcmp(x,SIGMASTR))   /*    σ sigma           */
          return 10;
       if (!strcmp(x,PSISTR))   /*     ψ psi              */
          return 10;
       if (!strcmp(x,BIGPSISTR))   /* Ψ uppercase psi, for digamma function */
          return 16;
       if (!strcmp(x,BETASTR))   /*    β beta             */
          return 8;
       if (!strcmp(x,MUSTR))      /* μ mu                 */
          return 8;
       if (!strcmp(x,THETASTR))   /* θ theta              */
          return 8;
       if (!strcmp(x,DELTASTR))   /* δ delta              */
          return 8;
       if (!strcmp(x,PHISTR ))    /* φ phi                */
          return 10;
      if (!strcmp(x,EPSILONSTR))  /* ε epsilon            */
         return 8;
      if (!strcmp(x,PISTR))       /* π pi                 */
         return 10;
      if (!strcmp(x, LAMBDASTR))  /* λ lambda             */
         return 8;
      if (!strcmp(x,RHOSTR))      /* ρ rho                */
         return 8;
      if (!strcmp(x,NUSTR))       /* ν nu                 */
         return 8;
      if (!strcmp(x,TAUSTR))      /* τ tau                */
         return 8;
      if (!strcmp(x,OMEGASTR))    /* ω little omega       */
         return 10;
      if (!strcmp(x,BIGOMEGASTR)) /* Ω omega              */
         return 8;
      if (!strcmp(x, ZETASTR))     /*    zeta              */
         return 8;
     }
  else if (strlen(x) == 3)
     { // three-byte UTF-8
       if (!strcmp(x,SEQSTR))              /* =>  implies          */
          return 12;
       if (!strcmp(x,APPROXEQSTR))         /* ≅ approximately equal */
          return 8;
       if (!strcmp(x,SETMEMBERSHIPSTR))    /* ∈ special epsilon    */
          return 8;
       if (!strcmp(x,EXISTSSTR))            /* ∃ exists             */
          return 8;
       if (!strcmp(x,FORALLSTR))            /* ∀ for all            */
          return 8;
       if (!strcmp(x,INFINITYSTR))          /* ∞ infinity           */
          return 10;
       if (!strcmp(x,SUMSTR))               /* ∑ summation sign     */
          return 8;
       if (!strcmp(x,PRODUCTSTR))           /* ∏ indexed product    */
          return 8;
       if (!strcmp(x,ARROWSTR))             /* → limit arrow        */
          return 12;
       if (!strcmp(x,GESTR))                /* ≥ greater than or equal to */
          return 8;
       if (!strcmp(x,LESTR))                /* ≤ less than or equal to    */
          return 8;
       if (!strcmp(x,NESTR))                /* ≠ not equal to             */
          return 8;
       if (!strcmp(x,PRIMESTR))             /* ′ prime                    */
          return 4;
       if (!strcmp(x,ABSSTR))               /* ∣ absolute value           */
          return 8;
       if (!strcmp(x,INTEGRALSTR))          /* ∫ one-line integral symbol */
          return 8;
       if (!strcmp(x,SQRTSTR))              /* √ square root              */
          return 8;
       if (!strcmp(x,WEIERSTRASSPSTR))      /* ℘ Weierstrass p            */
          return 8;
       if (!strcmp(x,DOUBLEARROWSTR))       /* ⇒ double arrow             */
          return 8;
       if (!strcmp(x,DOWNARROWSTR))         /* ↓ down arrow               */
          return 8;
       if (!strcmp(x,LANDSTR))              /* ∧ logical and              */
          return 8;
       if (!strcmp(x,LORSTR))               /* ∨ logical or               */
          return 8;
       if (!strcmp(x,SUMSTR))               /* ∑ summation sign           */
          return 8;
       
     
     }
  if(pointsize == TENPOINT)
    return 8*strlen(x);
  else
    return 5.3*strlen(x) + 0.5;  // it will be truncated, so add 0.5 first
}

/*______________________________________________________________*/
long bignum_text_width(char *x, short pointsize, int separator)
 /* Given a long string x, such as a
large integer, we can't get the width correct by
starting with strlen(x)*get_charspace() and applying
various fudge factors.  In particular it may make a difference
if there are commas (or periods) or spaces or not.
here is the meaning of the separator argument:
      2 = blocks of 3 digits with commas
      0 = blocks of 6 digits with space
      1 = no separator
    > 2 specifies ascii code to use for separator,e.g. '.' or ' '
*/
{ long width = svg_text_width(x,pointsize);
  if(separator >= 2)
     width *= 0.875;
  else if (separator == 0)
     width *= 6.0/7.0;
  return width;
}

 

/*____________________________________________________________________*/
/* following data gives widths of functor names in tenpoint
papyrus coordinates.  These data were originally computed
using GetTextExtent by functions in font3.c.
   Some data for characters from the symbol font were put
in by hand, as were the initial 16's, and some character sizes
were also adjusted by hand, so these numbers should
NEVER be replaced by recomputed data.
*/

unsigned char functorwidth[] =
{
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,
86,78,84,86,80,80,        /* ACOS-ATAN */
36,42,38,38,40,36,        /* SIN-COT   */
48,50,24,40,              /* EXP-LOG   */
0,40,                     /* ABSFUNCTOR, DET  */
56,62,56,                 /* SINH, COSH, TANH */
12,16,10,8,8,8,           /* *, +, DEG, -, FACTORIAL, / */
0,40,36,32,38,14,18,14,    /* FLOOR-BESSELI */
22,46,24,112,16,16,16,16, /* BESSELK, GCD, ':', BINOMIAL, <, =, >, VAR */
18,18,22,20,22,20,22,22,  /* ILLEGAL (which is also '?')  A,- G */
22,12,22,22,18,28,22,22,   /* H-O */
26,22,22,20,18,22,18,28,  /* P-W */
20,26,20,22,0,56,0,0,     /* X,Y,Z,BIGOH, PSEUDOATOM,MAXFUNCTOR,^,LINEARSYSTEM */
0,18,18,14,20,16,18,20,   /* NUM,a-g; a,b,d,f,g made wider by hand */
18,14,20,14,14,24,16,16,  /* h-o; adjusted by hand */
18,18,16,18,14,16,16,24,  /* p-w; adjusted by hand */
18,22,18,52,16,16,16,56,  /* x,y,z,MINFUNCTOR,GE,LE,NE,MOD */
150,36,18,40,98,40,16,48, /* MULTIPLICITY, IMPLIES (ARROW), SEQ, DIFF, INTEGRAL, LOGB, IF, AND */
26,8,50,26,78,24,24,0,   /* OR, PR, ROOT, LIMIT, CASES, SUM, PRODUCT, EVAL */
0,64,0,48,96,0,0,0,       /* VECTOR, EVEN1, FRACT, ODD1, DEFINED, MATRIXINVERSE, STROKE, POLY */
0,0,60,62,54,96,102,96,   /* MATRIXMULT, MATRIX, CSCH,SECH, COTH,ASINH,ACOSH,ATANH */
100,102,94,20,32,44,50,26, /* ACSCH, ASECH,ACOTH,GAMMA, DIGAMMA, ERF, ERFC, POLYGAMMA */
26,24,26,26,20,20,18,20,   /* COSINTEGRAL, LOGINTEGRAL, SININTEGRAL, EXPINTEGRALI, BETAFUNCTION, INCOMPLETEBETA, EXPINTEGRALE, INCOMPLETEGAMMA */
18,0,0,0,0,0,0,24,         /* INCOMPLETEGAMMAP,...EXISTS */
24,0,20,0,132,20,20,24,0,0,       /* ALL, INFINITESIMAL, LAM, AP, NUMERATOR, DENOM, CONSTANTOFINTEGRATION, RIEMANNZETA, SERIES, SETOF*/
20, 24,24,24,24,24,24,24,24                   /* EULERGAMMA, BERNOULLI, EULERNUMBER,
                         RHO, PSI, TAU, OMEGA, NU, WEIERSTRASSP */
};
/*______________________________________________________________*/
unsigned short functor_width(unsigned short f, short pointsize)
/* pointsize is TENPOINT or EIGHTPOINT (which are 0 or 1, not actual sizes)
Return the width in papyrus coordinates required to display the
display string for functor f.  This presumes that
f is a predefined functor for which functor_string is
defined.
*/
{ unsigned short ans = functorwidth[f];
  if(f == '<' || f == '>') //   || f == LE || f == LE)
     return 8;  //  get_ineqspace();  commented this out for ThreeBody
  //apparently I gave up in Windows on the use of the elaborate table above and decide to
  // just measure the text width.  But in SVG you can't measure the text width.
  if(pointsize == EIGHTPOINT)
     { double smaller = 0.6;
       ans  *= smaller;
     }
  return 0.5*ans;
 }
 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists