Skip to content

Commit

Permalink
feat: extend all platform abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Aug 11, 2024
1 parent 836a958 commit c579df9
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 11 deletions.
20 changes: 20 additions & 0 deletions lib/dotnet/AlphaSkia/AlphaSkiaCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ public static AlphaSkiaColorType ColorType
}
}

/// <summary>
/// Switches the rendering to use the operating system font manager and font rendering.
/// This results in a platform specific display of any rendered texts and allows using of any
/// fonts installed on the system.
/// </summary>
public static void SwitchToOperatingSystemFonts()
{
NativeMethods.alphaskia_switch_to_operating_system_fonts();
}

/// <summary>
/// Switches the rendering to use the FreeType font manager and font rendering.
/// This results in a platform independent display of any rendered texts achieving consistent rendering.
/// Operating system fonts cannot be used in this mode.
/// </summary>
public static void SwitchToFreeTypeFonts()
{
NativeMethods.alphaskia_switch_to_freetype_fonts();
}

/// <summary>
/// Initializes a new empty instance of the <see cref="AlphaSkiaCanvas"/> class.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions lib/dotnet/AlphaSkia/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ internal static class NativeMethods

[DllImport(AlphaSkiaNativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int alphaskia_get_color_type();
[DllImport(AlphaSkiaNativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void alphaskia_switch_to_freetype_fonts();
[DllImport(AlphaSkiaNativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void alphaskia_switch_to_operating_system_fonts();


[DllImport(AlphaSkiaNativeLibName, CallingConvention = CallingConvention.Cdecl)]
Expand Down
16 changes: 16 additions & 0 deletions lib/java/jni/include/alphaTab_alphaSkia_AlphaSkiaCanvas.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion lib/java/jni/src/AlphaSkiaCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,12 @@ extern "C"
{
return static_cast<jint>(alphaskia_get_color_type());
}
}

JNIEXPORT jint JNICALL Java_alphaTab_alphaSkia_AlphaSkiaCanvas_switchToFreeTypeFonts(JNIEnv *, jclass) {
alphaskia_switch_to_freetype_fonts();
}

JNIEXPORT jint JNICALL Java_alphaTab_alphaSkia_AlphaSkiaCanvas_switchToOperatingSystemFonts(JNIEnv *, jclass) {
alphaskia_switch_to_operating_system_fonts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,18 @@ public native void fillText(String text, AlphaSkiaTypeface typeface, float fontS
private native static long alphaskiaCanvasAllocate();

private static native int alphaskiaColorType();

/**
* Switches the rendering to use the operating system font manager and font rendering.
* This results in a platform specific display of any rendered texts and allows using of any
* fonts installed on the system.
*/
public static native int switchToFreeTypeFonts();

/**
* Switches the rendering to use the FreeType font manager and font rendering.
* This results in a platform independent display of any rendered texts achieving consistent rendering.
* Operating system fonts cannot be used in this mode.
*/
public static native int switchToOperatingSystemFonts();
}
20 changes: 20 additions & 0 deletions lib/node/addon/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ static napi_value node_alphaskia_get_color_type(napi_env env, napi_callback_info
return node_color_type;
}

static napi_value node_alphaskia_switch_to_freetype_fonts(napi_env env, napi_callback_info info)
{
napi_status status(napi_ok);

alphaskia_switch_to_freetype_fonts();

RETURN_UNDEFINED();
}

static napi_value node_alphaskia_switch_to_operating_system_fonts(napi_env env, napi_callback_info info)
{
napi_status status(napi_ok);

alphaskia_switch_to_operating_system_fonts();

RETURN_UNDEFINED();
}

static napi_value node_alphaskia_data_new_copy(napi_env env, napi_callback_info info)
{
napi_status status(napi_ok);
Expand Down Expand Up @@ -824,6 +842,8 @@ napi_value init(napi_env env, napi_value exports)
std::vector<napi_property_descriptor> methods;

EXPORT_NODE_FUNCTION(alphaskia_get_color_type);
EXPORT_NODE_FUNCTION(alphaskia_switch_to_freetype_fonts);
EXPORT_NODE_FUNCTION(alphaskia_switch_to_operating_system_fonts);

EXPORT_NODE_FUNCTION(alphaskia_data_new_copy);
EXPORT_NODE_FUNCTION(alphaskia_data_get_data);
Expand Down
2 changes: 2 additions & 0 deletions lib/node/alphaskia/src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export enum AlphaSkiaColorType {
*/
export interface AlphaSkiaNodeAddon {
alphaskia_get_color_type(): AlphaSkiaColorType;
alphaskia_switch_to_freetype_fonts(): void;
alphaskia_switch_to_operating_system_fonts(): void;

alphaskia_data_new_copy(data: ArrayBuffer): AlphaSkiaDataHandle | undefined;
alphaskia_data_get_data(data: AlphaSkiaDataHandle): ArrayBuffer;
Expand Down
14 changes: 4 additions & 10 deletions wrapper/src/alphaskia_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,15 @@ extern "C"
AS_API void alphaskia_switch_to_freetype_fonts()
{
sk_sp<SkFontMgr> fm = SkFontMgr::RefDefault();
SkFontMgr_AlphaSkia *afm = dynamic_cast<SkFontMgr_AlphaSkia *>(fm.get());
if (afm != nullptr)
{
afm->switch_to_freetype_fonts();
}
SkFontMgr_AlphaSkia *afm = reinterpret_cast<SkFontMgr_AlphaSkia *>(fm.get());
afm->switch_to_freetype_fonts();
}

AS_API void alphaskia_switch_to_operating_system_fonts()
{
sk_sp<SkFontMgr> fm = SkFontMgr::RefDefault();
SkFontMgr_AlphaSkia *afm = dynamic_cast<SkFontMgr_AlphaSkia *>(fm.get());
if (afm != nullptr)
{
afm->switch_to_operating_system_fonts();
}
SkFontMgr_AlphaSkia *afm = reinterpret_cast<SkFontMgr_AlphaSkia *>(fm.get());
afm->switch_to_operating_system_fonts();
}

AS_API int32_t alphaskia_get_color_type()
Expand Down

0 comments on commit c579df9

Please sign in to comment.