From 1e63045cca99ec957122228b8c6979d61b0282cc Mon Sep 17 00:00:00 2001 From: Alexey Nikitin Date: Mon, 4 Sep 2017 13:13:02 +0700 Subject: [PATCH] Added loadChar --- freetype2/CMakeLists.txt | 2 ++ .../src/main/cpp/commons/freetype2errors.cpp | 3 ++- .../src/main/cpp/commons/freetype2errors.h | 2 +- freetype2/src/main/cpp/face.cpp | 25 ++----------------- freetype2/src/main/cpp/freetype2.cpp | 14 ++--------- freetype2/src/main/cpp/glyph.cpp | 24 ++++++++++++++++++ .../exceptions/Freetype2Exception.java | 13 ++++++++-- .../freetype2/exceptions/Initialize.java | 15 ----------- .../freetype2/exceptions/Release.java | 15 ----------- .../freetype2/face/exceptions/Initialize.java | 17 ------------- .../freetype2/face/exceptions/Release.java | 17 ------------- .../nikialeksey/freetype2/glyph/Glyph.java | 4 +++ .../freetype2/glyph/NativeGlyph.java | 22 ++++++++++++++++ 13 files changed, 70 insertions(+), 103 deletions(-) create mode 100644 freetype2/src/main/cpp/glyph.cpp delete mode 100644 freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Initialize.java delete mode 100644 freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Release.java delete mode 100644 freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Initialize.java delete mode 100644 freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Release.java create mode 100644 freetype2/src/main/java/com/nikialeksey/freetype2/glyph/Glyph.java create mode 100644 freetype2/src/main/java/com/nikialeksey/freetype2/glyph/NativeGlyph.java diff --git a/freetype2/CMakeLists.txt b/freetype2/CMakeLists.txt index ac39a55..11e4399 100644 --- a/freetype2/CMakeLists.txt +++ b/freetype2/CMakeLists.txt @@ -6,4 +6,6 @@ add_library(Freetype2 SHARED src/main/cpp/freetype2.cpp) add_library(Freetype2Face SHARED src/main/cpp/face.cpp) +add_library(Freetype2Glyph SHARED src/main/cpp/glyph.cpp) + include_directories(jni/include/) \ No newline at end of file diff --git a/freetype2/src/main/cpp/commons/freetype2errors.cpp b/freetype2/src/main/cpp/commons/freetype2errors.cpp index b237ffe..9cadae3 100644 --- a/freetype2/src/main/cpp/commons/freetype2errors.cpp +++ b/freetype2/src/main/cpp/commons/freetype2errors.cpp @@ -12,8 +12,9 @@ const char *getErrorMessage(FT_Error err) { return "(Unknown error)"; } -jint throwException(JNIEnv *env, FT_Error error, const char *className) { +jint throwException(JNIEnv *env, FT_Error error) { jclass exClass; + const char *className = "com/nikialeksey/freetype2/exceptions/Freetype2Exception"; exClass = env->FindClass(className); if (exClass == NULL) { return throwNoClassDefError(env, className); diff --git a/freetype2/src/main/cpp/commons/freetype2errors.h b/freetype2/src/main/cpp/commons/freetype2errors.h index 87c4299..9eddb1c 100644 --- a/freetype2/src/main/cpp/commons/freetype2errors.h +++ b/freetype2/src/main/cpp/commons/freetype2errors.h @@ -3,4 +3,4 @@ #include #include "freetype/freetype.h" FT_FREETYPE_H -jint throwException(JNIEnv *env, FT_Error error, const char *className); \ No newline at end of file +jint throwException(JNIEnv *env, FT_Error error); \ No newline at end of file diff --git a/freetype2/src/main/cpp/face.cpp b/freetype2/src/main/cpp/face.cpp index c9f69dc..a993d88 100644 --- a/freetype2/src/main/cpp/face.cpp +++ b/freetype2/src/main/cpp/face.cpp @@ -2,16 +2,6 @@ extern "C" { -jint throwInitialize(JNIEnv *env, FT_Error error) { - const char *className = "com/nikialeksey/freetype2/face/exceptions/Initialize"; - return throwException(env, error, className); -} - -jint throwRelease(JNIEnv *env, FT_Error error) { - const char *className = "com/nikialeksey/freetype2/face/exceptions/Release"; - return throwException(env, error, className); -} - JNIEXPORT jlong JNICALL Java_com_nikialeksey_freetype2_face_NativeFace_init(JNIEnv *env, jclass cls, jlong library, jstring filename) { FT_Face face; @@ -21,7 +11,7 @@ Java_com_nikialeksey_freetype2_face_NativeFace_init(JNIEnv *env, jclass cls, jlo env->ReleaseStringUTFChars(filename, nativeFilename); if (error) { - return throwInitialize(env, error); + return throwException(env, error); } return (jlong) face; } @@ -30,18 +20,7 @@ JNIEXPORT void JNICALL Java_com_nikialeksey_freetype2_face_NativeFace_release(JNIEnv *env, jclass cls, jlong face) { FT_Error error = FT_Done_Face((FT_Face) face); if (error) { - throwRelease(env, error); - } -} - -JNIEXPORT void JNICALL -Java_com_nikialeksey_freetype2_face_NativeFace_charSize(JNIEnv *env, jclass cls, jlong face, - jlong width, jlong height, - jint hResolution, jint vResolution) { - FT_Error error = FT_Set_Char_Size((FT_Face) face, (FT_F26Dot6) width, (FT_F26Dot6) height, - (FT_UInt) hResolution, (FT_UInt) vResolution); - if (error) { - throwInitialize(env, error); + throwException(env, error); } } diff --git a/freetype2/src/main/cpp/freetype2.cpp b/freetype2/src/main/cpp/freetype2.cpp index 2056473..653731b 100644 --- a/freetype2/src/main/cpp/freetype2.cpp +++ b/freetype2/src/main/cpp/freetype2.cpp @@ -2,22 +2,12 @@ extern "C" { -jint throwInitialize(JNIEnv *env, FT_Error error) { - const char *className = "com/nikialeksey/freetype2/exceptions/Initialize"; - return throwException(env, error, className); -} - -jint throwRelease(JNIEnv *env, FT_Error error) { - const char *className = "com/nikialeksey/freetype2/exceptions/Release"; - return throwException(env, error, className); -} - JNIEXPORT jlong JNICALL Java_com_nikialeksey_freetype2_NativeFreetype2_init(JNIEnv *env, jclass cls) { FT_Library library; FT_Error error = FT_Init_FreeType(&library); if (error) { - return throwInitialize(env, error); + return throwException(env, error); } return (jlong) library; } @@ -26,7 +16,7 @@ JNIEXPORT void JNICALL Java_com_nikialeksey_freetype2_NativeFreetype2_release(JNIEnv *env, jclass cls, jlong library) { FT_Error error = FT_Done_FreeType((FT_Library) library); if (error) { - throwRelease(env, error); + throwException(env, error); } } diff --git a/freetype2/src/main/cpp/glyph.cpp b/freetype2/src/main/cpp/glyph.cpp new file mode 100644 index 0000000..de49d12 --- /dev/null +++ b/freetype2/src/main/cpp/glyph.cpp @@ -0,0 +1,24 @@ +#include "commons/freetype2errors.h" + +extern "C" { + +JNIEXPORT void JNICALL +Java_com_nikialeksey_freetype2_glyph_NativeGlyph_charSize(JNIEnv *env, jclass cls, jlong face, + jlong width, jlong height, + jint hResolution, jint vResolution) { + FT_Error error = FT_Set_Char_Size((FT_Face) face, (FT_F26Dot6) width, (FT_F26Dot6) height, + (FT_UInt) hResolution, (FT_UInt) vResolution); + if (error) { + throwException(env, error); + } +} + +JNIEXPORT void JNICALL +Java_com_nikialeksey_freetype2_glyph_NativeGlyph_loadChar(JNIEnv *env, jclass cls, jlong face, jchar character) { + FT_Error error = FT_Load_Char((FT_Face) face, (FT_ULong) character, FT_LOAD_RENDER); + if (error) { + throwException(env, error); + } +} + +} \ No newline at end of file diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Freetype2Exception.java b/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Freetype2Exception.java index 41be8ce..36b656d 100644 --- a/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Freetype2Exception.java +++ b/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Freetype2Exception.java @@ -1,5 +1,14 @@ package com.nikialeksey.freetype2.exceptions; -public interface Freetype2Exception { - String message(); +public class Freetype2Exception extends RuntimeException { + private final String message; + + public Freetype2Exception(final String message) { + this.message = message; + } + + public String message() { + return message; + } } + diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Initialize.java b/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Initialize.java deleted file mode 100644 index bf7125a..0000000 --- a/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Initialize.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.nikialeksey.freetype2.exceptions; - -public class Initialize extends RuntimeException implements Freetype2Exception { - - private final String message; - - public Initialize(final String message) { - this.message = message; - } - - @Override - public String message() { - return message; - } -} diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Release.java b/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Release.java deleted file mode 100644 index dbfd983..0000000 --- a/freetype2/src/main/java/com/nikialeksey/freetype2/exceptions/Release.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.nikialeksey.freetype2.exceptions; - -public class Release extends RuntimeException implements Freetype2Exception { - - private final String message; - - public Release(final String message) { - this.message = message; - } - - @Override - public String message() { - return message; - } -} diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Initialize.java b/freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Initialize.java deleted file mode 100644 index 11d0d67..0000000 --- a/freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Initialize.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nikialeksey.freetype2.face.exceptions; - -import com.nikialeksey.freetype2.exceptions.Freetype2Exception; - -public class Initialize extends RuntimeException implements Freetype2Exception { - - private final String message; - - public Initialize(final String message) { - this.message = message; - } - - @Override - public String message() { - return message; - } -} diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Release.java b/freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Release.java deleted file mode 100644 index ea9feab..0000000 --- a/freetype2/src/main/java/com/nikialeksey/freetype2/face/exceptions/Release.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nikialeksey.freetype2.face.exceptions; - -import com.nikialeksey.freetype2.exceptions.Freetype2Exception; - -public class Release extends RuntimeException implements Freetype2Exception { - - private final String message; - - public Release(final String message) { - this.message = message; - } - - @Override - public String message() { - return message; - } -} diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/glyph/Glyph.java b/freetype2/src/main/java/com/nikialeksey/freetype2/glyph/Glyph.java new file mode 100644 index 0000000..b74c474 --- /dev/null +++ b/freetype2/src/main/java/com/nikialeksey/freetype2/glyph/Glyph.java @@ -0,0 +1,4 @@ +package com.nikialeksey.freetype2.glyph; + +public interface Glyph { +} diff --git a/freetype2/src/main/java/com/nikialeksey/freetype2/glyph/NativeGlyph.java b/freetype2/src/main/java/com/nikialeksey/freetype2/glyph/NativeGlyph.java new file mode 100644 index 0000000..b0ee619 --- /dev/null +++ b/freetype2/src/main/java/com/nikialeksey/freetype2/glyph/NativeGlyph.java @@ -0,0 +1,22 @@ +package com.nikialeksey.freetype2.glyph; + +import com.nikialeksey.freetype2.face.Face; + +public class NativeGlyph implements Glyph { + private final long faceAddress; + + public NativeGlyph(Face face) { + faceAddress = face.address(); + // @todo #3:30m set charSize and loadChar + // @todo #4:30m get char bitmap + } + + private native void charSize(long faceAddress, long width, long height, long hResolution, + long vResolution); + + private native void loadChar(long faceAddress, char character); + + static { + System.loadLibrary("Freetype2Glyph"); + } +}