Skip to content

Commit

Permalink
Added loadChar
Browse files Browse the repository at this point in the history
  • Loading branch information
nikialeksey committed Sep 4, 2017
1 parent 9d273b0 commit 1e63045
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 103 deletions.
2 changes: 2 additions & 0 deletions freetype2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
3 changes: 2 additions & 1 deletion freetype2/src/main/cpp/commons/freetype2errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion freetype2/src/main/cpp/commons/freetype2errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#include <ft2build.h>
#include "freetype/freetype.h" FT_FREETYPE_H

jint throwException(JNIEnv *env, FT_Error error, const char *className);
jint throwException(JNIEnv *env, FT_Error error);
25 changes: 2 additions & 23 deletions freetype2/src/main/cpp/face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down
14 changes: 2 additions & 12 deletions freetype2/src/main/cpp/freetype2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
}

Expand Down
24 changes: 24 additions & 0 deletions freetype2/src/main/cpp/glyph.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.nikialeksey.freetype2.glyph;

public interface Glyph {
}
Original file line number Diff line number Diff line change
@@ -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");
}
}

3 comments on commit 1e63045

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 1e63045 Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 3-da6ea56c discovered in freetype2/src/main/java/com/nikialeksey/freetype2/glyph/NativeGlyph.java and submitted as #3.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 1e63045 Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 4-642155c9 discovered in freetype2/src/main/java/com/nikialeksey/freetype2/glyph/NativeGlyph.java and submitted as #4.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 1e63045 Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base (if you think that it's a bug on your our side, please submit it to yegor256/0pdd):

Tag "1-0532b2a6/submit" already exists, won't submit again. This situation most probably means that this puzzle was already seen in the code and you're trying to create it again. We would recommend you to re-phrase the text of the puzzle and push again. If this doesn't work, pleas let us know in GitHub: https://github.com/yegor256/0pdd/issues
/app/objects/logged_tickets.rb:41:in `submit'
/app/objects/commit_tickets.rb:39:in `submit'
/app/objects/emailed_tickets.rb:37:in `submit'
/app/objects/puzzles.rb:86:in `block in submit'
/app/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
/app/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
/app/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
/app/objects/puzzles.rb:86:in `map'
/app/objects/puzzles.rb:86:in `submit'
/app/objects/puzzles.rb:44:in `deploy'
/app/objects/job.rb:42:in `proceed'
/app/objects/job_starred.rb:35:in `proceed'
/app/objects/job_recorded.rb:33:in `proceed'
/app/objects/job_emailed.rb:36:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:51:in `block in exclusive'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `block in catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:106:in `timeout'
/app/objects/job_detached.rb:49:in `exclusive'
/app/objects/job_detached.rb:39:in `block in proceed'
/app/objects/job_detached.rb:39:in `fork'
/app/objects/job_detached.rb:39:in `proceed'
/app/0pdd.rb:306:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `block in compile!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:994:in `route_eval'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1015:in `block in process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:973:in `block in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1085:in `block in dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1082:in `dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `block in call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:895:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.8/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.8/lib/rack/commonlogger.rb:33:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:219:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:212:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.8/lib/rack/head.rb:13:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.8/lib/rack/methodoverride.rb:22:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.8/lib/rack/handler/webrick.rb:88:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Please sign in to comment.