viking-gps / viking

Viking is a free/open source program to manage GPS data (inc GPX, FIT, TCX and KML files). You can import and plot tracks, routes and waypoints, show OpenStreetMaps (OSM), Bing Aerial and other maps, generate Mapnik maps, geotag images, make new tracks, routes and waypoints, see real-time GPS position, etc. It is written mostly in C with GTK
http://sourceforge.net/projects/viking/
GNU General Public License v2.0
226 stars 56 forks source link

Trouble with Generate Image File in 1.9 with gtk+3 #122

Closed ljb279 closed 3 years ago

ljb279 commented 3 years ago

When using File > Generate Image File in Viking-1.9 (on 64-bit Linux), I am seeing these problems:

  1. After generating the image file, all waypoint text is turned off. It comes back on if I toggle the layer visiblity.

  2. In about the center of the image file, there is a rectangle with "smeared" contents. It's easy to see but hard to describe. It happens every time. (If I can figure out how, I'll attach an image.) It happens with both JPEG and PNG, and with different base map backgrounds.

  3. Through Viking-1.8, I often generated image files at half the pixelfact (zoom factor) as displayed, to make higher resolution maps. For example, view at 2, Generate Image File, change zoom to 1, click Area in current viewable window. This no longer works at Viking-1.9. I get a small map taking up the upper 1/4 of the image file with the remaining parts black.

The above is using the default Gtk+3 build, and I have gtk-3.24.28 installed. This is the latest gtk+3 version, as of now. Then I rebuilt Viking-1.9 using Gtk+2 (--enable-gtk2) and these problems all went away. Unfortunately, that is "deprecated".

rnorris commented 3 years ago

Regarding points 1 & 2 - On my Debian desktop (x11) I can not reproduce this and it works fine. However on Ubuntu running Wayland, it produces a totally blank image.

Are you running an X11 or Wayland desktop?

Regarding point 3, yes I get the same behaviour. I think under GTK3 it needs properly force a flushing the temporary surface better, as otherwise GTK3 is probably more 'clever' and thinks it doesn't need to draw it. And/or possibly try a different approach such as accessing the cairo surface directly, rather than from a GdkWindow

ljb279 commented 3 years ago

I am using X11, not Wayland, with Xfce desktop.

On point 2, I realized and confirmed something very odd: The blurred rectangle on the generated image file exactly corresponds to the position and size of the "Image file generated" dialog that Viking displays after the image file is generated. Just out of curiosity, I'm going to try adding a short delay before this dialog appears. Maybe it needs more time to generate the image file on my PC?

Aside, today I updated to the just-release Gtk+3 3.24.29 and it didn't help.

rnorris commented 3 years ago

Here is my currently working solution, which fixes point 3 for me and also works under Wayland.

If you could confirm this fixes it you - then I'll commit it to the mainline.

https://zerobin.net/?31aea8f2ad8a4cd8#NB4VW4O1q3pl4FUg9c+IRuneVbN4Y5RFZnY7qab0oho=

ljb279 commented 3 years ago

Sorry, I can't figure out what to do what that file. It looks like a patch or diff file, but the 'patch' program can't read it. What is it, and how do I apply it to 1.9?

I did try re-ordering code and adding a loop with gtk_main_iteration() in save_image_file(). It changes the results but does not fix it. Sometimes I get the file save dialog in my generated image file, and sometimes the generated image file has no waypoint text.

rnorris commented 3 years ago

It was meant to be a git patch, but it wasn't in the right format. So try this one

https://zerobin.net/?e24de3b65637106d#rE7H8JM9vEcNPgPjL9+s3yHOcVuUiaQHSYtbpBXjXa0=

Save the raw output as a text file, copy it to your top level Viking directory, then run the command

git apply patch.txt

You may need to undo / stash your modifications in order for it to apply.

HTH.

ljb279 commented 3 years ago

Thanks - I was able to apply this patch.

This did fix (3): the map now fills the image at the selected zoom factor, which is lower than the viewed zoom, giving me a higher resolution map image file.

It also fixed (2), blurred area where the dialog was. I am not sure why, but I ran enough tests before and after the patch to be pretty sure your changes did fix it.

Unfortunately, (1) is now worse. Now the waypoint and track text are missing from the image file. They are also missing on-screen, but only when generating the image file at the same zoom factor.

To summarize:

Viking-1.9 (unpatched) with gtk+3:

  Generate image file at same zoom factor:
    Text goes away on-screen after
    Text is OK in the image file
    Image file has a blurred box where the dialog was.

  Generate image file at 1/2 viewed zoom factor:
    Text is OK on-screen after
    Map only takes up 1/4 of the image file
    Text is OK in the image file
    Image file has a blurred box where the dialog was.

Viking-1.9 + above patch with gtk+3:

  Generate image file at same zoom factor:
    Text goes away on-screen after
    Text is missing from the image file
    No blurred box in the image file

  Generate image file at 1/2 viewed zoom factor:
    Text is OK on-screen after
    Map fills the image file
    Text is missing from the image file
    No blurred box in the image file
rnorris commented 3 years ago

Thanks for the update. With the patch, I too can now recreate the 'Text' not ever drawn on image/ not on screen if same zoom. Not quite sure why I didn't see this behaviour before. Must be some weird low level Viking update / GTK3 / pango / cairo interaction, which will require much more deeper thought / trail and error...

rnorris commented 3 years ago

Try adding these additional lines (in conjunction with the above patch), to the file vikviewport.c at the end of the vik_viewport_configure_manually() function:

#if GTK_CHECK_VERSION (3,0,0)
  // Performed after above gc's are reset
  vik_layers_panel_configure_layers ( vik_window_layers_panel(VIK_WINDOW_FROM_WIDGET(vvp)) );
#endif

This seems to provisionally fix (1) but I haven't done much testing yet.

ljb279 commented 3 years ago

That's perfect. Fixes all 3 problems I had with Generate Image File under Gtk+3. Thanks.