index ebd71968bed972bc2c0ce6824d9f0665b0346086..7b0b4938b7584acde2e529e6bac7eb488b3a2734 100644 (file)
* Read the file 'COPYING' for more information.
*/
-#include <libnr/n-art-bpath.h>
+#include <libnr/n-art-bpath-2geom.h>
+#include <2geom/pathvector.h>
+#include <2geom/transforms.h>
#include "../style.h"
#include <cairo.h>
#include <vector>
//We use that info to allocate memory for the glyphs
*glyphs = (cairo_glyph_t*) malloc(count*sizeof(cairo_glyph_t));
- char* previous_unicode = NULL; //This is used for kerning
+ char* previous_unicode = NULL; //This is used for kerning
+ gchar* previous_glyph_name = NULL; //This is used for kerning
+
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;
for (i=0; i < (unsigned long) this->glyphs.size(); i++){
- if ( len = compare_them(this->glyphs[i]->unicode, _utf8) ){
+ if ( (len = compare_them(this->glyphs[i]->unicode, _utf8)) ){
//check whether is there a glyph declared on the SVG document
// that matches with the text string in its current position
for(SPObject* node = this->font->children;previous_unicode && node;node=node->next){
//apply glyph kerning if appropriate
if (SP_IS_HKERN(node) && is_horizontal_text){
- if ( (((SPHkern*)node)->u1[0] == previous_unicode[0]) && (((SPHkern*)node)->u2[0] == this->glyphs[i]->unicode[0]))//TODO: strings
+ if ( (((SPHkern*)node)->u1->contains(previous_unicode[0])
+ || ((SPHkern*)node)->g1->contains(previous_glyph_name)) &&
+ (((SPHkern*)node)->u2->contains(this->glyphs[i]->unicode[0])
+ || ((SPHkern*)node)->g2->contains(this->glyphs[i]->glyph_name))
+ )//TODO: verify what happens when using unicode strings.
x -= (((SPHkern*)node)->k / this->font->horiz_adv_x);
}
if (SP_IS_VKERN(node) && !is_horizontal_text){
- if ( (((SPVkern*)node)->u1[0] == previous_unicode[0]) && (((SPVkern*)node)->u2[0] == this->glyphs[i]->unicode[0]))//TODO: strings
+ if ( (((SPVkern*)node)->u1->contains(previous_unicode[0])
+ || ((SPVkern*)node)->g1->contains(previous_glyph_name)) &&
+ (((SPVkern*)node)->u2->contains(this->glyphs[i]->unicode[0])
+ || ((SPVkern*)node)->g2->contains(this->glyphs[i]->glyph_name))
+ )//TODO: idem
y -= (((SPVkern*)node)->k / this->font->vert_adv_y);
}
}
previous_unicode = this->glyphs[i]->unicode;//used for kerning checking
+ previous_glyph_name = this->glyphs[i]->glyph_name;//used for kerning checking
+
(*glyphs)[count].index = i;
(*glyphs)[count].x = x;
(*glyphs)[count++].y = y;
//glyphs can be described by arbitrary SVG declared in the childnodes of a glyph node
// or using the d attribute of a glyph node.
- // bpath stores the path description from the d attribute:
- NArtBpath *bpath = NULL;
- if (SP_IS_GLYPH(node) && ((SPGlyph*)node)->d) bpath = sp_svg_read_path(((SPGlyph*)node)->d);
- if (SP_IS_MISSING_GLYPH(node) && ((SPMissingGlyph*)node)->d) bpath = sp_svg_read_path(((SPMissingGlyph*)node)->d);
-
- if (bpath){
- //This glyph have a path description on its d attribute, so we render it:
- cairo_new_path(cr);
- NR::scale s(1.0/((SPFont*) node->parent)->horiz_adv_x);
- NR::Matrix t(s);
- NRRect area(0,0,1,1); //I need help here!
- feed_curve_to_cairo (cr, bpath, t, area.upgrade(), false, 0);
- cairo_fill(cr);
+ // pathv stores the path description from the d attribute:
+ Geom::PathVector pathv;
+ if (SP_IS_GLYPH(node) && ((SPGlyph*)node)->d) {
+ pathv = sp_svg_read_pathv(((SPGlyph*)node)->d);
+ } else if (SP_IS_MISSING_GLYPH(node) && ((SPMissingGlyph*)node)->d) {
+ pathv = sp_svg_read_pathv(((SPMissingGlyph*)node)->d);
+ } else {
+ return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return?
+ }
+
+ if (!pathv.empty()){
+ //This glyph has a path description on its d attribute, so we render it:
+ cairo_new_path(cr);
+ Geom::Scale s(1.0/((SPFont*) node->parent)->horiz_adv_x);
+ NRRect area(0,0,1,1); //I need help here!
+ feed_pathvector_to_cairo (cr, pathv, s, area.upgrade(), false, 0);
+ cairo_fill(cr);
}
//TODO: render the SVG described on this glyph's child nodes.