jdk/src/solaris/native/sun/java2d/x11/X11FontScaler_md.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <sys/utsname.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "fontscalerdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "X11FontScaler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <X11/Xlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <awt.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
static GC pixmapGC = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
static Pixmap pixmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
static Atom psAtom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
static Atom fullNameAtom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
static int pixmapWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static int pixmapHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define FONT_AWT_LOCK() \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
int CreatePixmapAndGC (int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* REMIND: use the actual screen, not the default screen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Window awt_defaultRoot =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        RootWindow(awt_display, DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    if (width < 100) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
      width = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    if (height < 100) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      height = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    pixmapHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    pixmapWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    if (pixmap != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      XFreePixmap (awt_display, pixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    if (pixmapGC != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
      XFreeGC (awt_display, pixmapGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    pixmap = XCreatePixmap (awt_display, awt_defaultRoot, pixmapWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                          pixmapHeight, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    if (pixmap == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      return BadAlloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    pixmapGC = XCreateGC (awt_display, pixmap, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (pixmapGC == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      return BadAlloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    XFillRectangle (awt_display, pixmap, pixmapGC, 0, 0, pixmapWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                  pixmapHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    XSetForeground (awt_display, pixmapGC, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    return Success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#ifdef DUMP_IMAGES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
static void dumpXImage(XImage *ximage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    int height = ximage->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    int width = ximage->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    fprintf(stderr, "-------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    for (row = 0; row < height; ++row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      for (column = 0; column < width; ++column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
          int pixel = ximage->f.get_pixel(ximage, column, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
          fprintf(stderr, (pixel == 0) ? "  " : "XX");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    fprintf(stderr, "-------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
JNIEXPORT int JNICALL AWTCountFonts(char* xlfd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    char **names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    FONT_AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    names = XListFonts(awt_display, xlfd, 3, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    XFreeFontNames(names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
JNIEXPORT void JNICALL AWTLoadFont(char* name, AWTFont *pReturn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    *pReturn = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    FONT_AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    *pReturn = (AWTFont)XLoadQueryFont(awt_display, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
JNIEXPORT void JNICALL AWTFreeFont(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    FONT_AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    XFreeFont(awt_display, (XFontStruct *)font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
JNIEXPORT unsigned JNICALL AWTFontMinByte1(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    return ((XFontStruct *)font)->min_byte1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
JNIEXPORT unsigned JNICALL AWTFontMaxByte1(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    return ((XFontStruct *)font)->max_byte1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
JNIEXPORT unsigned JNICALL AWTFontMinCharOrByte2(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    return ((XFontStruct *)font)->min_char_or_byte2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
JNIEXPORT unsigned JNICALL AWTFontMaxCharOrByte2(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    return ((XFontStruct *)font)->max_char_or_byte2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
JNIEXPORT unsigned JNICALL AWTFontDefaultChar(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    return ((XFontStruct *)font)->default_char;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
JNIEXPORT AWTChar JNICALL AWTFontPerChar(AWTFont font, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    XFontStruct *fXFont = (XFontStruct *)font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    XCharStruct *perChar = fXFont->per_char;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    if (perChar == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    return (AWTChar)&(perChar[index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
JNIEXPORT AWTChar JNICALL AWTFontMaxBounds(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    return (AWTChar)&((XFontStruct *)font)->max_bounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
JNIEXPORT int JNICALL AWTFontAscent(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    return ((XFontStruct *)font)->ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
JNIEXPORT int JNICALL AWTFontDescent(AWTFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    return ((XFontStruct *)font)->descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
JNIEXPORT void JNICALL AWTFontTextExtents16(AWTFont font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                            AWTChar2b* xChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                            AWTChar* overall) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    int ascent, descent, direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    XFontStruct* xFont = (XFontStruct*)font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    XCharStruct* newChar = (XCharStruct*)malloc(sizeof(XCharStruct));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    *overall = (AWTChar)newChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /* There is a claim from the pre 1.5 source base that the info in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * XFontStruct is flaky for 16 byte chars. This seems plausible as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * for info to be valid, that struct would need a large number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * XCharStructs. But there's nothing in the X APIs which warns you of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * this. If it really is flaky you must question why there's an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * XTextExtents16 API call. Try XTextExtents16 for now and if it fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * go back to XQueryTextExtents16 in this function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Indeed the metrics from the Solaris 9 JA font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * -ricoh-gothic-medium-r-normal--*-140-72-72-m-*-jisx0208.1983-0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * do appear different so revert to the query api
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    FONT_AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    XQueryTextExtents16(awt_display,xFont->fid, xChar, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        &direction, &ascent, &descent, newChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
/* XTextExtents16(xFont, xChar, 1, &direction, &ascent, &descent, newChar);  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
JNIEXPORT void JNICALL AWTFreeChar(AWTChar xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    free(xChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
JNIEXPORT jlong JNICALL AWTFontGenerateImage(AWTFont pFont, AWTChar2b* xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    int width, height, direction, ascent, descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    GlyphInfo *glyphInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    XFontStruct* xFont = (XFontStruct*)pFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    XCharStruct xcs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    XImage *ximage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    int h, i, j, nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    unsigned char *srcRow, *dstRow, *dstByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    int wholeByteCount, remainingBitsCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    unsigned int imageSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    FONT_AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
/*     XTextExtents16(xFont, xChar, 1, &direction, &ascent, &descent, &xcs); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    XQueryTextExtents16(awt_display,xFont->fid, xChar, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        &direction, &ascent, &descent, &xcs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    width = xcs.rbearing - xcs.lbearing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    height = xcs.ascent+xcs.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    imageSize = width*height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    glyphInfo = (GlyphInfo*)malloc(sizeof(GlyphInfo)+imageSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    glyphInfo->cellInfo = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    glyphInfo->width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    glyphInfo->height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    glyphInfo->topLeftX = xcs.lbearing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    glyphInfo->topLeftY = -xcs.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    glyphInfo->advanceX = xcs.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    glyphInfo->advanceY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    if (imageSize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        glyphInfo->image = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return (jlong)(uintptr_t)glyphInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        glyphInfo->image = (unsigned char*)glyphInfo+sizeof(GlyphInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if ((pixmap == 0) || (width > pixmapWidth) || (height > pixmapHeight)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (CreatePixmapAndGC(width, height) != Success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            glyphInfo->image = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return (jlong)(uintptr_t)glyphInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    XSetFont(awt_display, pixmapGC, xFont->fid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    XSetForeground(awt_display, pixmapGC, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    XFillRectangle(awt_display, pixmap, pixmapGC, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                   pixmapWidth, pixmapHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    XSetForeground(awt_display, pixmapGC, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    XDrawString16(awt_display, pixmap, pixmapGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                  -xcs.lbearing, xcs.ascent, xChar, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    ximage = XGetImage(awt_display, pixmap, 0, 0, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                       AllPlanes, XYPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    if (ximage == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        glyphInfo->image = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return (jlong)(uintptr_t)glyphInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
#ifdef DUMP_IMAGES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    dumpXImage(ximage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    nbytes =  ximage->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    srcRow = (unsigned char*)ximage->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    dstRow = (unsigned char*)glyphInfo->image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    wholeByteCount = width >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    remainingBitsCount = width & 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    for (h=0; h<height; h++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        const UInt8* src8 = srcRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        UInt8 *dstByte = dstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        UInt32 srcValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        srcRow += nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        dstRow += width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        for (i = 0; i < wholeByteCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            srcValue = *src8++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            for (j = 0; j < 8; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                if (ximage->bitmap_bit_order == LSBFirst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    *dstByte++ = (srcValue & 0x01) ? 0xFF : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    srcValue >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                } else {                /* MSBFirst */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    *dstByte++ = (srcValue & 0x80) ? 0xFF : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    srcValue <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (remainingBitsCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            srcValue = *src8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            for (j = 0; j < remainingBitsCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                if (ximage->bitmap_bit_order == LSBFirst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    *dstByte++ = (srcValue & 0x01) ? 0xFF : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    srcValue >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                } else {                /* MSBFirst */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    *dstByte++ = (srcValue & 0x80) ? 0xFF : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    srcValue <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    XDestroyImage (ximage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    return (jlong)(uintptr_t)glyphInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    return (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
JNIEXPORT short JNICALL AWTCharAdvance(AWTChar xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    return ((XCharStruct *)xChar)->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
JNIEXPORT short JNICALL AWTCharLBearing(AWTChar xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    return ((XCharStruct *)xChar)->lbearing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
JNIEXPORT short JNICALL AWTCharRBearing(AWTChar xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    return ((XCharStruct *)xChar)->rbearing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
JNIEXPORT short JNICALL AWTCharAscent(AWTChar xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    return ((XCharStruct *)xChar)->ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
JNIEXPORT short JNICALL AWTCharDescent(AWTChar xChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    return ((XCharStruct *)xChar)->descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
}