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