[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft-devel] Trying to figure out how to render a single character represe

From: joe M
Subject: [ft-devel] Trying to figure out how to render a single character represented by a FT_Bitmap in X
Date: Fri, 15 Feb 2013 22:24:32 -0500


I am trying to figure how to print one character from a FT_Bitmap
(freetype2 bitmap).

But, I am not able to get the character to display properly. I seem to
be missing something simple.

I seem to be missing something simple while creating the X pixmap
based on the FT_Bitmap.buffer.

Any thoughts, please?


P.S: I sent this email to the freetype mailing list as I was not sure
which mailing list is more appropriate. Please excuse me, if this is
not the correct forum to be asking these questions.

#include <X11/Xlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <ft2build.h>
#include FT_FREETYPE_H

main( int     argc,
      char**  argv )
  FT_Library    library;
  FT_Face       face;

  FT_GlyphSlot  slot;
  FT_Matrix     matrix;                 /* transformation matrix */
  FT_Vector     pen;                    /* untransformed origin  */
  FT_Error      error;

   Display *d;
   Window w;
   XEvent e;
   int s,i;
   Pixmap p, pixmap;
    unsigned int bwidth, bheight;
    int hotspot_x, hotspot_y;

  error = FT_Init_FreeType( &library );              /* initialize library */
  /* error handling omitted */

  error = FT_New_Face( library,
"/usr/share/fonts/anonymous-pro/Anonymous Pro I.ttf", 0, &face );/*
create face object */
  /* error handling omitted */

 error = FT_Set_Pixel_Sizes( face, 0, 24  );

  slot = face->glyph;

  error = FT_Load_Char( face, 'z', FT_LOAD_RENDER );

   d = XOpenDisplay(NULL);
   if (d == NULL) {
      fprintf(stderr, "Cannot open display\n");

   s = DefaultScreen(d);
   w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
                           BlackPixel(d, s), WhitePixel(d, s));
   XSelectInput(d, w, ExposureMask | KeyPressMask);
   XMapWindow(d, w);

   while (1) {
      XNextEvent(d, &e); if (e.type == Expose) {
         p = XCreateBitmapFromData(d, w,
               slot->bitmap.buffer, slot->bitmap.width ,
         XCopyPlane(d, p , w, DefaultGC(d,s),
                    0, 0,
                     slot->bitmap.width, slot->bitmap.rows,
                     40, 40,1);
         XSync(d, False);
      if (e.type == KeyPress)

  FT_Done_Face    ( face );
  FT_Done_FreeType( library );

  return 0;

/* EOF */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]