IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39595


Ignore:
Timestamp:
Jun 11, 2016, 12:44:40 PM (10 years ago)
Author:
eugene
Message:

add unused latex parser for rotfont; add comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libkapa/src/DrawRotString.c

    r39457 r39595  
    8888    if (!code && !protect) {
    8989      /* subscript, starts with _ */
    90       if (N == 94) {
     90      if (N == 94) { // underscore
    9191        SetRotFont (currentname, (int)(0.8*currentsize));
    9292        currentfont = GetRotFontData (&currentscale);
     
    9595      }
    9696      /* superscript, starts with ^ */
    97       if (N == 95) {
     97      if (N == 95) { // caret
    9898        SetRotFont (currentname, (int)(0.8*currentsize));
    9999        currentfont = GetRotFontData (&currentscale);
     
    102102      }
    103103      /* normal script, starts with | */
    104       if (N == 124) {
     104      if (N == 124) { // pipe
    105105        SetRotFont (currentname, basesize);
    106106        currentfont = GetRotFontData (&currentscale);
     
    108108        continue;
    109109      }
    110       if (N == 92) {
     110      if (N == 92) { // backslash
    111111        code = TRUE;
    112112        continue;
    113113      }
    114       if (N == 38) {
     114      if (N == 38) { // ampersand
     115        if (string[i+1] == 'h') {
     116          SetRotFont ("helvetica", currentsize);
     117          currentfont = GetRotFontData (&currentscale);
     118        }
     119        if (string[i+1] == 't') {
     120          SetRotFont ("times", currentsize);
     121          currentfont = GetRotFontData (&currentscale);
     122        }
     123        if (string[i+1] == 'c') {
     124          SetRotFont ("courier", currentsize);
     125          currentfont = GetRotFontData (&currentscale);
     126        }
     127        if (string[i+1] == 's') {
     128          SetRotFont ("symbol", currentsize);
     129          currentfont = GetRotFontData (&currentscale);
     130        }
     131        i++;
     132        continue;
     133      }
     134    }
     135    code = FALSE;
     136
     137    bitmap = currentfont[N].bits;
     138    dx = currentfont[N].dx;
     139    dy = currentfont[N].dy;
     140    X = x + (int)(Xoff*cs - Yoff*sn) + (int)(currentscale*currentfont[N].ascent*sn);
     141    Y = y + (int)(Xoff*sn + Yoff*cs) - (int)(currentscale*currentfont[N].ascent*cs);
     142    DrawRotBitmap (X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
     143    Xoff += 1 + (int)(currentscale*dx + 0.5);
     144  }
     145  SetRotFont (basename, basesize);
     146  return (TRUE);
     147}
     148
     149/*
     150   latex interpretation rules:
     151   \word = special character
     152   interpretation is LaTeX math mode
     153   
     154
     155 */
     156
     157int DrawRotText_Latex (int x, int y, char *string, int pos, double angle) {
     158
     159  unsigned char *bitmap;
     160  char *currentname, basename[64];
     161  int dy, dx, N, X, Y, code, protect;
     162  int dX, Xoff, dY, Yoff, YoffBase;
     163  int currentsize, basesize;
     164  double cs, sn, currentscale;
     165  RotFont *currentfont;
     166
     167  currentname = GetRotFont (&currentsize);
     168  currentfont = GetRotFontData (&currentscale);
     169  strcpy (basename, currentname);
     170  basesize = currentsize;
     171
     172  /* strip leading WHITESPACE */
     173  stripwhite (string);
     174  if (*string == 0) return (FALSE);
     175 
     176  /* compute string length */
     177  cs = cos(angle*RAD_DEG);
     178  sn = sin(angle*RAD_DEG);
     179  dX = RotStrlen (string);
     180  dY = currentfont[65].ascent;
     181
     182  /* apply appropriate offset */
     183  Xoff = Yoff = 0;
     184  switch (pos) {
     185  case 0: Xoff =     -dX; Yoff = dY; break;
     186  case 1: Xoff = -0.5*dX; Yoff = dY; break;
     187  case 2: Xoff =       0; Yoff = dY; break;
     188  case 3: Xoff =     -dX; Yoff = 0.5*dY; break;
     189  case 4: Xoff = -0.5*dX; Yoff = 0.5*dY; break;
     190  case 5: Xoff =       0; Yoff = 0.5*dY; break;
     191  case 6: Xoff =     -dX; Yoff = 0; break;
     192  case 7: Xoff = -0.5*dX; Yoff = 0; break;
     193  case 8: Xoff =       0; Yoff = 0; break;
     194  }
     195
     196  code = FALSE;
     197  protect = FALSE;
     198
     199  YoffBase = Yoff;
     200  /* draw characters one-by-one */
     201  unsigned int i;
     202  for (i = 0; i < strlen(string); i++) {
     203    N = (int)(string[i]);
     204    if ((N < 0) || (N >= NROTCHARS)) continue;
     205
     206    if (N == 39) { // single-quote
     207      protect = protect ? FALSE : TRUE;
     208    }
     209
     210    /* check for special characters */
     211    if (!code && !protect) {
     212      /* subscript, starts with _ */
     213      if (N == 94) { // underscore
     214        SetRotFont (currentname, (int)(0.8*currentsize));
     215        currentfont = GetRotFontData (&currentscale);
     216        Yoff -= 0.5*currentscale*dY;
     217        continue;
     218      }
     219      /* superscript, starts with ^ */
     220      if (N == 95) { // caret
     221        SetRotFont (currentname, (int)(0.8*currentsize));
     222        currentfont = GetRotFontData (&currentscale);
     223        Yoff += 0.5*currentscale*dY;
     224        continue;
     225      }
     226      /* normal script, starts with | */
     227      if (N == 124) { // pipe
     228        SetRotFont (currentname, basesize);
     229        currentfont = GetRotFontData (&currentscale);
     230        Yoff = YoffBase;
     231        continue;
     232      }
     233      if (N == 92) { // backslash
     234        code = TRUE;
     235        continue;
     236      }
     237      if (N == 38) { // ampersand
    115238        if (string[i+1] == 'h') {
    116239          SetRotFont ("helvetica", currentsize);
Note: See TracChangeset for help on using the changeset viewer.