1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// WIN32 font selection routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2012-03-18 22:48:29 +04:00
|
|
|
// Copyright 1998-2012 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2010-05-27 21:20:18 +04:00
|
|
|
|
|
|
|
#include <FL/Fl_Printer.H>
|
|
|
|
|
2009-04-24 13:28:30 +04:00
|
|
|
static int fl_angle_ = 0;
|
|
|
|
|
2008-09-18 23:09:34 +04:00
|
|
|
#ifndef FL_DOXYGEN
|
2011-02-07 16:49:34 +03:00
|
|
|
Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize fsize) {
|
1998-10-06 23:14:55 +04:00
|
|
|
int weight = FW_NORMAL;
|
|
|
|
int italic = 0;
|
|
|
|
switch (*name++) {
|
|
|
|
case 'I': italic = 1; break;
|
|
|
|
case 'P': italic = 1;
|
|
|
|
case 'B': weight = FW_BOLD; break;
|
|
|
|
case ' ': break;
|
|
|
|
default: name--;
|
|
|
|
}
|
|
|
|
fid = CreateFont(
|
2011-02-07 16:49:34 +03:00
|
|
|
-fsize, // negative makes it use "char size"
|
2008-11-19 23:34:27 +03:00
|
|
|
0, // logical average character width
|
2009-04-24 13:28:30 +04:00
|
|
|
fl_angle_*10, // angle of escapement
|
|
|
|
fl_angle_*10, // base-line orientation angle
|
1998-10-06 23:14:55 +04:00
|
|
|
weight,
|
|
|
|
italic,
|
2008-11-19 23:34:27 +03:00
|
|
|
FALSE, // underline attribute flag
|
|
|
|
FALSE, // strikeout attribute flag
|
|
|
|
DEFAULT_CHARSET, // character set identifier
|
|
|
|
OUT_DEFAULT_PRECIS, // output precision
|
|
|
|
CLIP_DEFAULT_PRECIS,// clipping precision
|
|
|
|
DEFAULT_QUALITY, // output quality
|
|
|
|
DEFAULT_PITCH, // pitch and family
|
|
|
|
name // pointer to typeface name string
|
1998-10-06 23:14:55 +04:00
|
|
|
);
|
2009-04-24 13:28:30 +04:00
|
|
|
angle = fl_angle_;
|
1998-10-06 23:14:55 +04:00
|
|
|
if (!fl_gc) fl_GetDC(0);
|
|
|
|
SelectObject(fl_gc, fid);
|
|
|
|
GetTextMetrics(fl_gc, &metr);
|
|
|
|
// BOOL ret = GetCharWidthFloat(fl_gc, metr.tmFirstChar, metr.tmLastChar, font->width+metr.tmFirstChar);
|
|
|
|
// ...would be the right call, but is not implemented into Window95! (WinNT?)
|
2008-09-11 03:56:49 +04:00
|
|
|
//GetCharWidth(fl_gc, 0, 255, width);
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 64; i++) width[i] = NULL;
|
1998-10-06 23:14:55 +04:00
|
|
|
#if HAVE_GL
|
|
|
|
listbase = 0;
|
2008-09-11 03:56:49 +04:00
|
|
|
for (i = 0; i < 64; i++) glok[i] = 0;
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
2011-02-07 16:49:34 +03:00
|
|
|
size = fsize;
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2008-08-16 01:18:27 +04:00
|
|
|
Fl_Font_Descriptor::~Fl_Font_Descriptor() {
|
1998-10-06 23:14:55 +04:00
|
|
|
#if HAVE_GL
|
|
|
|
// Delete list created by gl_draw(). This is not done by this code
|
|
|
|
// as it will link in GL unnecessarily. There should be some kind
|
|
|
|
// of "free" routine pointer, or a subclass?
|
|
|
|
// if (listbase) {
|
|
|
|
// int base = font->min_char_or_byte2;
|
|
|
|
// int size = font->max_char_or_byte2-base+1;
|
|
|
|
// int base = 0; int size = 256;
|
|
|
|
// glDeleteLists(listbase+base,size);
|
|
|
|
// }
|
|
|
|
#endif
|
2011-02-07 16:49:34 +03:00
|
|
|
if (this == fl_graphics_driver->font_descriptor()) fl_graphics_driver->font_descriptor(NULL);
|
1998-10-06 23:14:55 +04:00
|
|
|
DeleteObject(fid);
|
2013-10-21 00:17:13 +04:00
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
if ( width[i] )
|
|
|
|
free(width[i]);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// WARNING: if you add to this table, you must redefine FL_FREE_FONT
|
|
|
|
// in Enumerations.H & recompile!!
|
|
|
|
static Fl_Fontdesc built_in_table[] = {
|
|
|
|
{" Arial"},
|
|
|
|
{"BArial"},
|
|
|
|
{"IArial"},
|
|
|
|
{"PArial"},
|
|
|
|
{" Courier New"},
|
|
|
|
{"BCourier New"},
|
|
|
|
{"ICourier New"},
|
|
|
|
{"PCourier New"},
|
|
|
|
{" Times New Roman"},
|
|
|
|
{"BTimes New Roman"},
|
|
|
|
{"ITimes New Roman"},
|
|
|
|
{"PTimes New Roman"},
|
|
|
|
{" Symbol"},
|
|
|
|
{" Terminal"},
|
|
|
|
{"BTerminal"},
|
|
|
|
{" Wingdings"},
|
|
|
|
};
|
|
|
|
|
1998-12-02 18:51:38 +03:00
|
|
|
Fl_Fontdesc* fl_fonts = built_in_table;
|
1998-10-06 23:14:55 +04:00
|
|
|
|
2009-04-24 13:28:30 +04:00
|
|
|
static Fl_Font_Descriptor* find(Fl_Font fnum, Fl_Fontsize size, int angle) {
|
1998-12-02 18:51:38 +03:00
|
|
|
Fl_Fontdesc* s = fl_fonts+fnum;
|
1998-10-06 23:14:55 +04:00
|
|
|
if (!s->name) s = fl_fonts; // use 0 if fnum undefined
|
2008-08-16 01:18:27 +04:00
|
|
|
Fl_Font_Descriptor* f;
|
1998-10-06 23:14:55 +04:00
|
|
|
for (f = s->first; f; f = f->next)
|
2011-02-07 16:49:34 +03:00
|
|
|
if (f->size == size && f->angle == angle) return f;
|
2008-08-16 01:18:27 +04:00
|
|
|
f = new Fl_Font_Descriptor(s->name, size);
|
1998-10-06 23:14:55 +04:00
|
|
|
f->next = s->first;
|
|
|
|
s->first = f;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// Public interface:
|
|
|
|
|
2011-02-16 18:17:01 +03:00
|
|
|
static void fl_font(Fl_Graphics_Driver *driver, Fl_Font fnum, Fl_Fontsize size, int angle) {
|
2006-09-05 15:16:15 +04:00
|
|
|
if (fnum==-1) { // just make sure that we will load a new font next time
|
2011-02-16 18:17:01 +03:00
|
|
|
fl_angle_ = 0;
|
|
|
|
driver->Fl_Graphics_Driver::font(0, 0);
|
2006-09-05 15:16:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-16 18:17:01 +03:00
|
|
|
if (fnum == driver->Fl_Graphics_Driver::font() && size == driver->size() && angle == fl_angle_) return;
|
|
|
|
fl_angle_ = angle;
|
|
|
|
driver->Fl_Graphics_Driver::font(fnum, size);
|
|
|
|
driver->font_descriptor( find(fnum, size, angle) );
|
2009-04-24 13:28:30 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:02:23 +03:00
|
|
|
void Fl_GDI_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
|
2011-02-16 18:17:01 +03:00
|
|
|
fl_font(this, fnum, size, 0);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2011-02-18 16:39:48 +03:00
|
|
|
int Fl_GDI_Graphics_Driver::height() {
|
|
|
|
Fl_Font_Descriptor *fl_fontsize = font_descriptor();
|
2004-09-08 00:59:18 +04:00
|
|
|
if (fl_fontsize) return (fl_fontsize->metr.tmAscent + fl_fontsize->metr.tmDescent);
|
|
|
|
else return -1;
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2011-02-18 16:39:48 +03:00
|
|
|
int Fl_GDI_Graphics_Driver::descent() {
|
|
|
|
Fl_Font_Descriptor *fl_fontsize = font_descriptor();
|
2004-09-08 00:59:18 +04:00
|
|
|
if (fl_fontsize) return fl_fontsize->metr.tmDescent;
|
|
|
|
else return -1;
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
// Unicode string buffer
|
2011-04-12 01:49:05 +04:00
|
|
|
static unsigned short *wstr = NULL;
|
2008-09-11 03:56:49 +04:00
|
|
|
static int wstr_len = 0;
|
|
|
|
|
|
|
|
|
2011-02-18 16:39:48 +03:00
|
|
|
double Fl_GDI_Graphics_Driver::width(const char* c, int n) {
|
2008-09-11 03:56:49 +04:00
|
|
|
int i = 0;
|
2011-02-18 16:39:48 +03:00
|
|
|
if (!font_descriptor()) return -1.0;
|
1998-10-06 23:14:55 +04:00
|
|
|
double w = 0.0;
|
2008-09-11 03:56:49 +04:00
|
|
|
char *end = (char *)&c[n];
|
|
|
|
while (i < n) {
|
|
|
|
unsigned int ucs;
|
|
|
|
int l;
|
|
|
|
ucs = fl_utf8decode((const char*)(c + i), end, &l);
|
|
|
|
// if (l < 1) l = 1;
|
|
|
|
i += l;
|
|
|
|
if (!fl_nonspacing(ucs)) {
|
2011-02-18 16:39:48 +03:00
|
|
|
w += width(ucs);
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-06 23:14:55 +04:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2011-02-18 16:39:48 +03:00
|
|
|
double Fl_GDI_Graphics_Driver::width(unsigned int c) {
|
|
|
|
Fl_Font_Descriptor *fl_fontsize = font_descriptor();
|
2008-09-11 03:56:49 +04:00
|
|
|
unsigned int r;
|
2011-04-12 14:08:58 +04:00
|
|
|
SIZE s;
|
2011-04-13 19:43:22 +04:00
|
|
|
// Special Case Handling of Unicode points over U+FFFF.
|
2011-04-12 14:08:58 +04:00
|
|
|
// The logic (below) computes a lookup table for char widths
|
|
|
|
// on-the-fly, but the table only covers codepoints up to
|
|
|
|
// U+FFFF, which covers the basic multilingual plane, but
|
|
|
|
// not any higher plane, or glyphs that require surrogate-pairs
|
2011-04-13 19:43:22 +04:00
|
|
|
// to encode them in WinXX, which is UTF16.
|
2011-04-12 14:08:58 +04:00
|
|
|
// This code assumes that these glyphs are rarely used and simply
|
2011-04-13 19:43:22 +04:00
|
|
|
// measures them explicitly if they occur - This will be slow...
|
2011-04-12 14:08:58 +04:00
|
|
|
if(c > 0x0000FFFF) { // UTF16 surrogate pair is needed
|
|
|
|
if (!fl_gc) { // We have no valid gc, so nothing to measure - bail out
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
int cc; // cell count
|
2011-04-13 19:43:22 +04:00
|
|
|
unsigned short u16[4]; // Array for UTF16 representation of c
|
|
|
|
// Creates a UTF16 string from a UCS code point.
|
|
|
|
cc = fl_ucs_to_Utf16(c, u16, 4);
|
2011-05-10 19:37:05 +04:00
|
|
|
// Make sure the current font is selected before we make the measurement
|
|
|
|
SelectObject(fl_gc, fl_fontsize->fid);
|
|
|
|
// measure the glyph width
|
2011-04-13 19:43:22 +04:00
|
|
|
GetTextExtentPoint32W(fl_gc, (WCHAR*)u16, cc, &s);
|
2011-04-12 14:08:58 +04:00
|
|
|
return (double)s.cx;
|
|
|
|
}
|
|
|
|
// else - this falls through to the lookup-table for glyph widths
|
|
|
|
// in the basic multilingual plane
|
2008-09-11 03:56:49 +04:00
|
|
|
r = (c & 0xFC00) >> 10;
|
|
|
|
if (!fl_fontsize->width[r]) {
|
|
|
|
fl_fontsize->width[r] = (int*) malloc(sizeof(int) * 0x0400);
|
|
|
|
unsigned short i = 0, ii = r * 0x400;
|
2009-02-16 00:52:49 +03:00
|
|
|
// The following code makes a best effort attempt to obtain a valid fl_gc.
|
|
|
|
// If no fl_gc is available at the time we call fl_width(), then we first
|
|
|
|
// try to obtain a gc from the first fltk window.
|
|
|
|
// If that is null then we attempt to obtain the gc from the current screen
|
|
|
|
// using (GetDC(NULL)).
|
|
|
|
// This should resolve STR #2086
|
2008-12-04 20:33:30 +03:00
|
|
|
HDC gc = fl_gc;
|
|
|
|
HWND hWnd = 0;
|
2009-02-16 00:52:49 +03:00
|
|
|
if (!gc) { // We have no valid gc, try and obtain one
|
2011-04-12 14:08:58 +04:00
|
|
|
// Use our first fltk window, or fallback to using the screen via GetDC(NULL)
|
|
|
|
hWnd = Fl::first_window() ? fl_xid(Fl::first_window()) : NULL;
|
|
|
|
gc = GetDC(hWnd);
|
2008-12-04 20:33:30 +03:00
|
|
|
}
|
|
|
|
if (!gc)
|
|
|
|
Fl::fatal("Invalid graphic context: fl_width() failed because no valid HDC was found!");
|
2011-02-04 02:00:30 +03:00
|
|
|
SelectObject(gc, fl_fontsize->fid);
|
2008-09-11 03:56:49 +04:00
|
|
|
for (; i < 0x400; i++) {
|
2008-12-04 20:33:30 +03:00
|
|
|
GetTextExtentPoint32W(gc, (WCHAR*)&ii, 1, &s);
|
2008-09-11 03:56:49 +04:00
|
|
|
fl_fontsize->width[r][i] = s.cx;
|
|
|
|
ii++;
|
|
|
|
}
|
2008-12-04 20:33:30 +03:00
|
|
|
if (gc && gc!=fl_gc) ReleaseDC(hWnd, gc);
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
return (double) fl_fontsize->width[r][c & 0x03FF];
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2008-12-02 00:01:58 +03:00
|
|
|
/* Add function pointer to allow us to access GetGlyphIndicesW on systems that have it,
|
|
|
|
* without crashing on systems that do not. */
|
|
|
|
/* DWORD WINAPI GetGlyphIndicesW(HDC,LPCWSTR,int,LPWORD,DWORD) */
|
|
|
|
typedef DWORD (WINAPI* fl_GetGlyphIndices_func)(HDC,LPCWSTR,int,LPWORD,DWORD);
|
|
|
|
|
|
|
|
static fl_GetGlyphIndices_func fl_GetGlyphIndices = NULL; // used to hold a proc pointer for GetGlyphIndicesW
|
|
|
|
static int have_loaded_GetGlyphIndices = 0; // Set this non-zero once we have tried to load GetGlyphIndices
|
|
|
|
|
|
|
|
// Function that tries to dynamically load GetGlyphIndicesW at runtime
|
|
|
|
static void GetGlyphIndices_init() {
|
|
|
|
// Since not all versions of Windows include GetGlyphIndicesW support,
|
|
|
|
// we do a run-time check for the required function.
|
|
|
|
HMODULE hMod = GetModuleHandle("GDI32.DLL");
|
|
|
|
if (hMod) {
|
|
|
|
// check that GetGlyphIndicesW is available
|
|
|
|
fl_GetGlyphIndices = (fl_GetGlyphIndices_func)GetProcAddress(hMod, "GetGlyphIndicesW");
|
|
|
|
}
|
|
|
|
have_loaded_GetGlyphIndices = -1; // set this non-zero when we have attempted to load GetGlyphIndicesW
|
|
|
|
} // GetGlyphIndices_init function
|
|
|
|
|
2010-03-14 21:07:24 +03:00
|
|
|
static void on_printer_extents_update(int &dx, int &dy, int &w, int &h)
|
|
|
|
// converts text extents from device coords to logical coords
|
|
|
|
{
|
|
|
|
POINT pt[3] = { {0, 0}, {dx, dy}, {dx+w, dy+h} };
|
|
|
|
DPtoLP(fl_gc, pt, 3);
|
|
|
|
w = pt[2].x - pt[1].x;
|
|
|
|
h = pt[2].y - pt[1].y;
|
|
|
|
dx = pt[1].x - pt[0].x;
|
|
|
|
dy = pt[1].y - pt[0].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if printer context, extents shd be converted to logical coords
|
|
|
|
#define EXTENTS_UPDATE(x,y,w,h) \
|
2012-03-18 22:48:29 +04:00
|
|
|
if (Fl_Surface_Device::surface() != Fl_Display_Device::display_device()) { on_printer_extents_update(x,y,w,h); }
|
2010-03-14 21:07:24 +03:00
|
|
|
|
2008-12-02 00:01:58 +03:00
|
|
|
// Function to determine the extent of the "inked" area of the glyphs in a string
|
2011-02-18 16:39:48 +03:00
|
|
|
void Fl_GDI_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h) {
|
2011-04-18 01:19:14 +04:00
|
|
|
|
2011-02-18 16:39:48 +03:00
|
|
|
Fl_Font_Descriptor *fl_fontsize = font_descriptor();
|
2011-04-18 01:19:14 +04:00
|
|
|
if (!fl_fontsize) { // no valid font, nothing to measure
|
2008-11-19 23:34:27 +03:00
|
|
|
w = 0; h = 0;
|
|
|
|
dx = dy = 0;
|
|
|
|
return;
|
|
|
|
}
|
2011-04-18 01:19:14 +04:00
|
|
|
|
|
|
|
static unsigned short *ext_buff = NULL; // UTF-16 converted version of input UTF-8 string
|
2011-04-18 18:34:20 +04:00
|
|
|
static WORD *w_buff = NULL; // glyph indices array
|
|
|
|
static unsigned wc_len = 0; // current string buffer dimensions
|
2011-04-18 01:19:14 +04:00
|
|
|
static const MAT2 matrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } }; // identity mat for GetGlyphOutlineW
|
2008-11-19 23:34:27 +03:00
|
|
|
GLYPHMETRICS metrics;
|
|
|
|
int maxw = 0, maxh = 0, dh;
|
|
|
|
int minx = 0, miny = -999999;
|
2008-12-11 17:38:04 +03:00
|
|
|
unsigned len = 0, idx = 0;
|
2009-02-16 00:52:49 +03:00
|
|
|
HWND hWnd = 0;
|
2011-04-12 20:18:42 +04:00
|
|
|
HDC gc = fl_gc; // local copy of current gc - make a copy in case we change it...
|
2011-04-18 01:19:14 +04:00
|
|
|
int has_surrogates; // will be set if the string contains surrogate pairs
|
2008-12-02 00:01:58 +03:00
|
|
|
|
|
|
|
// Have we loaded the GetGlyphIndicesW function yet?
|
|
|
|
if (have_loaded_GetGlyphIndices == 0) {
|
|
|
|
GetGlyphIndices_init();
|
|
|
|
}
|
|
|
|
// Do we have a usable GetGlyphIndices function?
|
|
|
|
if(!fl_GetGlyphIndices) goto exit_error; // No GetGlyphIndices function, use fallback mechanism instead
|
|
|
|
|
2009-02-16 00:52:49 +03:00
|
|
|
// The following code makes a best effort attempt to obtain a valid fl_gc.
|
|
|
|
// See description in fl_width() above for an explanation.
|
2011-04-12 20:18:42 +04:00
|
|
|
if (!gc) { // We have no valid gc, try and obtain one
|
|
|
|
// Use our first fltk window, or fallback to using the screen via GetDC(NULL)
|
|
|
|
hWnd = Fl::first_window() ? fl_xid(Fl::first_window()) : NULL;
|
|
|
|
gc = GetDC(hWnd);
|
2009-02-16 00:52:49 +03:00
|
|
|
}
|
2011-04-12 20:18:42 +04:00
|
|
|
if (!gc) goto exit_error; // no valid gc, attempt to use fallback measure
|
2009-02-16 00:52:49 +03:00
|
|
|
|
2008-11-19 23:34:27 +03:00
|
|
|
// now convert the string to WCHAR and measure it
|
2008-12-02 14:10:03 +03:00
|
|
|
len = fl_utf8toUtf16(c, n, ext_buff, wc_len);
|
2008-11-19 23:34:27 +03:00
|
|
|
if(len >= wc_len) {
|
|
|
|
if(ext_buff) {delete [] ext_buff;}
|
2011-04-18 01:19:14 +04:00
|
|
|
if(w_buff) {delete [] w_buff;}
|
2011-04-18 18:34:20 +04:00
|
|
|
wc_len = len + 64;
|
2008-11-19 23:34:27 +03:00
|
|
|
ext_buff = new unsigned short[wc_len];
|
2011-04-18 18:34:20 +04:00
|
|
|
w_buff = new WORD[wc_len];
|
2008-11-19 23:34:27 +03:00
|
|
|
len = fl_utf8toUtf16(c, n, ext_buff, wc_len);
|
|
|
|
}
|
2011-04-12 20:18:42 +04:00
|
|
|
SelectObject(gc, fl_fontsize->fid);
|
2008-11-19 23:34:27 +03:00
|
|
|
|
2011-04-18 01:19:14 +04:00
|
|
|
// Are there surrogate-pairs in this string? If so GetGlyphIndicesW will fail
|
|
|
|
// since it can only handle the BMP range.
|
|
|
|
// We ideally want to use GetGlyphIndicesW, as it is the Right Thing, but it
|
|
|
|
// only works for the BMP, so we leverage GetCharacterPlacementW instead, which
|
|
|
|
// is not ideal, but works adequately well, and does handle surrogate pairs.
|
|
|
|
has_surrogates = 0;
|
|
|
|
for(unsigned ll = 0; ll < len; ll++) {
|
2011-04-18 18:34:20 +04:00
|
|
|
if((ext_buff[ll] >= 0xD800) && (ext_buff[ll] < 0xE000)) {
|
|
|
|
has_surrogates = -1;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-19 23:34:27 +03:00
|
|
|
}
|
2011-04-18 01:19:14 +04:00
|
|
|
if (has_surrogates) {
|
|
|
|
// GetGlyphIndices will not work - use GetCharacterPlacementW() instead
|
|
|
|
GCP_RESULTSW gcp_res;
|
2011-04-18 18:34:20 +04:00
|
|
|
memset(w_buff, 0, (sizeof(WORD) * wc_len));
|
2011-04-18 01:19:14 +04:00
|
|
|
memset(&gcp_res, 0, sizeof(GCP_RESULTSW));
|
2011-04-18 18:34:20 +04:00
|
|
|
gcp_res.lpGlyphs = (LPWSTR)w_buff;
|
2011-04-18 01:19:14 +04:00
|
|
|
gcp_res.nGlyphs = wc_len;
|
|
|
|
gcp_res.lStructSize = sizeof(gcp_res);
|
|
|
|
|
|
|
|
DWORD dr = GetCharacterPlacementW(gc, (WCHAR*)ext_buff, len, 0, &gcp_res, GCP_GLYPHSHAPE);
|
2011-04-18 18:34:20 +04:00
|
|
|
if(dr) {
|
|
|
|
len = gcp_res.nGlyphs;
|
|
|
|
} else goto exit_error;
|
2011-04-18 01:19:14 +04:00
|
|
|
} else {
|
|
|
|
if (fl_GetGlyphIndices(gc, (WCHAR*)ext_buff, len, w_buff, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) {
|
|
|
|
// some error occured here - just return fl_measure values
|
|
|
|
goto exit_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-19 23:34:27 +03:00
|
|
|
// now we have the glyph array we measure each glyph in turn...
|
2008-12-11 17:38:04 +03:00
|
|
|
for(idx = 0; idx < len; idx++){
|
2011-04-18 18:34:20 +04:00
|
|
|
if (GetGlyphOutlineW (gc, w_buff[idx], GGO_METRICS | GGO_GLYPH_INDEX,
|
|
|
|
&metrics, 0, NULL, &matrix) == GDI_ERROR) {
|
2011-04-12 20:18:42 +04:00
|
|
|
goto exit_error;
|
2008-11-19 23:34:27 +03:00
|
|
|
}
|
|
|
|
maxw += metrics.gmCellIncX;
|
2011-04-18 18:34:20 +04:00
|
|
|
if(idx == 0) minx = metrics.gmptGlyphOrigin.x;
|
2008-11-19 23:34:27 +03:00
|
|
|
dh = metrics.gmBlackBoxY - metrics.gmptGlyphOrigin.y;
|
2011-04-18 18:34:20 +04:00
|
|
|
if(dh > maxh) maxh = dh;
|
|
|
|
if(miny < metrics.gmptGlyphOrigin.y) miny = metrics.gmptGlyphOrigin.y;
|
2008-11-19 23:34:27 +03:00
|
|
|
}
|
|
|
|
// for the last cell, we only want the bounding X-extent, not the glyphs increment step
|
|
|
|
maxw = maxw - metrics.gmCellIncX + metrics.gmBlackBoxX + metrics.gmptGlyphOrigin.x;
|
|
|
|
w = maxw - minx;
|
|
|
|
h = maxh + miny;
|
|
|
|
dx = minx;
|
|
|
|
dy = -miny;
|
2010-03-14 21:07:24 +03:00
|
|
|
EXTENTS_UPDATE(dx, dy, w, h);
|
2008-11-19 23:34:27 +03:00
|
|
|
return; // normal exit
|
|
|
|
|
|
|
|
exit_error:
|
|
|
|
// some error here - just return fl_measure values
|
2011-02-18 16:39:48 +03:00
|
|
|
w = (int)width(c, n);
|
|
|
|
h = height();
|
2008-11-19 23:34:27 +03:00
|
|
|
dx = 0;
|
2011-02-18 16:39:48 +03:00
|
|
|
dy = descent() - h;
|
2010-03-14 21:07:24 +03:00
|
|
|
EXTENTS_UPDATE(dx, dy, w, h);
|
2008-11-19 23:34:27 +03:00
|
|
|
return;
|
|
|
|
} // fl_text_extents
|
|
|
|
|
2010-12-28 15:02:23 +03:00
|
|
|
void Fl_GDI_Graphics_Driver::draw(const char* str, int n, int x, int y) {
|
2001-12-03 21:29:49 +03:00
|
|
|
COLORREF oldColor = SetTextColor(fl_gc, fl_RGB());
|
2011-04-07 01:02:35 +04:00
|
|
|
SelectObject(fl_gc, font_descriptor()->fid);
|
2011-04-12 02:00:19 +04:00
|
|
|
int wn = fl_utf8toUtf16(str, n, wstr, wstr_len);
|
|
|
|
if(wn >= wstr_len) {
|
|
|
|
wstr = (unsigned short*) realloc(wstr, sizeof(unsigned short) * (wn + 1));
|
|
|
|
wstr_len = wn + 1;
|
|
|
|
wn = fl_utf8toUtf16(str, n, wstr, wstr_len);
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
2011-04-12 02:00:19 +04:00
|
|
|
TextOutW(fl_gc, x, y, (WCHAR*)wstr, wn);
|
|
|
|
SetTextColor(fl_gc, oldColor); // restore initial state
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:02:23 +03:00
|
|
|
void Fl_GDI_Graphics_Driver::draw(int angle, const char* str, int n, int x, int y) {
|
2011-02-16 18:17:01 +03:00
|
|
|
fl_font(this, Fl_Graphics_Driver::font(), size(), angle);
|
2011-04-12 01:49:05 +04:00
|
|
|
int wn = 0; // count of UTF16 cells to render full string
|
2009-04-24 13:28:30 +04:00
|
|
|
COLORREF oldColor = SetTextColor(fl_gc, fl_RGB());
|
2011-02-18 16:39:48 +03:00
|
|
|
SelectObject(fl_gc, font_descriptor()->fid);
|
2011-04-12 01:49:05 +04:00
|
|
|
wn = fl_utf8toUtf16(str, n, wstr, wstr_len);
|
|
|
|
if(wn >= wstr_len) { // Array too small
|
|
|
|
wstr = (unsigned short*) realloc(wstr, sizeof(unsigned short) * (wn + 1));
|
|
|
|
wstr_len = wn + 1;
|
|
|
|
wn = fl_utf8toUtf16(str, n, wstr, wstr_len); // respin the translation
|
2011-04-11 17:13:08 +04:00
|
|
|
}
|
2011-04-12 01:49:05 +04:00
|
|
|
TextOutW(fl_gc, x, y, (WCHAR*)wstr, wn);
|
2009-04-24 13:28:30 +04:00
|
|
|
SetTextColor(fl_gc, oldColor);
|
2011-02-16 18:17:01 +03:00
|
|
|
fl_font(this, Fl_Graphics_Driver::font(), size(), 0);
|
2009-04-24 13:28:30 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:02:23 +03:00
|
|
|
void Fl_GDI_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
|
2008-09-11 03:56:49 +04:00
|
|
|
int wn;
|
2011-04-12 01:49:05 +04:00
|
|
|
wn = fl_utf8toUtf16(c, n, wstr, wstr_len);
|
2008-09-11 03:56:49 +04:00
|
|
|
if(wn >= wstr_len) {
|
2011-04-12 01:49:05 +04:00
|
|
|
wstr = (unsigned short*) realloc(wstr, sizeof(unsigned short) * (wn + 1));
|
2008-09-11 03:56:49 +04:00
|
|
|
wstr_len = wn + 1;
|
2011-04-12 01:49:05 +04:00
|
|
|
wn = fl_utf8toUtf16(c, n, wstr, wstr_len);
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
COLORREF oldColor = SetTextColor(fl_gc, fl_RGB());
|
2011-02-18 16:39:48 +03:00
|
|
|
SelectObject(fl_gc, font_descriptor()->fid);
|
2010-12-29 00:24:15 +03:00
|
|
|
#ifdef RTL_CHAR_BY_CHAR
|
2011-01-07 19:19:30 +03:00
|
|
|
int i = 0;
|
|
|
|
int lx = 0;
|
2010-12-29 00:24:15 +03:00
|
|
|
while (i < wn) { // output char by char is very bad for Arabic but coherent with fl_width()
|
2011-02-18 16:39:48 +03:00
|
|
|
lx = (int) width(wstr[i]);
|
2008-09-11 03:56:49 +04:00
|
|
|
x -= lx;
|
|
|
|
TextOutW(fl_gc, x, y, (WCHAR*)wstr + i, 1);
|
|
|
|
if (fl_nonspacing(wstr[i])) {
|
|
|
|
x += lx;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2010-12-29 00:24:15 +03:00
|
|
|
#else
|
|
|
|
UINT old_align = SetTextAlign(fl_gc, TA_RIGHT | TA_RTLREADING);
|
2011-02-18 16:39:48 +03:00
|
|
|
TextOutW(fl_gc, x, y - height() + descent(), (WCHAR*)wstr, wn);
|
2010-12-29 00:24:15 +03:00
|
|
|
SetTextAlign(fl_gc, old_align);
|
|
|
|
#endif
|
2008-09-11 03:56:49 +04:00
|
|
|
SetTextColor(fl_gc, oldColor);
|
2004-09-10 01:34:48 +04:00
|
|
|
}
|
2008-09-18 23:09:34 +04:00
|
|
|
#endif
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|