From 6bc6c0cca6c105450f7cc6f080c72d99f87c173f Mon Sep 17 00:00:00 2001 From: Stefan Wildemann Date: Sun, 28 Jul 2019 12:29:58 +0200 Subject: add:graphics:dpi scaling support (#813) This commit adds calculating a scaling factor out of the virtual_dpi assumed when the layout was created, and the real_dpi value of the hardware. It is activated if "virtual_dpi" tag is set into the "graphics" tag on navit.xml. Currently only qt5 graphics implment returning the hardware dpi. But this can be simulated and overwritten by setting "real_dpi" tag to "graphics" tag on navit.xm on all available graphics.l --- navit/attr_def.h | 2 + navit/callback.c | 12 ++ navit/callback.h | 2 + navit/graphics.c | 292 ++++++++++++++++++++++++++++++------ navit/graphics.h | 181 ++++++++++++---------- navit/graphics/qt5/graphics_qt5.cpp | 28 +++- navit/xslt/sailfish_cursor.xslt | 2 +- navit/xslt/sailfish_qt5.xslt | 2 +- 8 files changed, 390 insertions(+), 131 deletions(-) diff --git a/navit/attr_def.h b/navit/attr_def.h index 4d859d1fa..055936b4a 100644 --- a/navit/attr_def.h +++ b/navit/attr_def.h @@ -200,6 +200,8 @@ ATTR(turn_around_penalty) ATTR(turn_around_penalty2) ATTR(autozoom_max) ATTR(nav_status) +ATTR(virtual_dpi) +ATTR(real_dpi) ATTR2(0x00027500,type_rel_abs_begin) /* These attributes are int that can either hold relative or absolute values. See the * documentation of ATTR_REL_RELSHIFT for details. diff --git a/navit/callback.c b/navit/callback.c index c9ce5adea..edf594c3e 100644 --- a/navit/callback.c +++ b/navit/callback.c @@ -23,6 +23,7 @@ #include "debug.h" #include "callback.h" + struct callback { /* func has variable number of arguments, not (void), * but we must declare something... */ @@ -34,6 +35,8 @@ struct callback { }; struct callback_list { + callback_patch patch; + void * patch_context; GList *list; }; @@ -115,6 +118,13 @@ void callback_list_remove_destroy(struct callback_list *l, struct callback *cb) g_free(cb); } +void callback_list_add_patch_function (struct callback_list *l, callback_patch patch, void * context) { + if(!l) + return; + l->patch = patch; + l->patch_context = context; +} + void callback_call(struct callback *cb, int pcount, void **p) { int i; void *pf[8]; @@ -193,6 +203,8 @@ void callback_list_call_attr(struct callback_list *l, enum attr_type type, int p if (!l) { return; } + if(l->patch != NULL) + l->patch(l, type, pcount, p, l->patch_context); cbi=l->list; while (cbi) { diff --git a/navit/callback.h b/navit/callback.h index b0f4b9f81..c45735280 100644 --- a/navit/callback.h +++ b/navit/callback.h @@ -30,6 +30,7 @@ extern "C" { enum attr_type; struct callback; struct callback_list; +typedef void (*callback_patch) (struct callback_list *l, enum attr_type type, int pcount, void **p, void * context); struct callback_list *callback_list_new(void); struct callback *callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p); struct callback *callback_new_attr_args(void (*func)(void), enum attr_type type, int count, ...); @@ -41,6 +42,7 @@ void callback_list_add(struct callback_list *l, struct callback *cb); struct callback *callback_list_add_new(struct callback_list *l, void (*func)(void), int pcount, void **p); void callback_list_remove(struct callback_list *l, struct callback *cb); void callback_list_remove_destroy(struct callback_list *l, struct callback *cb); +void callback_list_add_patch_function (struct callback_list *l, callback_patch patch, void * context); void callback_call(struct callback *cb, int pcount, void **p); void callback_call_args(struct callback *cb, int count, ...); void callback_list_call_attr(struct callback_list *l, enum attr_type type, int pcount, void **p); diff --git a/navit/graphics.c b/navit/graphics.c index 1bb7dbd3c..40e04bb06 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -51,6 +51,7 @@ #include "callback.h" #include "file.h" #include "event.h" +#include "navit.h" //############################################################################################################## @@ -88,6 +89,8 @@ struct graphics { */ int current_z_order; GHashTable *image_cache_hash; + /* for dpi compensation */ + int dpi_factor; }; struct display_context { @@ -140,6 +143,38 @@ static void circle_to_points(const struct point *center, int diameter, int scale static void graphics_process_selection(struct graphics *gra, struct displaylist *dl); static void graphics_gc_init(struct graphics *this_); + +static int graphics_dpi_scale(struct graphics * gra, int p) { + int result; + if(gra == NULL) + return p; + result = p * gra->dpi_factor; + return result; +} +static struct point graphics_dpi_scale_point(struct graphics * gra, struct point *p) { + struct point result = {-1,-1}; + if(!p) + return result; + result.x = graphics_dpi_scale(gra, p->x); + result.y = graphics_dpi_scale(gra, p->y); + return result; +} +static int graphics_dpi_unscale(struct graphics * gra, int p) { + int result; + if(gra == NULL) + return p; + result = p / gra->dpi_factor; + return result; +} +static struct point graphics_dpi_unscale_point(struct graphics * gra, struct point *p) { + struct point result = {-1,-1}; + if(!p) + return result; + result.x = graphics_dpi_unscale(gra, p->x); + result.y = graphics_dpi_unscale(gra, p->y); + return result; +} + static void clear_hash(struct displaylist *dl) { int i; for (i = 0 ; i < HASH_SIZE ; i++) @@ -242,6 +277,49 @@ void graphics_set_rect(struct graphics *gra, struct point_rect *pr) { gra->r=*pr; } +/** + * @brief unscale coordinates coming from the graphics backend via callback. + * + * @param l pointer to callback list + * @param pcount number of parameters attached to this callback + * @param p list of parameters + * @param context context handed over by callback_list_add_patch_function, gra in this case. + * @return nothing + */ +static void graphics_dpi_patch (struct callback_list *l, enum attr_type type, int pcount, void **p, void * context) { + /* this is black magic. We scaled all coordinates to the graphics backend + * to compensate screen dpi. Since the backends communicate back via the callback + * list, we hook this function to unscale the coordinates coming back to + * navit before actually calling the callbacks. + */ + struct graphics * gra; + gra = (struct graphics *) context; + if(gra == NULL) + return; + + if((type == attr_resize) && (pcount >= 2)) { + int w, h; + w = GPOINTER_TO_INT(p[0]); + h = GPOINTER_TO_INT(p[1]); + dbg(lvl_debug,"scaling attr_resize %d, %d, %d", pcount, w, h); + p[0] = GINT_TO_POINTER(graphics_dpi_unscale(gra,w)); + p[1] = GINT_TO_POINTER(graphics_dpi_unscale(gra,h)); + } + if((type == attr_button) && (pcount >=3)) { + struct point * pnt; + pnt = (struct point *) p[2]; + dbg(lvl_debug,"scaling attr_button %d, %d, %d", pcount, pnt->x, pnt->y); + *pnt = graphics_dpi_unscale_point(gra, pnt); + } + if((type == attr_motion) && (pcount >=1)) { + struct point * pnt; + pnt = (struct point *) p[0]; + dbg(lvl_debug,"scaling attr_motion %d, %d, %d", pcount, pnt->x, pnt->y); + *pnt = graphics_dpi_unscale_point(gra, pnt); + } + /* any more? attr_keypress doesn't come with coordinates */ +} + /** * Creates a new graphics object * attr type required @@ -251,7 +329,7 @@ void graphics_set_rect(struct graphics *gra, struct point_rect *pr) { */ struct graphics * graphics_new(struct attr *parent, struct attr **attrs) { struct graphics *this_; - struct attr *type_attr, cbl_attr; + struct attr *type_attr, cbl_attr, *real_dpi_attr, *virtual_dpi_attr; struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl); @@ -265,11 +343,15 @@ struct graphics * graphics_new(struct attr *parent, struct attr **attrs) { dbg(lvl_error,"Failed to load graphics plugin %s.", type_attr->u.str); return NULL; } + this_=g_new0(struct graphics, 1); this_->attrs=attr_list_dup(attrs); + /* start with no scaling */ + this_->dpi_factor=1; this_->cbl=callback_list_new(); cbl_attr.type=attr_callback_list; cbl_attr.u.callback_list=this_->cbl; + callback_list_add_patch_function (this_->cbl, graphics_dpi_patch, (void*) this_); this_->attrs=attr_generic_add_attr(this_->attrs, &cbl_attr); this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, this_->attrs, this_->cbl); this_->brightness=0; @@ -277,6 +359,26 @@ struct graphics * graphics_new(struct attr *parent, struct attr **attrs) { this_->gamma=65536; this_->font_size=20; this_->image_cache_hash = g_hash_table_new_full(g_str_hash, g_str_equal,g_free,g_free); + /*get dpi */ + virtual_dpi_attr=attr_search(attrs, NULL, attr_virtual_dpi); + real_dpi_attr=attr_search(attrs, NULL, attr_real_dpi); + if(virtual_dpi_attr != NULL) { + navit_float virtual_dpi, real_dpi=0; + virtual_dpi=virtual_dpi_attr->u.num; + if(real_dpi_attr != NULL) + real_dpi=real_dpi_attr->u.num; + else + real_dpi=graphics_get_dpi(this_); + if((real_dpi != 0) && (virtual_dpi != 0)) { + this_->dpi_factor = round(real_dpi / virtual_dpi); + if(this_->dpi_factor < 1) + this_->dpi_factor = 1; + dbg(lvl_error,"Using virtual dpi %f, real dpi %f factor %d", virtual_dpi, real_dpi, this_->dpi_factor); + } + } + if(this_->dpi_factor != 1) + callback_list_call_attr_2(this_->cbl, attr_resize, GINT_TO_POINTER(navit_get_width(parent->u.navit)), + GINT_TO_POINTER(navit_get_height(parent->u.navit))); while (*attrs) { graphics_set_attr_do(this_,*attrs); attrs++; @@ -335,10 +437,16 @@ int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr * struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int wraparound) { struct graphics *this_; struct point_rect pr; + struct point p_scaled; + int w_scaled, h_scaled; if (!parent->meth.overlay_new) return NULL; this_=g_new0(struct graphics, 1); - this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, wraparound); + this_->dpi_factor = parent->dpi_factor; + p_scaled=graphics_dpi_scale_point(parent,p); + w_scaled=graphics_dpi_scale(parent,w); + h_scaled=graphics_dpi_scale(parent,h); + this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, &p_scaled, w_scaled, h_scaled, wraparound); this_->image_cache_hash = parent->image_cache_hash; this_->parent = parent; pr.lu.x=0; @@ -364,11 +472,16 @@ struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, * @param wraparound The new wraparound of the overlay */ void graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, int wraparound) { + struct point p_scaled; + int w_scaled, h_scaled; if (! this_->meth.overlay_resize) { return; } - this_->meth.overlay_resize(this_->priv, p, w, h, wraparound); + p_scaled = graphics_dpi_scale_point(this_,p); + w_scaled = graphics_dpi_scale(this_,w); + h_scaled =graphics_dpi_scale(this_,h); + this_->meth.overlay_resize(this_->priv, &p_scaled, w_scaled, h_scaled, wraparound); } static void graphics_gc_init(struct graphics *this_) { @@ -428,18 +541,15 @@ void graphics_remove_callback(struct graphics *this_, struct callback *cb) { * @author Martin Schaller (04/2008) */ struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags) { - struct graphics_font *this_; - this_=g_new0(struct graphics_font,1); - this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags); - return this_; + return graphics_named_font_new(gra, gra->default_font, size, flags); } struct graphics_font * graphics_named_font_new(struct graphics *gra, char *font, int size, int flags) { struct graphics_font *this_; this_=g_new0(struct graphics_font,1); - this_->priv=gra->meth.font_new(gra->priv, &this_->meth, font, size, flags); + this_->priv=gra->meth.font_new(gra->priv, &this_->meth, font, graphics_dpi_scale(gra,size), flags); return this_; } @@ -603,7 +713,7 @@ void graphics_gc_set_background(struct graphics_gc *gc, struct color *c) { * @author Martin Schaller (04/2008) */ void graphics_gc_set_linewidth(struct graphics_gc *gc, int width) { - gc->meth.gc_set_linewidth(gc->priv, width); + gc->meth.gc_set_linewidth(gc->priv, graphics_dpi_scale(gc->gra, width)); } /** @@ -613,8 +723,15 @@ void graphics_gc_set_linewidth(struct graphics_gc *gc, int width) { * @author Martin Schaller (04/2008) */ void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n) { - if (gc->meth.gc_set_dashes) - gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n); + if (gc->meth.gc_set_dashes) { + int a; + unsigned char * dash_list_scaled = g_alloca(sizeof (unsigned char) * n); + for(a = 0; a < n; a ++) { + dash_list_scaled[a]=graphics_dpi_scale(gc->gra,dash_list[a]); + } + gc->meth.gc_set_dashes(gc->priv, graphics_dpi_scale(gc->gra,width), graphics_dpi_scale(gc->gra,offset), + dash_list_scaled, n); + } } /** @@ -728,13 +845,34 @@ static void image_new_helper(struct graphics *gra, struct graphics_image *this_, struct graphics_image_buffer buffer= {"buffer:",graphics_image_type_unknown}; buffer.start=start; buffer.len=len; + this_->hot = graphics_dpi_scale_point(gra,&this_->hot); + if(this_->width != IMAGE_W_H_UNSET) + this_->width = graphics_dpi_scale(gra,this_->width); + if(this_->height != IMAGE_W_H_UNSET) + this_->height = graphics_dpi_scale(gra,this_->height); this_->priv=gra->meth.image_new(gra->priv, &this_->meth, (char *)&buffer, &this_->width, &this_->height, &this_->hot, rotate); + this_->hot = graphics_dpi_unscale_point(gra,&this_->hot); + if(this_->width != IMAGE_W_H_UNSET) + this_->width = graphics_dpi_unscale(gra,this_->width); + if(this_->height != IMAGE_W_H_UNSET) + this_->height = graphics_dpi_unscale(gra,this_->height); g_free(start); } } else { - if (strcmp(new_name,"buffer:")) + if (strcmp(new_name,"buffer:")) { + this_->hot = graphics_dpi_scale_point(gra,&this_->hot); + if(this_->width != IMAGE_W_H_UNSET) + this_->width = graphics_dpi_scale(gra,this_->width); + if(this_->height != IMAGE_W_H_UNSET) + this_->height = graphics_dpi_scale(gra,this_->height); this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate); + this_->hot = graphics_dpi_unscale_point(gra,&this_->hot); + if(this_->width != IMAGE_W_H_UNSET) + this_->width = graphics_dpi_unscale(gra,this_->width); + if(this_->height != IMAGE_W_H_UNSET) + this_->height = graphics_dpi_unscale(gra,this_->height); + } } if (this_->priv) { dbg(lvl_info,"Using image '%s' for '%s' at %dx%d", new_name, path, width, height); @@ -897,7 +1035,11 @@ void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode) { * @author Martin Schaller (04/2008) */ void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count) { - this_->meth.draw_lines(this_->priv, gc->priv, p, count); + struct point * p_scaled = g_alloca(sizeof (struct point)*count); + int a; + for(a=0; a < count; a ++) + p_scaled[a] = graphics_dpi_scale_point(this_,&(p[a])); + this_->meth.draw_lines(this_->priv, gc->priv, p_scaled, count); } /** @@ -912,14 +1054,16 @@ void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r) { struct point *pnt=g_alloca(sizeof(struct point)*(r*4+64)); int i=0; - - if(this_->meth.draw_circle) - this_->meth.draw_circle(this_->priv, gc->priv, p, r); - else { + if(this_->meth.draw_circle) { + struct point p_scaled; + p_scaled = graphics_dpi_scale_point(this_,p); + this_->meth.draw_circle(this_->priv, gc->priv, &p_scaled, graphics_dpi_scale(this_,r)); + } else { + /* do not scale circle_to_points */ circle_to_points(p, r, 0, -1, 1026, pnt, &i, 1); pnt[i] = pnt[0]; i++; - this_->meth.draw_lines(this_->priv, gc->priv, pnt, i); + graphics_draw_lines(this_, gc, pnt, i); } } @@ -930,7 +1074,29 @@ void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct * @author Martin Schaller (04/2008) */ void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h) { - this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h); + struct point p_scaled; + p_scaled = graphics_dpi_scale_point(this_,p); + this_->meth.draw_rectangle(this_->priv, gc->priv, &p_scaled, graphics_dpi_scale(this_,w), graphics_dpi_scale(this_,h)); +} + +/** + * @brief Draw a plain polygon on the display + * + * @param gra The graphics instance on which to draw + * @param gc The graphics context + * @param[in] pin An array of points forming the polygon + * @param count_in The number of elements inside @p pin + */ +static void graphics_draw_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in) { + if (! gra->meth.draw_polygon) { + return; + } else { + struct point * pin_scaled = g_alloca(sizeof (struct point)*count_in); + int a; + for(a=0; a < count_in; a ++) + pin_scaled[a] = graphics_dpi_scale_point(gra,&(pin[a])); + gra->meth.draw_polygon(gra->priv, gc->priv, pin_scaled, count_in); + } } void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, @@ -949,9 +1115,9 @@ void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc p[i]=p[0]; i++; if (fill) - this_->meth.draw_polygon(this_->priv, gc->priv, p, i); + graphics_draw_polygon(this_,gc,p,i); else - this_->meth.draw_lines(this_->priv, gc->priv, p, i); + graphics_draw_lines(this_,gc,p,i); } @@ -963,7 +1129,9 @@ void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc */ void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy) { - this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy); + struct point p_scaled; + p_scaled = graphics_dpi_scale_point(this_,p); + this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, &p_scaled, dx, dy); } @@ -976,6 +1144,10 @@ void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate) { this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate); + ret[0]=graphics_dpi_unscale_point(this_,&(ret[0])); + ret[1]=graphics_dpi_unscale_point(this_,&(ret[1])); + ret[2]=graphics_dpi_unscale_point(this_,&(ret[2])); + ret[3]=graphics_dpi_unscale_point(this_,&(ret[3])); } /** @@ -1001,9 +1173,29 @@ int graphics_is_disabled(struct graphics *this_) { * @author Martin Schaller (04/2008) */ void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img) { - this_->meth.draw_image(this_->priv, gc->priv, p, img->priv); + struct point p_scaled; + p_scaled = graphics_dpi_scale_point(this_,p); + this_->meth.draw_image(this_->priv, gc->priv, &p_scaled, img->priv); } +/** + * FIXME + * @param <> + * @returns <> + * @author Martin Schaller (04/2008) +*/ +static void graphics_draw_image_warp(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count, + struct graphics_image *img) { + if(this_->meth.draw_image_warp) { + struct point * p_scaled = g_alloca(sizeof (struct point)*count); + int a; + for(a=0; a < count; a ++) + p_scaled[a] = graphics_dpi_scale_point(this_,&(p[a])); + this_->meth.draw_image_warp(this_->priv, gc->priv, p_scaled, count, img->priv); + } else { + dbg(lvl_error,"draw_image_warp not supported by graphics driver"); + } +} //############################################################################################################## //# Description: @@ -1011,9 +1203,11 @@ void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct //# Authors: Martin Schaller (04/2008) //############################################################################################################## int graphics_draw_drag(struct graphics *this_, struct point *p) { + struct point p_scaled; if (!this_->meth.draw_drag) return 0; - this_->meth.draw_drag(this_->priv, p); + p_scaled = graphics_dpi_scale_point(this_,p); + this_->meth.draw_drag(this_->priv, &p_scaled); return 1; } @@ -1204,7 +1398,7 @@ static void label_line(struct graphics *gra, struct graphics_gc *fg, struct grap struct point pb[5]; if (gra->meth.get_text_bbox) { - gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1); + graphics_get_text_bbox(gra,font,label,0x10000, 0x00, pb, 1); tl=(pb[2].x-pb[0].x); th=(pb[0].y-pb[1].y); } else { @@ -1237,7 +1431,7 @@ static void label_line(struct graphics *gra, struct graphics_gc *fg, struct grap p_t.x=x; p_t.y=y; if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y) - gra->meth.draw_text(gra->priv, fg->priv, bg?bg->priv:NULL, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l); + graphics_draw_text(gra, fg, bg, font, label, &p_t, dx*0x10000/l, dy*0x10000/l); } } } @@ -1249,7 +1443,7 @@ static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct gr pnt[0].y+=-dy*l/65536-dx*l/65536; pnt[2].x+=-dx*l/65536-dy*l/65536; pnt[2].y+=-dy*l/65536+dx*l/65536; - gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3); + graphics_draw_lines(gra, gc, pnt, 3); } static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count) { @@ -1612,9 +1806,8 @@ static void draw_init_ctx(struct draw_polyline_context *ctx, int maxpoints) { } -static void graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, struct graphics_gc_priv *gc_priv, - struct point *pnt, int count, int *width, void (*draw)(struct graphics_priv *gr, struct graphics_gc_priv *gc, - struct point *p, int count)) { +static void graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, + struct point *pnt, int count, int *width) { int maxpoints=200; struct draw_polyline_context ctx; int i=0; @@ -1633,7 +1826,7 @@ static void graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, st if (ctx.npos < max_circle_points || ctx.ppos >= maxpoints-max_circle_points || !draw_middle(&ctx,&pnt[i])) { draw_end(&ctx,&pnt[i]); ctx.res[ctx.npos]=ctx.res[ctx.ppos-1]; - draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos); + graphics_draw_polygon(gra, gc, ctx.res+ctx.npos, ctx.ppos-ctx.npos); draw_init_ctx(&ctx, maxpoints); draw_begin(&ctx,&pnt[i]); } @@ -1642,7 +1835,7 @@ static void graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, st ctx.prev_shape=ctx.shape; draw_end(&ctx,&pnt[count-1]); ctx.res[ctx.npos]=ctx.res[ctx.ppos-1]; - draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos); + graphics_draw_polygon(gra, gc, ctx.res+ctx.npos, ctx.ppos-ctx.npos); } @@ -1792,9 +1985,9 @@ void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc // ... then draw the resulting polyline if (points_to_draw_cnt > 1) { if (poly) { - graphics_draw_polyline_as_polygon(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt, w, gra->meth.draw_polygon); + graphics_draw_polyline_as_polygon(gra, gc, points_to_draw, points_to_draw_cnt, w); } else - gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt); + graphics_draw_lines(gra, gc, points_to_draw, points_to_draw_cnt); points_to_draw_cnt=0; } } @@ -1894,7 +2087,7 @@ void graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, pout=p2; } } - gra->meth.draw_polygon(gra->priv, gc->priv, pin, count_in); + graphics_draw_polygon(gra, gc, pin, count_in); if (count_in >= limit) { g_free(p1); g_free(p2); @@ -2030,8 +2223,8 @@ static void multiline_label_draw(struct graphics *gra, struct graphics_gc *fg, s /* Parse all stored lines, and display them */ for (label_linepos=0; label_lineposmeth.draw_text(gra->priv, fg->priv, bg?bg->priv:NULL, font->priv, label_lines[label_linepos], - &pref, 0x10000, 0); + graphics_draw_text(gra, fg, bg, font, label_lines[label_linepos], + &pref, 0x10000, 0); pref.y+=line_spacing; } g_free(input_label); @@ -2080,7 +2273,7 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display graphics_draw_polygon_clipped(gra, gc, pa, count); break; case element_polyline: { - gc->meth.gc_set_linewidth(gc->priv, 1); + graphics_gc_set_linewidth(gc, 1); if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0) graphics_gc_set_dashes(gc, e->u.polyline.width, e->u.polyline.offset, e->u.polyline.dash_table, e->u.polyline.dash_num); for (i = 0 ; i < count ; i++) { @@ -2093,7 +2286,7 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display case element_circle: if (count) { if (e->u.circle.width > 1) - gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width); + graphics_gc_set_linewidth(gc, e->u.polyline.width); graphics_draw_circle(gra, gc, pa, e->u.circle.radius); if (di->label && e->text_size) { struct graphics_font *font=get_font(gra, e->text_size); @@ -2159,7 +2352,7 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display p.x=pa[0].x - img->hot.x; p.y=pa[0].y - img->hot.y; } - gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv); + graphics_draw_image(gra, gra->gc[0], &p, img); } } break; @@ -2168,7 +2361,7 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display if (gra->meth.draw_image_warp) { img=graphics_image_new_scaled_rotated(gra, di->label, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0); if (img) - gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, img->priv); + graphics_draw_image_warp(gra, gra->gc[0], pa, count, img); } else dbg(lvl_error,"draw_image_warp not supported by graphics driver drawing '%s'", di->label); break; @@ -2524,9 +2717,9 @@ void graphics_displaylist_draw(struct graphics *gra, struct displaylist *display graphics_background_gc(gra, gra->gc[0]); if (flags & 1) callback_list_call_attr_0(gra->cbl, attr_predraw); - gra->meth.draw_mode(gra->priv, draw_mode_begin); + graphics_draw_mode(gra, draw_mode_begin); if (!(flags & 2)) - gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y); + graphics_draw_rectangle(gra, gra->gc[0], &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y); if (l) { order+=l->order_delta; xdisplay_draw(displaylist, gra, l, order>0?order:0); @@ -2534,7 +2727,7 @@ void graphics_displaylist_draw(struct graphics *gra, struct displaylist *display if (flags & 1) callback_list_call_attr_0(gra->cbl, attr_postdraw); if (!(flags & 4)) - gra->meth.draw_mode(gra->priv, draw_mode_end); + graphics_draw_mode(gra, draw_mode_end); } static void graphics_load_mapset(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, @@ -2941,3 +3134,14 @@ static void graphics_process_selection(struct graphics *gra, struct displaylist } } +/** + * @brief get display resolution in DPI + * This method returns the native display density in DPI + * @param gra graphics handle + * @returns dpi value. May be fraction therefore double. + */ +navit_float graphics_get_dpi(struct graphics *gra) { + if (!gra->meth.get_dpi) + return 0; + return gra->meth.get_dpi(gra->priv); +} diff --git a/navit/graphics.h b/navit/graphics.h index befeb8e2b..eec44ae14 100644 --- a/navit/graphics.h +++ b/navit/graphics.h @@ -24,6 +24,7 @@ #ifndef NAVIT_GRAPHICS_H #define NAVIT_GRAPHICS_H +#include "coord.h" #ifdef __cplusplus extern "C" { @@ -42,7 +43,7 @@ struct mapset; /* This enum must be synchronized with the constants in NavitGraphics.java. */ enum draw_mode_num { - draw_mode_begin, draw_mode_end + draw_mode_begin, draw_mode_end }; struct graphics_priv; @@ -54,14 +55,14 @@ struct graphics_gc_methods; struct graphics_image_methods; enum graphics_image_type { - graphics_image_type_unknown=0, + graphics_image_type_unknown=0, }; struct graphics_image_buffer { - char magic[8]; /* buffer:\0 */ - enum graphics_image_type type; - void *start; - int len; + char magic[8]; /* buffer:\0 */ + enum graphics_image_type type; + void *start; + int len; }; struct graphics_keyboard_priv; @@ -70,20 +71,20 @@ struct graphics_keyboard_priv; * Describes an instance of the native on-screen keyboard or other input method. */ struct graphics_keyboard { - int w; /**< The width of the area obscured by the keyboard (-1 for full width) */ - int h; /**< The height of the area obscured by the keyboard (-1 for full height) */ - /* TODO mode is currently a copy of the respective value in the internal GUI and uses the same values. - * This may need to be changed to something with globally available enum, possibly with revised values. - * The Android implementation (the first to support a native on-screen keyboard) does not use this field - * due to limitations of the platform. */ - int mode; /**< Mode flags for the keyboard */ - char *lang; /**< The preferred language for text input, may be {@code NULL}. */ - void *gui_priv; /**< Private data determined by the GUI. The GUI may store + int w; /**< The width of the area obscured by the keyboard (-1 for full width) */ + int h; /**< The height of the area obscured by the keyboard (-1 for full height) */ + /* TODO mode is currently a copy of the respective value in the internal GUI and uses the same values. + * This may need to be changed to something with globally available enum, possibly with revised values. + * The Android implementation (the first to support a native on-screen keyboard) does not use this field + * due to limitations of the platform. */ + int mode; /**< Mode flags for the keyboard */ + char *lang; /**< The preferred language for text input, may be {@code NULL}. */ + void *gui_priv; /**< Private data determined by the GUI. The GUI may store * a pointer to a data structure of its choice here. It is * the responsibility of the GUI to free the data structure * when it is no longer needed. The graphics plugin should * not access this member. */ - struct graphics_keyboard_priv *gra_priv; /**< Private data determined by the graphics plugin. The + struct graphics_keyboard_priv *gra_priv; /**< Private data determined by the graphics plugin. The * graphics plugin is responsible for its management. If it * uses this member, it must free the associated data in * its {@code hide_native_keyboard} method. */ @@ -108,67 +109,75 @@ struct graphics_keyboard { * to be visible as long as Navit is in the foreground. */ struct padding { - int left; - int top; - int right; - int bottom; + int left; + int top; + int right; + int bottom; }; struct graphics_methods { - void (*graphics_destroy)(struct graphics_priv *gr); - void (*draw_mode)(struct graphics_priv *gr, enum draw_mode_num mode); - void (*draw_lines)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count); - void (*draw_polygon)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count); - void (*draw_rectangle)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h); - void (*draw_circle)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r); - void (*draw_text)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy); - void (*draw_image)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img); - void (*draw_image_warp)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img); - void (*draw_drag)(struct graphics_priv *gr, struct point *p); - struct graphics_font_priv *(*font_new)(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags); - struct graphics_gc_priv *(*gc_new)(struct graphics_priv *gr, struct graphics_gc_methods *meth); - void (*background_gc)(struct graphics_priv *gr, struct graphics_gc_priv *gc); - struct graphics_priv *(*overlay_new)(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound); - /** @brief Load an image from a file. - * - * @param gr graphics object - * @param meth output parameter for graphics methods object - * @param path file name/path of image to load - * @param w In: width to scale image to, or IMAGE_W_H_UNSET for original width. - * Out: Actual width of returned image. - * @param h heigth; see w - * @param hot output parameter for image hotspot - * @param rotate angle to rotate the image, in 90 degree steps (not supported by all plugins). - * @return pointer to allocated image, to be freed by image_free() - * @see image_free() - */ - struct graphics_image_priv *(*image_new)(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation); - void *(*get_data)(struct graphics_priv *gr, const char *type); - void (*image_free)(struct graphics_priv *gr, struct graphics_image_priv *priv); - void (*get_text_bbox)(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate); - void (*overlay_disable)(struct graphics_priv *gr, int disable); - void (*overlay_resize)(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound); - int (*set_attr)(struct graphics_priv *gr, struct attr *attr); - int (*show_native_keyboard)(struct graphics_keyboard *kbd); - void (*hide_native_keyboard)(struct graphics_keyboard *kbd); + void (*graphics_destroy)(struct graphics_priv *gr); + void (*draw_mode)(struct graphics_priv *gr, enum draw_mode_num mode); + void (*draw_lines)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count); + void (*draw_polygon)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count); + void (*draw_rectangle)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h); + void (*draw_circle)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r); + void (*draw_text)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, + struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy); + void (*draw_image)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, + struct graphics_image_priv *img); + void (*draw_image_warp)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, + struct graphics_image_priv *img); + void (*draw_drag)(struct graphics_priv *gr, struct point *p); + struct graphics_font_priv *(*font_new)(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, + int size, int flags); + struct graphics_gc_priv *(*gc_new)(struct graphics_priv *gr, struct graphics_gc_methods *meth); + void (*background_gc)(struct graphics_priv *gr, struct graphics_gc_priv *gc); + struct graphics_priv *(*overlay_new)(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, + int h, int wraparound); + /** @brief Load an image from a file. + * + * @param gr graphics object + * @param meth output parameter for graphics methods object + * @param path file name/path of image to load + * @param w In: width to scale image to, or IMAGE_W_H_UNSET for original width. + * Out: Actual width of returned image. + * @param h heigth; see w + * @param hot output parameter for image hotspot + * @param rotate angle to rotate the image, in 90 degree steps (not supported by all plugins). + * @return pointer to allocated image, to be freed by image_free() + * @see image_free() + */ + struct graphics_image_priv *(*image_new)(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, + int *w, int *h, struct point *hot, int rotation); + void *(*get_data)(struct graphics_priv *gr, const char *type); + void (*image_free)(struct graphics_priv *gr, struct graphics_image_priv *priv); + void (*get_text_bbox)(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, + struct point *ret, int estimate); + void (*overlay_disable)(struct graphics_priv *gr, int disable); + void (*overlay_resize)(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound); + int (*set_attr)(struct graphics_priv *gr, struct attr *attr); + int (*show_native_keyboard)(struct graphics_keyboard *kbd); + void (*hide_native_keyboard)(struct graphics_keyboard *kbd); + navit_float (*get_dpi)(struct graphics_priv * gr); }; struct graphics_font_methods { - void (*font_destroy)(struct graphics_font_priv *font); + void (*font_destroy)(struct graphics_font_priv *font); }; struct graphics_font { - struct graphics_font_priv *priv; - struct graphics_font_methods meth; + struct graphics_font_priv *priv; + struct graphics_font_methods meth; }; struct graphics_gc_methods { - void (*gc_destroy)(struct graphics_gc_priv *gc); - void (*gc_set_linewidth)(struct graphics_gc_priv *gc, int width); - void (*gc_set_dashes)(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n); - void (*gc_set_foreground)(struct graphics_gc_priv *gc, struct color *c); - void (*gc_set_background)(struct graphics_gc_priv *gc, struct color *c); + void (*gc_destroy)(struct graphics_gc_priv *gc); + void (*gc_set_linewidth)(struct graphics_gc_priv *gc, int width); + void (*gc_set_dashes)(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n); + void (*gc_set_foreground)(struct graphics_gc_priv *gc, struct color *c); + void (*gc_set_background)(struct graphics_gc_priv *gc, struct color *c); }; /** @@ -177,26 +186,26 @@ struct graphics_gc_methods { * linewidth and drawing color. */ struct graphics_gc { - struct graphics_gc_priv *priv; - struct graphics_gc_methods meth; - struct graphics *gra; + struct graphics_gc_priv *priv; + struct graphics_gc_methods meth; + struct graphics *gra; }; struct graphics_image_methods { - void (*image_destroy)(struct graphics_image_priv *img); + void (*image_destroy)(struct graphics_image_priv *img); }; struct graphics_image { - struct graphics_image_priv *priv; - struct graphics_image_methods meth; - int width; - int height; - struct point hot; + struct graphics_image_priv *priv; + struct graphics_image_methods meth; + int width; + int height; + struct point hot; }; struct graphics_data_image { - void *data; - int size; + void *data; + int size; }; /* prototypes */ @@ -250,9 +259,12 @@ void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode); void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count); void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r); void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h); -void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, int r, int fill); -void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy); -void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate); +void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, + int r, int fill); +void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, + struct graphics_font *font, char *text, struct point *p, int dx, int dy); +void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, + struct point *ret, int estimate); void graphics_overlay_disable(struct graphics *this_, int disable); int graphics_is_disabled(struct graphics *this_); void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img); @@ -261,8 +273,10 @@ void graphics_background_gc(struct graphics *this_, struct graphics_gc *gc); void graphics_draw_text_std(struct graphics *this_, int text_size, char *text, struct point *p); char *graphics_icon_path(const char *icon); void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label); -void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int flags); -void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags); +void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, + struct layout *l, int flags); +void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, + struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags); int graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist); struct displaylist_handle *graphics_displaylist_open(struct displaylist *displaylist); struct displayitem *graphics_displaylist_next(struct displaylist_handle *dlh); @@ -276,14 +290,17 @@ int graphics_displayitem_get_coord_count(struct displayitem *di); char *graphics_displayitem_get_label(struct displayitem *di); int graphics_displayitem_get_displayed(struct displayitem *di); int graphics_displayitem_get_z_order(struct displayitem *di); -int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, int dist); +int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, + int dist); void graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl); void graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl); void graphics_clear_selection(struct graphics *gra, struct displaylist *dl); int graphics_show_native_keyboard (struct graphics *this_, struct graphics_keyboard *kbd); int graphics_hide_native_keyboard (struct graphics *this_, struct graphics_keyboard *kbd); void graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in); -void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int poly); +void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, + int *width, int poly); +navit_float graphics_get_dpi(struct graphics *gra); /* end of prototypes */ #ifdef __cplusplus diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index e7b31c605..535b370dc 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -172,7 +172,10 @@ static const char* fontfamilies[] = { * @param gr own private context * @param meth fill this structure with correct functions to be called with handle as interface to font * @param font font family e.g. "Arial" - * @param size Font size in ??? + * @param size Font size in 16.6 fractional points @ 300dpi. This is bullsh***. The encoding is freetypes + * 16.6 fixed point format usually giving points. One point is usually 72th part of an inch. But + * navit does not honor dpi correct. It's traditionally used freetype backend is fixed to 300 dpi. + * So this value is (300/72) pixels * @param flags Font flags (currently 1 if bold and 0 if not) * * @return font handle @@ -205,8 +208,9 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap dbg(lvl_debug, "No matching font. Resort to: %s", font_priv->font->family().toUtf8().data()); } - /* No clue why factor 20. Found this by comparing to Freetype rendering. */ - font_priv->font->setPointSize(size / 20); + /* Convert silly font size to pixels. by 64 is to convert fixpoint to int. */ + dbg(lvl_debug, "(font %s, %d=%f, %d)", font, size,((float)size)/64.0, ((size * 300) / 72) / 64); + font_priv->font->setPixelSize(((size * 300) / 72) / 64); //font_priv->font->setStyleStrategy(QFont::NoSubpixelAntialias); /* Check for bold font */ if (flags) { @@ -809,6 +813,20 @@ static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int #endif } +/** + * @brief Return number of dots per inch + * @param gr self handle + * @return dpi value + */ +static navit_float get_dpi(struct graphics_priv * gr) { + qreal dpi = 96; + QScreen* primary = navit_app->primaryScreen(); + if (primary != NULL) { + dpi = primary->physicalDotsPerInch(); + } + return (navit_float)dpi; +} + static struct graphics_methods graphics_methods = { graphics_destroy, draw_mode, @@ -830,6 +848,10 @@ static struct graphics_methods graphics_methods = { get_text_bbox, overlay_disable, overlay_resize, + NULL, //set_attr + NULL, //show_native_keyboard + NULL, //hide_native_keyboard + get_dpi }; /* create new graphics context on given context */ diff --git a/navit/xslt/sailfish_cursor.xslt b/navit/xslt/sailfish_cursor.xslt index 01029638c..40e128305 100644 --- a/navit/xslt/sailfish_cursor.xslt +++ b/navit/xslt/sailfish_cursor.xslt @@ -12,7 +12,7 @@ - + diff --git a/navit/xslt/sailfish_qt5.xslt b/navit/xslt/sailfish_qt5.xslt index 5ee20e2e9..80ce1c402 100644 --- a/navit/xslt/sailfish_qt5.xslt +++ b/navit/xslt/sailfish_qt5.xslt @@ -13,7 +13,7 @@ - + -- cgit v1.2.1 From ab4d8087a349fa580a4fca1053eca44b1813be16 Mon Sep 17 00:00:00 2001 From: Stefan Wildemann Date: Wed, 7 Aug 2019 13:29:37 +0200 Subject: fix:core: Correct default layout handling. (#816) This commit corrects the default layout handling broken when splitting the layouts to own files. It restores the layout saving of the internal gui. So now it starts again with the last selected layout. --- navit/main.c | 4 ---- navit/main.h | 1 - navit/navit.c | 22 +++++++++++++++++++++- navit/start_real.c | 1 - 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/navit/main.c b/navit/main.c index 986947f0d..f4a59970d 100644 --- a/navit/main.c +++ b/navit/main.c @@ -328,10 +328,6 @@ static void win_set_nls(void) { } #endif -void main_update_default_layout(struct navit *navit) { - navit_update_current_layout(navit, NULL); -} - void main_init(const char *program) { char *s; #ifdef _UNICODE /* currently for wince */ diff --git a/navit/main.h b/navit/main.h index 910d56200..47f275c09 100644 --- a/navit/main.h +++ b/navit/main.h @@ -35,7 +35,6 @@ void main_add_navit(struct navit *nav); void main_remove_navit(struct navit *nav); int main_add_attr(struct attr *attr); int main_remove_attr(struct attr *attr); -void main_update_default_layout(struct navit *navit); void main_init(const char *program); void main_init_nls(void); int main(int argc, char **argv); diff --git a/navit/navit.c b/navit/navit.c index 1d1b8e664..ae39aca59 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -2551,6 +2551,7 @@ static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init) { case attr_layout: if(!attr->u.layout) return 0; + dbg(lvl_debug,"setting attr_layout to %s", attr->u.layout->name); if(this_->layout_current!=attr->u.layout) { navit_update_current_layout(this_, attr->u.layout); graphics_font_destroy_all(this_->gra); @@ -2563,6 +2564,7 @@ static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init) { case attr_layout_name: if(!attr->u.str) return 0; + dbg(lvl_debug,"setting attr_layout_name to %s", attr->u.str); l=this_->layouts; while (l) { lay=l->data; @@ -3000,9 +3002,27 @@ static int navit_add_log(struct navit *this_, struct log *log) { static int navit_add_layout(struct navit *this_, struct layout *layout) { struct attr active; + int is_default=0; + int is_active=0; this_->layouts = g_list_append(this_->layouts, layout); + /** check if we want to immediately activate this layout. + * Unfortunately we have concurring conditions about when to activate + * a layout: + * - A layout could bear the "active" property + * - A layout's name could match this_->default_layout_name + * This cannot be fully resolved, as we cannot predict the future, so + * lets set the last parsed layout active, which either matches default_layout_name or + * bears the "active" tag, or is the first layout ever parsed. + */ + if((layout->name != NULL) && (this_->default_layout_name != NULL)) { + if (strcmp(layout->name, this_->default_layout_name) == 0) + is_default = 1; + } layout_get_attr(layout, attr_active, &active, NULL); - if(active.u.num || !this_->layout_current) { + if(active.u.num) + is_active = 1; + dbg(lvl_debug, "add layout '%s' is_default %d, is_active %d", layout->name, is_default, is_active); + if(is_default || is_active || !this_->layout_current) { this_->layout_current=layout; return 1; } diff --git a/navit/start_real.c b/navit/start_real.c index ad990d874..a29d558bf 100644 --- a/navit/start_real.c +++ b/navit/start_real.c @@ -207,7 +207,6 @@ int main_real(int argc, char * const* argv) { dbg(lvl_error, "%s", _("Internal initialization failed, exiting. Check previous error messages.")); exit(5); } - main_update_default_layout(navit.u.navit); conf.type=attr_config; conf.u.config=config; if (startup_file) { -- cgit v1.2.1 From c2f9838f07a52cc64cb05e9cf95bb378261946d9 Mon Sep 17 00:00:00 2001 From: jandegr Date: Fri, 16 Aug 2019 20:45:07 +0200 Subject: Android build fix and update (#827) --- .circleci/config.yml | 11 ++++++++--- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- navit/CMakeLists.txt | 11 +++++------ navit/android/build.gradle | 14 +++++++------- navit/android/src/org/navitproject/navit/Navit.java | 2 +- scripts/build_android.sh | 9 ++++++++- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 823ca54d0..273406c54 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ jobs: build_android: working_directory: ~/code docker: - - image: circleci/android:api-28-ndk + - image: circleci/android:api-29 environment: JVM_OPTS: -Xmx3200m GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' @@ -78,13 +78,18 @@ jobs: name: Id command: cat /etc/*release - run: - name: Install cmake gettext libsaxonb-java librsvg2-bin pkg-config libprotobuf-c-dev protobuf-c-compiler + name: Install cmake gettext libsaxonb-java librsvg2-bin pkg-config rename command: | sudo apt-get update - sudo apt-get install -y cmake gettext libsaxonb-java librsvg2-bin pkg-config libprotobuf-c-dev protobuf-c-compiler + sudo apt-get install -y cmake gettext libsaxonb-java librsvg2-bin pkg-config rename - run: name: Install Android SDK components command: sdkmanager "cmake;3.6.4111459" + - run: + name: Install ndk + command: | + echo y | sdkmanager --licenses + echo y | sdkmanager ndk-bundle - run: name: Build for Android command: bash scripts/build_android.sh diff --git a/build.gradle b/build.gradle index 5d598ab8b..8fe92d2f1 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.4.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 73bb13d55..25f587d12 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip diff --git a/navit/CMakeLists.txt b/navit/CMakeLists.txt index 0c4d4243d..1234bd0cb 100644 --- a/navit/CMakeLists.txt +++ b/navit/CMakeLists.txt @@ -95,13 +95,12 @@ if(NOT ANDROID) endif() endif() -#if (SHARED_LIBNAVIT) -# add_library (${NAVIT_LIBNAME} SHARED ${NAVIT_SRC} ) -#else(SHARED_LIBNAVIT) -# add_library (${NAVIT_LIBNAME} STATIC ${NAVIT_SRC} ) -#endif(SHARED_LIBNAVIT) +if (SHARED_LIBNAVIT) + add_library (${NAVIT_LIBNAME} SHARED ${NAVIT_SRC} ) +else(SHARED_LIBNAVIT) + add_library (${NAVIT_LIBNAME} STATIC ${NAVIT_SRC} ) +endif(SHARED_LIBNAVIT) -add_library (${NAVIT_LIBNAME} ${NAVIT_SRC} ) if(NOT MSVC) SET(NAVIT_LIBS ${NAVIT_LIBS} m) endif(NOT MSVC) diff --git a/navit/android/build.gradle b/navit/android/build.gradle index 1385336bf..faf5acc03 100644 --- a/navit/android/build.gradle +++ b/navit/android/build.gradle @@ -3,17 +3,17 @@ apply from: "$project.rootDir/gradle/scripts/git-scm-version.gradle" apply plugin: 'checkstyle' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 + buildToolsVersion "29.0.1" defaultConfig { applicationId "org.navitproject.navit" minSdkVersion 9 - targetSdkVersion 27 + targetSdkVersion 28 versionCode gitVersionCode versionName gitVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - ndk { // need for now for 'x86_64' and , 'armeabi' and , 'arm64-v8a' - abiFilters 'x86', 'armeabi-v7a' + ndk { // need for now for 'x86_64' and 'armeabi' + abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a' } externalNativeBuild { cmake { @@ -61,10 +61,10 @@ android { xml.enabled = true html.enabled = true xml { - destination "checkstyle/checkstyleMain.xml" + destination file("checkstyle/checkstyleMain.xml") } html { - destination "checkstyle/checkstyleMain.html" + destination file("checkstyle/checkstyleMain.html") } } diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java index bc2af1632..a2c1a4ff1 100644 --- a/navit/android/src/org/navitproject/navit/Navit.java +++ b/navit/android/src/org/navitproject/navit/Navit.java @@ -444,7 +444,7 @@ public class Navit extends Activity { ActivityResults = new NavitActivityResult[16]; setVolumeControlStream(AudioManager.STREAM_MUSIC); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); - wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,"NavitDoNotDimScreen"); + wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,"navit:DoNotDimScreen"); if (!extractRes(langc, NAVIT_DATA_DIR + "/locale/" + langc + "/LC_MESSAGES/navit.mo")) { Log.e(TAG, "Failed to extract language resource " + langc); diff --git a/scripts/build_android.sh b/scripts/build_android.sh index 4b915f35e..3f2738451 100755 --- a/scripts/build_android.sh +++ b/scripts/build_android.sh @@ -22,8 +22,13 @@ export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin export JVM_OPTS="-Xmx3200m" export GRADLE_OPTS='-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' +# processing xml is messed up a bit after the original introduction of gradle +# so a useless install of ant here even if using gradle/ninja + +sudo apt-get install -y ant + echo Run CMake -cmake ./ -Dvehicle/gpsd_dbus:BOOL=FALSE -Dsvg2png_scaling:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_nav:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_flag:STRING=-1,24,32,64,96 -DUSE_PLUGINS=n -DBUILD_MAPTOOL=n -DXSL_PROCESSING=y -DXSLTS=android -DANDROID=y -DSAMPLE_MAP=n || exit 1 +cmake ./ -Dvehicle/gpsd_dbus:BOOL=FALSE -Dsvg2png_scaling:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_nav:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_flag:STRING=-1,24,32,64,96 -DXSL_PROCESSING=y -DXSLTS=android -DANDROID=y || exit 1 echo Process icons pushd navit/icons @@ -45,6 +50,8 @@ rename 'y/A-Z/a-z/' ./*.mo popd popd + + echo Process xml config files make navit_config_xml || exit 96 pushd navit -- cgit v1.2.1