-//#if !USE_RESOURCES
-#define wxGetResource(a, b, c) 0
-//#endif
-
-static void SearchResource(const char *prefix, const char **names, int count, char **v)
-{
- int k, i, j;
- char resource[1024], **defaults, *internal;
-
- k = 1 << count;
-
- *v = (char *) NULL;
- internal = (char *) NULL;
-
- for (i = 0; i < k; i++) {
- strcpy(resource, prefix);
- for (j = 0; j < count; j++) {
- if (!(i & (1 << j)))
- strcat(resource, names[j]);
- else
- strcat(resource, "_");
- }
- if (wxGetResource(wxAPP_CLASS, (char *)resource, v))
- return;
- if (!internal) {
- defaults = font_defaults;
- while (*defaults) {
- if (!strcmp(*defaults, resource)) {
- internal = defaults[1];
- break;
- }
- defaults += 2;
- }
- }
- }
- if (internal)
- *v = copystring(internal);
-}
-
-wxSuffixMap::~wxSuffixMap(void)
-{
- int k, j;
-
- for (k = 0; k < wxNUM_WEIGHTS; ++k)
- for (j = 0; j < wxNUM_STYLES; ++j)
- if (map[k][j]) {
- delete[] map[k][j];
- map[k][j] = (char *) NULL;
- }
-}
-
-void wxSuffixMap::Initialize(const char *resname, const char *devresname)
-{
- const char *weight, *style;
- char *v;
- int i, j, k;
- const char *names[3];
-
- for (k = 0; k < wxNUM_WEIGHTS; k++) {
- switch (k) {
- case wxWEIGHT_NORMAL: weight = "Medium"; break;
- case wxWEIGHT_LIGHT: weight = "Light"; break;
- case wxWEIGHT_BOLD:
- default: weight = "Bold";
- }
- for (j = 0; j < wxNUM_STYLES; j++) {
- switch (j) {
- case wxSTYLE_NORMAL: style = "Straight"; break;
- case wxSTYLE_ITALIC: style = "Italic"; break;
- case wxSTYLE_SLANT:
- default: style = "Slant";
- }
- names[0] = resname;
- names[1] = weight;
- names[2] = style;
-
- SearchResource(devresname, names, 3, &v);
-
- /* Expand macros in the found string: */
- found:
- int len, closer = 0, startpos = 0;
-
- len = (v ? strlen(v) : 0);
- for (i = 0; i < len; i++) {
- if (v[i] == '$' && ((v[i+1] == '[') || (v[i+1] == '{'))) {
- startpos = i;
- closer = (v[i+1] == '[') ? ']' : '}';
- ++i;
- } else if (v[i] == closer) {
- int newstrlen;
- const char *r = (char *) NULL; bool delete_r = FALSE;
- char *name;
-
- name = v + startpos + 2;
- v[i] = 0;
-
- if (closer == '}') {
- int i, count, len;
- char **names;
-
- for (i = 0, count = 1; name[i]; i++)
- if (name[i] == ',')
- count++;
-
- len = i;
-
- names = new char*[count];
- names[0] = name;
- for (i = 0, count = 1; i < len; i++)
- if (name[i] == ',') {
- names[count++] = name + i + 1;
- name[i] = 0;
- }
-
- SearchResource("", (const char **)names, count, (char **)&r);
- delete_r = (r != 0);
- delete[] names;
-
- if (!r) {
- for (i = 0; i < len; i++)
- if (!name[i])
- name[i] = ',';
- r = "";
- printf("Bad resource name \"%s\" in font lookup\n", name);
- }
- } else if (!strcmp(name, "weight")) {
- r = weight;
- } else if (!strcmp(name, "style")) {
- r = style;
- } else if (!strcmp(name, "family")) {
- r = resname;
- } else {
- r = "";
- printf("Bad font macro name \"%s\"\n", name);
- }
-
- // add r to v
- newstrlen = strlen(r);
- char *naya = new char[startpos + newstrlen + len - i];
- memcpy(naya, v, startpos);
- memcpy(naya + startpos, r, newstrlen);
- memcpy(naya + startpos + newstrlen, v + i + 1, len - i);
- if (delete_r)
- delete[] (char*)r;
- delete[] v;
- v = naya;
-
- goto found;
- }
- }
- /* We have a final value: */
- map[k][j] = v;
- }
- }