sxiv icon indicating copy to clipboard operation
sxiv copied to clipboard

added svg support and modified Makefile enough so that it compiles

Open Dhruv-Vanjari opened this issue 3 years ago • 11 comments

Hi, This is a loader for svg images.

I am not very good at Makefile so I have modified it just enough so that the code compiles. Makefile has to be updated after this commit.

The following libraries are used for loading svg documents

  • librsvg
  • cairo

First the svg document is opened using librsvg and then rendered on a cairo surface, and finally the cairo surface pixel buffer is used to create an Imlib_Image.

dependencies also need to updated in README after this commit.

Dhruv-Vanjari avatar Mar 14 '21 07:03 Dhruv-Vanjari

I forgot to mention one thing. The vector images are converted to raster and thus not retain their scalable nature. I am planing to implement functions to zoom in the image without loosing clarity in the future.

Dhruv-Vanjari avatar Mar 14 '21 07:03 Dhruv-Vanjari

Nice, added to my fork. Waiting for your next commit. Before I forget, I guess it's nice to add image/svg+xml; to the .desktop file. Thanks dude and have a nice day

Naheel-Azawy avatar Apr 09 '21 19:04 Naheel-Azawy

Thanks for the suggestion Naheel.

Dhruv-Vanjari avatar Apr 11 '21 07:04 Dhruv-Vanjari

Implemented zooming

Now users can zoom in svg images without loosing quality.

Because size (resolution) of the raster image changes when scaling svg images, zoom steps were increasing/decreasing exponentialy and the result was unusable. That's why while performing operations like img_check_pan and img_render, img->zoom property is forced to equal to 1.0 then reverted to the actual zoom value.

Now that svg support has been implemented, I will work on error handling and checks so that the program won't break. And also try work on the make file.

Dhruv-Vanjari avatar Apr 13 '21 10:04 Dhruv-Vanjari

Great work! I found a little issue though. It seems that img_fit_win (when pressing w) is not following the new zoom mechanism.

Naheel-Azawy avatar Apr 13 '21 17:04 Naheel-Azawy

Yeah, I encountered this issue as well. I will look into it. Thanks

Dhruv-Vanjari avatar Apr 13 '21 17:04 Dhruv-Vanjari

Does anyone know why @muennich doesn't show up on the net?

PRESFIL avatar Apr 13 '21 17:04 PRESFIL

I figured out the solution to the img_fit problem and it requires to modify the way regular raster images are handled. I don't think that is a very good idea to have so many commits on so many different areas of the code base in one PR. I was thinking that once this PR gets accepted, I will create another PR as a bug fix. Mean while I will work on svg support and other features on the build branch in my fork of sxiv

Dhruv-Vanjari avatar Apr 16 '21 11:04 Dhruv-Vanjari

@Dhruv-Vanjari you could always squash your commits :)

As for getting the PR accepted, good luck. I thought muennich has made it pretty clear that he is not accepting any more pull requests, but that could of course still happen.

bakkeby avatar Apr 16 '21 12:04 bakkeby

@Dhruv-Vanjari nice work! The only thing that i didn't work for me was in the thumbnail mode. Unfortunately I dont know enough C to make this work, so I'll keep an eye on here to see if that's fixed

GRFreire avatar Aug 23 '21 21:08 GRFreire

I'm also having some kind of error. I works flawless afaik, but it does prints out to the terminal:

GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

How to reproduce

  • Open sxiv in a folder with an svg in it ( open the svg here with -n option, because you wont be able to open it after )
  • Go to thumbnail mode
  • Open a raster image

What do I got so far I know if you remove this part of the code, the error disappears, but I dunno how important it is to just remove it like that.

diff --git a/image.c b/image.c
index a850533..0a7caf4 100644
--- a/image.c
+++ b/image.c
@@ -428,9 +428,6 @@ CLEANUP void img_close(img_t *img, bool decache)
 			imlib_free_image();
 		img->im = NULL;
 	}
-
-	if (img->svg.h)
-		g_object_unref(img->svg.h);
 }
 
 void img_check_pan(img_t *img, bool moved)

GRFreire avatar Aug 23 '21 22:08 GRFreire