Freetype stuff is now only in ttfont.c.

SVN revision: 8100
This commit is contained in:
Kim Woelders 2003-12-12 18:42:15 +00:00
parent bd85fc492e
commit aa96555f51
5 changed files with 431 additions and 392 deletions

View File

@ -51,13 +51,6 @@
#include <sys/resource.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#ifdef HAVE_FREETYPE1_FREETYPE_FREETYPE_H
#include <freetype1/freetype/freetype.h>
#elif defined(HAVE_FREETYPE_FREETYPE_H)
#include <freetype/freetype.h>
#else
#include <freetype.h>
#endif
#define ESetColor(pxc, r, g, b) \
({ (pxc)->red = ((r)<<8)|r; (pxc)->green = ((g)<<8)|g; (pxc)->blue = ((b)<<8)|b; })
@ -189,6 +182,8 @@ extern Drawable vIcDrw;
#define ENCOING_ISO_8859_3 2
#define ENCOING_ISO_8859_4 3
typedef struct _efont Efont;
#define Esetenv(var, val, overwrite) \
{ \
static char envvar[1024]; \
@ -208,21 +203,6 @@ typedef struct _root
}
Root;
typedef struct _efont
{
TT_Engine engine;
TT_Face face;
TT_Instance instance;
TT_Face_Properties properties;
int num_glyph;
TT_Glyph *glyphs;
TT_Raster_Map **glyphs_cached;
TT_CharMap char_map;
int max_descent;
int max_ascent;
}
Efont;
typedef struct _textstate
{
char *fontname;
@ -377,3 +357,6 @@ extern Root root;
extern FnlibData *pFnlibData;
#endif
extern char *docdir;
#define Emalloc malloc
#define Efree free

View File

@ -1,46 +1,72 @@
/*
Copyright (C) 2000-2003 Carsten Haitzler, Geoff Harrison and various contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies of the Software, its documentation and marketing & publicity
materials, and acknowledgment shall be given in the documentation, materials
and software packages that this Software was used.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Copyright (C) 2000-2003 Carsten Haitzler, Geoff Harrison and various contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of the Software, its documentation and marketing & publicity
* materials, and acknowledgment shall be given in the documentation, materials
* and software packages that this Software was used.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "dox.h"
#if TEST_TTFONT
#undef XSync
#undef IC_RenderDepth
#define IC_RenderDepth() DefaultDepth(disp, DefaultScreen(disp))
#define EGetGeometry XGetGeometry
#endif
#ifdef HAVE_FREETYPE1_FREETYPE_FREETYPE_H
#include <freetype1/freetype/freetype.h>
#elif defined(HAVE_FREETYPE_FREETYPE_H)
#include <freetype/freetype.h>
#else
#include <freetype.h>
#endif
struct _efont
{
TT_Engine engine;
TT_Face face;
TT_Instance instance;
TT_Face_Properties properties;
int num_glyph;
TT_Glyph *glyphs;
TT_Raster_Map **glyphs_cached;
TT_CharMap char_map;
int max_descent;
int max_ascent;
};
typedef struct _efont_color_tab EfontColorTable;
struct _efont_color_tab
{
Colormap cmap;
{
Colormap cmap;
XColor list[256];
unsigned char match[8][8][8];
};
XColor list[256];
unsigned char match[8][8][8];
};
/*static EfontColorTable *color_tab = NULL; */
static unsigned char alpha_lut[5] =
{0, 64, 128, 192, 255};
static unsigned char bounded_palette[9] =
{0, 1, 2, 3, 4, 4, 4, 4, 4};
static unsigned char alpha_lut[5] = { 0, 64, 128, 192, 255 };
static unsigned char bounded_palette[9] = { 0, 1, 2, 3, 4, 4, 4, 4, 4 };
struct _imlib_encoding_map {
struct _imlib_encoding_map
{
unsigned short char_map[98];
};
@ -48,140 +74,146 @@ typedef struct _imlib_encoding_map ImlibEncodingMap;
/* Encoding maps */
static const ImlibEncodingMap iso1 = {
{
/* ISO-8859-1 encoding (conversion to UTF-8) */
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8,
0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1,
0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA,
0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3,
0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC,
0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5,
0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE,
0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0,
0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9,
0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
}
{
/* ISO-8859-1 encoding (conversion to UTF-8) */
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8,
0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1,
0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA,
0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3,
0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC,
0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5,
0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE,
0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0,
0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9,
0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF}
};
static const ImlibEncodingMap iso2 = {
{
/* ISO-8859-2 encoding (conversion to UTF-8) */
0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8,
0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0, 0x0105,
0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8, 0x0161, 0x015F,
0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154, 0x00C1, 0x00C2, 0x0102,
0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A,
0x00CD, 0x00CE, 0x010E, 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150,
0x00D6, 0x00D7, 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162,
0x00DF, 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111,
0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159, 0x016F,
0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
}
{
/* ISO-8859-2 encoding (conversion to UTF-8) */
0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8,
0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0, 0x0105,
0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8, 0x0161, 0x015F,
0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154, 0x00C1, 0x00C2, 0x0102,
0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A,
0x00CD, 0x00CE, 0x010E, 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150,
0x00D6, 0x00D7, 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162,
0x00DF, 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111,
0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159, 0x016F,
0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9}
};
static const ImlibEncodingMap iso3 = {
{
/* ISO-8859-3 encoding (conversion to UTF-8) */
0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0x0124, 0x00A7, 0x00A8, 0x0130,
0x015E, 0x011E, 0x0134, 0x00AD, 0x017B, 0x00B0, 0x0127, 0x00B2, 0x00B3,
0x00B4, 0x00B5, 0x0125, 0x00B7, 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135,
0x00BD, 0x017C, 0x00C0, 0x00C1, 0x00C2, 0x00C4, 0x010A, 0x0108, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D1,
0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, 0x011C, 0x00D9, 0x00DA,
0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E4,
0x010B, 0x0109, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED,
0x00EE, 0x00EF, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7,
0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9
}
{
/* ISO-8859-3 encoding (conversion to UTF-8) */
0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0x0124, 0x00A7, 0x00A8, 0x0130,
0x015E, 0x011E, 0x0134, 0x00AD, 0x017B, 0x00B0, 0x0127, 0x00B2, 0x00B3,
0x00B4, 0x00B5, 0x0125, 0x00B7, 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135,
0x00BD, 0x017C, 0x00C0, 0x00C1, 0x00C2, 0x00C4, 0x010A, 0x0108, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D1,
0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, 0x011C, 0x00D9, 0x00DA,
0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E4,
0x010B, 0x0109, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED,
0x00EE, 0x00EF, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7,
0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9}
};
static const ImlibEncodingMap iso4 = {
{
/* ISO-8859-4 encoding (conversion to UTF-8) */
0x00A0, 0x0104, 0x0138, 0x0156, 0x00A4, 0x0128, 0x013B, 0x00A7, 0x00A8,
0x0160, 0x0112, 0x0122, 0x0166, 0x00AD, 0x017D, 0x00AF, 0x00B0, 0x0105,
0x02DB, 0x0157, 0x00B4, 0x0129, 0x013C, 0x02C7, 0x00B8, 0x0161, 0x0113,
0x0123, 0x0167, 0x014A, 0x017E, 0x014B, 0x0100, 0x00C1, 0x00C2, 0x00C3,
0x00C4, 0x00C5, 0x00C6, 0x012E, 0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116,
0x00CD, 0x00CE, 0x012A, 0x0110, 0x0145, 0x014C, 0x0136, 0x00D4, 0x00D5,
0x00D6, 0x00D7, 0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x0168, 0x016A,
0x00DF, 0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F,
0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x012B, 0x0111,
0x0146, 0x014D, 0x0137, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x0173,
0x00FA, 0x00FB, 0x00FC, 0x0169, 0x016B, 0x02D9
}
{
/* ISO-8859-4 encoding (conversion to UTF-8) */
0x00A0, 0x0104, 0x0138, 0x0156, 0x00A4, 0x0128, 0x013B, 0x00A7, 0x00A8,
0x0160, 0x0112, 0x0122, 0x0166, 0x00AD, 0x017D, 0x00AF, 0x00B0, 0x0105,
0x02DB, 0x0157, 0x00B4, 0x0129, 0x013C, 0x02C7, 0x00B8, 0x0161, 0x0113,
0x0123, 0x0167, 0x014A, 0x017E, 0x014B, 0x0100, 0x00C1, 0x00C2, 0x00C3,
0x00C4, 0x00C5, 0x00C6, 0x012E, 0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116,
0x00CD, 0x00CE, 0x012A, 0x0110, 0x0145, 0x014C, 0x0136, 0x00D4, 0x00D5,
0x00D6, 0x00D7, 0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x0168, 0x016A,
0x00DF, 0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F,
0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x012B, 0x0111,
0x0146, 0x014D, 0x0137, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x0173,
0x00FA, 0x00FB, 0x00FC, 0x0169, 0x016B, 0x02D9}
};
static const ImlibEncodingMap iso5 = {
{
/* ISO-8859-5 encoding (conversion to UTF-8) */
0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408,
0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F, 0x0410, 0x0411,
0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A,
0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423,
0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C,
0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435,
0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E,
0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x2116,
0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459,
0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F
}
{
/* ISO-8859-5 encoding (conversion to UTF-8) */
0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408,
0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F, 0x0410, 0x0411,
0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A,
0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423,
0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C,
0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435,
0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E,
0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x2116,
0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459,
0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F}
};
static const ImlibEncodingMap* _imlib_encodings[5] = { &iso1, &iso2, &iso3, &iso4, &iso5 };
int IsoEncoding = ENCOING_ISO_8859_1;
char encoding_initialized = 0;
static const ImlibEncodingMap *_imlib_encodings[5] =
{ &iso1, &iso2, &iso3, &iso4, &iso5 };
int IsoEncoding = ENCOING_ISO_8859_1;
char encoding_initialized = 0;
static void
static void
__init_iso_encoding()
{
/* Set the current ISO encoding based on (in that order):
* the "IMLIB_ENCODING" environment variable,
* the "LANG" variable,
* the ISO-8859-1 default */
char *s, *enc_num, *lang;
char iso2lang[21] = "cs hu pl ro hr sk sl";
char iso3lang[6] = "eo mt";
char iso4lang[12] = "et lv lt kl";
char iso5lang[18] = "bg be mk ru sr uk";
/* Set the current ISO encoding based on (in that order):
* the "IMLIB_ENCODING" environment variable,
* the "LANG" variable,
* the ISO-8859-1 default */
/* Check if we already initialized the encoding */
if (!encoding_initialized)
{
IsoEncoding = 255;
/* First check if we have IMLIB_ENCODING variable set */
if ((s = getenv("IMLIB_ENCODING")) != NULL)
{
if ((enc_num = strstr(s, "8859-")) != NULL)
{
if (!strcmp((enc_num+5), "1")) IsoEncoding = 0;
else if (!strcmp((enc_num+5), "2")) IsoEncoding = 1;
else if (!strcmp((enc_num+5), "3")) IsoEncoding = 2;
else if (!strcmp((enc_num+5), "4")) IsoEncoding = 3;
else if (!strcmp((enc_num+5), "5")) IsoEncoding = 4;
}
}
if (IsoEncoding == 255)
{
/* Still not initialized - try to guess from LANG variable */
if ((lang = getenv("LANG")) != NULL)
{
if (strstr(iso2lang, lang) != NULL) IsoEncoding = 1;
else if (strstr(iso3lang, lang) != NULL) IsoEncoding = 2;
else if (strstr(iso4lang, lang) != NULL) IsoEncoding = 3;
else if (strstr(iso5lang, lang) != NULL) IsoEncoding = 4;
}
}
if (IsoEncoding == 255) {
/* Still not initialized - default to ISO8859-1 */
IsoEncoding = 0;
}
encoding_initialized = 1;
}
char *s, *enc_num, *lang;
char iso2lang[21] = "cs hu pl ro hr sk sl";
char iso3lang[6] = "eo mt";
char iso4lang[12] = "et lv lt kl";
char iso5lang[18] = "bg be mk ru sr uk";
/* Check if we already initialized the encoding */
if (!encoding_initialized)
{
IsoEncoding = 255;
/* First check if we have IMLIB_ENCODING variable set */
if ((s = getenv("IMLIB_ENCODING")) != NULL)
{
if ((enc_num = strstr(s, "8859-")) != NULL)
{
if (!strcmp((enc_num + 5), "1"))
IsoEncoding = 0;
else if (!strcmp((enc_num + 5), "2"))
IsoEncoding = 1;
else if (!strcmp((enc_num + 5), "3"))
IsoEncoding = 2;
else if (!strcmp((enc_num + 5), "4"))
IsoEncoding = 3;
else if (!strcmp((enc_num + 5), "5"))
IsoEncoding = 4;
}
}
if (IsoEncoding == 255)
{
/* Still not initialized - try to guess from LANG variable */
if ((lang = getenv("LANG")) != NULL)
{
if (strstr(iso2lang, lang) != NULL)
IsoEncoding = 1;
else if (strstr(iso3lang, lang) != NULL)
IsoEncoding = 2;
else if (strstr(iso4lang, lang) != NULL)
IsoEncoding = 3;
else if (strstr(iso5lang, lang) != NULL)
IsoEncoding = 4;
}
}
if (IsoEncoding == 255)
{
/* Still not initialized - default to ISO8859-1 */
IsoEncoding = 0;
}
encoding_initialized = 1;
}
}
static TT_Raster_Map *
@ -189,14 +221,19 @@ create_font_raster(int width, int height)
{
TT_Raster_Map *rmap;
rmap = malloc(sizeof(TT_Raster_Map));
rmap = Emalloc(sizeof(TT_Raster_Map));
rmap->width = (width + 3) & -4;
rmap->rows = height;
rmap->flow = TT_Flow_Down;
rmap->cols = rmap->width;
rmap->size = rmap->rows * rmap->width;
rmap->bitmap = malloc(rmap->size);
memset(rmap->bitmap, 0, rmap->size);
if (rmap->size > 0)
{
rmap->bitmap = Emalloc(rmap->size);
memset(rmap->bitmap, 0, rmap->size);
}
else
rmap->bitmap = NULL;
return rmap;
}
@ -205,10 +242,15 @@ duplicate_raster(TT_Raster_Map * rmap)
{
TT_Raster_Map *new_rmap;
new_rmap = malloc(sizeof(TT_Raster_Map));
new_rmap = Emalloc(sizeof(TT_Raster_Map));
*new_rmap = *rmap;
new_rmap->bitmap = malloc(new_rmap->size);
memcpy(new_rmap->bitmap, rmap->bitmap, new_rmap->size);
if (new_rmap->size > 0)
{
new_rmap->bitmap = Emalloc(new_rmap->size);
memcpy(new_rmap->bitmap, rmap->bitmap, new_rmap->size);
}
else
new_rmap->bitmap = NULL;
return new_rmap;
}
@ -221,8 +263,11 @@ clear_raster(TT_Raster_Map * rmap)
static void
destroy_font_raster(TT_Raster_Map * rmap)
{
free(rmap->bitmap);
free(rmap);
if (!rmap)
return;
if (rmap->bitmap)
Efree(rmap->bitmap);
Efree(rmap);
}
static TT_Raster_Map *
@ -244,7 +289,7 @@ calc_size(Efont * f, int *width, int *height, char *text)
for (i = 0; text[i]; i++)
{
unsigned char j = text[i];
unsigned char j = text[i];
if (!TT_VALID(f->glyphs[j]))
continue;
@ -278,7 +323,7 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text,
int i, ioff, iread;
char *off, *read, *_off, *_read;
int x_offset, y_offset;
unsigned char j;
unsigned char j;
TT_Raster_Map *rtmp;
TT_Get_Instance_Metrics(f->instance, &imetrics);
@ -295,7 +340,7 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text,
rtmp = NULL;
for (i = 0; text[i]; i++)
{
j = text[i];
j = text[i];
if (!TT_VALID(f->glyphs[j]))
continue;
@ -327,10 +372,8 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text,
/* This was the cause of strange misplacements when Bit.rows */
/* was unsigned. */
if (xmin >= (int)rmap->width ||
ymin >= (int)rmap->rows ||
xmax < 0 ||
ymax < 0)
if (xmin >= (int)rmap->width || ymin >= (int)rmap->rows ||
xmax < 0 || ymax < 0)
continue;
/* Note that the clipping check is performed _after_ rendering */
@ -407,7 +450,8 @@ merge_text_16(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
cb = (col << 3) & 0xf8;
for (y = 0; y < xim->height; y++)
{
ptr = (unsigned char *)rmap->bitmap + offset_x + ((y + offset_y) * rmap->cols);
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
if ((a = alpha_lut[*ptr]) > 0)
@ -425,7 +469,8 @@ merge_text_16(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
ng = g + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (cb - b) * a;
nb = b + ((tmp + (tmp >> 8) + 0x80) >> 8);
pixel = ((nr & 0xf8) << 8) | ((ng & 0xfc) << 3) | ((nb & 0xf8) >> 3);
pixel = ((nr & 0xf8) << 8) | ((ng & 0xfc) << 3) |
((nb & 0xf8) >> 3);
XPutPixel(xim, x, y, pixel);
}
else
@ -450,7 +495,8 @@ merge_text_15(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
cb = (col << 3) & 0xf8;
for (y = 0; y < xim->height; y++)
{
ptr = (unsigned char *)rmap->bitmap + offset_x + ((y + offset_y) * rmap->cols);
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
if ((a = alpha_lut[*ptr]) > 0)
@ -468,7 +514,8 @@ merge_text_15(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
ng = g + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (cb - b) * a;
nb = b + ((tmp + (tmp >> 8) + 0x80) >> 8);
pixel = ((nr & 0xf8) << 7) | ((ng & 0xf8) << 2) | ((nb & 0xf8) >> 3);
pixel = ((nr & 0xf8) << 7) | ((ng & 0xf8) << 2) |
((nb & 0xf8) >> 3);
XPutPixel(xim, x, y, pixel);
}
else
@ -493,7 +540,8 @@ merge_text_24(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
cb = col & 0xff;
for (y = 0; y < xim->height; y++)
{
ptr = (unsigned char *)rmap->bitmap + offset_x + ((y + offset_y) * rmap->cols);
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
if ((a = alpha_lut[*ptr]) > 0)
@ -570,7 +618,8 @@ merge_text_1(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
for (y = 0; y < xim->height; y++)
{
ptr = (unsigned char *)rmap->bitmap + offset_x + ((y + offset_y) * rmap->cols);
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
if (alpha_lut[*ptr] > 2)
@ -641,8 +690,7 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
XGetWindowAttributes(disp, xatt.root, &ratt);
XTranslateCoordinates(disp, win, xatt.root, 0, 0, &rx, &ry, &chld);
if ((xatt.map_state != IsViewable) &&
(xatt.backing_store == NotUseful))
if ((xatt.map_state != IsViewable) && (xatt.backing_store == NotUseful))
{
destroy_font_raster(rmap);
destroy_font_raster(rtmp);
@ -724,7 +772,8 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
shm = 0;
XDestroyImage(xim);
xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
XSetErrorHandler((XErrorHandler) erh);
shm_checked = 1;
}
@ -736,7 +785,8 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
shm = 0;
XDestroyImage(xim);
xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
XSetErrorHandler((XErrorHandler) erh);
shm_checked = 1;
}
@ -756,7 +806,8 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
shm = 0;
XDestroyImage(xim);
xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
XSetErrorHandler((XErrorHandler) erh);
shm_checked = 1;
}
@ -774,7 +825,8 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
shm = 0;
XDestroyImage(xim);
xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
shm_checked = 1;
}
XSetErrorHandler((XErrorHandler) erh);
@ -814,8 +866,7 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
merge_text_1(xim, rmap, clipx, clipy, col);
if (shm)
XShmPutImage(disp, win, gc, xim, 0, 0, x, y,
width, height, False);
XShmPutImage(disp, win, gc, xim, 0, 0, x, y, width, height, False);
else
XPutImage(disp, win, gc, xim, 0, 0, x, y, width, height);
destroy_font_raster(rmap);
@ -847,9 +898,11 @@ Efont_free(Efont * f)
if (!TT_VALID(f->glyphs[i]))
TT_Done_Glyph(f->glyphs[i]);
}
free(f->glyphs);
free(f->glyphs_cached);
free(f);
if (f->glyphs)
Efree(f->glyphs);
if (f->glyphs_cached)
Efree(f->glyphs_cached);
Efree(f);
}
Efont *
@ -873,12 +926,12 @@ Efont_load(char *file, int size)
return NULL;
have_engine = 1;
}
f = malloc(sizeof(Efont));
f = Emalloc(sizeof(Efont));
f->engine = engine;
error = TT_Open_Face(f->engine, file, &f->face);
if (error)
{
free(f);
Efree(f);
/* fprintf(stderr, "Unable to open font\n"); */
return NULL;
}
@ -886,7 +939,7 @@ Efont_load(char *file, int size)
if (error)
{
TT_Close_Face(f->face);
free(f);
Efree(f);
/* fprintf(stderr, "Unable to get face properties\n"); */
return NULL;
}
@ -894,7 +947,7 @@ Efont_load(char *file, int size)
if (error)
{
TT_Close_Face(f->face);
free(f);
Efree(f);
/* fprintf(stderr, "Unable to create instance\n"); */
return NULL;
}
@ -909,8 +962,8 @@ Efont_load(char *file, int size)
if ((platform == 3 && encoding == 1) ||
(platform == 0 && encoding == 0))
{
/* TT_Get_CharMap(f->face, i, &char_map); */
TT_Get_CharMap(f->face, i, &(f->char_map));
/* TT_Get_CharMap(f->face, i, &char_map); */
TT_Get_CharMap(f->face, i, &(f->char_map));
break;
}
}
@ -920,14 +973,14 @@ Efont_load(char *file, int size)
num_glyphs = f->properties.num_Glyphs;
TT_Done_Instance(f->instance);
TT_Close_Face(f->face);
free(f);
Efree(f);
/* fprintf(stderr, "Sorry, but this font doesn't contain any Unicode mapping table\n"); */
return NULL;
}
f->num_glyph = 256;
f->glyphs = (TT_Glyph *) malloc(256 * sizeof(TT_Glyph));
f->glyphs = (TT_Glyph *) Emalloc(256 * sizeof(TT_Glyph));
memset(f->glyphs, 0, 256 * sizeof(TT_Glyph));
f->glyphs_cached = (TT_Raster_Map **) malloc(256 * sizeof(TT_Raster_Map *));
f->glyphs_cached = (TT_Raster_Map **) Emalloc(256 * sizeof(TT_Raster_Map *));
memset(f->glyphs_cached, 0, 256 * sizeof(TT_Raster_Map *));
load_flags = TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH;
@ -946,11 +999,13 @@ Efont_load(char *file, int size)
if (index >= num_glyphs)
index = 0;
}
else if (i < 0xA0)
index = TT_Char_Index(f->char_map, i);
else
if (i < 0xA0 )
index = TT_Char_Index(f->char_map, i);
else
index = TT_Char_Index(f->char_map, _imlib_encodings[IsoEncoding]->char_map[(i - 0xA0)]);
index =
TT_Char_Index(f->char_map,
_imlib_encodings[IsoEncoding]->
char_map[(i - 0xA0)]);
TT_New_Glyph(f->face, &f->glyphs[i]);
TT_Load_Glyph(f->instance, f->glyphs[i], index, load_flags);
@ -989,7 +1044,7 @@ Efont_extents(Efont * f, char *text, int *font_ascent_return,
for (i = 0; text[i]; i++)
{
unsigned char j = text[i];
unsigned char j = text[i];
if (!TT_VALID(f->glyphs[j]))
continue;
@ -1002,7 +1057,8 @@ Efont_extents(Efont * f, char *text, int *font_ascent_return,
if (text[i + 1] == 0)
{
if (rbearing_return)
*rbearing_return = ((gmetrics.bbox.xMax - gmetrics.advance) / 64);
*rbearing_return =
((gmetrics.bbox.xMax - gmetrics.advance) / 64);
}
pw += gmetrics.advance / 64;
}
@ -1018,42 +1074,43 @@ Efont_extents(Efont * f, char *text, int *font_ascent_return,
*max_descent_return = f->max_descent;
}
/*
* int
* main( int argc, char **argv)
* {
* Display *disp;
* Efont *f;
* GC gc;
* XGCValues gcv;
* Window win;
* int i;
*
* disp=XOpenDisplay(NULL);
* XSync(disp, False);
* srand(time(NULL));
* win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
* 0, 0);
* XMapWindow(disp, win);
* XSync(disp, False);
*
* gcv.subwindow_mode = IncludeInferiors;
* gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
* for (;;)
* {
* for (i = 3; i < argc; i++)
* {
* XSetForeground(disp, gc, rand()<<16 | rand());
* f = Efont_load(argv[i], atoi(argv[1]));
* if (f)
* EFont_draw_string(disp, win, gc, 20, (atoi(argv[1])/10) * (i-2), argv[2],
* f,
* DefaultVisual(disp, DefaultScreen(disp)),
* DefaultColormap(disp, DefaultScreen(disp)));
* Efont_free(f);
* f = NULL;
* }
* }
* return 0;
* }
*/
#if TEST_TTFONT
Display *disp;
int
main(int argc, char **argv)
{
Efont *f;
GC gc;
XGCValues gcv;
Window win;
int i, j;
disp = XOpenDisplay(NULL);
XSync(disp, False);
srand(time(NULL));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
0, 0);
XMapWindow(disp, win);
XSync(disp, False);
gcv.subwindow_mode = IncludeInferiors;
gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
for (;; j++)
{
for (i = 3; i < argc; i++)
{
XSetForeground(disp, gc, rand() << 16 | rand());
f = Efont_load(argv[i], atoi(argv[1]));
if (f)
EFont_draw_string(disp, win, gc, 20,
atoi(argv[1]) * (i - 2), argv[2], f,
DefaultVisual(disp, DefaultScreen(disp)),
DefaultColormap(disp, DefaultScreen(disp)));
Efont_free(f);
f = NULL;
}
}
return 0;
}
#endif

32
src/E.h
View File

@ -195,13 +195,6 @@ if (__xim) XDestroyImage(__xim);}
#include <sys/resource.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#ifdef HAVE_FREETYPE1_FREETYPE_FREETYPE_H
#include <freetype1/freetype/freetype.h>
#elif defined(HAVE_FREETYPE_FREETYPE_H)
#include <freetype/freetype.h>
#else
#include <freetype.h>
#endif
/* workaround for 64bit architectures - xlib expects 32bit CARDINALS to be */
/* long's on 64bit machines... thus well the CARD32's Im unsing shoudl be.. */
@ -671,6 +664,8 @@ typedef struct _group Group;
typedef struct _button Button;
typedef struct _buttoncontainer Container;
typedef struct _efont Efont;
typedef struct
{
char type;
@ -786,21 +781,6 @@ typedef struct _imageclass
}
ImageClass;
typedef struct _efont
{
TT_Engine engine;
TT_Face face;
TT_Instance instance;
TT_Face_Properties properties;
int num_glyph;
TT_Glyph *glyphs;
TT_Raster_Map **glyphs_cached;
TT_CharMap char_map;
int max_descent;
int max_ascent;
}
Efont;
#if !USE_FNLIB
#define MODE_VERBATIM 0
#define MODE_WRAP_CHAR 1
@ -2498,7 +2478,13 @@ void FreeProgressbar(Progressbar * p);
Window *ListProgressWindows(int *num);
void RaiseProgressbars(void);
#if defined(__FILE__) && defined(__LINE__)
#if defined(USE_LIBC_MALLOC)
#define Emalloc malloc
#define Efree free
#elif defined(__FILE__) && defined(__LINE__)
#define Efree(x) \
__Efree(x, __FILE__, __LINE__)
#define Emalloc(x) \

View File

@ -1,4 +1,3 @@
/*
* Copyright (C) 2000-2003 Carsten Haitzler, Geoff Harrison and various contributors
*
@ -48,9 +47,6 @@ CreateTclass()
void
FreeTextState(TextState * ts)
{
int i = 0;
if (ts->fontname)
Efree(ts->fontname);
#if USE_FNLIB
@ -60,21 +56,8 @@ FreeTextState(TextState * ts)
if (ts->xfont)
XFreeFont(disp, ts->xfont);
if (ts->efont)
{
for (i = 0; i < ts->efont->num_glyph; i++)
{
Efree(ts->efont->glyphs_cached[i]->bitmap);
Efree(ts->efont->glyphs_cached[i]);
TT_Done_Glyph(ts->efont->glyphs[i]);
}
Efree(ts->efont->glyphs_cached);
Efree(ts->efont->glyphs);
Efree(ts->efont);
}
Efont_free(ts->efont);
Efree(ts);
return;
}
void

View File

@ -22,6 +22,35 @@
*/
#include "E.h"
#if TEST_TTFONT
#undef XSync
#undef IC_RenderDepth
#define IC_RenderDepth() DefaultDepth(disp, DefaultScreen(disp))
#define EGetGeometry XGetGeometry
#endif
#ifdef HAVE_FREETYPE1_FREETYPE_FREETYPE_H
#include <freetype1/freetype/freetype.h>
#elif defined(HAVE_FREETYPE_FREETYPE_H)
#include <freetype/freetype.h>
#else
#include <freetype.h>
#endif
struct _efont
{
TT_Engine engine;
TT_Face face;
TT_Instance instance;
TT_Face_Properties properties;
int num_glyph;
TT_Glyph *glyphs;
TT_Raster_Map **glyphs_cached;
TT_CharMap char_map;
int max_descent;
int max_ascent;
};
typedef struct _efont_color_tab EfontColorTable;
struct _efont_color_tab
@ -343,8 +372,8 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text,
/* This was the cause of strange misplacements when Bit.rows */
/* was unsigned. */
if (xmin >= (int)rmap->width || ymin >= (int)rmap->rows || xmax < 0
|| ymax < 0)
if (xmin >= (int)rmap->width || ymin >= (int)rmap->rows ||
xmax < 0 || ymax < 0)
continue;
/* Note that the clipping check is performed _after_ rendering */
@ -421,8 +450,7 @@ merge_text_16(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
cb = (col << 3) & 0xf8;
for (y = 0; y < xim->height; y++)
{
ptr =
(unsigned char *)rmap->bitmap + offset_x +
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
@ -441,8 +469,7 @@ merge_text_16(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
ng = g + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (cb - b) * a;
nb = b + ((tmp + (tmp >> 8) + 0x80) >> 8);
pixel =
((nr & 0xf8) << 8) | ((ng & 0xfc) << 3) |
pixel = ((nr & 0xf8) << 8) | ((ng & 0xfc) << 3) |
((nb & 0xf8) >> 3);
XPutPixel(xim, x, y, pixel);
}
@ -468,8 +495,7 @@ merge_text_15(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
cb = (col << 3) & 0xf8;
for (y = 0; y < xim->height; y++)
{
ptr =
(unsigned char *)rmap->bitmap + offset_x +
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
@ -488,8 +514,7 @@ merge_text_15(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
ng = g + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (cb - b) * a;
nb = b + ((tmp + (tmp >> 8) + 0x80) >> 8);
pixel =
((nr & 0xf8) << 7) | ((ng & 0xf8) << 2) |
pixel = ((nr & 0xf8) << 7) | ((ng & 0xf8) << 2) |
((nb & 0xf8) >> 3);
XPutPixel(xim, x, y, pixel);
}
@ -515,8 +540,7 @@ merge_text_24(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
cb = col & 0xff;
for (y = 0; y < xim->height; y++)
{
ptr =
(unsigned char *)rmap->bitmap + offset_x +
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
@ -594,8 +618,7 @@ merge_text_1(XImage * xim, TT_Raster_Map * rmap, int offset_x, int offset_y,
for (y = 0; y < xim->height; y++)
{
ptr =
(unsigned char *)rmap->bitmap + offset_x +
ptr = (unsigned char *)rmap->bitmap + offset_x +
((y + offset_y) * rmap->cols);
for (x = 0; x < xim->width; x++)
{
@ -649,9 +672,9 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
x_error = 0;
is_pixmap = 1;
EGetGeometry(disp, win, &chld, &rx, &rx, (unsigned int *)&xatt.width,
(unsigned int *)&xatt.height, (unsigned int *)&rx,
(unsigned int *)&xatt.depth);
EGetGeometry(disp, win, &chld, &rx, &rx,
(unsigned int *)&xatt.width, (unsigned int *)&xatt.height,
(unsigned int *)&rx, (unsigned int *)&xatt.depth);
XFlush(disp);
if (x_error)
{
@ -744,9 +767,8 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
erh = XSetErrorHandler((XErrorHandler) handle_x_error);
}
xim =
XShmCreateImage(disp, vis, xatt.depth, ZPixmap, NULL, &shminfo,
width, height);
xim = XShmCreateImage(disp, vis, xatt.depth, ZPixmap, NULL,
&shminfo, width, height);
if (!shm_checked)
{
XSync(disp, False);
@ -754,24 +776,21 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
shm = 0;
XDestroyImage(xim);
xim =
XGetImage(disp, win, x, y, width, height, 0xffffffff,
ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
XSetErrorHandler((XErrorHandler) erh);
shm_checked = 1;
}
else
{
shminfo.shmid =
shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height,
IPC_CREAT | 0666);
shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line *
xim->height, IPC_CREAT | 0666);
if (shminfo.shmid < 0)
{
shm = 0;
XDestroyImage(xim);
xim =
XGetImage(disp, win, x, y, width, height, 0xffffffff,
ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
XSetErrorHandler((XErrorHandler) erh);
shm_checked = 1;
}
@ -785,16 +804,14 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
}
else
{
shminfo.shmid =
shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height,
IPC_CREAT | 0666);
shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line *
xim->height, IPC_CREAT | 0666);
if (shminfo.shmid < 0)
{
shm = 0;
XDestroyImage(xim);
xim =
XGetImage(disp, win, x, y, width, height, 0xffffffff,
ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
XSetErrorHandler((XErrorHandler) erh);
shm_checked = 1;
}
@ -812,9 +829,8 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
{
shm = 0;
XDestroyImage(xim);
xim =
XGetImage(disp, win, x, y, width, height, 0xffffffff,
ZPixmap);
xim = XGetImage(disp, win, x, y, width, height,
0xffffffff, ZPixmap);
shm_checked = 1;
}
XSetErrorHandler((XErrorHandler) erh);
@ -829,22 +845,22 @@ EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
/* XUngrabServer(disp); */
/* XFlush(disp); */
/*
* if (xatt.depth == 16)
* {
* XVisualInfo xvi, *xvir;
* int num;
*
* xvi.visualid = XVisualIDFromVisual(vis);;
* xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num);
* if (xvir)
* {
* if (xvir->red_mask != 0xf800)
* xatt.depth = 15;
* XFree(xvir);
* }
* }
*/
#if 0
if (xatt.depth == 16)
{
XVisualInfo xvi, *xvir;
int num;
xvi.visualid = XVisualIDFromVisual(vis);;
xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num);
if (xvir)
{
if (xvir->red_mask != 0xf800)
xatt.depth = 15;
XFree(xvir);
}
}
#endif
if (xim)
{
if (xatt.depth == 16)
@ -961,8 +977,8 @@ Efont_load(char *file, int size)
for (i = 0; i < n; i++)
{
TT_Get_CharMap_ID(f->face, i, &platform, &encoding);
if ((platform == 3 && encoding == 1)
|| (platform == 0 && encoding == 0))
if ((platform == 3 && encoding == 1) ||
(platform == 0 && encoding == 0))
{
/* TT_Get_CharMap(f->face, i, &char_map); */
TT_Get_CharMap(f->face, i, &(f->char_map));
@ -1076,42 +1092,56 @@ Efont_extents(Efont * f, char *text, int *font_ascent_return,
*max_descent_return = f->max_descent;
}
/*
* int
* main( int argc, char **argv)
* {
* Display *disp;
* Efont *f;
* GC gc;
* XGCValues gcv;
* Window win;
* int i;
*
* disp=XOpenDisplay(NULL);
* XSync(disp, False);
* srand(time(NULL));
* win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
* 0, 0);
* EMapWindow(disp, win);
* XSync(disp, False);
*
* gcv.subwindow_mode = IncludeInferiors;
* gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
* for (;;)
* {
* for (i = 3; i < argc; i++)
* {
* XSetForeground(disp, gc, rand()<<16 | rand());
* f = Efont_load(argv[i], atoi(argv[1]));
* if (f)
* EFont_draw_string(disp, win, gc, 20, (atoi(argv[1])/10) * (i-2), argv[2],
* f,
* DefaultVisual(disp, DefaultScreen(disp)),
* DefaultColormap(disp, DefaultScreen(disp)));
* Efont_free(f);
* f = NULL;
* }
* }
* return 0;
* }
*/
#if TEST_TTFONT
Display *disp;
int
main(int argc, char **argv)
{
Efont *f;
GC gc;
XGCValues gcv;
Window win;
int i, j;
disp = XOpenDisplay(NULL);
XSync(disp, False);
srand(time(NULL));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
0, 0);
XMapWindow(disp, win);
XSync(disp, False);
gcv.subwindow_mode = IncludeInferiors;
gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
for (;; j++)
{
for (i = 3; i < argc; i++)
{
XSetForeground(disp, gc, rand() << 16 | rand());
f = Efont_load(argv[i], atoi(argv[1]));
if (f)
EFont_draw_string(disp, win, gc, 20,
atoi(argv[1]) * (i - 2), argv[2], f,
DefaultVisual(disp, DefaultScreen(disp)),
DefaultColormap(disp, DefaultScreen(disp)));
Efont_free(f);
f = NULL;
}
}
return 0;
}
void
GrabX()
{
XGrabServer(disp);
}
void
UngrabX()
{
XUngrabServer(disp);
XFlush(disp);
}
#endif