diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-10-03 20:51:05 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-10-03 20:51:05 +0000 |
| commit | 4db35e8a6706ddece9e977e5f26d4a6867ff8cbe (patch) | |
| tree | f9711f260f694d96e26bf3216fb64f2b38611b2b /src/display | |
| parent | update to trunk (diff) | |
| parent | Merge in jabiertxof's hover information for measure tool (diff) | |
| download | inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.tar.gz inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.zip | |
Update to trunk
(bzr r15017.1.35)
Diffstat (limited to 'src/display')
| -rw-r--r-- | src/display/Makefile_insert | 125 | ||||
| -rw-r--r-- | src/display/cairo-utils.cpp | 86 | ||||
| -rw-r--r-- | src/display/cairo-utils.h | 2 | ||||
| -rw-r--r-- | src/display/canvas-axonomgrid.cpp | 40 | ||||
| -rw-r--r-- | src/display/canvas-bpath.cpp | 34 | ||||
| -rw-r--r-- | src/display/canvas-bpath.h | 6 | ||||
| -rw-r--r-- | src/display/canvas-grid.cpp | 40 | ||||
| -rw-r--r-- | src/display/canvas-text.cpp | 2 | ||||
| -rw-r--r-- | src/display/drawing-text.cpp | 2 | ||||
| -rw-r--r-- | src/display/guideline.cpp | 2 | ||||
| -rw-r--r-- | src/display/nr-svgfonts.cpp | 75 | ||||
| -rw-r--r-- | src/display/nr-svgfonts.h | 3 | ||||
| -rw-r--r-- | src/display/sp-canvas.cpp | 100 | ||||
| -rw-r--r-- | src/display/sp-canvas.h | 7 | ||||
| -rw-r--r-- | src/display/sp-ctrlline.cpp | 2 |
15 files changed, 187 insertions, 339 deletions
diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert deleted file mode 100644 index 419852f7d..000000000 --- a/src/display/Makefile_insert +++ /dev/null @@ -1,125 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -display/canvas-arena.$(OBJEXT): helper/sp-marshal.h -display/sp-canvas.$(OBJEXT): helper/sp-marshal.h - -ink_common_sources += \ - display/cairo-templates.h \ - display/cairo-utils.cpp \ - display/cairo-utils.h \ - display/canvas-arena.cpp \ - display/canvas-arena.h \ - display/canvas-axonomgrid.cpp \ - display/canvas-axonomgrid.h \ - display/canvas-bpath.cpp \ - display/canvas-bpath.h \ - display/canvas-grid.cpp \ - display/canvas-grid.h \ - display/canvas-temporary-item.cpp \ - display/canvas-temporary-item.h \ - display/canvas-temporary-item-list.cpp \ - display/canvas-temporary-item-list.h \ - display/canvas-text.cpp \ - display/canvas-text.h \ - display/curve.cpp \ - display/curve.h \ - display/drawing.cpp \ - display/drawing.h \ - display/drawing-context.cpp \ - display/drawing-context.h \ - display/drawing-group.cpp \ - display/drawing-group.h \ - display/drawing-image.cpp \ - display/drawing-image.h \ - display/drawing-item.cpp \ - display/drawing-item.h \ - display/drawing-pattern.cpp \ - display/drawing-pattern.h \ - display/drawing-shape.cpp \ - display/drawing-shape.h \ - display/drawing-surface.cpp \ - display/drawing-surface.h \ - display/drawing-text.cpp \ - display/drawing-text.h \ - display/gnome-canvas-acetate.cpp \ - display/gnome-canvas-acetate.h \ - display/grayscale.cpp \ - display/grayscale.h \ - display/guideline.cpp \ - display/guideline.h \ - display/nr-3dutils.cpp \ - display/nr-3dutils.h \ - display/nr-filter-blend.cpp \ - display/nr-filter-blend.h \ - display/nr-filter-colormatrix.cpp \ - display/nr-filter-colormatrix.h \ - display/nr-filter-component-transfer.cpp \ - display/nr-filter-component-transfer.h \ - display/nr-filter-composite.cpp \ - display/nr-filter-composite.h \ - display/nr-filter-convolve-matrix.cpp \ - display/nr-filter-convolve-matrix.h \ - display/nr-filter.cpp \ - display/nr-filter-diffuselighting.cpp \ - display/nr-filter-diffuselighting.h \ - display/nr-filter-displacement-map.cpp \ - display/nr-filter-displacement-map.h \ - display/nr-filter-flood.cpp \ - display/nr-filter-flood.h \ - display/nr-filter-gaussian.cpp \ - display/nr-filter-gaussian.h \ - display/nr-filter.h \ - display/nr-filter-image.cpp \ - display/nr-filter-image.h \ - display/nr-filter-merge.cpp \ - display/nr-filter-merge.h \ - display/nr-filter-morphology.cpp \ - display/nr-filter-morphology.h \ - display/nr-filter-offset.cpp \ - display/nr-filter-offset.h \ - display/nr-filter-primitive.cpp \ - display/nr-filter-primitive.h \ - display/nr-filter-slot.cpp \ - display/nr-filter-slot.h \ - display/nr-filter-specularlighting.cpp \ - display/nr-filter-specularlighting.h \ - display/nr-filter-tile.cpp \ - display/nr-filter-tile.h \ - display/nr-filter-turbulence.cpp \ - display/nr-filter-turbulence.h \ - display/nr-filter-types.h \ - display/nr-filter-units.cpp \ - display/nr-filter-units.h \ - display/nr-filter-utils.h \ - display/nr-light.cpp \ - display/nr-light.h \ - display/nr-light-types.h \ - display/nr-style.cpp \ - display/nr-style.h \ - display/nr-svgfonts.cpp \ - display/nr-svgfonts.h \ - display/rendermode.h \ - display/snap-indicator.cpp \ - display/snap-indicator.h \ - display/sodipodi-ctrl.cpp \ - display/sodipodi-ctrl.h \ - display/sodipodi-ctrlrect.cpp \ - display/sodipodi-ctrlrect.h \ - display/sp-canvas.cpp \ - display/sp-canvas.h \ - display/sp-canvas-item.h \ - display/sp-canvas-group.h \ - display/sp-canvas-util.cpp \ - display/sp-canvas-util.h \ - display/sp-ctrlcurve.cpp \ - display/sp-ctrlcurve.h \ - display/sp-ctrlline.cpp \ - display/sp-ctrlline.h \ - display/sp-ctrlquadr.cpp \ - display/sp-ctrlquadr.h - -# ###################### -# ### CxxTest stuff #### -# ###################### -CXXTEST_TESTSUITES += \ - $(srcdir)/display/curve-test.h diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 24a75de4c..a7625f4a1 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -13,6 +13,7 @@ #endif #include "display/cairo-utils.h" +#include <arpa/inet.h> #include <stdexcept> #include <glib/gstdio.h> @@ -1321,6 +1322,91 @@ guint32 argb32_from_rgba(guint32 in) return px; } + +/** + * Converts a pixbuf to a PNG data structure. + * For 8-but RGBA png, this is like copying. + * + */ +const guchar* pixbuf_to_png(guchar const**rows, guchar* px, int num_rows, int num_cols, int stride, int color_type, int bit_depth) +{ + int n_fields = 1 + (color_type&2) + (color_type&4)/4; + const guchar* new_data = (const guchar*)malloc((n_fields * bit_depth * num_rows * num_cols)/8 + 64); + char* ptr = (char*) new_data; + int pad=0; //used when we write image data smaller than one byte (for instance in black and white images where 1px = 1bit) + for(int row = 0; row < num_rows; ++row){ + rows[row] = (const guchar*)ptr; + for(int col = 0; col < num_cols; ++col){ + guint32 *pixel = reinterpret_cast<guint32*>(px + row*stride)+col; +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + //this part should probably be rewritten as (a tested, working) big endian, using htons() and ntohs() + guint64 a = (*pixel & 0xff000000) >> 24; + guint64 b = (*pixel & 0x00ff0000) >> 16; + guint64 g = (*pixel & 0x0000ff00) >> 8; + guint64 r = (*pixel & 0x000000ff); + + //one of possible rgb to greyscale formulas. This one is called "luminance, "luminosity" or "luma" + guint16 gray = (guint16)((guint32)((0.2126*(r<<24) + 0.7152*(g<<24) + 0.0722*(b<<24)))>>16); + + if (!pad) *((guint64*)ptr)=0; + if (color_type & 2) { //RGB + // for 8bit->16bit transition, I take the FF -> FFFF convention (multiplication by 0x101). + // If you prefer FF -> FF00 (multiplication by 0x100), remove the <<8, <<24, <<40 and <<56 + if (color_type & 4) { //RGBA + if (bit_depth==8) + *((guint32*)ptr) = *pixel; + else + *((guint64*)ptr) = (guint64)((a<<56)+(a<<48)+(b<<40)+(b<<32)+(g<<24)+(g<<16)+(r<<8)+(r)); + } + else{ //no alpha + if(bit_depth==8) + *((guint32*)ptr) = ((*pixel)<<8)>>8; + else + *((guint64*)ptr) = (guint64)((b<<40)+(b<<32)+(g<<24)+(g<<16)+(r<<8)+r); + } + } else { //Grayscale + if(bit_depth==16) + *(guint16*)ptr= ((gray & 0xff00)>>8) + ((gray &0x00ff)<<8); + else *((guint16*)ptr) += guint16(((gray >> (16-bit_depth))<<pad) ); //note the "+=" + + if(color_type & 4) { //Alpha channel + if (bit_depth == 16) + *((guint32*)(ptr+2)) = a + (a<<8); + else + *((guint32*)(ptr)) += guint32((a << 8) >> (16 - bit_depth))<<(bit_depth + pad); + } + } + +#else + // I don't have any access to a big-endian machine to test this. It should still work with default export settings. + guint64 r = (*pixel & 0xff000000) >> 24; + guint64 g = (*pixel & 0x00ff0000) >> 16; + guint64 b = (*pixel & 0x0000ff00) >> 8; + guint64 a = (*pixel & 0x000000ff); + guint32 gray = (guint32)(0.2126*(r<<24) + 0.7152*(g<<24) + 0.0722*(b<<24)); + if(color_type & 2){ + if(bit_depth==8)*ptr = *pixel; else *ptr = (guint64)((r<<56)+(g<<40)+(b<<24)+(a<<8)); + } else { + *((guint32*)ptr) += guint32(gray>>pad); + if(color_type & 4) *((guint32*)ptr) += guint32((a>>pad)>> bit_depth); + } +#endif + pad+=bit_depth*n_fields; + ptr+=(pad/8); + pad%=8; + } + if(pad){pad=0;ptr++;}//align bytes on rows + } + return new_data; +} + + + + + + + + /* Local Variables: mode:c++ diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h index 2a7e460e8..72087471d 100644 --- a/src/display/cairo-utils.h +++ b/src/display/cairo-utils.h @@ -178,6 +178,8 @@ void convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int rs); G_GNUC_CONST guint32 argb32_from_pixbuf(guint32 in); G_GNUC_CONST guint32 pixbuf_from_argb32(guint32 in); +const guchar* pixbuf_to_png(guchar const**rows, guchar* px, int nrows, int ncols, int stride, int color_type, int bit_depth); + /** Convert a pixel in 0xRRGGBBAA format to Cairo ARGB32 format. */ G_GNUC_CONST guint32 argb32_from_rgba(guint32 in); diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 14f36376f..421a39fbd 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -19,12 +19,7 @@ #include <gtkmm/box.h> #include <gtkmm/label.h> - -#if WITH_GTKMM_3_0 -# include <gtkmm/grid.h> -#else -# include <gtkmm/table.h> -#endif +#include <gtkmm/grid.h> #include <glibmm/i18n.h> @@ -94,15 +89,10 @@ namespace Inkscape { #define SPACE_SIZE_X 15 #define SPACE_SIZE_Y 10 static inline void -#if WITH_GTKMM_3_0 attach_all(Gtk::Grid &table, Gtk::Widget const *const arr[], unsigned size, int start = 0) -#else -attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int start = 0) -#endif { for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2) { if (arr[i] && arr[i+1]) { -#if WITH_GTKMM_3_0 (const_cast<Gtk::Widget&>(*arr[i])).set_hexpand(); (const_cast<Gtk::Widget&>(*arr[i])).set_valign(Gtk::ALIGN_CENTER); table.attach(const_cast<Gtk::Widget&>(*arr[i]), 1, r, 1, 1); @@ -110,44 +100,23 @@ attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand(); (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER); table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 2, r, 1, 1); -#else - table.attach (const_cast<Gtk::Widget&>(*arr[i]), 1, 2, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); -#endif } else { if (arr[i+1]) { -#if WITH_GTKMM_3_0 (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand(); (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER); table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 1, r, 2, 1); -#else - table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); -#endif } else if (arr[i]) { Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i])); label.set_alignment (0.0); -#if WITH_GTKMM_3_0 label.set_hexpand(); label.set_valign(Gtk::ALIGN_CENTER); table.attach(label, 0, r, 3, 1); -#else - table.attach (label, 0, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); -#endif } else { Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); -#if WITH_GTKMM_3_0 space->set_halign(Gtk::ALIGN_CENTER); space->set_valign(Gtk::ALIGN_CENTER); table.attach(*space, 0, r, 1, 1); -#else - table.attach (*space, 0, 1, r, r+1, - (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0); -#endif } } ++r; @@ -342,14 +311,9 @@ CanvasAxonomGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const * Gtk::Widget * CanvasAxonomGrid::newSpecificWidget() { -#if WITH_GTKMM_3_0 - Gtk::Grid *table = Gtk::manage(new Gtk::Grid()); + auto table = Gtk::manage(new Gtk::Grid()); table->set_row_spacing(2); table->set_column_spacing(2); -#else - Gtk::Table * table = Gtk::manage( new Gtk::Table(1,1) ); - table->set_spacings(2); -#endif _wr.setUpdating (true); diff --git a/src/display/canvas-bpath.cpp b/src/display/canvas-bpath.cpp index 46b59d25a..fc6b79b43 100644 --- a/src/display/canvas-bpath.cpp +++ b/src/display/canvas-bpath.cpp @@ -53,6 +53,7 @@ sp_canvas_bpath_init (SPCanvasBPath * bpath) bpath->stroke_linejoin = SP_STROKE_LINEJOIN_MITER; bpath->stroke_linecap = SP_STROKE_LINECAP_BUTT; bpath->stroke_miterlimit = 11.0; + bpath->phantom_line = false; } static void sp_canvas_bpath_destroy(SPCanvasItem *object) @@ -71,7 +72,7 @@ static void sp_canvas_bpath_update(SPCanvasItem *item, Geom::Affine const &affin { SPCanvasBPath *cbp = SP_CANVAS_BPATH(item); - item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); + item->canvas->requestRedraw((int)item->x1 - 1, (int)item->y1 - 1, (int)item->x2 + 1 , (int)item->y2 + 1); if (reinterpret_cast<SPCanvasItemClass *>(sp_canvas_bpath_parent_class)->update) { reinterpret_cast<SPCanvasItemClass *>(sp_canvas_bpath_parent_class)->update(item, affine, flags); @@ -86,10 +87,10 @@ static void sp_canvas_bpath_update(SPCanvasItem *item, Geom::Affine const &affin Geom::OptRect bbox = bounds_exact_transformed(cbp->curve->get_pathvector(), affine); if (bbox) { - item->x1 = (int)bbox->min()[Geom::X] - 1; - item->y1 = (int)bbox->min()[Geom::Y] - 1; - item->x2 = (int)bbox->max()[Geom::X] + 1; - item->y2 = (int)bbox->max()[Geom::Y] + 1; + item->x1 = (int)floor(bbox->min()[Geom::X]) - 1; + item->y1 = (int)floor(bbox->min()[Geom::Y]) - 1; + item->x2 = (int)ceil(bbox->max()[Geom::X]) + 1; + item->y2 = (int)ceil(bbox->max()[Geom::Y]) + 1; } else { item->x1 = 0; item->y1 = 0; @@ -131,7 +132,21 @@ sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf) cairo_fill_preserve(buf->ct); } - if (dostroke) { + if (dostroke && cbp->phantom_line) { + ink_cairo_set_source_rgba32(buf->ct, 0xffffff4d); + cairo_set_line_width(buf->ct, 2); + if (cbp->dashes[0] != 0 && cbp->dashes[1] != 0) { + cairo_set_dash (buf->ct, cbp->dashes, 2, 0); + } + cairo_stroke(buf->ct); + cairo_set_tolerance(buf->ct, 0.5); + cairo_new_path(buf->ct); + feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), cbp->affine, area, + /* optimized_stroke = */ !dofill, 1); + ink_cairo_set_source_rgba32(buf->ct, cbp->stroke_rgba); + cairo_set_line_width(buf->ct, 1); + cairo_stroke(buf->ct); + } else if (dostroke) { ink_cairo_set_source_rgba32(buf->ct, cbp->stroke_rgba); cairo_set_line_width(buf->ct, 1); if (cbp->dashes[0] != 0 && cbp->dashes[1] != 0) { @@ -167,24 +182,25 @@ sp_canvas_bpath_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_ } SPCanvasItem * -sp_canvas_bpath_new (SPCanvasGroup *parent, SPCurve *curve) +sp_canvas_bpath_new (SPCanvasGroup *parent, SPCurve *curve, bool phantom_line) { g_return_val_if_fail (parent != NULL, NULL); g_return_val_if_fail (SP_IS_CANVAS_GROUP (parent), NULL); SPCanvasItem *item = sp_canvas_item_new (parent, SP_TYPE_CANVAS_BPATH, NULL); - sp_canvas_bpath_set_bpath (SP_CANVAS_BPATH (item), curve); + sp_canvas_bpath_set_bpath (SP_CANVAS_BPATH (item), curve, phantom_line); return item; } void -sp_canvas_bpath_set_bpath (SPCanvasBPath *cbp, SPCurve *curve) +sp_canvas_bpath_set_bpath (SPCanvasBPath *cbp, SPCurve *curve, bool phantom_line) { g_return_if_fail (cbp != NULL); g_return_if_fail (SP_IS_CANVAS_BPATH (cbp)); + cbp->phantom_line = phantom_line; if (cbp->curve) { cbp->curve = cbp->curve->unref(); } diff --git a/src/display/canvas-bpath.h b/src/display/canvas-bpath.h index 72eca6eeb..686eb7c5a 100644 --- a/src/display/canvas-bpath.h +++ b/src/display/canvas-bpath.h @@ -80,7 +80,7 @@ struct SPCanvasBPath { SPStrokeJoinType stroke_linejoin; SPStrokeCapType stroke_linecap; gdouble stroke_miterlimit; - + bool phantom_line; /* State */ Shape *fill_shp; Shape *stroke_shp; @@ -92,9 +92,9 @@ struct SPCanvasBPathClass { GType sp_canvas_bpath_get_type (void); -SPCanvasItem *sp_canvas_bpath_new (SPCanvasGroup *parent, SPCurve *curve); +SPCanvasItem *sp_canvas_bpath_new (SPCanvasGroup *parent, SPCurve *curve, bool phantom_line = false); -void sp_canvas_bpath_set_bpath (SPCanvasBPath *cbp, SPCurve *curve); +void sp_canvas_bpath_set_bpath (SPCanvasBPath *cbp, SPCurve *curve, bool phantom_line = false); void sp_canvas_bpath_set_fill (SPCanvasBPath *cbp, guint32 rgba, SPWindRule rule); void sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width, SPStrokeJoinType join, SPStrokeCapType cap, double dash=0, double gap=0); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index decf93626..fa45fe02c 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -19,12 +19,7 @@ #include <gtkmm/box.h> #include <gtkmm/label.h> - -#if WITH_GTKMM_3_0 -# include <gtkmm/grid.h> -#else -# include <gtkmm/table.h> -#endif +#include <gtkmm/grid.h> #include <glibmm/i18n.h> @@ -400,15 +395,10 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px) **/ #define SPACE_SIZE_X 15 #define SPACE_SIZE_Y 10 -#if WITH_GTKMM_3_0 static inline void attach_all(Gtk::Grid &table, Gtk::Widget const *const arr[], unsigned size, int start = 0) -#else -static inline void attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int start = 0) -#endif { for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2) { if (arr[i] && arr[i+1]) { -#if WITH_GTKMM_3_0 (const_cast<Gtk::Widget&>(*arr[i])).set_hexpand(); (const_cast<Gtk::Widget&>(*arr[i])).set_valign(Gtk::ALIGN_CENTER); table.attach(const_cast<Gtk::Widget&>(*arr[i]), 1, r, 1, 1); @@ -416,44 +406,23 @@ static inline void attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand(); (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER); table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 2, r, 1, 1); -#else - table.attach (const_cast<Gtk::Widget&>(*arr[i]), 1, 2, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); -#endif } else { if (arr[i+1]) { -#if WITH_GTKMM_3_0 (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand(); (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER); table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 1, r, 2, 1); -#else - table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); -#endif } else if (arr[i]) { Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i])); label.set_alignment (0.0); -#if WITH_GTKMM_3_0 label.set_hexpand(); label.set_valign(Gtk::ALIGN_CENTER); table.attach(label, 0, r, 3, 1); -#else - table.attach (label, 0, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); -#endif } else { Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); -#if WITH_GTKMM_3_0 space->set_halign(Gtk::ALIGN_CENTER); space->set_valign(Gtk::ALIGN_CENTER); table.attach(*space, 0, r, 1, 1); -#else - table.attach (*space, 0, 1, r, r+1, - (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0); -#endif } } ++r; @@ -684,14 +653,9 @@ CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const */*ke Gtk::Widget * CanvasXYGrid::newSpecificWidget() { -#if WITH_GTKMM_3_0 - Gtk::Grid * table = Gtk::manage( new Gtk::Grid() ); + auto table = Gtk::manage( new Gtk::Grid() ); table->set_row_spacing(2); table->set_column_spacing(2); -#else - Gtk::Table * table = Gtk::manage( new Gtk::Table(1,1) ); - table->set_spacings(2); -#endif Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu( _("Grid _units:"), "units", _wr, repr, doc) ); diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 7c019caf5..efef018e6 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -84,6 +84,7 @@ sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf) if (!buf->ct) return; + cairo_select_font_face(buf->ct, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(buf->ct, cl->fontsize); if (cl->background){ @@ -138,6 +139,7 @@ sp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned i cairo_surface_t *tmp_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); cairo_t* tmp_buf = cairo_create(tmp_surface); + cairo_select_font_face(tmp_buf, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(tmp_buf, cl->fontsize); cairo_text_extents_t extents; cairo_text_extents(tmp_buf, cl->text, &extents); diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index f0d83abfd..a0918e9f5 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -269,7 +269,7 @@ void DrawingText::decorateStyle(DrawingContext &dc, double vextent, double xphas int dashes[16]={ 8, 7, 6, 5, 4, 3, 2, 1, - -8, -7, -6, -5 + -8, -7, -6, -5, -4, -3, -2, -1 }; int dots[16]={ diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 126fcf87c..f66b65e1a 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -48,7 +48,7 @@ static void sp_guideline_init(SPGuideLine *gl) gl->locked = false; gl->normal_to_line = Geom::Point(0,1); - gl->angle = 3.14159265358979323846/2; + gl->angle = M_PI_2; gl->point_on_line = Geom::Point(0,0); gl->sensitive = 0; diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index 011f51977..fd092aed8 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -197,21 +197,27 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, bool is_horizontal_text = true; //TODO _utf8 = (char*) utf8; + double font_height = units_per_em(); while(g_utf8_get_char(_utf8)){ len = 0; for (i=0; i < (unsigned long) this->glyphs.size(); i++){ //check whether is there a glyph declared on the SVG document // that matches with the text string in its current position if ( (len = size_of_substring(this->glyphs[i]->unicode.c_str(), _utf8)) ){ - for(SPObject* node = this->font->children;previous_unicode && node;node=node->next){ + for(auto& node: font->children) { + if (!previous_unicode) { + break; + } //apply glyph kerning if appropriate - SPHkern *hkern = dynamic_cast<SPHkern *>(node); - if (hkern && is_horizontal_text && MatchHKerningRule(hkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){ - x -= (hkern->k / 1000.0);//TODO: use here the height of the font + SPHkern *hkern = dynamic_cast<SPHkern *>(&node); + if (hkern && is_horizontal_text && + MatchHKerningRule(hkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){ + x -= (hkern->k / font_height); } - SPVkern *vkern = dynamic_cast<SPVkern *>(node); - if (vkern && !is_horizontal_text && MatchVKerningRule(vkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){ - y -= (vkern->k / 1000.0);//TODO: use here the "height" of the font + SPVkern *vkern = dynamic_cast<SPVkern *>(&node); + if (vkern && !is_horizontal_text && + MatchVKerningRule(vkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){ + y -= (vkern->k / font_height); } } previous_unicode = const_cast<char*>(this->glyphs[i]->unicode.c_str());//used for kerning checking @@ -221,8 +227,15 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, (*glyphs)[count++].y = y; //advance glyph coordinates: - if (is_horizontal_text) x+=(this->font->horiz_adv_x/1000.0);//TODO: use here the height of the font - else y+=(this->font->vert_adv_y/1000.0);//TODO: use here the "height" of the font + if (is_horizontal_text) { + if (this->glyphs[i]->horiz_adv_x != 0) { + x+=(this->glyphs[i]->horiz_adv_x/font_height); + } else { + x+=(this->font->horiz_adv_x/font_height); + } + } else { + y+=(this->font->vert_adv_y/font_height); + } _utf8+=len; //advance 'len' bytes in our string pointer //continue; goto raptorz; @@ -235,8 +248,8 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, (*glyphs)[count++].y = y; //advance glyph coordinates: - if (is_horizontal_text) x+=(this->font->horiz_adv_x/1000.0);//TODO: use here the height of the font - else y+=(this->font->vert_adv_y/1000.0);//TODO: use here the "height" of the font + if (is_horizontal_text) x+=(this->font->horiz_adv_x/font_height);//TODO: use here the height of the font + else y+=(this->font->vert_adv_y/font_height);//TODO: use here the "height" of the font _utf8 = g_utf8_next_char(_utf8); //advance 1 char in our string pointer } @@ -252,9 +265,7 @@ SvgFont::render_glyph_path(cairo_t* cr, Geom::PathVector* pathv){ cairo_new_path(cr); //adjust scale of the glyph -// Geom::Scale s(1.0/((SPFont*) node->parent)->horiz_adv_x); - Geom::Scale s(1.0/1000);//TODO: use here the units-per-em attribute? - + Geom::Scale s(1.0/units_per_em()); Geom::Rect area( Geom::Point(0,0), Geom::Point(1,1) ); //I need help here! (reaction: note that the 'area' parameter is an *optional* rect, so you can pass an empty Geom::OptRect() ) feed_pathvector_to_cairo (cr, *pathv, s, area, false, 0); @@ -270,11 +281,11 @@ SvgFont::glyph_modified(SPObject* /* blah */, unsigned int /* bleh */){ Geom::PathVector SvgFont::flip_coordinate_system(SPFont* spfont, Geom::PathVector pathv){ - double units_per_em = 1000; - for (SPObject *obj = spfont->children; obj; obj = obj->next){ - if (dynamic_cast<SPFontFace *>(obj)) { + double units_per_em = 1024; + for(auto& obj: spfont->children) { + if (dynamic_cast<SPFontFace *>(&obj)) { //XML Tree being directly used here while it shouldn't be. - sp_repr_get_double(obj->getRepr(), "units_per_em", &units_per_em); + sp_repr_get_double(obj.getRepr(), "units_per_em", &units_per_em); } } @@ -339,19 +350,19 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, if (node->hasChildren()){ //render the SVG described on this glyph's child nodes. - for(node = node->children; node; node=node->next){ + for(auto& child: node->children) { { - SPPath *path = dynamic_cast<SPPath *>(node); + SPPath *path = dynamic_cast<SPPath *>(&child); if (path) { pathv = path->_curve->get_pathvector(); pathv = flip_coordinate_system(spfont, pathv); render_glyph_path(cr, &pathv); } } - if (dynamic_cast<SPObjectGroup *>(node)) { + if (dynamic_cast<SPObjectGroup *>(&child)) { g_warning("TODO: svgfonts: render OBJECTGROUP"); } - SPUse *use = dynamic_cast<SPUse *>(node); + SPUse *use = dynamic_cast<SPUse *>(&child); if (use) { SPItem* item = use->ref->getObject(); SPPath *path = dynamic_cast<SPPath *>(item); @@ -374,12 +385,12 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, cairo_font_face_t* SvgFont::get_font_face(){ if (!this->userfont) { - for(SPObject* node = this->font->children;node;node=node->next){ - SPGlyph *glyph = dynamic_cast<SPGlyph *>(node); + for(auto& node: font->children) { + SPGlyph *glyph = dynamic_cast<SPGlyph *>(&node); if (glyph) { glyphs.push_back(glyph); } - SPMissingGlyph *missing = dynamic_cast<SPMissingGlyph *>(node); + SPMissingGlyph *missing = dynamic_cast<SPMissingGlyph *>(&node); if (missing) { missingglyph = missing; } @@ -395,6 +406,20 @@ void SvgFont::refresh(){ this->userfont = NULL; } +double SvgFont::units_per_em() { + double units_per_em = 1024; + for (auto& obj: font->children) { + if (dynamic_cast<SPFontFace *>(&obj)) { + //XML Tree being directly used here while it shouldn't be. + sp_repr_get_double(obj.getRepr(), "units-per-em", &units_per_em); + } + } + if (units_per_em <= 0.0) { + units_per_em = 1024; + } + return units_per_em; +} + /* Local Variables: mode:c++ diff --git a/src/display/nr-svgfonts.h b/src/display/nr-svgfonts.h index 21ab3ed02..d4488fb17 100644 --- a/src/display/nr-svgfonts.h +++ b/src/display/nr-svgfonts.h @@ -52,7 +52,8 @@ private: SPMissingGlyph* missingglyph; sigc::connection glyph_modified_connection; - bool drawing_expose_cb (Gtk::Widget *widget, GdkEventExpose *event, void* data); + double units_per_em(); + //bool drawing_expose_cb (Gtk::Widget *widget, GdkEventExpose *event, void* data); }; #endif //#ifndef NR_SVGFONTS_H_SEEN diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 7d76fa043..9201168ef 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -322,13 +322,9 @@ void sp_canvas_item_dispose(GObject *object) if (item == item->canvas->_grabbed_item) { item->canvas->_grabbed_item = NULL; -#if GTK_CHECK_VERSION(3,0,0) - GdkDeviceManager *dm = gdk_display_get_device_manager(gdk_display_get_default()); - GdkDevice *device = gdk_device_manager_get_client_pointer(dm); + auto dm = gdk_display_get_device_manager(gdk_display_get_default()); + auto device = gdk_device_manager_get_client_pointer(dm); gdk_device_ungrab(device, GDK_CURRENT_TIME); -#else - gdk_pointer_ungrab (GDK_CURRENT_TIME); -#endif } if (item == item->canvas->_focused_item) { @@ -617,9 +613,8 @@ int sp_canvas_item_grab(SPCanvasItem *item, guint event_mask, GdkCursor *cursor, // fixme: Top hack (Lauris) // fixme: If we add key masks to event mask, Gdk will abort (Lauris) // fixme: But Canvas actualle does get key events, so all we need is routing these here -#if GTK_CHECK_VERSION(3,0,0) - GdkDeviceManager *dm = gdk_display_get_device_manager(gdk_display_get_default()); - GdkDevice *device = gdk_device_manager_get_client_pointer(dm); + auto dm = gdk_display_get_device_manager(gdk_display_get_default()); + auto device = gdk_device_manager_get_client_pointer(dm); gdk_device_grab(device, getWindow(item->canvas), GDK_OWNERSHIP_NONE, @@ -627,11 +622,6 @@ int sp_canvas_item_grab(SPCanvasItem *item, guint event_mask, GdkCursor *cursor, (GdkEventMask)(event_mask & (~(GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK))), cursor, etime); -#else - gdk_pointer_grab( getWindow(item->canvas), FALSE, - (GdkEventMask)(event_mask & (~(GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK))), - NULL, cursor, etime); -#endif item->canvas->_grabbed_item = item; item->canvas->_grabbed_event_mask = event_mask; @@ -658,13 +648,9 @@ void sp_canvas_item_ungrab(SPCanvasItem *item, guint32 etime) item->canvas->_grabbed_item = NULL; -#if GTK_CHECK_VERSION(3,0,0) - GdkDeviceManager *dm = gdk_display_get_device_manager(gdk_display_get_default()); - GdkDevice *device = gdk_device_manager_get_client_pointer(dm); + auto dm = gdk_display_get_device_manager(gdk_display_get_default()); + auto device = gdk_device_manager_get_client_pointer(dm); gdk_device_ungrab(device, etime); -#else - gdk_pointer_ungrab (etime); -#endif } /** @@ -913,16 +899,9 @@ void sp_canvas_class_init(SPCanvasClass *klass) widget_class->realize = SPCanvas::handle_realize; widget_class->unrealize = SPCanvas::handle_unrealize; - -#if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = SPCanvas::handle_get_preferred_width; widget_class->get_preferred_height = SPCanvas::handle_get_preferred_height; widget_class->draw = SPCanvas::handle_draw; -#else - widget_class->size_request = SPCanvas::handle_size_request; - widget_class->expose_event = SPCanvas::handle_expose; -#endif - widget_class->size_allocate = SPCanvas::handle_size_allocate; widget_class->button_press_event = SPCanvas::handle_button; widget_class->button_release_event = SPCanvas::handle_button; @@ -980,13 +959,9 @@ void SPCanvas::shutdownTransients() if (_grabbed_item) { _grabbed_item = NULL; -#if GTK_CHECK_VERSION(3,0,0) - GdkDeviceManager *dm = gdk_display_get_device_manager(gdk_display_get_default()); - GdkDevice *device = gdk_device_manager_get_client_pointer(dm); + auto dm = gdk_display_get_device_manager(gdk_display_get_default()); + auto device = gdk_device_manager_get_client_pointer(dm); gdk_device_ungrab(device, GDK_CURRENT_TIME); -#else - gdk_pointer_ungrab(GDK_CURRENT_TIME); -#endif } removeIdle(); } @@ -1053,10 +1028,6 @@ void SPCanvas::handle_realize(GtkWidget *widget) attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gdk_visual_get_system(); -#if !GTK_CHECK_VERSION(3,0,0) - attributes.colormap = gdk_colormap_get_system(); -#endif - attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | @@ -1073,11 +1044,7 @@ void SPCanvas::handle_realize(GtkWidget *widget) GDK_SCROLL_MASK | GDK_FOCUS_CHANGE_MASK); -#if GTK_CHECK_VERSION(3,0,0) gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; -#else - gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; -#endif GdkWindow *window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gtk_widget_set_window (widget, window); @@ -1086,18 +1053,8 @@ void SPCanvas::handle_realize(GtkWidget *widget) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/useextinput/value", true)) { gtk_widget_set_events(widget, attributes.event_mask); -#if !GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_extension_events(widget, GDK_EXTENSION_EVENTS_ALL); - // TODO: Extension event stuff has been deprecated in GTK+ 3 -#endif } -#if !GTK_CHECK_VERSION(3,0,0) - // This does nothing in GTK+ 3 - GtkStyle *style = gtk_widget_get_style (widget); - gtk_widget_set_style (widget, gtk_style_attach (style, window)); -#endif - gtk_widget_set_realized (widget, TRUE); } @@ -1115,8 +1072,6 @@ void SPCanvas::handle_unrealize(GtkWidget *widget) (* GTK_WIDGET_CLASS(sp_canvas_parent_class)->unrealize)(widget); } - -#if GTK_CHECK_VERSION(3,0,0) void SPCanvas::handle_get_preferred_width(GtkWidget *widget, gint *minimum_width, gint *natural_width) { static_cast<void>(SP_CANVAS (widget)); @@ -1130,16 +1085,6 @@ void SPCanvas::handle_get_preferred_height(GtkWidget *widget, gint *minimum_heig *minimum_height = 256; *natural_height = 256; } -#else -void SPCanvas::handle_size_request(GtkWidget *widget, GtkRequisition *req) -{ - static_cast<void>(SP_CANVAS (widget)); - - req->width = 256; - req->height = 256; -} -#endif - void SPCanvas::handle_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { @@ -1219,9 +1164,7 @@ int SPCanvas::emitEvent(GdkEvent *event) break; case GDK_SCROLL: mask = GDK_SCROLL_MASK; -#if GTK_CHECK_VERSION(3,0,0) mask |= GDK_SMOOTH_SCROLL_MASK; -#endif break; default: mask = 0; @@ -1503,13 +1446,9 @@ gint SPCanvas::handle_scroll(GtkWidget *widget, GdkEventScroll *event) } static inline void request_motions(GdkWindow *w, GdkEventMotion *event) { -#if GTK_CHECK_VERSION(3,0,0) gdk_window_get_device_position(w, gdk_event_get_device((GdkEvent *)(event)), NULL, NULL, NULL); -#else - gdk_window_get_pointer(w, NULL, NULL, NULL); -#endif gdk_event_request_motions(event); } @@ -1746,16 +1685,12 @@ bool SPCanvas::paintRect(int xx0, int yy0, int xx1, int yy1) // Save the mouse location gint x, y; -#if GTK_CHECK_VERSION(3,0,0) - GdkDeviceManager *dm = gdk_display_get_device_manager(gdk_display_get_default()); - GdkDevice *device = gdk_device_manager_get_client_pointer(dm); + auto dm = gdk_display_get_device_manager(gdk_display_get_default()); + auto device = gdk_device_manager_get_client_pointer(dm); gdk_window_get_device_position(gtk_widget_get_window(GTK_WIDGET(this)), device, &x, &y, NULL); -#else - gdk_window_get_pointer(gtk_widget_get_window(GTK_WIDGET(this)), &x, &y, NULL); -#endif setup.mouse_loc = sp_canvas_window_to_world(this, Geom::Point(x,y)); @@ -1818,21 +1753,6 @@ gboolean SPCanvas::handle_draw(GtkWidget *widget, cairo_t *cr) { return TRUE; } -#if !GTK_CHECK_VERSION(3,0,0) -gboolean SPCanvas::handle_expose(GtkWidget *widget, GdkEventExpose *event) -{ - cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget)); - - gdk_cairo_region (cr, event->region); - cairo_clip (cr); - gboolean result = SPCanvas::handle_draw(widget, cr); - - cairo_destroy (cr); - - return result; -} -#endif - gint SPCanvas::handle_key_event(GtkWidget *widget, GdkEventKey *event) { diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 171fdaf67..78d96d728 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -145,12 +145,8 @@ public: static void dispose(GObject *object); static void handle_realize(GtkWidget *widget); static void handle_unrealize(GtkWidget *widget); -#if GTK_CHECK_VERSION(3,0,0) static void handle_get_preferred_width(GtkWidget *widget, gint *min_w, gint *nat_w); static void handle_get_preferred_height(GtkWidget *widget, gint *min_h, gint *nat_h); -#else - static void handle_size_request(GtkWidget *widget, GtkRequisition *req); -#endif static void handle_size_allocate(GtkWidget *widget, GtkAllocation *allocation); static gint handle_button(GtkWidget *widget, GdkEventButton *event); @@ -162,9 +158,6 @@ public: static gint handle_scroll(GtkWidget *widget, GdkEventScroll *event); static gint handle_motion(GtkWidget *widget, GdkEventMotion *event); static gboolean handle_draw(GtkWidget *widget, cairo_t *cr); -#if !GTK_CHECK_VERSION(3,0,0) - static gboolean handle_expose(GtkWidget *widget, GdkEventExpose *event); -#endif static gint handle_key_event(GtkWidget *widget, GdkEventKey *event); static gint handle_crossing(GtkWidget *widget, GdkEventCrossing *event); static gint handle_focus_in(GtkWidget *widget, GdkEventFocus *event); diff --git a/src/display/sp-ctrlline.cpp b/src/display/sp-ctrlline.cpp index 1bde540c0..6c5674935 100644 --- a/src/display/sp-ctrlline.cpp +++ b/src/display/sp-ctrlline.cpp @@ -84,7 +84,7 @@ void sp_ctrlline_render(SPCanvasItem *item, SPCanvasBuf *buf) Geom::Point s = cl->s * cl->affine; Geom::Point e = cl->e * cl->affine; - ink_cairo_set_source_rgba32(buf->ct, 0xffffffbf); + ink_cairo_set_source_rgba32(buf->ct, 0xffffff7f); cairo_set_line_width(buf->ct, 2); cairo_new_path(buf->ct); |
