[cairo-commit] CairoJava/jni CairoFreetypeFont.cpp,NONE,1.1
Soorya Kuloor
commit at pdx.freedesktop.org
Fri Apr 30 10:46:07 PDT 2004
- Previous message: [cairo-commit] libsvg/src svg_element.c,1.32,1.33
- Next message: [cairo-commit] CairoJava/jni CairoImageBuffer.cpp, NONE,
1.1 CairoGlitzSurface.cpp, NONE, 1.1 CairoLinearPattern.cpp,
NONE, 1.1 CairoImageBufferSurface.cpp, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: skuloor
Update of /cvs/cairo/CairoJava/jni
In directory pdx:/tmp/cvs-serv13535/jni
Added Files:
CairoFreetypeFont.cpp
Log Message:
Initial Version
--- NEW FILE: CairoFreetypeFont.cpp ---
/*
* $Id: Cairo.java,v 1.5 2003/12/23 17:36:01 skuloor Exp $
*
* Copyright (C) 2003 Verano
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of Verano not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
* Verano makes no representations about the suitability of this software for
* any purpose. It is provided "as is" without express or implied warranty.
*
* VERANO MAKES NO REPRESENTATIONS OR WARRANTIES OR COVENANTS, EITHER EXPRESS OR
* IMPLIED, WITH RESPECT TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
* STATUTORY OR IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR
* A PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR ARISING FROM CUSTOM, COURSE
* OF DEALING, USAGE OF TRADE OR COURSE OF PERFORMANCE, ALL OF WHICH ARE
* EXPRESSLY DISCLAIMED TO THE FULLEST EXTENT ALLOWABLE BY APPLICABLE LAW. IN NO
* EVENT SHALL VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <cairo.h>
#include "CairoFreetypeFont.h"
#include "utils.h"
static FT_Library ft_library;
static short ft_lib_init = 0;
/*
* Class: org_cairographics_cairo_CairoFreetypeFont
* Method: cairo_ft_font_create
* Signature: (Ljava/lang/String;SS)J
*/
JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_CairoFreetypeFont_cairo_1ft_1font_1create__Ljava_lang_String_2SS
(JNIEnv *env, jclass me, jstring family, jshort slant, jshort weight)
{
const char *family_utf = env->GetStringUTFChars(family, NULL);
cairo_font_t *font = NULL;
FcPattern * pat = NULL;
int fcslant;
int fcweight;
FT_Error error;
pat = FcPatternCreate ();
if (pat == NULL)
return 0;
switch (weight)
{
case CAIRO_FONT_WEIGHT_BOLD:
fcweight = FC_WEIGHT_BOLD;
break;
case CAIRO_FONT_WEIGHT_NORMAL:
default:
fcweight = FC_WEIGHT_MEDIUM;
break;
}
switch (slant)
{
case CAIRO_FONT_SLANT_ITALIC:
fcslant = FC_SLANT_ITALIC;
break;
case CAIRO_FONT_SLANT_OBLIQUE:
fcslant = FC_SLANT_OBLIQUE;
break;
case CAIRO_FONT_SLANT_NORMAL:
default:
fcslant = FC_SLANT_ROMAN;
break;
}
FcPatternAddString (pat, FC_FAMILY, (const FcChar8*) family_utf);
FcPatternAddInteger (pat, FC_SLANT, fcslant);
FcPatternAddInteger (pat, FC_WEIGHT, fcweight);
if (ft_lib_init == 0) {
error = FT_Init_FreeType (&ft_library);
if (error) {
FcPatternDestroy (pat);
return 0;
}
ft_lib_init = 1;
}
font = cairo_ft_font_create (ft_library, pat);
if (font == NULL)
return 0;
#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
FT_Set_Char_Size (cairo_ft_font_face(font),
DOUBLE_TO_26_6 (1.0),
DOUBLE_TO_26_6 (1.0),
0, 0);
FcPatternDestroy (pat);
env->ReleaseStringUTFChars(family, family_utf);
return TO_LONG(font);
}
/*
* Class: org_cairographics_cairo_CairoFreetypeFont
* Method: cairo_ft_font_create
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J
*/
JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_CairoFreetypeFont_cairo_1ft_1font_1create__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2
(JNIEnv *env, jclass me, jstring family, jstring slant, jstring weight)
{
const char *family_utf = env->GetStringUTFChars(family, NULL);
const char *slant_utf = env->GetStringUTFChars(slant, NULL);
const char *weight_utf = env->GetStringUTFChars(weight, NULL);
cairo_font_t *font = NULL;
FcPattern * pat = NULL;
FT_Error error;
char fontBuf[256];
strcpy(fontBuf, family_utf);
strcat(fontBuf, ":");
strcat(fontBuf, weight_utf);
strcat(fontBuf, ":");
strcat(fontBuf, slant_utf);
pat = FcNameParse ((const FcChar8*) fontBuf);
if (pat == NULL)
return 0;
if (ft_lib_init == 0) {
error = FT_Init_FreeType (&ft_library);
if (error) {
FcPatternDestroy (pat);
return 0;
}
ft_lib_init = 1;
}
font = cairo_ft_font_create (ft_library, pat);
if (font == NULL)
return 0;
#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
FT_Set_Char_Size (cairo_ft_font_face(font),
DOUBLE_TO_26_6 (1.0),
DOUBLE_TO_26_6 (1.0),
0, 0);
FcPatternDestroy (pat);
env->ReleaseStringUTFChars(family, family_utf);
env->ReleaseStringUTFChars(slant, slant_utf);
env->ReleaseStringUTFChars(weight, weight_utf);
return TO_LONG(font);
}
#if 0
/*
* Class: org_cairographics_cairo_CairoFreetypeFont
* Method: cairo_ft_font_destroy
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_cairographics_cairo_CairoFreetypeFont_cairo_1ft_1font_1destroy
(JNIEnv *env, jclass me, jlong fontp)
{
cairo_ft_font_destroy(TO_PTR(cairo_font_t, fontp));
}
#endif
- Previous message: [cairo-commit] libsvg/src svg_element.c,1.32,1.33
- Next message: [cairo-commit] CairoJava/jni CairoImageBuffer.cpp, NONE,
1.1 CairoGlitzSurface.cpp, NONE, 1.1 CairoLinearPattern.cpp,
NONE, 1.1 CairoImageBufferSurface.cpp, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list