jdk/src/solaris/native/sun/awt/multi_font.c
author yan
Thu, 19 Jun 2008 11:26:54 +0400
changeset 1175 026b52c440fe
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6706121: makefile: unnecessary Motif classes compilation in JDK7 Summary: removed 80 obsolete .c and .java files, temporary modified some more Reviewed-by: denis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * These routines are used for display string with multi font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    #error This file should not be included in headless library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <math.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <jvm.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <Xm/Display.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "awt_MenuItem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "multi_font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
extern XFontStruct *loadFont(Display *, char *, int32_t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
extern struct FontIDs fontIDs;
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
    55
//extern struct MComponentPeerIDs mComponentPeerIDs;
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
    56
//extern struct MMenuItemPeerIDs mMenuItemPeerIDs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
extern struct PlatformFontIDs platformFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
extern struct MFontPeerIDs mFontPeerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * make string with str + string representation of num
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * This string is used as tag string of Motif Compound String and FontList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
makeTag(char *str, int32_t num, char *buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    int32_t len = strlen(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    strcpy(buf, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    buf[len] = '0' + num % 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    buf[len + 1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
awtJNI_CreateAndSetGlobalRef(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jobject gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    gRef = (*env)->NewGlobalRef(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    JNU_SetLongFieldFromPtr(env, this, mComponentPeerIDs.jniGlobalRef, gRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    return gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
struct gRefStruct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    jobject gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    struct gRefStruct *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
static struct gRefStruct *gRefHead = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static struct gRefStruct *gRefTail = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * This function is called by components that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * are being disposed. It used to invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * the global ref immediately, but the awt is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * rather full of thread race conditions involving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * component disposal and outstanding events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Now we queue up 'to be deleted' global refs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * as they come in, and don't invalidate them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * until the X event queue is empty. Callers of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * either of these functions _must_ have AWT_LOCK'd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * before using them!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
awtJNI_DeleteGlobalRef(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    jobject gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    struct gRefStruct *newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    struct gRefStruct *temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    gRef = (jobject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        JNU_GetLongFieldAsPtr(env, this, mComponentPeerIDs.jniGlobalRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    JNU_SetLongFieldFromPtr(env, this, mComponentPeerIDs.jniGlobalRef, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Verra handy for tracking down race conditions. If you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * have a peer getting called after its been disposed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /* jio_fprintf(stderr,"%p\n",(void *)gRef); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    newGRef = (struct gRefStruct *)malloc((size_t)sizeof(struct gRefStruct));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if(newGRef == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        (*env)->DeleteGlobalRef(env, gRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        newGRef->gRef = gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        newGRef->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if(gRefHead == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            gRefTail = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            gRefHead = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            gRefTail->next = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            gRefTail = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
awtJNI_DeleteGlobalMenuRef(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    jobject gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    struct gRefStruct *newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    struct gRefStruct *temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    gRef = (jobject)
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   154
    //JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.jniGlobalRef);
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   155
    //JNU_SetLongFieldFromPtr(env, this, mMenuItemPeerIDs.jniGlobalRef, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Verra handy for tracking down race conditions. If you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * have a peer getting called after its been disposed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* jio_fprintf(stderr,"%p\n",(void *)gRef); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    newGRef = (struct gRefStruct *)malloc((size_t)sizeof(struct gRefStruct));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    if(newGRef == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        (*env)->DeleteGlobalRef(env, gRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        newGRef->gRef = gRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        newGRef->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if(gRefHead == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            gRefTail = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            gRefHead = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            gRefTail->next = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            gRefTail = newGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
void awtJNI_CleanupGlobalRefs()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    struct gRefStruct *working,*next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    int32_t count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    if(gRefHead == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    working = gRefHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    gRefHead = gRefTail = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    while(working != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        next = working->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        (*env)->DeleteGlobalRef(env, working->gRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        free((void *)working);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        working = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
awtJNI_GetFontDescriptorNumber(JNIEnv * env
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                               ,jobject font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                               ,jobject fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    int32_t i = 0, num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /* initialize to NULL so that DeleteLocalRef will work. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    jobjectArray componentFonts = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    jobject temp = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jboolean validRet = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    if ((*env)->EnsureLocalCapacity(env, 2) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    if (peer == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    componentFonts = (jobjectArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        (*env)->GetObjectField(env,peer,platformFontIDs.componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    if (componentFonts == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    num = (*env)->GetArrayLength(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    for (i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        temp = (*env)->GetObjectArrayElement(env, componentFonts, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if ((*env)->IsSameObject(env, fd, temp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            validRet = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        (*env)->DeleteLocalRef(env, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    (*env)->DeleteLocalRef(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (validRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
awtJNI_GetFont(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    jobject target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    jobject font = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    target = (*env)->GetObjectField(env, this, mComponentPeerIDs.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    // SECURITY: Must call _NoClientCode() methods to ensure that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    //           are not invoking client code on the privileged thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    font = JNU_CallMethodByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                "getFont_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                "()Ljava/awt/Font;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    (*env)->DeleteLocalRef(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
awtJNI_GetFMFont(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    return JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                "()Ljava/awt/Font;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
awtJNI_IsMultiFont(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    jobject fontConfig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    if (this == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    if ((*env)->EnsureLocalCapacity(env, 2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    peer = (*env)->CallObjectMethod(env,this,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    fontConfig = (*env)->GetObjectField(env,peer,platformFontIDs.fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (fontConfig == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    (*env)->DeleteLocalRef(env, fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
awtJNI_IsMultiFontMetrics(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    jobject fontConfig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    jobject font = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    if (JNU_IsNull(env, this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    if ((*env)->EnsureLocalCapacity(env, 3) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    font = JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                "()Ljava/awt/Font;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (JNU_IsNull(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    (*env)->DeleteLocalRef(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    fontConfig = (*env)->GetObjectField(env,peer,platformFontIDs.fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    if (fontConfig == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    (*env)->DeleteLocalRef(env, fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
XmString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
unicodeXmStringCreate(char* text, char* tag, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    XmString ret_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    XtProcessLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    ret_val = _XmStringNCreate (text, tag, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    XtProcessUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    return ret_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * Unicode to Motif Multi Font Compound String converter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * ASSUMES: We are not running on a privileged thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
XmString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
awtJNI_MakeMultiFontString(JNIEnv * env, jstring s, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    XmString xmstr = NULL, xmtmp1, xmtmp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    jobjectArray dataArray = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    char *err = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    int32_t stringCount,i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    int32_t fdnumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    struct FontData *fdata = awtJNI_GetFontData(env, font, &err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    jobject fontDescriptor = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    jbyteArray data = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    char *stringData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    char tag[BUFSIZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    if ((*env)->PushLocalFrame(env, 16) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    if (!JNU_IsNull(env, s) && !JNU_IsNull(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        jobject peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        DASSERT(!awt_currentThreadIsPrivileged(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        dataArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            (*env)->CallObjectMethod(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                             env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                             peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                             platformFontIDs.makeConvertedMultiFontString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                             s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            (*env)->PopLocalFrame(env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return (XmString) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if(dataArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            (*env)->PopLocalFrame(env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return (XmString) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        (*env)->PopLocalFrame(env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return (XmString) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    stringCount = (*env)->GetArrayLength(env, dataArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    for (i = 0; i < stringCount; i+=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        fontDescriptor = (*env)->GetObjectArrayElement(env, dataArray, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        data = (*env)->GetObjectArrayElement(env, dataArray, i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        /* Bail if we've finished */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if(fontDescriptor == NULL || data == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        fdnumber = awtJNI_GetFontDescriptorNumber(env, font, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        fdata = awtJNI_GetFontData(env, font, &err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        makeTag(fdata->flist[fdnumber].charset_name, fdnumber, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        stringData = (char *)(*env)->GetPrimitiveArrayCritical(env, data, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if(stringData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            unsigned char* buf = stringData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            char *offsetStringData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            offsetStringData = stringData + (4 * sizeof(char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            len = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            /* Motif XmStringCreate() API requests "text must be a NULL-terminated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
               string" and its implementation uses "strlen()" to calculate the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
               of the text string. Unfortunately when we deal with iso10646 font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
               on linux, the "text" is requested to be encoded in UTF16, which has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
               posibility of including code points like "0xYY00" ("0xYY" + "0x00") that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
               causes problem when XmStringCreate() calls _XmStringNCreate() without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
               specifying a specific text lenth (see Motif XmString.c). The workaround is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
               to call _XmStringNCreate() directly with specific text length at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
               cirsumstance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (strstr(fdata->flist[fdnumber].charset_name, "UnicodeBigUnmarked"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                xmtmp1 = unicodeXmStringCreate(offsetStringData, tag, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                xmtmp1 = XmStringCreate(offsetStringData, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            if (xmstr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                xmstr = xmtmp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                xmtmp2 = XmStringConcat(xmstr, xmtmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                XmStringFree(xmtmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                XmStringFree(xmstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                xmstr = xmtmp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if(xmstr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                xmstr = XmStringCreate(offsetStringData, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                xmtmp1 = XmStringCreate(offsetStringData, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                xmtmp2 = XmStringConcat(xmstr, xmtmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                XmStringFree(xmtmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                XmStringFree(xmstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                xmstr = xmtmp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        (*env)->ReleasePrimitiveArrayCritical(env, data, stringData, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    (*env)->PopLocalFrame(env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    return xmstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
 * Find the character encoding for a given font and register that encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
 * with the given tag.  The encoding is the last two fields of the XLFD of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
 * the font (converted to uppercase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
static void registerEncoding(char *xlfd, char *tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    char *e = xlfd + strlen(xlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    char *ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    do { --e; } while (e != xlfd && *e != '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    do { --e; } while (e != xlfd && *e != '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    if (e != xlfd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        char *encoding = strdup(++e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        char *u = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        for (u = encoding; *u != '\0'; ++u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            if (islower(*u)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                *u = toupper(*u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * Motif will core dump on or otherwise mishandle unknown (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         * non-standard) character encodings (in conversion to compound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         * text, bug 4122785).  Register Sun private encodings for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         * Symbol or dingbat fonts as ISO8859-1, which is a lie,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         * but produces predictable results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (strncmp(encoding, "SUN-", 4) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                free(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                encoding = strdup("ISO8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        ret = XmRegisterSegmentEncoding(tag, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (ret != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                XtFree(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        free(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
XmFontList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
awtJNI_GetFontList(JNIEnv * env, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    int32_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    XmFontListEntry fle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    XmFontList fontlist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    XFontStruct *xf = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    int32_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    struct FontData *fdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    char *err = NULL, tag[BUFSIZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    fdata = awtJNI_GetFontData(env, font, &err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    makeTag(fdata->flist[0].charset_name, 0, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    size = (int32_t) (*env)->GetIntField(env, font, fontIDs.size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    if (fdata->flist[0].load == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        xf = loadFont(awt_display, fdata->flist[0].xlfd, size * 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            /* printf("Cannot load font: %s\n", fdata->list[0].xlfd); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            fdata->flist[0].xfont = xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            fdata->flist[0].load = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            if (xf->min_byte1 == 0 && xf->max_byte1 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                fdata->flist[0].index_length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                fdata->flist[0].index_length = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    registerEncoding(fdata->flist[0].xlfd, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    fle = XmFontListEntryCreate(tag, XmFONT_IS_FONT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                (XtPointer) fdata->flist[0].xfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    fontlist = XmFontListAppendEntry(NULL, fle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Some versions of motif have a bug in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * XmFontListEntryFree() which causes it to free more than it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * should.  Use XtFree() is used instead.  See O'Reilly's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * Motif Reference Manual for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    XmFontListEntryFree(&fle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    for (i = 1; i < fdata->charset_num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        makeTag(fdata->flist[i].charset_name, i, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (fdata->flist[i].load == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            xf = loadFont(awt_display, fdata->flist[i].xlfd, size * 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            if (xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                /* printf("Cannot load font: %s\n", fdata->flist[0].xlfd); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            fdata->flist[i].xfont = xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            fdata->flist[i].load = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            if (xf->min_byte1 == 0 && xf->max_byte1 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                fdata->flist[i].index_length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                fdata->flist[i].index_length = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        registerEncoding(fdata->flist[i].xlfd, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        fle = XmFontListEntryCreate(tag, XmFONT_IS_FONT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                    (XtPointer) fdata->flist[i].xfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        fontlist = XmFontListAppendEntry(fontlist, fle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * Some versions of motif have a bug in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         * XmFontListEntryFree() which causes it to free more than it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * should.  Use XtFree() instead.  See O'Reilly's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         * Motif Reference Manual for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        XmFontListEntryFree(&fle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    return fontlist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
/* #define FONT_DEBUG 2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
XFontSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
awtJNI_MakeFontSet(JNIEnv * env, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    jstring xlfd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    char *xfontset = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    int32_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    int32_t length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    char *realxlfd = NULL, *ptr = NULL, *prev = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    char **missing_list = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    int32_t missing_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    char *def_string = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    XFontSet xfs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    jstring xfsname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
#ifdef FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    char xx[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    if ((*env)->EnsureLocalCapacity(env, 2) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    size = (*env)->GetIntField(env, font, fontIDs.size) * 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    xfsname = (*env)->GetObjectField(env, peer, mFontPeerIDs.xfsname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    if (JNU_IsNull(env, xfsname))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        xfontset = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        xfontset = (char *)JNU_GetStringPlatformChars(env, xfsname, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    realxlfd = malloc(strlen(xfontset) + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    prev = ptr = xfontset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    while ((ptr = strstr(ptr, "%d"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        char save = *(ptr + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        *(ptr + 2) = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        jio_snprintf(realxlfd + length, strlen(xfontset) + 50 - length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                     prev, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        length = strlen(realxlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        *(ptr + 2) = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        prev = ptr + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        ptr += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    strcpy(realxlfd + length, prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
#ifdef FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    strcpy(xx, realxlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    xfs = XCreateFontSet(awt_display, realxlfd, &missing_list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                         &missing_count, &def_string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
#if FONT_DEBUG >= 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    fprintf(stderr, "XCreateFontSet(%s)->0x%x\n", xx, xfs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
#if FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    if (missing_count != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        int32_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        fprintf(stderr, "XCreateFontSet missing %d fonts:\n", missing_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        for (i = 0; i < missing_count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            fprintf(stderr, "\t\"%s\"\n", missing_list[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        fprintf(stderr, "  requested \"%s\"\n", xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
#if FONT_DEBUG >= 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    free((void *)realxlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    if (xfontset && !JNU_IsNull(env, xfsname))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        JNU_ReleaseStringPlatformChars(env, xfsname, (const char *) xfontset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    (*env)->DeleteLocalRef(env, xfsname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    return xfs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
 * get multi font string width with multiple X11 font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
 * ASSUMES: We are not running on a privileged thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
awtJNI_GetMFStringWidth(JNIEnv * env, jcharArray s, int offset, int sLength, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    char *err = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    unsigned char *stringData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    char *offsetStringData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    int32_t stringCount, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    int32_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    struct FontData *fdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    jobject fontDescriptor = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    jbyteArray data = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    int32_t j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    int32_t width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    int32_t length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    XFontStruct *xf = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    jobjectArray dataArray = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    DASSERT(!awt_currentThreadIsPrivileged(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    if ((*env)->EnsureLocalCapacity(env, 3) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    if (!JNU_IsNull(env, s) && !JNU_IsNull(env, font))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        jobject peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        dataArray = (*env)->CallObjectMethod(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                 env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                 peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                 platformFontIDs.makeConvertedMultiFontChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                                 s, offset, sLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if ((*env)->ExceptionOccurred(env))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if(dataArray == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    fdata = awtJNI_GetFontData(env, font, &err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    stringCount = (*env)->GetArrayLength(env, dataArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    size = (*env)->GetIntField(env, font, fontIDs.size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    for (i = 0; i < stringCount; i+=2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        fontDescriptor = (*env)->GetObjectArrayElement(env, dataArray, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        data = (*env)->GetObjectArrayElement(env, dataArray, i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        /* Bail if we've finished */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (fontDescriptor == NULL || data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        j = awtJNI_GetFontDescriptorNumber(env, font, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        if (fdata->flist[j].load == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            xf = loadFont(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                          fdata->flist[j].xlfd, size * 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            fdata->flist[j].load = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            fdata->flist[j].xfont = xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            if (xf->min_byte1 == 0 && xf->max_byte1 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                fdata->flist[j].index_length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                fdata->flist[j].index_length = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        xf = fdata->flist[j].xfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        stringData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            (unsigned char *)(*env)->GetPrimitiveArrayCritical(env, data,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        length = (stringData[0] << 24) | (stringData[1] << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            (stringData[2] << 8) | stringData[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        offsetStringData = (char *)(stringData + (4 * sizeof(char)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (fdata->flist[j].index_length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            width += XTextWidth16(xf, (XChar2b *)offsetStringData, length/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            width += XTextWidth(xf, offsetStringData, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        (*env)->ReleasePrimitiveArrayCritical(env, data, stringData, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    (*env)->DeleteLocalRef(env, dataArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
}