Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for glyph index based msdfgen-ext APIs #1002

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 3 additions & 70 deletions doc/notes/latest.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,13 @@
### 3.3.4

_Release 2024 Jul 17_
### 3.3.5

This build includes the following changes:

#### Bindings

- Added [msdfgen](https://github.com/Chlumsky/msdfgen) bindings.
- Assimp: Updated to 5.4.2 (up from 5.2.5)
- bgfx: Updated to API version 128 (up from 122)
* Windows: support for the Direct3D 9 backend has been dropped.
- CUDA: Updated to 12.5.1 (up from 12.1.0)
- FMOD: Updated to 2.02.21 (up from 2.02.16)
- glfw: Updated to 3.4 (up from 3.3.8)
* Added `GLFW_UNLIMITED_MOUSE_BUTTONS`, `GLFW_SCALE_FRAMEBUFFER`, `GLFW_WIN32_SHOWDEFAULT`.
* Added `glfwGetWindowTitle`, `glfwGetCocoaView`.
- glfw: Added experimental support for IME. (#946)
* Added `GLFW_SOFT_FULLSCREEN`, `GLFW_IME`, `GLFW_MANAGE_PREEDIT_CANDIDATE` and `GLFW_X11_ONTHESPOT`.
* Added `glfwGetPreeditCursorRectangle`, `glfwSetPreeditCursorRectangle`, `glfwResetPreeditText`, `glfwGetPreeditCandidate`.
* Added `glfwSetPreeditCallback`, `glfwSetIMEStatusCallback`, `glfwSetPreeditCandidateCallback`.
- harfbuzz: Updated to 9.0.0 (up from 8.2.0)
- hwloc: Updated to 2.11.1 (up from 2.9.3)
- KTX: Updated to 4.3.2 (up from 4.3.0-alpha3)
- libffi: Updated to 3.4.6 (up from 3.4.4)
- liburing: Updated to 2.6 (up from 2.4)
- lmdb: Updated to 0.9.32 (up from 0.9.31)
- LLVM/Clang: Updated to 18.1.7 (up from 16.0.0)
- meshoptimizer: Updated to 0.21 (up from 0.19)
- NativeFileDialog: Update to 1.2.0 (up from 1.1.0)
- Nuklear: Updated to 4.12.1 (up from 4.10.6)
- OpenVR: Updated to 2.5.1 (up from 1.26.7)
* Added support for Linux ARM64
- OpenXR: Updated to 1.1.38 (up from 1.0.29)
- Opus: Updated to 1.5.2 (up from 1.4.0)
- rpmalloc: Updated to 1.4.5 (up from 1.4.4)
- Shaderc: Updated to 2024.2 (up from 2023.6)
- SPIRV-Cross: Updated to 0.61.0 (up from 0.57.0)
- stb
* Updated `stb_image` to 2.30 (up from 2.28)
* Updated `stb_image_resize` to 2.09 (up from 0.97)
- tinyexr: Updated to 1.0.8 (up from 1.0.7)
- tinyfiledialogs: Updated to 3.18.1 (up from 3.13.3)
- vma: Updated to 3.1.0 (up from 3.0.1)
- Vulkan: Updated to 1.3.289 (up from 1.3.264)
* Includes MoltenVK 1.2.10 (up from 1.2.5)
- Yoga: Updated to 3.1.0 (up from 2.0.0)
- Zstd: Updated to 1.5.6 (up from 1.5.5)
- Added support for glyph index based msdfgen-ext APIs

#### Improvements

- FreeBSD: Added support for the FreeBSD operating system, x64 architecture. (#421)
* Maven classifier: `freebsd`
- Linux: Added support for the PowerPC 64 LE architecture. (#495)
* Maven classifier: `linux-ppc64le`
- Linux: Added support for the RISC-V 64 architecture. (#890)
* Maven classifier: `linux-riscv64`
- Linux: ARM/PowerPC/RISC-V shared libraries are now built with GCC 11 (up from GCC 7).
- Windows: Shared libraries are now built with Clang/LLVM (clang-cl toolset) when possible.
- Vulkan: Made `VkMemoryRequirements` mutable for the `vmaAllocateMemory(Pages)` functions. (#937)

#### Fixes

- Core: Fixed callback wrapper memory leak with the CHM closure registry. (#927)
- Core: The `SharedLibraryLoader` will now always test if `System::load` works before choosing the extract path. (#987)
- bgfx: Fixed `bgfx_is_frame_buffer_valid` to accept `BGFXAttachment.Buffer`. (#993)
- JAWT: Fixed `JAWT_MACOSX_USE_CALAYER` value.
- LLVM: Fixed `LLVMGetBufferStart` to return `ByteBuffer` instead of `String`. (#934)
- LLVM: Fixed `LookupIntrinsicID` to return `unsigned` instead of `void`. (#950)
- Nuklear: Fixed auto-sizing of `nk_stroke_polyline`, `nk_stroke_polygon`, `nk_fill_polygon` buffers. (#978)
- tinyfd: The `aDefaultPath` parameter of `tinyfd_selectFolderDialog` is now nullable. (#922)

#### Breaking Changes

- Linux: ARM/PowerPC/RISC-V shared libraries now require GLIBC version 2.35 (up from 2.27)
- macOS: LWJGL now requires macOS 10.11/El Capitan or later (up from 10.9/Mavericks)
- meshoptimizer: Fixed autosizing issues. (#981)
* For consistency across the API, auto-sizing of some parameters was removed and the corresponding count parameters were made explicit.
* Auto-sizing is now always based on input parameters, the destination buffers are only checked for enough capacity.
- stb: `stb_image_resize2.h` replaced `stb_image_resize.h` with a new API.
#### Breaking Changes
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_util_msdfgen_MSDFGenExt_nmsdf_1ft_1font_1l
return (jint)msdf_ft_font_load_glyph(font, (unsigned)cp, coordinateScaling, shape);
}

JNIEXPORT jint JNICALL Java_org_lwjgl_util_msdfgen_MSDFGenExt_nmsdf_1ft_1font_1load_1glyph_1by_1index(JNIEnv *__env, jclass clazz, jlong fontAddress, jint index, jint coordinateScaling, jlong shapeAddress) {
msdf_ft_font_handle font = (msdf_ft_font_handle)(uintptr_t)fontAddress;
msdf_shape_handle *shape = (msdf_shape_handle *)(uintptr_t)shapeAddress;
UNUSED_PARAMS(__env, clazz)
return (jint)msdf_ft_font_load_glyph_by_index(font, (unsigned)index, coordinateScaling, shape);
}

JNIEXPORT jint JNICALL Java_org_lwjgl_util_msdfgen_MSDFGenExt_nmsdf_1ft_1font_1get_1glyph_1index(JNIEnv *__env, jclass clazz, jlong fontAddress, jint cp, jlong indexAddress) {
msdf_ft_font_handle font = (msdf_ft_font_handle)(uintptr_t)fontAddress;
unsigned *index = (unsigned *)(uintptr_t)indexAddress;
UNUSED_PARAMS(__env, clazz)
return (jint)msdf_ft_font_get_glyph_index(font, (unsigned)cp, index);
}

JNIEXPORT jint JNICALL Java_org_lwjgl_util_msdfgen_MSDFGenExt_nmsdf_1ft_1font_1get_1kerning(JNIEnv *__env, jclass clazz, jlong fontAddress, jint cp1, jint cp2, jlong kerningAddress) {
msdf_ft_font_handle font = (msdf_ft_font_handle)(uintptr_t)fontAddress;
double *kerning = (double *)(uintptr_t)kerningAddress;
UNUSED_PARAMS(__env, clazz)
return (jint)msdf_ft_font_get_kerning(font, (unsigned)cp1, (unsigned)cp2, kerning);
}

JNIEXPORT jint JNICALL Java_org_lwjgl_util_msdfgen_MSDFGenExt_nmsdf_1ft_1font_1get_1kerning_1by_1index(JNIEnv *__env, jclass clazz, jlong fontAddress, jint index1, jint index2, jlong kerningAddress) {
msdf_ft_font_handle font = (msdf_ft_font_handle)(uintptr_t)fontAddress;
double *kerning = (double *)(uintptr_t)kerningAddress;
UNUSED_PARAMS(__env, clazz)
return (jint)msdf_ft_font_get_kerning_by_index(font, (unsigned)index1, (unsigned)index2, kerning);
}

JNIEXPORT void JNICALL Java_org_lwjgl_util_msdfgen_MSDFGenExt_nmsdf_1ft_1font_1destroy(JNIEnv *__env, jclass clazz, jlong fontAddress) {
msdf_ft_font_handle font = (msdf_ft_font_handle)(uintptr_t)fontAddress;
UNUSED_PARAMS(__env, clazz)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,99 @@ public static int msdf_ft_font_load_glyph(@NativeType("msdf_ft_font_handle") lon
return nmsdf_ft_font_load_glyph(font, cp, coordinateScaling, memAddress(shape));
}

// --- [ msdf_ft_font_load_glyph_by_index ] ---

/** Unsafe version of: {@link #msdf_ft_font_load_glyph_by_index ft_font_load_glyph_by_index} */
public static native int nmsdf_ft_font_load_glyph_by_index(long font, int index, int coordinateScaling, long shape);

/**
* Loads a single glyph from the given font and converts it into a vector shape for rendering glyph sprites.
*
* @param font a handle to the font to use for generating the glyph shape
* @param index the glyph index to generate a shape for
* @param coordinateScaling the coordinate scaling to use. One of:<br><table><tr><td>{@link #MSDF_FONT_SCALING_NONE FONT_SCALING_NONE}</td><td>{@link #MSDF_FONT_SCALING_EM_NORMALIZED FONT_SCALING_EM_NORMALIZED}</td><td>{@link #MSDF_FONT_SCALING_LEGACY FONT_SCALING_LEGACY}</td></tr></table>
* @param shape a pointer to a handle to be populated with the address of the newly created shape.
*
* <p>This shape must later be freed using {@link MSDFGen#msdf_shape_free shape_free}!</p>
*
* @return {@link MSDFGen#MSDF_SUCCESS SUCCESS} on success, otherwise one of the constants prefixed with {@code MSDF_ERR_}.
*/
public static int msdf_ft_font_load_glyph_by_index(@NativeType("msdf_ft_font_handle") long font, @NativeType("unsigned") int index, int coordinateScaling, @NativeType("msdf_shape_handle *") PointerBuffer shape) {
if (CHECKS) {
check(font);
check(shape, 1);
}
return nmsdf_ft_font_load_glyph_by_index(font, index, coordinateScaling, memAddress(shape));
}

// --- [ msdf_ft_font_get_glyph_index ] ---

/** Unsafe version of: {@link #msdf_ft_font_get_glyph_index ft_font_get_glyph_index} */
public static native int nmsdf_ft_font_get_glyph_index(long font, int cp, long index);

/**
* Retrieves the glyph index of the given unicode codepoint.
*
* @param font a handle to the font to retrieve the glyph index from
* @param cp the codepoint to retrieve the glyph index for
* @param index a pointer to the glyph index to be retrieved
*
* @return {@link MSDFGen#MSDF_SUCCESS SUCCESS} on success, otherwise one of the constants prefixed with {@code MSDF_ERR_}.
*/
public static int msdf_ft_font_get_glyph_index(@NativeType("msdf_ft_font_handle") long font, @NativeType("unsigned") int cp, @NativeType("unsigned *") IntBuffer index) {
if (CHECKS) {
check(font);
check(index, 1);
}
return nmsdf_ft_font_get_glyph_index(font, cp, memAddress(index));
}

// --- [ msdf_ft_font_get_kerning ] ---

/** Unsafe version of: {@link #msdf_ft_font_get_kerning ft_font_get_kerning} */
public static native int nmsdf_ft_font_get_kerning(long font, int cp1, int cp2, long kerning);

/**
* Retrieves the kerning between the two given codepoints.
*
* @param font a handle to the font to retrieve the kerning from
* @param cp1 the left codepoint
* @param cp2 the right codepoint
* @param kerning a pointer to the kerning value to be retrieved
*
* @return {@link MSDFGen#MSDF_SUCCESS SUCCESS} on success, otherwise one of the constants prefixed with {@code MSDF_ERR_}.
*/
public static int msdf_ft_font_get_kerning(@NativeType("msdf_ft_font_handle") long font, @NativeType("unsigned") int cp1, @NativeType("unsigned") int cp2, @NativeType("double *") DoubleBuffer kerning) {
if (CHECKS) {
check(font);
check(kerning, 1);
}
return nmsdf_ft_font_get_kerning(font, cp1, cp2, memAddress(kerning));
}

// --- [ msdf_ft_font_get_kerning_by_index ] ---

/** Unsafe version of: {@link #msdf_ft_font_get_kerning_by_index ft_font_get_kerning_by_index} */
public static native int nmsdf_ft_font_get_kerning_by_index(long font, int index1, int index2, long kerning);

/**
* etrieves the kerning between the two given glyphs.
*
* @param font a handle to the font to retrieve the kerning from
* @param index1 the glyph index of the left glyph
* @param index2 the glyph index of the right glyph
* @param kerning a pointer to the kerning value to be retrieved
*
* @return {@link MSDFGen#MSDF_SUCCESS SUCCESS} on success, otherwise one of the constants prefixed with {@code MSDF_ERR_}.
*/
public static int msdf_ft_font_get_kerning_by_index(@NativeType("msdf_ft_font_handle") long font, @NativeType("unsigned") int index1, @NativeType("unsigned") int index2, @NativeType("double *") DoubleBuffer kerning) {
if (CHECKS) {
check(font);
check(kerning, 1);
}
return nmsdf_ft_font_get_kerning_by_index(font, index1, index2, memAddress(kerning));
}

// --- [ msdf_ft_font_destroy ] ---

/** Unsafe version of: {@link #msdf_ft_font_destroy ft_font_destroy} */
Expand Down
38 changes: 37 additions & 1 deletion modules/lwjgl/msdfgen/src/main/c/msdfgen-ext-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MSDF_API int msdf_ft_load_font_data(msdf_ft_handle handle, const void* data, con
return MSDF_SUCCESS;
}

MSDF_API int msdf_ft_font_load_glyph(msdf_ft_font_handle font, const unsigned cp, int coordinateScaling, msdf_shape_handle* shape) {
MSDF_API int msdf_ft_font_load_glyph(msdf_ft_font_handle font, const unsigned cp, const int coordinateScaling, msdf_shape_handle* shape) {
if(font == nullptr || shape == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
Expand All @@ -81,6 +81,42 @@ MSDF_API int msdf_ft_font_load_glyph(msdf_ft_font_handle font, const unsigned cp
return MSDF_SUCCESS;
}

MSDF_API int msdf_ft_font_load_glyph_by_index(msdf_ft_font_handle font, const unsigned index, const int coordinateScaling, msdf_shape_handle* shape) {
if(font == nullptr || shape == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
auto* actual_shape = new msdfgen::Shape();
msdfgen::loadGlyph(*actual_shape, reinterpret_cast<msdfgen::FontHandle*>(font), msdfgen::GlyphIndex(index), (msdfgen::FontCoordinateScaling)coordinateScaling);
*shape = reinterpret_cast<msdf_shape_handle>(actual_shape);
return MSDF_SUCCESS;
}

MSDF_API int msdf_ft_font_get_glyph_index(msdf_ft_font_handle font, unsigned cp, unsigned* index) {
if(font == nullptr || index == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
msdfgen::GlyphIndex glyph_index{};
msdfgen::getGlyphIndex(glyph_index, reinterpret_cast<msdfgen::FontHandle*>(font), cp);
*index = glyph_index.getIndex();
return MSDF_SUCCESS;
}

MSDF_API int msdf_ft_font_get_kerning_by_index(msdf_ft_font_handle font, unsigned index1, unsigned index2, double* kerning) {
if(font == nullptr || kerning == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
msdfgen::getKerning(*kerning, reinterpret_cast<msdfgen::FontHandle*>(font), msdfgen::GlyphIndex(index1), msdfgen::GlyphIndex(index2));
return MSDF_SUCCESS;
}

MSDF_API int msdf_ft_font_get_kerning(msdf_ft_font_handle font, unsigned cp1, unsigned cp2, double* kerning) {
if(font == nullptr || kerning == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
msdfgen::getKerning(*kerning, reinterpret_cast<msdfgen::FontHandle*>(font), cp1, cp2);
return MSDF_SUCCESS;
}

MSDF_API void msdf_ft_font_destroy(msdf_ft_font_handle handle) {
if(handle == nullptr) {
return;
Expand Down
43 changes: 42 additions & 1 deletion modules/lwjgl/msdfgen/src/main/c/msdfgen-ext-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,55 @@ MSDF_API int msdf_ft_load_font_data(msdf_ft_handle handle, const void* data, siz
/**
* Loads a single glyph from the given font and converts it into a vector shape
* for rendering glyph sprites.
* @param font A handle to the font to use for generating the glyph shape.
* @param font A handle to the font to load the glyph shape from.
* @param cp The codepoint to generate a shape for.
* @param coordinateScaling The type of coordinate transform applied to the shape.
* @param shape A pointer to a handle to be populated with the address of the newly created shape.
* This shape must later be freed using msdf_shape_free!
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_font_load_glyph(msdf_ft_font_handle font, unsigned cp, int coordinateScaling, msdf_shape_handle* shape);

/**
* Loads a single glyph from the given font and converts it into a vector shape
* for rendering glyph sprites.
* @param font A handle to the font to load the glyph shape from.
* @param index The glyph index to generate a shape for.
* @param coordinateScaling The type of coordinate transform applied to the shape.
* @param shape A pointer to a handle to be populated with the address of the newly created shape.
* This shape must later be freed using msdf_shape_free!
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_font_load_glyph_by_index(msdf_ft_font_handle font, unsigned index, int coordinateScaling, msdf_shape_handle* shape);

/**
* Retrieves the glyph index of the given unicode codepoint.
* @param font A handle to the font to retrieve the glyph index from.
* @param cp The codepoint to retrieve the glyph index for.
* @param index A pointer to the glyph index to be retrieved.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_font_get_glyph_index(msdf_ft_font_handle font, unsigned cp, unsigned* index);

/**
* Retrieves the kerning between the two given glyphs.
* @param font A handle to the font to retrieve the kerning from.
* @param index1 The glyph index of the left glyph.
* @param index2 The glyph index of the right glyph.
* @param kerning A pointer to the kerning value to be retrieved.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_font_get_kerning_by_index(msdf_ft_font_handle font, unsigned index1, unsigned index2, double* kerning);

/**
* Retrieves the kerning between the two given codepoints.
* @param font A handle to the font to retrieve the kerning from.
* @param cp1 The left codepoint.
* @param cp2 The right codepoint.
* @param kerning A pointer to the kerning value to be retrieved.
*/
MSDF_API int msdf_ft_font_get_kerning(msdf_ft_font_handle font, unsigned cp1, unsigned cp2, double* kerning);

/**
* Frees the underlying instance of the given FreeType font.
* @param handle The handle to the font to free.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,60 @@ val msdfGenExt = "MSDFGenExt".nativeClass(Module.MSDFGEN, prefix = "MSDF", prefi
returnDoc = returnDoc
)

int(
"ft_font_load_glyph_by_index",
"Loads a single glyph from the given font and converts it into a vector shape for rendering glyph sprites.",

msdf_ft_font_handle("font", "a handle to the font to use for generating the glyph shape"),
unsigned("index", "the glyph index to generate a shape for"),
int("coordinateScaling", "the coordinate scaling to use", "FONT_SCALING_\\w+"),
Check(1)..msdf_shape_handle.p(
"shape",
"""
a pointer to a handle to be populated with the address of the newly created shape.

This shape must later be freed using #shape_free()!
"""
),

returnDoc = returnDoc
)

int(
"ft_font_get_glyph_index",
"Retrieves the glyph index of the given unicode codepoint.",

msdf_ft_font_handle("font", "a handle to the font to retrieve the glyph index from"),
unsigned("cp", "the codepoint to retrieve the glyph index for"),
Check(1)..unsigned.p("index", "a pointer to the glyph index to be retrieved"),

returnDoc = returnDoc
)

int(
"ft_font_get_kerning",
"Retrieves the kerning between the two given codepoints.",

msdf_ft_font_handle("font", "a handle to the font to retrieve the kerning from"),
unsigned("cp1", "the left codepoint"),
unsigned("cp2", "the right codepoint"),
Check(1)..double.p("kerning", "a pointer to the kerning value to be retrieved"),

returnDoc = returnDoc
)

int(
"ft_font_get_kerning_by_index",
"etrieves the kerning between the two given glyphs.",

msdf_ft_font_handle("font", "a handle to the font to retrieve the kerning from"),
unsigned("index1", "the glyph index of the left glyph"),
unsigned("index2", "the glyph index of the right glyph"),
Check(1)..double.p("kerning", "a pointer to the kerning value to be retrieved"),

returnDoc = returnDoc
)

void(
"ft_font_destroy",
"Frees the underlying instance of the given FreeType font.",
Expand Down