Verified Commit 665f9429 authored by Zander's avatar Zander 💥

Remove libart renderer

Only benefit to libart was antialiasing with is now provided by cairo
parent ea21bcab
......@@ -328,13 +328,9 @@ do_convert(const char *infname,
* are quite some filter selecting their output format by it. --hb
*/
if (size) {
if (ef == filter_export_get_by_name ("png-libart")) /* the warning we get is appropriate, don't cast */
ef->export_func(diagdata, ctx, outfname, infname, (gpointer) size);
else {
g_warning ("--size parameter unsupported for %s filter",
ef->unique_name ? ef->unique_name : "selected");
ef->export_func(diagdata, ctx, outfname, infname, ef->user_data);
}
g_warning ("--size parameter unsupported for %s filter",
ef->unique_name ? ef->unique_name : "selected");
ef->export_func(diagdata, ctx, outfname, infname, ef->user_data);
}
else
ef->export_func(diagdata, ctx, outfname, infname, ef->user_data);
......@@ -371,9 +367,6 @@ dump_dependencies(void)
"threads "
#endif
"cairo "
#ifdef HAVE_LIBART
"libart "
#endif
"pangocairo "
"\n");
......@@ -482,11 +475,7 @@ handle_initial_diagram(const char *in_file_name,
/* First try guessing based on extension */
export_file_name = build_output_file_name(in_file_name, export_file_format, outdir);
/* to make the --size hack even uglier but work again for the only filter supporting it */
if ( size && strcmp(export_file_format, "png") == 0)
ef = filter_export_get_by_name ("png-libart");
if (!ef)
ef = filter_guess_export_filter(export_file_name);
ef = filter_guess_export_filter(export_file_name);
if (ef == NULL) {
ef = filter_export_get_by_name(export_file_format);
if (ef == NULL) {
......@@ -502,11 +491,6 @@ handle_initial_diagram(const char *in_file_name,
g_free(export_file_name);
} else if (out_file_name) {
DiaExportFilter *ef = NULL;
/* if this looks like an ugly hack to you, agreed ;) */
if (size && strstr(out_file_name, ".png"))
ef = filter_export_get_by_name ("png-libart");
made_conversions |= do_convert(in_file_name, out_file_name, ef,
size, show_layers);
} else {
......
......@@ -1091,44 +1091,6 @@ ddisplay_get_clicked_position(DDisplay *ddisp)
return ddisp->clicked_position;
}
/**
* Kind of dirty way to initialize an anti-aliased renderer, maybe there
* should be some plug-in interface to do this.
* With the Libart renderer being a deprecated plug-in and the cairo renderer
* offering a lot of features including proper highlighting it seems reasonable
* to have default at cairo, although you loose a lot when it is switched off ;)
*/
static DiaRenderer *
new_aa_renderer (DDisplay *ddisp)
{
GType renderer_type;
renderer_type = g_type_from_name ("DiaCairoInteractiveRenderer");
if (renderer_type) {
DiaRenderer *renderer = g_object_new(renderer_type, NULL);
g_object_set (renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
return renderer;
}
renderer_type = g_type_from_name ("DiaLibartRenderer");
if (renderer_type) {
DiaRenderer *renderer = g_object_new(renderer_type, NULL);
g_object_set (renderer,
"transform", dia_transform_new (&ddisp->visible, &ddisp->zoom_factor),
NULL);
return renderer;
}
/* we really should not come here but instead disable the menu command earlier */
message_warning (_("No antialiased renderer found"));
/* fallback: built-in libart renderer */
return dia_cairo_interactive_renderer_new ();
}
void
ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer)
{
......@@ -1149,15 +1111,14 @@ ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer)
width = ddisp->canvas->allocation.width;
height = ddisp->canvas->allocation.height;
if (ddisp->aa_renderer){
ddisp->renderer = new_aa_renderer (ddisp);
} else {
ddisp->renderer = dia_cairo_interactive_renderer_new();
g_object_set (ddisp->renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
if (!ddisp->aa_renderer){
g_message ("Only antialias renderers supported");
}
ddisp->renderer = dia_cairo_interactive_renderer_new ();
g_object_set (ddisp->renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
if (window)
dia_renderer_set_size(ddisp->renderer, window, width, height);
......@@ -1168,15 +1129,14 @@ ddisplay_resize_canvas(DDisplay *ddisp,
int width, int height)
{
if (ddisp->renderer==NULL) {
if (ddisp->aa_renderer) {
ddisp->renderer = new_aa_renderer (ddisp);
} else {
ddisp->renderer = dia_cairo_interactive_renderer_new();
g_object_set (ddisp->renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
if (!ddisp->aa_renderer){
g_message ("Only antialias renderers supported");
}
ddisp->renderer = dia_cairo_interactive_renderer_new ();
g_object_set (ddisp->renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
}
dia_renderer_set_size(ddisp->renderer, gtk_widget_get_window(ddisp->canvas), width, height);
......@@ -1343,7 +1303,7 @@ display_update_menu_state(DDisplay *ddisp)
antialiased = GTK_TOGGLE_ACTION (menus_get_action ("ViewAntialiased"));
gtk_action_set_sensitive (menus_get_action ("ViewAntialiased"),
g_type_from_name ("DiaCairoInteractiveRenderer") != 0 || g_type_from_name ("DiaLibartRenderer") != 0);
g_type_from_name ("DiaCairoInteractiveRenderer") != 0);
ddisplay_do_update_menu_sensitivity (ddisp);
......
......@@ -16,10 +16,6 @@
/* NOT: #define LOCALEDIR "../lib/locale" */
/* some non critical defines */
#if 0
#define HAVE_LIBART
#define HAVE_LIBPNG
#endif
#define HAVE_LIBZ
#define VERSION "0.97+git"
......
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* dialibart.c -- libart based export plugin for dia
* moved out of the core 2008, Hans Breuer, <Hans@Breuer.Org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <stdio.h>
#include "intl.h"
#include "filter.h"
#include "plug-ins.h"
#include "dialibartrenderer.h"
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
extern DiaExportFilter png_export_filter;
#endif
static gboolean
_plugin_can_unload (PluginInfo *info)
{
/* Can't unlaod as long as we are giving away our types, e.g. dia_libart_renderer_get_type () */
return FALSE;
}
static void
_plugin_unload (PluginInfo *info)
{
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
filter_unregister_export(&png_export_filter);
#endif
}
/* --- dia plug-in interface --- */
DIA_PLUGIN_CHECK_INIT
PluginInitResult
dia_plugin_init(PluginInfo *info)
{
if (!dia_plugin_info_init(info, "Libart",
_("Libart-based rendering"),
_plugin_can_unload,
_plugin_unload))
return DIA_PLUGIN_INIT_ERROR;
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
/* FIXME: need to think about of proper way of registartion, see also app/display.c */
png_export_filter.renderer_type = dia_libart_renderer_get_type ();
/* PNG with libart rendering */
filter_register_export(&png_export_filter);
#endif
return DIA_PLUGIN_INIT_OK;
}
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <math.h>
#include <string.h> /* strlen */
#include "dialibartrenderer.h"
#include "color.h"
#include "font.h"
#include "intl.h"
#include "dia_image.h"
#include "object.h"
#include "textline.h"
#ifdef HAVE_LIBART
#ifdef HAVE_FREETYPE
#include <pango/pango.h>
#undef PANGO_DISABLE_DEPRECATED /* pango_ft2_get_context */
#include <pango/pangoft2.h>
#elif defined G_OS_WIN32
/* ugly namespace clashes */
#define Rectangle Win32Rectangle
#include <pango/pango.h>
#undef Rectangle
#else
#include <pango/pango.h>
#include <gdk/gdk.h>
#endif
#include <libart_lgpl/art_point.h>
#include <libart_lgpl/art_misc.h>
#include <libart_lgpl/art_affine.h>
#include <libart_lgpl/art_svp_vpath.h>
#include <libart_lgpl/art_bpath.h>
#include <libart_lgpl/art_vpath_bpath.h>
#include <libart_lgpl/art_rgb.h>
#include <libart_lgpl/art_rgb_svp.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_rgb_rgba_affine.h>
#include <libart_lgpl/art_rgb_bitmap_affine.h>
#include <libart_lgpl/art_filterlevel.h>
#include <libart_lgpl/art_svp_intersect.h>
static inline guint32
color_to_rgba(DiaLibartRenderer *renderer, Color *col)
{
int rgba;
if (renderer->highlight_color != NULL) {
rgba = (guint)(0xFF*renderer->highlight_color->alpha);
rgba |= (guint)(0xFF*renderer->highlight_color->red) << 24;
rgba |= (guint)(0xFF*renderer->highlight_color->green) << 16;
rgba |= (guint)(0xFF*renderer->highlight_color->blue) << 8;
} else {
rgba = (guint)(0xFF*col->alpha);
rgba |= (guint)(0xFF*col->red) << 24;
rgba |= (guint)(0xFF*col->green) << 16;
rgba |= (guint)(0xFF*col->blue) << 8;
}
return rgba;
}
static int
get_width_pixels (DiaRenderer *self)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
return renderer->pixel_width;
}
static int
get_height_pixels (DiaRenderer *self)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
return renderer->pixel_height;
}
static void
begin_render(DiaRenderer *self, const Rectangle *update)
{
#ifdef HAVE_FREETYPE
/* pango_ft2_get_context API docs :
* ... Use of this function is discouraged, ...
*
* I've tried using the proper font_map stuff, but it kills font size:(
*/
dia_font_push_context(pango_ft2_get_context(75, 75));
# define FONT_SCALE (1.0)
#elif defined G_OS_WIN32
dia_font_push_context(gdk_pango_context_get());
/* I shall never claim again to have understood Dias/Pangos font size
* relations ;). This was (1.0/22.0) but nowadays 1.0 seems to be
* fine with Pango/win32, too. --hb
*/
# define FONT_SCALE (1.0)
#else
dia_font_push_context (gdk_pango_context_get ());
# define FONT_SCALE (0.8)
#endif
}
static void
end_render(DiaRenderer *self)
{
dia_font_pop_context();
}
static gboolean
is_capable_to (DiaRenderer *renderer, RenderCapability cap)
{
if (RENDER_HOLES == cap)
return TRUE;
else if (RENDER_ALPHA == cap)
return TRUE;
return FALSE;
}
static void
set_linewidth(DiaRenderer *self, real linewidth)
{ /* 0 == hairline **/
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
if (renderer->highlight_color != NULL) {
/* 6 pixels wide -> 3 pixels beyond normal obj */
real border = dia_untransform_length(renderer->transform, 6);
linewidth += border;
}
renderer->line_width =
dia_transform_length(renderer->transform, linewidth);
if (renderer->line_width<=0.5)
renderer->line_width = 0.5; /* Minimum 0.5 pixel. */
}
static void
set_linecaps(DiaRenderer *self, LineCaps mode)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
if (renderer->highlight_color != NULL) {
/* Can't tell that this does anything:( -LC */
renderer->cap_style = ART_PATH_STROKE_CAP_ROUND;
} else {
switch(mode) {
case LINECAPS_DEFAULT:
case LINECAPS_BUTT:
renderer->cap_style = ART_PATH_STROKE_CAP_BUTT;
break;
case LINECAPS_ROUND:
renderer->cap_style = ART_PATH_STROKE_CAP_ROUND;
break;
case LINECAPS_PROJECTING:
renderer->cap_style = ART_PATH_STROKE_CAP_SQUARE;
break;
}
}
}
static void
set_linejoin(DiaRenderer *self, LineJoin mode)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
if (renderer->highlight_color != NULL) {
/* Can't tell that this does anything:( -LC */
renderer->join_style = ART_PATH_STROKE_JOIN_ROUND;
} else {
switch(mode) {
case LINEJOIN_DEFAULT:
case LINEJOIN_MITER:
renderer->join_style = ART_PATH_STROKE_JOIN_MITER;
break;
case LINEJOIN_ROUND:
renderer->join_style = ART_PATH_STROKE_JOIN_ROUND;
break;
case LINEJOIN_BEVEL:
renderer->join_style = ART_PATH_STROKE_JOIN_BEVEL;
break;
}
}
}
static void
set_linestyle(DiaRenderer *self, LineStyle mode, real length)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
static double dash[10];
double hole_width;
real dash_length;
real dot_length;
real ddisp_len;
ddisp_len =
dia_transform_length(renderer->transform, length);
dash_length = ddisp_len;
dot_length = ddisp_len*0.1;
if (dash_length<1.0)
dash_length = 1.0;
if (dash_length>255.0)
dash_length = 255.0;
if (dot_length<1.0)
dot_length = 1.0;
if (dot_length>255.0)
dot_length = 255.0;
switch(mode) {
case LINESTYLE_DEFAULT:
case LINESTYLE_SOLID:
renderer->dash_enabled = 0;
break;
case LINESTYLE_DASHED:
renderer->dash_enabled = 1;
renderer->dash.offset = 0.0;
renderer->dash.n_dash = 2;
renderer->dash.dash = dash;
dash[0] = dash_length;
dash[1] = dash_length;
break;
case LINESTYLE_DASH_DOT:
renderer->dash_enabled = 1;
renderer->dash.offset = 0.0;
renderer->dash.n_dash = 4;
renderer->dash.dash = dash;
hole_width = (dash_length - dot_length) / 2.0;
if (hole_width<1.0)
hole_width = 1.0;
dash[0] = dash_length;
dash[1] = hole_width;
dash[2] = dot_length;
dash[3] = hole_width;
break;
case LINESTYLE_DASH_DOT_DOT:
renderer->dash_enabled = 1;
renderer->dash.offset = 0.0;
renderer->dash.n_dash = 6;
renderer->dash.dash = dash;
hole_width = (dash_length - 2*dot_length) / 3;
if (hole_width<1.0)
hole_width = 1.0;
dash[0] = dash_length;
dash[1] = hole_width;
dash[2] = dot_length;
dash[3] = hole_width;
dash[4] = dot_length;
dash[5] = hole_width;
break;
case LINESTYLE_DOTTED:
renderer->dash_enabled = 1;
renderer->dash.offset = 0.0;
renderer->dash.n_dash = 2;
renderer->dash.dash = dash;
dash[0] = dot_length;
dash[1] = dot_length;
break;
}
}
static void
set_fillstyle(DiaRenderer *self, FillStyle mode)
{
switch(mode) {
case FILLSTYLE_SOLID:
break;
default:
g_warning ("%s: Unsupported fill mode specified!",
G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (self)));
}
}
static void
set_font(DiaRenderer *self, DiaFont *font, real height)
{
self->font_height = height * FONT_SCALE;
dia_font_ref(font);
if (self->font)
dia_font_unref(self->font);
self->font = font;
}
static void
draw_line(DiaRenderer *self,
Point *start, Point *end,
Color *line_color)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
ArtVpath *vpath, *vpath_dashed;
ArtSVP *svp;
guint32 rgba;
double x,y;
rgba = color_to_rgba(renderer, line_color);
vpath = art_new (ArtVpath, 3);
dia_transform_coords_double(renderer->transform, start->x, start->y, &x, &y);
vpath[0].code = ART_MOVETO;
vpath[0].x = x;
vpath[0].y = y;
dia_transform_coords_double(renderer->transform, end->x, end->y, &x, &y);
vpath[1].code = ART_LINETO;
vpath[1].x = x;
vpath[1].y = y;
vpath[2].code = ART_END;
vpath[2].x = 0;
vpath[2].y = 0;
if (renderer->dash_enabled) {
vpath_dashed = art_vpath_dash(vpath, &renderer->dash);
art_free( vpath );
vpath = vpath_dashed;
}
svp = art_svp_vpath_stroke (vpath,
renderer->join_style,
renderer->cap_style,
renderer->line_width,
4,
0.25);
art_free( vpath );
art_rgb_svp_alpha (svp,
0, 0,
renderer->pixel_width,
renderer->pixel_height,
rgba,
renderer->rgb_buffer, renderer->pixel_width*3,
NULL);
art_svp_free( svp );
}
static void
draw_polyline(DiaRenderer *self,
Point *points, int num_points,
Color *line_color)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
ArtVpath *vpath, *vpath_dashed;
ArtSVP *svp;
guint32 rgba;
double x,y;
int i;
rgba = color_to_rgba(renderer, line_color);
vpath = art_new (ArtVpath, num_points+1);
for (i=0;i<num_points;i++) {
dia_transform_coords_double(renderer->transform,
points[i].x, points[i].y,
&x, &y);
vpath[i].code = (i==0)?ART_MOVETO:ART_LINETO;
vpath[i].x = x;
vpath[i].y = y;
}
vpath[i].code = ART_END;
vpath[i].x = 0;
vpath[i].y = 0;
if (renderer->dash_enabled) {
vpath_dashed = art_vpath_dash(vpath, &renderer->dash);
art_free( vpath );
vpath = vpath_dashed;
}
svp = art_svp_vpath_stroke (vpath,
renderer->join_style,
renderer->cap_style,
renderer->line_width,
4,
0.25);
art_free( vpath );
art_rgb_svp_alpha (svp,
0, 0,
renderer->pixel_width,
renderer->pixel_height,
rgba,
renderer->rgb_buffer, renderer->pixel_width*3,
NULL);
art_svp_free( svp );
}
static void
stroke_polygon (DiaRenderer *self,
Point *points, int num_points,
Color *line_color)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
ArtVpath *vpath, *vpath_dashed;
ArtSVP *svp;
guint32 rgba;
double x,y;
int i;
rgba = color_to_rgba(renderer, line_color);
vpath = art_new (ArtVpath, num_points+2);
for (i=0;i<num_points;i++) {
dia_transform_coords_double(renderer->transform,
points[i].x, points[i].y,
&x, &y);
vpath[i].code = (i==0)?ART_MOVETO:ART_LINETO;
vpath[i].x = x;
vpath[i].y = y;
}
dia_transform_coords_double(renderer->transform,
points[0].x, points[0].y,
&x, &y);
vpath[i].code = ART_LINETO;
vpath[i].x = x;
vpath[i].y = y;
vpath[i+1].code = ART_END;
vpath[i+1].x = 0;
vpath[i+1].y = 0;
if (renderer->dash_enabled) {
vpath_dashed = art_vpath_dash(vpath, &renderer->dash);
art_free( vpath );
vpath = vpath_dashed;
}
svp = art_svp_vpath_stroke (vpath,
renderer->join_style,
renderer->cap_style,
renderer->line_width,
4,
0.25);
art_free( vpath );
art_rgb_svp_alpha (svp,
0, 0,
renderer->pixel_width,
renderer->pixel_height,
rgba,
renderer->rgb_buffer, renderer->pixel_width*3,
NULL);
art_svp_free( svp );
}
static void
fill_polygon (DiaRenderer *self,
Point *points, int num_points,
Color *color)
{
DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self);
ArtVpath *vpath;
ArtSVP *svp, *temp;
guint32 rgba;
double x,y;
int i;
ArtSvpWriter *swr;
rgba = color_to_rgba(renderer, color);
vpath = art_new (ArtVpath, num_points+2);
for (i=0;i<num_points;i++) {
dia_transform_coords_double(renderer->transform,
points[i].x, points[i].y,
&x, &y);
vpath[i].code = (i==0)?ART_MOVETO:ART_LINETO;
vpath[i].x = x;
vpath[i].y = y;
}
dia_transform_coords_double(renderer->transform,
points[0].x, points[0].y,