mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-08 09:25:49 +01:00
- If fonts are specified as xlfd, convert to fc names before creating them.
This was we internally only deal with fc names and properties. It will incur a small performance hit as the font needs to be parsed/unparsed, but this is only for backward-compatibility to support old xlfd names. People are encouraged to swtich to fontconfig names. - WINGs no longer adds sans as a fallback for internal fonts. It is automatically done by fontconfig (if it can't find the requested font it will use the closest match which is the default font: sans-serif) - Added code to honor the AntialiasesText global option - Fixed style names for WMCopyFontWithStyle() - Added fonts in style files where they were missing. Also changed some fonts to better defaults.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* You need to define this function to link any program to WINGs.
|
||||
@@ -590,6 +590,8 @@ testText(WMScreen *scr)
|
||||
{
|
||||
WMWindow *win;
|
||||
WMText *text;
|
||||
WMFont *font;
|
||||
void *tb;
|
||||
FILE *file = fopen("wm.html", "rb");
|
||||
|
||||
windowCount++;
|
||||
@@ -604,23 +606,22 @@ testText(WMScreen *scr)
|
||||
WMMoveWidget(text, 10, 10);
|
||||
WMSetTextHasVerticalScroller(text, True);
|
||||
WMSetTextEditable(text, False);
|
||||
WMSetTextIgnoresNewline(text, False);
|
||||
|
||||
{
|
||||
WMFont *font, *ifont;
|
||||
#define FNAME "Verdana,Luxi Sans:pixelsize=12"
|
||||
#define MSG \
|
||||
"Window Maker is the GNU window manager for the " \
|
||||
"X Window System. It was designed to emulate the " \
|
||||
"look and feel of part of the NEXTSTEP(tm) GUI. It's " \
|
||||
"supposed to be relatively fast and small, feature " \
|
||||
"rich, easy to configure and easy to use, with a simple " \
|
||||
"and elegant appearance borrowed from NEXTSTEP(tm)."
|
||||
|
||||
font = WMDefaultSystemFont(scr);
|
||||
//ifont = WMCopyFontWithStyle(scr, font, WFSEmphasized);
|
||||
ifont = WMCreateFont(scr, "verdana,sans:pixelsize=12:italic");
|
||||
if (ifont) {
|
||||
WMSetTextDefaultFont(text, ifont);
|
||||
WMReleaseFont(ifont);
|
||||
} else {
|
||||
WMSetTextDefaultFont(text, font);
|
||||
}
|
||||
WMReleaseFont(font);
|
||||
}
|
||||
font = WMCreateFont(scr, FNAME":autohint=false");
|
||||
WMSetTextDefaultFont(text, font);
|
||||
WMReleaseFont(font);
|
||||
|
||||
if (file) {
|
||||
if (0 && file) {
|
||||
char buf[1024];
|
||||
|
||||
WMFreezeText(text);
|
||||
@@ -630,13 +631,16 @@ testText(WMScreen *scr)
|
||||
fclose(file);
|
||||
WMThawText(text);
|
||||
} else {
|
||||
WMAppendTextStream(text,
|
||||
"Window Maker is the GNU window manager for the "
|
||||
"X Window System. It was designed to emulate the "
|
||||
"look and feel of part of the NEXTSTEP(tm) GUI. Its "
|
||||
"supposed to be relatively fast and small, feature "
|
||||
"rich, easy to configure and easy to use, with a simple "
|
||||
"and elegant appearance borrowed from NEXTSTEP(tm).");
|
||||
WMAppendTextStream(text, "First paragraph has autohinting turned off, "
|
||||
"while the second has it turned on:");
|
||||
WMAppendTextStream(text, "\n\n\n");
|
||||
WMAppendTextStream(text, MSG);
|
||||
WMAppendTextStream(text, "\n\n\n");
|
||||
font = WMCreateFont(scr, FNAME":autohint=true");
|
||||
tb = WMCreateTextBlockWithText(text, MSG, font, WMBlackColor(scr),
|
||||
0, strlen(MSG));
|
||||
WMAppendTextBlock(text, tb);
|
||||
WMReleaseFont(font);
|
||||
}
|
||||
|
||||
WMRealizeWidget(win);
|
||||
@@ -1043,7 +1047,6 @@ main(int argc, char **argv)
|
||||
|
||||
testColorPanel(scr);
|
||||
|
||||
testFrame(scr);
|
||||
#if 0
|
||||
|
||||
testBox(scr);
|
||||
|
||||
@@ -431,8 +431,8 @@ typedef struct WMInputPanel {
|
||||
typedef enum WMFontStyle {
|
||||
WFSNormal = 0,
|
||||
WFSBold = 1,
|
||||
WFSEmphasized = 2,
|
||||
WFSBoldEmphasized = 3
|
||||
WFSItalic = 2,
|
||||
WFSBoldItalic = 3
|
||||
} WMFontStyle;
|
||||
|
||||
|
||||
|
||||
@@ -13,11 +13,15 @@
|
||||
#include <X11/Xlocale.h>
|
||||
|
||||
|
||||
#define DEFAULT_FONT "sans-serif:pixelsize=12"
|
||||
|
||||
#define DEFAULT_SIZE WINGsConfiguration.defaultFontSize
|
||||
|
||||
static char*
|
||||
fixXLFD(char *xlfd, int size)
|
||||
|
||||
static FcPattern*
|
||||
xlfdToFcPattern(char *xlfd, int size)
|
||||
{
|
||||
FcPattern *pattern;
|
||||
char *fname, *ptr;
|
||||
|
||||
fname = wmalloc(strlen(xlfd) + 20);
|
||||
@@ -30,6 +34,28 @@ fixXLFD(char *xlfd, int size)
|
||||
*ptr = 0;
|
||||
}
|
||||
|
||||
pattern = XftXlfdParse(fname, False, False);
|
||||
wfree(fname);
|
||||
|
||||
if (!pattern) {
|
||||
wwarning(_("invalid font: %s. Using default %s"), xlfd, DEFAULT_FONT);
|
||||
pattern = FcNameParse(DEFAULT_FONT);
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
xlfdToFcName(char *xlfd, int size)
|
||||
{
|
||||
FcPattern *pattern;
|
||||
char *fname;
|
||||
|
||||
pattern = xlfdToFcPattern(xlfd, size);
|
||||
fname = FcNameUnparse(pattern);
|
||||
FcPatternDestroy(pattern);
|
||||
|
||||
return fname;
|
||||
}
|
||||
|
||||
@@ -68,7 +94,6 @@ hasPropertyWithStringValue(FcPattern *pattern, const char *object, char *value)
|
||||
}
|
||||
|
||||
|
||||
// also handle an xlfd with %d for size?
|
||||
static char*
|
||||
makeFontOfSize(char *font, int size, char *fallback)
|
||||
{
|
||||
@@ -76,16 +101,13 @@ makeFontOfSize(char *font, int size, char *fallback)
|
||||
char *result;
|
||||
|
||||
if (font[0]=='-') {
|
||||
char *fname;
|
||||
|
||||
fname = fixXLFD(font, size);
|
||||
pattern = XftXlfdParse(fname, False, False);
|
||||
wfree(fname);
|
||||
pattern = xlfdToFcPattern(font, size);
|
||||
} else {
|
||||
pattern = FcNameParse(font);
|
||||
}
|
||||
|
||||
//FcPatternPrint(pattern);
|
||||
/*FcPatternPrint(pattern);*/
|
||||
|
||||
if (size > 0) {
|
||||
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
||||
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)size);
|
||||
@@ -98,6 +120,8 @@ makeFontOfSize(char *font, int size, char *fallback)
|
||||
FcPatternAddString(pattern, FC_FAMILY, fallback);
|
||||
}
|
||||
|
||||
/*FcPatternPrint(pattern);*/
|
||||
|
||||
result = FcNameUnparse(pattern);
|
||||
FcPatternDestroy(pattern);
|
||||
|
||||
@@ -108,20 +132,20 @@ makeFontOfSize(char *font, int size, char *fallback)
|
||||
WMFont*
|
||||
WMCreateFont(WMScreen *scrPtr, char *fontName)
|
||||
{
|
||||
WMFont *font;
|
||||
Display *display = scrPtr->display;
|
||||
char *fname, *ptr;
|
||||
WMFont *font;
|
||||
char *fname;
|
||||
|
||||
/* This is for back-compat (to allow reading of old xlfd descriptions) */
|
||||
if (fontName[0]=='-' && (ptr = strchr(fontName, ','))) {
|
||||
// warn for deprecation
|
||||
fname = wmalloc(ptr - fontName + 1);
|
||||
strncpy(fname, fontName, ptr - fontName);
|
||||
fname[ptr - fontName] = 0;
|
||||
if (fontName[0]=='-'){
|
||||
fname = xlfdToFcName(fontName, 0);
|
||||
} else {
|
||||
fname = wstrdup(fontName);
|
||||
}
|
||||
|
||||
if (!WINGsConfiguration.antialiasedText && !strstr(fname, ":antialias=")) {
|
||||
fname = wstrappend(fname, ":antialias=false");
|
||||
}
|
||||
|
||||
font = WMHashGet(scrPtr->fontCache, fname);
|
||||
if (font) {
|
||||
WMRetainFont(font);
|
||||
@@ -134,12 +158,7 @@ WMCreateFont(WMScreen *scrPtr, char *fontName)
|
||||
|
||||
font->screen = scrPtr;
|
||||
|
||||
if (fname[0] == '-') {
|
||||
// Backward compat thing. Remove in a later version
|
||||
font->font = XftFontOpenXlfd(display, scrPtr->screen, fname);
|
||||
} else {
|
||||
font->font = XftFontOpenName(display, scrPtr->screen, fname);
|
||||
}
|
||||
font->font = XftFontOpenName(display, scrPtr->screen, fname);
|
||||
if (!font->font) {
|
||||
wfree(font);
|
||||
wfree(fname);
|
||||
@@ -231,12 +250,12 @@ WMSystemFontOfSize(WMScreen *scrPtr, int size)
|
||||
WMFont *font;
|
||||
char *fontSpec;
|
||||
|
||||
fontSpec = makeFontOfSize(WINGsConfiguration.systemFont, size, "sans");
|
||||
fontSpec = makeFontOfSize(WINGsConfiguration.systemFont, size, NULL);
|
||||
|
||||
font = WMCreateFont(scrPtr, fontSpec);
|
||||
|
||||
if (!font) {
|
||||
wwarning(_("could not load font %s."), fontSpec);
|
||||
wwarning(_("could not load font: %s."), fontSpec);
|
||||
}
|
||||
|
||||
wfree(fontSpec);
|
||||
@@ -251,12 +270,12 @@ WMBoldSystemFontOfSize(WMScreen *scrPtr, int size)
|
||||
WMFont *font;
|
||||
char *fontSpec;
|
||||
|
||||
fontSpec = makeFontOfSize(WINGsConfiguration.boldSystemFont, size, "sans");
|
||||
fontSpec = makeFontOfSize(WINGsConfiguration.boldSystemFont, size, NULL);
|
||||
|
||||
font = WMCreateFont(scrPtr, fontSpec);
|
||||
|
||||
if (!font) {
|
||||
wwarning(_("could not load font %s."), fontSpec);
|
||||
wwarning(_("could not load font: %s."), fontSpec);
|
||||
}
|
||||
|
||||
wfree(fontSpec);
|
||||
@@ -348,23 +367,29 @@ WMCopyFontWithStyle(WMScreen *scrPtr, WMFont *font, WMFontStyle style)
|
||||
case WFSNormal:
|
||||
FcPatternDel(pattern, FC_WEIGHT);
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "regular");
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "medium");
|
||||
FcPatternAddString(pattern, FC_SLANT, "roman");
|
||||
//FcPatternAddString(pattern, FC_WEIGHT, "medium");
|
||||
//FcPatternAddString(pattern, FC_WEIGHT, "light");
|
||||
//FcPatternAddString(pattern, FC_SLANT, "roman");
|
||||
break;
|
||||
case WFSBold:
|
||||
FcPatternDel(pattern, FC_WEIGHT);
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "bold");
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "demibold");
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "black");
|
||||
break;
|
||||
case WFSEmphasized:
|
||||
case WFSItalic:
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddString(pattern, FC_SLANT, "italic");
|
||||
FcPatternAddString(pattern, FC_SLANT, "oblique");
|
||||
//FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
||||
//FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_OBLIQUE);
|
||||
break;
|
||||
case WFSBoldEmphasized:
|
||||
case WFSBoldItalic:
|
||||
FcPatternDel(pattern, FC_WEIGHT);
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "bold");
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "demibold");
|
||||
FcPatternAddString(pattern, FC_WEIGHT, "black");
|
||||
FcPatternAddString(pattern, FC_SLANT, "italic");
|
||||
FcPatternAddString(pattern, FC_SLANT, "oblique");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user