nr-svgfonts.cpp revision 90a3966dd44e306d23febc15ebd65cde07d7a4dd
#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;
}
unsigned int p=0;
if (s1[p]=='\0') return p;
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;
//First we findout whats the worst case number of glyphs.
while(_utf8[0] != '\0'){
_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(_utf8[0] != '\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++;
_utf8++; //advance 1 char in our string pointer
}
}
*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;
g_warning("RENDER MISSING-GLYPH");
} 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:
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 boost::optional<Geom::Rect>() )
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)){
g_warning("missingglyph=(SPMissingGlyph*)node;");
}
}
}
}
#endif //#ifdef ENABLE_SVG_FONTS