2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
2004-11-03 05:29:01 +03:00
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2006-01-29 15:23:22 +03:00
|
|
|
* Copyright 2006 James Bursa <bursa@users.sourceforge.net>
|
2002-07-28 01:10:45 +04:00
|
|
|
*/
|
|
|
|
|
2004-01-22 02:57:19 +03:00
|
|
|
/** \file
|
|
|
|
* Font handling (RISC OS implementation).
|
|
|
|
*
|
2005-02-20 16:19:19 +03:00
|
|
|
* The RUfl is used handle and render fonts.
|
2004-01-22 02:57:19 +03:00
|
|
|
*/
|
|
|
|
|
2002-09-27 01:38:33 +04:00
|
|
|
#include <assert.h>
|
2005-02-23 02:36:14 +03:00
|
|
|
#include <string.h>
|
2005-02-25 01:00:41 +03:00
|
|
|
#include "oslib/wimp.h"
|
2006-08-21 07:11:44 +04:00
|
|
|
#include "oslib/wimpreadsysinfo.h"
|
2005-02-20 16:19:19 +03:00
|
|
|
#include "rufl.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2003-07-18 03:01:02 +04:00
|
|
|
#include "netsurf/render/font.h"
|
2003-12-27 03:11:57 +03:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-07-06 00:19:52 +04:00
|
|
|
#include "netsurf/riscos/options.h"
|
2002-10-05 21:50:21 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
2005-02-23 02:36:14 +03:00
|
|
|
#include "netsurf/utils/messages.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
2003-07-18 03:01:02 +04:00
|
|
|
|
2004-09-14 03:56:18 +04:00
|
|
|
|
2005-02-25 01:00:41 +03:00
|
|
|
wimp_menu *font_menu;
|
|
|
|
|
2006-08-21 07:11:44 +04:00
|
|
|
/** desktop font, size and style being used */
|
|
|
|
char ro_gui_desktop_font_family[80];
|
|
|
|
int ro_gui_desktop_font_size = 12;
|
|
|
|
rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400;
|
|
|
|
|
2005-02-25 01:00:41 +03:00
|
|
|
|
2005-02-23 02:36:14 +03:00
|
|
|
static void nsfont_check_option(char **option, const char *family,
|
|
|
|
const char *fallback);
|
|
|
|
static int nsfont_list_cmp(const void *keyval, const void *datum);
|
|
|
|
static void nsfont_check_fonts(void);
|
2005-02-25 01:00:41 +03:00
|
|
|
static void nsfont_init_menu(void);
|
2006-08-21 07:11:44 +04:00
|
|
|
static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize,
|
|
|
|
rufl_style *pstyle);
|
2004-01-31 01:28:32 +03:00
|
|
|
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2005-02-23 02:36:14 +03:00
|
|
|
/**
|
|
|
|
* Initialize font handling.
|
|
|
|
*
|
|
|
|
* Exits through die() on error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsfont_init(void)
|
|
|
|
{
|
2006-01-10 11:17:51 +03:00
|
|
|
const char *fallback;
|
2005-02-23 02:36:14 +03:00
|
|
|
rufl_code code;
|
|
|
|
|
|
|
|
nsfont_check_fonts();
|
|
|
|
|
|
|
|
code = rufl_init();
|
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR)
|
|
|
|
LOG(("rufl_init: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
|
|
|
|
rufl_fm_error->errnum,
|
|
|
|
rufl_fm_error->errmess));
|
|
|
|
else
|
|
|
|
LOG(("rufl_init: 0x%x", code));
|
|
|
|
die("The Unicode font library could not be initialized. "
|
|
|
|
"Please report this to the developers.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rufl_family_list_entries == 0)
|
|
|
|
die("No fonts could be found. At least one font must be "
|
|
|
|
"installed.");
|
|
|
|
|
2006-01-10 11:17:51 +03:00
|
|
|
fallback = nsfont_fallback_font();
|
2005-02-23 02:36:14 +03:00
|
|
|
|
|
|
|
nsfont_check_option(&option_font_sans, "Homerton", fallback);
|
|
|
|
nsfont_check_option(&option_font_serif, "Trinity", fallback);
|
|
|
|
nsfont_check_option(&option_font_mono, "Corpus", fallback);
|
|
|
|
nsfont_check_option(&option_font_cursive, "Churchill", fallback);
|
|
|
|
nsfont_check_option(&option_font_fantasy, "Sassoon", fallback);
|
|
|
|
|
|
|
|
if (option_font_default != CSS_FONT_FAMILY_SANS_SERIF &&
|
|
|
|
option_font_default != CSS_FONT_FAMILY_SERIF &&
|
|
|
|
option_font_default != CSS_FONT_FAMILY_MONOSPACE &&
|
|
|
|
option_font_default != CSS_FONT_FAMILY_CURSIVE &&
|
|
|
|
option_font_default != CSS_FONT_FAMILY_FANTASY)
|
|
|
|
option_font_default = CSS_FONT_FAMILY_SANS_SERIF;
|
2005-02-25 01:00:41 +03:00
|
|
|
|
|
|
|
nsfont_init_menu();
|
2005-02-23 02:36:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-03 00:24:43 +03:00
|
|
|
/**
|
|
|
|
* Retrieve the fallback font name
|
|
|
|
*
|
|
|
|
* \return Fallback font name
|
|
|
|
*/
|
|
|
|
const char *nsfont_fallback_font(void)
|
|
|
|
{
|
|
|
|
const char *fallback = "Homerton";
|
|
|
|
|
2006-06-28 18:38:31 +04:00
|
|
|
if (!nsfont_exists(fallback)) {
|
|
|
|
LOG(("Homerton not found, dumping RUfl family list"));
|
|
|
|
for (unsigned int i = 0; i < rufl_family_list_entries; i++) {
|
|
|
|
LOG(("'%s'", rufl_family_list[i]));
|
|
|
|
}
|
2006-01-03 00:24:43 +03:00
|
|
|
fallback = rufl_family_list[0];
|
2006-06-28 18:38:31 +04:00
|
|
|
}
|
2006-01-03 00:24:43 +03:00
|
|
|
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
2005-02-23 02:36:14 +03:00
|
|
|
/**
|
|
|
|
* Check that a font option is valid, and fix it if not.
|
|
|
|
*
|
|
|
|
* \param option pointer to option, as used by options.[ch]
|
|
|
|
* \param family font family to use if option is not set, or the set
|
|
|
|
* family is not available
|
|
|
|
* \param fallback font family to use if family is not available either
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsfont_check_option(char **option, const char *family,
|
|
|
|
const char *fallback)
|
|
|
|
{
|
|
|
|
if (*option && !nsfont_exists(*option)) {
|
|
|
|
free(*option);
|
|
|
|
*option = 0;
|
|
|
|
}
|
|
|
|
if (!*option) {
|
|
|
|
if (nsfont_exists(family))
|
|
|
|
*option = strdup(family);
|
|
|
|
else
|
|
|
|
*option = strdup(fallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a font family is available.
|
|
|
|
*
|
|
|
|
* \param font_family name of font family
|
|
|
|
* \return true if the family is available
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool nsfont_exists(const char *font_family)
|
|
|
|
{
|
|
|
|
if (bsearch(font_family, rufl_family_list,
|
|
|
|
rufl_family_list_entries, sizeof rufl_family_list[0],
|
|
|
|
nsfont_list_cmp))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int nsfont_list_cmp(const void *keyval, const void *datum)
|
|
|
|
{
|
|
|
|
const char *key = keyval;
|
|
|
|
const char * const *entry = datum;
|
2006-01-10 11:17:51 +03:00
|
|
|
return strcasecmp(key, *entry);
|
2005-02-23 02:36:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that at least Homerton.Medium is available.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsfont_check_fonts(void)
|
|
|
|
{
|
|
|
|
char s[252];
|
|
|
|
font_f font;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
error = xfont_find_font("Homerton.Medium\\ELatin1",
|
|
|
|
160, 160, 0, 0, &font, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
if (error->errnum == error_FILE_NOT_FOUND) {
|
|
|
|
xwimp_start_task("TaskWindow -wimpslot 200K -quit "
|
|
|
|
"<NetSurf$Dir>.FixFonts", 0);
|
|
|
|
die("FontBadInst");
|
|
|
|
} else {
|
|
|
|
LOG(("xfont_find_font: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
snprintf(s, sizeof s, messages_get("FontError"),
|
|
|
|
error->errmess);
|
|
|
|
die(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xfont_lose_font(font);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xfont_lose_font: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
snprintf(s, sizeof s, messages_get("FontError"),
|
|
|
|
error->errmess);
|
|
|
|
die(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-25 01:00:41 +03:00
|
|
|
/**
|
|
|
|
* Prepare the menu of font families.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsfont_init_menu(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
font_menu = malloc(wimp_SIZEOF_MENU(rufl_family_list_entries));
|
|
|
|
if (!font_menu)
|
|
|
|
die("NoMemory");
|
|
|
|
font_menu->title_data.indirected_text.text = messages_get("Fonts");
|
|
|
|
font_menu->title_fg = wimp_COLOUR_BLACK;
|
|
|
|
font_menu->title_bg = wimp_COLOUR_LIGHT_GREY;
|
|
|
|
font_menu->work_fg = wimp_COLOUR_BLACK;
|
|
|
|
font_menu->work_bg = wimp_COLOUR_WHITE;
|
|
|
|
font_menu->width = 200;
|
|
|
|
font_menu->height = wimp_MENU_ITEM_HEIGHT;
|
|
|
|
font_menu->gap = wimp_MENU_ITEM_GAP;
|
|
|
|
for (i = 0; i != rufl_family_list_entries; i++) {
|
|
|
|
font_menu->entries[i].menu_flags = 0;
|
|
|
|
font_menu->entries[i].sub_menu = wimp_NO_SUB_MENU;
|
|
|
|
font_menu->entries[i].icon_flags = wimp_ICON_TEXT |
|
|
|
|
wimp_ICON_INDIRECTED |
|
|
|
|
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) |
|
|
|
|
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
|
|
|
|
font_menu->entries[i].data.indirected_text.text =
|
|
|
|
rufl_family_list[i];
|
|
|
|
font_menu->entries[i].data.indirected_text.validation =
|
|
|
|
(char *) -1;
|
|
|
|
font_menu->entries[i].data.indirected_text.size =
|
|
|
|
strlen(rufl_family_list[i]);
|
|
|
|
}
|
|
|
|
font_menu->entries[0].menu_flags = wimp_MENU_TITLE_INDIRECTED;
|
|
|
|
font_menu->entries[i - 1].menu_flags |= wimp_MENU_LAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-27 01:38:33 +04:00
|
|
|
/**
|
2005-02-20 16:19:19 +03:00
|
|
|
* Measure the width of a string.
|
2004-01-22 02:57:19 +03:00
|
|
|
*
|
2005-02-20 16:19:19 +03:00
|
|
|
* \param style css_style for this text, with style->font_size.size ==
|
|
|
|
* CSS_FONT_SIZE_LENGTH
|
|
|
|
* \param string UTF-8 string to measure
|
|
|
|
* \param length length of string
|
|
|
|
* \param width updated to width of string[0..length)
|
|
|
|
* \return true on success, false on error and error reported
|
2002-09-27 01:38:33 +04:00
|
|
|
*/
|
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
bool nsfont_width(const struct css_style *style,
|
|
|
|
const char *string, size_t length,
|
|
|
|
int *width)
|
2002-09-27 01:38:33 +04:00
|
|
|
{
|
2005-02-20 16:19:19 +03:00
|
|
|
const char *font_family;
|
|
|
|
unsigned int font_size;
|
|
|
|
rufl_style font_style;
|
|
|
|
rufl_code code;
|
|
|
|
|
|
|
|
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
|
|
|
|
|
|
|
code = rufl_width(font_family, font_style, font_size,
|
|
|
|
string, length,
|
|
|
|
width);
|
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR)
|
|
|
|
LOG(("rufl_width: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
|
|
|
|
rufl_fm_error->errnum,
|
|
|
|
rufl_fm_error->errmess));
|
|
|
|
else
|
|
|
|
LOG(("rufl_width: 0x%x", code));
|
|
|
|
/* warn_user("MiscError", "font error"); */
|
|
|
|
return false;
|
2002-09-27 01:38:33 +04:00
|
|
|
}
|
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
*width /= 2;
|
|
|
|
return true;
|
2002-09-27 01:38:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-22 02:57:19 +03:00
|
|
|
/**
|
2005-02-20 16:19:19 +03:00
|
|
|
* Find the position in a string where an x coordinate falls.
|
2004-01-22 02:57:19 +03:00
|
|
|
*
|
2005-02-20 16:19:19 +03:00
|
|
|
* \param style css_style for this text, with style->font_size.size ==
|
|
|
|
* CSS_FONT_SIZE_LENGTH
|
|
|
|
* \param string UTF-8 string to measure
|
|
|
|
* \param length length of string
|
|
|
|
* \param x x coordinate to search for
|
|
|
|
* \param char_offset updated to offset in string of actual_x, [0..length]
|
|
|
|
* \param actual_x updated to x coordinate of character closest to x
|
|
|
|
* \return true on success, false on error and error reported
|
2004-01-22 02:57:19 +03:00
|
|
|
*/
|
2004-07-06 00:19:52 +04:00
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
bool nsfont_position_in_string(const struct css_style *style,
|
|
|
|
const char *string, size_t length,
|
|
|
|
int x, size_t *char_offset, int *actual_x)
|
2004-07-06 00:19:52 +04:00
|
|
|
{
|
2005-02-20 16:19:19 +03:00
|
|
|
const char *font_family;
|
|
|
|
unsigned int font_size;
|
|
|
|
rufl_style font_style;
|
|
|
|
rufl_code code;
|
|
|
|
|
|
|
|
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
|
|
|
|
|
|
|
code = rufl_x_to_offset(font_family, font_style, font_size,
|
|
|
|
string, length,
|
|
|
|
x * 2, char_offset, actual_x);
|
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR)
|
|
|
|
LOG(("rufl_x_to_offset: rufl_FONT_MANAGER_ERROR: "
|
|
|
|
"0x%x: %s",
|
|
|
|
rufl_fm_error->errnum,
|
|
|
|
rufl_fm_error->errmess));
|
|
|
|
else
|
|
|
|
LOG(("rufl_x_to_offset: 0x%x", code));
|
|
|
|
/* warn_user("MiscError", "font error"); */
|
|
|
|
return false;
|
2004-07-06 00:19:52 +04:00
|
|
|
}
|
2002-09-27 01:38:33 +04:00
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
*actual_x /= 2;
|
|
|
|
return true;
|
2002-09-27 01:38:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-22 02:57:19 +03:00
|
|
|
/**
|
2005-02-20 16:19:19 +03:00
|
|
|
* Find where to split a string to make it fit a width.
|
|
|
|
*
|
|
|
|
* \param style css_style for this text, with style->font_size.size ==
|
|
|
|
* CSS_FONT_SIZE_LENGTH
|
|
|
|
* \param string UTF-8 string to measure
|
|
|
|
* \param length length of string
|
|
|
|
* \param x width available
|
|
|
|
* \param char_offset updated to offset in string of actual_x, [0..length]
|
|
|
|
* \param actual_x updated to x coordinate of character closest to x
|
|
|
|
* \return true on success, false on error and error reported
|
2004-01-22 02:57:19 +03:00
|
|
|
*
|
2005-02-20 16:19:19 +03:00
|
|
|
* On exit, [char_offset == 0 ||
|
|
|
|
* string[char_offset] == ' ' ||
|
|
|
|
* char_offset == length]
|
2004-01-22 02:57:19 +03:00
|
|
|
*/
|
2005-01-02 06:58:21 +03:00
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
bool nsfont_split(const struct css_style *style,
|
|
|
|
const char *string, size_t length,
|
|
|
|
int x, size_t *char_offset, int *actual_x)
|
|
|
|
{
|
|
|
|
const char *font_family;
|
|
|
|
unsigned int font_size;
|
|
|
|
rufl_style font_style;
|
|
|
|
rufl_code code;
|
|
|
|
|
|
|
|
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
|
|
|
|
2005-03-24 10:45:41 +03:00
|
|
|
code = rufl_split(font_family, font_style, font_size,
|
2005-02-20 16:19:19 +03:00
|
|
|
string, length,
|
|
|
|
x * 2, char_offset, actual_x);
|
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR)
|
2005-03-24 10:45:41 +03:00
|
|
|
LOG(("rufl_split: rufl_FONT_MANAGER_ERROR: "
|
2005-02-20 16:19:19 +03:00
|
|
|
"0x%x: %s",
|
|
|
|
rufl_fm_error->errnum,
|
|
|
|
rufl_fm_error->errmess));
|
|
|
|
else
|
2005-03-24 10:45:41 +03:00
|
|
|
LOG(("rufl_split: 0x%x", code));
|
2005-02-20 16:19:19 +03:00
|
|
|
/* warn_user("MiscError", "font error"); */
|
|
|
|
return false;
|
2004-07-06 00:19:52 +04:00
|
|
|
}
|
2005-02-20 16:19:19 +03:00
|
|
|
|
|
|
|
while (*char_offset && string[*char_offset] != ' ')
|
|
|
|
(*char_offset)--;
|
|
|
|
|
|
|
|
code = rufl_width(font_family, font_style, font_size,
|
|
|
|
string, *char_offset,
|
|
|
|
actual_x);
|
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR)
|
|
|
|
LOG(("rufl_width: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
|
|
|
|
rufl_fm_error->errnum,
|
|
|
|
rufl_fm_error->errmess));
|
|
|
|
else
|
|
|
|
LOG(("rufl_width: 0x%x", code));
|
|
|
|
/* warn_user("MiscError", "font error"); */
|
|
|
|
return false;
|
2004-01-22 02:57:19 +03:00
|
|
|
}
|
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
*actual_x /= 2;
|
|
|
|
return true;
|
2004-01-22 02:57:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-02-20 16:19:19 +03:00
|
|
|
* Paint a string.
|
2004-01-22 02:57:19 +03:00
|
|
|
*
|
2005-02-20 16:19:19 +03:00
|
|
|
* \param style css_style for this text, with style->font_size.size ==
|
|
|
|
* CSS_FONT_SIZE_LENGTH
|
|
|
|
* \param string UTF-8 string to measure
|
|
|
|
* \param length length of string
|
|
|
|
* \param x x coordinate
|
|
|
|
* \param y y coordinate
|
|
|
|
* \param scale scale to apply to font size
|
|
|
|
* \param bg background colour
|
|
|
|
* \param c colour for text
|
|
|
|
* \return true on success, false on error and error reported
|
2004-01-22 02:57:19 +03:00
|
|
|
*/
|
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
bool nsfont_paint(struct css_style *style, const char *string,
|
|
|
|
size_t length, int x, int y, float scale)
|
|
|
|
{
|
|
|
|
const char *font_family;
|
|
|
|
unsigned int font_size;
|
|
|
|
rufl_style font_style;
|
|
|
|
rufl_code code;
|
|
|
|
|
|
|
|
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
|
|
|
|
|
|
|
code = rufl_paint(font_family, font_style, font_size * scale,
|
2006-03-08 11:27:19 +03:00
|
|
|
string, length, x, y,
|
|
|
|
print_active ? 0 : rufl_BLEND_FONT);
|
2005-02-20 16:19:19 +03:00
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR)
|
2005-03-24 10:45:41 +03:00
|
|
|
LOG(("rufl_paint: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
|
2005-02-20 16:19:19 +03:00
|
|
|
rufl_fm_error->errnum,
|
|
|
|
rufl_fm_error->errmess));
|
|
|
|
else
|
2005-03-24 10:45:41 +03:00
|
|
|
LOG(("rufl_paint: 0x%x", code));
|
2004-01-22 02:57:19 +03:00
|
|
|
}
|
2005-03-20 21:58:34 +03:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
return true;
|
2002-09-27 01:38:33 +04:00
|
|
|
}
|
|
|
|
|
2002-10-12 17:05:16 +04:00
|
|
|
|
2004-01-22 02:57:19 +03:00
|
|
|
/**
|
2005-02-20 16:19:19 +03:00
|
|
|
* Convert a css_style to a font family, size and rufl_style.
|
2004-01-22 02:57:19 +03:00
|
|
|
*
|
2005-02-20 16:19:19 +03:00
|
|
|
* \param style css_style for this text, with style->font_size.size ==
|
|
|
|
* CSS_FONT_SIZE_LENGTH
|
|
|
|
* \param font_family updated to font family
|
|
|
|
* \param font_size updated to font size
|
|
|
|
* \param font_style updated to font style
|
2004-01-22 02:57:19 +03:00
|
|
|
*/
|
2002-10-12 17:05:16 +04:00
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
void nsfont_read_style(const struct css_style *style,
|
|
|
|
const char **font_family, unsigned int *font_size,
|
|
|
|
rufl_style *font_style)
|
|
|
|
{
|
|
|
|
assert(style->font_size.size == CSS_FONT_SIZE_LENGTH);
|
|
|
|
*font_size = css_len2px(&style->font_size.value.length, style) *
|
|
|
|
72.0 / 90.0 * 16.;
|
|
|
|
if (*font_size < option_font_min_size * 1.6)
|
|
|
|
*font_size = option_font_min_size * 1.6;
|
|
|
|
if (1600 < *font_size)
|
|
|
|
*font_size = 1600;
|
2002-10-12 17:05:16 +04:00
|
|
|
|
2005-02-23 02:36:14 +03:00
|
|
|
switch (style->font_family) {
|
|
|
|
case CSS_FONT_FAMILY_SANS_SERIF:
|
|
|
|
*font_family = option_font_sans;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_FAMILY_SERIF:
|
|
|
|
*font_family = option_font_serif;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_FAMILY_MONOSPACE:
|
|
|
|
*font_family = option_font_mono;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_FAMILY_CURSIVE:
|
|
|
|
*font_family = option_font_cursive;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_FAMILY_FANTASY:
|
|
|
|
*font_family = option_font_fantasy;
|
|
|
|
break;
|
|
|
|
default:
|
2006-01-03 02:31:29 +03:00
|
|
|
*font_family = option_font_sans;
|
2005-02-23 02:36:14 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
switch (style->font_style) {
|
2005-02-23 02:36:14 +03:00
|
|
|
case CSS_FONT_STYLE_ITALIC:
|
|
|
|
case CSS_FONT_STYLE_OBLIQUE:
|
|
|
|
*font_style = rufl_SLANTED;
|
|
|
|
break;
|
|
|
|
default:
|
2006-01-29 15:23:22 +03:00
|
|
|
*font_style = 0;
|
2005-02-23 02:36:14 +03:00
|
|
|
break;
|
2005-02-20 16:19:19 +03:00
|
|
|
}
|
2005-01-02 06:58:21 +03:00
|
|
|
|
2005-02-20 16:19:19 +03:00
|
|
|
switch (style->font_weight) {
|
2006-01-29 15:23:22 +03:00
|
|
|
case CSS_FONT_WEIGHT_100:
|
|
|
|
*font_style |= rufl_WEIGHT_100;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_WEIGHT_200:
|
|
|
|
*font_style |= rufl_WEIGHT_200;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_WEIGHT_300:
|
|
|
|
*font_style |= rufl_WEIGHT_300;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_WEIGHT_NORMAL:
|
|
|
|
case CSS_FONT_WEIGHT_400:
|
|
|
|
*font_style |= rufl_WEIGHT_400;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_WEIGHT_500:
|
|
|
|
*font_style |= rufl_WEIGHT_500;
|
|
|
|
break;
|
2005-02-23 02:36:14 +03:00
|
|
|
case CSS_FONT_WEIGHT_600:
|
2006-01-29 15:23:22 +03:00
|
|
|
*font_style |= rufl_WEIGHT_600;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_WEIGHT_BOLD:
|
2005-02-23 02:36:14 +03:00
|
|
|
case CSS_FONT_WEIGHT_700:
|
2006-01-29 15:23:22 +03:00
|
|
|
*font_style |= rufl_WEIGHT_700;
|
|
|
|
break;
|
2005-02-23 02:36:14 +03:00
|
|
|
case CSS_FONT_WEIGHT_800:
|
2006-01-29 15:23:22 +03:00
|
|
|
*font_style |= rufl_WEIGHT_800;
|
|
|
|
break;
|
2005-02-23 02:36:14 +03:00
|
|
|
case CSS_FONT_WEIGHT_900:
|
2006-01-29 15:23:22 +03:00
|
|
|
*font_style |= rufl_WEIGHT_900;
|
2005-02-23 02:36:14 +03:00
|
|
|
break;
|
|
|
|
default:
|
2006-01-29 15:23:22 +03:00
|
|
|
*font_style |= rufl_WEIGHT_400;
|
2005-02-23 02:36:14 +03:00
|
|
|
break;
|
2002-10-12 17:05:16 +04:00
|
|
|
}
|
|
|
|
}
|
2006-08-21 07:11:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Looks up the current desktop font and converts that to a family name,
|
|
|
|
* font size and style flags suitable for passing directly to rufl
|
|
|
|
*
|
|
|
|
* \param family buffer to receive font family
|
|
|
|
* \param family_size buffer size
|
|
|
|
* \param psize receives the font size in 1/16 points
|
|
|
|
* \param pstyle receives the style settings to be passed to rufl
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_wimp_desktop_font(char *family, size_t family_size, int *psize,
|
|
|
|
rufl_style *pstyle)
|
|
|
|
{
|
|
|
|
rufl_style style = rufl_WEIGHT_400;
|
|
|
|
os_error *error;
|
|
|
|
int ptx, pty;
|
|
|
|
font_f font_handle;
|
|
|
|
int used;
|
|
|
|
|
|
|
|
assert(family);
|
|
|
|
assert(20 < family_size);
|
|
|
|
assert(psize);
|
|
|
|
assert(pstyle);
|
|
|
|
|
|
|
|
error = xwimpreadsysinfo_font(&font_handle, NULL);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimpreadsysinfo_font: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
goto failsafe;
|
|
|
|
}
|
|
|
|
|
2006-09-08 00:10:14 +04:00
|
|
|
if (font_handle == font_SYSTEM) {
|
|
|
|
/* Er, yeah; like that's ever gonna work with RUfl */
|
|
|
|
goto failsafe;
|
|
|
|
}
|
|
|
|
|
2006-08-21 07:11:44 +04:00
|
|
|
error = xfont_read_identifier(font_handle, NULL, &used);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xfont_read_identifier: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
goto failsafe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (family_size < (size_t) used + 1) {
|
|
|
|
LOG(("desktop font name too long"));
|
|
|
|
goto failsafe;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xfont_read_defn(font_handle, family,
|
|
|
|
&ptx, &pty, NULL, NULL, NULL, NULL);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xfont_read_defn: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
goto failsafe;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i != (size_t) used; i++) {
|
|
|
|
if (family[i] < ' ') {
|
|
|
|
family[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("desktop font \"%s\"", family));
|
|
|
|
|
2006-08-22 04:08:18 +04:00
|
|
|
if (strcasestr(family, ".Medium"))
|
|
|
|
style = rufl_WEIGHT_500;
|
|
|
|
else if (strcasestr(family, ".Bold"))
|
2006-08-21 07:11:44 +04:00
|
|
|
style = rufl_WEIGHT_700;
|
2006-08-22 04:08:18 +04:00
|
|
|
if (strcasestr(family, ".Italic") || strcasestr(family, ".Oblique"))
|
2006-08-21 07:11:44 +04:00
|
|
|
style |= rufl_SLANTED;
|
|
|
|
|
|
|
|
char *dot = strchr(family, '.');
|
|
|
|
if (dot)
|
|
|
|
*dot = 0;
|
|
|
|
|
|
|
|
*psize = max(ptx, pty);
|
|
|
|
*pstyle = style;
|
|
|
|
|
|
|
|
LOG(("family \"%s\", size %i, style %i", family, *psize, style));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
failsafe:
|
|
|
|
strcpy(family, "Homerton");
|
|
|
|
*psize = 12*16;
|
|
|
|
*pstyle = rufl_WEIGHT_400;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the current desktop font family, size and style from
|
|
|
|
* the WindowManager in a form suitable for passing to rufl
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_wimp_get_desktop_font(void)
|
|
|
|
{
|
|
|
|
ro_gui_wimp_desktop_font(ro_gui_desktop_font_family,
|
|
|
|
sizeof(ro_gui_desktop_font_family),
|
|
|
|
&ro_gui_desktop_font_size,
|
|
|
|
&ro_gui_desktop_font_style);
|
|
|
|
}
|