Render themes: SVG resources on iOS, improves #69
This commit is contained in:
parent
4c5de7453d
commit
21ea5a7842
@ -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)
|
||||
|
||||
@ -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/)
|
||||
|
57
docs/ios.md
57
docs/ios.md
@ -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
|
||||
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>
|
||||
```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>
|
||||
...
|
||||
```
|
||||
```
|
||||
|
@ -123,10 +123,11 @@ public class IosBitmap implements Bitmap {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
@ -138,7 +139,6 @@ public class IosBitmap implements Bitmap {
|
||||
// can dispose helper images for release memory
|
||||
image.dispose();
|
||||
cgiIimage.dispose();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class IosGraphics extends CanvasAdapter {
|
||||
try {
|
||||
return new IosSvgBitmap(inputStream);
|
||||
} catch (IOException e) {
|
||||
log.error("decodeSvgImpl", e);
|
||||
log.error("decodeSvgBitmapImpl", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -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);
|
||||
@ -56,32 +66,7 @@ public class IosSvgBitmap extends IosBitmap {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,10 @@ import org.robovm.apple.coregraphics.CGAffineTransform;
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,10 @@ import org.robovm.apple.foundation.NSObject;
|
||||
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);
|
||||
}
|
||||
|
@ -10,22 +10,39 @@ import org.robovm.rt.bro.annotation.Library;
|
||||
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 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 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();
|
||||
|
||||
}
|
||||
|
@ -16,37 +16,56 @@ import org.robovm.rt.bro.annotation.MachineSizedFloat;
|
||||
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);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user