Skip to content

Commit

Permalink
Proof of concept of switching to Skiko
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-grouchnikov committed Jan 21, 2022
1 parent 6a361b6 commit aa8eab2
Show file tree
Hide file tree
Showing 11 changed files with 3,280 additions and 3,177 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea/**

target/**
103 changes: 78 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<kotlin.version>1.6.10</kotlin.version>
</properties>

<name>SkijaGraphics2D</name>
Expand Down Expand Up @@ -50,27 +51,18 @@
<activation>
<os><family>mac</family></os>
</activation>
<properties>
<skija.platform>macos-x64</skija.platform>
</properties>
</profile>
<profile>
<id>build-linux</id>
<activation>
<os><family>linux</family></os>
</activation>
<properties>
<skija.platform>linux</skija.platform>
</properties>
</profile>
<profile>
<id>build-windows</id>
<activation>
<os><family>windows</family></os>
</activation>
<properties>
<skija.platform>windows</skija.platform>
</properties>
</profile>

<profile>
Expand Down Expand Up @@ -142,16 +134,21 @@

<repositories>
<repository>
<id>space-maven</id>
<url>https://packages.jetbrains.team/maven/p/skija/maven</url>
<id>space-maven-compose</id>
<url>https://maven.pkg.jetbrains.space/public/p/compose/dev</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>io.github.humbleui</groupId>
<artifactId>skija-${skija.platform}</artifactId>
<version>0.98.1</version>
<groupId>org.jetbrains.skiko</groupId>
<artifactId>skiko-jvm</artifactId>
<version>0.6.6</version>
</dependency>
<dependency>
<groupId>org.jetbrains.skiko</groupId>
<artifactId>skiko-jvm-runtime-macos-x64</artifactId>
<version>0.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -175,6 +172,22 @@
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -192,17 +205,6 @@
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgument>-Xlint:unchecked</compilerArgument>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -244,6 +246,57 @@
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgument>-Xlint:unchecked</compilerArgument>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,74 +32,66 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package org.jfree.skija

package org.jfree.skija;

import io.github.humbleui.skija.FontMetrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import org.jetbrains.skia.*
import org.slf4j.LoggerFactory
import java.awt.Font
import java.awt.FontMetrics

/**
* Returns font metrics.
*/
public class SkijaFontMetrics extends java.awt.FontMetrics {

private static final Logger LOGGER = LoggerFactory.getLogger(SkijaFontMetrics.class);
class SkijaFontMetrics(skijaFont: org.jetbrains.skia.Font?, awtFont: Font?) :
FontMetrics(awtFont) {
/** Skija font. */
private val skijaFont: org.jetbrains.skia.Font?

/** Skija font. */
private io.github.humbleui.skija.Font skijaFont;

/** Skija font metrics. */
private FontMetrics metrics;
/** Skija font metrics. */
private val metrics: org.jetbrains.skia.FontMetrics

/**
* Creates a new instance.
*
* @param skijaFont the Skija font ({@code null} not permitted).
* @param awtFont the AWT font ({@code null} not permitted).
* @param skijaFont the Skija font (`null` not permitted).
* @param awtFont the AWT font (`null` not permitted).
*/
public SkijaFontMetrics(io.github.humbleui.skija.Font skijaFont, Font awtFont) {
super(awtFont);
this.metrics = skijaFont.getMetrics();
this.skijaFont = skijaFont;
init {
metrics = skijaFont!!.metrics
this.skijaFont = skijaFont
}

/**
* Returns the leading.
*
* @return The leading.
*/
@Override
public int getLeading() {
int result = (int) this.metrics.getLeading();
LOGGER.debug("getLeading() -> {}", result);
return result;
override fun getLeading(): Int {
val result = metrics.leading.toInt()
LOGGER.debug("getLeading() -> {}", result)
return result
}

/**
* Returns the ascent for the font.
*
* @return The ascent.
*/
@Override
public int getAscent() {
int result = (int) -this.metrics.getAscent();
LOGGER.debug("getAscent() -> {}", result);
return result;
override fun getAscent(): Int {
val result = -metrics.ascent.toInt()
LOGGER.debug("getAscent() -> {}", result)
return result
}

/**
* Returns the descent for the font.
*
* @return The descent.
*/
@Override
public int getDescent() {
int result = (int) this.metrics.getDescent();
LOGGER.debug("getDescent() -> {}", result);
return result;
override fun getDescent(): Int {
val result = metrics.descent.toInt()
LOGGER.debug("getDescent() -> {}", result)
return result
}

/**
Expand All @@ -109,11 +101,10 @@ public int getDescent() {
*
* @return The width.
*/
@Override
public int charWidth(char ch) {
int result = (int) this.skijaFont.measureTextWidth(Character.toString(ch));
LOGGER.debug("charWidth({}) -> {}", ch, result);
return result;
override fun charWidth(ch: Char): Int {
val result = skijaFont!!.measureTextWidth(Character.toString(ch)).toInt()
LOGGER.debug("charWidth({}) -> {}", ch, result)
return result
}

/**
Expand All @@ -125,10 +116,13 @@ public int charWidth(char ch) {
*
* @return The width of the character sequence.
*/
@Override
public int charsWidth(char[] data, int off, int len) {
int result = (int) this.skijaFont.measureTextWidth(new String(data, off, len));
LOGGER.debug("charsWidth({}, {}, {}) -> {}", data, off, len, result);
return result;
override fun charsWidth(data: CharArray, off: Int, len: Int): Int {
val result = skijaFont!!.measureTextWidth(String(data, off, len)).toInt()
LOGGER.debug("charsWidth({}, {}, {}) -> {}", data, off, len, result)
return result
}

companion object {
private val LOGGER = LoggerFactory.getLogger(SkijaFontMetrics::class.java)
}
}
}
Loading

0 comments on commit aa8eab2

Please sign in to comment.