summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6abea08)
raw | patch | inline | side by side (parent: 6abea08)
author | JucaBlues <JucaBlues@users.sourceforge.net> | |
Sun, 25 May 2008 15:35:28 +0000 (15:35 +0000) | ||
committer | JucaBlues <JucaBlues@users.sourceforge.net> | |
Sun, 25 May 2008 15:35:28 +0000 (15:35 +0000) |
* First code for SVGFonts rendering. Renders in a separate window because we still dont have pango integration.
17 files changed:
configure.ac | patch | blob | history | |
share/examples/svgfont.svg | patch | blob | history | |
src/display/Makefile_insert | patch | blob | history | |
src/display/nr-arena-glyphs.cpp | patch | blob | history | |
src/display/nr-svgfonts.cpp | [new file with mode: 0644] | patch | blob |
src/display/nr-svgfonts.h | [new file with mode: 0644] | patch | blob |
src/sp-font-face.cpp | patch | blob | history | |
src/sp-font-face.h | patch | blob | history | |
src/sp-font.cpp | patch | blob | history | |
src/sp-font.h | patch | blob | history | |
src/sp-glyph-kerning.cpp | patch | blob | history | |
src/sp-glyph-kerning.h | patch | blob | history | |
src/sp-glyph.cpp | patch | blob | history | |
src/sp-glyph.h | patch | blob | history | |
src/sp-missing-glyph.cpp | patch | blob | history | |
src/sp-missing-glyph.h | patch | blob | history | |
src/sp-object-repr.cpp | patch | blob | history |
diff --git a/configure.ac b/configure.ac
index 00cffd4a74299e0337b0f2c72f205fc804c44267..852970ba8d2a579c020035ef60d6fff147f2e70c 100644 (file)
--- a/configure.ac
+++ b/configure.ac
AC_SUBST(IMAGEMAGICK_LIBS)
AC_SUBST(IMAGEMAGICK_CFLAGS)
+dnl ***********************************************************************************************************
+dnl Check for a Cairo version that implements user-fonts feature, so that we conditionally add SVGFonts support
+dnl ***********************************************************************************************************
+
+PKG_CHECK_MODULES(CAIRO_USER_FONTS, cairo > 1.6.4, cairouserfonts=yes, cairouserfonts=no)
+if test "x$cairouserfonts" = "xyes"; then
+ AC_DEFINE(ENABLE_SVG_FONTS, 1, [SVG Fonts should be used])
+fi
+
dnl ******************************
dnl Unconditional dependencies
dnl ******************************
index 4e9a06eab2009bb0a74ac952f9f13e0266a8c4c6..10bac6e9178440dc51447cc4c01493647c711efb 100644 (file)
<?xml version="1.0" standalone="yes"?>
<svg width="400px" height="300px" version="1.1"
xmlns = 'http://www.w3.org/2000/svg'>
- <defs>
- <font id="Font1" horiz-adv-x="1000">
- <font-face font-family="Super Sans" font-weight="bold"
- units-per-em="1234" font-style="normal, oblique" cap-height="600" x-height="400"
- ascent="700" descent="300"
- alphabetic="0" mathematical="350" ideographic="400" hanging="500">
- <font-face-src>
- <font-face-name name="Super Sans Bold"/>
- </font-face-src>
- </font-face>
- <!--<missing-glyph d="M0,0h200v200h-200z"/>--><!-- uncomment this line in orther to test missing-glyph -->
- <glyph unicode="!" d="M0,0h500v500h-500z"><circle r='500' cx='500' cy='500' style="fill:none;stroke:green;"/></glyph>
- <glyph unicode="@" d="M500,500h500v500h-500z"><circle r='250' cx='500' cy='500' style="fill:blue;"/></glyph>
- <!--<hkern u1="!" u2="@" k="1000" />--><!-- uncomment this line in orther to test horizontal kerning-->
+ <font id="Font1" horiz-adv-x="1000">
+ <font-face font-family="Super Sans" font-style="oblique" font-stretch="ultra-expanded" />
+ <glyph unicode="!" d="M0,0h500v500h-500z">
+ <circle r='500' cx='500' cy='500' style="fill:none;stroke:green;"/>
+ </glyph>
+ <glyph unicode="@" d="M500,500h500v500h-500z">
+ <circle r='250' cx='500' cy='500' style="fill:blue;"/>
+ </glyph>
+ <missing-glyph d="M0,0h1000v1000h-1000z"></missing-glyph>
+ <hkern u1="!" u2="@" k="1000" />
</font>
- </defs>
- <text x="100" y="100"
- style="font-family: 'Super Sans';font-weight: bold; font-style: normal;fill:red;">A!@A</text>
+
+ <text x="100" y="100" style="font-size:70;font-family:'Super Sans';fill:red;">This text is not used yet. Currently test strings are hardcoded...</text>
</svg>
index 2e27cc1889b5efc1285fae3b667cfeb4eae0f7f2..5c7fd892eb7149a6660fe75ba77f3828c919a836 100644 (file)
display/nr-plain-stuff-gdk.h \
display/nr-plain-stuff.cpp \
display/nr-plain-stuff.h \
+ display/nr-svgfonts.cpp \
+ display/nr-svgfonts.h \
display/rendermode.h \
display/snap-indicator.cpp \
display/snap-indicator.h \
index 6ee1be796b534febaed10b06b0a225e4032c2e6e..63af4787adbf14cf14641f126cc8a61ddd7a413b 100644 (file)
void nr_pixblock_render_shape_mask_or(NRPixBlock &m, Shape *theS);
#endif
+#include "nr-svgfonts.h"
+
static void nr_arena_glyphs_class_init(NRArenaGlyphsClass *klass);
static void nr_arena_glyphs_init(NRArenaGlyphs *glyphs);
static void nr_arena_glyphs_finalize(NRObject *object);
diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp
--- /dev/null
@@ -0,0 +1,156 @@
+#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.h>
+#include "../style.h"
+#include "../sp-glyph.h"
+#include "../sp-missing-glyph.h"
+#include "../sp-font.h"
+#include <cairo.h>
+#include <vector>
+#include "svg/svg.h"
+#include "inkscape-cairo.h"
+#include <gtk/gtk.h>
+
+static std::vector<SPGlyph*> glyphs;
+static SPMissingGlyph* missingglyph = NULL;
+static std::vector<SPFont*> svgfonts;
+
+cairo_font_face_t* nr_svgfonts_get_user_font_face();
+void nr_svgfonts_append_spfont(SPFont* font);
+static cairo_status_t scaled_font_init (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *metrics);
+static cairo_status_t scaled_font_unicode_to_glyph (cairo_scaled_font_t *scaled_font, unsigned long unicode, unsigned long *glyph);
+static cairo_status_t scaled_font_render_glyph (cairo_scaled_font_t *scaled_font, unsigned long glyph, cairo_t *cr, cairo_text_extents_t *metrics);
+
+void nr_svgfonts_append_spfont(SPFont* font){
+ svgfonts.push_back(font);
+ nr_svgfonts_get_user_font_face();
+}
+
+static cairo_status_t
+scaled_font_init (cairo_scaled_font_t *scaled_font,
+ cairo_font_extents_t *metrics)
+{
+//TODO
+// metrics->ascent = .75;
+// metrics->descent = .25;
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
+scaled_font_unicode_to_glyph (cairo_scaled_font_t *scaled_font,
+ unsigned long unicode,
+ unsigned long *glyph)
+{
+//g_warning("scaled_font_unicode_to_glyph CALL. unicode=%c", (char)unicode);
+
+ unsigned long i;
+ for (i=0; i < (unsigned long) glyphs.size(); i++){
+ //TODO: compare unicode strings for ligadure glyphs (i.e. scaled_font_text_to_glyph)
+ if ( ((unsigned long) glyphs[i]->unicode[0]) == unicode){
+ *glyph = i;
+ return CAIRO_STATUS_SUCCESS;
+ }
+ }
+ *glyph = i;
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
+scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
+ unsigned long glyph,
+ cairo_t *cr,
+ cairo_text_extents_t *metrics)
+{
+//g_warning("scaled_font_render_glyph CALL. glyph=%d", (int)glyph);
+
+ if (glyph > glyphs.size()) return CAIRO_STATUS_SUCCESS;
+
+ SPObject* node;
+ if (glyph == glyphs.size()){
+ if (!missingglyph) return CAIRO_STATUS_SUCCESS;
+ node = (SPObject*) missingglyph;
+ g_warning("RENDER MISSING-GLYPH");
+ } else {
+ node = (SPObject*) glyphs[glyph];
+ g_warning("RENDER %c", glyphs[glyph]->unicode[0]);
+ }
+
+ NArtBpath *bpath = NULL;
+ if (SP_IS_GLYPH(node)) bpath = sp_svg_read_path(((SPGlyph*)node)->d);
+ if (SP_IS_MISSING_GLYPH(node)) bpath = sp_svg_read_path(((SPMissingGlyph*)node)->d);
+
+ 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);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+
+bool drawing_expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+ cairo_t *cr = gdk_cairo_create (widget->window);
+
+ cairo_set_font_face (cr, nr_svgfonts_get_user_font_face());
+ cairo_set_font_size (cr, 200);
+ cairo_move_to (cr, 200, 200);
+ cairo_show_text (cr, "A@!A");
+
+ cairo_move_to (cr, 200, 400);
+ cairo_show_text (cr, "A!@A");
+
+ cairo_destroy (cr);
+
+ return TRUE;
+}
+
+
+cairo_font_face_t * nr_svgfonts_get_user_font_face(){
+ static cairo_font_face_t *user_font_face = NULL;
+
+ if (!user_font_face) {
+ for(SPObject* node = svgfonts[0]->children;node;node=node->next){
+ if (SP_IS_GLYPH(node)){
+ g_warning("glyphs.push_back((SPGlyph*)node); (node->unicode[0]='%c')", ((SPGlyph*)node)->unicode[0]);
+ glyphs.push_back((SPGlyph*)node);
+ }
+ if (SP_IS_MISSING_GLYPH(node)){
+ g_warning("missingglyph=(SPMissingGlyph*)node;");
+ missingglyph=(SPMissingGlyph*)node;
+ }
+ }
+ user_font_face = cairo_user_font_face_create ();
+ cairo_user_font_face_set_init_func (user_font_face, scaled_font_init);
+ cairo_user_font_face_set_render_glyph_func (user_font_face, scaled_font_render_glyph);
+ cairo_user_font_face_set_unicode_to_glyph_func (user_font_face, scaled_font_unicode_to_glyph);
+
+ GtkWidget *window;
+ GtkWidget *drawing;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW(window), 1200, 850);
+ drawing = gtk_drawing_area_new ();
+ gtk_container_add (GTK_CONTAINER (window), drawing);
+ gtk_widget_show_all (window);
+ g_signal_connect (drawing, "expose-event", G_CALLBACK (drawing_expose_cb), NULL);
+ }
+ return user_font_face;
+}
+#endif //#ifdef ENABLE_SVG_FONTS
+
diff --git a/src/display/nr-svgfonts.h b/src/display/nr-svgfonts.h
--- /dev/null
@@ -0,0 +1,25 @@
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
+#ifndef __SVGFONTS_H__
+#define __SVGFONTS_H__
+/*
+ * SVGFonts rendering headear
+ *
+ * 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 "../sp-font.h"
+#include "cairo.h"
+
+void nr_svgfonts_append_spfont(SPFont* font);
+cairo_font_face_t* nr_svgfonts_get_user_font_face();
+
+#endif //#ifndef __SVGFONTS_H__
+#endif //#ifdef ENABLE_SVG_FONTS
+
diff --git a/src/sp-font-face.cpp b/src/sp-font-face.cpp
index 78fc51a6bf627d9d7ba7bad1c07c62ea3e5302b0..ad4d586fc2e8f3f3d6d9ab1ed527090b5efbe574 100644 (file)
--- a/src/sp-font-face.cpp
+++ b/src/sp-font-face.cpp
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#define __SP_FONTFACE_C__
/*
@@ -531,7 +533,7 @@ static Inkscape::XML::Node *sp_fontface_write(SPObject *object, Inkscape::XML::N
return repr;
}
-
+#endif //#ifdef ENABLE_SVG_FONTS
/*
Local Variables:
mode:c++
diff --git a/src/sp-font-face.h b/src/sp-font-face.h
index 754125831ab6e2a0722dfed792caf57979027e01..d4ac8790a0f7151895634d582705b1a9b04207a4 100644 (file)
--- a/src/sp-font-face.h
+++ b/src/sp-font-face.h
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#ifndef __SP_FONTFACE_H__
#define __SP_FONTFACE_H__
GType sp_fontface_get_type (void);
#endif //#ifndef __SP_FONTFACE_H__
+#endif //#ifdef ENABLE_SVG_FONTS
diff --git a/src/sp-font.cpp b/src/sp-font.cpp
index a78f92cc00733abbd40f9d0d787a36194275eee2..5f8d3440a6f35f17cc2eb7d0c6b3099264f14662 100644 (file)
--- a/src/sp-font.cpp
+++ b/src/sp-font.cpp
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#define __SP_FONT_C__
/*
#include "document.h"
#include "helper-fns.h"
+#include "display/nr-svgfonts.h"
+
static void sp_font_class_init(SPFontClass *fc);
static void sp_font_init(SPFont *font);
sp_object_read_attr(object, "vert-origin-x");
sp_object_read_attr(object, "vert-origin-y");
sp_object_read_attr(object, "vert-adv-y");
+
+ nr_svgfonts_append_spfont(SP_FONT(object));
}
return repr;
}
-
+#endif //#ifdef ENABLE_SVG_FONTS
/*
Local Variables:
mode:c++
diff --git a/src/sp-font.h b/src/sp-font.h
index 3ec866ccc83e3a18b9373b9cbc05e9472c22a418..d8dc3718944e284425bf4d64f068b1fa0d15a343 100644 (file)
--- a/src/sp-font.h
+++ b/src/sp-font.h
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#ifndef __SP_FONT_H__
#define __SP_FONT_H__
GType sp_font_get_type (void);
#endif //#ifndef __SP_FONT_H__
+#endif //#ifdef ENABLE_SVG_FONTS
index 6d7006f577a89e1df10445bcefb59399d136ac39..b8a2bb1edd0e1db17dc768b6e4cb3911c71ad564 100644 (file)
--- a/src/sp-glyph-kerning.cpp
+++ b/src/sp-glyph-kerning.cpp
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#define __SP_ANCHOR_C__
/*
@@ -229,7 +231,7 @@ static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::X
return repr;
}
-
+#endif //#ifdef ENABLE_SVG_FONTS
/*
Local Variables:
mode:c++
diff --git a/src/sp-glyph-kerning.h b/src/sp-glyph-kerning.h
index 2933a8abe578ce36b0ca3ae3ffdadb02f6b6bce4..806ec0986731fc67a281340acdf93e32ba13ab09 100644 (file)
--- a/src/sp-glyph-kerning.h
+++ b/src/sp-glyph-kerning.h
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#ifndef __SP_GLYPH_KERNING_H__
#define __SP_GLYPH_KERNING_H__
GType sp_glyph_kerning_v_get_type (void);
#endif //#ifndef __SP_GLYPH_KERNING_H__
+#endif //#ifdef ENABLE_SVG_FONTS
diff --git a/src/sp-glyph.cpp b/src/sp-glyph.cpp
index 0c6d3f1e0dd9541e61b142ff669880c4cd2a671c..4860b42ed2a804026bde95b62c30a23aa63488b9 100644 (file)
--- a/src/sp-glyph.cpp
+++ b/src/sp-glyph.cpp
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#define __SP_GLYPH_C__
/*
@@ -295,7 +297,7 @@ static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Node
return repr;
}
-
+#endif //#ifdef ENABLE_SVG_FONTS
/*
Local Variables:
mode:c++
diff --git a/src/sp-glyph.h b/src/sp-glyph.h
index 40513a259ee080c2f3a1ea9f0cabca2c1b3bf594..a1657dd43075cdfb667f0c66ac5542b963610be4 100644 (file)
--- a/src/sp-glyph.h
+++ b/src/sp-glyph.h
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#ifndef __SP_GLYPH_H__
#define __SP_GLYPH_H__
GType sp_glyph_get_type (void);
#endif //#ifndef __SP_GLYPH_H__
+#endif //#ifdef ENABLE_SVG_FONTS
index d4cd16360192bc6bc9c6c58968bb14cc9123e414..7cd75b3b810292b3d4719c3659d7adf81b1b615c 100644 (file)
--- a/src/sp-missing-glyph.cpp
+++ b/src/sp-missing-glyph.cpp
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#define __SP_MISSING_GLYPH_C__
/*
@@ -178,7 +180,7 @@ static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::X
return repr;
}
-
+#endif //#ifdef ENABLE_SVG_FONTS
/*
Local Variables:
mode:c++
diff --git a/src/sp-missing-glyph.h b/src/sp-missing-glyph.h
index 41b988ab17fcde8ebc7c142b9b183d9deac053d6..4983dce69f708c60d3e226bdcd28fc0a3e267713 100644 (file)
--- a/src/sp-missing-glyph.h
+++ b/src/sp-missing-glyph.h
+#include "config.h"
+#ifdef ENABLE_SVG_FONTS
#ifndef __SP_MISSING_GLYPH_H__
#define __SP_MISSING_GLYPH_H__
GType sp_missing_glyph_get_type (void);
#endif //#ifndef __SP_MISSING_GLYPH_H__
+#endif //#ifdef ENABLE_SVG_FONTS
diff --git a/src/sp-object-repr.cpp b/src/sp-object-repr.cpp
index 6ed2f9adab00879452af4a2803d0a47d83ec8aca..7eb91d281046aa13bc9a6eed2d00374578cabf92 100644 (file)
--- a/src/sp-object-repr.cpp
+++ b/src/sp-object-repr.cpp
#include "sp-flowdiv.h"
#include "sp-flowregion.h"
#include "sp-flowtext.h"
-#include "sp-font.h"
-#include "sp-font-face.h"
-#include "sp-glyph.h"
-#include "sp-missing-glyph.h"
-#include "sp-glyph-kerning.h"
+#include "config.h"
+
+#ifdef ENABLE_SVG_FONTS
+ #include "sp-font.h"
+ #include "sp-font-face.h"
+ #include "sp-glyph.h"
+ #include "sp-missing-glyph.h"
+ #include "sp-glyph-kerning.h"
+#endif
+
#include "sp-style-elem.h"
#include "sp-switch.h"
#include "color-profile-fns.h"
{ "svg:flowRegionExclude", SP_TYPE_FLOWREGIONEXCLUDE },
{ "svg:flowRoot", SP_TYPE_FLOWTEXT },
{ "svg:flowSpan", SP_TYPE_FLOWTSPAN },
+#ifdef ENABLE_SVG_FONTS
{ "svg:font", SP_TYPE_FONT },
{ "svg:font-face", SP_TYPE_FONTFACE },
{ "svg:glyph", SP_TYPE_GLYPH },
{ "svg:missing-glyph", SP_TYPE_MISSING_GLYPH },
{ "svg:hkern", SP_TYPE_HKERN },
{ "svg:vkern", SP_TYPE_VKERN },
+#endif
{ "svg:g", SP_TYPE_GROUP },
{ "svg:feBlend", SP_TYPE_FEBLEND },
{ "svg:feColorMatrix", SP_TYPE_FECOLORMATRIX },