Skip to content

Commit

Permalink
Render themes: SVG resources on iOS, improves #69
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Jul 19, 2016
1 parent 4c5de74 commit 21ea5a7
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 111 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you have any questions or problems, don't hesitate to ask our public [mailing
- bitmap: any quadtree-scheme tiles as texture
- Backends:
- Android (optional libGDX)
- iOS (using libGDX/RoboVM)
- iOS (using libGDX/RoboVM) ([instructions](docs/ios.md))
- Desktop (using libGDX/JGLFW)
- HTML5/WebGL (using libGDX/GWT)

Expand All @@ -35,7 +35,7 @@ If you have any questions or problems, don't hesitate to ask our public [mailing
- **vtm-web** HTML5/GWT backend
- **vtm-web-app** HTML5/GWT application

The libGDX backends for iOS and GWT are experimental.
The libGDX backend for GWT is experimental.

## Master build downloads
- [Latest jars and Samples applications](http://ci.mapsforge.org/job/vtm/)
Expand Down
59 changes: 29 additions & 30 deletions docs/ios.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
###Implement Exemple:
### Implementation example

RoboVm needs the native libs/frameworks for create a build!
Copy this files from vtm-ios-0.6.0-SNAPSHOT-natives.jar into a temp folder!
RoboVm needs the native libs / frameworks to create a build.
Copy those files from `vtm-ios-0.6.0-SNAPSHOT-natives.jar` into a temp folder.

Create a copy task into your <b>build.gradle</b>
Create a copy task into your **build.gradle**.

```java
```groovy
task copyFrameWorks(type: Copy) {
from(zipTree("./libs/vtm-ios-0.6.0-SNAPSHOT-natives.jar"))
into("${buildDir}/native")
}

tasks.withType(org.gradle.api.tasks.compile.JavaCompile) {
compileTask -> compileTask.dependsOn copyFrameWorks
}
```

Now you can configure your robovm.xml to implement the vtm-natives and the SVG-Framework

```
<libs>
<lib>z</lib>
<lib>build/native/libvtm-jni.a</lib> <!--vtm native -->
</libs>
<frameworkPaths>
<path>build/native</path> <!--SVGgh framework path -->
</frameworkPaths>
<frameworks>
<framework>SVGgh</framework> <!--SVGgh framework name -->
<framework>UIKit</framework>
<framework>OpenGLES</framework>
<framework>QuartzCore</framework>
<framework>CoreGraphics</framework>
<framework>OpenAL</framework>
<framework>AudioToolbox</framework>
<framework>AVFoundation</framework>
</frameworks>
Now you can configure your `robovm.xml` to implement the vtm-natives and the SVG-Framework.

```xml
<libs>
<lib>z</lib>
<lib>build/native/libvtm-jni.a</lib> <!--vtm native -->
</libs>
<frameworkPaths>
<path>build/native</path> <!--SVGgh framework path -->
</frameworkPaths>
<frameworks>
<framework>SVGgh</framework> <!--SVGgh framework name -->
<framework>UIKit</framework>
<framework>OpenGLES</framework>
<framework>QuartzCore</framework>
<framework>CoreGraphics</framework>
<framework>OpenAL</framework>
<framework>AudioToolbox</framework>
<framework>AVFoundation</framework>
</frameworks>
```

Remember, the implementation of a iOS- framework is possible since iOS 8!
So we must set the min iOS-Version at Info.plist.xml!
Remember the implementation of a iOS framework is possible since iOS 8.
So we must set the min iOS-Version at `Info.plist.xml`.

```
```xml
<dict>
<key>MinimumOSVersion</key>
<string>8.0</string>
...
```
```
6 changes: 3 additions & 3 deletions vtm-ios/src/org/oscim/ios/backend/IosBitmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ public IosBitmap(String fileName) throws IOException {
}

/**
* protected constructor for create IosBitmap from IosSvgBitmap
* Protected constructor for create IosBitmap from IosSvgBitmap.
*
* @param image
*/
protected IosBitmap(UIImage image){
protected IosBitmap(UIImage image) {
CGImage cgiIimage = image.getCGImage();
this.width = (int) cgiIimage.getWidth();
this.height = (int) cgiIimage.getHeight();
Expand All @@ -138,7 +139,6 @@ protected IosBitmap(UIImage image){
// can dispose helper images for release memory
image.dispose();
cgiIimage.dispose();

}


Expand Down
2 changes: 1 addition & 1 deletion vtm-ios/src/org/oscim/ios/backend/IosGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected Bitmap decodeSvgBitmapImpl(InputStream inputStream) {
try {
return new IosSvgBitmap(inputStream);
} catch (IOException e) {
log.error("decodeSvgImpl", e);
log.error("decodeSvgBitmapImpl", e);
return null;
}
}
Expand Down
65 changes: 25 additions & 40 deletions vtm-ios/src/org/oscim/ios/backend/IosSvgBitmap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2016 Longri
* Copyright 2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand All @@ -14,34 +15,43 @@
*/
package org.oscim.ios.backend;


import org.oscim.backend.CanvasAdapter;
import org.oscim.utils.IOUtils;
import org.robovm.apple.coregraphics.CGRect;
import org.robovm.apple.coregraphics.CGSize;
import org.robovm.apple.uikit.UIImage;
import svg.SVGRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* Created by Longri on 17.07.16.
*/
import svg.SVGRenderer;

public class IosSvgBitmap extends IosBitmap {
private static final Logger log = LoggerFactory.getLogger(IosSvgBitmap.class);

private static final float DEFAULT_SIZE = 400f;

/**
* Constructor<br>
* @param inputStream
* @throws IOException
*/
public IosSvgBitmap(InputStream inputStream) throws IOException {
super(getUIImage(inputStream));
private static String getStringFromInputStream(InputStream is) {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
String line;
try {
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(br);
}
return sb.toString();
}

//get UIImage from SVG file
private static UIImage getUIImage(InputStream inputStream) {
String svg = getStringFromInputStream(inputStream);
SVGRenderer renderer = new SVGRenderer(svg);
Expand All @@ -56,32 +66,7 @@ private static UIImage getUIImage(InputStream inputStream) {
return renderer.asImageWithSize(new CGSize(bitmapWidth, bitmapHeight), 1);
}


// convert InputStream to String
private static String getStringFromInputStream(InputStream is) {

BufferedReader br = null;
StringBuilder sb = new StringBuilder();

String line;
try {

br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}

} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
public IosSvgBitmap(InputStream inputStream) throws IOException {
super(getUIImage(inputStream));
}
}
6 changes: 2 additions & 4 deletions vtm-ios/src/svg/GHRenderable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import org.robovm.apple.foundation.NSObjectProtocol;
import org.robovm.objc.annotation.Property;

public interface GHRenderable extends NSObjectProtocol{
public interface GHRenderable extends NSObjectProtocol {
@Property(selector = "transform")
public CGAffineTransform getTransform();

@Property(selector = "hidden")
public boolean isHidden();


}
5 changes: 2 additions & 3 deletions vtm-ios/src/svg/SVGContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import org.robovm.apple.uikit.UIColor;
import org.robovm.objc.annotation.Method;

public interface SVGContext {
public interface SVGContext {
@Method(selector = "colorForSVGColorString:")
public UIColor colorForSVGColorString(String svgColorString);

@Method(selector = "objectAtURL:")
public NSObject objectAtURL(String aLocation);

public NSObject objectAtURL(String aLocation);
}
41 changes: 29 additions & 12 deletions vtm-ios/src/svg/SVGParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,39 @@
import org.robovm.rt.bro.annotation.Pointer;
import org.robovm.rt.bro.ptr.Ptr;

@Library(Library.INTERNAL)
@Library(Library.INTERNAL)
@NativeClass("SVGParser")
public class SVGParser extends NSObject {
public static class SVGParserPtr extends Ptr<SVGParser, SVGParserPtr> {}
static { ObjCRuntime.bind(SVGParser.class); }/*</bind>*/

public SVGParser() {};
protected SVGParser(long handle) { super(handle); }
protected SVGParser(SkipInit skipInit) { super(skipInit); }

public SVGParser(String utf8String) { super((SkipInit) null); initObject(init(utf8String)); }

public static class SVGParserPtr extends Ptr<SVGParser, SVGParserPtr> {
}

static {
ObjCRuntime.bind(SVGParser.class);
}/*</bind>*/

public SVGParser() {
}

;

protected SVGParser(long handle) {
super(handle);
}

protected SVGParser(SkipInit skipInit) {
super(skipInit);
}

public SVGParser(String utf8String) {
super((SkipInit) null);
initObject(init(utf8String));
}

@Method(selector = "initWithString:")
protected native @Pointer long init(String utf8String);
protected native
@Pointer
long init(String utf8String);

@Property(selector = "parserError")
public native NSError getParserError();

}
51 changes: 35 additions & 16 deletions vtm-ios/src/svg/SVGRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,56 @@
import org.robovm.rt.bro.annotation.Pointer;
import org.robovm.rt.bro.ptr.Ptr;

@Library(Library.INTERNAL)
@Library(Library.INTERNAL)
@NativeClass("SVGRenderer")
public class SVGRenderer extends SVGParser implements SVGContext, GHRenderable {
public static class SVGRendererPtr extends Ptr<SVGRenderer, SVGRendererPtr> {}
static { ObjCRuntime.bind(SVGRenderer.class); }/*</bind>*/
public static class SVGRendererPtr extends Ptr<SVGRenderer, SVGRendererPtr> {
}

public SVGRenderer() {};
protected SVGRenderer(long handle) { super(handle); }
protected SVGRenderer(SkipInit skipInit) { super(skipInit); }
static {
ObjCRuntime.bind(SVGRenderer.class);
}/*</bind>*/

public SVGRenderer() {
}

;

protected SVGRenderer(long handle) {
super(handle);
}

protected SVGRenderer(SkipInit skipInit) {
super(skipInit);
}

public SVGRenderer(String utf8String) {
super((SkipInit) null);
initObject(init(utf8String));
}

public SVGRenderer(String utf8String) { super((SkipInit) null); initObject(init(utf8String)); }

@Method(selector = "initWithString:")
protected native @Pointer long init(String utf8String);

protected native
@Pointer
long init(String utf8String);

@Property(selector = "viewRect")
public native @ByVal CGRect getViewRect();

public native
@ByVal
CGRect getViewRect();

@Method(selector = "colorForSVGColorString:")
public native UIColor colorForSVGColorString(String svgColorString);

@Method(selector = "objectAtURL:")
public native NSObject objectAtURL(String aLocation);
public native NSObject objectAtURL(String aLocation);

@Property(selector = "transform")
public native CGAffineTransform getTransform();

@Property(selector = "hidden")
public native boolean isHidden();

@Method(selector = "asImageWithSize:andScale:")
public native UIImage asImageWithSize(@ByVal CGSize maximumSize, @MachineSizedFloat double scale);

}

0 comments on commit 21ea5a7

Please sign in to comment.