WIP: SVG images support for TDEHTML #156

Draft
blu.256 wants to merge 7 commits from feat/tdehtml+svg into master
Collaborator

Overview

The aim of this PR is to add support for showing SVG documents embedded in HTML documents via the <img> tag, for applications which use TDEHTML to be able to display SVG icons normally (e.g. Konqueror's launch page about:konqueror, kweatherreport, etc.).

This PR does not add support for:

  • the <svg> element
  • tiled SVG backgrounds

(might be added later if need arises for these)

Commits description

  • The first commit (dbd8fb94cc) is KSVGIconEngine-related. It allows passing 0 values for width and height to use defaults. This is useful for cases when these attributes are not specified in any way, so using the image's defaults is needed (pixmap(...)) in contrast to when width and height are specified (scaled_pixmap(...)).

    How to test this commit:

    $ ksvgtopng 0 0 <some svg file> <name of PNG output file>
    

    Expected outcome if it works: Output image has the SVG documents's default width and height (which can be checked e.g. via Inkscape).

    Expected outcome if it doesn't work:

    art_render_new: x0 >= x1 (x0 = 0, x1 = 0)
    Segmemtation fault
    
  • The second commit (85cac902ac) adds SVG rendering support into TDEHTML. The process is the following and it respects, more or less, the standard process followed by TDEHTML for images:

    1. A special rendering function is made available in misc/svgrender.cpp
    2. In CachedImage class (misc/loader.cpp) the image is loaded, parsed (once it is fully loaded) and rendered with its default size. Some attributes (isVectorImage(), svgExtension(), svg()) are stored for later use in rendering/render_image.cpp.
    3. If the image needs scaling, instead of resizing it like a raster image, the image is re-rendered with the new width and height in rendering/render_image.cpp.

    How to test this commit:

    1. Download and extract tdehtml_svg_test.tar.gz (contains an HTML document, the BasKet icon as SVG and as PNG).
    2. Open the HTML document in Konqueror.

    Expected outcome: see attached screenshot.

    Variant 1: check if icons in about:konqueror are rendered correctly (test with a SVG icon theme, e.g. Masalla).
    Variant 2: check if icons in kweatherreport are rendered correctly, either by clicking on the KWeather Kicker applet or manually launching it: kweatherreport [city.airport code] (test with a SVG icon theme)


    NOTE: Squash before merging

# Overview The aim of this PR is to **add support for showing SVG documents embedded in HTML documents via the `<img>` tag**, for applications which use TDEHTML to be able to display SVG icons normally (e.g. Konqueror's launch page `about:konqueror`, kweatherreport, etc.). This PR does not add support for: * the `<svg>` element * tiled SVG backgrounds (might be added later if need arises for these) ## Commits description * The first commit (dbd8fb94cc) is KSVGIconEngine-related. It allows passing 0 values for width and height to use defaults. This is useful for cases when these attributes are not specified in any way, so using the image's defaults is needed (`pixmap(...)`) in contrast to when width and height are specified (`scaled_pixmap(...)`). How to test this commit: ``` $ ksvgtopng 0 0 <some svg file> <name of PNG output file> ``` Expected outcome **if it works**: Output image has the SVG documents's default width and height (which can be checked e.g. via Inkscape). Expected outcome **if it doesn't work**: ``` art_render_new: x0 >= x1 (x0 = 0, x1 = 0) Segmemtation fault ``` * The second commit (85cac902ac) adds SVG rendering support into TDEHTML. The process is the following and it respects, more or less, the standard process followed by TDEHTML for images: 1. A special rendering function is made available in `misc/svgrender.cpp` 2. In `CachedImage` class (`misc/loader.cpp`) the image is loaded, parsed (once it is fully loaded) and rendered with its default size. Some attributes (`isVectorImage()`, `svgExtension()`, `svg()`) are stored for later use in `rendering/render_image.cpp`. 3. If the image needs scaling, instead of resizing it like a raster image, the image is re-rendered with the new width and height in `rendering/render_image.cpp`. How to test this commit: 1. Download and extract `tdehtml_svg_test.tar.gz` (contains an HTML document, the BasKet icon as SVG and as PNG). 2. Open the HTML document in Konqueror. Expected outcome: see attached screenshot. **Variant 1**: check if icons in `about:konqueror` are rendered correctly (test with a SVG icon theme, e.g. *Masalla*). **Variant 2**: check if icons in kweatherreport are rendered correctly, either by clicking on the KWeather Kicker applet or manually launching it: `kweatherreport [city.airport code]` (test with a SVG icon theme) ---- **NOTE: Squash before merging**
blu.256 force-pushed feat/tdehtml+svg from ba62f9ec88 to 26e845fb81 2 years ago
Owner

Hi Philippe,
is the segmentation fault a result of the changes or was it there even before? The commit seems simple enough, so I would be surprise if it causes a SEGV

Hi Philippe, is the segmentation fault a result of the changes or was it there even before? The commit seems simple enough, so I would be surprise if it causes a SEGV
Poster
Collaborator

Hi Philippe,
is the segmentation fault a result of the changes or was it there even before? The commit seems simple enough, so I would be surprise if it causes a SEGV

The segfault caused is an assertion by libart when either requested width or height are <= 0 (which would be invalid).

The changes make KSVGIconEngine assume 0 width and height mean image default width and height (before this there was no way to use default values for width and height from the image itself). Thus the default values are used and the segfault is avoided. This means it will still crash if negative width or height are requested, but this is an improbable case.

> Hi Philippe, > is the segmentation fault a result of the changes or was it there even before? The commit seems simple enough, so I would be surprise if it causes a SEGV The segfault caused is an assertion by libart when either requested width or height are <= 0 (which would be invalid). The changes make KSVGIconEngine assume 0 width and height mean image default width and height (before this there was no way to use default values for width and height from the image itself). Thus the default values are used and the segfault is avoided. This means it will still crash if negative width or height are requested, but this is an improbable case.
Owner

Ok thanks for the explanation. That make sense.

Ok thanks for the explanation. That make sense.
Poster
Collaborator

Status update: I'm nearly there. Little remains to be fixed before I push the remaining changes to this PR.

Status update: I'm nearly there. Little remains to be fixed before I push the remaining changes to this PR.
Owner

Status update: I'm nearly there. Little remains to be fixed before I push the remaining changes to this PR.

That sounds good! We'll look forward.

In any case, independently of it, we can probably integrate the tdemarkdown under the TDE umbrella.

> Status update: I'm nearly there. Little remains to be fixed before I push the remaining changes to this PR. That sounds good! We'll look forward. In any case, independently of it, we can probably integrate the [tdemarkdown](../../blu.256/tdemarkdown) under the TDE umbrella.
Owner

In any case, independently of it, we can probably integrate the tdemarkdown under the TDE umbrella.

Yes, it is a good idea. Would tdemarkdown remain an independent repository or make it a part of tdelibs? or maybe tdaddons? or other ideas?

> In any case, independently of it, we can probably integrate the [tdemarkdown](../../blu.256/tdemarkdown) under the TDE umbrella. Yes, it is a good idea. Would tdemarkdown remain an independent repository or make it a part of tdelibs? or maybe tdaddons? or other ideas?
Poster
Collaborator

Yes, it is a good idea. Would tdemarkdown remain an independent repository or make it a part of tdelibs? or maybe tdaddons? or other ideas?

tdemarkdown is lightweight enough to make it part of either tdelibs or tdeaddons without much added size penalty. That said, the point of making it was more or less to be able to display the README.md files in a quick and simple way.

> Yes, it is a good idea. Would tdemarkdown remain an independent repository or make it a part of tdelibs? or maybe tdaddons? or other ideas? tdemarkdown is lightweight enough to make it part of either `tdelibs` or `tdeaddons` without much added size penalty. That said, the point of making it was more or less to be able to display the README.md files in a quick and simple way.
Owner

tdemarkdown is lightweight enough to make it part of either tdelibs or tdeaddons without much added size penalty.

Exactly. tdelibs seems the best choice to me and that would offer the part to any application that would like to use it.
@SlavekB what do you think?

> tdemarkdown is lightweight enough to make it part of either `tdelibs` or `tdeaddons` without much added size penalty. Exactly. tdelibs seems the best choice to me and that would offer the part to any application that would like to use it. @SlavekB what do you think?
Owner

tdemarkdown is lightweight enough to make it part of either tdelibs or tdeaddons without much added size penalty.

Exactly. tdelibs seems the best choice to me and that would offer the part to any application that would like to use it.
@SlavekB what do you think?

I considered pros and cons for tdelibs, tdebase and tdeaddons. Because it seems good for markdown to be in basic libraries, tdeaddons seems less suitable. Because tdebase contains primarily basic applications, while tdemarkdown is a component, then as the most suitable seems tdelibs.

It would be good to rename the component to libtdemarkdownopart to remains the opportunity for future creation of the libtdemarkdown shared library. Like libtdehtml + libtdehtmlpart.

> > tdemarkdown is lightweight enough to make it part of either `tdelibs` or `tdeaddons` without much added size penalty. > > Exactly. tdelibs seems the best choice to me and that would offer the part to any application that would like to use it. > @SlavekB what do you think? > I considered pros and cons for `tdelibs`, `tdebase` and `tdeaddons`. Because it seems good for markdown to be in basic libraries, `tdeaddons` seems less suitable. Because `tdebase` contains primarily basic applications, while `tdemarkdown` is a component, then as the most suitable seems `tdelibs`. It would be good to rename the component to `libtdemarkdownopart` to remains the opportunity for future creation of the `libtdemarkdown` shared library. Like `libtdehtml` + `libtdehtmlpart`.
blu.256 force-pushed feat/tdehtml+svg from fff53bc5f2 to 85cac902ac 2 years ago
blu.256 changed title from WIP: SVG images support for TDEHTML to SVG images support for TDEHTML 2 years ago
Poster
Collaborator

Finally it's ready for testing (see first comment -second commit- on how to test).

Finally it's ready for testing (see [first comment -second commit-](https://mirror.git.trinitydesktop.org/gitea/TDE/tdelibs/pulls/156#issue-2152) on how to test).
blu.256 added the PR/rfc label 2 years ago
SlavekB added 1 commit 2 years ago
Owner

I added a small commit about which I assume it will then be squashed to the previous one.

I added a small commit about which I assume it will then be squashed to the previous one.
Poster
Collaborator

@SlavekB Is the PR okay otherwise?

@SlavekB Is the PR okay otherwise?
Owner

@SlavekB Is the PR okay otherwise?

I builded tdelibs with these patches to later afternoon I could do a test on my computer.

> @SlavekB Is the PR okay otherwise? I builded tdelibs with these patches to later afternoon I could do a test on my computer.
SlavekB added 1 commit 2 years ago
4df3893c30
svgicons: Prevent a crash in case of a problem with the SVG image.
Owner

I did the test and I have several observations:

  1. I tested the opening of git repository tdesudo in Konqueror. In the place where there is a graph of language translation status, instead of an unavailable image icon, there is now to see the picture of the right dimensions, but with no content – just white.

  2. For some pages (for example, our news server iDnes), where some images in svg were previously missing (probably, I did not even notice, because CSS rendering is not okay), there is now a crash due to the problem of processing such images. It seems that there is a size 0×0. In the console I see:

art_render_new: x0 >= x1 (x0 = 0, x1 = 0)
  1. In the case of a not loaded images (html mail with alert to load external images), there is a crash in KMail.

Problems 2 and 3 are resolved in the added commits. In the case of a problem 2, there is solved only a consequence – I did not find the beginning of the problem – that is, there was no attempt to render the image when the size is 0×0.

I did the test and I have several observations: 1. I tested the opening of git repository [tdesudo](../tdesudo) in Konqueror. In the place where there is a graph of language translation status, instead of an unavailable image icon, there is now *to see* the picture of the right dimensions, but with no content – just white. 2. For some pages (for example, our news server [iDnes](https://www.idnes.cz/)), where some images in svg were previously missing (probably, I did not even notice, because CSS rendering is not okay), there is now a crash due to the problem of processing such images. It seems that there is a size 0×0. In the console I see: ``` art_render_new: x0 >= x1 (x0 = 0, x1 = 0) ``` 3. In the case of a not loaded images (html mail with alert to load external images), there is a crash in KMail. Problems 2 and 3 are resolved in the added commits. In the case of a problem 2, there is solved only a consequence – I did not find the beginning of the problem – that is, there was no attempt to render the image when the size is 0×0.
SlavekB force-pushed feat/tdehtml+svg from f684881361 to 003976f81b 2 years ago
Poster
Collaborator

Thank you for testing, I will repeat these tests for myself and see how to solve remaining points.

Thank you for testing, I will repeat these tests for myself and see how to solve remaining points.
Poster
Collaborator

I did not find the beginning of the problem – that is, there was no attempt to render the image when the size is 0×0.

I dont know if it is relevant, but the second commit (TDEHTML-relevant) passes size 0x0 to KSVGIconEngine (to avoid changing order of parameters in constructor function) as a specjal case to be substituted with the SVG image's default size, which is implemented with the first commit. So this error would probably occur if the second commit was applied but not the first one.

> I did not find the beginning of the problem – that is, there was no attempt to render the image when the size is 0×0. I dont know if it is relevant, but the second commit (TDEHTML-relevant) passes size 0x0 to KSVGIconEngine (to avoid changing order of parameters in constructor function) as a specjal case to be substituted with the SVG image's default size, which is implemented with the first commit. So this error would probably occur if the second commit was applied but not the first one.
SlavekB requested changes 2 years ago
SlavekB left a comment
Owner

Now there is a fatal problem that needs a different solution. See comment.

Now there is a fatal problem that needs a different solution. See comment.
d->width = width; // this sets default for no width -> 100% case
if(rootElement.hasAttribute("width"))
{
d->width = d->helper->toPixel(rootElement.attribute("width"), true);
Owner

During other tests and searching for the cause of another crash, I found one fundamental problem. Calling d->helper->toPixel requires that already exists painter. Because the creation of painter was moved in the code down, it now causes crash. Another solution is necessary here.

During other tests and searching for the cause of another crash, I found one fundamental problem. Calling `d->helper->toPixel` **requires** that already exists `painter`. Because the creation of `painter` was moved in the code down, it now causes crash. Another solution is necessary here.
Owner

To solve the potential crash during size detection, I moved the creation of the initial icon painter back before the size is detected. And if needed, a new icon painter is created when size detection is complete. Therefore, for existing primary use for icons, it should not be a noticeable increase in overhead.

To solve the potential crash during size detection, I moved the creation of the initial icon painter back before the size is detected. And if needed, a new icon painter is created when size detection is complete. Therefore, for existing primary use for icons, it should not be a noticeable increase in overhead.
Poster
Collaborator

The fix looks good. I've been unable to reproduce the crash but the changes make sense to me.

The fix looks good. I've been unable to reproduce the crash but the changes make sense to me.
SlavekB added 1 commit 2 years ago
2fcbb8f256
svgicons: Create initial icon painter before size detection.
Poster
Collaborator

I'm thinking of some API changes to KSVGIconEngine to allow using TQDomDocument or TQString as SVG data and also change order of parameters of existing load(width, height, path) to load(path, width, height) so that width and height parameters can be omitted.

I'm thinking of some API changes to KSVGIconEngine to allow using TQDomDocument or TQString as SVG data and also change order of parameters of existing `load(width, height, path)` to `load(path, width, height)` so that `width` and `height` parameters can be omitted.
blu.256 changed title from SVG images support for TDEHTML to WIP: SVG images support for TDEHTML 2 years ago
blu.256 added 1 commit 2 years ago
d52839aabb
svgicons: API changes proposal
blu.256 requested review from SlavekB 2 years ago
Poster
Collaborator
  1. I tested the opening of git repository tdesudo in Konqueror. In the place where there is a graph of language translation status, instead of an unavailable image icon, there is now to see the picture of the right dimensions, but with no content – just white.

I tried to do so and I could see this too. Then I tried downloading the SVG picture and running ksvgtopng on it. This resulted in a transparent image. This probably means that KSVGIconEngine can't render it for some reason. I think KSVGIconEngine was not actually meant for stuff more complex than icons and the problem might be some unsupported stuff (I can think of links).

In contrast, Konqueror's KSVG plugin displays it just fine. Maybe we should actually consider using KSVG instead of KSVGIconEngine? Then we won't even need modifying the API of KSVGIconEngine and let it handle just the icons. But KSVG is in tdegraphics, not tdelibs, so how to integrate it with TDEHTML then?

> 1. I tested the opening of git repository tdesudo in Konqueror. In the place where there is a graph of language translation status, instead of an unavailable image icon, there is now to see the picture of the right dimensions, but with no content – just white. I tried to do so and I could see this too. Then I tried downloading the SVG picture and running `ksvgtopng` on it. This resulted in a transparent image. This probably means that KSVGIconEngine can't render it for some reason. I think KSVGIconEngine was not actually meant for stuff more complex than icons and the problem might be some unsupported stuff (I can think of links). In contrast, Konqueror's KSVG plugin displays it just fine. Maybe we should actually consider using KSVG instead of KSVGIconEngine? Then we won't even need modifying the API of KSVGIconEngine and let it handle just the icons. But KSVG is in tdegraphics, not tdelibs, so how to integrate it with TDEHTML then?
Poster
Collaborator

I think I'll try implementing dynamic loading and embedding of the KSVG part from TDEHTML (via TDETrader and KService). This way the part will get automatically loaded if ksvg from tdegraphics is installed and rendering will be better.

I'll probably try this in a separate branch, which I'll create a PR for when/if I have an acceptable result. KSVGIconEngine is a dead end IMO, it is useful only for what it was initially created, simple icons.

I think I'll try implementing dynamic loading and embedding of the KSVG part from TDEHTML (via TDETrader and KService). This way the part will get automatically loaded if ksvg from tdegraphics is installed and rendering will be better. I'll probably try this in a separate branch, which I'll create a PR for when/if I have an acceptable result. KSVGIconEngine is a dead end IMO, it is useful only for what it was initially created, simple icons.
blu.256 added PR/not-ok and removed PR/rfc labels 2 years ago
Owner

Yes, the KSVGIconEngine seems to require many fixes and possibly copy some parts of the code from KSVG in tdegraphics. It looks like futile effort. It will be great if there will be possible to use of KSVG part instead of KSVGIconEngine.

Yes, the KSVGIconEngine seems to require many fixes and possibly copy some parts of the code from KSVG in tdegraphics. It looks like futile effort. It will be great if there will be possible to use of KSVG part instead of KSVGIconEngine.
Owner

Yes, the KSVGIconEngine seems to require many fixes and possibly copy some parts of the code from KSVG in tdegraphics. It looks like futile effort. It will be great if there will be possible to use of KSVG part instead of KSVGIconEngine.

I agree, it would be a better option.

> Yes, the KSVGIconEngine seems to require many fixes and possibly copy some parts of the code from KSVG in tdegraphics. It looks like futile effort. It will be great if there will be possible to use of KSVG part instead of KSVGIconEngine. I agree, it would be a better option.

Reviewers

SlavekB was requested for review 2 years ago
This pull request has changes conflicting with the target branch.
tdehtml/misc/loader.h
tdehtml/rendering/render_image.cpp
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: TDE/tdelibs#156
Loading…
There is no content yet.