[cairo-commit] roadster/src glyph.c,NONE,1.1 glyph.h,NONE,1.1
Ian McIntosh
commit at pdx.freedesktop.org
Sun Feb 27 19:34:06 PST 2005
- Previous message: [cairo-commit] roadster/src Makefile.am, 1.5, 1.6 datasetwindow.c,
1.3, 1.4 db.c, 1.8, 1.9 db.h, 1.3, 1.4 geometryset.c, 1.6,
1.7 gotowindow.c, 1.3, 1.4 gui.c, 1.3, 1.4 main.c, 1.5,
1.6 mainwindow.c, 1.7, 1.8 mainwindow.h, 1.1, 1.2 map.c, 1.10,
1.11 map.h, 1.1, 1.2 pointstring.c, 1.1, 1.2 pointstring.h,
1.1, 1.2 search_location.c, 1.4, 1.5 search_road.c, 1.8,
1.9 searchwindow.c, 1.5, 1.6
- Next message: [cairo-commit] roadster ChangeLog,1.25,1.26 configure.ac,1.5,1.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: ian
Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv17532/src
Added Files:
glyph.c glyph.h
Log Message:
* glyph.c:
* glyph.h: Added.
--- NEW FILE: glyph.c ---
/***************************************************************************
* glyph.c
*
* Copyright 2005 Ian McIntosh
* ian_mcintosh at linuxadvocate.org
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gnome.h>
#include <svg-cairo.h>
typedef enum { GLYPHTYPE_NONE=0, GLYPHTYPE_BITMAP, GLYPHTYPE_VECTOR } EGlyphType;
typedef struct glyph {
EGlyphType m_eType;
svg_cairo_t *m_pCairoSVG;
gint m_nWidth;
gint m_nHeight;
} glyph_t;
struct {
GPtrArray* m_pGlyphArray;
} g_Glyph;
void glyph_init(void)
{
g_Glyph.m_pGlyphArray = g_ptr_array_new();
g_ptr_array_add(g_Glyph.m_pGlyphArray, NULL); // index 0 is taken!
}
gint glyph_load(const gchar* pszPath)
{
svg_cairo_t* pCairoSVG = NULL;
if(SVG_CAIRO_STATUS_SUCCESS != svg_cairo_create(&pCairoSVG)) {
g_warning("svg_cairo_create failed\n");
return 0;
}
if(SVG_CAIRO_STATUS_SUCCESS != svg_cairo_parse(pCairoSVG, pszPath)) {
g_warning("svg_cairo_parse failed on '%s'\n", pszPath);
svg_cairo_destroy(pCairoSVG);
return 0;
}
glyph_t* pNewGlyph = g_new0(glyph_t, 1);
pNewGlyph->m_pCairoSVG = pCairoSVG;
svg_cairo_get_size(pNewGlyph->m_pCairoSVG, &(pNewGlyph->m_nWidth), &(pNewGlyph->m_nHeight));
// add it to array
gint nGlyphHandle = g_Glyph.m_pGlyphArray->len; // next available slot
g_ptr_array_add(g_Glyph.m_pGlyphArray, pNewGlyph);
return nGlyphHandle;
}
static gboolean glyph_lookup(gint nGlyphHandle, glyph_t** ppReturnGlyph)
{
g_assert(ppReturnGlyph != NULL);
g_assert(*ppReturnGlyph == NULL); // must be pointer to NULL pointer
glyph_t* pGlyph = g_ptr_array_index(g_Glyph.m_pGlyphArray, nGlyphHandle);
if(pGlyph != NULL) {
*ppReturnGlyph = pGlyph;
return TRUE;
}
return FALSE;
}
void glyph_draw_centered(cairo_t* pCairo, gint nGlyphHandle, gdouble fX, gdouble fY)
{
glyph_t* pGlyph = NULL;
if(!glyph_lookup(nGlyphHandle, &pGlyph)) {
// use a default glyph?
return;
}
cairo_save(pCairo);
// cairo_scale(pCairo, 2, 2);
cairo_set_alpha(pCairo, 0.5);
cairo_translate(pCairo, (fX - (pGlyph->m_nWidth/2)), (fY - (pGlyph->m_nHeight/2)));
svg_cairo_render(pGlyph->m_pCairoSVG, pCairo);
cairo_restore(pCairo);
}
void glyph_deinit(void)
{
// svg_cairo_destroy(svgc) all glyphs
}
--- NEW FILE: glyph.h ---
/***************************************************************************
* glyph.h
*
* Copyright 2005 Ian McIntosh
* ian_mcintosh at linuxadvocate.org
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GLYPH_H_
#define _GLYPH_H_
void glyph_init(void);
gint glyph_load(const gchar* pszPath);
void glyph_draw_centered(cairo_t* pCairo, gint nGlyphHandle, gdouble fX, gdouble fY);
void glyph_deinit(void);
#endif
- Previous message: [cairo-commit] roadster/src Makefile.am, 1.5, 1.6 datasetwindow.c,
1.3, 1.4 db.c, 1.8, 1.9 db.h, 1.3, 1.4 geometryset.c, 1.6,
1.7 gotowindow.c, 1.3, 1.4 gui.c, 1.3, 1.4 main.c, 1.5,
1.6 mainwindow.c, 1.7, 1.8 mainwindow.h, 1.1, 1.2 map.c, 1.10,
1.11 map.h, 1.1, 1.2 pointstring.c, 1.1, 1.2 pointstring.h,
1.1, 1.2 search_location.c, 1.4, 1.5 search_road.c, 1.8,
1.9 searchwindow.c, 1.5, 1.6
- Next message: [cairo-commit] roadster ChangeLog,1.25,1.26 configure.ac,1.5,1.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list