nr-svgfonts.cpp revision 280e31bdf7f5ffd28f8b14565c1d93de4070bd0c
#include "config.h"
#ifdef ENABLE_SVG_FONTS
/*
* SVGFonts rendering implementation
*
* Authors:
* Felipe C. da S. Sanches <felipe.sanches@gmail.com>
*
* Copyright (C) 2008 Felipe C. da S. Sanches
*
* Released under GNU GPL version 2 or later.
* Read the file 'COPYING' for more information.
*/
#include "../style.h"
#include <cairo.h>
#include <vector>
#include "inkscape-cairo.h"
#include "nr-svgfonts.h"
//*************************//
// UserFont Implementation //
//*************************//
// I wrote this binding code because Cairomm does not yet support userfonts. I have moved this code to cairomm and sent them a patch.
// Once Cairomm incorporate the UserFonts binding, this code should be removed from inkscape and Cairomm API should be used.
static cairo_user_data_key_t key;
}
static cairo_status_t font_text_to_glyphs_cb (
const char *utf8,
int utf8_len,
int *num_glyphs,
int *num_clusters,
return instance->scaled_font_text_to_glyphs(scaled_font, utf8, utf8_len, glyphs, num_glyphs, clusters, num_clusters, flags);
}
unsigned long glyph,
}
this->face = cairo_user_font_face_create ();
}
//******************************//
// SvgFont class Implementation //
//******************************//
this->missingglyph = NULL;
}
{
//TODO
// metrics->ascent = .75;
// metrics->descent = .25;
return CAIRO_STATUS_SUCCESS;
}
while((g_utf8_get_char(substring)==g_utf8_get_char(str)) && g_utf8_get_char(substring) != 0 && g_utf8_get_char(str) != 0){
}
if (g_utf8_get_char(substring)==0)
return substring - original_substring;
else
return 0;
}
const char *utf8,
int utf8_len,
int *num_glyphs,
int *num_clusters,
{
//This function receives a text string to be rendered. It then defines what is the sequence of glyphs that
// is used to properly render this string. It also defines the respective coordinates of each glyph. Thus, it
// has to read the attributes of the SVGFont hkern and vkern nodes in order to adjust the glyph kerning.
//It also determines the usage of the missing-glyph in portions of the string that does not match any of the declared glyphs.
unsigned long i;
int count = 0;
unsigned int len;
bool missing;
//First we findout whats the number of glyphs needed.
while(g_utf8_get_char(_utf8) != 0){
missing = true;
//TODO: store this cluster
count++;
missing=false;
break;
}
}
if (missing){
//TODO: store this cluster
_utf8++;
count++;
}
}
//We use that info to allocate memory for the glyphs
count=0;
double x=0, y=0;//These vars store the position of the glyph within the rendered string
bool is_horizontal_text = true; //TODO
while(g_utf8_get_char(_utf8) != 0){
len = 0;
//check whether is there a glyph declared on the SVG document
// that matches with the text string in its current position
//apply glyph kerning if appropriate
)//TODO: verify what happens when using unicode strings.
}
)//TODO: idem
}
}
//advance glyph coordinates:
if (is_horizontal_text) x++;
else y++;
//continue;
goto dirty;
}
}
if (!len){
//advance glyph coordinates:
if (is_horizontal_text) x++;
else y++;
}
}
*num_glyphs = count;
return CAIRO_STATUS_SUCCESS;
}
unsigned long glyph,
{
// This method does the actual rendering of glyphs.
// We have glyphs.size() glyphs and possibly one missing-glyph declared on this SVG document
// The id of the missing-glyph is always equal to glyphs.size()
// All the other glyphs have ids ranging from 0 to glyphs.size()-1
if (!this->missingglyph) return CAIRO_STATUS_SUCCESS;
} else {
}
//glyphs can be described by arbitrary SVG declared in the childnodes of a glyph node
// or using the d attribute of a glyph node.
// pathv stores the path description from the d attribute:
} else {
return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return?
}
//This glyph has a path description on its d attribute, so we render it:
//adjust scale of the glyph
//This matrix flips the glyph vertically
Geom::Matrix m(Geom::Coord(1),Geom::Coord(0),Geom::Coord(0),Geom::Coord(-1),Geom::Coord(0),Geom::Coord(0));
//then we offset it
Geom::Rect area( Geom::Point(0,0), Geom::Point(1,1) ); //I need help here! (reaction: note that the 'area' parameter is an *optional* rect, so you can pass an empty Geom::OptRect() )
cairo_fill(cr);
}
//TODO: render the SVG described on this glyph's child nodes.
return CAIRO_STATUS_SUCCESS;
}
SvgFont::get_font_face(){
if (!this->userfont) {
if (SP_IS_GLYPH(node)){
}
if (SP_IS_MISSING_GLYPH(node)){
}
}
}
}
delete this->userfont;
}
#endif //#ifdef ENABLE_SVG_FONTS