/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The function here is used to get a GDI rasterized LCD glyph and place it
* into the JDK glyph cache. The benefit is rendering fidelity for the
* most common cases, with no impact on the 2D rendering pipelines.
*
* Requires that the font and graphics are unrotated, and the scale is
* a simple one, and the font is a TT font registered with windows.
* Those conditions are established by the calling code.
*
* This code
* - Receives the family name, style, and size of the font
* and creates a Font object.
* - Create a surface from which we can get a DC : must be 16 bit or more.
* Ideally we'd be able to specify the depth of this, but in practice we
* have to accept it will be the same as the default screen.
* - Selects the GDI font on to the device
* - Uses GetGlyphOutline to estimate the bounds.
* - Creates a DIB on to which to blit the image.
* - Creates a GlyphInfo structure and copies the GDI glyph and offsets
* into the glyph which is returned.
*/
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <windows.h>
#include <winuser.h>
#include <jni.h>
#include <jni_util.h>
#include <jlong_md.h>
#include <sizecalc.h>
#include <sun_font_FileFontStrike.h>
#include "fontscalerdefs.h"
/* Some of these are also defined in awtmsg.h but I don't want a dependency
* on that here. They are needed here - and in awtmsg.h - until we
* move up our build to define WIN32_WINNT >= 0x501 (ie XP), since MS
* headers will not define them otherwise.
*/
#ifndef SPI_GETFONTSMOOTHINGTYPE
#endif //SPI_GETFONTSMOOTHINGTYPE
#ifndef SPI_GETFONTSMOOTHINGCONTRAST
#endif //SPI_GETFONTSMOOTHINGCONTRAST
#ifndef SPI_GETFONTSMOOTHINGORIENTATION
#endif //SPI_GETFONTSMOOTHINGORIENTATION
#ifndef FE_FONTSMOOTHINGORIENTATIONBGR
#endif //FE_FONTSMOOTHINGORIENTATIONBGR
#ifndef FE_FONTSMOOTHINGORIENTATIONRGB
#endif //FE_FONTSMOOTHINGORIENTATIONRGB
int i, index;
double ig;
char *igTable;
}
}
return NULL;
}
igTable[0] = 0;
for (i=1;i<255;i++) {
}
return igTable;
}
/* Need at least XP which is 5.1 */
return JNI_FALSE;
}
return JNI_TRUE;
}
#ifndef CLEARTYPE_QUALITY
#endif
#ifndef CLEARTYPE_NATURAL_QUALITY
#endif
#define FREE_AND_RETURN \
if (hDesktopDC != 0 && hWnd != 0) { \
}\
if (hMemoryDC != 0) { \
} \
if (hBitmap != 0) { \
DeleteObject(hBitmap); \
} \
} \
} \
return (jlong)0;
/* end define */
unsigned char r,g,b;
unsigned char* igTable;
int nameLen;
unsigned short width;
unsigned short height;
short advanceX;
short advanceY;
int topLeftX;
int topLeftY;
int err;
int x, y;
hWnd = GetDesktopWindow();
if (hDesktopDC == NULL) {
return (jlong)0;
}
}
}
if (err == 0) {
}
}
} else {
}
}
if (err == 0) {
}
/* Probably no such glyph - ie the font wasn't the one we expected. */
}
/* Don't handle "invisible" glyphs in this code */
}
/* GetGlyphOutline pre-dates cleartype and I'm not sure that it will
* account for all pixels touched by the rendering. Need to widen,
* and also adjust by one the x position at which it is rendered.
* The extra pixels of width are used as follows :
* One extra pixel at the left and the right will be needed to absorb
* the pixels that will be touched by filtering by GDI to compensate
* for colour fringing.
* However there seem to be some cases where GDI renders two extra
* pixels to the right, so we add one additional pixel to the right,
* and in the code that copies this to the image cache we test for
* the (rare) cases when this is touched, and if its not reduce the
* stated image width for the blitting loops.
* For fractional metrics :
* One extra pixel at each end to account for sub-pixel positioning used
* when fractional metrics is on in LCD mode.
* The pixel at the left is needed so the blitting loop can index into
* that a byte at a time to more accurately position the glyph.
* The pixel at the right is needed so that when such indexing happens,
* the blitting still can use the same width.
* Consequently the width that is specified for the glyph is one less
* than that of the actual image.
* Note that in the FM case as a consequence we need to adjust the
* position at which GDI renders, and the declared width of the glyph
* See the if (fm) {} cases in the code.
* For the non-FM case, we not only save 3 bytes per row, but this
* prevents apparent glyph overlapping which affects the rendering
* performance of accelerated pipelines since it adds additional
* read-back requirements.
*/
width+=3;
if (fm) {
width+=1;
}
/* DIB scanline must end on a DWORD boundary. We specify 3 bytes per pixel,
* so must round up as needed to a multiple of 4 bytes.
*/
if (extra != 0) {
}
/* The glyph cache image must be a multiple of 3 bytes wide. */
if (extra != 0) {
}
/* Must use desktop DC to create a bitmap of that depth */
}
/* Fill in black */
/* Set text color to white, background to black. */
/* adjust rendering position */
x = -topLeftX+1;
if (fm) {
x += 1;
}
if (err == 0) {
}
/* Now get the image into a DIB.
* MS docs for GetDIBits says the compatible bitmap must not be
* selected into a DC, so restore the original first.
*/
}
&bmi, DIB_RGB_COLORS);
if (err == 0) { /* GetDIBits failed. */
}
if (err == 0) {
}
if (err == 0) {
}
}
/* Now copy glyph image into a GlyphInfo structure and return it.
* NB the xadvance calculated here may be overwritten by the caller.
* 1 is subtracted from the bitmap width to get the glyph width, since
* that extra "1" was added as padding, so the sub-pixel positioning of
* fractional metrics could index into it.
*/
bytesWidth, height);
}
if (fm) {
}
if (fm) {
}
/* DIB 24bpp data is always stored in BGR order, but we usually
* need this in RGB, so we can't just memcpy and need to swap B and R.
* Also need to apply inverse gamma adjustment here.
* We re-use the variable "extra" to see if the last pixel is touched
* at all. If its not we can reduce the glyph image width. This comes
* into play in some cases where GDI touches more pixels than accounted
* for by increasing width by two pixels over the B&W image. Whilst
* the bytes are in the cache, it doesn't affect rendering performance
* of the hardware pipelines.
*/
extra = 0;
if (fm) {
}
for (y=0;y<height;y++) {
for (x=0;x<width;x++) {
if (orient == FE_FONTSMOOTHINGORIENTATIONRGB) {
b = *dibPixPtr++;
g = *dibPixPtr++;
r = *dibPixPtr++;
} else {
r = *dibPixPtr++;
g = *dibPixPtr++;
b = *dibPixPtr++;
}
extra = 1;
}
}
rowPtr += bytesWidth;
}
if (!extra) {
}
return ptr_to_jlong(glyphInfo);
}