pango_renderer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "font_cache.h"
00028 #include "pango_renderer.h"
00029
00030 void render_single_line(unsigned char *bmp,
00031 PangoLayoutLine *pango_line,
00032 unsigned int font_hash_code,
00033 int x,
00034 int y,
00035 const int width)
00036 {
00037
00038 int glyph_pos_x = 0, glyph_pos_y = 0;
00039 GSList *runs_list = pango_line->runs;
00040
00041 FontCache& font_cache = FontCache::instance();
00042
00043
00044 while (runs_list)
00045 {
00046
00047 PangoLayoutRun *run = (PangoLayoutRun *)runs_list->data;
00048 PangoGlyphString *glyphs = run->glyphs;
00049 FT_Face ft_face = pango_fc_font_lock_face(PANGO_FC_FONT(run->item->analysis.font));
00050
00051
00052 for (int i=0; i<glyphs->num_glyphs; i++)
00053 {
00054 PangoGlyphGeometry geometry = glyphs->glyphs[i].geometry;
00055 glyph_pos_x = x + geometry.x_offset;
00056 glyph_pos_y = y + geometry.y_offset;
00057 x += geometry.width;
00058
00059 if (glyphs->glyphs[i].glyph == PANGO_GLYPH_EMPTY)
00060 {
00061 continue;
00062 }
00063
00064
00065 FT_BitmapGlyph data = font_cache.get_glyph(ft_face,
00066 font_hash_code,
00067 glyphs->glyphs[i].glyph);
00068 if (data)
00069 {
00070 render_single_glyph(bmp,
00071 PANGO_PIXELS(glyph_pos_x) + data->left,
00072 PANGO_PIXELS(glyph_pos_y) - data->top,
00073 width,
00074 data);
00075 }
00076 }
00077
00078 pango_fc_font_unlock_face(PANGO_FC_FONT(run->item->analysis.font));
00079 runs_list = runs_list->next;
00080 }
00081 }
00082
00083 void render_single_glyph(unsigned char *bmp,
00084 int x,
00085 int y,
00086 const int width,
00087 const FT_BitmapGlyph glyph)
00088 {
00089 unsigned char *src = glyph->bitmap.buffer;
00090 unsigned char *dst = bmp + y * width + x;
00091
00092 for(int i = 0; i < glyph->bitmap.rows; i++)
00093 {
00094 unsigned char *p = dst;
00095 for (int j = 0; j < glyph->bitmap.pitch; j++)
00096 {
00097 *p++ ^= *src++;
00098 }
00099 dst += width;
00100 }
00101 }