Opened 9 years ago
Closed 7 years ago
#1222 closed defect/bug (fixed)
Better REGEX in navit/xpm/CMakeLists.txt
Reported by: | tobe deprez | Owned by: | KaZeR |
---|---|---|---|
Priority: | major | Milestone: | version 0.5.1 |
Component: | core | Version: | git master |
Severity: | normal | Keywords: | |
Cc: |
Description
In the file navit/xpm/CMakeLists.txt, there is some code to detect the width of the svg file (line 21-24):
if (${SCALE} EQUAL 0) file(STRINGS ${IMAGE_INPUT} NEW_SCALE_LINE REGEX "[^-]width=\"[0-9pxt.]*\"") string(REGEX REPLACE ".*width=\"([0-9]*).*" "\\1" NEW_SCALE ${NEW_SCALE_LINE}) endif()
This code does not seem to work for some files (museum.svg and hotel.svg if I remember correctly): the ${NEW_SCALE} variable was 0. I don't know exactly what happened, but I think the code read some other width attribute somewhere the svg file. To avoid this, you can use the following code, which specifically tries to read the width attribute in the <svg> tag:
if (${SCALE} EQUAL 0) file (READ ${IMAGE_INPUT} IMAGE_CONTENTS) string(REGEX MATCH "<svg[^>-]*width=\"([0-9]+)(px)?\"[^>]*>" SVG_TAG "${IMAGE_CONTENTS}") set (NEW_SCALE "${CMAKE_MATCH_1}") endif()
Change History (7)
comment:1 Changed 8 years ago by tobe deprez
comment:2 Changed 7 years ago by davo
Ah, I spent several hours working out what was happening during my install, should have looked here first. Anyway, more info - The problem happens because some SVG files mention "width=" more than once, the author assumed there would be only one instance in the strings output. I am pretty sure that the first instance is always the right one, so all that needs happen is to add an option to the cmake strings command, "LIMIT_COUNT 1" so it returns the first one it finds. Easier than changing the regex ....
So line 23 of CMakeLists.txt in xpm directory becomes -
file(STRINGS ${IMAGE_INPUT} NEW_SCALE_LINE LIMIT_COUNT 1 REGEX "[^-]width=\"[0-9pxt.]*\"")
I don't have commit permission to the code but this change is trivial, so I'm not offering to send a diff or any such. But will help is anyone wnat me to.
David
comment:3 Changed 7 years ago by davo
Hmm, sorry, that should have been "line 22" not 23. Forgot I'd added a debugging line further up. So currently it says -
file(STRINGS ${IMAGE_INPUT} NEW_SCALE_LINE REGEX "[^-]width=\"[0-9pxt.]*\"")
But it needs to say -
file(STRINGS ${IMAGE_INPUT} NEW_SCALE_LINE LIMIT_COUNT 1 REGEX "[^-]width=\"[0-9pxt.]*\"")
and will install without fatal errors !
If I can help with anything, more than happy .....
David
comment:4 Changed 7 years ago by kazer
Thanks for your report and patch. I cannot reproduce the issue with the current code.
Museum : https://circle-artifacts.com/gh/navit-gps/navit/853/artifacts/0/tmp/circle-artifacts.5GUwwNH/xpm/museum.svg Hotel : https://circle-artifacts.com/gh/navit-gps/navit/853/artifacts/0/tmp/circle-artifacts.5GUwwNH/xpm/hotel.svg
Are you guys still facing this problem? Maybe this is related to the tool used for the conversion.
I tested in my own dev environment and the CI.
comment:5 Changed 7 years ago by kazer
- Milestone set to version 0.5.1
comment:6 Changed 7 years ago by tobe deprez
Also here, the new code seems to build without problems
comment:7 Changed 7 years ago by kazer
- Resolution set to fixed
- Status changed from new to closed
Ok, we can close the ticket then.
Thanks!
Somehow a superfluous '-' crept in my code above. It should have been