Exemple #1
0
static inline void iV_printFontList(void)
{
	unsigned int i;
	unsigned int font_count = glcGeti(GLC_CURRENT_FONT_COUNT);
	debug(LOG_NEVER, "GLC_CURRENT_FONT_COUNT = %d", font_count);

	if (font_count == 0)
	{
		debug(LOG_ERROR, "The required font (%s) isn't loaded", font_family);

		// Fall back to unselected fonts since the requested font apparently
		// isn't available.
		glcEnable(GLC_AUTO_FONT);
	}

	for (i = 0; i < font_count; ++i)
	{
		GLint font = glcGetListi(GLC_CURRENT_FONT_LIST, i);
		/* The output of the family name and the face is printed using 2 steps
		 * because glcGetFontc and glcGetFontFace return their result in the
		 * same buffer (according to GLC specs).
		 */
		char prBuffer[1024];
		snprintf(prBuffer, sizeof(prBuffer), "Font #%d : %s ", (int)font, (const char *)glcGetFontc(font, GLC_FAMILY));
		prBuffer[sizeof(prBuffer) - 1] = 0;
		sstrcat(prBuffer, (char const *)glcGetFontFace(font));
		debug(LOG_NEVER, "%s", prBuffer);
	}
}
Exemple #2
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;
}
Exemple #3
0
static void
access_font()
{

   /* This routine contains all the necessary steps to setup a */
   /* font master and a face.  Subsequent glcRenderChar() and  */
   /* glcRenderString() calls will draw the characters in the  */
   /* specified font/face.                                     */

   static GLboolean have_context = GL_FALSE;
   GLint glc_context;

   GLint master_count;
#ifdef _WIN32_
   const char* master_name = "Times New Roman";
#else
   const char* master_name = "Times";
#endif
   GLint master;

   GLint face_count;
   const char* face_name   = "Bold";
   static GLint glc_font_id;

   GLint result;
   unsigned int i, j;

   if (have_context == GL_FALSE) {

      /* Only get a context once.                                           */
      /* When using SGI's implementation of GLC, don't call glcGetError()   */
      /* after  this  glcGenContext()  call  because  it  always  returns   */
      /* GLC_STATE_ERROR. That's probably a bug in SGI's GLC. This behavior */
      /* doesn't occur in QuesoGLC.                                         */ 
      /* So, in order to let glclogo run with both implementations, just    */
      /* validate the context. If it's OK, then go for it.                  */
      glc_context = glcGenContext();
      if (!glcIsContext(glc_context)) {
         fprintf(stderr, "Error - glcGenContext() failed.  Exiting.\n");
         exit(-1);
      }
      else {

         /* Context is valid.  Make it the current context. */
         glcContext(glc_context);
         check_glc_error("glcContext()");
         have_context = GL_TRUE;

         /* Get a unique font ID. */
         glc_font_id = glcGenFontID();

         /* Choose a master and a face. */
         master_count = glcGeti(GLC_MASTER_COUNT);
         master = 0; 
         for (i = 0; i < master_count; i++) {
            if (!strcmp((const char*)glcGetMasterc(i, GLC_FAMILY), 
                        master_name)) {
               face_count = glcGetMasteri(i, GLC_FACE_COUNT);
               for (j = 0; j < face_count; j++) {
                  if (!strcmp((const char*)glcGetMasterListc(i, GLC_FACE_LIST, j), face_name)) {
                     master = i;
                  }
               }
            }
         }
         
         /* Access the font family. */
         result = glcNewFontFromFamily(glc_font_id, 
                                       glcGetMasterc(master, GLC_FAMILY));
         check_glc_error("glcNewFontFromFamily()");
         if (result != glc_font_id) {
            fprintf(stderr, "Error - glcNewFontFromFamily() failed.  Exiting.\n");
            exit(-1);
         }
         else {

            /* Use the font. */
            glcFont(glc_font_id);
            check_glc_error("glcFont()");

            /* Use the face. */
            glcFontFace(glc_font_id, face_name);
            check_glc_error("glcFontFace()");

#if 0
            /* This only speeds up immediate mode rendering.              */
            /* Don't do this when compiling your own display list because */
            /* the polygons will go into the GLC internal display lists   */
            /* rather than the display list you are trying to construct.  */
            glcEnable(GLC_GL_OBJECTS);
            check_glc_error("glcEnable(GLC_GL_OBJECTS)");
#else
            glcDisable(GLC_GL_OBJECTS);
            check_glc_error("glcDisable(GLC_GL_OBJECTS)");
#endif

            /* Draw as polygons for smooth rotation & zoom. */
            glcRenderStyle(GLC_TRIANGLE);
            check_glc_error("glcRenderStyle(GLC_TRIANGLE)");
         }
      }
   }
}
Exemple #4
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;
}