اوپن سٹریٹ میپ دا لوگو اوپن سٹریٹ میپ

GSoC 2019 - SVG texture support & making external Fonts configurable - OSM2World

ایہہ ؜12؍؜July ؜2019ء‬ English وچ «JasonManoloudis» لیکھ چھپیا گیا سی۔

Intoduction

SVG texture support was an important part of for this Google Summer of Code project. Apart from the reasons mentioned in the application document, on why adding Scalable Vector Graphics support would be benefitial, its true importance lays on this fact: Most Wikimedia CC0 available images are SVG files. That would also be the reason that led in “swapping” priorities between the 3d and 4th task listed in the application; SVGs had to be supported if users were to make use of textures provided in traffic sign catalogues like this one.
By the end of it, this task ended up leaving some extra time in our hands, presenting a good opportunity to implement another useful functionality: Make external fonts configurable and able to be registered in the application. (Note: “external” refers to fonts not supported by default in the user’s OS). The need for a functionality like this (mostly) derived from the fact that texts on traffic signs use fonts not so widespread (e.g. Interstate) but it can also come in handy in many other cases as well.
The changes described bellow can be found under the July 12 2019 commits of this feature’s branch.
So, with that out of the way, let’s see how everything got blended into the project:

SVG textures support

The concept of implementing svg textures support was pretty straightforward: a really good support for png images already exists, that of course works with all target outputs of OSM2World; so converting svgs to pngs to make further use it would be the best course of action. As of the latest updates described in a previous diary entry, image layers in a texture are now of the ImageTextureData type. That of course makes ImageTextureData.java the appropriate class to implement such a mechanism.
A couple of changes took place in that class:

  1. A new private field private File convertedToPng was introduced to hold the file created after the conversion
  2. The private method private File SVG2PNG(File svg) was created to implement the actual conversion

The usual way of converting files from one type to another is through “Transcoding” methods; their name speaks for itself. For svgs such methods (and classes) come with svg libraries, like the one used in this case, Apache Batik. The Batik transcoders need a new File object to write the png to and those new files were deemed to also be temporary ones i.e. be deleted once the application terminates.
Apart from that, the getFile() method in ImageTextureData was extended to the state presented below and with that, pretty much everything worthy to be covered on svg to png conversion is included! Png exports with textures where svg images are being used can be found at the end of this entry.

public File getFile() {
	
	if(this.file.getName().endsWith(".svg") && this.convertedToPng == null) {
		convertedToPng = SVG2PNG(this.file);
	}
	
	if(this.file.getName().endsWith(".svg") && this.convertedToPng != null) {
		return convertedToPng;
	}
	
	return this.file;
	
}

Making external fonts configurable

Let me clear out what “configurable” stands for in this case: the user is now able to include in his configuration file a path to a folder containing font files, under the fontDirectory key. These fonts are then parsed and registered into the application, allowing them to be used in Font constructors, in-code, as well as in text layers definitions in a configuration file.
The method for that was defined in ConfigUtil.java that holds other configuration utilities as well.
public static void parseFonts(Configuration config) , as described before, takes a Configuration object (with the configuration file loaded) as a parameter, navigates to the folder path given under the fontDirectory key and loops through the files. Each file is then registered into the application using the “key” method of this mechanism, GraphicsEnvironment.registerFont().
Reading through the Apache Commons Configuration documentation, it was made clear that a PropertiesConfiguration object was always necessary if a configuration file was to be loaded. Following that, a call to parseFonts was made in the 2 classes that held such an object: OSM2World.java, which also includes the main class of the project and ReloadOSMAction.java which reloads a previously opened OSM file.
And with that said, making external fonts configurable mechanism is also wrapped-up!

PNG outputs of SVG textures used (stop sign and tennis net)

STOP sign tennis net

Application document:

https://github.com/JayGhb/GSoC-2019-Application/blob/master/application.pdf

Coming up: Traffic Sign catalogues

Email icon Bluesky Icon Facebook Icon LinkedIn Icon Mastodon Icon Telegram Icon X Icon

Discussion

ایہہ ؜14؍؜July ؜2019ء ‪08:49‬ تے «imagico» ٹپݨی کیتی گئی سی۔

If i understand you correctly your project is to add SVG support by converting to a raster image in the original SVG coordinate system.

The much more interesting feature for 3d rendering would be to have native support for rendering 2d vector data. That is of course much harder to accomplish and way beyond what can be done in a GSOC.

In case this is interesting for you see http://www.math.ualberta.ca/~bowman/publications/asyTUG3.pdf.

ٹپݨی چھڈݨ واسطے لوگ‌این کرو