# HG changeset patch
# User wycc
# Date 1233366064 -28800
# Node ID a90fd749af82d6238d977a09a0e9d022724bef8c
# Parent 5006e4abdda5e8a41235eb71356c594ae8866439
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
diff -r 5006e4abdda5 -r a90fd749af82 configure.ac
--- a/configure.ac Sun Jan 04 12:01:41 2009 +0800
+++ b/configure.ac Sat Jan 31 09:41:04 2009 +0800
@@ -13,7 +13,8 @@
AC_PROG_LIBTOOL
# Checks for libraries.
-PKG_CHECK_MODULES([cairo], [cairo >= 1.6], , AC_MSG_ERROR([cairo >= 1.6 not found]))
+PKG_CHECK_MODULES([cairo], [cairo >= 0.22], , AC_MSG_ERROR([cairo >= 0.22 not found]))
+PKG_CHECK_MODULES([pangocairo], [pangocairo >= 0.22], , AC_MSG_ERROR([pangocairo >= 0.22 not found]))
# Checks for header files.
AC_PATH_X
diff -r 5006e4abdda5 -r a90fd749af82 examples/calculator/Makefile.am
--- a/examples/calculator/Makefile.am Sun Jan 04 12:01:41 2009 +0800
+++ b/examples/calculator/Makefile.am Sat Jan 31 09:41:04 2009 +0800
@@ -5,8 +5,8 @@
calc_SOURCES = main.c
nodist_calc_SOURCES = calculator_scr.c calculator_scr.h
-calc_CPPFLAGS = @cairo_CFLAGS@ $(INCLUDES)
-calc_LDFLAGS = @cairo_LIBS@
+calc_CPPFLAGS = @pangocairo_CFLAGS@ $(INCLUDES)
+calc_LDFLAGS = @pangocairo_LIBS@
calc_LDADD = $(top_builddir)/src/libmbfly.la
BUILT_SOURCES = calculator_scr.c calculator_scr.h calculator_scr.mb
CLEANFILES = calculator_scr.c calculator_scr.h calculator_scr.mb
diff -r 5006e4abdda5 -r a90fd749af82 examples/calculator/calculator_scr.svg
--- a/examples/calculator/calculator_scr.svg Sun Jan 04 12:01:41 2009 +0800
+++ b/examples/calculator/calculator_scr.svg Sat Jan 31 09:41:04 2009 +0800
@@ -519,9 +519,9 @@
style="font-size:14px;font-style:normal;font-weight:normal;fill:#008000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans Mono"
x="71.767807"
y="78.100266"
- id="text2238">None
diff -r 5006e4abdda5 -r a90fd749af82 examples/calculator/main.c
--- a/examples/calculator/main.c Sun Jan 04 12:01:41 2009 +0800
+++ b/examples/calculator/main.c Sat Jan 31 09:41:04 2009 +0800
@@ -66,8 +66,8 @@
rdman = X_MB_rdman(calc_data->rt);
sprintf(buf, "%d%s", num, suffix);
- sh_text_set_text(calc_data->code->screen_text, buf);
- rdman_shape_changed(rdman, calc_data->code->screen_text);
+ sh_text_set_text(calc_data->code->screen_text_u, buf);
+ rdman_shape_changed(rdman, calc_data->code->screen_text_u);
if(op == 'n')
sprintf(buf, "None");
diff -r 5006e4abdda5 -r a90fd749af82 examples/drag/Makefile.am
--- a/examples/drag/Makefile.am Sun Jan 04 12:01:41 2009 +0800
+++ b/examples/drag/Makefile.am Sat Jan 31 09:41:04 2009 +0800
@@ -5,8 +5,8 @@
ex1_SOURCES = main.c
nodist_ex1_SOURCES = menu.c menu.h
-ex1_CPPFLAGS = @cairo_CFLAGS@ -I$(top_srcdir)
-ex1_LDFLAGS = @cairo_LIBS@
+ex1_CPPFLAGS = @pangocairo_CFLAGS@ -I$(top_srcdir)
+ex1_LDFLAGS = @pangocairo_LIBS@
ex1_LDADD = $(top_builddir)/src/libmbfly.la
BUILT_SOURCES = menu.c menu.h menu.mb
CLEANFILES = menu.c menu.h menu.mb
diff -r 5006e4abdda5 -r a90fd749af82 examples/dynamic/Makefile.am
--- a/examples/dynamic/Makefile.am Sun Jan 04 12:01:41 2009 +0800
+++ b/examples/dynamic/Makefile.am Sat Jan 31 09:41:04 2009 +0800
@@ -1,6 +1,6 @@
include $(top_srcdir)/config.mk
-SUFFIXES=.svg .mbso
+SUFFIXES=.svg .so
%.so:%.svg
$(top_srcdir)/tools/svg2code.py $< $<.mb
@@ -9,24 +9,23 @@
make $(<:.svg=.o)
gcc -shared -o $@ $(<:.svg=.o)
-noinst_PROGRAMS = dynamic hello list button.so scene.so
+noinst_PROGRAMS = dynamic hello list
EXTRA_DIST = menu.svg button.svg
dynamic_SOURCES = main.c mbapp.c mbapp.h mbbutton.c mbbutton.h
nodist_dynamic_SOURCES =
-CPPFLAGS = @cairo_CFLAGS@ $(INCLUDES)
-dynamic_LDFLAGS = @cairo_LIBS@
+CPPFLAGS = @pangocairo_CFLAGS@ $(INCLUDES)
+dynamic_LDFLAGS = @pangocairo_LIBS@
dynamic_LDADD = $(top_builddir)/src/libmbfly.la
-BUILT_SOURCES = menu.c menu.h menu.mb button.c button.h button.mb
-CLEANFILES = menu.c menu.h menu.mb button.c button.h button.mb
+CLEANFILES = menu.c menu.h menu.mb button.c button.o button.mb button.so
hello_SOURCES = hello.c mbapp.c mbapp.h
-hello_LDFLAGS = @cairo_LIBS@
+hello_LDFLAGS = @pangocairo_LIBS@
hello_LDADD = $(top_builddir)/src/libmbfly.la
list_SOURCES = list.c mbapp.c mbapp.h
-list_LDFLAGS = @cairo_LIBS@
+list_LDFLAGS = @pangocairo_LIBS@
list_LDADD = $(top_builddir)/src/libmbfly.la
diff -r 5006e4abdda5 -r a90fd749af82 examples/dynamic/button.svg
--- a/examples/dynamic/button.svg Sun Jan 04 12:01:41 2009 +0800
+++ b/examples/dynamic/button.svg Sat Jan 31 09:41:04 2009 +0800
@@ -198,6 +198,20 @@
sodipodi:role="line">Click Me
+ ssssssssss
#include "mb_types.h"
#include "mb_redraw_man.h"
+#include
/*! \page define_shape How to Define Shapes
*
@@ -50,12 +51,97 @@
extern shape_t *rdman_shape_text_new(redraw_man_t *rdman,
const char *txt, co_aix x, co_aix y,
co_aix font_size,
- cairo_font_face_t *face);
+ cairo_font_face_t *face,PangoAttrList *attrs);
extern void sh_text_set_text(shape_t *shape, const char *txt);
extern void sh_text_transform(shape_t *shape);
extern void sh_text_draw(shape_t *shape, cairo_t *cr);
/* @} */
+/*! \defgroup mb_text_t Shape of Text
+ * @{
+ */
+#define TEXTSTYLE_BOLD 1
+#define TEXTSTYLE_ITALIC 2
+#define TEXTSTYLE_UNDERLINE 4
+#define TEXTSTYLE_COLOR 8
+#define TEXTSTYLE_FONT 0x10
+#define TEXTSTYLE_ALIGN 0x20
+
+typedef struct {
+ int property;
+ unsigned int color;
+ unsigned int align;
+ char *font;
+} mb_textstyle_t;
+
+typedef struct _textsegment {
+ int x;
+ int y;
+ mb_textstyle_t style;
+ int size;
+ char *buf;
+ struct _textsegment *next;
+} mb_text_segment_t;
+
+#define MBTEXT_DIRTY 1
+
+typedef struct {
+ int nseg;
+ mb_text_segment_t *segs;
+ int flag;
+ cairo_surface_t *surface;
+} mb_text_t;
+
+extern void mb_textstyle_init(mb_textstyle_t *style);
+extern void mb_textstyle_set_font(mb_textstyle_t *style, char *font);
+static inline char *mb_textstyle_get_font(mb_textstyle_t *style)
+{
+ if (style->property & TEXTSTYLE_FONT)
+ return style->font;
+ else
+ return NULL;
+}
+extern void mb_textstyle_set_bold(mb_textstyle_t *style, int bold);
+static inline int mb_textstyle_get_bold(mb_textstyle_t *style)
+{
+ return style->property & TEXTSTYLE_BOLD;
+}
+extern void mb_textstyle_set_italic(mb_textstyle_t *style, int italic);
+static inline int mb_textstyle_get_italic(mb_textstyle_t *style)
+{
+ return style->property & TEXTSTYLE_ITALIC;
+}
+extern void mb_textstyle_set_underline(mb_textstyle_t *style, int underline);
+static inline int mb_textstyle_get_undeline(mb_textstyle_t *style)
+{
+ return style->property & TEXTSTYLE_UNDERLINE;
+}
+extern void mb_textstyle_set_color(mb_textstyle_t *style, unsigned int color);
+static inline unsigned int mb_textstyle_get_color(mb_textstyle_t *style)
+{
+ if (style->property & TEXTSTYLE_COLOR)
+ return style->color;
+ else
+ return 0;
+}
+
+static inline int mb_textstyle_has_color(mb_textstyle_t *style)
+{
+ return style->property & TEXTSTYLE_COLOR;
+}
+extern void mb_textstyle_set_alignment(mb_textstyle_t *style, int alignment);
+extern int mb_textstyle_get_alignment(mb_textstyle_t *style);
+
+
+
+extern void mb_text_set_style(mb_text_t *text, int begin,int end,mb_textstyle_t *style);
+extern void mb_text_get_style(mb_text_t *text, int n,mb_textstyle_t *style);
+extern void mb_text_set_text(mb_text_t *text, char *string,int begin,int end);
+extern void mb_text_get_text(mb_text_t *text, int begin,int end, char *string);
+
+
+/* @} */
+
/*! \defgroup shape_rect Shape of Rectangle
* @{
*/
diff -r 5006e4abdda5 -r a90fd749af82 inkscape/MB_Frame.py
--- a/inkscape/MB_Frame.py Sun Jan 04 12:01:41 2009 +0800
+++ b/inkscape/MB_Frame.py Sat Jan 31 09:41:04 2009 +0800
@@ -494,7 +494,7 @@
def effect(self):
- self.OK = False
+ self.OK = True
self.parseScene()
self.showGrid()
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
diff -r 5006e4abdda5 -r a90fd749af82 src/Makefile.am
--- a/src/Makefile.am Sun Jan 04 12:01:41 2009 +0800
+++ b/src/Makefile.am Sat Jan 31 09:41:04 2009 +0800
@@ -9,10 +9,10 @@
shape_rect.c shape_text.c shift.c subtree_free.c timer.c \
timertool.c tools.c visibility.c X_supp.c prop.c sprite.c \
mouse.c
-libmbfly_la_CPPFLAGS = @cairo_CFLAGS@
-libmbfly_la_LDFLAGS = @cairo_LIBS@
+libmbfly_la_CPPFLAGS = @cairo_CFLAGS@ `pkg-config --cflags pangocairo`
+libmbfly_la_LDFLAGS = @cairo_LIBS@ `pkg-config --libs pangocairo`
X_main_SOURCES = X_main.c
X_main_LDADD = $(top_builddir)/src/libmbfly.la
-X_main_CPPFLAGS = @cairo_CFLAGS@ -I$(top_builddir)/src
-X_main_LDFLAGS = @cairo_LIBS@
+X_main_CPPFLAGS = @pangocairo_CFLAGS@ -I$(top_builddir)/src
+X_main_LDFLAGS = @pangocairo_LIBS@
diff -r 5006e4abdda5 -r a90fd749af82 src/X_main.c
--- a/src/X_main.c Sun Jan 04 12:01:41 2009 +0800
+++ b/src/X_main.c Sat Jan 31 09:41:04 2009 +0800
@@ -6,6 +6,7 @@
#include
#include
#include
+#include
#include
#include "mb_shapes.h"
@@ -138,6 +139,7 @@
mb_progm_t *progm;
mb_word_t *word;
mb_action_t *act;
+ PangoAttrList *attrs = pango_attr_list_new();
tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
tmpcr = cairo_create(tmpsuf);
@@ -155,7 +157,7 @@
face = cairo_get_font_face(tmpcr);
text = rdman_shape_text_new(&rdman, "hello \xe6\xbc\xa2\xe5\xad\x97",
- 10, h / 4, 36.0, face);
+ 10, h / 4, 36.0, face, attrs);
text_fill = rdman_paint_radial_new(&rdman, 100, h / 4, 70);
grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1);
grad_stop_init(text_stops + 1, 1, 0.9, 0.2, 0.2, 0.1);
diff -r 5006e4abdda5 -r a90fd749af82 src/shape_text.c
--- a/src/shape_text.c Sun Jan 04 12:01:41 2009 +0800
+++ b/src/shape_text.c Sat Jan 31 09:41:04 2009 +0800
@@ -3,6 +3,7 @@
#include
#include
#include
+#include
#include "mb_types.h"
#include "mb_shapes.h"
@@ -20,6 +21,8 @@
cairo_font_face_t *face;
cairo_scaled_font_t *scaled_font;
int flags;
+ PangoLayout *layout;
+ PangoAttrList *attrs;
} sh_text_t;
#define TXF_SCALE_DIRTY 0x1
@@ -34,13 +37,14 @@
shape_t *rdman_shape_text_new(redraw_man_t *rdman,
const char *txt, co_aix x, co_aix y,
- co_aix font_size, cairo_font_face_t *face) {
+ co_aix font_size, cairo_font_face_t *face,PangoAttrList *attrs) {
sh_text_t *text;
text = (sh_text_t *)malloc(sizeof(sh_text_t));
if(text == NULL)
return NULL;
+
memset(text, 0, sizeof(sh_text_t));
mb_obj_init(text, MBO_TEXT);
text->data = strdup(txt);
@@ -56,6 +60,8 @@
text->flags |= TXF_SCALE_DIRTY;
text->shape.free = sh_text_free;
+ text->layout = NULL;
+ text->attrs = attrs;
rdman_shape_man(rdman, (shape_t *)text);
@@ -126,7 +132,7 @@
ASSERT(r == OK);
text->d_x = x;
- text->d_y = y;
+ text->d_y = y-text->font_size;
shw = shape->stroke_width / 2;
/* FIXME: It is unreasonable that a font exceed it's bbox.
* We add 5 pixels in get right bbox. But, it is unreasonable.
@@ -139,11 +145,29 @@
/*! \todo Support ratation for shape_text. */
}
+static void sh_text_P_generate_layout(sh_text_t *text,cairo_t *cr)
+{
+ PangoAttribute *attr;
+ PangoAttrList *attrlist;
+ PangoFontDescription *desc;
+ if (text->layout) {
+ g_object_unref(text->layout);
+ }
+ text->layout = pango_cairo_create_layout(cr);
+ desc = pango_font_description_from_string("Sans Bold");
+ pango_layout_set_font_description (text->layout, desc);
+ pango_cairo_update_layout(cr,text->layout);
+ pango_layout_set_text(text->layout,text->data,-1);
+ pango_layout_set_attributes(text->layout, text->attrs);
+
+}
static void draw_text(sh_text_t *text, cairo_t *cr) {
- cairo_set_scaled_font(cr, text->scaled_font);
+ if (text->layout==NULL) {
+ sh_text_P_generate_layout(text,cr);
+ }
cairo_move_to(cr, text->d_x, text->d_y);
- cairo_text_path(cr, text->data);
+ pango_cairo_show_layout(cr,text->layout);
}
diff -r 5006e4abdda5 -r a90fd749af82 tools/mb_c_header.m4
--- a/tools/mb_c_header.m4 Sun Jan 04 12:01:41 2009 +0800
+++ b/tools/mb_c_header.m4 Sat Jan 31 09:41:04 2009 +0800
@@ -20,6 +20,15 @@
define([ADD_TEXT],[
[ shape_t *$1;
]])
+define([PANGO_BEGIN_TEXT],[
+[ shape_t *$1;
+]])
+define([PANGO_END_TEXT],[
+])
+define([PANGO_SIZE],[])
+define([PANGO_STYLE],[])
+define([PANGO_WEIGHT],[])
+define([PANGO_FAMILY],[])
define([COLOR_STOP],[ ])
define([REF_STOPS_RADIAL],)
diff -r 5006e4abdda5 -r a90fd749af82 tools/mb_c_source.m4
--- a/tools/mb_c_source.m4 Sun Jan 04 12:01:41 2009 +0800
+++ b/tools/mb_c_source.m4 Sat Jan 31 09:41:04 2009 +0800
@@ -20,6 +20,12 @@
define([ADD_RECT])
define([ADD_COORD])
define([ADD_TEXT],)
+define([PANGO_BEGIN_TEXT],)
+define([PANGO_END_TEXT],)
+define([PANGO_SIZE],)
+define([PANGO_STYLE],)
+define([PANGO_WEIGHT],)
+define([PANGO_FAMILY],)
define([FILL_SHAPE])
define([STROKE_SHAPE])
define([FILL_SHAPE_WITH_PAINT])
@@ -118,6 +124,42 @@
cairo_get_font_face(rdman->cr));
rdman_add_shape(rdman, obj->$1, obj->$6);
]])
+define([S_PANGO_BEGIN_TEXT],[[
+ {
+ PangoAttribute *attr;
+ PangoAttrList *attrs = pango_attr_list_new();
+
+]])
+define([S_PANGO_END_TEXT],[[
+ obj->$1 = rdman_shape_text_new(rdman, "$2", $3, $4, $5,
+ cairo_get_font_face(rdman->cr),attrs);
+ rdman_add_shape(rdman, obj->$1, obj->$6);
+ }
+]])
+define([S_PANGO_SIZE],[[
+ attr = pango_attr_size_new($1);
+ attr->start_index = $2;
+ attr->end_index = $3;
+ pango_attr_list_insert(attrs,attr);
+]])
+define([S_PANGO_WEIGHT],[[
+ attr = pango_attr_weight_new($1);
+ attr->start_index = $2;
+ attr->end_index = $3;
+ pango_attr_list_insert(attrs,attr);
+]])
+define([S_PANGO_FAMILY],[[
+ attr = pango_attr_family_new("$1");
+ attr->start_index = $2;
+ attr->end_index = $3;
+ pango_attr_list_insert(attrs,attr);
+]])
+define([S_PANGO_STYLE],[[
+ attr = pango_attr_style_new($1);
+ attr->start_index = $2;
+ attr->end_index = $3;
+ pango_attr_list_insert(attrs,attr);
+]])
define([S_FILL_SHAPE_WITH_PAINT],[dnl
[ rdman_paint_fill(rdman, obj->$2, obj->$1);
@@ -203,6 +245,12 @@
SIMPORT([ADD_RECT])
SIMPORT([ADD_COORD])
SIMPORT([ADD_TEXT])
+SIMPORT([PANGO_BEGIN_TEXT])
+SIMPORT([PANGO_END_TEXT])
+SIMPORT([PANGO_SIZE])
+SIMPORT([PANGO_WEIGHT])
+SIMPORT([PANGO_FAMILY])
+SIMPORT([PANGO_STYLE])
SIMPORT([FILL_SHAPE])
SIMPORT([STROKE_SHAPE])
SIMPORT([FILL_SHAPE_WITH_PAINT])
@@ -240,6 +288,15 @@
define([F_ADD_TEXT],[[
rdman_shape_free(rdman, obj->$1);
]])
+define([F_PANGO_BEGIN_TEXT],[[
+ rdman_shape_free(rdman, obj->$1);
+]])
+define([F_PANGO_SIZE],[[
+]])
+define([F_PANGO_STYLE],[[
+]])
+define([F_PANGO_WEIGHT],[[
+]])
define([F_FILL_SHAPE],[[
rdman_paint_free(rdman, obj->$1_fill);
@@ -257,6 +314,7 @@
FIMPORT([ADD_PATH],)
FIMPORT([ADD_RECT])
FIMPORT([ADD_TEXT])
+FIMPORT([PANGO_BEGIN_TEXT])
FIMPORT([FILL_SHAPE])
FIMPORT([STROKE_SHAPE])
divert[]])
@@ -283,6 +341,7 @@
RIMPORT([ADD_RECT])
RIMPORT([ADD_COORD])
RIMPORT([ADD_TEXT])
+RIMPORT([PANGO_BEGIN_TEXT])
RIMPORT([FILL_SHAPE])
RIMPORT([STROKE_SHAPE])
RIMPORT([FILL_SHAPE_WITH_PAINT])
diff -r 5006e4abdda5 -r a90fd749af82 tools/svg2code.py
--- a/tools/svg2code.py Sun Jan 04 12:01:41 2009 +0800
+++ b/tools/svg2code.py Sat Jan 31 09:41:04 2009 +0800
@@ -128,6 +128,7 @@
style_str = node.getAttribute('style')
prop_map = get_style_map(style_str)
+ print node_id,style_str
try:
opacity = float(node.getAttribute('opacity'))
except:
@@ -350,47 +351,139 @@
style_str = text.getAttribute('style')
style_map = get_style_map(style_str)
- font_sz = 10.0
- if style_map.has_key('font-size'):
- if style_map['font-size'].endswith('px'):
- font_sz = float(style_map['font-size'][:-2])
- print >> codefo, 'define([MB_FONT_SZ], %f)dnl' % (font_sz)
+ return style_map
+
+
+def translate_tspan(tspan, coord_id, codefo, doc,txt_strs,attrs):
+ map = translate_font_style(tspan, codefo)
+ tspan.style_map = map
+ attr = [len(txt_strs),0, tspan]
+ attrs.append(attr)
+ for node in tspan.childNodes:
+ if node.localName == None:
+ txt_strs = txt_strs + node.data
+ elif node.localName == 'tspan':
+ txt_strs = translate_tspan(node,coord_id, codefo, doc,txt_strs,attrs)
pass
pass
+ attr[1] = len(txt_strs)-1
+ return txt_strs
- font_style = 'normal'
- if style_map.has_key('font-style'):
- font_style = style_map['font-style'].lower()
+
+
+def generate_font_attributes(attrs,coord_id, codefo,doc):
+ for a in attrs:
+ start = a[0]
+ end = a[1]
+ node = a[2]
+ #print "generate attributes from %d to %d" %(start,end)
+ style_map = node.style_map
+ #print [style_map]
+ if style_map.has_key('font-size'):
+ # FIXME: Implement all units here
+ if style_map['font-size'].endswith('px'):
+ font_sz = float(style_map['font-size'][:-2])
+ print >> codefo, 'PANGO_SIZE(%d,%d,%d)' % (font_sz,start,end)
+ else:
+ font_sz = float(style_map['font-size'])
+ print >> codefo, 'PANGO_SIZE(%d,%d,%d)' % (font_sz,start,end)
+ pass
+
+ if style_map.has_key('font-style'):
+ font_style = style_map['font-style'].lower()
+ if font_style == 'normal':
+ print >> codefo, 'PANGO_STYLE(PANGO_STYLE_NORMAL,%d,%d)' % (start,end)
+ elif font_style == 'italic':
+ print >> codefo, 'PANGO_STYLE(PANGO_STYLE_ITALIC,%d,%d)' % (start,end)
+ elif font_style == 'oblique':
+ print >> codefo, 'PANGO_STYLE(PANGO_STYLE_OBLIQUE,%d,%d)' % (start,end)
pass
- font_family = 'Roman'
- if style_map.has_key('font-family'):
- font_family = style_map['font-family'].lower()
+ if style_map.has_key('font-family'):
+ font_family = style_map['font-family'].lower()
+ print >> codefo, 'PANGO_FAMILY(%s,%d,%d)' % (font_family,start,end)
+ pass
+ if style_map.has_key('text-anchor'):
+ text_anchor = style_map['text-anchor'].lower()
+ # FIXME: We need to implement a mb_text_set_aligment to implement SVG-styled alignment.
+ print "The text-anchor is not implemented yet"
+ pass
+ if style_map.has_key('font-variant'):
+ font_variant = style_map['font-variant'].lower()
+ print "The font-variant is not implemented yet"
+ pass
+ if style_map.has_key('font-weight'):
+ font_weight = style_map['font-weight'].lower()
+ if font_weight == 'normal':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_NORMAL,%d,%d)' % (start,end)
+ elif font_weight == 'bold':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_BOLD,%d,%d)' % (start,end)
+ elif font_weight == 'bolder':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_HEAVY,%d,%d)' % (start,end)
+ elif font_weight == 'lighter':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRALIGHT,%d,%d)' % (start,end)
+ elif font_weight == '100':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRALIGHT,%d,%d)' % (start,end)
+ elif font_weight == '200':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRALIGHT,%d,%d)' % (start,end)
+ elif font_weight == '300':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_LIGHT,%d,%d)' % (start,end)
+ elif font_weight == '400':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_NORMAL,%d,%d)' % (start,end)
+ elif font_weight == '500':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_NORMAL,%d,%d)' % (start,end)
+ elif font_weight == '600':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_SEMIBOLD,%d,%d)' % (start,end)
+ elif font_weight == '700':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_BOLD,%d,%d)' % (start,end)
+ elif font_weight == '800':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRABOLD,%d,%d)' % (start,end)
+ elif font_weight == '900':
+ print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_HEAVY,%d,%d)' % (start,end)
+ else:
+ print "The font-weight %s is not supported" % font_weight
+ pass
+ if style_map.has_key('direction'):
+ direction = style_map['direction'].lower()
+ print "The direction is not implemented yet"
+ pass
+ if style_map.has_key('unicode-bidi'):
+ bidi = style_map['unicode-bidi'].lower()
+ print "The bidi is not implemented yet"
pass
pass
-
+
def translate_text(text, coord_id, codefo, doc):
- translate_font_style(text, codefo)
+ map = translate_font_style(text, codefo)
+ attrs = []
+ text.style_map = map
+ attr = [0,0, text]
+ attrs.append(attr)
- txt_strs = []
+ txt_strs = ''
for node in text.childNodes:
if node.localName == None:
- txt_strs.append(node.data)
+ txt_strs = txt_strs + node.data
elif node.localName == 'tspan':
- node.setAttribute('style', text.getAttribute('style'))
- translate_text(node, coord_id, codefo, doc)
+ txt_strs = translate_tspan(node,coord_id, codefo, doc,txt_strs,attrs)
pass
pass
+ attr[1] = len(txt_strs)-1
if txt_strs:
text_id = _get_id(text)
x = float(text.getAttribute('x'))
y = float(text.getAttribute('y'))
print >> codefo, 'dnl'
print >> codefo, \
- 'ADD_TEXT([%s], [%s], %f, %f, MB_FONT_SZ, [%s])dnl' % (
+ 'PANGO_BEGIN_TEXT([%s], [%s], %f, %f, 16, [%s])dnl' % (
text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'),
x, y, coord_id.encode('utf8'))
- translate_style(text, coord_id, codefo, doc, 'TEXT_')
+ generate_font_attributes(attrs, coord_id, codefo, doc)
+ print >> codefo, \
+ 'PANGO_END_TEXT([%s], [%s], %f, %f, 16, [%s])dnl' % (
+ text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'),
+ x, y, coord_id.encode('utf8'))
+ translate_style(text, coord_id, codefo, doc, 'TEXT_')
pass
pass
@@ -449,6 +542,9 @@
elif node.localName == 'text':
translate_text(node, group_id, codefo, doc)
pass
+ elif node.localName == 'textarea':
+ translate_textarea(node, group_id, codefo, doc)
+ pass
pass
pass