~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/freetype/main_2.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* example1.c                                                      */
 
2
/*                                                                 */
 
3
/* This small program shows how to print a rotated string with the */
 
4
/* FreeType 2 library.                                             */
 
5
 
 
6
 
 
7
#include <stdio.h>
 
8
#include <string.h>
 
9
#include <math.h>
 
10
#include <stdlib.h>
 
11
 
 
12
#include <ft2build.h>
 
13
#include FT_FREETYPE_H
 
14
 
 
15
int WIDTH = 0;
 
16
int HEIGHT = 0;
 
17
 
 
18
/* origin is the upper left corner */
 
19
unsigned char *image;
 
20
 
 
21
 
 
22
/* Replace this function with something useful. */
 
23
 
 
24
void
 
25
draw_bitmap( FT_Bitmap*  bitmap,
 
26
             FT_Int      x,
 
27
             FT_Int      y)
 
28
{
 
29
  FT_Int  i, j, p, q;
 
30
  FT_Int  x_max = x + bitmap->width;
 
31
  FT_Int  y_max = y + bitmap->rows;
 
32
 
 
33
  for ( i = x, p = 0; i < x_max; i++, p++ )
 
34
  {
 
35
    for ( j = y, q = 0; j < y_max; j++, q++ )
 
36
    {
 
37
      if ( i < 0      || j < 0       ||
 
38
           i >= WIDTH || j >= HEIGHT )
 
39
        continue;
 
40
 
 
41
      image[j*WIDTH + i] |= bitmap->buffer[q * bitmap->width + p];
 
42
    }
 
43
  }
 
44
}
 
45
 
 
46
 
 
47
void
 
48
show_image( void )
 
49
{
 
50
  int  i, j;
 
51
  int count = 0;
 
52
 
 
53
  for ( i = 0; i < HEIGHT; i++ )
 
54
  {
 
55
    for ( j = 0; j < WIDTH; j++ ) 
 
56
        {
 
57
      if (image[i*WIDTH + j]) count++;
 
58
      putchar(image[i*WIDTH + j] == 0? ' '
 
59
                                : image[i*WIDTH + j] < 128 ? '+'
 
60
                                                           : '*' );
 
61
    }
 
62
    putchar( '\n' );
 
63
  }
 
64
  printf("Non-0s: %d\n", count);
 
65
}
 
66
 
 
67
 
 
68
int
 
69
main( int     argc,
 
70
      char**  argv )
 
71
{
 
72
  FT_Library    library;
 
73
  FT_Face       face;
 
74
 
 
75
  FT_GlyphSlot  slot;
 
76
  FT_Error      error;
 
77
 
 
78
  FT_UInt glyphIndex;
 
79
 
 
80
  char*         filename;
 
81
  char*         text;
 
82
 
 
83
  int           target_height;
 
84
 
 
85
  if ( argc != 6 )
 
86
  {
 
87
    fprintf ( stderr, "usage: %s font sample-text width height angle\n", argv[0] );
 
88
    exit( 1 );
 
89
  }
 
90
 
 
91
  // Only test the character 'w'
 
92
  text = "w";
 
93
  
 
94
  filename      = argv[1];                           /* first argument     */
 
95
  WIDTH         = atoi(argv[3]);
 
96
  HEIGHT        = atoi(argv[4]);
 
97
  target_height = HEIGHT;
 
98
        
 
99
  image = (unsigned char*)malloc(WIDTH*HEIGHT);
 
100
  for (int x = 0; x < WIDTH; x++)
 
101
    for (int y = 0; y < HEIGHT; y++)
 
102
      image[y*WIDTH + x] = 0;
 
103
 
 
104
  error = FT_Init_FreeType( &library );              /* initialize library */
 
105
  if (error) printf("Init Error! %d\n", error);
 
106
 
 
107
  error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
 
108
  if (error) printf("New_Face Error! %d\n", error);
 
109
 
 
110
  /* use 50pt at 100dpi */
 
111
  error = FT_Set_Char_Size( face, 0, 32 * 64, 0, 0 );                /* set character size */
 
112
  if (error) printf("Set_Cshar_Size Error! %d\n", error);
 
113
        
 
114
  slot = face->glyph;
 
115
 
 
116
  glyphIndex = FT_Get_Char_Index(face, text[0]);
 
117
        
 
118
  /* load glyph image into the slot (erase previous one) */
 
119
  error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_NO_BITMAP);
 
120
  if(error) printf("FT_Load_Glyph Error! %d\n", error);
 
121
        
 
122
  error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
 
123
  if(error) printf("FT_Render_Glyph Error! %d\n", error);
 
124
        
 
125
  /* now, draw to our target surface (convert position) */
 
126
  draw_bitmap(&slot->bitmap, slot->bitmap_left, target_height - slot->bitmap_top);
 
127
        
 
128
  show_image();
 
129
        
 
130
  FT_Done_Face(face);
 
131
  FT_Done_FreeType(library);
 
132
  return 0;
 
133
}
 
134
 
 
135
/* EOF */
 
 
b'\\ No newline at end of file'