コード例 #1
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
void acBitmapFont::drawChar(unsigned char c, float x, float y) {
  // x,y is insertion point, lower-left, on baseline
  //if (c < 33) return;
  //if (c > numChars + 32) return;
  if (!charExists(c)) return;

  /*
  if (!charExists(c)) {
    int m = win2mac[c-128];
    if (m == -1) m = 'X';
    printf("%d does not exist %c '%c'\n", c, c, m);
    return;
  }

  //if (c+33 > 127) {
  if (c > 127) {
    //printf("got something outside: %d\n", c+33);
    c = win2mac[c];
    if (c == -1) return; // char not in encoding
    printf("found %c\n", (unsigned char)c);
  }
  //glEnable(GL_TEXTURE_2D);
  */

  float height = charHeight(c);
  //float width = charWidth(c);
  float bwidth = charBitmapWidth(c);
  float top = charTop(c);
  float lextent = charLeftExtent(c);

#ifndef CANNOT_BIND_TEXTURES

  if (glIsTexture(texNames[win2mac[c]-33])) {
    acuNamedTexRectf(x+lextent, y+top, 
		     x+lextent+bwidth, y+height+top, 
		     texNames[win2mac[c]-33], bwidth, height);
  } else {
    sprintf(acuDebugStr, "Could not bind: %c %d\n", c, c);
    acuDebugString(ACU_DEBUG_MUMBLE);
    acuTexRectf(x+lextent, y+top, x+lextent+bwidth, y+height+top, 
		images[c-33], GL_RGBA, 4, 64, 64, bwidth, height);
  }

#else  

  acuTexRectf(x+lextent, y+top, x+lextent+bwidth, y+height+top, 
	      images[win2mac[c]-33], GL_RGBA, 4, 64, 64, bwidth, height);
#endif

#if 0
  // to draw the baseline
  glBegin(GL_LINES);
  glVertex3f(x, y, 0);
  glVertex3f(x+width*0.95f, y, 0);
  glEnd();
#endif
}
コード例 #2
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
float acBitmapFont::charWidth(unsigned char c) {
  // width of the horizontal space char takes up
  //if (c != ' ') {
  if (charExists(c)) {
    return (float)setWidth[win2mac[c]-33] / 64.0f;

  } else {
    //return charWidth('i')*1.2f;
    return charWidth('n'); // support monospace better
  }
}
コード例 #3
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
unsigned char* acBitmapFont::getCharData(unsigned char c, float *x, float *y, float *w, float *h) {
  if (!charExists(c)) return NULL;
  *x = charLeftExtent(c);
  *y = charTop(c);
  *w = charBitmapWidth(c);
  *h = charHeight(c);
  /*
  params[0] = charLeftExtent(c); // x
  params[1] = charTop(c); // y
  params[2] = charBitmapWidth(c); // width
  params[3] = charHeight(c); // height
  //params[4] = bwidth; // maxu
  //params[5] = height; // maxv
  */
  return images[c-33];
}
コード例 #4
0
ファイル: xtotroff.c プロジェクト: DemonFang/groff
static int MapFont(char *font_name, const char *troff_name)
{
  XFontStruct *fi;
  int count;
  char **names;
  FILE *out;
  unsigned int c;
  unsigned int attributes;
  XFontName parsed;
  int j, k;
  DviCharNameMap *char_map;
  char encoding[256];
  char *s;
  int wid;
  char name_string[2048];

  if (!XParseFontName(font_name, &parsed, &attributes)) {
    fprintf(stderr, "not a standard name: %s\n", font_name);
    return 0;
  }

  attributes &= ~(FontNamePixelSize | FontNameAverageWidth);
  attributes |= FontNameResolutionX;
  attributes |= FontNameResolutionY;
  attributes |= FontNamePointSize;
  parsed.ResolutionX = resolution;
  parsed.ResolutionY = resolution;
  parsed.PointSize = point_size * 10;
  XFormatFontName(&parsed, attributes, name_string);

  names = XListFonts(dpy, name_string, 100000, &count);
  if (count < 1) {
    fprintf(stderr, "bad font name: %s\n", font_name);
    return 0;
  }

  if (FontNamesAmbiguous(font_name, names, count))
    return 0;

  XParseFontName(names[0], &parsed, &attributes);
  sprintf(encoding, "%s-%s", parsed.CharSetRegistry,
	  parsed.CharSetEncoding);
  for (s = encoding; *s; s++)
    if (isupper(*s))
      *s = tolower(*s);
  char_map = DviFindMap(encoding);
  if (!char_map) {
    fprintf(stderr, "not a standard encoding: %s\n", encoding);
    return 0;
  }

  fi = XLoadQueryFont(dpy, names[0]);
  if (!fi) {
    fprintf(stderr, "font does not exist: %s\n", names[0]);
    return 0;
  }

  printf("%s -> %s\n", names[0], troff_name);

  {				/* Avoid race while opening file */
    int fd;
    (void) unlink(troff_name);
    fd = open(troff_name, O_WRONLY | O_CREAT | O_EXCL, 0600);
    out = fdopen(fd, "w");
  }

  if (!out) {
    perror(troff_name);
    return 0;
  }
  fprintf(out, "name %s\n", troff_name);
  if (!strcmp(char_map->encoding, "adobe-fontspecific"))
    fprintf(out, "special\n");
  if (charExists(fi, ' ')) {
    int w = charWidth(fi, ' ');
    if (w > 0)
      fprintf(out, "spacewidth %d\n", w);
  }
  fprintf(out, "charset\n");
  for (c = fi->min_char_or_byte2; c <= fi->max_char_or_byte2; c++) {
    const char *name = DviCharName(char_map, c, 0);
    if (charExists(fi, c)) {
      int param[5];

      wid = charWidth(fi, c);

      fprintf(out, "%s\t%d", name ? name : "---", wid);
      param[0] = charHeight(fi, c);
      param[1] = charDepth(fi, c);
      param[2] = 0;		/* charRBearing (fi, c) - wid */
      param[3] = 0;		/* charLBearing (fi, c) */
      param[4] = 0;		/* XXX */
      for (j = 0; j < 5; j++)
	if (param[j] < 0)
	  param[j] = 0;
      for (j = 4; j >= 0; j--)
	if (param[j] != 0)
	  break;
      for (k = 0; k <= j; k++)
	fprintf(out, ",%d", param[k]);
      fprintf(out, "\t0\t0%o\n", c);

      if (name) {
	for (k = 1; DviCharName(char_map, c, k); k++) {
	  fprintf(out, "%s\t\"\n", DviCharName(char_map, c, k));
	}
      }
    }
  }
  XUnloadFont(dpy, fi->fid);
  fclose(out);
  return 1;
}
コード例 #5
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
float acBitmapFont::charLeftExtent(unsigned char c) {
  return charExists(c) ? 
    (float)leftExtent[win2mac[c]-33] / 64.0f : 0;
}
コード例 #6
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
float acBitmapFont::charTop(unsigned char c) {
  return charExists(c) ? 
    (-charHeight(c) + (float)(topExtent[win2mac[c]-33]) / 64.0f) : 0;
}
コード例 #7
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
float acBitmapFont::charBitmapHeight(unsigned char c) {
  // same as charHeight
  return charExists(c) ? (float)height[win2mac[c]-33] / 64.0f : 0;
}
コード例 #8
0
ファイル: acBitmapFont.cpp プロジェクト: blackaller/acu
float acBitmapFont::charBitmapWidth(unsigned char c) {
  // width of the bitmap itself
  return charExists(c) ? (float)width[win2mac[c]-33] / 64.0f : 0;
}