nr-svgfonts.cpp revision f45619747d788d05b19687aedde8620096f50048
#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 <libnr/n-art-bpath-2geom.h>
#include "../style.h"
#include <cairo.h>
#include <vector>
#include "inkscape-cairo.h"
#include "nr-svgfonts.h"
//***********************************//
// SvgFontDrawingArea Implementation //
//***********************************//
public:
}
private:
cr->set_font_face( Cairo::RefPtr<Cairo::FontFace>(new Cairo::FontFace(this->svgfont->get_font_face(), false /* does not have reference */)) );
return TRUE;
}
};//class SvgFontDrawingArea
//*************************//
// 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;
}
const char *utf8,
int *num_glyphs){
}
unsigned long glyph,
}
this->face = cairo_user_font_face_create ();
}
//******************************//
// SvgFont class Implementation //
//******************************//
this->missingglyph = NULL;
//This is an auxiliary gtkWindow used only while we do not have proper Pango integration with cairo-user-fonts.
font_da = new SvgFontDrawingArea(this);
}
{
//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 *num_glyphs)
{
//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 alse defines the respective coordinates of each glyph. Thus, it
// has to read the attributes od 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;
}
}
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:
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