Exemplo n.º 1
0
int main(int argc, char **argv)
{
  int ctx = 0;
  int numMasters = 0;
  int numFaces = 0;
  int numCatalogs = 0;
  int i = 0;
  int j = 0;

  /* Needed to initialize an OpenGL context */
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutCreateWindow("testfont");

  ctx = glcGenContext();
  glcContext(ctx);

  numCatalogs = glcGeti(GLC_CATALOG_COUNT);
  printf("Catalogs : %d\n", numCatalogs);
  
  for (i = 0; i < numCatalogs; i++)
    printf("Catalog #%d : %s\n", i,
	   (const char *)glcGetListc(GLC_CATALOG_LIST, i));

  numMasters = glcGeti(GLC_MASTER_COUNT);
  printf("Masters : %d\n", numMasters);

  for (i = 0; i < numMasters; i++) {
    numFaces = glcGetMasteri(i, GLC_FACE_COUNT);
    printf("Master #%d\n", i);
    printf("- Vendor : %s\n", (char*)glcGetMasterc(i, GLC_VENDOR));
    printf("- Format : %s\n", (char*)glcGetMasterc(i, GLC_MASTER_FORMAT));
    printf("- Face count : %d\n", numFaces);
    printf("- Family : %s\n", (char*)glcGetMasterc(i, GLC_FAMILY));
    printf("- Version : %s\n", (char*)glcGetMasterc(i, GLC_VERSION));
    printf("- Is Fixed Pitch : %s\n", glcGetMasteri(i, GLC_IS_FIXED_PITCH) ?
	   "YES" : "NO");
    for (j = 0; j < numFaces; j++)
      printf("- Face #%d : %s\n", j, 
	     (char *)glcGetMasterListc(i, GLC_FACE_LIST, j));
    printf("- Master #%d maps 0x%X to %s\n", i, 65 + i,
	   (char *)glcGetMasterMap(i, 65 + i));
  }

  glcDeleteContext(ctx);
  return 0;
}
Exemplo n.º 2
0
void iV_TextShutdown()
{
	if (_glcFont_Regular)
	{
		glcDeleteFont(_glcFont_Regular);
	}

	if (_glcFont_Bold)
	{
		glcDeleteFont(_glcFont_Bold);
	}

	glcContext(0);

	if (_glcContext)
	{
		glcDeleteContext(_glcContext);
	}
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
  GLint ctx;
  GLCenum err;
  GLint length = 0;
  GLint i, j, n;
  GLint font = 0;
  GLfloat baseline1[4], baseline2[4];
  GLfloat boundingBox1[8], boundingBox2[8];
  GLfloat v1, v2, norm, area;

  /* Needed to initialize an OpenGL context */
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutCreateWindow("test7");

  ctx = glcGenContext();
  CheckError();

  glcContext(ctx);
  CheckError();

  length = glcMeasureCountedString(GL_TRUE, strlen(string)-1, string);
  CheckError();

  if ((!length) || (length != (strlen(string)-1))) {
    printf("glcMeasureString() failed to measure %d characters"
	   " (%d measured instead)\n", (int)strlen(string), length);
    return -1;
  }

  n = glcGeti(GLC_MEASURED_CHAR_COUNT);
  CheckError();

  if (length != n) {
    printf("glcGeti(GLC_MEASURED_CHAR_COUNT) == %d is not consistent with the"
	   " value returned by glcMeasureString() == %d\n", n, length);
    return -1;
  }

  length = glcMeasureString(GL_TRUE, string);
  CheckError();

  if ((!length) || (length != strlen(string))) {
    printf("glcMeasureString() failed to measure %d characters"
	   " (%d measured instead)\n", (int)strlen(string), length);
    return -1;
  }

  n = glcGeti(GLC_MEASURED_CHAR_COUNT);
  CheckError();

  if (length != n) {
    printf("glcGeti(GLC_MEASURED_CHAR_COUNT) == %d is not consistent with the"
	   " value returned by glcMeasureString() == %d\n", n, length);
    return -1;
  }

  for (i = 0; i < strlen(string); i++) {
    if (!glcGetCharMetric(string[i], GLC_BASELINE, baseline1)) {
      printf("Failed to measure the baseline of the character %c\n",
	     string[i]);
      return -1;
    }

    CheckError();

    if (!glcGetStringCharMetric(i, GLC_BASELINE, baseline2)) {
      printf("Failed to get the baseline of the %dth character of the string"
	     " %s\n", i, string);
      return -1;
    }

    CheckError();

    for (j = 0; j < 2; j++) {
      v1 = fabs(baseline1[j + 2] - baseline1[j]);
      v2 = fabs(baseline2[j + 2] - baseline2[j]);
      norm = v1 > v2 ? v1 : v2;

      if (fabs(v1 - v2) > EPSILON * norm) {
	printf("Baseline values differ [rank %d char %d] %f (char),"
	       " %f (string)\n", j, i, v1, v2);
	return -1;
      }
    }

    if (!glcGetCharMetric(string[i], GLC_BOUNDS, boundingBox1)) {
      printf("Failed to measure the bounding box of the character %c\n",
	     string[i]);
      return -1;
    }

    CheckError();

    if (!glcGetStringCharMetric(i, GLC_BOUNDS, boundingBox2)) {
      printf("Failed to get the bounding box of the %dth character of the"
	     " string %s\n", i, string);
      return -1;
    }

    CheckError();

    for (j = 0; j < 6; j++) {
      v1 = fabs(boundingBox1[j + 2] - boundingBox1[j]);
      v2 = fabs(boundingBox2[j + 2] - boundingBox2[j]);
      norm = v1 > v2 ? v1 : v2;

      if (fabs(v1 - v2) > EPSILON * norm) {
	printf("Bounding Box values differ [rank %d char %d] %f (char),"
	       " %f (string)", j, i, v1, v2);
	return -1;
      }
    }
  }

  if (!glcGeti(GLC_FONT_COUNT)) {
    printf("GLC_FONT_LIST is empty\n");
    return -1;
  }

  CheckError();

  if (!glcGeti(GLC_CURRENT_FONT_COUNT)) {
    printf("GLC_CURRENT_FONT_LIST is empty\n");
    return -1;
  }

  CheckError();

  if (!glcGetMaxCharMetric(GLC_BASELINE, baseline1)) {
    printf("Failed to get the max baseline of the current fonts\n");
    return -1;
  }

  CheckError();

  v1 = fabs(baseline1[1]);
  v2 = fabs(baseline1[3]);
  norm = v1 > v2 ? v1 : v2;

  if (fabs(v1 - v2) < EPSILON * norm) {
    v1 = fabs(baseline1[0]);
    v2 = fabs(baseline1[2]);
    norm = v1 > v2 ? v1 : v2;
    if ((fabs(v1 - v2) < EPSILON * norm) || (baseline1[2] < baseline1[0])) {
      printf("Right and left side of the max baseline are swapped\n");
      printf("%f %f %f %f\n", baseline1[0], baseline1[1], baseline1[2],
	     baseline1[3]);
      font = glcGetListi(GLC_FONT_LIST, 0);
      printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
      printf("Face : %s\n", (char*)glcGetFontFace(font));
      return -1;
    }
  }

  if (!glcGetMaxCharMetric(GLC_BOUNDS, boundingBox1)) {
    printf("Failed to get the max bounding box of the current fonts\n");
    return -1;
  }

  CheckError();

  area = 0.;
  for (i = 0; i < 3; i++) {
    area += boundingBox1[2*i] * boundingBox1[2*(i+1)+1] 
      - boundingBox1[2*(i+1)] * boundingBox1[2*i+1];
  }

  if (fabs(area * .5) < EPSILON) {
    printf("Max area of the characters is null\n");
    return -1;
  }

  /* Regression test for bug #1821219 (glcGetCharMetric randomly crashes when
   * requesting measurement for the space character).
   */

  for (i = 0; i < glcGeti(GLC_MASTER_COUNT); i++) {
    GLint font = glcGenFontID();

    if (!glcNewFontFromMaster(font, i)) {
      printf("Can not get a font from master %s\n",
             (char*)glcGetMasterc(i, GLC_FAMILY));
      return -1;
    }

    CheckError();

    glcFont(font);

    CheckError();

    if (!glcGetFontMap(font, ' ')) {
      printf("INFO : Family %s %s has no space character\n",
	     (char*)glcGetFontc(font, GLC_FAMILY), (char*)glcGetFontFace(font));
      continue;
    }

    if (!glcGetCharMetric(' ', GLC_BOUNDS, boundingBox1)) {
      printf("Failed to get the bounding box of the space character\n");
      printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
      printf("Face : %s\n", (char*)glcGetFontFace(font));
      return -1;
    }

    CheckError();

    if (!glcGetCharMetric(' ', GLC_BASELINE, baseline1)) {
      printf("Failed to get the baseline of the space character\n");
      printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
      printf("Face : %s\n", (char*)glcGetFontFace(font));
      return -1;
    }

    CheckError();

    v1 = fabs(baseline1[1]);
    v2 = fabs(baseline1[3]);
    norm = v1 > v2 ? v1 : v2;

    if (fabs(v1 - v2) < EPSILON * norm) {
      v1 = fabs(baseline1[0]);
      v2 = fabs(baseline1[2]);
      norm = v1 > v2 ? v1 : v2;
      if ((fabs(v1 - v2) < EPSILON * norm) || (baseline1[2] < baseline1[0])) {
        printf("Right and left side of the baseline are swapped\n");
        printf("%f %f %f %f\n", baseline1[0], baseline1[1], baseline1[2],
               baseline1[3]);
	printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
	printf("Face : %s\n", (char*)glcGetFontFace(font));
        return -1;
      }
    }
  }

  glcDeleteContext(ctx);
  glcContext(0);

  printf("Tests successful\n");
  return 0;
}