Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
c7e5032c
Unverified
Commit
c7e5032c
authored
Nov 02, 2021
by
Aleksandr Veselov
Committed by
GitHub
Nov 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement native methods of SVGSVG and SVGDOM (#334)
parent
36c350d8
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
144 additions
and
158 deletions
+144
-158
SVGDOM.kt
skiko/src/commonMain/kotlin/org/jetbrains/skia/svg/SVGDOM.kt
+3
-7
SVGLength.kt
...src/commonMain/kotlin/org/jetbrains/skia/svg/SVGLength.kt
+9
-0
SVGPreserveAspectRatio.kt
...n/kotlin/org/jetbrains/skia/svg/SVGPreserveAspectRatio.kt
+10
-0
SVGSVG.kt
skiko/src/commonMain/kotlin/org/jetbrains/skia/svg/SVGSVG.kt
+12
-18
SvgTest.kt
skiko/src/commonTest/kotlin/org/jetbrains/skia/SvgTest.kt
+15
-16
SVGDOM.cc
skiko/src/jvmMain/cpp/common/svg/SVGDOM.cc
+3
-3
SVGSVG.cc
skiko/src/jvmMain/cpp/common/svg/SVGSVG.cc
+22
-21
interop.cc
skiko/src/jvmMain/cpp/common/svg/interop.cc
+11
-0
interop.hh
skiko/src/jvmMain/cpp/common/svg/interop.hh
+2
-0
common.h
skiko/src/nativeJsMain/cpp/common.h
+11
-0
common_interop.cc
skiko/src/nativeJsMain/cpp/common_interop.cc
+18
-0
SVGDOM.cc
skiko/src/nativeJsMain/cpp/svg/SVGDOM.cc
+3
-12
SVGSVG.cc
skiko/src/nativeJsMain/cpp/svg/SVGSVG.cc
+25
-81
No files found.
skiko/src/commonMain/kotlin/org/jetbrains/skia/svg/SVGDOM.kt
View file @
c7e5032c
package
org.jetbrains.skia.svg
import
org.jetbrains.skia.impl.Library.Companion.staticLoad
import
org.jetbrains.skia.impl.RefCnt
import
org.jetbrains.skia.*
import
org.jetbrains.skia.impl.Stats
import
org.jetbrains.skia.impl.reachabilityBarrier
import
org.jetbrains.skia.ExternalSymbolName
import
org.jetbrains.skia.impl.NativePointer
import
org.jetbrains.skia.impl.getPtr
import
org.jetbrains.skia.impl.*
class
SVGDOM
internal
constructor
(
ptr
:
NativePointer
)
:
RefCnt
(
ptr
)
{
companion
object
{
...
...
@@ -36,7 +32,7 @@ class SVGDOM internal constructor(ptr: NativePointer) : RefCnt(ptr) {
@get
:
Deprecated
(
""
)
val
containerSize
:
Point
get
()
=
try
{
SVGDOM_nGetContainerSize
(
_ptr
)
Point
.
fromInteropPointer
{
SVGDOM_nGetContainerSize
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -70,7 +66,7 @@ private external fun SVGDOM_nMakeFromData(dataPtr: NativePointer): NativePointer
private
external
fun
SVGDOM_nGetRoot
(
ptr
:
NativePointer
):
NativePointer
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGDOM__1nGetContainerSize"
)
private
external
fun
SVGDOM_nGetContainerSize
(
ptr
:
NativePointer
):
Point
private
external
fun
SVGDOM_nGetContainerSize
(
ptr
:
NativePointer
,
dst
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGDOM__1nSetContainerSize"
)
private
external
fun
SVGDOM_nSetContainerSize
(
ptr
:
NativePointer
,
width
:
Float
,
height
:
Float
)
...
...
skiko/src/commonMain/kotlin/org/jetbrains/skia/svg/SVGLength.kt
View file @
c7e5032c
package
org.jetbrains.skia.svg
import
org.jetbrains.skia.impl.InteropPointer
import
org.jetbrains.skia.impl.withResult
class
SVGLength
(
val
value
:
Float
,
val
unit
:
SVGLengthUnit
)
{
companion
object
{
internal
fun
fromInterop
(
block
:
(
InteropPointer
)
->
Unit
)
=
withResult
(
IntArray
(
2
),
block
).
let
{
SVGLength
(
Float
.
fromBits
(
it
[
0
]),
it
[
1
])
}
}
internal
constructor
(
value
:
Float
,
unit
:
Int
)
:
this
(
value
,
SVGLengthUnit
.
values
()[
unit
])
...
...
skiko/src/commonMain/kotlin/org/jetbrains/skia/svg/SVGPreserveAspectRatio.kt
View file @
c7e5032c
package
org.jetbrains.skia.svg
import
org.jetbrains.skia.impl.InteropPointer
import
org.jetbrains.skia.impl.withResult
class
SVGPreserveAspectRatio
(
align
:
SVGPreserveAspectRatioAlign
,
scale
:
SVGPreserveAspectRatioScale
)
{
internal
val
_align
:
SVGPreserveAspectRatioAlign
internal
val
_scale
:
SVGPreserveAspectRatioScale
companion
object
{
internal
fun
fromInterop
(
block
:
(
InteropPointer
)
->
Unit
)
=
withResult
(
IntArray
(
2
),
block
).
let
{
SVGPreserveAspectRatio
(
it
[
0
],
it
[
1
])
}
}
internal
constructor
(
align
:
Int
,
scale
:
Int
)
:
this
(
SVGPreserveAspectRatioAlign
.
valueOf
(
align
),
SVGPreserveAspectRatioScale
.
values
()[
scale
]
...
...
skiko/src/commonMain/kotlin/org/jetbrains/skia/svg/SVGSVG.kt
View file @
c7e5032c
...
...
@@ -15,10 +15,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
var
x
:
SVGLength
get
()
=
try
{
Stats
.
onNativeCall
()
val
result
=
withResult
(
IntArray
(
2
))
{
SVGSVG_nGetX
(
_ptr
,
it
)
}
SVGLength
(
Float
.
fromBits
(
result
[
0
]),
result
[
1
])
SVGLength
.
fromInterop
{
SVGSVG_nGetX
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -32,10 +29,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
var
y
:
SVGLength
get
()
=
try
{
Stats
.
onNativeCall
()
val
result
=
withResult
(
IntArray
(
2
))
{
SVGSVG_nGetY
(
_ptr
,
it
)
}
SVGLength
(
Float
.
fromBits
(
result
[
0
]),
result
[
1
])
SVGLength
.
fromInterop
{
SVGSVG_nGetY
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -56,7 +50,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
var
width
:
SVGLength
get
()
=
try
{
Stats
.
onNativeCall
()
SVG
SVG_nGetWidth
(
_ptr
)
SVG
Length
.
fromInterop
{
SVGSVG_nGetWidth
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -70,7 +64,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
var
height
:
SVGLength
get
()
=
try
{
Stats
.
onNativeCall
()
SVG
SVG_nGetHeight
(
_ptr
)
SVG
Length
.
fromInterop
{
SVGSVG_nGetHeight
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -85,7 +79,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
var
preserveAspectRatio
:
SVGPreserveAspectRatio
get
()
=
try
{
Stats
.
onNativeCall
()
SVG
SVG_nGetPreserveAspectRatio
(
_ptr
)
SVG
PreserveAspectRatio
.
fromInterop
{
SVGSVG_nGetPreserveAspectRatio
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -99,7 +93,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
var
viewBox
:
Rect
?
get
()
=
try
{
Stats
.
onNativeCall
()
SVGSVG_nGetViewBox
(
_ptr
)
Rect
.
fromInteropPointerNullable
{
SVGSVG_nGetViewBox
(
_ptr
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -113,7 +107,7 @@ class SVGSVG internal constructor(ptr: NativePointer) : SVGContainer(ptr) {
fun
getIntrinsicSize
(
lc
:
SVGLengthContext
):
Point
{
return
try
{
Stats
.
onNativeCall
()
SVGSVG_nGetIntrinsicSize
(
_ptr
,
lc
.
width
,
lc
.
height
,
lc
.
dpi
)
Point
.
fromInteropPointer
{
SVGSVG_nGetIntrinsicSize
(
_ptr
,
lc
.
width
,
lc
.
height
,
lc
.
dpi
,
it
)
}
}
finally
{
reachabilityBarrier
(
this
)
}
...
...
@@ -127,19 +121,19 @@ private external fun SVGSVG_nGetX(ptr: NativePointer, result: InteropPointer)
private
external
fun
SVGSVG_nGetY
(
ptr
:
NativePointer
,
result
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGSVG__1nGetWidth"
)
private
external
fun
SVGSVG_nGetWidth
(
ptr
:
NativePointer
):
SVGLength
private
external
fun
SVGSVG_nGetWidth
(
ptr
:
NativePointer
,
result
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGSVG__1nGetHeight"
)
private
external
fun
SVGSVG_nGetHeight
(
ptr
:
NativePointer
):
SVGLength
private
external
fun
SVGSVG_nGetHeight
(
ptr
:
NativePointer
,
result
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGSVG__1nGetPreserveAspectRatio"
)
private
external
fun
SVGSVG_nGetPreserveAspectRatio
(
ptr
:
NativePointer
):
SVGPreserveAspectRatio
private
external
fun
SVGSVG_nGetPreserveAspectRatio
(
ptr
:
NativePointer
,
result
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGSVG__1nGetViewBox"
)
private
external
fun
SVGSVG_nGetViewBox
(
ptr
:
NativePointer
):
Rect
?
private
external
fun
SVGSVG_nGetViewBox
(
ptr
:
NativePointer
,
result
:
InteropPointer
):
Boolean
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGSVG__1nGetIntrinsicSize"
)
private
external
fun
SVGSVG_nGetIntrinsicSize
(
ptr
:
NativePointer
,
width
:
Float
,
height
:
Float
,
dpi
:
Float
):
Point
private
external
fun
SVGSVG_nGetIntrinsicSize
(
ptr
:
NativePointer
,
width
:
Float
,
height
:
Float
,
dpi
:
Float
,
result
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_svg_SVGSVG__1nSetX"
)
private
external
fun
SVGSVG_nSetX
(
ptr
:
NativePointer
,
value
:
Float
,
unit
:
Int
)
...
...
skiko/src/commonTest/kotlin/org/jetbrains/skia/SvgTest.kt
View file @
c7e5032c
package
org.jetbrains.skia
import
org.jetbrains.skia.svg.SVGDOM
import
org.jetbrains.skia.svg.SVGLengthContext
import
org.jetbrains.skia.svg.SVGLengthUnit
import
org.jetbrains.skia.svg.SVGTag
import
org.jetbrains.skia.svg.*
import
org.jetbrains.skia.tests.assertCloseEnough
import
org.jetbrains.skiko.KotlinBackend
import
org.jetbrains.skiko.kotlinBackend
import
kotlin.test.Test
import
kotlin.test.assertEquals
class
SvgTest
{
@Test
...
...
@@ -33,17 +32,17 @@ class SvgTest {
val
e
=
dom
.
root
!!
require
(
e
.
x
.
unit
==
SVGLengthUnit
.
NUMBER
)
require
(
e
.
y
.
unit
==
SVGLengthUnit
.
NUMBER
)
if
(
kotlinBackend
==
KotlinBackend
.
JVM
)
{
// TODO: disabled for other platforms until all methods implemented in JS/Native.
require
(
e
.
width
.
unit
==
SVGLengthUnit
.
NUMBER
)
require
(
e
.
height
.
unit
==
SVGLengthUnit
.
NUMBER
)
require
(
e
.
viewBox
==
null
)
require
(
e
.
tag
==
SVGTag
.
SVG
)
// e.viewBox = Rect(0f, 1f, 100f, 200f
)
// assert(e.viewBox!!.top == 1f)
require
(
e
.
getIntrinsicSize
(
SVGLengthContext
(
100f
,
100f
)).
x
==
300f
)
e
.
viewBox
=
Rect
.
makeXYWH
(
0f
,
1f
,
2f
,
3
f
)
require
(
e
.
viewBox
==
Rect
.
makeXYWH
(
0f
,
1f
,
2f
,
3f
)
)
}
require
(
e
.
width
.
unit
==
SVGLengthUnit
.
NUMBER
)
require
(
e
.
height
.
unit
==
SVGLengthUnit
.
NUMBER
)
require
(
e
.
viewBox
==
null
)
require
(
e
.
tag
==
SVGTag
.
SVG
)
e
.
viewBox
=
Rect
(
0f
,
1f
,
100f
,
200f
)
assertCloseEnough
(
Rect
(
0f
,
1f
,
100f
,
200f
),
e
.
viewBox
)
val
aspectRatio
=
SVGPreserveAspectRatio
(
SVGPreserveAspectRatioAlign
.
XMIN_YMIN
,
SVGPreserveAspectRatioScale
.
MEET
)
e
.
preserveAspectRatio
=
aspectRatio
assertEquals
(
aspectRatio
,
e
.
preserveAspectRatio
)
require
(
e
.
getIntrinsicSize
(
SVGLengthContext
(
100f
,
100f
)).
x
==
300
f
)
e
.
viewBox
=
Rect
.
makeXYWH
(
0f
,
1f
,
2f
,
3f
)
require
(
e
.
viewBox
==
Rect
.
makeXYWH
(
0f
,
1f
,
2f
,
3f
))
}
}
skiko/src/jvmMain/cpp/common/svg/SVGDOM.cc
View file @
c7e5032c
...
...
@@ -22,11 +22,11 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_svg_SVGDOMKt_SVGDOM_1
return
reinterpret_cast
<
jlong
>
(
root
);
}
extern
"C"
JNIEXPORT
jobject
JNICALL
Java_org_jetbrains_skia_svg_SVGDOMKt_SVGDOM_1nGetContainerSize
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
)
{
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGDOMKt_SVGDOM_1nGetContainerSize
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jfloatArray
dst
)
{
SkSVGDOM
*
instance
=
reinterpret_cast
<
SkSVGDOM
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
const
SkSize
&
size
=
instance
->
containerSize
();
return
skija
::
Point
::
make
(
env
,
size
.
fWidth
,
size
.
fHeigh
t
);
skija
::
Point
::
copyToInterop
(
env
,
{
size
.
fWidth
,
size
.
fHeight
},
ds
t
);
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGDOMKt_SVGDOM_1nSetContainerSize
...
...
skiko/src/jvmMain/cpp/common/svg/SVGSVG.cc
View file @
c7e5032c
...
...
@@ -7,50 +7,51 @@
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetX
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jintArray
jresult
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
auto
x
=
instance
->
getX
();
jint
result
[
2
]
=
{
rawBits
(
x
.
value
()),
(
jint
)
x
.
unit
()
};
env
->
SetIntArrayRegion
(
jresult
,
0
,
2
,
result
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
env
,
instance
->
getX
(),
jresult
);
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetY
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jintArray
jresult
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
auto
y
=
instance
->
getY
();
jint
result
[
2
]
=
{
rawBits
(
y
.
value
()),
(
jint
)
y
.
unit
()
};
env
->
SetIntArrayRegion
(
jresult
,
0
,
2
,
result
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
env
,
instance
->
getY
(),
jresult
);
}
extern
"C"
JNIEXPORT
jobject
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetWidth
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
)
{
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetWidth
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jintArray
jresult
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
return
skija
::
svg
::
SVGLength
::
toJava
(
env
,
instance
->
getWidth
()
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
env
,
instance
->
getWidth
(),
jresult
);
}
extern
"C"
JNIEXPORT
jobject
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetHeight
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
)
{
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetHeight
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jintArray
jresult
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
return
skija
::
svg
::
SVGLength
::
toJava
(
env
,
instance
->
getHeight
()
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
env
,
instance
->
getHeight
(),
jresult
);
}
extern
"C"
JNIEXPORT
jobject
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetPreserveAspectRatio
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
)
{
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetPreserveAspectRatio
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jintArray
jresult
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
return
skija
::
svg
::
SVGPreserveAspectRatio
::
toJava
(
env
,
instance
->
getPreserveAspectRatio
()
);
return
skija
::
svg
::
SVGPreserveAspectRatio
::
copyToInterop
(
env
,
instance
->
getPreserveAspectRatio
(),
jresult
);
}
extern
"C"
JNIEXPORT
j
object
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetViewBox
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
)
{
extern
"C"
JNIEXPORT
j
boolean
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetViewBox
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jfloatArray
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
SkTLazy
<
SkSVGViewBoxType
>
viewBox
=
instance
->
getViewBox
();
return
viewBox
.
isValid
()
?
skija
::
Rect
::
fromSkRect
(
env
,
*
viewBox
.
get
())
:
nullptr
;
if
(
viewBox
.
isValid
())
{
skija
::
Rect
::
copyToInterop
(
env
,
*
viewBox
.
get
(),
result
);
return
true
;
}
else
{
return
false
;
}
}
extern
"C"
JNIEXPORT
jobject
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetIntrinsicSize
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
float
width
,
float
height
,
float
dpi
)
{
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nGetIntrinsicSize
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
float
width
,
float
height
,
float
dpi
,
jfloatArray
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
SkSVGLengthContext
lc
({
width
,
height
},
dpi
);
SkSize
size
=
instance
->
intrinsicSize
(
lc
);
return
skija
::
Point
::
fromSkPoint
(
env
,
{
size
.
width
(),
size
.
height
()}
);
skija
::
Point
::
copyToInterop
(
env
,
{
size
.
width
(),
size
.
height
()},
result
);
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_svg_SVGSVGKt_SVGSVG_1nSetX
...
...
skiko/src/jvmMain/cpp/common/svg/interop.cc
View file @
c7e5032c
#include <jni.h>
#include "../interop.hh"
#include "interop.hh"
namespace
skija
{
...
...
@@ -20,6 +21,11 @@ namespace skija {
jobject
toJava
(
JNIEnv
*
env
,
SkSVGLength
length
)
{
return
env
->
NewObject
(
cls
,
ctor
,
length
.
value
(),
static_cast
<
jint
>
(
length
.
unit
()));
}
void
copyToInterop
(
JNIEnv
*
env
,
const
SkSVGLength
&
length
,
jintArray
dst
)
{
jint
result
[
2
]
=
{
rawBits
(
length
.
value
()),
static_cast
<
jint
>
(
length
.
unit
())
};
env
->
SetIntArrayRegion
(
dst
,
0
,
2
,
result
);
}
}
namespace
SVGPreserveAspectRatio
{
...
...
@@ -39,6 +45,11 @@ namespace skija {
jobject
toJava
(
JNIEnv
*
env
,
SkSVGPreserveAspectRatio
ratio
)
{
return
env
->
NewObject
(
cls
,
ctor
,
static_cast
<
jint
>
(
ratio
.
fAlign
),
static_cast
<
jint
>
(
ratio
.
fScale
));
}
void
copyToInterop
(
JNIEnv
*
env
,
const
SkSVGPreserveAspectRatio
&
aspectRatio
,
jintArray
dst
)
{
jint
data
[
2
]
{
static_cast
<
jint
>
(
aspectRatio
.
fAlign
),
static_cast
<
jint
>
(
aspectRatio
.
fScale
)
};
env
->
SetIntArrayRegion
(
dst
,
0
,
2
,
data
);
}
}
void
onLoad
(
JNIEnv
*
env
)
{
...
...
skiko/src/jvmMain/cpp/common/svg/interop.hh
View file @
c7e5032c
...
...
@@ -10,6 +10,7 @@ namespace skija {
void
onLoad
(
JNIEnv
*
env
);
void
onUnload
(
JNIEnv
*
env
);
jobject
toJava
(
JNIEnv
*
env
,
SkSVGLength
length
);
void
copyToInterop
(
JNIEnv
*
env
,
const
SkSVGLength
&
length
,
jintArray
dst
);
}
namespace
SVGPreserveAspectRatio
{
...
...
@@ -18,6 +19,7 @@ namespace skija {
void
onLoad
(
JNIEnv
*
env
);
void
onUnload
(
JNIEnv
*
env
);
jobject
toJava
(
JNIEnv
*
env
,
SkSVGPreserveAspectRatio
ratio
);
void
copyToInterop
(
JNIEnv
*
env
,
const
SkSVGPreserveAspectRatio
&
aspectRatio
,
jintArray
dst
);
}
void
onLoad
(
JNIEnv
*
env
);
...
...
skiko/src/nativeJsMain/cpp/common.h
View file @
c7e5032c
...
...
@@ -19,6 +19,7 @@
#include "SkShaper.h"
#include "SkString.h"
#include "SkSurfaceProps.h"
#include "SkSVGTypes.h"
#include "TextStyle.h"
#include "types.h"
...
...
@@ -93,6 +94,16 @@ namespace skija {
int
fromString
(
SkString
str
);
}
}
namespace
svg
{
namespace
SVGLength
{
void
copyToInterop
(
const
SkSVGLength
&
length
,
KInteropPointer
dst
);
}
namespace
SVGPreserveAspectRatio
{
void
copyToInterop
(
const
SkSVGPreserveAspectRatio
&
aspectRatio
,
KInteropPointer
dst
);
}
}
}
std
::
unique_ptr
<
SkMatrix
>
skMatrix
(
KFloat
*
matrixArray
);
...
...
skiko/src/nativeJsMain/cpp/common_interop.cc
View file @
c7e5032c
...
...
@@ -285,4 +285,22 @@ namespace skija {
}
}
}
namespace
svg
{
namespace
SVGLength
{
void
copyToInterop
(
const
SkSVGLength
&
length
,
KInteropPointer
dst
)
{
KInt
*
result
=
reinterpret_cast
<
KInt
*>
(
dst
);
result
[
0
]
=
rawBits
(
length
.
value
());
result
[
1
]
=
static_cast
<
KInt
>
(
length
.
unit
());
}
}
namespace
SVGPreserveAspectRatio
{
void
copyToInterop
(
const
SkSVGPreserveAspectRatio
&
aspectRatio
,
KInteropPointer
dst
)
{
KInt
*
result
=
reinterpret_cast
<
KInt
*>
(
dst
);
result
[
0
]
=
static_cast
<
KInt
>
(
aspectRatio
.
fAlign
);
result
[
1
]
=
static_cast
<
KInt
>
(
aspectRatio
.
fScale
);
}
}
}
}
skiko/src/nativeJsMain/cpp/svg/SVGDOM.cc
View file @
c7e5032c
...
...
@@ -24,21 +24,12 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_svg_SVGDOM__1nGetRoot
return
reinterpret_cast
<
KNativePointer
>
(
root
);
}
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_svg_SVGDOM__1nGetContainerSize
(
KNativePointer
ptr
)
{
TODO
(
"implement org_jetbrains_skia_svg_SVGDOM__1nGetContainerSize"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGDOM__1nGetContainerSize
(KNativePointer ptr) {
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGDOM__1nGetContainerSize
(
KNativePointer
ptr
,
KInteropPointer
dst
)
{
SkSVGDOM
*
instance
=
reinterpret_cast
<
SkSVGDOM
*>
((
ptr
));
const
SkSize
&
size
=
instance
->
containerSize
();
return skija::Point::make(env, size.fWidth, size.fHeigh
t);
skija
::
Point
::
copyToInterop
({
size
.
fWidth
,
size
.
fHeight
},
ds
t
);
}
#endif
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGDOM__1nSetContainerSize
(
KNativePointer
ptr
,
KFloat
width
,
KFloat
height
)
{
...
...
skiko/src/nativeJsMain/cpp/svg/SVGSVG.cc
View file @
c7e5032c
...
...
@@ -11,107 +11,51 @@ SKIKO_EXPORT KInt org_jetbrains_skia_svg_SVGSVG__1nGetTag
return
static_cast
<
KInt
>
(
instance
->
tag
());
}
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetX
(
KNativePointer
ptr
,
KInt
*
result
)
{
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetX
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
ptr
);
auto
x
=
instance
->
getX
();
result
[
0
]
=
rawBits
(
x
.
value
());
result
[
1
]
=
static_cast
<
KInt
>
(
x
.
unit
());
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
instance
->
getX
(),
result
);
}
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetY
(
KNativePointer
ptr
,
KInt
*
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
ptr
);
auto
y
=
instance
->
getY
();
result
[
0
]
=
rawBits
(
y
.
value
());
result
[
1
]
=
static_cast
<
KInt
>
(
y
.
unit
());
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGSVG__1nGetY
(KNativePointer ptr) {
SkSVGSVG* instance = reinterpret_cast<SkSVGSVG*>((ptr));
return skija::svg::SVGLength::toJava(env, instance->getY());
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetY
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
ptr
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
instance
->
getY
(),
result
);
}
#endif
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_svg_SVGSVG__1nGetWidth
(
KNativePointer
ptr
)
{
TODO
(
"implement org_jetbrains_skia_svg_SVGSVG__1nGetWidth"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGSVG__1nGetWidth
(KNativePointer ptr) {
SkSVGSVG* instance = reinterpret_cast<SkSVGSVG*>((ptr));
return skija::svg::SVGLength::toJava(env, instance->getWidth());
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetHeight
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
ptr
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
instance
->
getHeight
(),
result
);
}
#endif
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_svg_SVGSVG__1nGetHeight
(
KNativePointer
ptr
)
{
TODO
(
"implement org_jetbrains_skia_svg_SVGSVG__1nGetHeight"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGSVG__1nGetHeight
(KNativePointer ptr) {
SkSVGSVG* instance = reinterpret_cast<SkSVGSVG*>((ptr));
return skija::svg::SVGLength::toJava(env, instance->getHeight());
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetWidth
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
(
ptr
);
return
skija
::
svg
::
SVGLength
::
copyToInterop
(
instance
->
getWidth
(),
result
);
}
#endif
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_svg_SVGSVG__1nGetPreserveAspectRatio
(
KNativePointer
ptr
)
{
TODO
(
"implement org_jetbrains_skia_svg_SVGSVG__1nGetPreserveAspectRatio"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGSVG__1nGetPreserveAspectRatio
(KNativePointer ptr) {
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetPreserveAspectRatio
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
((
ptr
));
return skija::svg::SVGPreserveAspectRatio::
toJava(env, instance->getPreserveAspectRatio()
);
return
skija
::
svg
::
SVGPreserveAspectRatio
::
copyToInterop
(
instance
->
getPreserveAspectRatio
(),
result
);
}
#endif
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_svg_SVGSVG__1nGetViewBox
(
KNativePointer
ptr
)
{
TODO
(
"implement org_jetbrains_skia_svg_SVGSVG__1nGetViewBox"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGSVG__1nGetViewBox
(KNativePointer ptr) {
SKIKO_EXPORT
KBoolean
org_jetbrains_skia_svg_SVGSVG__1nGetViewBox
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
((
ptr
));
SkTLazy
<
SkSVGViewBoxType
>
viewBox
=
instance
->
getViewBox
();
return viewBox.isValid() ? skija::Rect::fromSkRect(env, *viewBox.get()) : nullptr;
if
(
viewBox
.
isValid
())
{
skija
::
Rect
::
copyToInterop
(
*
viewBox
.
get
(),
result
);
return
true
;
}
else
{
return
false
;
}
}
#endif
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_svg_SVGSVG__1nGetIntrinsicSize
(
KNativePointer
ptr
,
float
width
,
float
height
,
float
dpi
)
{
TODO
(
"implement org_jetbrains_skia_svg_SVGSVG__1nGetIntrinsicSize"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_svg_SVGSVG__1nGetIntrinsicSize
(KNativePointer ptr, float width, float height, float dpi) {
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nGetIntrinsicSize
(
KNativePointer
ptr
,
float
width
,
float
height
,
float
dpi
,
KInteropPointer
result
)
{
SkSVGSVG
*
instance
=
reinterpret_cast
<
SkSVGSVG
*>
((
ptr
));
SkSVGLengthContext
lc
({
width
,
height
},
dpi
);
SkSize
size
=
instance
->
intrinsicSize
(
lc
);
return skija::Point::fromSkPoint(env, {size.width(), size.height()}
);
skija
::
Point
::
copyToInterop
({
size
.
width
(),
size
.
height
()},
result
);
}
#endif
SKIKO_EXPORT
void
org_jetbrains_skia_svg_SVGSVG__1nSetX
(
KNativePointer
ptr
,
float
value
,
int
unit
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment