jdk/src/java.desktop/share/native/common/font/fontscalerdefs.h
author prr
Mon, 28 Aug 2017 11:53:44 -0700
changeset 47188 0048f025c993
parent 28059 e576535359cc
permissions -rw-r--r--
8186317: Cache font layout tables for use by harfbuzz Reviewed-by: srl, pnarayanan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 16891
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef FontScalerDefsIncludesDefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define FontScalerDefsIncludesDefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "AccelGlyphCache.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#ifdef  __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define kPosInfinity16          (32767)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define kNegInfinity16          (-32768)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define kPosInfinity32          (0x7fffffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define kNegInfinity32          (0x80000000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#ifdef _LP64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
typedef unsigned int            UInt32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
typedef int                     Int32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
typedef unsigned long           UInt32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
typedef long                    Int32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
typedef unsigned short          UInt16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
typedef short                   Int16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
typedef unsigned char           UInt8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
typedef UInt8                   Byte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
typedef Int32                   hsFixed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
typedef Int32                   hsFract;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
typedef UInt32                  Bool32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
    58
#ifndef  __cplusplus
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#ifndef false
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
    60
         #define false           0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#ifndef true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        #define true            1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#endif
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
    66
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define kPosInfinity32          (0x7fffffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define kNegInfinity32          (0x80000000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define F26Dot6ToFixed(n)  ((n) << 10)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#define F26Dot6ToScalar(n) (((t2kScalar)(n)) / (t2kScalar)64)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  /* t2kFixed is the same as F16Dot16 format although T2K also uses 26.6 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
typedef Int32 t2kFixed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
typedef float t2kScalar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define t2kIntToFixed(x) ((t2kFixed)(x) << 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define t2kFixedToInt(x) ((x) >> 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define t2kFixedRound(x) (((x) + 0x8000) >> 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define t2kFixed1 t2kIntToFixed(1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define t2kFloatToFixed(f) (t2kFixed)((f) * (float)(t2kFixed1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#define t2kFixedToFloat(x) ((x) / (float)(65536))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define t2kScalarAverage(a, b) (((a) + (b)) / (t2kScalar)(2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    89
  /* managed: 1 means the glyph has a hardware cached
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26751
diff changeset
    90
   * copy, and its freeing is managed by the usual
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    91
   * 2D disposer code.
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    92
   * A value of 0 means its either unaccelerated (and so has no cellInfos)
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    93
   * or we want to free this in a different way.
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    94
   * The field uses previously unused padding, so doesn't enlarge
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    95
   * the structure.
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    96
   */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    97
#define UNMANAGED_GLYPH 0
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
    98
#define MANAGED_GLYPH   1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
typedef struct GlyphInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    float        advanceX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    float        advanceY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    UInt16       width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    UInt16       height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    UInt16       rowBytes;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   105
    UInt8         managed;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    float        topLeftX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    float        topLeftY;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   108
    void         *cellInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    UInt8        *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
} GlyphInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  /* We use fffe and ffff as meaning invisible glyphs which have no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   * image, or advance and an empty outline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
   * Since there are no valid glyphs with this great a value (watch out for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   * large fonts in the future!) we can safely use check for >= this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#define INVISIBLE_GLYPHS 0xfffe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
#define GSUB_TAG 0x47535542 /* 'GSUB' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#define GPOS_TAG 0x47504F53 /* 'GPOS' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#define GDEF_TAG 0x47444546 /* 'GDEF' */
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 28059
diff changeset
   122
#define HEAD_TAG 0x68656164 /* 'head' */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#define MORT_TAG 0x6D6F7274 /* 'mort' */
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   124
#define MORX_TAG 0x6D6F7278 /* 'morx' */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#define KERN_TAG 0x6B65726E /* 'kern' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   127
typedef struct TTLayoutTableCacheEntry {
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   128
  const void* ptr;
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   129
  int   len;
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 28059
diff changeset
   130
  int   tag;
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   131
} TTLayoutTableCacheEntry;
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   132
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 28059
diff changeset
   133
#define LAYOUTCACHE_ENTRIES 7
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   134
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
typedef struct TTLayoutTableCache {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   136
  TTLayoutTableCacheEntry entries[LAYOUTCACHE_ENTRIES];
91e99bed64ae 8001031: Better font processing
prr
parents: 9460
diff changeset
   137
  void* kernPairs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
} TTLayoutTableCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#include "sunfontids.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
JNIEXPORT extern TTLayoutTableCache* newLayoutTableCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
JNIEXPORT extern void freeLayoutTableCache(TTLayoutTableCache* ltc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
/* If font is malformed then scaler context created by particular scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * will be replaced by null scaler context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * Note that this context is not compatible with structure of the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * object used by particular scaler. Therefore, before using context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * scaler has to check if it is NullContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * Note that in theory request with NullContext should not even reach native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * scaler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * It seems that the only reason to support NullContext is to simplify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * FileFontStrike logic - presence of context is used as marker to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * free the memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
JNIEXPORT int isNullScalerContext(void *context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#ifdef  __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
#endif