pango_renderer.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: pango_renderer.cpp
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-common.
00007  *
00008  * uds-plugin-common is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-common is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
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     // Draw run list .
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     // draw each pango run
00044     while (runs_list)
00045     {
00046         // Get glyph data.
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         // draw each glyph
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             // load glyph bitmap and copy
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 }
Generated by  doxygen 1.6.2-20100208