jdk/src/windows/native/sun/windows/awt_Font.cpp
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6825 795e9fe949d3
child 14305 52548c249171
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6825
diff changeset
     2
 * Copyright (c) 1996, 2010, 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: 1954
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: 1954
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: 1954
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    26
#include "awt.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <math.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_Toolkit.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "java_awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "java_awt_FontMetrics.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "java_awt_Dimension.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "sun_awt_FontDescriptor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "sun_awt_windows_WDefaultFontCharset.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "sun_awt_windows_WFontPeer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "Disposer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/* IMPORTANT! Read the README.JNI file for notes on JNI converted AWT code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
AwtFontCache fontCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
extern jboolean IsMultiFont(JNIEnv *env, jobject obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    if (obj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    if (env->EnsureLocalCapacity(2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jobject peer = env->CallObjectMethod(obj, AwtFont::peerMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    jobject fontConfig = env->GetObjectField(peer, AwtFont::fontConfigID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    jboolean result = fontConfig != NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    env->DeleteLocalRef(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    env->DeleteLocalRef(fontConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
extern jstring GetTextComponentFontName(JNIEnv *env, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    DASSERT(font != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    if (env->EnsureLocalCapacity(2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    jobject peer = env->CallObjectMethod(font, AwtFont::peerMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    DASSERT(peer != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    jstring textComponentFontName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            (jstring) env->GetObjectField(peer, AwtFont::textComponentFontNameID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    env->DeleteLocalRef(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    return textComponentFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * AwtFont fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
/* sun.awt.windows.WFontMetrics fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
jfieldID AwtFont::widthsID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
jfieldID AwtFont::ascentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
jfieldID AwtFont::descentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
jfieldID AwtFont::leadingID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
jfieldID AwtFont::heightID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
jfieldID AwtFont::maxAscentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
jfieldID AwtFont::maxDescentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
jfieldID AwtFont::maxHeightID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
jfieldID AwtFont::maxAdvanceID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/* java.awt.FontDescriptor fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
jfieldID AwtFont::nativeNameID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
jfieldID AwtFont::useUnicodeID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
/* java.awt.Font fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
jfieldID AwtFont::pDataID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
jfieldID AwtFont::nameID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
jfieldID AwtFont::sizeID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
jfieldID AwtFont::styleID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
/* java.awt.FontMetrics fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
jfieldID AwtFont::fontID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
/* sun.awt.PlatformFont fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
jfieldID AwtFont::fontConfigID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
jfieldID AwtFont::componentFontsID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/* sun.awt.windows.WFontPeer fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
jfieldID AwtFont::textComponentFontNameID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
/* sun.awt.windows.WDefaultFontCharset fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
jfieldID AwtFont::fontNameID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
/* java.awt.Font methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
jmethodID AwtFont::peerMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/* sun.awt.PlatformFont methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
jmethodID AwtFont::makeConvertedMultiFontStringMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
/* sun.awt.PlatformFont methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
jmethodID AwtFont::getFontMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
/* java.awt.FontMetrics methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
jmethodID AwtFont::getHeightMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * AwtFont methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
AwtFont::AwtFont(int num, JNIEnv *env, jobject javaFont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (num == 0) {  // not multi-font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        num = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    m_hFontNum = num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    m_hFont = new HFONT[num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        m_hFont[i] = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    m_textInput = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    m_ascent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    m_overhang = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
AwtFont::~AwtFont()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
void AwtFont::Dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    for (int i = 0; i < m_hFontNum; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        HFONT font = m_hFont[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (font != NULL && fontCache.Search(font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            fontCache.Remove(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            /*  NOTE: delete of windows HFONT happens in FontCache::Remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                      only when the final reference to the font is disposed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        } else if (font != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         // if font was not in cache, its not shared and we delete it now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
           VERIFY(::DeleteObject(font));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    delete[] m_hFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    AwtObject::Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
static void pDataDisposeMethod(JNIEnv *env, jlong pData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    TRY_NO_VERIFY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    AwtObject::_Dispose((PDATA)pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
AwtFont* AwtFont::GetFont(JNIEnv *env, jobject font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                          jint angle, jfloat awScale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    jlong pData = env->GetLongField(font, AwtFont::pDataID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    AwtFont* awtFont = (AwtFont*)jlong_to_ptr(pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    if (awtFont != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return awtFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    awtFont = Create(env, font, angle, awScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    env->SetLongField(font, AwtFont::pDataID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        reinterpret_cast<jlong>(awtFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    return awtFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
// Get suitable CHARSET from charset string provided by font configuration.
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   199
static int GetNativeCharset(LPCWSTR name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    if (wcsstr(name, L"ANSI_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return ANSI_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    if (wcsstr(name, L"DEFAULT_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return DEFAULT_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    if (wcsstr(name, L"SYMBOL_CHARSET") || wcsstr(name, L"WingDings"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return SYMBOL_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    if (wcsstr(name, L"SHIFTJIS_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return SHIFTJIS_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    if (wcsstr(name, L"GB2312_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return GB2312_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if (wcsstr(name, L"HANGEUL_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return HANGEUL_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    if (wcsstr(name, L"CHINESEBIG5_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return CHINESEBIG5_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    if (wcsstr(name, L"OEM_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return OEM_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if (wcsstr(name, L"JOHAB_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return JOHAB_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    if (wcsstr(name, L"HEBREW_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return HEBREW_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (wcsstr(name, L"ARABIC_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return ARABIC_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    if (wcsstr(name, L"GREEK_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return GREEK_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    if (wcsstr(name, L"TURKISH_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return TURKISH_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (wcsstr(name, L"VIETNAMESE_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return VIETNAMESE_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    if (wcsstr(name, L"THAI_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return THAI_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (wcsstr(name, L"EASTEUROPE_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return EASTEUROPE_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    if (wcsstr(name, L"RUSSIAN_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return RUSSIAN_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    if (wcsstr(name, L"MAC_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return MAC_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    if (wcsstr(name, L"BALTIC_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return BALTIC_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    return ANSI_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
AwtFont* AwtFont::Create(JNIEnv *env, jobject font, jint angle, jfloat awScale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    int fontSize = env->GetIntField(font, AwtFont::sizeID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    int fontStyle = env->GetIntField(font, AwtFont::styleID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    AwtFont* awtFont = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    jobjectArray compFont = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    int cfnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (env->EnsureLocalCapacity(3) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (IsMultiFont(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            compFont = GetComponentFonts(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            cfnum = env->GetArrayLength(compFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            compFont = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            cfnum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   263
        LPCWSTR wName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        awtFont = new AwtFont(cfnum, env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        awtFont->textAngle = angle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        awtFont->awScale = awScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (cfnum > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // Ask peer class for the text component font name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            jstring jTextComponentFontName = GetTextComponentFontName(env, font);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   273
            LPCWSTR textComponentFontName = JNU_GetStringPlatformChars(env, jTextComponentFontName, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            awtFont->m_textInput = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            for (int i = 0; i < cfnum; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                // nativeName is a pair of platform fontname and its charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                // tied with a comma; "Times New Roman,ANSI_CHARSET".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                jobject fontDescriptor = env->GetObjectArrayElement(compFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                                                    i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                jstring nativeName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    (jstring)env->GetObjectField(fontDescriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                                 AwtFont::nativeNameID);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   284
                wName = JNU_GetStringPlatformChars(env, nativeName, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                DASSERT(wName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                //On NT platforms, if the font is not Symbol or Dingbats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                //use "W" version of Win32 APIs directly, info the FontDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                //no need to convert characters from Unicode to locale encodings.
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   290
                if (GetNativeCharset(wName) != SYMBOL_CHARSET) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    env->SetBooleanField(fontDescriptor, AwtFont::useUnicodeID, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                // Check to see if this font is suitable for input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                // on AWT TextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                if ((awtFont->m_textInput == -1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        (textComponentFontName != NULL) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        (wcscmp(wName, textComponentFontName) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    awtFont->m_textInput = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                }
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   301
                HFONT hfonttmp = CreateHFont(const_cast<LPWSTR>(wName), fontStyle, fontSize,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                             angle, awScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                awtFont->m_hFont[i] = hfonttmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   305
                JNU_ReleaseStringPlatformChars(env, nativeName, wName);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   306
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                env->DeleteLocalRef(fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                env->DeleteLocalRef(nativeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (awtFont->m_textInput == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                // no text component font was identified, so default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                // to first component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                awtFont->m_textInput = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   315
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   316
            JNU_ReleaseStringPlatformChars(env, jTextComponentFontName, textComponentFontName);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   317
            env->DeleteLocalRef(jTextComponentFontName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            // Instantiation for English version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            jstring fontName = (jstring)env->GetObjectField(font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                                            AwtFont::nameID);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   322
            wName = JNU_GetStringPlatformChars(env, fontName, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            WCHAR* wEName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (!wcscmp(wName, L"Helvetica") || !wcscmp(wName, L"SansSerif")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                wEName = L"Arial";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            } else if (!wcscmp(wName, L"TimesRoman") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                       !wcscmp(wName, L"Serif")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                wEName = L"Times New Roman";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            } else if (!wcscmp(wName, L"Courier") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                       !wcscmp(wName, L"Monospaced")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                wEName = L"Courier New";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } else if (!wcscmp(wName, L"Dialog")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                wEName = L"MS Sans Serif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } else if (!wcscmp(wName, L"DialogInput")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                wEName = L"MS Sans Serif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            } else if (!wcscmp(wName, L"ZapfDingbats")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                wEName = L"WingDings";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                wEName = L"Arial";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            awtFont->m_textInput = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            awtFont->m_hFont[0] = CreateHFont(wEName, fontStyle, fontSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                              angle, awScale);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   345
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   346
            JNU_ReleaseStringPlatformChars(env, fontName, wName);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   347
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            env->DeleteLocalRef(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        /* The several callers of this method also set the pData field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * That's unnecessary but harmless duplication. However we definitely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         * want only one disposer record.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        env->SetLongField(font, AwtFont::pDataID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        reinterpret_cast<jlong>(awtFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        Disposer_AddRecord(env, font, pDataDisposeMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                       reinterpret_cast<jlong>(awtFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        env->DeleteLocalRef(compFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    env->DeleteLocalRef(compFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    return awtFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
int CALLBACK FindFamilyName (ENUMLOGFONTEX *lpelfe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
          NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    if(_tcsstr((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        _tcscpy((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
static void strip_tail(wchar_t* text, wchar_t* tail) { // strips tail and any possible whitespace before it from the end of text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    if (wcslen(text)<=wcslen(tail)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    wchar_t* p = text+wcslen(text)-wcslen(tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    if (!wcscmp(p, tail)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        while(p>text && iswspace(*(p-1)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            p--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        *p = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   391
static HFONT CreateHFont_sub(LPCWSTR name, int style, int height,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                             int angle=0, float awScale=1.0f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    LOGFONTW logFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    logFont.lfWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    logFont.lfEscapement = angle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    logFont.lfOrientation = angle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    logFont.lfUnderline = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    logFont.lfStrikeOut = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    logFont.lfCharSet = GetNativeCharset(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    if (angle == 0 && awScale == 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        logFont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    logFont.lfQuality = DEFAULT_QUALITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    logFont.lfPitchAndFamily = DEFAULT_PITCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    // Set style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    logFont.lfWeight = (style & java_awt_Font_BOLD) ? FW_BOLD : FW_NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    logFont.lfItalic = (style & java_awt_Font_ITALIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    logFont.lfUnderline = 0;//(style & java_awt_Font_UNDERLINE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    // Get point size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    logFont.lfHeight = -height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // Set font name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    WCHAR tmpname[80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    wcscpy(tmpname, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    WCHAR* delimit = wcschr(tmpname, L',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    if (delimit != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        *delimit = L'\0';  // terminate the string after the font name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    // strip "Bold" and "Italic" from the end of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    strip_tail(tmpname,L""); //strip possible trailing whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    strip_tail(tmpname,L"Italic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    strip_tail(tmpname,L"Bold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    wcscpy(&(logFont.lfFaceName[0]), tmpname);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   430
    HFONT hFont = ::CreateFontIndirect(&logFont);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    DASSERT(hFont != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    // get a expanded or condensed version if its specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    if (awScale != 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        HDC hDC = ::GetDC(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        HFONT oldFont = (HFONT)::SelectObject(hDC, hFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        TEXTMETRIC tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        DWORD avgWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        GetTextMetrics(hDC, &tm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        oldFont = (HFONT)::SelectObject(hDC, oldFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (oldFont != NULL) { // should be the same as hFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            VERIFY(::DeleteObject(oldFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        avgWidth = tm.tmAveCharWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        logFont.lfWidth = (LONG)((fabs)(avgWidth*awScale));
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   445
        hFont = ::CreateFontIndirect(&logFont);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        DASSERT(hFont != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        VERIFY(::ReleaseDC(0, hDC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    return hFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
HFONT AwtFont::CreateHFont(WCHAR* name, int style, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                           int angle, float awScale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    WCHAR longName[80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    // 80 > (max face name(=30) + strlen("CHINESEBIG5_CHARSET"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    // longName doesn't have to be printable.  So, it is OK not to convert.
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   459
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   460
    wsprintf(longName, L"%ls-%d-%d", name, style, height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    HFONT hFont = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    // only cache & share unrotated, unexpanded/uncondensed fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    if (angle == 0 && awScale == 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        hFont = fontCache.Lookup(longName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (hFont != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            fontCache.IncRefCount(hFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return hFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    hFont = CreateHFont_sub(name, style, height, angle, awScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    if (angle == 0 && awScale == 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        fontCache.Add(longName, hFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    return hFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
void AwtFont::Cleanup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    fontCache.Clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
void AwtFont::SetupAscent(AwtFont* font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    HDC hDC = ::GetDC(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    DASSERT(hDC != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    HGDIOBJ oldFont = ::SelectObject(hDC, font->GetHFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    TEXTMETRIC metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    VERIFY(::GetTextMetrics(hDC, &metrics));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    font->SetAscent(metrics.tmAscent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    ::SelectObject(hDC, oldFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    VERIFY(::ReleaseDC(0, hDC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
void AwtFont::LoadMetrics(JNIEnv *env, jobject fontMetrics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    if (env->EnsureLocalCapacity(3) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    jintArray widths = env->NewIntArray(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    if (widths == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        /* no local refs to delete yet. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    jobject font = env->GetObjectField(fontMetrics, AwtFont::fontID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    AwtFont* awtFont = AwtFont::GetFont(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    HDC hDC = ::GetDC(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    DASSERT(hDC != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    HGDIOBJ oldFont = ::SelectObject(hDC, awtFont->GetHFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    TEXTMETRIC metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    VERIFY(::GetTextMetrics(hDC, &metrics));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    awtFont->m_ascent = metrics.tmAscent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    int ascent = metrics.tmAscent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    int descent = metrics.tmDescent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    int leading = metrics.tmExternalLeading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    env->SetIntField(fontMetrics, AwtFont::ascentID, ascent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    env->SetIntField(fontMetrics, AwtFont::descentID, descent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    env->SetIntField(fontMetrics, AwtFont::leadingID, leading);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    env->SetIntField(fontMetrics, AwtFont::heightID, metrics.tmAscent +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                     metrics.tmDescent + leading);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    env->SetIntField(fontMetrics, AwtFont::maxAscentID, ascent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    env->SetIntField(fontMetrics, AwtFont::maxDescentID, descent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    int maxHeight =  ascent + descent + leading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    env->SetIntField(fontMetrics, AwtFont::maxHeightID, maxHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    int maxAdvance = metrics.tmMaxCharWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    env->SetIntField(fontMetrics, AwtFont::maxAdvanceID, maxAdvance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    awtFont->m_overhang = metrics.tmOverhang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    jint intWidths[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    memset(intWidths, 0, 256 * sizeof(int));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    VERIFY(::GetCharWidth(hDC, metrics.tmFirstChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                          min(metrics.tmLastChar, 255),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                          (int *)&intWidths[metrics.tmFirstChar]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    env->SetIntArrayRegion(widths, 0, 256, intWidths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    env->SetObjectField(fontMetrics, AwtFont::widthsID, widths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    // Get font metrics on remaining fonts (if multifont).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    for (int j = 1; j < awtFont->GetHFontNum(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        ::SelectObject(hDC, awtFont->GetHFont(j));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        VERIFY(::GetTextMetrics(hDC, &metrics));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        env->SetIntField(fontMetrics, AwtFont::maxAscentID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                         ascent = max(ascent, metrics.tmAscent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        env->SetIntField(fontMetrics, AwtFont::maxDescentID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                         descent = max(descent, metrics.tmDescent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        env->SetIntField(fontMetrics, AwtFont::maxHeightID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                         maxHeight = max(maxHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                         metrics.tmAscent +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                         metrics.tmDescent +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                                         metrics.tmExternalLeading));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        env->SetIntField(fontMetrics, AwtFont::maxAdvanceID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                         maxAdvance = max(maxAdvance, metrics.tmMaxCharWidth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    VERIFY(::SelectObject(hDC, oldFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    VERIFY(::ReleaseDC(0, hDC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    env->DeleteLocalRef(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    env->DeleteLocalRef(widths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
SIZE AwtFont::TextSize(AwtFont* font, int columns, int rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    HDC hDC = ::GetDC(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    DASSERT(hDC != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    HGDIOBJ oldFont = ::SelectObject(hDC, (font == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                           ? ::GetStockObject(SYSTEM_FONT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                           : font->GetHFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    SIZE size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    VERIFY(::GetTextExtentPoint(hDC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        TEXT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 52, &size));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    VERIFY(::SelectObject(hDC, oldFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    VERIFY(::ReleaseDC(0, hDC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    size.cx = size.cx * columns / 52;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    size.cy = size.cy * rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
int AwtFont::getFontDescriptorNumber(JNIEnv *env, jobject font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                     jobject fontDescriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    int i, num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    jobject refFontDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    jobjectArray array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    if (env->EnsureLocalCapacity(2) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    if (IsMultiFont(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        array = GetComponentFonts(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        num = env->GetArrayLength(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        array = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    for (i = 0; i < num; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        // Trying to identify the same FontDescriptor by comparing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        // pointers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        refFontDescriptor = env->GetObjectArrayElement(array, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (env->IsSameObject(refFontDescriptor, fontDescriptor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            env->DeleteLocalRef(refFontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            env->DeleteLocalRef(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        env->DeleteLocalRef(refFontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    env->DeleteLocalRef(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    return 0;   // Not found.  Use default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
 * This is a faster version of the same function, which does most of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 * the work in Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
SIZE  AwtFont::DrawStringSize_sub(jstring str, HDC hDC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                  jobject font, long x, long y, BOOL draw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                  UINT codePage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    SIZE size, temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    size.cx = size.cy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    if (str == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    if (env->EnsureLocalCapacity(3) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    jobjectArray array = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    int arrayLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    if (env->GetStringLength(str) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    //Init AwtFont object, which will "create" a AwtFont object if necessry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    //before calling makeconvertedMultiFontString(), otherwise, the FontDescriptor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    //"useUnicode" field might not be initialized correctly (font in Menu Component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    //for example").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    AwtFont* awtFont = AwtFont::GetFont(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    if (IsMultiFont(env, font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        jobject peer = env->CallObjectMethod(font, AwtFont::peerMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        array =  (jobjectArray)(env->CallObjectMethod(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        peer, AwtFont::makeConvertedMultiFontStringMID, str));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        DASSERT(!safe_ExceptionOccurred(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (array != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            arrayLength = env->GetArrayLength(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        env->DeleteLocalRef(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        array = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        arrayLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    HFONT oldFont = (HFONT)::SelectObject(hDC, awtFont->GetHFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    if (arrayLength == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        int length = env->GetStringLength(str);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   674
        LPCWSTR strW = JNU_GetStringPlatformChars(env, str, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        VERIFY(::SelectObject(hDC, awtFont->GetHFont()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (AwtComponent::GetRTLReadingOrder()){
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   677
            VERIFY(!draw || ::ExtTextOut(hDC, x, y, ETO_RTLREADING, NULL,
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   678
                                          strW, length, NULL));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        } else {
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   680
            VERIFY(!draw || ::TextOut(hDC, x, y, strW, length));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   682
        VERIFY(::GetTextExtentPoint32(hDC, strW, length, &size));
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   683
        JNU_ReleaseStringPlatformChars(env, str, strW);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        for (int i = 0; i < arrayLength; i = i + 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            jobject fontDescriptor = env->GetObjectArrayElement(array, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            if (fontDescriptor == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            jbyteArray convertedBytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                (jbyteArray)env->GetObjectArrayElement(array, i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (convertedBytes == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                env->DeleteLocalRef(fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            int fdIndex = getFontDescriptorNumber(env, font, fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            VERIFY(::SelectObject(hDC, awtFont->GetHFont(fdIndex)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
             * The strange-looking code that follows this comment is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
             * the result of upstream optimizations. In the array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
             * alternating font descriptor and buffers, the buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
             * contain their length in the first four bytes, a la
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
             * Pascal arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
             * Note: the buffer MUST be unsigned, or VC++ will sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
             * extend buflen and bad things will happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            unsigned char* buffer = NULL;
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   712
            jboolean unicodeUsed = env->GetBooleanField(fontDescriptor, AwtFont::useUnicodeID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                buffer = (unsigned char *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    env->GetPrimitiveArrayCritical(convertedBytes, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                int buflen = (buffer[0] << 24) | (buffer[1] << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    (buffer[2] << 8) | buffer[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                DASSERT(buflen >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                 * the offsetBuffer, on the other hand, must be signed because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                 * TextOutA and GetTextExtentPoint32A expect it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                char* offsetBuffer = (char *)(buffer + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                if (unicodeUsed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    VERIFY(!draw || ::TextOutW(hDC, x, y, (LPCWSTR)offsetBuffer, buflen / 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    VERIFY(::GetTextExtentPoint32W(hDC, (LPCWSTR)offsetBuffer, buflen / 2, &temp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    VERIFY(!draw || ::TextOutA(hDC, x, y, offsetBuffer, buflen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    VERIFY(::GetTextExtentPoint32A(hDC, offsetBuffer, buflen, &temp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                if (buffer != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    env->ReleasePrimitiveArrayCritical(convertedBytes, buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                                                       0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            env->ReleasePrimitiveArrayCritical(convertedBytes, buffer, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            if (awtFont->textAngle == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                x += temp.cx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
               // account for rotation of the text used in 2D printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
               double degrees = 360.0 - (awtFont->textAngle/10.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
               double rads = degrees/(180.0/3.1415926535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
               double dx = temp.cx * cos(rads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
               double dy = temp.cx * sin(rads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
               x += (long)floor(dx+0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
               y += (long)floor(dy+0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            size.cx += temp.cx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            size.cy = (size.cy < temp.cy) ? temp.cy : size.cy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            env->DeleteLocalRef(fontDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            env->DeleteLocalRef(convertedBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    env->DeleteLocalRef(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    VERIFY(::SelectObject(hDC, oldFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
 * WFontMetrics native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * Class:     sun_awt_windows_WFontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 * Method:    stringWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 * Signature: (Ljava/lang/String;)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
Java_sun_awt_windows_WFontMetrics_stringWidth(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                              jstring str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    if (str == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        JNU_ThrowNullPointerException(env, "str argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    HDC hDC = ::GetDC(0);    DASSERT(hDC != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    jobject font = env->GetObjectField(self, AwtFont::fontID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    long ret = AwtFont::getMFStringWidth(hDC, font, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    VERIFY(::ReleaseDC(0, hDC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
 * Class:     sun_awt_windows_WFontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
 * Method:    charsWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
 * Signature: ([CII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
Java_sun_awt_windows_WFontMetrics_charsWidth(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                                             jcharArray str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                                             jint off, jint len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    if (str == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        JNU_ThrowNullPointerException(env, "str argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        JNU_ThrowArrayIndexOutOfBoundsException(env, "off/len argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    jchar *strp = new jchar[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    env->GetCharArrayRegion(str, off, len, strp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    jstring jstr = env->NewString(strp, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    jint result = Java_sun_awt_windows_WFontMetrics_stringWidth(env, self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                                                                jstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    delete [] strp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
 * Class:     sun_awt_windows_WFontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
 * Method:    bytesWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
 * Signature: ([BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                                             jbyteArray str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                                             jint off, jint len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    if (str == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        JNU_ThrowNullPointerException(env, "bytes argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        JNU_ThrowArrayIndexOutOfBoundsException(env, "off or len argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    char *pStrBody = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    jint result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        jintArray array = (jintArray)env->GetObjectField(self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                                                         AwtFont::widthsID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        char *pStr = pStrBody + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        jint *widths = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            widths = (jint *)env->GetPrimitiveArrayCritical(array, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            for (; len; len--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                result += widths[*pStr++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            if (widths != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                env->ReleasePrimitiveArrayCritical(array, widths, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        env->ReleasePrimitiveArrayCritical(array, widths, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if (pStrBody != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
 * Class:     sun_awt_windows_WFontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
Java_sun_awt_windows_WFontMetrics_init(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    jobject font = env->GetObjectField(self, AwtFont::fontID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    if (font == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        JNU_ThrowNullPointerException(env, "fontMetrics' font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    // This local variable is unused. Is there some subtle side-effect here?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    jlong pData = env->GetLongField(font, AwtFont::pDataID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    AwtFont::LoadMetrics(env, self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 * Class:     sun_awt_windows_WFontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
Java_sun_awt_windows_WFontMetrics_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    AwtFont::widthsID = env->GetFieldID(cls, "widths", "[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    AwtFont::ascentID = env->GetFieldID(cls, "ascent", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    AwtFont::descentID = env->GetFieldID(cls, "descent", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    AwtFont::leadingID = env->GetFieldID(cls, "leading", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    AwtFont::heightID = env->GetFieldID(cls, "height", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    AwtFont::maxAscentID = env->GetFieldID(cls, "maxAscent", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    AwtFont::maxDescentID = env->GetFieldID(cls, "maxDescent", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    AwtFont::maxHeightID = env->GetFieldID(cls, "maxHeight", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    AwtFont::maxAdvanceID = env->GetFieldID(cls, "maxAdvance", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    DASSERT(AwtFont::widthsID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    DASSERT(AwtFont::ascentID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    DASSERT(AwtFont::descentID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    DASSERT(AwtFont::leadingID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    DASSERT(AwtFont::heightID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    DASSERT(AwtFont::maxAscentID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    DASSERT(AwtFont::maxDescentID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    DASSERT(AwtFont::maxHeightID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    DASSERT(AwtFont::maxAdvanceID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
 * java.awt.Font native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
Java_java_awt_Font_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    AwtFont::peerMID = env->GetMethodID(cls, "getPeer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                                        "()Ljava/awt/peer/FontPeer;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    AwtFont::pDataID = env->GetFieldID(cls, "pData", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    AwtFont::nameID = env->GetFieldID(cls, "name", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    AwtFont::sizeID = env->GetFieldID(cls, "size", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    AwtFont::styleID = env->GetFieldID(cls, "style", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    AwtFont::getFontMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
      env->GetStaticMethodID(cls, "getFont",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                             "(Ljava/lang/String;)Ljava/awt/Font;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    DASSERT(AwtFont::peerMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    DASSERT(AwtFont::pDataID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    DASSERT(AwtFont::nameID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    DASSERT(AwtFont::sizeID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    DASSERT(AwtFont::styleID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    DASSERT(AwtFont::getFontMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
 * java.awt.FontMetric native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
Java_java_awt_FontMetrics_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    AwtFont::fontID = env->GetFieldID(cls, "font", "Ljava/awt/Font;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    AwtFont::getHeightMID = env->GetMethodID(cls, "getHeight", "()I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    DASSERT(AwtFont::fontID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    DASSERT(AwtFont::getHeightMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
 * sun.awt.FontDescriptor native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
Java_sun_awt_FontDescriptor_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    AwtFont::nativeNameID = env->GetFieldID(cls, "nativeName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                            "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    AwtFont::useUnicodeID = env->GetFieldID(cls, "useUnicode", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    DASSERT(AwtFont::nativeNameID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    DASSERT(AwtFont::useUnicodeID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
 * sun.awt.PlatformFont native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
Java_sun_awt_PlatformFont_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    AwtFont::fontConfigID = env->GetFieldID(cls, "fontConfig", "Lsun/awt/FontConfiguration;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    AwtFont::componentFontsID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        env->GetFieldID(cls, "componentFonts", "[Lsun/awt/FontDescriptor;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    AwtFont::makeConvertedMultiFontStringMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        env->GetMethodID(cls, "makeConvertedMultiFontString",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                         "(Ljava/lang/String;)[Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    DASSERT(AwtFont::makeConvertedMultiFontStringMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    DASSERT(AwtFont::componentFontsID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    DASSERT(AwtFont::fontConfigID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
 * sun.awt.windows.WFontPeer native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
Java_sun_awt_windows_WFontPeer_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    AwtFont::textComponentFontNameID = env->GetFieldID(cls, "textComponentFontName", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    DASSERT(AwtFont::textComponentFontNameID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
 * FontCache methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
void AwtFontCache::Add(WCHAR* name, HFONT font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    fontCache.m_head = new Item(name, font, fontCache.m_head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
HFONT AwtFontCache::Lookup(WCHAR* name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    Item* item = fontCache.m_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    Item* lastItem = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    while (item != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        if (wcscmp(item->name, name) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            return item->font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        lastItem = item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        item = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
BOOL AwtFontCache::Search(HFONT font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    Item* item = fontCache.m_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    while (item != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        if (item->font == font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        item = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
void AwtFontCache::Remove(HFONT font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    Item* item = fontCache.m_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    Item* lastItem = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    while (item != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        if (item->font == font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (DecRefCount(item) <= 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                if (lastItem == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                    fontCache.m_head = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                lastItem->next = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
             delete item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        lastItem = item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        item = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
void AwtFontCache::Clear()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    Item* item = m_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    Item* next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    while (item != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        next = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        delete item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        item = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    m_head = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
/* NOTE: In the interlock calls below the return value is different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
         depending on which version of windows. However, all versions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
         return a 0 or less than value when the count gets there. Only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
         under NT 4.0 & 98 does the value actaully represent the new value. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
void AwtFontCache::IncRefCount(HFONT hFont){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    Item* item = fontCache.m_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    while (item != NULL){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        if (item->font == hFont){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            IncRefCount(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        item = item->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
LONG AwtFontCache::IncRefCount(Item* item){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    LONG    newVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    if(NULL != item){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        newVal = InterlockedIncrement((long*)&item->refCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    return(newVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
LONG AwtFontCache::DecRefCount(Item* item){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    LONG    newVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    if(NULL != item){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        newVal = InterlockedDecrement((long*)&item->refCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    return(newVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
AwtFontCache::Item::Item(const WCHAR* s, HFONT f, AwtFontCache::Item* n )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
{
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1192
    name = _wcsdup(s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    next = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    refCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
AwtFontCache::Item::~Item() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
  VERIFY(::DeleteObject(font));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
  free(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
/////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
// for canConvert native method of WDefaultFontCharset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
class CSegTableComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    CSegTableComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    virtual ~CSegTableComponent();
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1211
    virtual void Create(LPCWSTR name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    virtual BOOL In(USHORT iChar) { DASSERT(FALSE); return FALSE; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    LPWSTR GetFontName(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        DASSERT(m_lpszFontName != NULL); return m_lpszFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    LPWSTR m_lpszFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
CSegTableComponent::CSegTableComponent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    m_lpszFontName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
CSegTableComponent::~CSegTableComponent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    if (m_lpszFontName != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        free(m_lpszFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        m_lpszFontName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1234
void CSegTableComponent::Create(LPCWSTR name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    if (m_lpszFontName != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        free(m_lpszFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        m_lpszFontName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1240
    m_lpszFontName = _wcsdup(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    DASSERT(m_lpszFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
#define CMAPHEX 0x70616d63 // = "cmap" (reversed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
// CSegTable: Segment table describing character coverage for a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
class CSegTable : public CSegTableComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    CSegTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    virtual ~CSegTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    virtual BOOL In(USHORT iChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    BOOL HasCmap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    virtual BOOL IsEUDC() { DASSERT(FALSE); return FALSE; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
protected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    virtual void GetData(DWORD dwOffset, LPVOID lpData, DWORD cbData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        DASSERT(FALSE); };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    void MakeTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    static void SwapShort(USHORT& p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    static void SwapULong(ULONG& p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    USHORT m_cSegCount;     // number of segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    PUSHORT m_piStart;      // pointer to array of starting values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    PUSHORT m_piEnd;        // pointer to array of ending values (inclusive)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    USHORT m_cSeg;          // current segment (cache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
CSegTable::CSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    m_cSegCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    m_piStart = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    m_piEnd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    m_cSeg = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
CSegTable::~CSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    if (m_piStart != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        delete[] m_piStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    if (m_piEnd != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        delete[] m_piEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
#define OFFSETERROR 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
void CSegTable::MakeTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
typedef struct tagTABLE{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    USHORT  platformID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    USHORT  encodingID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    ULONG   offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
} TABLE, *PTABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
typedef struct tagSUBTABLE{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    USHORT  format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    USHORT  length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    USHORT  version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    USHORT  segCountX2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    USHORT  searchRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    USHORT  entrySelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    USHORT  rangeShift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
} SUBTABLE, *PSUBTABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    USHORT aShort[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    (void) GetData(0, aShort, sizeof(aShort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    USHORT nTables = aShort[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    SwapShort(nTables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    // allocate buffer to hold encoding tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    DWORD cbData = nTables * sizeof(TABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    PTABLE pTables = new TABLE[nTables];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    PTABLE pTable = pTables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    // get array of encoding tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    (void) GetData(4, (PBYTE) pTable, cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    ULONG offsetFormat4 = OFFSETERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    USHORT i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    for (i = 0; i < nTables; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        SwapShort(pTable->encodingID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        SwapShort(pTable->platformID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        //for a Unicode font for Windows, platformID == 3, encodingID == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if ((pTable->platformID == 3)&&(pTable->encodingID == 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            offsetFormat4 = pTable->offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            SwapULong(offsetFormat4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        pTable++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    delete[] pTables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    if (offsetFormat4 == OFFSETERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
//    DASSERT(offsetFormat4 != OFFSETERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    SUBTABLE subTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    (void) GetData(offsetFormat4, &subTable, sizeof(SUBTABLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    SwapShort(subTable.format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    SwapShort(subTable.segCountX2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    DASSERT(subTable.format == 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    m_cSegCount = subTable.segCountX2/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    // read in the array of segment end values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    m_piEnd = new USHORT[m_cSegCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    ULONG offset = offsetFormat4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        + sizeof(SUBTABLE); //skip constant # bytes in subtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    cbData = m_cSegCount * sizeof(USHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    (void) GetData(offset, m_piEnd, cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    for (i = 0; i < m_cSegCount; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        SwapShort(m_piEnd[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    DASSERT(m_piEnd[m_cSegCount-1] == 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    // read in the array of segment start values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        m_piStart = new USHORT[m_cSegCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    } catch (std::bad_alloc&) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        delete [] m_piEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        m_piEnd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    offset += cbData        //skip SegEnd array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        + sizeof(USHORT);   //skip reservedPad
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    (void) GetData(offset, m_piStart, cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    for (i = 0; i < m_cSegCount; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        SwapShort(m_piStart[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    DASSERT(m_piStart[m_cSegCount-1] == 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
BOOL CSegTable::In(USHORT iChar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    if (!HasCmap()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
//    DASSERT(m_piStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
//    DASSERT(m_piEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    if (iChar > m_piEnd[m_cSeg]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        for (; (m_cSeg < m_cSegCount)&&(iChar > m_piEnd[m_cSeg]); m_cSeg++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    } else if (iChar < m_piStart[m_cSeg]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        for (; (m_cSeg > 0)&&(iChar < m_piStart[m_cSeg]); m_cSeg--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    if ((iChar <= m_piEnd[m_cSeg])&&(iChar >= m_piStart[m_cSeg])&&(iChar != 0xffff))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
inline BOOL CSegTable::HasCmap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    return (((m_piEnd)&&(m_piStart)) ? TRUE : FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
inline void CSegTable::SwapShort(USHORT& p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    SHORT temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    temp = (SHORT)(HIBYTE(p) + (LOBYTE(p) << 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    p = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
inline void CSegTable::SwapULong(ULONG& p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    ULONG temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    temp = (LONG) ((BYTE) p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    temp <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    p >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    temp += (LONG) ((BYTE) p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    temp <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    p >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    temp += (LONG) ((BYTE) p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    temp <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    p >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    temp += (LONG) ((BYTE) p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    p = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
class CStdSegTable : public CSegTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    CStdSegTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    virtual ~CStdSegTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    BOOL IsEUDC() { return FALSE; };
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1433
    virtual void Create(LPCWSTR name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
protected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    void GetData(DWORD dwOffset, LPVOID lpData, DWORD cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    HDC m_hTmpDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
CStdSegTable::CStdSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    m_hTmpDC = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
CStdSegTable::~CStdSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    DASSERT(m_hTmpDC == NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
inline void CStdSegTable::GetData(DWORD dwOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                                  LPVOID lpData, DWORD cbData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    DASSERT(m_hTmpDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    DWORD nBytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        ::GetFontData(m_hTmpDC, CMAPHEX, dwOffset, lpData, cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    DASSERT(nBytes != GDI_ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1461
void CStdSegTable::Create(LPCWSTR name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    CSegTableComponent::Create(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    HWND hWnd = ::GetDesktopWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    DASSERT(hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    m_hTmpDC = ::GetWindowDC(hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    DASSERT(m_hTmpDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    HFONT hFont = CreateHFont_sub(name, 0, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    HFONT hOldFont = (HFONT)::SelectObject(m_hTmpDC, hFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    DASSERT(hOldFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
    (void) MakeTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    VERIFY(::SelectObject(m_hTmpDC, hOldFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    VERIFY(::DeleteObject(hFont));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    VERIFY(::ReleaseDC(hWnd, m_hTmpDC) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    m_hTmpDC = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
class CEUDCSegTable : public CSegTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    CEUDCSegTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    virtual ~CEUDCSegTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    BOOL IsEUDC() { return TRUE; };
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1489
    virtual void Create(LPCWSTR name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
protected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    void GetData(DWORD dwOffset, LPVOID lpData, DWORD cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    HANDLE m_hTmpFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    ULONG m_hTmpCMapOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
CEUDCSegTable::CEUDCSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    m_hTmpFile = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    m_hTmpCMapOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
CEUDCSegTable::~CEUDCSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    DASSERT(m_hTmpFile == NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    DASSERT(m_hTmpCMapOffset == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
inline void CEUDCSegTable::GetData(DWORD dwOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                                   LPVOID lpData, DWORD cbData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    DASSERT(m_hTmpFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    DASSERT(m_hTmpCMapOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    ::SetFilePointer(m_hTmpFile, m_hTmpCMapOffset + dwOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        NULL, FILE_BEGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    DWORD dwRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    VERIFY(::ReadFile(m_hTmpFile, lpData, cbData, &dwRead, NULL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    DASSERT(dwRead == cbData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1523
void CEUDCSegTable::Create(LPCWSTR name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
typedef struct tagHEAD{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    FIXED   sfnt_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    USHORT  numTables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    USHORT  searchRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    USHORT  entrySelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    USHORT  rangeShift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
} HEAD, *PHEAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
typedef struct tagENTRY{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    ULONG   tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    ULONG   checkSum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
    ULONG   offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    ULONG   length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
} ENTRY, *PENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    CSegTableComponent::Create(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    // create EUDC font file and make EUDCSegTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    // after wrapper function for CreateFileW, we use only CreateFileW
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1544
    m_hTmpFile = ::CreateFile(name, GENERIC_READ,
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1545
                               FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    if (m_hTmpFile == INVALID_HANDLE_VALUE){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        m_hTmpFile = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    HEAD head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    DWORD dwRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    VERIFY(::ReadFile(m_hTmpFile, &head, sizeof(head), &dwRead, NULL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    DASSERT(dwRead == sizeof(HEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    SwapShort(head.numTables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    ENTRY entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    for (int i = 0; i < head.numTables; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        VERIFY(::ReadFile(m_hTmpFile, &entry, sizeof(entry), &dwRead, NULL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        DASSERT(dwRead == sizeof(ENTRY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        if (entry.tag == CMAPHEX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    DASSERT(entry.tag == CMAPHEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    SwapULong(entry.offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    m_hTmpCMapOffset = entry.offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    (void) MakeTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    m_hTmpCMapOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    VERIFY(::CloseHandle(m_hTmpFile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    m_hTmpFile = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
class CSegTableManagerComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    CSegTableManagerComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    ~CSegTableManagerComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
protected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    void MakeBiggerTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
    CSegTableComponent **m_tables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    int m_nTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    int m_nMaxTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
#define TABLENUM 20
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
CSegTableManagerComponent::CSegTableManagerComponent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    m_nTable = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    m_nMaxTable = TABLENUM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    m_tables = new CSegTableComponent*[m_nMaxTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
CSegTableManagerComponent::~CSegTableManagerComponent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    for (int i = 0; i < m_nTable; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        DASSERT(m_tables[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        delete m_tables[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    delete [] m_tables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    m_tables = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
void CSegTableManagerComponent::MakeBiggerTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    CSegTableComponent **tables =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        new CSegTableComponent*[m_nMaxTable + TABLENUM];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    for (int i = 0; i < m_nMaxTable; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        tables[i] = m_tables[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    delete[] m_tables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    m_tables = tables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    m_nMaxTable += TABLENUM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
class CSegTableManager : public CSegTableManagerComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
public:
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1623
    CSegTable* GetTable(LPCWSTR lpszFontName, BOOL fEUDC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1626
CSegTable* CSegTableManager::GetTable(LPCWSTR lpszFontName, BOOL fEUDC)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    for (int i = 0; i < m_nTable; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        if ((((CSegTable*)m_tables[i])->IsEUDC() == fEUDC) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            (wcscmp(m_tables[i]->GetFontName(),lpszFontName) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            return (CSegTable*) m_tables[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    if (m_nTable == m_nMaxTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        (void) MakeBiggerTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    DASSERT(m_nTable < m_nMaxTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    if (!fEUDC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        m_tables[m_nTable] = new CStdSegTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        m_tables[m_nTable] = new CEUDCSegTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    m_tables[m_nTable]->Create(lpszFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    return (CSegTable*) m_tables[m_nTable++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
CSegTableManager g_segTableManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
class CCombinedSegTable : public CSegTableComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    CCombinedSegTable();
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1654
    void Create(LPCWSTR name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    BOOL In(USHORT iChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    LPSTR GetCodePageSubkey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    void GetEUDCFileName(LPWSTR lpszFileName, int cchFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    static char m_szCodePageSubkey[16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    static WCHAR m_szDefaultEUDCFile[_MAX_PATH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    static BOOL m_fEUDCSubKeyExist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    static BOOL m_fTTEUDCFileExist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    CStdSegTable* m_pStdSegTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    CEUDCSegTable* m_pEUDCSegTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
char CCombinedSegTable::m_szCodePageSubkey[16] = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
WCHAR CCombinedSegTable::m_szDefaultEUDCFile[_MAX_PATH] = L"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
BOOL CCombinedSegTable::m_fEUDCSubKeyExist = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
BOOL CCombinedSegTable::m_fTTEUDCFileExist = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
CCombinedSegTable::CCombinedSegTable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    m_pStdSegTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
    m_pEUDCSegTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
LPSTR CCombinedSegTable::GetCodePageSubkey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    if (strlen(m_szCodePageSubkey) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        return m_szCodePageSubkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    LPSTR lpszLocale = setlocale(LC_CTYPE, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    // cf lpszLocale = "Japanese_Japan.932"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    if (lpszLocale == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    LPSTR lpszCP = strchr(lpszLocale, (int) '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
    if (lpszCP == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    lpszCP++; // cf lpszCP = "932"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    char szSubKey[80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    strcpy(szSubKey, "EUDC\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    strcpy(&(szSubKey[strlen(szSubKey)]), lpszCP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    strcpy(m_szCodePageSubkey, szSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    return m_szCodePageSubkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
void CCombinedSegTable::GetEUDCFileName(LPWSTR lpszFileName, int cchFileName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    if (m_fEUDCSubKeyExist == FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    // get filename of typeface-specific TureType EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    LPSTR lpszSubKey = GetCodePageSubkey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    if (lpszSubKey == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        m_fEUDCSubKeyExist = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        return; // can not get codepage information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    HKEY hRootKey = HKEY_CURRENT_USER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    HKEY hKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    LONG lRet = ::RegOpenKeyExA(hRootKey, lpszSubKey, 0, KEY_ALL_ACCESS, &hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    if (lRet != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        m_fEUDCSubKeyExist = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        return; // no EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    // get EUDC font file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
    WCHAR szFamilyName[80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    wcscpy(szFamilyName, GetFontName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    WCHAR* delimit = wcschr(szFamilyName, L',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
    if (delimit != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        *delimit = L'\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    DWORD dwType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    UCHAR szFileName[_MAX_PATH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    ::ZeroMemory(szFileName, sizeof(szFileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    DWORD dwBytes = sizeof(szFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    // try Typeface-specific EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    char szTmpName[80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
    VERIFY(::WideCharToMultiByte(CP_ACP, 0, szFamilyName, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        szTmpName, sizeof(szTmpName), NULL, NULL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    LONG lStatus = ::RegQueryValueExA(hKey, (LPCSTR) szTmpName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        NULL, &dwType, szFileName, &dwBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    BOOL fUseDefault = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    if (lStatus != ERROR_SUCCESS){ // try System default EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        if (m_fTTEUDCFileExist == FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        if (wcslen(m_szDefaultEUDCFile) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            wcscpy(lpszFileName, m_szDefaultEUDCFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        char szDefault[] = "SystemDefaultEUDCFont";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        lStatus = ::RegQueryValueExA(hKey, (LPCSTR) szDefault,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            NULL, &dwType, szFileName, &dwBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        fUseDefault = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        if (lStatus != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            m_fTTEUDCFileExist = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            // This font is associated with no EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            // and there is no system default EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    if (strcmp((LPCSTR) szFileName, "userfont.fon") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        // This font is associated with no EUDC font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        // and the system default EUDC font is not TrueType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        m_fTTEUDCFileExist = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
    DASSERT(strlen((LPCSTR)szFileName) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
    VERIFY(::MultiByteToWideChar(CP_ACP, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        (LPCSTR)szFileName, -1, lpszFileName, cchFileName) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
    if (fUseDefault)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        wcscpy(m_szDefaultEUDCFile, lpszFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1776
void CCombinedSegTable::Create(LPCWSTR name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    CSegTableComponent::Create(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    m_pStdSegTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        (CStdSegTable*) g_segTableManager.GetTable(name, FALSE/*not EUDC*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    WCHAR szEUDCFileName[_MAX_PATH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    ::ZeroMemory(szEUDCFileName, sizeof(szEUDCFileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    (void) GetEUDCFileName(szEUDCFileName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        sizeof(szEUDCFileName)/sizeof(WCHAR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    if (wcslen(szEUDCFileName) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        m_pEUDCSegTable = (CEUDCSegTable*) g_segTableManager.GetTable(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            szEUDCFileName, TRUE/*EUDC*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        if (m_pEUDCSegTable->HasCmap() == FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            m_pEUDCSegTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
BOOL CCombinedSegTable::In(USHORT iChar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    DASSERT(m_pStdSegTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
    if (m_pStdSegTable->In(iChar))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    if (m_pEUDCSegTable != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        return m_pEUDCSegTable->In(iChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
class CCombinedSegTableManager : public CSegTableManagerComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
public:
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1809
    CCombinedSegTable* GetTable(LPCWSTR lpszFontName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1812
CCombinedSegTable* CCombinedSegTableManager::GetTable(LPCWSTR lpszFontName)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
    for (int i = 0; i < m_nTable; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        if (wcscmp(m_tables[i]->GetFontName(),lpszFontName) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            return (CCombinedSegTable*) m_tables[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
    if (m_nTable == m_nMaxTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        (void) MakeBiggerTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
    DASSERT(m_nTable < m_nMaxTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    m_tables[m_nTable] = new CCombinedSegTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    m_tables[m_nTable]->Create(lpszFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    return (CCombinedSegTable*) m_tables[m_nTable++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
 * WDefaultFontCharset native methos
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
Java_sun_awt_windows_WDefaultFontCharset_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    AwtFont::fontNameID = env->GetFieldID(cls, "fontName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                                          "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
    DASSERT(AwtFont::fontNameID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
 * !!!!!!!!!!!!!!!!!!!! this does not work. I am not sure why, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
 * when active, this will reliably crash HJ, with no hope of debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
 * for java.  It doesn't seem to crash the _g version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
 * I suspect may be running out of C stack: see alloca in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
 * JNI_GET_STRING, the alloca in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
 * (the method is prefixed with XXX so that the linker won't find it) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
Java_sun_awt_windows_WDefaultFontCharset_canConvert(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                                                    jchar ch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
    static CCombinedSegTableManager tableManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    jstring fontName = (jstring)env->GetObjectField(self, AwtFont::fontNameID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    DASSERT(fontName != NULL);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1870
    LPCWSTR fontNameW = JNU_GetStringPlatformChars(env, fontName, NULL);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1871
    CCombinedSegTable* pTable = tableManager.GetTable(fontNameW);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
  1872
    JNU_ReleaseStringPlatformChars(env, fontName, fontNameW);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    return (pTable->In((USHORT) ch) ? JNI_TRUE : JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    CATCH_BAD_ALLOC_RET(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
} /* extern "C" */