title: Pango and FreeType -- not rendering text, just weird pixels
body: <p>I'm trying to get Pango to control FreeType. I've successfully got FreeType to render into a bitmap but Pango doesn't seem to know what's going on, I'm obviously not doing something correctly.</p>
  
  <p>This is the code that I'm using at the moment:</p>
  
  <pre><code>font_map = pango_ft2_font_map_new();
  pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(font_map), 72, 72);
  cr = pango_font_map_create_context(PANGO_FONT_MAP(font_map));
  
  font_description = pango_font_description_new ();
  pango_font_description_set_family (font_description, "Courier New");
  pango_font_description_set_weight (font_description, PANGO_WEIGHT_BOLD);
  pango_font_description_set_absolute_size (font_description, 32 * PANGO_SCALE);
  
  layout = pango_layout_new(cr);
  pango_layout_set_font_description(layout, font_description);
  pango_layout_set_text(layout, "Some sample text!", -1);
  
  pango_context_set_font_description(cr, font_description);
  
  FT_Bitmap bitmap = { 0 };
  bitmap.width = drawBitmap.get()-&gt;getWidth();
  bitmap.rows = drawBitmap.get()-&gt;getHeight();
  bitmap.pitch = bitmap.width * 4;
  bitmap.buffer = (unsigned char*)drawBitmap.get()-&gt;getDataPtr();
  bitmap.num_grays = 256;
  bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
  pango_ft2_render_layout(&amp;bitmap, layout, 100, 100);
  </code></pre>
  
  <p><code>drawBitmap</code> is just my helper class, I know this works because I can fill it with random colours and they show up.</p>
  
  <p>This is what gets rendered:</p>
  
  <p><img src="https://i.stack.imgur.com/caLWi.png" alt="enter image description here"></p>
  
  <p>I want to try to get that text to show up properly.</p>
  
  <hr>
  
  <p>EDIT: The problem has been brought into sharper relief after fixing the bit depth of the image and switching from bare Pango FreeType to Pango Cairo with the FreeType engine.</p>
  
  <p>Using this line:</p>
  
  <pre><code>font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_WIN32);
  </code></pre>
  
  <p>produces</p>
  
  <p><img src="https://i.stack.imgur.com/6I7nK.png" alt="enter image description here"></p>
  
  <p>and when I run through <code>pango_font_map_list_families</code>, I get a long list of the fonts installed on my system.</p>
  
  <p>However if I change it to this, to use FreeType:</p>
  
  <pre><code>font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
  </code></pre>
  
  <p>it produces</p>
  
  <p><img src="https://i.stack.imgur.com/l2Qy3.png" alt="enter image description here"></p>
  
  <p>and then there are suddenly only 3 fonts on my system, <code>Sans</code>, <code>Serif</code> and <code>Monospace</code>.</p>