-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
114 changed files
with
10,053 additions
and
10,056 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
324 changes: 162 additions & 162 deletions
324
...ain/java/org/freedesktop/cairo/Cairo.java → ...ain/java/org/freedesktop/cairo/Cairo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,162 +1,162 @@ | ||
package org.freedesktop.cairo; | ||
|
||
import io.github.jwharm.javagi.interop.Interop; | ||
import io.github.jwharm.javagi.interop.LibLoad; | ||
import io.github.jwharm.javagi.interop.Platform; | ||
|
||
import java.lang.foreign.FunctionDescriptor; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.lang.invoke.MethodHandle; | ||
|
||
/** | ||
* This class contains global declarations that do not belong in a specific | ||
* cairo class definition. | ||
*/ | ||
public final class Cairo { | ||
|
||
static { | ||
switch (Platform.getRuntimePlatform()) { | ||
case "linux" -> io.github.jwharm.javagi.interop.LibLoad.loadLibrary("libcairo.so.2"); | ||
case "windows" -> io.github.jwharm.javagi.interop.LibLoad.loadLibrary("cairo-2.dll"); | ||
case "macos" -> LibLoad.loadLibrary("libcairo.2.dylib"); | ||
} | ||
} | ||
|
||
/** | ||
* Ensures the class initializer has loaded the cairo library. | ||
*/ | ||
public static void ensureInitialized() { | ||
} | ||
|
||
// Prohibit instantiation | ||
private Cairo() { | ||
} | ||
|
||
/** | ||
* encodes the given cairo version into an integer. The numbers returned by | ||
* {@link #version()} are encoded in the same way. Two encoded | ||
* version numbers can be compared as integers. The encoding ensures that later | ||
* versions compare greater than earlier versions. | ||
* | ||
* @param major the major component of the version number | ||
* @param minor the minor component of the version number | ||
* @param micro the micro component of the version number | ||
* @return the encoded version. | ||
* @since 1.0 | ||
*/ | ||
public static int versionEncode(int major, int minor, int micro) { | ||
return (major * 10000) + (minor * 100) + micro; | ||
} | ||
|
||
/** | ||
* Encodes the given cairo version into a string. The numbers returned by | ||
* {@link #versionString()} are encoded in the same way. | ||
* | ||
* @param major the major component of the version number | ||
* @param minor the minor component of the version number | ||
* @param micro the micro component of the version number | ||
* @return a string literal containing the version. | ||
* @since 1.8 | ||
*/ | ||
public static String versionStringize(int major, int minor, int micro) { | ||
return major + "." + minor + "." + micro; | ||
} | ||
|
||
/** | ||
* Returns the version of the cairo library encoded in a single integer. The | ||
* encoding ensures that later versions compare greater than earlier versions. | ||
* <p> | ||
* A run-time comparison to check that cairo's version is greater than or equal | ||
* to version X.Y.Z could be performed as follows: | ||
* | ||
* <pre> | ||
* if (Cairo.version() >= versionEncode(X,Y,Z)) {...} | ||
* </pre> | ||
* | ||
* @return the encoded version. | ||
* @see #versionString() | ||
* @since 1.0 | ||
*/ | ||
public static int version() { | ||
try { | ||
return (int) cairo_version.invoke(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static final MethodHandle cairo_version = Interop.downcallHandle("cairo_version", | ||
FunctionDescriptor.of(ValueLayout.JAVA_INT)); | ||
|
||
/** | ||
* Returns the version of the cairo library as a human-readable string of the | ||
* form "X.Y.Z". | ||
* <p> | ||
* Cairo has a three-part version number scheme. In this scheme, we use even vs. | ||
* odd numbers to distinguish fixed points in the software vs. in-progress | ||
* development, (such as from git instead of a tar file, or as a "snapshot" tar | ||
* file as opposed to a "release" tar file). | ||
* | ||
* <pre> | ||
* _____ Major. Always 1, until we invent a new scheme. | ||
* / ___ Minor. Even/Odd = Release/Snapshot (tar files) or Branch/Head (git) | ||
* | / _ Micro. Even/Odd = Tar-file/git | ||
* | | / | ||
* 1.0.0 | ||
* </pre> | ||
* | ||
* Here are a few examples of versions that one might see. | ||
* | ||
* <pre> | ||
* Releases | ||
* -------- | ||
* 1.0.0 - A major release | ||
* 1.0.2 - A subsequent maintenance release | ||
* 1.2.0 - Another major release | ||
* | ||
* Snapshots | ||
* --------- | ||
* 1.1.2 - A snapshot (working toward the 1.2.0 release) | ||
* | ||
* In-progress development (eg. from git) | ||
* -------------------------------------- | ||
* 1.0.1 - Development on a maintenance branch (toward 1.0.2 release) | ||
* 1.1.1 - Development on head (toward 1.1.2 snapshot and 1.2.0 release) | ||
* </pre> | ||
* | ||
* <strong>Compatibility</strong> | ||
* <p> | ||
* The API/ABI compatibility guarantees for various versions are as follows. | ||
* First, let's assume some cairo-using application code that is successfully | ||
* using the API/ABI "from" one version of cairo. Then let's ask the question | ||
* whether this same code can be moved "to" the API/ABI of another version of | ||
* cairo. Moving from a release to any later version (release, snapshot, | ||
* development) is always guaranteed to provide compatibility. Moving from a | ||
* snapshot to any later version is not guaranteed to provide compatibility, | ||
* since snapshots may introduce new API that ends up being removed before the | ||
* next release. Moving from an in-development version (odd micro component) to | ||
* any later version is not guaranteed to provide compatibility. In fact, | ||
* there's not even a guarantee that the code will even continue to work with | ||
* the same in-development version number. This is because these numbers don't | ||
* correspond to any fixed state of the software, but rather the many states | ||
* between snapshots and releases. | ||
* | ||
* @return a string containing the version. | ||
* @since 1.0 | ||
*/ | ||
public static String versionString() { | ||
try { | ||
MemorySegment result = (MemorySegment) cairo_version_string.invoke(); | ||
if (MemorySegment.NULL.equals(result)) { | ||
return null; | ||
} | ||
return result.getUtf8String(0); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static final MethodHandle cairo_version_string = Interop.downcallHandle("cairo_version_string", | ||
FunctionDescriptor.of(ValueLayout.ADDRESS.asUnbounded())); | ||
} | ||
package org.freedesktop.cairo; | ||
|
||
import io.github.jwharm.javagi.interop.Interop; | ||
import io.github.jwharm.javagi.interop.LibLoad; | ||
import io.github.jwharm.javagi.interop.Platform; | ||
|
||
import java.lang.foreign.FunctionDescriptor; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.lang.invoke.MethodHandle; | ||
|
||
/** | ||
* This class contains global declarations that do not belong in a specific | ||
* cairo class definition. | ||
*/ | ||
public final class Cairo { | ||
|
||
static { | ||
switch (Platform.getRuntimePlatform()) { | ||
case "linux" -> io.github.jwharm.javagi.interop.LibLoad.loadLibrary("libcairo.so.2"); | ||
case "windows" -> io.github.jwharm.javagi.interop.LibLoad.loadLibrary("cairo-2.dll"); | ||
case "macos" -> LibLoad.loadLibrary("libcairo.2.dylib"); | ||
} | ||
} | ||
|
||
/** | ||
* Ensures the class initializer has loaded the cairo library. | ||
*/ | ||
public static void ensureInitialized() { | ||
} | ||
|
||
// Prohibit instantiation | ||
private Cairo() { | ||
} | ||
|
||
/** | ||
* encodes the given cairo version into an integer. The numbers returned by | ||
* {@link #version()} are encoded in the same way. Two encoded | ||
* version numbers can be compared as integers. The encoding ensures that later | ||
* versions compare greater than earlier versions. | ||
* | ||
* @param major the major component of the version number | ||
* @param minor the minor component of the version number | ||
* @param micro the micro component of the version number | ||
* @return the encoded version. | ||
* @since 1.0 | ||
*/ | ||
public static int versionEncode(int major, int minor, int micro) { | ||
return (major * 10000) + (minor * 100) + micro; | ||
} | ||
|
||
/** | ||
* Encodes the given cairo version into a string. The numbers returned by | ||
* {@link #versionString()} are encoded in the same way. | ||
* | ||
* @param major the major component of the version number | ||
* @param minor the minor component of the version number | ||
* @param micro the micro component of the version number | ||
* @return a string literal containing the version. | ||
* @since 1.8 | ||
*/ | ||
public static String versionStringize(int major, int minor, int micro) { | ||
return major + "." + minor + "." + micro; | ||
} | ||
|
||
/** | ||
* Returns the version of the cairo library encoded in a single integer. The | ||
* encoding ensures that later versions compare greater than earlier versions. | ||
* <p> | ||
* A run-time comparison to check that cairo's version is greater than or equal | ||
* to version X.Y.Z could be performed as follows: | ||
* | ||
* <pre> | ||
* if (Cairo.version() >= versionEncode(X,Y,Z)) {...} | ||
* </pre> | ||
* | ||
* @return the encoded version. | ||
* @see #versionString() | ||
* @since 1.0 | ||
*/ | ||
public static int version() { | ||
try { | ||
return (int) cairo_version.invoke(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static final MethodHandle cairo_version = Interop.downcallHandle("cairo_version", | ||
FunctionDescriptor.of(ValueLayout.JAVA_INT)); | ||
|
||
/** | ||
* Returns the version of the cairo library as a human-readable string of the | ||
* form "X.Y.Z". | ||
* <p> | ||
* Cairo has a three-part version number scheme. In this scheme, we use even vs. | ||
* odd numbers to distinguish fixed points in the software vs. in-progress | ||
* development, (such as from git instead of a tar file, or as a "snapshot" tar | ||
* file as opposed to a "release" tar file). | ||
* | ||
* <pre> | ||
* _____ Major. Always 1, until we invent a new scheme. | ||
* / ___ Minor. Even/Odd = Release/Snapshot (tar files) or Branch/Head (git) | ||
* | / _ Micro. Even/Odd = Tar-file/git | ||
* | | / | ||
* 1.0.0 | ||
* </pre> | ||
* | ||
* Here are a few examples of versions that one might see. | ||
* | ||
* <pre> | ||
* Releases | ||
* -------- | ||
* 1.0.0 - A major release | ||
* 1.0.2 - A subsequent maintenance release | ||
* 1.2.0 - Another major release | ||
* | ||
* Snapshots | ||
* --------- | ||
* 1.1.2 - A snapshot (working toward the 1.2.0 release) | ||
* | ||
* In-progress development (eg. from git) | ||
* -------------------------------------- | ||
* 1.0.1 - Development on a maintenance branch (toward 1.0.2 release) | ||
* 1.1.1 - Development on head (toward 1.1.2 snapshot and 1.2.0 release) | ||
* </pre> | ||
* | ||
* <strong>Compatibility</strong> | ||
* <p> | ||
* The API/ABI compatibility guarantees for various versions are as follows. | ||
* First, let's assume some cairo-using application code that is successfully | ||
* using the API/ABI "from" one version of cairo. Then let's ask the question | ||
* whether this same code can be moved "to" the API/ABI of another version of | ||
* cairo. Moving from a release to any later version (release, snapshot, | ||
* development) is always guaranteed to provide compatibility. Moving from a | ||
* snapshot to any later version is not guaranteed to provide compatibility, | ||
* since snapshots may introduce new API that ends up being removed before the | ||
* next release. Moving from an in-development version (odd micro component) to | ||
* any later version is not guaranteed to provide compatibility. In fact, | ||
* there's not even a guarantee that the code will even continue to work with | ||
* the same in-development version number. This is because these numbers don't | ||
* correspond to any fixed state of the software, but rather the many states | ||
* between snapshots and releases. | ||
* | ||
* @return a string containing the version. | ||
* @since 1.0 | ||
*/ | ||
public static String versionString() { | ||
try { | ||
MemorySegment result = (MemorySegment) cairo_version_string.invoke(); | ||
if (MemorySegment.NULL.equals(result)) { | ||
return null; | ||
} | ||
return result.getUtf8String(0); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static final MethodHandle cairo_version_string = Interop.downcallHandle("cairo_version_string", | ||
FunctionDescriptor.of(ValueLayout.ADDRESS.asUnbounded())); | ||
} |
22 changes: 11 additions & 11 deletions
22
...in/java/org/freedesktop/cairo/Circle.java → ...in/java/org/freedesktop/cairo/Circle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package org.freedesktop.cairo; | ||
|
||
/** | ||
* A circle defined by the x and y coordinates of the center and the radius. | ||
* | ||
* @param x x coordinate of the center | ||
* @param y y coordinate of the center | ||
* @param radius radius of the circle | ||
*/ | ||
public record Circle(double x, double y, double radius) { | ||
} | ||
package org.freedesktop.cairo; | ||
|
||
/** | ||
* A circle defined by the x and y coordinates of the center and the radius. | ||
* | ||
* @param x x coordinate of the center | ||
* @param y y coordinate of the center | ||
* @param radius radius of the circle | ||
*/ | ||
public record Circle(double x, double y, double radius) { | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.