mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-02-03 21:52:24 +00:00
Add platform-independent fontspec_new_default() function.
Constructing a FontSpec in platform-independent code is awkward, because you can't call fontspec_new() outside the platform subdirs (since its prototype varies per platform). But sometimes you just need _some_ valid FontSpec, e.g. to put in a Conf that will be used in some place where you don't actually care about font settings, such as a purely CLI program. Both Unix and Windows _have_ an idiom for this, but they're different, because their FontSpec constructors have different prototypes. The existing CLI tools have always had per-platform main source files, so they just use the locally appropriate method of constructing a boring don't-care FontSpec. But if you want a _platform-independent_ main source file, such as you might find in a test program, then that's rather awkward. Better to have a platform-independent API for making a default FontSpec.
This commit is contained in:
parent
9e01de7c2b
commit
4341ba6d5c
8
putty.h
8
putty.h
@ -2118,7 +2118,15 @@ bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
|
|||||||
* Functions to copy, free, serialise and deserialise FontSpecs.
|
* Functions to copy, free, serialise and deserialise FontSpecs.
|
||||||
* Provided per-platform, to go with the platform's idea of a
|
* Provided per-platform, to go with the platform's idea of a
|
||||||
* FontSpec's contents.
|
* FontSpec's contents.
|
||||||
|
*
|
||||||
|
* The full fontspec_new is declared in the platform header, because
|
||||||
|
* each platform may need it to have a different prototype, due to
|
||||||
|
* constructing fonts in different ways. But fontspec_new_default()
|
||||||
|
* will at least produce _some_ kind of a FontSpec, for use in
|
||||||
|
* situations where one needs to exist (e.g. to put in a Conf) and be
|
||||||
|
* freeable but won't actually be used for anything important.
|
||||||
*/
|
*/
|
||||||
|
FontSpec *fontspec_new_default(void);
|
||||||
FontSpec *fontspec_copy(const FontSpec *f);
|
FontSpec *fontspec_copy(const FontSpec *f);
|
||||||
void fontspec_free(FontSpec *f);
|
void fontspec_free(FontSpec *f);
|
||||||
void fontspec_serialise(BinarySink *bs, FontSpec *f);
|
void fontspec_serialise(BinarySink *bs, FontSpec *f);
|
||||||
|
@ -201,7 +201,7 @@ int platform_default_i(const char *name, int def)
|
|||||||
|
|
||||||
FontSpec *platform_default_fontspec(const char *name)
|
FontSpec *platform_default_fontspec(const char *name)
|
||||||
{
|
{
|
||||||
return fontspec_new("");
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -172,7 +172,7 @@ void random_destroy_seed(void) {}
|
|||||||
char *platform_default_s(const char *name) { return NULL; }
|
char *platform_default_s(const char *name) { return NULL; }
|
||||||
bool platform_default_b(const char *name, bool def) { return def; }
|
bool platform_default_b(const char *name, bool def) { return def; }
|
||||||
int platform_default_i(const char *name, int def) { return def; }
|
int platform_default_i(const char *name, int def) { return def; }
|
||||||
FontSpec *platform_default_fontspec(const char *name) { return fontspec_new(""); }
|
FontSpec *platform_default_fontspec(const char *name) { return fontspec_new_default(); }
|
||||||
Filename *platform_default_filename(const char *name) { return filename_from_str(""); }
|
Filename *platform_default_filename(const char *name) { return filename_from_str(""); }
|
||||||
char *x_get_default(const char *key) { return NULL; }
|
char *x_get_default(const char *key) { return NULL; }
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ int platform_default_i(const char *name, int def)
|
|||||||
|
|
||||||
FontSpec *platform_default_fontspec(const char *name)
|
FontSpec *platform_default_fontspec(const char *name)
|
||||||
{
|
{
|
||||||
return fontspec_new("");
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -78,7 +78,7 @@ int platform_default_i(const char *name, int def)
|
|||||||
|
|
||||||
FontSpec *platform_default_fontspec(const char *name)
|
FontSpec *platform_default_fontspec(const char *name)
|
||||||
{
|
{
|
||||||
return fontspec_new("");
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -52,7 +52,7 @@ int platform_default_i(const char *name, int def)
|
|||||||
|
|
||||||
FontSpec *platform_default_fontspec(const char *name)
|
FontSpec *platform_default_fontspec(const char *name)
|
||||||
{
|
{
|
||||||
return fontspec_new("");
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -80,7 +80,7 @@ int platform_default_i(const char *name, int def)
|
|||||||
|
|
||||||
FontSpec *platform_default_fontspec(const char *name)
|
FontSpec *platform_default_fontspec(const char *name)
|
||||||
{
|
{
|
||||||
return fontspec_new("");
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -13,6 +13,11 @@ FontSpec *fontspec_new(const char *name)
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FontSpec *fontspec_new_default(void)
|
||||||
|
{
|
||||||
|
return fontspec_new("");
|
||||||
|
}
|
||||||
|
|
||||||
FontSpec *fontspec_copy(const FontSpec *f)
|
FontSpec *fontspec_copy(const FontSpec *f)
|
||||||
{
|
{
|
||||||
return fontspec_new(f->name);
|
return fontspec_new(f->name);
|
||||||
|
@ -304,7 +304,7 @@ FontSpec *platform_default_fontspec(const char *name)
|
|||||||
if (!strcmp(name, "Font"))
|
if (!strcmp(name, "Font"))
|
||||||
return fontspec_new(DEFAULT_GTK_FONT);
|
return fontspec_new(DEFAULT_GTK_FONT);
|
||||||
else
|
else
|
||||||
return fontspec_new("");
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -1683,7 +1683,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
shortcuts[nshortcuts++] = ctrl->fontselect.shortcut;
|
shortcuts[nshortcuts++] = ctrl->fontselect.shortcut;
|
||||||
statictext(&pos, escaped, 1, base_id);
|
statictext(&pos, escaped, 1, base_id);
|
||||||
staticbtn(&pos, "", base_id+1, "Change...", base_id+2);
|
staticbtn(&pos, "", base_id+1, "Change...", base_id+2);
|
||||||
data = fontspec_new("", false, 0, 0);
|
data = fontspec_new_default();
|
||||||
sfree(escaped);
|
sfree(escaped);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -11,7 +11,7 @@ FontSpec *platform_default_fontspec(const char *name)
|
|||||||
if (!strcmp(name, "Font"))
|
if (!strcmp(name, "Font"))
|
||||||
return fontspec_new("Courier New", false, 10, ANSI_CHARSET);
|
return fontspec_new("Courier New", false, 10, ANSI_CHARSET);
|
||||||
else
|
else
|
||||||
return fontspec_new("", false, 0, 0);
|
return fontspec_new_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
Filename *platform_default_filename(const char *name)
|
Filename *platform_default_filename(const char *name)
|
||||||
|
@ -14,6 +14,11 @@ FontSpec *fontspec_new(const char *name, bool bold, int height, int charset)
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FontSpec *fontspec_new_default(void)
|
||||||
|
{
|
||||||
|
return fontspec_new("", false, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
FontSpec *fontspec_copy(const FontSpec *f)
|
FontSpec *fontspec_copy(const FontSpec *f)
|
||||||
{
|
{
|
||||||
return fontspec_new(f->name, f->isbold, f->height, f->charset);
|
return fontspec_new(f->name, f->isbold, f->height, f->charset);
|
||||||
|
Loading…
Reference in New Issue
Block a user