jdk/src/java.desktop/unix/native/common/awt/awt_Font.c
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 26751 70bac69b37c9
child 28089 ba6da71f7be0
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
     2
 * Copyright (c) 1995, 2014, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "java_awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "java_awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "java_awt_FontMetrics.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "sun_awt_X11GraphicsEnvironment.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "java_awt_Dimension.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "multi_font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "Disposer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define defaultXLFD "-*-helvetica-*-*-*-*-12-*-*-*-*-*-iso8859-1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
struct FontIDs fontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
struct PlatformFontIDs platformFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static void pDataDisposeMethod(JNIEnv *env, jlong pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/* #define FONT_DEBUG 2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/* 1- print failures, 2- print all, 3- terminate on failure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#if FONT_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static XFontStruct *XLoadQueryFontX(Display *display, char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    XFontStruct *result = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    result = XLoadQueryFont(display, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#if FONT_DEBUG < 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    if (result == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        fprintf(stderr, "XLoadQueryFont(\"%s\") -> 0x%x.\n", name, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#if FONT_DEBUG >= 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    if (result == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define XLoadQueryFont XLoadQueryFontX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Class:     java_awt_Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/* This function gets called from the static initializer for Font.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
   to initialize the fieldIDs for fields that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
Java_java_awt_Font_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** We call "NoClientCode" methods because they won't invoke client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        code on the privileged toolkit thread **/
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    89
    CHECK_NULL(fontIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    90
    CHECK_NULL(fontIDs.style = (*env)->GetFieldID(env, cls, "style", "I"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    91
    CHECK_NULL(fontIDs.size = (*env)->GetFieldID(env, cls, "size", "I"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    92
    CHECK_NULL(fontIDs.getPeer = (*env)->GetMethodID(env, cls, "getPeer_NoClientCode",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    93
                                                     "()Ljava/awt/peer/FontPeer;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    94
    CHECK_NULL(fontIDs.getFamily = (*env)->GetMethodID(env, cls, "getFamily_NoClientCode",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
    95
                                                       "()Ljava/lang/String;"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
/* fieldIDs for FontDescriptor fields that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static struct FontDescriptorIDs {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    jfieldID nativeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    jfieldID charsetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
} fontDescriptorIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * Class:     sun_awt_FontDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
/* This function gets called from the static initializer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
   FontDescriptor.java to initialize the fieldIDs for fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
Java_sun_awt_FontDescriptor_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#ifndef HEADLESS
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   122
    CHECK_NULL(fontDescriptorIDs.nativeName =
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   123
               (*env)->GetFieldID(env, cls, "nativeName", "Ljava/lang/String;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   124
    CHECK_NULL(fontDescriptorIDs.charsetName =
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   125
               (*env)->GetFieldID(env, cls, "charsetName", "Ljava/lang/String;"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * Class:     sun_awt_PlatformFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
/* This function gets called from the static initializer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
   PlatformFont.java to initialize the fieldIDs for fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
Java_sun_awt_PlatformFont_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#ifndef HEADLESS
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   144
    CHECK_NULL(platformFontIDs.componentFonts =
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   145
               (*env)->GetFieldID(env, cls, "componentFonts",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   146
                                  "[Lsun/awt/FontDescriptor;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   147
    CHECK_NULL(platformFontIDs.fontConfig =
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   148
               (*env)->GetFieldID(env,cls, "fontConfig",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   149
                                  "Lsun/awt/FontConfiguration;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   150
    CHECK_NULL(platformFontIDs.makeConvertedMultiFontString =
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   151
               (*env)->GetMethodID(env, cls, "makeConvertedMultiFontString",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   152
                                   "(Ljava/lang/String;)[Ljava/lang/Object;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   153
    CHECK_NULL(platformFontIDs.makeConvertedMultiFontChars =
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   154
               (*env)->GetMethodID(env, cls, "makeConvertedMultiFontChars",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   155
                                   "([CII)[Ljava/lang/Object;"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
XFontStruct *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
loadFont(Display * display, char *name, int32_t pointSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    XFontStruct *f = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /* try the exact xlfd name in font configuration file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    f = XLoadQueryFont(display, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    if (f != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * try nearly font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *  1. specify FAMILY_NAME, WEIGHT_NAME, SLANT, POINT_SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *     CHARSET_REGISTRY and CHARSET_ENCODING.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *  2. change POINT_SIZE to PIXEL_SIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *  3. change FAMILY_NAME to *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *  4. specify only PIXEL_SIZE and CHARSET_REGISTRY/ENCODING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *  5. change PIXEL_SIZE +1/-1/+2/-2...+4/-4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *  6. default font pattern
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
         * This code assumes the name contains exactly 14 '-' delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * If not use default pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        int32_t i, length, pixelSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Boolean useDefault = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        char buffer[BUFSIZ], buffer2[BUFSIZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        char *family = NULL, *style = NULL, *slant = NULL, *encoding = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        char *start = NULL, *end = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (strlen(name) > BUFSIZ - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            useDefault = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            strcpy(buffer, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#define NEXT_HYPHEN\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        start = end + 1;\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        end = strchr(start, '-');\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (end == NULL) {\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                              useDefault = TRUE;\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        break;\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        *end = '\0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
             do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                 end = buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                 /* skip FOUNDRY */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                 /* set FAMILY_NAME */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                 family = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                 /* set STYLE_NAME */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                 style = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                 /* set SLANT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                 slant = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                 /* skip SETWIDTH_NAME, ADD_STYLE_NAME, PIXEL_SIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    POINT_SIZE, RESOLUTION_X, RESOLUTION_Y, SPACING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    and AVERAGE_WIDTH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                 NEXT_HYPHEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                 /* set CHARSET_REGISTRY and CHARSET_ENCODING */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                 encoding = end + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
             while (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
#define TRY_LOAD\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        f = XLoadQueryFont(display, buffer2);\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (f != NULL) {\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            strcpy(name, buffer2);\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return f;\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (!useDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            char *altstyle = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            /* Regular is the style for TrueType fonts -- Type1, F3 use roman */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (strcmp(style, "regular") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                altstyle = "roman";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   258
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (!strcmp(family, "lucidasans")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                family = "lucida";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            /* try 1. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                         "-*-%s-%s-%s-*-*-*-%d-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                         family, style, slant, pointSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (altstyle != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                             "-*-%s-%s-%s-*-*-*-%d-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                             family, altstyle, slant, pointSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            /* search bitmap font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            pixelSize = pointSize / 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            /* try 2. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                         "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                         family, style, slant, pixelSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (altstyle != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                             "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                             family, altstyle, slant, pixelSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            /* try 3 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                         "-*-*-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                         style, slant, pixelSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (altstyle != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                             "-*-*-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                             altstyle, slant, pixelSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            /* try 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                         "-*-*-*-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                         slant, pixelSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            /* try 5. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                         "-*-*-*-*-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                         pixelSize, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            /* try 6. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            for (i = 1; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                if (pixelSize < i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                             "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                             family, style, slant, pixelSize + i, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                             "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                             family, style, slant, pixelSize - i, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                             "-*-*-*-*-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                             pixelSize + i, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                jio_snprintf(buffer2, sizeof(buffer2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                             "-*-*-*-*-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                             pixelSize - i, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                TRY_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    strcpy(name, defaultXLFD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    return XLoadQueryFont(display, defaultXLFD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 * Hardwired list of mappings for generic font names "Helvetica",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 * "TimesRoman", "Courier", "Dialog", and "DialogInput".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
static char *defaultfontname = "fixed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
static char *defaultfoundry = "misc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
static char *anyfoundry = "*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
static char *anystyle = "*-*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static char *isolatin1 = "iso8859-1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
Style(int32_t s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    switch (s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        case java_awt_Font_ITALIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            return "medium-i";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        case java_awt_Font_BOLD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return "bold-r";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        case java_awt_Font_BOLD + java_awt_Font_ITALIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return "bold-i";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        case java_awt_Font_PLAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            return "medium-r";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
awtJNI_FontName(JNIEnv * env, jstring name, char **foundry, char **facename, char **encoding)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    char *cname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    if (JNU_IsNull(env, name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    cname = (char *) JNU_GetStringPlatformChars(env, name, NULL);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   383
    if (cname == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   384
        (*env)->ExceptionClear(env);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   385
        JNU_ThrowOutOfMemoryError(env, "Could not create font name");
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   386
        return 0;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   387
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /* additional default font names */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    if (strcmp(cname, "serif") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        *foundry = "adobe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        *facename = "times";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    } else if (strcmp(cname, "sansserif") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        *foundry = "adobe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        *facename = "helvetica";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    } else if (strcmp(cname, "monospaced") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        *foundry = "adobe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        *facename = "courier";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    } else if (strcmp(cname, "helvetica") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        *foundry = "adobe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        *facename = "helvetica";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    } else if (strcmp(cname, "timesroman") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        *foundry = "adobe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        *facename = "times";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    } else if (strcmp(cname, "courier") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        *foundry = "adobe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        *facename = "courier";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    } else if (strcmp(cname, "dialog") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        *foundry = "b&h";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        *facename = "lucida";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    } else if (strcmp(cname, "dialoginput") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        *foundry = "b&h";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        *facename = "lucidatypewriter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    } else if (strcmp(cname, "zapfdingbats") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        *foundry = "itc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        *facename = "zapfdingbats";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        *encoding = "*-*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        jio_fprintf(stderr, "Unknown font: %s\n", cname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        *foundry = defaultfoundry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        *facename = defaultfontname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        *encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    if (cname != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        JNU_ReleaseStringPlatformChars(env, name, (const char *) cname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
struct FontData *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
awtJNI_GetFontData(JNIEnv * env, jobject font, char **errmsg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /* We are going to create at most 4 outstanding local refs in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * function. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    if ((*env)->EnsureLocalCapacity(env, 4) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    if (!JNU_IsNull(env, font) && awtJNI_IsMultiFont(env, font)) {
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   451
        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   452
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        struct FontData *fdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        int32_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        char *fontsetname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        char *nativename = NULL;
23304
bb48872f9326 8035287: gcc warnings compiling various libraries files
mikael
parents: 12047
diff changeset
   457
        Boolean doFree = FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        jobjectArray componentFonts = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        jobject fontDescriptor = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        jstring fontDescriptorName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        jstring charsetName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        fdata = (struct FontData *) JNU_GetLongFieldAsPtr(env,font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                                         fontIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (fdata != NULL && fdata->flist != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            return fdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        size = (*env)->GetIntField(env, font, fontIDs.size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        fdata = (struct FontData *) malloc(sizeof(struct FontData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        peer = (*env)->CallObjectMethod(env, font, fontIDs.getPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        componentFonts =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
          (*env)->GetObjectField(env, peer, platformFontIDs.componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        /* We no longer need peer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        (*env)->DeleteLocalRef(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        fdata->charset_num = (*env)->GetArrayLength(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        fdata->flist = (awtFontList *) malloc(sizeof(awtFontList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                              * fdata->charset_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        fdata->xfont = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        for (i = 0; i < fdata->charset_num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
             * set xlfd name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            fontDescriptor = (*env)->GetObjectArrayElement(env, componentFonts, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            fontDescriptorName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
              (*env)->GetObjectField(env, fontDescriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                     fontDescriptorIDs.nativeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if (!JNU_IsNull(env, fontDescriptorName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                nativename = (char *) JNU_GetStringPlatformChars(env, fontDescriptorName, NULL);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   497
                if (nativename == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   498
                    nativename = "";
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   499
                    doFree = FALSE;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   500
                } else {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   501
                    doFree = TRUE;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   502
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                nativename = "";
23304
bb48872f9326 8035287: gcc warnings compiling various libraries files
mikael
parents: 12047
diff changeset
   505
                doFree = FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            fdata->flist[i].xlfd = malloc(strlen(nativename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                          + strlen(defaultXLFD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            jio_snprintf(fdata->flist[i].xlfd, strlen(nativename) + 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                         nativename, size * 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
23304
bb48872f9326 8035287: gcc warnings compiling various libraries files
mikael
parents: 12047
diff changeset
   513
            if (nativename != NULL && doFree)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                JNU_ReleaseStringPlatformChars(env, fontDescriptorName, (const char *) nativename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
             * set charset_name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            charsetName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
              (*env)->GetObjectField(env, fontDescriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                     fontDescriptorIDs.charsetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            fdata->flist[i].charset_name = (char *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                JNU_GetStringPlatformChars(env, charsetName, NULL);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   526
            if (fdata->flist[i].charset_name == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   527
                (*env)->ExceptionClear(env);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   528
                JNU_ThrowOutOfMemoryError(env, "Could not create charset name");
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   529
                return NULL;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23328
diff changeset
   530
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            /* We are done with the objects. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            (*env)->DeleteLocalRef(env, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            (*env)->DeleteLocalRef(env, fontDescriptorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            (*env)->DeleteLocalRef(env, charsetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
             * set load & XFontStruct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            fdata->flist[i].load = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
             * This appears to be a bogus check.  The actual intent appears
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
             * to be to find out whether this is the "base" font in a set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
             * rather than iso8859_1 explicitly.  Note that iso8859_15 will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
             * and must also pass this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            if (fdata->xfont == NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                strstr(fdata->flist[i].charset_name, "8859_1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                fdata->flist[i].xfont =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    loadFont(awt_display, fdata->flist[i].xlfd, size * 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                if (fdata->flist[i].xfont != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    fdata->flist[i].load = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    fdata->xfont = fdata->flist[i].xfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    fdata->flist[i].index_length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                } else {
24162
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   558
                    /* Free any already allocated storage and fonts */
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   559
                    int j = i;
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   560
                    for (j = 0; j <= i; j++) {
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   561
                        free((void *)fdata->flist[j].xlfd);
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   562
                        JNU_ReleaseStringPlatformChars(env, NULL,
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   563
                            fdata->flist[j].charset_name);
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   564
                        if (fdata->flist[j].load) {
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   565
                            XFreeFont(awt_display, fdata->flist[j].xfont);
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   566
                        }
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   567
                    }
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   568
                    free((void *)fdata->flist);
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   569
                    free((void *)fdata);
0fe6fb6759ab 8031095: [Parfait] warning from jdk/src/solaris/native/sun/awt: memory leak
prr
parents: 24130
diff changeset
   570
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    if (errmsg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                        *errmsg = "java/lang" "NullPointerException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    (*env)->DeleteLocalRef(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        (*env)->DeleteLocalRef(env, componentFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * XFontSet will create if the peer of TextField/TextArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        fdata->xfs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        JNU_SetLongFieldFromPtr(env,font,fontIDs.pData,fdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        Disposer_AddRecord(env, font, pDataDisposeMethod, ptr_to_jlong(fdata));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        return fdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        Display *display = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        struct FontData *fdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        char fontSpec[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        int32_t height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        int32_t oheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        int32_t above = 0;              /* tries above height */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        int32_t below = 0;              /* tries below height */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        char *foundry = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        char *name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        char *encoding = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        char *style = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        XFontStruct *xfont = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        jstring family = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (JNU_IsNull(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            if (errmsg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                *errmsg = "java/lang" "NullPointerException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            return (struct FontData *) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        display = XDISPLAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        fdata = (struct FontData *) JNU_GetLongFieldAsPtr(env,font,fontIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (fdata != NULL && fdata->xfont != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return fdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        family = (*env)->CallObjectMethod(env, font, fontIDs.getFamily);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (!awtJNI_FontName(env, family, &foundry, &name, &encoding)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            if (errmsg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                *errmsg = "java/lang" "NullPointerException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            (*env)->DeleteLocalRef(env, family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            return (struct FontData *) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        style = Style((*env)->GetIntField(env, font, fontIDs.style));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        oheight = height = (*env)->GetIntField(env, font, fontIDs.size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        while (1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            jio_snprintf(fontSpec, sizeof(fontSpec), "-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                         foundry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                         name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                         style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                         height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                         encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            /*fprintf(stderr,"LoadFont: %s\n", fontSpec); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            xfont = XLoadQueryFont(display, fontSpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            /* XXX: sometimes XLoadQueryFont returns a bogus font structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            /* with negative ascent. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            if (xfont == (Font) NULL || xfont->ascent < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                if (xfont != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    XFreeFont(display, xfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                if (foundry != anyfoundry) {  /* Use ptr comparison here, not strcmp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    /* Try any other foundry before messing with the sizes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    foundry = anyfoundry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                /* We couldn't find the font. We'll try to find an */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                /* alternate by searching for heights above and below our */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                /* preferred height. We try for 4 heights above and below. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                /* If we still can't find a font we repeat the algorithm */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                /* using misc-fixed as the font. If we then fail, then we */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                /* give up and signal an error. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                if (above == below) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    above++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    height = oheight + above;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                    below++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    if (below > 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                        if (name != defaultfontname || style != anystyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                            name = defaultfontname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                            foundry = defaultfoundry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                            height = oheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                            style = anystyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                            encoding = isolatin1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                            above = below = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                            if (errmsg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                *errmsg = "java/io/" "FileNotFoundException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                            (*env)->DeleteLocalRef(env, family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                            return (struct FontData *) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    height = oheight - below;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                fdata = ZALLOC(FontData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                if (fdata == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    if (errmsg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        *errmsg = "java/lang" "OutOfMemoryError";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    fdata->xfont = xfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    JNU_SetLongFieldFromPtr(env,font,fontIDs.pData,fdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    Disposer_AddRecord(env, font, pDataDisposeMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                                       ptr_to_jlong(fdata));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                (*env)->DeleteLocalRef(env, family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                return fdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        /* not reached */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
 * Registered with the 2D disposer to be called after the Font is GC'd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
static void pDataDisposeMethod(JNIEnv *env, jlong pData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    struct FontData *fdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    int32_t i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    Display *display = XDISPLAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    fdata = (struct FontData *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    if (fdata == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    if (fdata->xfs != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        XFreeFontSet(display, fdata->xfs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /* AWT fonts are always "multifonts" and probably have been in
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26751
diff changeset
   725
     * all post 1.0 releases, so this test for multi fonts is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * probably not needed, and the singleton xfont is probably never used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    if (fdata->charset_num > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        for (i = 0; i < fdata->charset_num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            free((void *)fdata->flist[i].xlfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            JNU_ReleaseStringPlatformChars(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                                           fdata->flist[i].charset_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            if (fdata->flist[i].load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                XFreeFont(display, fdata->flist[i].xfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        free((void *)fdata->flist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        /* Don't free fdata->xfont because it is equal to fdata->flist[i].xfont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
           for some 'i' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        if (fdata->xfont != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            XFreeFont(display, fdata->xfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    free((void *)fdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
#endif /* !HEADLESS */