Пример #1
0
static void
UpdateFaces(AG_Event *event)
{
	AG_Variable *bFont;
	AG_Font **pFont;
	AG_FontSelector *fs = AG_SELF();
	char fontPath[AG_SEARCHPATH_MAX], *pFontPath = &fontPath[0];
	AG_TlistItem *ti;
	char *s;
	int i;
	const int stdSizes[] = { 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
	                         22,24,26,28,32,48,64 };
	const int nStdSizes = sizeof(stdSizes) / sizeof(stdSizes[0]);
	
	bFont = AG_GetVariable(fs, "font", &pFont);
	AG_PushTextState();

	fs->flags &= ~(AG_FONTSELECTOR_UPDATE);

	for (i = 0; i < agBuiltinFontCount; i++) {
		AG_StaticFont *font = agBuiltinFonts[i];

		ti = AG_TlistAdd(fs->tlFaces, NULL, "_%s", font->name);
		ti->p1 = font;
		if (*pFont != NULL &&
		    strcmp(ti->text, OBJECT(*pFont)->name) == 0)
			ti->selected++;
	}

	AG_CopyCfgString("font-path", fontPath, sizeof(fontPath));
	while ((s = AG_Strsep(&pFontPath, ":")) != NULL) {
		AG_Dir *dir;
		int i;

		if ((dir = AG_OpenDir(s)) == NULL) {
			AG_Verbose(_("Ignoring: %s\n"), AG_GetError());
			continue;
		}
		for (i = 0; i < dir->nents; i++) {
			char path[AG_FILENAME_MAX];
			AG_FileInfo info;
			char *file = dir->ents[i], *pExt;

			if (file[0] == '.' ||
			    (pExt = strrchr(file, '.')) == NULL) {
				continue;
			}
			if (strcmp(pExt, ".ttf") != 0 &&
			    strcmp(pExt, ".TTF") != 0)
				continue;

			Strlcpy(path, s, sizeof(path));
			Strlcat(path, AG_PATHSEP, sizeof(path));
			Strlcat(path, file, sizeof(path));

			if (AG_GetFileInfo(path, &info) == -1 ||
			    info.type != AG_FILE_REGULAR) {
				continue;
			}
			ti = AG_TlistAddS(fs->tlFaces, NULL, file);
			if (*pFont != NULL &&
			    strcmp(file, OBJECT(*pFont)->name) == 0)
				ti->selected++;
		}
		AG_CloseDir(dir);
	}

	/* XXX */
	for (i = 0; i < nStdSizes; i++) {
		ti = AG_TlistAdd(fs->tlSizes, NULL, "%d", stdSizes[i]);
		if (*pFont != NULL &&
		    stdSizes[i] == (*pFont)->size)
			ti->selected++;
	}
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Regular"));
	if (*pFont != NULL && (*pFont)->flags == 0) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Italic"));
	if (*pFont != NULL && (*pFont)->flags == AG_FONT_ITALIC) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Bold"));
	if (*pFont != NULL && (*pFont)->flags == AG_FONT_BOLD) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Bold Italic"));
	if (*pFont != NULL && (*pFont)->flags == (AG_FONT_BOLD|AG_FONT_ITALIC)) { ti->selected++; }

	UpdatePreview(fs);

	AG_UnlockVariable(bFont);
}
Пример #2
0
AG_Color
AG_ColorFromString(const char *s, const AG_Color *pColor)
{
	char buf[128];
	AG_Color cIn = (pColor != NULL) ? *pColor : AG_ColorRGB(0,0,0);
 	AG_Color cOut = cIn;
	double v[4];
	int isPct[4], isHSV = 0;
 	char *c, *pc;
	int i, argc;

	Strlcpy(buf, s, sizeof(buf));
	
	for (c = &buf[0]; *c != '\0' && isspace(*c); c++) {
		;;
	}
	switch (*c) {
	case 'r':		/* rgb(r,g,b[,a]) */
		break;
	case 'h':		/* hsv(h,s,v[,a]) */
		isHSV = 1;
		break;
	default:
		return (cOut);
	}
	for (; *c != '\0' && *c != '('; c++)
		;;
	if (*c == '\0' || c[1] == '\0') {
		goto out;
	}
	pc = &c[1];
	for (i = 0, argc = 0; i < 4; i++) {
		char *tok, *ep;
		if ((tok = AG_Strsep(&pc, ",")) == NULL) {
			break;
		}
		v[i] = strtod(tok, &ep);
		isPct[i] = (*ep == '%');
		argc++;
	}
	if (argc < 3) {
		goto out;
	}
	if (isHSV) {
		float hue, sat, val;

		AG_RGB2HSV(cIn.r, cIn.g, cIn.b, &hue, &sat, &val);
		hue = isPct[0] ? ColorPct(hue, v[0]) : v[0];
		sat = isPct[1] ? ColorPct(sat, v[1]) : v[1];
		val = isPct[2] ? ColorPct(val, v[2]) : v[2];
		AG_HSV2RGB(hue, sat, val, &cOut.r, &cOut.g, &cOut.b);
		if (argc == 4) {
			cOut.a = isPct[3] ? ColorPct(cIn.a, v[3]) : v[3];
		} else {
			cOut.a = cIn.a;
		}
	} else {
		cOut.r = isPct[0] ? (Uint8)ColorPct(cIn.r, v[0]) : (Uint8)v[0];
		cOut.g = isPct[1] ? (Uint8)ColorPct(cIn.g, v[1]) : (Uint8)v[1];
		cOut.b = isPct[2] ? (Uint8)ColorPct(cIn.b, v[2]) : (Uint8)v[2];
		if (argc == 4) {
			cOut.a = isPct[3] ? (Uint8)ColorPct(cIn.a, v[3]) : (Uint8)v[3];
		} else {
			cOut.a = cIn.a;
		}
	}
out:
	return (cOut);
}
Пример #3
0
int
main(int argc, char *argv[])
{
	extern char *optarg;
	extern int optind;
	AG_Den *den;
	int c, i;

	AG_InitError();

	while ((c = getopt(argc, argv, "?vo:h:n:l:a:c:d:k:")) != -1) {
		switch (c) {
		case 'v':
			verbose = 1;
			break;
		case 'o':
			outfile = optarg;
			break;
		case 'h':
			hint = optarg;
			break;
		case 'n':
			name = optarg;
			break;
		case 'l':
			lang = optarg;
			break;
		case 'a':
			author = optarg;
			break;
		case 'c':
			copy = optarg;
			break;
		case 'd':
			descr = optarg;
			break;
		case 'k':
			keyw = optarg;
			break;
		case '?':
		default:
			printusage();
			goto fail1;
		}
	}
	argc -= optind;
	argv += optind;

	if (outfile == NULL) {
		fprintf(stderr, "No output file (-o) was specified\n");
		printusage();
		goto fail1;
	}

	den = AG_DenOpen(outfile, AG_DEN_WRITE);
	if (den == NULL) {
		fprintf(stderr, "opening %s: %s\n", outfile, AG_GetError());
		goto fail1;
	}

	if (verbose) {
		printf("Encoding `%s':\n", name);
		printf("\tHint:      %s\n", hint);
		printf("\tLanguage:  %s\n", lang);

		if (author[0] != '\0')	printf("\tAuthor:    %s\n", author);
		if (copy[0] != '\0')	printf("\tCopyright: %s\n", copy);
		if (descr[0] != '\0')	printf("\tDescr:     %s\n", descr);
		if (keyw[0] != '\0')	printf("\tKeywords:  %s\n", keyw);
		printf("\n");
	}

	Strlcpy(den->hint, hint, sizeof(den->hint));
	Strlcpy(den->name, name, sizeof(den->name));
	den->author = strdup(author);
	den->copyright = strdup(copy);
	den->descr = strdup(descr);
	den->keywords = strdup(keyw);

	AG_DenWriteHeader(den, argc);
	for (i = 0; i < argc; i++) {
		char *s, *fspec = argv[i];
		char *name = NULL, *langspec = NULL;

		if ((s = AG_Strsep(&fspec, ":")) != NULL && s[0] != '\0')
			name = s;
		if ((s = AG_Strsep(&fspec, ":")) != NULL && s[0] != '\0')
			langspec = s;
		if (langspec == NULL)
			langspec = lang;

		printf("+ %s (%s)\n", name, langspec);
		if (AG_DenImportFile(den, i, name, langspec, argv[i]) == -1) {
			fprintf(stderr, "Import of `%s' failed\n", argv[i]);
			goto fail2;
		}
	}
	AG_DenWriteMappings(den);
	AG_DenClose(den);
	AG_DestroyError();
	return (0);
fail2:
	AG_DenClose(den);
fail1:
	AG_DestroyError();
	return (1);
}