jdk/src/solaris/native/sun/awt/multi_font.c
author serb
Sat, 12 Nov 2011 04:13:38 +0400
changeset 11093 e753252dc8a9
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on Reviewed-by: art, dcherepanov, bae, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
     2
 * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
    23
 * questions.
2
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
#include "awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "multi_font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
extern XFontStruct *loadFont(Display *, char *, int32_t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
extern struct FontIDs fontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
extern struct PlatformFontIDs platformFontIDs;
11093
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 5506
diff changeset
    49
extern struct XFontPeerIDs xFontPeerIDs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * make string with str + string representation of num
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This string is used as tag string of Motif Compound String and FontList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
makeTag(char *str, int32_t num, char *buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    int32_t len = strlen(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    strcpy(buf, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    buf[len] = '0' + num % 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    buf[len + 1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
awtJNI_GetFontDescriptorNumber(JNIEnv * env
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                               ,jobject font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                               ,jobject fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    int32_t i = 0, num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /* initialize to NULL so that DeleteLocalRef will work. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    jobjectArray componentFonts = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    jobject temp = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    jboolean validRet = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    if ((*env)->EnsureLocalCapacity(env, 2) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (peer == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    componentFonts = (jobjectArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        (*env)->GetObjectField(env,peer,platformFontIDs.componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    if (componentFonts == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    num = (*env)->GetArrayLength(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    for (i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        temp = (*env)->GetObjectArrayElement(env, componentFonts, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if ((*env)->IsSameObject(env, fd, temp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            validRet = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        (*env)->DeleteLocalRef(env, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    (*env)->DeleteLocalRef(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    if (validRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
awtJNI_GetFMFont(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    return JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                "()Ljava/awt/Font;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
awtJNI_IsMultiFont(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    jobject fontConfig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    if (this == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    if ((*env)->EnsureLocalCapacity(env, 2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    peer = (*env)->CallObjectMethod(env,this,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    fontConfig = (*env)->GetObjectField(env,peer,platformFontIDs.fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    if (fontConfig == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    (*env)->DeleteLocalRef(env, fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
awtJNI_IsMultiFontMetrics(JNIEnv * env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    jobject fontConfig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    jobject font = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    if (JNU_IsNull(env, this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    if ((*env)->EnsureLocalCapacity(env, 3) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    font = JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                "()Ljava/awt/Font;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    if (JNU_IsNull(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    (*env)->DeleteLocalRef(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    fontConfig = (*env)->GetObjectField(env,peer,platformFontIDs.fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (fontConfig == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    (*env)->DeleteLocalRef(env, fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
/* #define FONT_DEBUG 2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
XFontSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
awtJNI_MakeFontSet(JNIEnv * env, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    jstring xlfd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    char *xfontset = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    int32_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    int32_t length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    char *realxlfd = NULL, *ptr = NULL, *prev = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    char **missing_list = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    int32_t missing_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    char *def_string = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    XFontSet xfs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    jstring xfsname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#ifdef FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    char xx[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    if ((*env)->EnsureLocalCapacity(env, 2) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    size = (*env)->GetIntField(env, font, fontIDs.size) * 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
11093
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 5506
diff changeset
   212
    xfsname = (*env)->GetObjectField(env, peer, xFontPeerIDs.xfsname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    if (JNU_IsNull(env, xfsname))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        xfontset = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        xfontset = (char *)JNU_GetStringPlatformChars(env, xfsname, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    realxlfd = malloc(strlen(xfontset) + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    prev = ptr = xfontset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    while ((ptr = strstr(ptr, "%d"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        char save = *(ptr + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        *(ptr + 2) = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        jio_snprintf(realxlfd + length, strlen(xfontset) + 50 - length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                     prev, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        length = strlen(realxlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        *(ptr + 2) = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        prev = ptr + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        ptr += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    strcpy(realxlfd + length, prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
#ifdef FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    strcpy(xx, realxlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    xfs = XCreateFontSet(awt_display, realxlfd, &missing_list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                         &missing_count, &def_string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
#if FONT_DEBUG >= 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    fprintf(stderr, "XCreateFontSet(%s)->0x%x\n", xx, xfs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
#if FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    if (missing_count != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        int32_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        fprintf(stderr, "XCreateFontSet missing %d fonts:\n", missing_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        for (i = 0; i < missing_count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            fprintf(stderr, "\t\"%s\"\n", missing_list[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        fprintf(stderr, "  requested \"%s\"\n", xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
#if FONT_DEBUG >= 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    free((void *)realxlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (xfontset && !JNU_IsNull(env, xfsname))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        JNU_ReleaseStringPlatformChars(env, xfsname, (const char *) xfontset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    (*env)->DeleteLocalRef(env, xfsname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    return xfs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * get multi font string width with multiple X11 font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * ASSUMES: We are not running on a privileged thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
awtJNI_GetMFStringWidth(JNIEnv * env, jcharArray s, int offset, int sLength, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    char *err = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    unsigned char *stringData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    char *offsetStringData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    int32_t stringCount, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    int32_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    struct FontData *fdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    jobject fontDescriptor = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    jbyteArray data = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    int32_t j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    int32_t width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    int32_t length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    XFontStruct *xf = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    jobjectArray dataArray = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    if ((*env)->EnsureLocalCapacity(env, 3) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    if (!JNU_IsNull(env, s) && !JNU_IsNull(env, font))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        jobject peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        dataArray = (*env)->CallObjectMethod(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                 env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                 peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                 platformFontIDs.makeConvertedMultiFontChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                 s, offset, sLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if ((*env)->ExceptionOccurred(env))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if(dataArray == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    fdata = awtJNI_GetFontData(env, font, &err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    stringCount = (*env)->GetArrayLength(env, dataArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    size = (*env)->GetIntField(env, font, fontIDs.size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    for (i = 0; i < stringCount; i+=2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        fontDescriptor = (*env)->GetObjectArrayElement(env, dataArray, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        data = (*env)->GetObjectArrayElement(env, dataArray, i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        /* Bail if we've finished */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (fontDescriptor == NULL || data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        j = awtJNI_GetFontDescriptorNumber(env, font, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (fdata->flist[j].load == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            xf = loadFont(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                          fdata->flist[j].xlfd, size * 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            if (xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            fdata->flist[j].load = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            fdata->flist[j].xfont = xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (xf->min_byte1 == 0 && xf->max_byte1 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                fdata->flist[j].index_length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                fdata->flist[j].index_length = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        xf = fdata->flist[j].xfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        stringData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            (unsigned char *)(*env)->GetPrimitiveArrayCritical(env, data,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        length = (stringData[0] << 24) | (stringData[1] << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            (stringData[2] << 8) | stringData[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        offsetStringData = (char *)(stringData + (4 * sizeof(char)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (fdata->flist[j].index_length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            width += XTextWidth16(xf, (XChar2b *)offsetStringData, length/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            width += XTextWidth(xf, offsetStringData, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        (*env)->ReleasePrimitiveArrayCritical(env, data, stringData, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        (*env)->DeleteLocalRef(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    (*env)->DeleteLocalRef(env, dataArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}