-
Notifications
You must be signed in to change notification settings - Fork 7
/
ExampleSvgCanvas.java
75 lines (65 loc) · 1.81 KB
/
ExampleSvgCanvas.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Example usage of libsvgandroid
* Written by Anton Persson
*
* This exmple file is in the public domain
*
* The rest of libsvgandroid is licensed under lgpl v3+
*
*/
package com.examplesvg;
import android.util.Log;
import android.view.View;
import android.graphics.Canvas;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.io.BufferedReader;
import android.content.Context;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import com.toolkits.libsvgandroid.*;
class ExampleSvgCanvas extends View {
private int width, height;
private long svgId;
// We must first load the svgandroid native library
static {
System.loadLibrary("svgandroid");
}
public HelloSvgCanvas(Context context) {
super(context);
InputStream is;
is = this.getResources().openRawResource(R.raw.hellosvg);
try {
StringBuilder sb = new StringBuilder();
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
svgId = SvgRaster.svgAndroidCreate();
SvgRaster.svgAndroidParseBuffer(svgId, sb.toString());
SvgRaster.svgAndroidSetAntialiasing(svgId, true);
} catch(java.io.UnsupportedEncodingException e) {
} catch(java.io.IOException e) {
}
}
@Override
protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
// get visible area
width = right - left;
height = bottom - top;
}
@Override
public void onDraw(Canvas canvas) {
// paint a white background...
canvas.drawARGB(255,255,255,255);
// OK, rasterize the SVG data
// SvgRaster.svgAndroidRender(svgId, canvas);
int k;
for(k = 1; k < 6; k++)
SvgRaster.svgAndroidRenderToArea(
svgId, canvas,
k * 30, k * 30, 80 * k, 80 * k);
}
}