1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-04-10 15:48:06 -05:00

Tidy up Simon's FontSpec abstraction.

Also, make fontspec_to_str not return the address of an automatic variable.
It now has a memory leak instead.

[originally from svn r2767]
This commit is contained in:
Ben Harris 2003-02-01 15:44:08 +00:00
parent 21275897d2
commit 947b70006e
5 changed files with 61 additions and 57 deletions

View File

@ -1,4 +1,4 @@
/* $Id: mac.c,v 1.38 2003/02/01 12:54:40 simon Exp $ */
/* $Id: mac.c,v 1.39 2003/02/01 15:44:08 ben Exp $ */
/*
* Copyright (c) 1999 Ben Harris
* All rights reserved.
@ -741,30 +741,27 @@ void old_keyfile_warning(void)
}
FontSpec platform_default_font(char const *name)
FontSpec platform_default_fontspec(char const *name)
{
FontSpec ret;
long smfs;
Str255 pname;
static char cname[256];
if (!strcmp(name, "Font")) {
smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize);
if (smfs == 0)
smfs = GetScriptVariable(smRoman, smScriptMonoFondSize);
if (smfs != 0) {
GetFontName(HiWord(smfs), pname);
if (pname[0] == 0)
strcpy(ret.name, "Monaco");
ret.height = LoWord(smfs);
p2cstrcpy(ret.name, pname);
GetFontName(HiWord(smfs), ret.name);
if (ret.name[0] == 0)
memcpy(ret.name, "\pMonaco", 7);
ret.size = LoWord(smfs);
} else {
strcpy(ret.name, "Monaco");
ret.height = 9;
memcpy(ret.name, "\pMonaco", 7);
ret.size = 9;
}
ret.isbold = 0;
ret.face = 0;
} else {
ret.name[0] = '\0';
ret.name[0] = 0;
}
return ret;
@ -787,7 +784,6 @@ char *platform_default_s(char const *name)
int platform_default_i(char const *name, int def)
{
long smfs;
/* Non-raw cut and paste of line-drawing chars works badly on the
* current Unix stub implementation of the Unicode functions.
@ -815,7 +811,9 @@ Filename filename_from_str(char *str)
char *filename_to_str(Filename fn)
{
return fn.path;
/* FIXME: Memory leak! */
return dupstr(fn.path);
}
int filename_equal(Filename f1, Filename f2)

View File

@ -13,21 +13,8 @@
#include <Palettes.h>
#include <UnicodeConverter.h>
#include <stdio.h> /* for FILENAME_MAX */
#include "charset.h"
struct Filename {
char path[FILENAME_MAX];
};
#define f_open(filename, mode) ( fopen((filename).path, (mode)) )
struct FontSpec {
char name[64];
int isbold;
int height;
};
#define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY')
#define INTERNAL_CREATOR FOUR_CHAR_CODE('pTTI')
#define SESS_TYPE FOUR_CHAR_CODE('Sess')

View File

@ -1,4 +1,4 @@
/* $Id: macstore.c,v 1.13 2003/02/01 12:54:40 simon Exp $ */
/* $Id: macstore.c,v 1.14 2003/02/01 15:44:08 ben Exp $ */
/*
* macstore.c: Macintosh-specific impementation of the interface
@ -327,18 +327,18 @@ int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
{
char *settingname;
FontSpec ret;
char tmp[256];
if (!read_setting_s(handle, name, ret.name, sizeof(ret.name)))
if (!read_setting_s(handle, name, tmp, sizeof(tmp)))
return 0;
settingname = dupcat(name, "IsBold", NULL);
ret.isbold = read_setting_i(handle, settingname, -1);
c2pstrcpy(ret.name, tmp);
settingname = dupcat(name, "Face", NULL);
ret.face = read_setting_i(handle, settingname, 0);
sfree(settingname);
if (ret.isbold == -1) return 0;
if (ret.charset == -1) return 0;
settingname = dupcat(name, "Height", NULL);
ret.height = read_setting_i(handle, settingname, INT_MIN);
ret.size = read_setting_i(handle, settingname, 0);
sfree(settingname);
if (ret.height == INT_MIN) return 0;
if (ret.size == 0) return 0;
*result = ret;
return 1;
}
@ -346,13 +346,15 @@ int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
void write_setting_fontspec(void *handle, const char *name, FontSpec font)
{
char *settingname;
char tmp[256];
write_setting_s(handle, name, font.name);
settingname = dupcat(name, "IsBold", NULL);
write_setting_i(handle, settingname, font.isbold);
p2cstrcpy(tmp, font.name);
write_setting_s(handle, name, tmp);
settingname = dupcat(name, "Face", NULL);
write_setting_i(handle, settingname, font.face);
sfree(settingname);
settingname = dupcat(name, "Height", NULL);
write_setting_i(handle, settingname, font.height);
settingname = dupcat(name, "Size", NULL);
write_setting_i(handle, settingname, font.size);
sfree(settingname);
}

View File

@ -4,6 +4,21 @@
typedef void *Context; /* FIXME */
#include <MacTypes.h>
#include <stdio.h> /* for FILENAME_MAX */
struct Filename {
char path[FILENAME_MAX];
};
#define f_open(filename, mode) ( fopen((filename).path, (mode)) )
/* Suspiciously similar to an ICFontRecord */
struct FontSpec {
short size;
Style face;
Str255 name;
};
/*
* On the Mac, Unicode text copied to the clipboard has U+2028 line separators.
* Non-Unicode text will have these converted to CR along with the rest of the

View File

@ -1,4 +1,4 @@
/* $Id: macterm.c,v 1.62 2003/02/01 12:54:40 simon Exp $ */
/* $Id: macterm.c,v 1.63 2003/02/01 15:44:08 ben Exp $ */
/*
* Copyright (c) 1999 Simon Tatham
* Copyright (c) 1999, 2002 Ben Harris
@ -207,17 +207,15 @@ static void mac_workoutfontscale(Session *s, int wantwidth,
static UnicodeToTextFallbackUPP uni_to_font_fallback_upp;
static void mac_initfont(Session *s) {
Str255 macfont;
FontInfo fi;
TextEncoding enc;
OptionBits fbflags;
SetPort(s->window);
c2pstrcpy(macfont, s->cfg.font.name);
GetFNum(macfont, &s->fontnum);
GetFNum(s->cfg.font.name, &s->fontnum);
TextFont(s->fontnum);
TextFace(s->cfg.font.isbold ? bold : 0);
TextSize(s->cfg.font.height);
TextFace(s->cfg.font.face);
TextSize(s->cfg.font.size);
GetFontInfo(&fi);
s->font_width = CharWidth('W'); /* Well, it's what NCSA uses. */
s->font_ascent = fi.ascent;
@ -227,10 +225,10 @@ static void mac_initfont(Session *s) {
&s->font_stdnumer, &s->font_stddenom);
mac_workoutfontscale(s, s->font_width * 2,
&s->font_widenumer, &s->font_widedenom);
TextSize(s->cfg.font.height * 2);
TextSize(s->cfg.font.size * 2);
mac_workoutfontscale(s, s->font_width * 2,
&s->font_bignumer, &s->font_bigdenom);
TextSize(s->cfg.font.height);
TextSize(s->cfg.font.size);
if (!s->cfg.bold_colour) {
TextFace(bold);
s->font_boldadjust = s->font_width - CharWidth('W');
@ -242,7 +240,7 @@ static void mac_initfont(Session *s) {
if (mac_gestalts.encvvers != 0 &&
UpgradeScriptInfoToTextEncoding(kTextScriptDontCare,
kTextLanguageDontCare,
kTextRegionDontCare, macfont,
kTextRegionDontCare, s->cfg.font.name,
&enc) == noErr &&
CreateUnicodeToTextInfoByEncoding(enc, &s->uni_to_font) == noErr) {
if (uni_to_font_fallback_upp == NULL)
@ -257,12 +255,15 @@ static void mac_initfont(Session *s) {
goto no_encv;
}
} else {
char cfontname[256];
no_encv:
s->uni_to_font = NULL;
p2cstrcpy(cfontname, s->cfg.font.name);
s->font_charset =
charset_from_macenc(FontToScript(s->fontnum),
GetScriptManagerVariable(smRegionCode),
mac_gestalts.sysvers, s->cfg.font.name);
mac_gestalts.sysvers, cfontname);
}
mac_adjustsize(s, s->term->rows, s->term->cols);
@ -581,7 +582,7 @@ void write_clip(void *cookie, wchar_t *data, int len, int must_deselect)
stsc->scrpStyleTab[0].scrpAscent = s->font_ascent;
stsc->scrpStyleTab[0].scrpFont = s->fontnum;
stsc->scrpStyleTab[0].scrpFace = 0;
stsc->scrpStyleTab[0].scrpSize = s->cfg.font.height;
stsc->scrpStyleTab[0].scrpSize = s->cfg.font.size;
stsc->scrpStyleTab[0].scrpColor.red = 0;
stsc->scrpStyleTab[0].scrpColor.green = 0;
stsc->scrpStyleTab[0].scrpColor.blue = 0;
@ -975,7 +976,7 @@ struct do_text_args {
void do_text(Context ctx, int x, int y, char *text, int len,
unsigned long attr, int lattr) {
Session *s = ctx;
int style = 0;
int style;
struct do_text_args a;
RgnHandle textrgn, saveclip;
char mactextbuf[1024];
@ -1029,25 +1030,26 @@ void do_text(Context ctx, int x, int y, char *text, int len,
a.lattr = lattr;
switch (lattr & LATTR_MODE) {
case LATTR_NORM:
TextSize(s->cfg.font.height);
TextSize(s->cfg.font.size);
a.numer = s->font_stdnumer;
a.denom = s->font_stddenom;
break;
case LATTR_WIDE:
TextSize(s->cfg.font.height);
TextSize(s->cfg.font.size);
a.numer = s->font_widenumer;
a.denom = s->font_widedenom;
break;
case LATTR_TOP:
case LATTR_BOT:
TextSize(s->cfg.font.height * 2);
TextSize(s->cfg.font.size * 2);
a.numer = s->font_bignumer;
a.denom = s->font_bigdenom;
break;
}
SetPort(s->window);
TextFont(s->fontnum);
if (s->cfg.font.isbold || (attr & ATTR_BOLD) && !s->cfg.bold_colour)
style = s->cfg.font.face;
if ((attr & ATTR_BOLD) && !s->cfg.bold_colour)
style |= bold;
if (attr & ATTR_UNDER)
style |= underline;