jdk/src/java.desktop/unix/native/common/awt/fontpath.c
author prr
Fri, 19 Sep 2014 09:41:05 -0700
changeset 26751 70bac69b37c9
parent 25859 jdk/src/java.desktop/unix/native/common/sun/awt/fontpath.c@3317bb8137f4
child 29513 643ff69483e8
permissions -rw-r--r--
8056216: Remove "sun" directory layer from libawt and common Reviewed-by: erikj, ihse, coffeys
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: 22597
diff changeset
     2
 * Copyright (c) 1998, 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: 3931
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: 3931
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: 3931
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3931
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3931
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 18232
diff changeset
    26
#if defined(__linux__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#endif /* __linux__ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <strings.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sys/stat.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <sys/mman.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <sys/systeminfo.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <jni_util.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
    43
#include <jvm_md.h>
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
    44
#include <sizecalc.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include <X11/Xlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include <awt.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/* locks ought to be included from awt.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define AWT_LOCK()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define AWT_UNLOCK()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#if defined(__linux__) && !defined(MAP_FAILED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define MAP_FAILED ((caddr_t)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
extern Display *awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
    62
#define FONTCONFIG_DLL_VERSIONED VERSIONED_JNI_LIB_NAME("fontconfig", "1")
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
    63
#define FONTCONFIG_DLL JNI_LIB_NAME("fontconfig")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define MAXFDIRS 512    /* Max number of directories that contain fonts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
    67
#if defined(__solaris__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * This can be set in the makefile to "/usr/X11" if so desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#ifndef OPENWINHOMELIB
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#define OPENWINHOMELIB "/usr/openwin/lib/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/* This is all known Solaris X11 directories on Solaris 8, 9 and 10.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * It is ordered to give precedence to TrueType directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * It is needed if fontconfig is not installed or configured properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
static char *fullSolarisFontPath[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    OPENWINHOMELIB "X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    OPENWINHOMELIB "locale/euro_fonts/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    OPENWINHOMELIB "locale/iso_8859_2/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    OPENWINHOMELIB "locale/iso_8859_5/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    OPENWINHOMELIB "locale/iso_8859_7/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    OPENWINHOMELIB "locale/iso_8859_8/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    OPENWINHOMELIB "locale/iso_8859_9/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    OPENWINHOMELIB "locale/iso_8859_13/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    OPENWINHOMELIB "locale/iso_8859_15/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    OPENWINHOMELIB "locale/ar/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    OPENWINHOMELIB "locale/hi_IN.UTF-8/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    OPENWINHOMELIB "locale/ja/X11/fonts/TT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    OPENWINHOMELIB "locale/ko/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    OPENWINHOMELIB "locale/ko.UTF-8/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    OPENWINHOMELIB "locale/KOI8-R/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    OPENWINHOMELIB "locale/ru.ansi-1251/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    OPENWINHOMELIB "locale/th_TH/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    OPENWINHOMELIB "locale/zh_TW/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    OPENWINHOMELIB "locale/zh_TW.BIG5/X11/fonts/TT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    OPENWINHOMELIB "locale/zh_HK.BIG5HK/X11/fonts/TT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    OPENWINHOMELIB "locale/zh_CN.GB18030/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    OPENWINHOMELIB "locale/zh/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    OPENWINHOMELIB "locale/zh.GBK/X11/fonts/TrueType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    OPENWINHOMELIB "X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    OPENWINHOMELIB "X11/fonts/Type1/sun",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    OPENWINHOMELIB "X11/fonts/Type1/sun/outline",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    OPENWINHOMELIB "locale/iso_8859_2/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    OPENWINHOMELIB "locale/iso_8859_4/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    OPENWINHOMELIB "locale/iso_8859_5/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    OPENWINHOMELIB "locale/iso_8859_7/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    OPENWINHOMELIB "locale/iso_8859_8/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    OPENWINHOMELIB "locale/iso_8859_9/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    OPENWINHOMELIB "locale/iso_8859_13/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    OPENWINHOMELIB "locale/ar/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    NULL, /* terminates the list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   117
#elif defined( __linux__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/* All the known interesting locations we have discovered on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * various flavors of Linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
static char *fullLinuxFontPath[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    "/usr/X11R6/lib/X11/fonts/TrueType",  /* RH 7.1+ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    "/usr/X11R6/lib/X11/fonts/truetype",  /* SuSE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    "/usr/X11R6/lib/X11/fonts/tt",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    "/usr/X11R6/lib/X11/fonts/TTF",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    "/usr/X11R6/lib/X11/fonts/OTF",       /* RH 9.0 (but empty!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    "/usr/share/fonts/ja/TrueType",       /* RH 7.2+ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    "/usr/share/fonts/truetype",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    "/usr/share/fonts/ko/TrueType",       /* RH 9.0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    "/usr/share/fonts/zh_CN/TrueType",    /* RH 9.0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    "/usr/share/fonts/zh_TW/TrueType",    /* RH 9.0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType", /* Debian */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    "/usr/X11R6/lib/X11/fonts/Type1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    "/usr/share/fonts/default/Type1",     /* RH 9.0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    NULL, /* terminates the list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
};
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   137
#elif defined(_AIX)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   138
static char *fullAixFontPath[] = {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   139
    "/usr/lpp/X11/lib/X11/fonts/Type1",    /* from X11.fnt.iso_T1  */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   140
    "/usr/lpp/X11/lib/X11/fonts/TrueType", /* from X11.fnt.ucs.ttf */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   141
    NULL, /* terminates the list */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   142
};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
static char **getFontConfigLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    const char *name[MAXFDIRS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    int  num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
} fDirRecord, *fDirRecordPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Returns True if display is local, False of it's remote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
jboolean isDisplayLocal(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    static jboolean isLocal = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static jboolean isLocalSet = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    jboolean ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   162
    if (! isLocalSet) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   163
      jclass geCls = (*env)->FindClass(env, "java/awt/GraphicsEnvironment");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
   164
      CHECK_NULL_RETURN(geCls, JNI_FALSE);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   165
      jmethodID getLocalGE = (*env)->GetStaticMethodID(env, geCls,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   166
                                                 "getLocalGraphicsEnvironment",
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   167
                                           "()Ljava/awt/GraphicsEnvironment;");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
   168
      CHECK_NULL_RETURN(getLocalGE, JNI_FALSE);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   169
      jobject ge = (*env)->CallStaticObjectMethod(env, geCls, getLocalGE);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
   170
      JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   171
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   172
      jclass sgeCls = (*env)->FindClass(env,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   173
                                        "sun/java2d/SunGraphicsEnvironment");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
   174
      CHECK_NULL_RETURN(sgeCls, JNI_FALSE);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   175
      if ((*env)->IsInstanceOf(env, ge, sgeCls)) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   176
        jmethodID isDisplayLocal = (*env)->GetMethodID(env, sgeCls,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   177
                                                       "isDisplayLocal",
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   178
                                                       "()Z");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
   179
        JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   180
        isLocal = (*env)->CallBooleanMethod(env, ge, isDisplayLocal);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   181
      } else {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   182
        isLocal = True;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   183
      }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   184
      isLocalSet = True;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    return isLocal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
static void AddFontsToX11FontPath ( fDirRecord *fDirP )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    char *onePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    int index, nPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    int origNumPaths, length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    int origIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    int totalDirCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    char  **origFontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    char  **tempFontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    int doNotAppend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    int *appendDirList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    char **newFontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    int err, compareLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    char fontDirPath[512];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    int dirFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    doNotAppend = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if ( fDirP->num == 0 ) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   210
    appendDirList = SAFE_SIZE_ARRAY_ALLOC(malloc, fDirP->num, sizeof ( int ));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if ( appendDirList == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      return;  /* if it fails we cannot do much */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    origFontPath = XGetFontPath ( awt_display, &nPaths );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    totalDirCount = nPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    origNumPaths = nPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    tempFontPath = origFontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    for (index = 0; index < fDirP->num; index++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        doNotAppend = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        tempFontPath = origFontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            onePath = *tempFontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            compareLength = strlen ( onePath );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if ( onePath[compareLength -1] == '/' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
              compareLength--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            /* there is a slash at the end of every solaris X11 font path name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if ( strncmp ( onePath, fDirP->name[index], compareLength ) == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
              doNotAppend = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            tempFontPath++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        appendDirList[index] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if ( doNotAppend == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            strcpy ( fontDirPath, fDirP->name[index] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            strcat ( fontDirPath, "/fonts.dir" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            dirFile = open ( fontDirPath, O_RDONLY, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if ( dirFile == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                doNotAppend = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
               close ( dirFile );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
               totalDirCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
               appendDirList[index] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /* if no changes are required do not bother to do a setfontpath */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    if ( totalDirCount == nPaths ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      free ( ( void *) appendDirList );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      XFreeFontPath ( origFontPath );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   267
    newFontPath = SAFE_SIZE_ARRAY_ALLOC(malloc, totalDirCount, sizeof ( char **) );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /* if it fails free things and get out */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    if ( newFontPath == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      free ( ( void *) appendDirList );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      XFreeFontPath ( origFontPath );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      onePath = origFontPath[origIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
      newFontPath[origIndex] = onePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /* now add the other font paths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    for (index = 0; index < fDirP->num; index++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      if ( appendDirList[index] == 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        /* printf ( "Appending %s\n", fDirP->name[index] ); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   288
        onePath = SAFE_SIZE_ARRAY_ALLOC(malloc, strlen (fDirP->name[index]) + 2, sizeof( char ) );
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   289
        if (onePath == NULL) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   290
            free ( ( void *) appendDirList );
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   291
            XFreeFontPath ( origFontPath );
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   292
            return;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 16734
diff changeset
   293
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        strcpy ( onePath, fDirP->name[index] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        strcat ( onePath, "/" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        newFontPath[nPaths++] = onePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        /* printf ( "The path to be appended is %s\n", onePath ); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /*   printf ( "The dir count = %d\n", totalDirCount ); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    free ( ( void *) appendDirList );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    XSetFontPath ( awt_display, newFontPath, totalDirCount );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        for ( index = origNumPaths; index < totalDirCount; index++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                free( newFontPath[index] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        free ( (void *) newFontPath );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    XFreeFontPath ( origFontPath );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
static char **getX11FontPath ()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    char **x11Path, **fontdirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    int i, pos, slen, nPaths, numDirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    x11Path = XGetFontPath (awt_display, &nPaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /* This isn't ever going to be perfect: the font path may contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * much we aren't interested in, but the cost should be moderate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Exclude all directories that contain the strings "Speedo","/F3/",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * "75dpi", "100dpi", "misc" or "bitmap", or don't begin with a "/",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * the last of which should exclude font servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Also exclude the user specific ".gnome*" directories which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * aren't going to contain the system fonts we need.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Hopefully we are left only with Type1 and TrueType directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * It doesn't matter much if there are extraneous directories, it'll just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * cost us a little wasted effort upstream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    for (i=0; i < nPaths; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (x11Path[i][0] != '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (strstr(x11Path[i], "/75dpi") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (strstr(x11Path[i], "/100dpi") != NULL) {
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
        if (strstr(x11Path[i], "/misc") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (strstr(x11Path[i], "/Speedo") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (strstr(x11Path[i], ".gnome") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (strstr(x11Path[i], "/F3/") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (strstr(x11Path[i], "bitmap") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        fontdirs[pos] = strdup(x11Path[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        slen = strlen(fontdirs[pos]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (slen > 0 && fontdirs[pos][slen-1] == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            fontdirs[pos][slen-1] = '\0'; /* null out trailing "/"  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    XFreeFontPath(x11Path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    if (pos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        free(fontdirs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        fontdirs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    return fontdirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 18232
diff changeset
   384
#if defined(__linux__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
/* from awt_LoadLibrary.c */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
JNIEXPORT jboolean JNICALL AWTIsHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
/* This eliminates duplicates, at a non-linear but acceptable cost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 * since the lists are expected to be reasonably short, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 * deletes references to non-existent directories, and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 * a single path consisting of unique font directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
static char* mergePaths(char **p1, char **p2, char **p3, jboolean noType1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    int len1=0, len2=0, len3=0, totalLen=0, numDirs=0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        currLen, i, j, found, pathLen=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    char **ptr, **fontdirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    char *fontPath = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    if (p1 != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        ptr = p1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        while (*ptr++ != NULL) len1++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    if (p2 != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        ptr = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        while (*ptr++ != NULL) len2++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    if (p3 != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        ptr = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        while (*ptr++ != NULL) len3++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    totalLen = len1+len2+len3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    fontdirs = (char**)calloc(totalLen, sizeof(char*));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    for (i=0; i < len1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (noType1 && strstr(p1[i], "Type1") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        fontdirs[numDirs++] = p1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    currLen = numDirs; /* only compare against previous path dirs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    for (i=0; i < len2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (noType1 && strstr(p2[i], "Type1") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        found = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        for (j=0; j < currLen; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (strcmp(fontdirs[j], p2[i]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                found = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
           fontdirs[numDirs++] = p2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    currLen = numDirs; /* only compare against previous path dirs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    for (i=0; i < len3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (noType1 && strstr(p3[i], "Type1") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        found = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        for (j=0; j < currLen; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (strcmp(fontdirs[j], p3[i]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                found = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
           fontdirs[numDirs++] = p3[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /* Now fontdirs contains unique dirs and numDirs records how many.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * What we don't know is if they all exist. On reflection I think
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * this isn't an issue, so for now I will return all these locations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * converted to one string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    for (i=0; i<numDirs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        pathLen += (strlen(fontdirs[i]) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    if (pathLen > 0 && (fontPath = malloc(pathLen))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        *fontPath = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        for (i = 0; i<numDirs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            if (i != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                strcat(fontPath, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            strcat(fontPath, fontdirs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    free (fontdirs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    return fontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
 * The goal of this function is to find all "system" fonts which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
 * are needed by the JRE to display text in supported locales etc, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
 * to support APIs which allow users to enumerate all system fonts and use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
 * them from their Java applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
 * The preferred mechanism is now using the new "fontconfig" library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
 * This exists on newer versions of Linux and Solaris (S10 and above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
 * The library is dynamically located. The results are merged with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
 * a set of "known" locations and with the X11 font path, if running in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
 * a local X11 environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 * The hardwired paths are built into the JDK binary so as new font locations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
 * are created on a host plaform for them to be located by the JRE they will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 * need to be added ito the host's font configuration database, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
 * /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
 * NB: Fontconfig also depends heavily for performance on the host O/S
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
 * maintaining up to date caches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
 * This is consistent with the requirements of the desktop environments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
 * on these OSes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
 * This also frees us from X11 APIs as JRE is required to function in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
 * a "headless" mode where there is no Xserver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /* As of 1.5 we try to use fontconfig on both Solaris and Linux.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * If its not available NULL is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    fcdirs = getFontConfigLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
   509
#if defined(__linux__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    knowndirs = fullLinuxFontPath;
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   511
#elif defined(__solaris__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    knowndirs = fullSolarisFontPath;
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   513
#elif defined(_AIX)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   514
    knowndirs = fullAixFontPath;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /* REMIND: this code requires to be executed when the GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * is already initialised. That is always true, but if it were not so,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * this code could throw an exception and the fontpath would fail to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * be initialised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
#ifndef HEADLESS
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 18232
diff changeset
   522
#if defined(__linux__)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
   523
    /* There's no headless build on linux ... */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    if (!AWTIsHeadless()) { /* .. so need to call a function to check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
#endif
7932
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   526
      /* Using the X11 font path to locate font files is now a fallback
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   527
       * useful only if fontconfig failed, or is incomplete. So we could
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   528
       * remove this code completely and the consequences should be rare
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   529
       * and non-fatal. If this happens, then the calling Java code can
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   530
       * be modified to no longer require that the AWT lock (the X11GE)
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   531
       * be initialised prior to calling this code.
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   532
       */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    if (isDisplayLocal(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        x11dirs = getX11FontPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    AWT_UNLOCK();
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 18232
diff changeset
   538
#if defined(__linux__)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    path = mergePaths(fcdirs, x11dirs, knowndirs, noType1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    if (fcdirs != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        char **p = fcdirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        while (*p != NULL)  free(*p++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        free(fcdirs);
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 (x11dirs != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        char **p = x11dirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        while (*p != NULL) free(*p++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        free(x11dirs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
7932
f4ec6ef455c3 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents: 7151
diff changeset
   558
JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPathNative
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   559
(JNIEnv *env, jobject thiz, jboolean noType1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    jstring ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    static char *ptr = NULL; /* retain result across calls */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    if (ptr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        ptr = getPlatformFontPathChars(env, noType1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    ret = (*env)->NewStringUTF(env, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
#include "fontconfig.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
static void* openFontConfig() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    char *homeEnv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    static char *homeEnvStr = "HOME="; /* must be static */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    void* libfontconfig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
#define SYSINFOBUFSZ 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    char sysinfobuf[SYSINFOBUFSZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /* Private workaround to not use fontconfig library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * May be useful during testing/debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    char *useFC = getenv("USE_J2D_FONTCONFIG");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    if (useFC != NULL && !strcmp(useFC, "no")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /* fontconfig is likely not properly configured on S8/S9 - skip it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * although allow user to override this behaviour with an env. variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * ie if USE_J2D_FONTCONFIG=yes then we skip this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * NB "4" is the length of a string which matches our patterns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    if (useFC == NULL || strcmp(useFC, "yes")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (sysinfo(SI_RELEASE, sysinfobuf, SYSINFOBUFSZ) == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if ((!strcmp(sysinfobuf, "5.8") || !strcmp(sysinfobuf, "5.9"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
#endif
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   607
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   608
#if defined(_AIX)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   609
    /* On AIX, fontconfig is not a standard package supported by IBM.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   610
     * instead it has to be installed from the "AIX Toolbox for Linux Applications"
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   611
     * site http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/alpha.html
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   612
     * and will be installed under /opt/freeware/lib/libfontconfig.a.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   613
     * Notice that the archive contains the real 32- and 64-bit shared libraries.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   614
     * We first try to load 'libfontconfig.so' from the default library path in the
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   615
     * case the user has installed a private version of the library and if that
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   616
     * doesn't succeed, we try the version from /opt/freeware/lib/libfontconfig.a
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   617
     */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   618
    libfontconfig = dlopen("libfontconfig.so", RTLD_LOCAL|RTLD_LAZY);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   619
    if (libfontconfig == NULL) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   620
        libfontconfig = dlopen("/opt/freeware/lib/libfontconfig.a(libfontconfig.so.1)", RTLD_MEMBER|RTLD_LOCAL|RTLD_LAZY);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   621
        if (libfontconfig == NULL) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   622
            return NULL;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   623
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   624
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   625
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /* 64 bit sparc should pick up the right version from the lib path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * New features may be added to libfontconfig, this is expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * be compatible with old features, but we may need to start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * distinguishing the library version, to know whether to expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * certain symbols - and functionality - to be available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * Also add explicit search for .so.1 in case .so symlink doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
   633
    libfontconfig = dlopen(FONTCONFIG_DLL_VERSIONED, RTLD_LOCAL|RTLD_LAZY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    if (libfontconfig == NULL) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 10407
diff changeset
   635
        libfontconfig = dlopen(FONTCONFIG_DLL, RTLD_LOCAL|RTLD_LAZY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        if (libfontconfig == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
   640
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /* Version 1.0 of libfontconfig crashes if HOME isn't defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * the environment. This should generally never happen, but we can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * control it, and can't control the version of fontconfig, so iff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * its not defined we set it to an empty value which is sufficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * to prevent a crash. I considered unsetting it before exit, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * it doesn't appear to work on Solaris, so I will leave it set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    homeEnv = getenv("HOME");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    if (homeEnv == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        putenv(homeEnvStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    return libfontconfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
typedef void* (FcFiniFuncType)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
static void closeFontConfig(void* libfontconfig, jboolean fcFini) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
  /* NB FcFini is not in (eg) the Solaris 10 version of fontconfig. Its not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
   * clear if this means we are really leaking resources in those cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
   * but it seems we should call this function when its available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
   * But since the Swing GTK code may be still accessing the lib, its probably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
   * safest for now to just let this "leak" rather than potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
   * concurrently free global data still in use by other code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
#if 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    if (fcFini) { /* release resources */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        FcFiniFuncType FcFini = (FcFiniFuncType)dlsym(libfontconfig, "FcFini");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (FcFini != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            (*FcFini)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    dlclose(libfontconfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
typedef FcConfig* (*FcInitLoadConfigFuncType)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
typedef FcPattern* (*FcPatternBuildFuncType)(FcPattern *orig, ...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
typedef FcObjectSet* (*FcObjectSetFuncType)(const char *first, ...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
typedef FcFontSet* (*FcFontListFuncType)(FcConfig *config,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                         FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                         FcObjectSet *os);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
typedef FcResult (*FcPatternGetBoolFuncType)(const FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                               const char *object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                               int n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                                               FcBool *b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
typedef FcResult (*FcPatternGetIntegerFuncType)(const FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                                const char *object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                                int n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                                                int *i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
typedef FcResult (*FcPatternGetStringFuncType)(const FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                                               const char *object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                                               int n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                                               FcChar8 ** s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
typedef FcChar8* (*FcStrDirnameFuncType)(const FcChar8 *file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
typedef void (*FcPatternDestroyFuncType)(FcPattern *p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
typedef void (*FcFontSetDestroyFuncType)(FcFontSet *s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
typedef FcPattern* (*FcNameParseFuncType)(const FcChar8 *name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
typedef FcBool (*FcPatternAddStringFuncType)(FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                                             const char *object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                                             const FcChar8 *s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
typedef void (*FcDefaultSubstituteFuncType)(FcPattern *p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
typedef FcBool (*FcConfigSubstituteFuncType)(FcConfig *config,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                                             FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                                             FcMatchKind kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
typedef FcPattern* (*FcFontMatchFuncType)(FcConfig *config,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                                          FcPattern *p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                                          FcResult *result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
typedef FcFontSet* (*FcFontSetCreateFuncType)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   715
typedef FcResult (*FcPatternGetCharSetFuncType)(FcPattern *p,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   716
                                                const char *object,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   717
                                                int n,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   718
                                                FcCharSet **c);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   719
typedef FcFontSet* (*FcFontSortFuncType)(FcConfig *config,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   720
                                         FcPattern *p,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   721
                                         FcBool trim,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   722
                                         FcCharSet **csp,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   723
                                         FcResult *result);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   724
typedef FcCharSet* (*FcCharSetUnionFuncType)(const FcCharSet *a,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   725
                                             const FcCharSet *b);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   726
typedef FcChar32 (*FcCharSetSubtractCountFuncType)(const FcCharSet *a,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   727
                                                   const FcCharSet *b);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   728
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   729
typedef int (*FcGetVersionFuncType)();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   730
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   731
typedef FcStrList* (*FcConfigGetCacheDirsFuncType)(FcConfig *config);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   732
typedef FcChar8* (*FcStrListNextFuncType)(FcStrList *list);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   733
typedef FcChar8* (*FcStrListDoneFuncType)(FcStrList *list);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
static char **getFontConfigLocations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    char **fontdirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    int numdirs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    FcInitLoadConfigFuncType FcInitLoadConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    FcPatternBuildFuncType FcPatternBuild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    FcObjectSetFuncType FcObjectSetBuild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    FcFontListFuncType FcFontList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    FcPatternGetStringFuncType FcPatternGetString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    FcStrDirnameFuncType FcStrDirname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    FcPatternDestroyFuncType FcPatternDestroy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    FcFontSetDestroyFuncType FcFontSetDestroy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    FcConfig *fontconfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    FcPattern *pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    FcObjectSet *objset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    FcFontSet *fontSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    FcStrList *strList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    FcChar8 *str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    int i, f, found, len=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    char **fontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    void* libfontconfig = openFontConfig();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    if (libfontconfig == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    FcPatternBuild     =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        (FcPatternBuildFuncType)dlsym(libfontconfig, "FcPatternBuild");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    FcObjectSetBuild   =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        (FcObjectSetFuncType)dlsym(libfontconfig, "FcObjectSetBuild");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    FcFontList         =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        (FcFontListFuncType)dlsym(libfontconfig, "FcFontList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    FcPatternGetString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        (FcPatternGetStringFuncType)dlsym(libfontconfig, "FcPatternGetString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    FcStrDirname       =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        (FcStrDirnameFuncType)dlsym(libfontconfig, "FcStrDirname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    FcPatternDestroy   =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        (FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    FcFontSetDestroy   =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        (FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    if (FcPatternBuild     == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        FcObjectSetBuild   == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        FcPatternGetString == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        FcFontList         == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        FcStrDirname       == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        FcPatternDestroy   == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        FcFontSetDestroy   == NULL) { /* problem with the library: return. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        closeFontConfig(libfontconfig, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /* Make calls into the fontconfig library to build a search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * outline fonts, and to get the set of full file paths from the matches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * This set is returned from the call to FcFontList(..)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * We allocate an array of char* pointers sufficient to hold all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * the matches + 1 extra which ensures there will be a NULL after all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * valid entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * We call FcStrDirname strip the file name from the path, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * check if we have yet seen this directory. If not we add a pointer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * it into our array of char*. Note that FcStrDirname returns newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * allocated storage so we can use this in the return char** value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Finally we clean up, freeing allocated resources, and return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * array of unique directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    pattern = (*FcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    objset = (*FcObjectSetBuild)(FC_FILE, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    fontSet = (*FcFontList)(NULL, pattern, objset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    for (f=0; f < fontSet->nfont; f++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        FcChar8 *file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        FcChar8 *dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                                  FcResultMatch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            dir = (*FcStrDirname)(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            found = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            for (i=0;i<numdirs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                if (strcmp(fontdirs[i], (char*)dir) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    found = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                fontdirs[numdirs++] = (char*)dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                free((char*)dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /* Free memory and close the ".so" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    (*FcFontSetDestroy)(fontSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    (*FcPatternDestroy)(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    closeFontConfig(libfontconfig, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    return fontdirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
/* These are copied from sun.awt.SunHints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
 * Consider initialising them as ints using JNI for more robustness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
#define TEXT_AA_OFF 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
#define TEXT_AA_ON  2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
#define TEXT_AA_LCD_HRGB 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
#define TEXT_AA_LCD_HBGR 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
#define TEXT_AA_LCD_VRGB 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
#define TEXT_AA_LCD_VBGR 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
JNIEXPORT jint JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   845
Java_sun_font_FontConfigManager_getFontConfigAASettings
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
(JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    FcNameParseFuncType FcNameParse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    FcPatternAddStringFuncType FcPatternAddString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    FcConfigSubstituteFuncType FcConfigSubstitute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    FcDefaultSubstituteFuncType  FcDefaultSubstitute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    FcFontMatchFuncType FcFontMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    FcPatternGetBoolFuncType FcPatternGetBool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    FcPatternGetIntegerFuncType FcPatternGetInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    FcPatternDestroyFuncType FcPatternDestroy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    FcPattern *pattern, *matchPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    FcResult result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    FcBool antialias = FcFalse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    int rgba = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    const char *locale=NULL, *fcName=NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    void* libfontconfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    if (fcNameStr == NULL || localeStr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    if (fcName == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    locale = (*env)->GetStringUTFChars(env, localeStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    if ((libfontconfig = openFontConfig()) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        if (locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            (*env)->ReleaseStringUTFChars (env, localeStr,(const char*)locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    FcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    FcPatternAddString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        (FcPatternAddStringFuncType)dlsym(libfontconfig, "FcPatternAddString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    FcConfigSubstitute =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        (FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    FcDefaultSubstitute = (FcDefaultSubstituteFuncType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        dlsym(libfontconfig, "FcDefaultSubstitute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    FcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    FcPatternGetBool = (FcPatternGetBoolFuncType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        dlsym(libfontconfig, "FcPatternGetBool");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    FcPatternGetInteger = (FcPatternGetIntegerFuncType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        dlsym(libfontconfig, "FcPatternGetInteger");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    FcPatternDestroy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        (FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    if (FcNameParse          == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        FcPatternAddString   == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        FcConfigSubstitute   == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        FcDefaultSubstitute  == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        FcFontMatch          == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        FcPatternGetBool     == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        FcPatternGetInteger  == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        FcPatternDestroy     == NULL) { /* problem with the library: return. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            (*env)->ReleaseStringUTFChars (env, localeStr,(const char*)locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        closeFontConfig(libfontconfig, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    pattern = (*FcNameParse)((FcChar8 *)fcName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    if (locale != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        (*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    (*FcConfigSubstitute)(NULL, pattern, FcMatchPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    (*FcDefaultSubstitute)(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    matchPattern = (*FcFontMatch)(NULL, pattern, &result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /* Perhaps should call FcFontRenderPrepare() here as some pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * elements might change as a result of that call, but I'm not seeing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * any difference in testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    if (matchPattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        (*FcPatternGetBool)(matchPattern, FC_ANTIALIAS, 0, &antialias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        (*FcPatternGetInteger)(matchPattern, FC_RGBA, 0, &rgba);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        (*FcPatternDestroy)(matchPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    (*FcPatternDestroy)(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    if (locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    closeFontConfig(libfontconfig, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    if (antialias == FcFalse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        return TEXT_AA_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    } else if (rgba <= FC_RGBA_UNKNOWN || rgba >= FC_RGBA_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        return TEXT_AA_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        switch (rgba) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        case FC_RGBA_RGB : return TEXT_AA_LCD_HRGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        case FC_RGBA_BGR : return TEXT_AA_LCD_HBGR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        case FC_RGBA_VRGB : return TEXT_AA_LCD_VRGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        case FC_RGBA_VBGR : return TEXT_AA_LCD_VBGR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        default : return TEXT_AA_LCD_HRGB; // should not get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   954
JNIEXPORT jint JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   955
Java_sun_font_FontConfigManager_getFontConfigVersion
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   956
    (JNIEnv *env, jclass obj) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   957
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   958
    void* libfontconfig;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   959
    FcGetVersionFuncType FcGetVersion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   960
    int version = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   961
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   962
    if ((libfontconfig = openFontConfig()) == NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   963
        return 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   964
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   965
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   966
    FcGetVersion = (FcGetVersionFuncType)dlsym(libfontconfig, "FcGetVersion");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   967
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   968
    if (FcGetVersion == NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   969
        closeFontConfig(libfontconfig, JNI_FALSE);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   970
        return 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   971
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   972
    version = (*FcGetVersion)();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   973
    closeFontConfig(libfontconfig, JNI_FALSE);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   974
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   975
    return version;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   976
}
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   977
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
JNIEXPORT void JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
   980
Java_sun_font_FontConfigManager_getFontConfig
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   981
(JNIEnv *env, jclass obj, jstring localeStr, jobject fcInfoObj,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   982
 jobjectArray fcCompFontArray,  jboolean includeFallbacks) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    FcNameParseFuncType FcNameParse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    FcPatternAddStringFuncType FcPatternAddString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    FcConfigSubstituteFuncType FcConfigSubstitute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    FcDefaultSubstituteFuncType  FcDefaultSubstitute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    FcFontMatchFuncType FcFontMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    FcPatternGetStringFuncType FcPatternGetString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    FcPatternDestroyFuncType FcPatternDestroy;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   991
    FcPatternGetCharSetFuncType FcPatternGetCharSet;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   992
    FcFontSortFuncType FcFontSort;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   993
    FcFontSetDestroyFuncType FcFontSetDestroy;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   994
    FcCharSetUnionFuncType FcCharSetUnion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   995
    FcCharSetSubtractCountFuncType FcCharSetSubtractCount;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   996
    FcGetVersionFuncType FcGetVersion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   997
    FcConfigGetCacheDirsFuncType FcConfigGetCacheDirs;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   998
    FcStrListNextFuncType FcStrListNext;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   999
    FcStrListDoneFuncType FcStrListDone;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    int i, arrlen;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1002
    jobject fcCompFontObj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    jstring fcNameStr, jstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    const char *locale, *fcName;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1005
    FcPattern *pattern;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    FcResult result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    void* libfontconfig;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1008
    jfieldID fcNameID, fcFirstFontID, fcAllFontsID, fcVersionID, fcCacheDirsID;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1009
    jfieldID familyNameID, styleNameID, fullNameID, fontFileID;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1010
    jmethodID fcFontCons;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1011
    char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1013
    CHECK_NULL(fcInfoObj);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1014
    CHECK_NULL(fcCompFontArray);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1015
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1016
    jclass fcInfoClass =
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
  1017
        (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1018
    CHECK_NULL(fcInfoClass);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1019
    jclass fcCompFontClass =
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
  1020
        (*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1021
    CHECK_NULL(fcCompFontClass);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1022
    jclass fcFontClass =
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1731
diff changeset
  1023
         (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1024
    CHECK_NULL(fcFontClass);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1025
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1026
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1027
    CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1028
    CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1029
                                                  "[Ljava/lang/String;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1030
    CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1031
                                             "fcName", "Ljava/lang/String;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1032
    CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1033
                                        "Lsun/font/FontConfigManager$FontConfigFont;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1034
    CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1035
                                        "[Lsun/font/FontConfigManager$FontConfigFont;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1036
    CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1037
    CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass,
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1038
                                      "familyName", "Ljava/lang/String;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1039
    CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass,
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1040
                                    "styleStr", "Ljava/lang/String;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1041
    CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass,
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1042
                                    "fullName", "Ljava/lang/String;"));
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1043
    CHECK_NULL(fontFileID = (*env)->GetFieldID(env, fcFontClass,
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1044
                                    "fontFile", "Ljava/lang/String;"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    if ((libfontconfig = openFontConfig()) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    FcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    FcPatternAddString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        (FcPatternAddStringFuncType)dlsym(libfontconfig, "FcPatternAddString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    FcConfigSubstitute =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        (FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    FcDefaultSubstitute = (FcDefaultSubstituteFuncType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        dlsym(libfontconfig, "FcDefaultSubstitute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    FcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    FcPatternGetString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        (FcPatternGetStringFuncType)dlsym(libfontconfig, "FcPatternGetString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    FcPatternDestroy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        (FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1062
    FcPatternGetCharSet =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1063
        (FcPatternGetCharSetFuncType)dlsym(libfontconfig,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1064
                                           "FcPatternGetCharSet");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1065
    FcFontSort =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1066
        (FcFontSortFuncType)dlsym(libfontconfig, "FcFontSort");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1067
    FcFontSetDestroy =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1068
        (FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1069
    FcCharSetUnion =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1070
        (FcCharSetUnionFuncType)dlsym(libfontconfig, "FcCharSetUnion");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1071
    FcCharSetSubtractCount =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1072
        (FcCharSetSubtractCountFuncType)dlsym(libfontconfig,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1073
                                              "FcCharSetSubtractCount");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1074
    FcGetVersion = (FcGetVersionFuncType)dlsym(libfontconfig, "FcGetVersion");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    if (FcNameParse          == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        FcPatternAddString   == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        FcConfigSubstitute   == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        FcDefaultSubstitute  == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        FcFontMatch          == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        FcPatternGetString   == NULL ||
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1082
        FcPatternDestroy     == NULL ||
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1083
        FcPatternGetCharSet  == NULL ||
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1084
        FcFontSetDestroy     == NULL ||
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1085
        FcCharSetUnion       == NULL ||
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1086
        FcGetVersion         == NULL ||
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1087
        FcCharSetSubtractCount == NULL) {/* problem with the library: return.*/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        closeFontConfig(libfontconfig, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1092
    (*env)->SetIntField(env, fcInfoObj, fcVersionID, (*FcGetVersion)());
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1093
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1094
    /* Optionally get the cache dir locations. This isn't
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1095
     * available until v 2.4.x, but this is OK since on those later versions
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1096
     * we can check the time stamps on the cache dirs to see if we
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1097
     * are out of date. There are a couple of assumptions here. First
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1098
     * that the time stamp on the directory changes when the contents are
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1099
     * updated. Secondly that the locations don't change. The latter is
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1100
     * most likely if a new version of fontconfig is installed, but we also
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1101
     * invalidate the cache if we detect that. Arguably even that is "rare",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1102
     * and most likely is tied to an OS upgrade which gets a new file anyway.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1103
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1104
    FcConfigGetCacheDirs =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1105
        (FcConfigGetCacheDirsFuncType)dlsym(libfontconfig,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1106
                                            "FcConfigGetCacheDirs");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1107
    FcStrListNext =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1108
        (FcStrListNextFuncType)dlsym(libfontconfig, "FcStrListNext");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1109
    FcStrListDone =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1110
        (FcStrListDoneFuncType)dlsym(libfontconfig, "FcStrListDone");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1111
    if (FcStrListNext != NULL && FcStrListDone != NULL &&
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1112
        FcConfigGetCacheDirs != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1113
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1114
        FcStrList* cacheDirs;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1115
        FcChar8* cacheDir;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1116
        int cnt = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1117
        jobject cacheDirArray =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1118
            (*env)->GetObjectField(env, fcInfoObj, fcCacheDirsID);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1119
        int max = (*env)->GetArrayLength(env, cacheDirArray);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1120
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1121
        cacheDirs = (*FcConfigGetCacheDirs)(NULL);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1122
        if (cacheDirs != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1123
            while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1124
                jstr = (*env)->NewStringUTF(env, (const char*)cacheDir);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1125
                JNU_CHECK_EXCEPTION(env);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1126
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1127
                (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1128
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1129
            (*FcStrListDone)(cacheDirs);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1130
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1131
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1132
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    locale = (*env)->GetStringUTFChars(env, localeStr, 0);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1134
    if (locale == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1135
        (*env)->ExceptionClear(env);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1136
        JNU_ThrowOutOfMemoryError(env, "Could not create locale");
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1137
        return;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 22597
diff changeset
  1138
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1140
    arrlen = (*env)->GetArrayLength(env, fcCompFontArray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    for (i=0; i<arrlen; i++) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1142
        FcFontSet* fontset;
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 9035
diff changeset
  1143
        int fn, j, fontCount, nfonts;
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 9035
diff changeset
  1144
        unsigned int minGlyphs;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1145
        FcChar8 **family, **styleStr, **fullname, **file;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1146
        jarray fcFontArr;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1147
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1148
        fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        fcNameStr =
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1150
            (jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        if (fcName == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        pattern = (*FcNameParse)((FcChar8 *)fcName);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1156
        if (pattern == NULL) {
7949
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1157
            (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1158
            closeFontConfig(libfontconfig, JNI_FALSE);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1159
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1160
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1161
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        /* locale may not usually be necessary as fontconfig appears to apply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
         * this anyway based on the user's environment. However we want
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
         * to use the value of the JDK startup locale so this should take
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
         * care of it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        if (locale != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            (*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        (*FcConfigSubstitute)(NULL, pattern, FcMatchPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        (*FcDefaultSubstitute)(pattern);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1172
        fontset = (*FcFontSort)(NULL, pattern, FcTrue, NULL, &result);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1173
        if (fontset == NULL) {
7949
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1174
            (*FcPatternDestroy)(pattern);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1175
            (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1176
            closeFontConfig(libfontconfig, JNI_FALSE);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1177
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1178
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1180
        /* fontconfig returned us "nfonts". If we are just getting the
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1181
         * first font, we set nfont to zero. Otherwise we use "nfonts".
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1182
         * Next create separate C arrrays of length nfonts for family file etc.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1183
         * Inspect the returned fonts and the ones we like (adds enough glyphs)
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1184
         * are added to the arrays and we increment 'fontCount'.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1185
         */
3931
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1186
        nfonts = fontset->nfont;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1187
        family   = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1188
        styleStr = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1189
        fullname = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1190
        file     = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1191
        if (family == NULL || styleStr == NULL ||
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1192
            fullname == NULL || file == NULL) {
7949
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1193
            if (family != NULL) {
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1194
                free(family);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1195
            }
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1196
            if (styleStr != NULL) {
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1197
                free(styleStr);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1198
            }
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1199
            if (fullname != NULL) {
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1200
                free(fullname);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1201
            }
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1202
            if (file != NULL) {
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1203
                free(file);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1204
            }
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1205
            (*FcPatternDestroy)(pattern);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1206
            (*FcFontSetDestroy)(fontset);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1207
            (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1208
            closeFontConfig(libfontconfig, JNI_FALSE);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1209
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1210
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1211
        fontCount = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1212
        minGlyphs = 20;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1213
        if (debugMinGlyphsStr != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1214
            int val = minGlyphs;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1215
            sscanf(debugMinGlyphsStr, "%5d", &val);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1216
            if (val >= 0 && val <= 65536) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1217
                minGlyphs = val;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1218
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1219
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1220
        for (j=0; j<nfonts; j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1221
            FcPattern *fontPattern = fontset->fonts[j];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1222
            FcChar8 *fontformat;
1731
830101735cdb 6764543: SIGSEGV in libfontconfig.so starting from jdk7b33
prr
parents: 1724
diff changeset
  1223
            FcCharSet *unionCharset = NULL, *charset;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1224
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1225
            fontformat = NULL;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1226
            (*FcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat);
10407
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1227
            /* We only want TrueType fonts but some Linuxes still depend
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1228
             * on Type 1 fonts for some Locale support, so we'll allow
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1229
             * them there.
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1230
             */
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1231
            if (fontformat != NULL
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1232
                && (strcmp((char*)fontformat, "TrueType") != 0)
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 21130
diff changeset
  1233
#if defined(__linux__) || defined(_AIX)
10407
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1234
                && (strcmp((char*)fontformat, "Type 1") != 0)
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1235
#endif
4f389b57b475 7050826: Hebrew characters are not rendered on OEL 5.6
prr
parents: 9460
diff changeset
  1236
             ) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1237
                continue;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1238
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1239
            result = (*FcPatternGetCharSet)(fontPattern,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1240
                                            FC_CHARSET, 0, &charset);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1241
            if (result != FcResultMatch) {
7949
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1242
                free(family);
13139
917a5a5434a9 7176447: Lunix/Solaris fontpath.c : double free(family)
prr
parents: 12389
diff changeset
  1243
                free(fullname);
7949
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1244
                free(styleStr);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1245
                free(file);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1246
                (*FcPatternDestroy)(pattern);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1247
                (*FcFontSetDestroy)(fontset);
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1248
                (*env)->ReleaseStringUTFChars(env,
073e8ab25a02 6892493: potential memory leaks in 2D font code indentified by parfait.
prr
parents: 7932
diff changeset
  1249
                                              fcNameStr, (const char*)fcName);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1250
                closeFontConfig(libfontconfig, JNI_FALSE);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1251
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1252
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1254
            /* We don't want 20 or 30 fonts, so once we hit 10 fonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1255
             * then require that they really be adding value. Too many
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1256
             * adversely affects load time for minimal value-add.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1257
             * This is still likely far more than we've had in the past.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1258
             */
3931
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1259
            if (j==10) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1260
                minGlyphs = 50;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1261
            }
1731
830101735cdb 6764543: SIGSEGV in libfontconfig.so starting from jdk7b33
prr
parents: 1724
diff changeset
  1262
            if (unionCharset == NULL) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1263
                unionCharset = charset;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1264
            } else {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1265
                if ((*FcCharSetSubtractCount)(charset, unionCharset)
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1266
                    > minGlyphs) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1267
                    unionCharset = (* FcCharSetUnion)(unionCharset, charset);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1268
                } else {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1269
                    continue;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1270
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1272
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1273
            fontCount++; // found a font we will use.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1274
            (*FcPatternGetString)(fontPattern, FC_FILE, 0, &file[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1275
            (*FcPatternGetString)(fontPattern, FC_FAMILY, 0, &family[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1276
            (*FcPatternGetString)(fontPattern, FC_STYLE, 0, &styleStr[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1277
            (*FcPatternGetString)(fontPattern, FC_FULLNAME, 0, &fullname[j]);
3931
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1278
            if (!includeFallbacks) {
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1279
                break;
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1280
            }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1281
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1282
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1283
        /* Once we get here 'fontCount' is the number of returned fonts
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1284
         * we actually want to use, so we create 'fcFontArr' of that length.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1285
         * The non-null entries of "family[]" etc are those fonts.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1286
         * Then loop again over all nfonts adding just those non-null ones
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1287
         * to 'fcFontArr'. If its null (we didn't want the font)
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1288
         * then we don't enter the main body.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1289
         * So we should never get more than 'fontCount' entries.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1290
         */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1291
        if (includeFallbacks) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1292
            fcFontArr =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1293
                (*env)->NewObjectArray(env, fontCount, fcFontClass, NULL);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1294
            (*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1295
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1296
        fn=0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1297
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1298
        for (j=0;j<nfonts;j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1299
            if (family[j] != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1300
                jobject fcFont =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1301
                    (*env)->NewObject(env, fcFontClass, fcFontCons);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1302
                jstr = (*env)->NewStringUTF(env, (const char*)family[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1303
                (*env)->SetObjectField(env, fcFont, familyNameID, jstr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1304
                if (file[j] != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1305
                    jstr = (*env)->NewStringUTF(env, (const char*)file[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1306
                    (*env)->SetObjectField(env, fcFont, fontFileID, jstr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1307
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1308
                if (styleStr[j] != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1309
                    jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1310
                    (*env)->SetObjectField(env, fcFont, styleNameID, jstr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1311
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1312
                if (fullname[j] != NULL) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1313
                    jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1314
                    (*env)->SetObjectField(env, fcFont, fullNameID, jstr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1315
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1316
                if (fn==0) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1317
                    (*env)->SetObjectField(env, fcCompFontObj,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1318
                                           fcFirstFontID, fcFont);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1319
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1320
                if (includeFallbacks) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1321
                    (*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont);
3931
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1322
                } else {
81071c37cc91 6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents: 3928
diff changeset
  1323
                    break;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1324
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1328
        (*FcFontSetDestroy)(fontset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        (*FcPatternDestroy)(pattern);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1330
        free(family);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1331
        free(styleStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1332
        free(fullname);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
  1333
        free(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    /* release resources and close the ".so" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    if (locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    closeFontConfig(libfontconfig, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
}