Commit f7c2a6f1 authored by hpi1's avatar hpi1

Configure options to select BD-J type and font support

parent c17ecee9
......@@ -105,6 +105,18 @@ AC_ARG_ENABLE([libxml2],
[use_libxml2=$enableval],
[use_libxml2=yes])
AC_ARG_ENABLE([freetype],
[AS_HELP_STRING([--enable-freetype],
[enable FreeType support for BD-J (default is yes)])],
[use_freetype=$enableval],
[use_freetype=yes])
AC_ARG_WITH([bdj-type],
[AS_HELP_STRING([--with-bdj-type=TYPE],
[Specify the type of BD-J implementation (j2se, j2me). Default is j2se.])],
[BDJ_TYPE=$withval],
[BDJ_TYPE=j2se])
# required programs
AC_PROG_CC
AC_PROG_LIBTOOL
......@@ -160,6 +172,18 @@ if test "x$use_libxml2" = "xyes"; then
fi
fi
dnl FreeType2
if test x"$use_bdjava" != x"no"; then
if test x"$use_freetype" != x"no"; then
PKG_CHECK_MODULES([FT2], [freetype2], [use_freetype=yes], [use_freetype=no])
if test x"$use_freetype" = x"no"; then
AC_MSG_ERROR([FreeType2 support requested but FreeType2 library not found])
elif test x"$use_freetype" = x"yes"; then
AC_DEFINE([HAVE_FT2], 1, [Define this if you have FreeType2 library])
fi
fi
fi
# function testing for supported compiler options
check_cc_options()
{
......@@ -263,6 +287,14 @@ if [[ $use_bdjava = "yes" ]]; then
fi
AM_CONDITIONAL([USING_BDJAVA], [ test $use_bdjava = "yes" ])
# BD-J type
if test "$BDJ_TYPE" = "j2me"; then
AC_DEFINE([HAVE_BDJ_J2ME], [1], [Define to 1 if using libbluray J2ME stack])
else
BDJ_TYPE=j2se
fi
AC_SUBST(BDJ_TYPE)
# generate documentation
DX_INIT_DOXYGEN(libbluray, doc/doxygen-config, [doc/doxygen])
......@@ -294,7 +326,11 @@ dnl ---------------------------------------------
echo " Summary:"
echo " --------"
echo " BD-J support: $use_bdjava"
echo " Metadata support: $use_libxml2"
echo " Build examples: $use_examples"
echo " BD-J support: $use_bdjava"
if [[ $use_bdjava = "yes" ]]; then
echo " BD-J font support (freetype2): $use_freetype"
echo " BD-J type: $BDJ_TYPE"
fi
echo " Metadata support (libxml): $use_libxml2"
echo " Build examples: $use_examples"
......@@ -9,7 +9,7 @@ SET_DEBUG_OPTS = @SET_DEBUG_OPTS@
SET_INCLUDES = -I$(top_srcdir) -Ifile -Ilibbluray/bdnav
AM_CFLAGS = -std=c99 $(SET_FEATURES) $(SET_WARNINGS) $(SET_OPTIMIZATIONS) \
$(SET_DEBUG_OPTS) $(SET_INCLUDES) $(LIBXML2_CFLAGS)
$(SET_DEBUG_OPTS) $(SET_INCLUDES) $(LIBXML2_CFLAGS) $(FT2_CFLAGS)
CFLAGS=$(shell test -z "$$CFLAGS" || echo "$$CFLAGS")
SOURCES_bdj = libbluray/bdj/bdj.h \
......@@ -20,6 +20,10 @@ SOURCES_bdj = libbluray/bdj/bdj.h \
libbluray/bdj/bdjo_parser.h \
libbluray/bdj/bdjo_parser.c \
libbluray/bdj/common.h \
libbluray/bdj/native/java_awt_BDGraphics.h \
libbluray/bdj/native/java_awt_BDGraphics.c \
libbluray/bdj/native/java_awt_BDFontMetrics.h \
libbluray/bdj/native/java_awt_BDFontMetrics.c \
libbluray/bdj/native/org_videolan_Libbluray.h \
libbluray/bdj/native/org_videolan_Libbluray.c \
libbluray/bdj/native/register_native.h \
......@@ -97,7 +101,7 @@ libbluray_la_SOURCES=libbluray/bluray.h \
util/logging.h
libbluray_la_HEADERS= libbluray/bluray.h file/filesystem.h util/log_control.h libbluray/keys.h libbluray/decoders/overlay.h libbluray/bdnav/meta_data.h libbluray/bdnav/clpi_data.h libbluray/bluray-version.h
libbluray_la_LDFLAGS= -version-info $(LIB_VERSION_INFO)
libbluray_la_LIBADD= $(LIBXML2_LIBS) $(DLOPEN_LIBS)
libbluray_la_LIBADD= $(LIBXML2_LIBS) $(DLOPEN_LIBS) $(FT2_LIBS)
if USING_BDJAVA
......@@ -110,7 +114,7 @@ libbluray_la_SOURCES+=$(SOURCES_bdj)
AM_CFLAGS+=@BDJAVA_CFLAGS@
all-local:
ant -f $(top_srcdir)/src/libbluray/bdj/build.xml
ant -f $(top_srcdir)/src/libbluray/bdj/build.xml -Dsrc_awt=:java-$(BDJ_TYPE)
clean-local:
ant -f $(top_srcdir)/src/libbluray/bdj/build.xml clean
......
......@@ -195,6 +195,9 @@ BDJAVA* bdj_open(const char *path, struct bluray *bd,
int n = 0;
option[n++].optionString = classpath_opt;
option[n++].optionString = vfs_opt;
#ifdef HAVE_BDJ_AWT
option[n++].optionString = str_dup("-Dawt.toolkit=java.awt.BDToolkit");
#endif
args.version = JNI_VERSION_1_4;
args.nOptions = n;
......
......@@ -6,6 +6,7 @@
<property name="src" location="java"/>
<property name="build" location="build"/>
<property name="dist" location="../../.libs"/>
<property name="src_awt" value=""/>
<target name="init">
<tstamp/>
......@@ -15,7 +16,7 @@
<target name="compile" depends="init"
description="compile the source " >
<javac srcdir="${src}" destdir="${build}" debug="yes"
<javac srcdir="${src}${src_awt}" destdir="${build}" debug="yes"
source="1.4" target="1.4" />
</target>
......
/*
* This file is part of libbluray
* Copyright (C) 2012 libbluray
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <jni.h>
#include "util/logging.h"
#ifdef HAVE_FT2
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
#include "java_awt_BDFontMetrics.h"
/* Disable some warnings */
#if defined __GNUC__
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
JNIEXPORT jlong JNICALL
Java_java_awt_BDFontMetrics_initN(JNIEnv * env, jclass cls)
{
#ifdef HAVE_FT2
FT_Library ftLib;
if (!FT_Init_FreeType(&ftLib)) {
return (jlong)ftLib;
}
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Loading FreeType2 failed\n");
#else
BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J font support not compiled in\n");
#endif
return 0;
}
JNIEXPORT void JNICALL
Java_java_awt_BDFontMetrics_destroyN(JNIEnv * env, jclass cls, jlong ftLib)
{
#ifdef HAVE_FT2
FT_Library lib = (FT_Library)(intptr_t)ftLib;
FT_Done_FreeType(lib);
#endif
}
JNIEXPORT jlong JNICALL
Java_java_awt_BDFontMetrics_loadFontN(JNIEnv * env, jobject obj, jlong ftLib, jstring fontName, jint size)
{
#ifdef HAVE_FT2
const char *name;
FT_Face ftFace;
FT_Error result;
jclass cls;
jfieldID fid;
FT_Library lib = (FT_Library)(intptr_t)ftLib;
name = (*env)->GetStringUTFChars(env, fontName, NULL);
result = FT_New_Face(lib, name, 0, &ftFace);
(*env)->ReleaseStringUTFChars(env, fontName, name);
if (result)
return 0;
FT_Set_Char_Size(ftFace, 0, size << 6, 0, 0);
cls = (*env)->GetObjectClass(env, obj);
fid = (*env)->GetFieldID(env, cls, "ascent", "I");
(*env)->SetIntField (env, obj, fid, ftFace->size->metrics.ascender >> 6);
fid = (*env)->GetFieldID(env, cls, "descent", "I");
(*env)->SetIntField (env, obj, fid, -ftFace->size->metrics.descender >> 6);
fid = (*env)->GetFieldID(env, cls, "leading", "I");
(*env)->SetIntField (env, obj, fid, (ftFace->size->metrics.height - ftFace->size->metrics.ascender + ftFace->size->metrics.descender) >> 6);
fid = (*env)->GetFieldID(env, cls, "maxAdvance", "I");
(*env)->SetIntField (env, obj, fid, ftFace->size->metrics.max_advance >> 6);
return (jlong)ftFace;
#else /* HAVE_FT2 */
return 0;
#endif /* HAVE_FT2 */
}
JNIEXPORT void JNICALL
Java_java_awt_BDFontMetrics_destroyFontN(JNIEnv *env, jobject obj, jlong ftFace)
{
#ifdef HAVE_FT2
FT_Face face = (FT_Face)(intptr_t)ftFace;
FT_Done_Face(face);
#endif
}
JNIEXPORT jint JNICALL
Java_java_awt_BDFontMetrics_charWidthN(JNIEnv * env, jobject obj, jlong ftFace, jchar c)
{
#ifdef HAVE_FT2
FT_Face face = (FT_Face)(intptr_t)ftFace;
if (FT_Load_Char(face, c, FT_LOAD_DEFAULT))
return 0;
return face->glyph->metrics.horiAdvance >> 6;
#else
return 0;
#endif
}
JNIEXPORT jint JNICALL
Java_java_awt_BDFontMetrics_stringWidthN(JNIEnv * env, jobject obj, jlong ftFace, jstring string)
{
#ifdef HAVE_FT2
jsize length;
const jchar *chars;
jint i, width;
FT_Face face = (FT_Face)(intptr_t)ftFace;
length = (*env)->GetStringLength(env, string);
if (length <= 0)
return 0;
chars = (*env)->GetStringCritical(env, string, NULL);
if (chars == NULL)
return 0;
for (i = 0, width = 0; i < length; i++) {
if (FT_Load_Char(face, chars[i], FT_LOAD_DEFAULT) == 0) {
width += face->glyph->metrics.horiAdvance >> 6;
}
}
(*env)->ReleaseStringCritical(env, string, chars);
return width;
#else /* HAVE_FT2 */
return 0;
#endif /* HAVE_FT2 */
}
JNIEXPORT jint JNICALL
Java_java_awt_BDFontMetrics_charsWidthN(JNIEnv * env, jobject obj, jlong ftFace, jcharArray charArray,
jint offset, jint length)
{
#ifdef HAVE_FT2
jchar *chars;
jint i, width;
FT_Face face = (FT_Face)(intptr_t)ftFace;
chars = (jchar *)malloc(sizeof(jchar) * length);
if (chars == NULL)
return 0;
(*env)->GetCharArrayRegion(env, charArray, offset, length, chars);
if ((*env)->ExceptionCheck(env)) {
free(chars);
return 0;
}
for (i = 0, width = 0; i < length; i++) {
if (FT_Load_Char(face, chars[i], FT_LOAD_DEFAULT) == 0) {
width += face->glyph->metrics.horiAdvance >> 6;
}
}
free(chars);
return width;
#else /* HAVE_FT2 */
return 0;
#endif /* HAVE_FT2 */
}
#define CC (char*) /*cast a literal from (const char*)*/
#pragma GCC diagnostic ignored "-Wcast-qual"
BD_PRIVATE const JNINativeMethod
Java_java_awt_BDFontMetrics_methods[] =
{ /* AUTOMATICALLY GENERATED */
{
CC("initN"),
CC("()J"),
Java_java_awt_BDFontMetrics_initN,
},
{
CC("destroyN"),
CC("(J)V"),
Java_java_awt_BDFontMetrics_destroyN,
},
{
CC("loadFontN"),
CC("(JLjava/lang/String;I)J"),
Java_java_awt_BDFontMetrics_loadFontN,
},
{
CC("destroyFontN"),
CC("(J)V"),
Java_java_awt_BDFontMetrics_destroyFontN,
},
{
CC("charWidthN"),
CC("(JC)I"),
Java_java_awt_BDFontMetrics_charWidthN,
},
{
CC("stringWidthN"),
CC("(JLjava/lang/String;)I"),
Java_java_awt_BDFontMetrics_stringWidthN,
},
{
CC("charsWidthN"),
CC("(J[CII)I"),
Java_java_awt_BDFontMetrics_charsWidthN,
},
};
BD_PRIVATE const int
Java_java_awt_BDFontMetrics_methods_count =
sizeof(Java_java_awt_BDFontMetrics_methods)/sizeof(Java_java_awt_BDFontMetrics_methods[0]);
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_awt_BDFontMetrics */
#ifndef WIN32
#undef JNIEXPORT
#define JNIEXPORT static
#endif
#ifndef _Included_java_awt_BDFontMetrics
#define _Included_java_awt_BDFontMetrics
#ifdef __cplusplus
extern "C" {
#endif
#undef java_awt_BDFontMetrics_serialVersionUID
#define java_awt_BDFontMetrics_serialVersionUID -4956160226949100590LL
/*
* Class: java_awt_BDFontMetrics
* Method: initN
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_java_awt_BDFontMetrics_initN
(JNIEnv *, jclass);
/*
* Class: java_awt_BDFontMetrics
* Method: destroyN
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_java_awt_BDFontMetrics_destroyN
(JNIEnv *, jclass, jlong);
/*
* Class: java_awt_BDFontMetrics
* Method: loadFontN
* Signature: (JLjava/lang/String;I)J
*/
JNIEXPORT jlong JNICALL Java_java_awt_BDFontMetrics_loadFontN
(JNIEnv *, jobject, jlong, jstring, jint);
/*
* Class: java_awt_BDFontMetrics
* Method: destroyFontN
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_java_awt_BDFontMetrics_destroyFontN
(JNIEnv *, jobject, jlong);
/*
* Class: java_awt_BDFontMetrics
* Method: charWidthN
* Signature: (JC)I
*/
JNIEXPORT jint JNICALL Java_java_awt_BDFontMetrics_charWidthN
(JNIEnv *, jobject, jlong, jchar);
/*
* Class: java_awt_BDFontMetrics
* Method: stringWidthN
* Signature: (JLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_java_awt_BDFontMetrics_stringWidthN
(JNIEnv *, jobject, jlong, jstring);
/*
* Class: java_awt_BDFontMetrics
* Method: charsWidthN
* Signature: (J[CII)I
*/
JNIEXPORT jint JNICALL Java_java_awt_BDFontMetrics_charsWidthN
(JNIEnv *, jobject, jlong, jcharArray, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of libbluray
* Copyright (C) 2012 libbluray
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <jni.h>
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include "util/logging.h"
#include <stdint.h>
#ifdef HAVE_FT2
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
#include "java_awt_BDGraphics.h"
/* Disable some warnings */
#if defined __GNUC__
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
JNIEXPORT void JNICALL
Java_java_awt_BDGraphics_drawStringN(JNIEnv * env, jobject obj, jlong ftFace, jstring string, jint x, jint y, jint rgb)
{
#ifdef HAVE_FT2
jsize length;
const jchar *chars;
jclass cls;
jmethodID mid;
jint a, c;
jint i, j, k;
FT_Face face = (FT_Face)(intptr_t)ftFace;
length = (*env)->GetStringLength(env, string);
if (length <= 0)
return;
chars = (*env)->GetStringCritical(env, string, NULL);
if (chars == NULL)
return;
cls = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID(env, cls, "drawPoint", "(III)V");
a = (rgb >> 24) & 0xff;
c = rgb & 0xffffff;
for (i = 0; i < length; i++) {
if (FT_Load_Char(face, chars[i], FT_LOAD_RENDER) == 0) {
for (j = 0; j < face->glyph->bitmap.rows; j++) {
for (k = 0; k < face->glyph->bitmap.width; k++) {
jint pixel;
pixel = face->glyph->bitmap.buffer[j*face->glyph->bitmap.pitch + k];
pixel = ((a * pixel / 255) << 24) | c;
(*env)->CallVoidMethod(env, obj, mid,
x + face->glyph->bitmap_left + k,
y - face->glyph->bitmap_top + j,
pixel);
}
}
x += face->glyph->metrics.horiAdvance >> 6;
}
}
(*env)->ReleaseStringCritical(env, string, chars);
#endif /* HAVE_FT2 */
}
#define CC (char*) /*cast a literal from (const char*)*/
#pragma GCC diagnostic ignored "-Wcast-qual"
BD_PRIVATE const JNINativeMethod
Java_java_awt_BDGraphics_methods[] =
{ /* AUTOMATICALLY GENERATED */
{
CC("drawStringN"),
CC("(JLjava/lang/String;III)V"),
Java_java_awt_BDGraphics_drawStringN,
},
};
BD_PRIVATE const int Java_java_awt_BDGraphics_methods_count =
sizeof(Java_java_awt_BDGraphics_methods)/sizeof(Java_java_awt_BDGraphics_methods[0]);
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_awt_BDGraphics */
#ifndef WIN32
#undef JNIEXPORT
#define JNIEXPORT static
#endif
#ifndef _Included_java_awt_BDGraphics
#define _Included_java_awt_BDGraphics
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: java_awt_BDGraphics
* Method: drawStringN
* Signature: (JLjava/lang/String;III)V
*/
JNIEXPORT void JNICALL Java_java_awt_BDGraphics_drawStringN
(JNIEnv *, jobject, jlong, jstring, jint, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
......@@ -358,6 +358,7 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_updateGraphicN(JNIEnv * env,
if (!rgbArray) {
bdj->osd_cb(bdj->bd, NULL, (int)width, (int)height, 0, 0, 0, 0);
return;
}
if (bdj->buf && bdj->buf->buf[BD_OVERLAY_IG]) {
......@@ -369,10 +370,11 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_updateGraphicN(JNIEnv * env,
}
if (bdj->buf->width != width || bdj->buf->height != height) {
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Incorrect ARGB frame buffer size\n");
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Incorrect ARGB frame buffer size (is: %dx%d expect: %dx%d)\n",
bdj->buf->width, bdj->buf->height, width, height);
}
jsize len = bdj->buf->width * bdj->buf->height * sizeof(uint32_t);
jsize len = bdj->buf->width * bdj->buf->height;
(*env)->GetByteArrayRegion(env, rgbArray, 0, len, (jbyte*)bdj->buf->buf[BD_OVERLAY_IG]);
if (bdj->buf->unlock) {
......
......@@ -24,11 +24,24 @@
int bdj_register_native_methods(JNIEnv *env)
{
extern const JNINativeMethod Java_org_videolan_Libbluray_methods[];
extern const JNINativeMethod Java_java_awt_BDGraphics_methods[];
extern const JNINativeMethod Java_java_awt_BDFontMetrics_methods[];
extern const int Java_org_videolan_Libbluray_methods_count;
extern const int Java_java_awt_BDGraphics_methods_count;
extern const int Java_java_awt_BDFontMetrics_methods_count;
return
bdj_register_methods(env, "org/videolan/Libbluray",
Java_org_videolan_Libbluray_methods,
Java_org_videolan_Libbluray_methods_count)
*
/* BDFontMetrics must be registered before BDGraphics */
bdj_register_methods(env, "java/awt/BDFontMetrics",
Java_java_awt_BDFontMetrics_methods,
Java_java_awt_BDFontMetrics_methods_count)
*
bdj_register_methods(env, "java/awt/BDGraphics",
Java_java_awt_BDGraphics_methods,
Java_java_awt_BDGraphics_methods_count)
;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment