Commit 4158afd8 authored by Roman Sedaikin's avatar Roman Sedaikin

Moved noerasebackground property to Library.load

parents 7bcf714c 5e28f92a
......@@ -10,6 +10,10 @@ import org.jetbrains.skiko.SkiaRenderer
import java.awt.event.MouseMotionAdapter
import kotlin.math.cos
import kotlin.math.sin
import org.jetbrains.skija.paragraph.FontCollection
import org.jetbrains.skija.paragraph.ParagraphBuilder
import org.jetbrains.skija.paragraph.ParagraphStyle
import org.jetbrains.skija.paragraph.TextStyle
fun main(args: Array<String>) {
createWindow("First window");
......@@ -117,4 +121,15 @@ fun displayScene(renderer: Renderer, width: Int, height: Int, xpos: Int, ypos: I
}
val text = "${state.text} ${state.frame++}!"
canvas.drawString(text, xpos.toFloat(), ypos.toFloat(), renderer.font, renderer.paint)
val fontCollection = FontCollection()
.setDefaultFontManager(FontMgr.getDefault())
val style = ParagraphStyle()
val paragraph = ParagraphBuilder(style, fontCollection)
.pushStyle(TextStyle().setColor(0xFF000000.toInt()))
.addText("Text")
.popStyle()
.build()
paragraph.layout(Float.POSITIVE_INFINITY)
paragraph.paint(canvas, 0f, 0f)
}
......@@ -13,7 +13,7 @@ version = when {
else -> project.property("deploy.version") as String
}
val skiaDir = System.getenv("SKIA_DIR") ?: "/Users/igotti/compose/skija/third_party/skia"
val skiaDir = System.getenv("SKIA_DIR") ?: System.getProperty("skia.dir") ?: "PLEASE_SET_SKIA_DIR"
val hostOs = System.getProperty("os.name")
val target = when {
hostOs == "Mac OS X" -> "macos"
......@@ -249,7 +249,12 @@ val skikoJvmJar: Provider<Jar> by tasks.registering(Jar::class) {
val skikoJvmRuntimeJar by project.tasks.registering(Jar::class) {
archiveBaseName.set("skiko-$target")
from(skikoJvmJar.map { zipTree(it.archiveFile) })
from(project.tasks.named("linkRelease${target.capitalize()}").map { it.outputs.files.filter { it.isFile }})
from(project.tasks.named("linkRelease${target.capitalize()}").map {
it.outputs.files.filter { it.isFile }
})
if (target == "windows") {
from(files("$skiaDir/out/Release-x64/icudtl.dat"))
}
}
project.tasks.register<JavaExec>("run") {
......
......@@ -3,7 +3,6 @@ package org.jetbrains.skiko
import java.io.File
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.util.*
// based on https://github.com/JetBrains/skija/blob/bc6e0531021e4ff839c07196e0336d6456ed7520/src/main/java/org/jetbrains/skija/Library.java
object Library {
......@@ -16,18 +15,30 @@ object Library {
val libFileName = System.mapLibraryName(name)
val url = Library::class.java.getResource(resourcePath + libFileName)
val tempRoot = File(System.getProperty("java.io.tmpdir"))
val tempDir = tempRoot.resolve("skiko_" + System.nanoTime()).apply { mkdirs() }
val libFile = when {
url == null -> error("Library $libFileName is not found in $resourcePath")
url.protocol == "file" -> File(url.toURI())
else -> url.openStream().use { input ->
val tempRoot = File(System.getProperty("java.io.tmpdir"))
val tempDir = tempRoot.resolve("skiko_" + System.nanoTime()).apply { mkdirs() }
File(tempDir, libFileName).also {
it.deleteOnExit()
Files.copy(input, it.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
}
}
val loadIcu = System.getProperty("os.name").toLowerCase().startsWith("win")
val icuData = "icudtl.dat"
if (loadIcu) {
val icuUrl = Library::class.java.getResource(resourcePath + icuData)
icuUrl.openStream().use { input ->
File(tempDir, icuData).also {
it.deleteOnExit()
Files.copy(input, it.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
}
}
System.load(libFile.absolutePath)
loaded = true
......
diff --git a/include/private/SkPathRef.h b/include/private/SkPathRef.h
index f9533d7261..9c178fb69f 100644
--- a/include/private/SkPathRef.h
+++ b/include/private/SkPathRef.h
@@ -8,6 +8,8 @@
#ifndef SkPathRef_DEFINED
#define SkPathRef_DEFINED
+#include <tuple>
+
#include "include/core/SkMatrix.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRRect.h"
diff --git a/third_party/icu/SkLoadICU.cpp b/third_party/icu/SkLoadICU.cpp
index ac7ba0c15d..b41af4e85a 100644
--- a/third_party/icu/SkLoadICU.cpp
+++ b/third_party/icu/SkLoadICU.cpp
@@ -68,6 +68,16 @@ static bool init_icu(void* addr) {
return true;
}
+static std::string library_directory() {
+ HMODULE hModule = NULL;
+ GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ reinterpret_cast<LPCSTR>(&library_directory), &hModule);
+ char path[MAX_PATH];
+ GetModuleFileNameA(hModule, path, MAX_PATH);
+ const char* end = strrchr(path, '\\');
+ return end ? std::string(path, end - path) : std::string();
+}
+
static std::string executable_directory() {
HMODULE hModule = GetModuleHandleA(NULL);
char path[MAX_PATH];
@@ -76,17 +86,21 @@ static std::string executable_directory() {
return end ? std::string(path, end - path) : std::string();
}
+static bool load_from(const std::string& dir) {
+ auto sPath = dir + "\\icudtl.dat";
+ if (void* addr = win_mmap(sPath.c_str())) {
+ if (init_icu(addr)) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool SkLoadICU() {
static bool good = false;
static std::once_flag flag;
std::call_once(flag, []() {
- std::string sPath = executable_directory();
- sPath += "\\icudtl.dat";
- if (void* addr = win_mmap(sPath.c_str())) {
- if (init_icu(addr)) {
- good = true;
- }
- }
+ good = load_from(executable_directory()) || load_from(library_directory());
});
return good;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment