1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-12 18:13:50 -05:00

On the Mac, support for setting the line codepage and for combining

characters.  I've just used libcharset in macucs.c since there seemed
little reason not to, and implemented combining characters by naive
overprinting.  It's not yet a lot of use without the ability to select
a font, of course.

[originally from svn r5322]
This commit is contained in:
Owen Dunn 2005-02-16 23:30:10 +00:00
parent 98d342a62a
commit abb7b4ea57
3 changed files with 49 additions and 20 deletions

View File

@ -8,6 +8,7 @@ typedef void *Context; /* FIXME */
#include <Files.h>
#include <stdio.h>
#include "charset.h"
struct Filename {
FSSpec fss;
@ -63,3 +64,6 @@ extern int strnicmp(char const *, char const *, size_t);
#define HELPCTX(foo) I(0)
#define FILTER_KEY_FILES "pAgt.PPK"
#define CP_UTF8 CS_UTF8 /* from libcharset */

View File

@ -87,6 +87,8 @@ static void mac_drawgrowicon(Session *s);
static pascal void mac_growtermdraghook(void);
static pascal void mac_scrolltracker(ControlHandle, short);
static pascal void do_text_for_device(short, short, GDHandle, long);
static void do_text_internal(Context, int, int, wchar_t *, int,
unsigned long, int);
static void text_click(Session *, EventRecord *);
static void mac_activateterm(WindowPtr, EventRecord *);
static void mac_adjusttermcursor(WindowPtr, Point, RgnHandle);
@ -1131,8 +1133,8 @@ struct do_text_args {
*
* x and y are text row and column (zero-based)
*/
void do_text(Context ctx, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr)
static void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr)
{
Session *s = ctx;
int style;
@ -1150,11 +1152,6 @@ void do_text(Context ctx, int x, int y, wchar_t *text, int len,
assert(len <= 1024);
/* SGT, 2004-10-14: I don't know how to support combining characters
* on the Mac. Hopefully the first person to fail this assertion will
* know how to do it better than me... */
assert(!(attr & TATTR_COMBINING));
SetPort((GrafPtr)GetWindowPort(s->window));
fontwidth = s->font_width;
@ -1259,6 +1256,24 @@ void do_text(Context ctx, int x, int y, wchar_t *text, int len,
#endif
}
/*
* Wrapper that handles combining characters.
*/
void do_text(Context ctx, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr)
{
if (attr & TATTR_COMBINING) {
unsigned long a = 0;
attr &= ~TATTR_COMBINING;
while (len--) {
do_text_internal(ctx, x, y, text, 1, attr | a, lattr);
text++;
a = TATTR_COMBINING;
}
} else
do_text_internal(ctx, x, y, text, len, attr, lattr);
}
static pascal void do_text_for_device(short depth, short devflags,
GDHandle device, long cookie)
{
@ -1313,7 +1328,8 @@ static pascal void do_text_for_device(short depth, short devflags,
}
}
EraseRect(&a->textrect);
if (!(a->attr & TATTR_COMBINING))
EraseRect(&a->textrect);
switch (a->lattr & LATTR_MODE) {
case LATTR_NORM:
case LATTR_WIDE:

View File

@ -1,4 +1,4 @@
/* $Id: macucs.c,v 1.7 2003/04/05 22:12:44 ben Exp $ */
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
@ -6,6 +6,7 @@
#include <time.h>
#include "putty.h"
#include "charset.h"
#include "terminal.h"
#include "misc.h"
#include "mac.h"
@ -13,14 +14,14 @@
/*
* Mac Unicode-handling routines.
*
* FIXME: currently trivial stub versions assuming all codepages
* are ISO8859-1.
*
* BJH:
* What we _should_ do is to use the Text Encoding Conversion Manager
* when it's available, and have our own routines for converting to
* standard Mac OS scripts when it's not. Support for ATSUI might be
* nice, too.
*/
*
* I (OSD) am unsure any of the above is necessary if we just use
* libcharset */
/*
* Determine whether a byte is the first byte of a double-byte
@ -91,6 +92,8 @@ void init_ucs(Session *s)
{
int i;
s->ucsdata.line_codepage = decode_codepage(s->cfg.line_codepage);
/* Find the line control characters. FIXME: this is not right. */
for (i = 0; i < 256; i++)
if (i < ' ' || (i >= 0x7F && i < 0xA0))
@ -112,19 +115,25 @@ void init_ucs(Session *s)
int decode_codepage(char *cp_name)
{
return 0;
if (!*cp_name)
return CS_NONE; /* use font encoding */
return charset_from_localenc(cp_name);
}
char const *cp_enumerate (int index)
{
if (index == 0) return "ISO/IEC 8859-1";
return NULL;
int charset;
if (index == 0)
return "Use font encoding";
charset = charset_localenc_nth(index-1);
if (charset == CS_NONE)
return NULL;
return charset_to_localenc(charset);
}
char const *cp_name(int codepage)
{
return "ISO/IEC 8859-1";
if (codepage == CS_NONE)
return "Use font encoding";
return charset_to_localenc(codepage);
}