mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-19 02:32:44 +03:00
update risc os frontend for layout table
This commit is contained in:
parent
0b7edfd252
commit
f687eb8886
185
riscos/font.c
185
riscos/font.c
@ -16,7 +16,8 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/**
|
||||||
|
* \file
|
||||||
* RISC OS implementation of Font handling.
|
* RISC OS implementation of Font handling.
|
||||||
*
|
*
|
||||||
* The RUfl is used to handle and render fonts.
|
* The RUfl is used to handle and render fonts.
|
||||||
@ -33,26 +34,11 @@
|
|||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
#include "utils/messages.h"
|
#include "utils/messages.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "desktop/font.h"
|
#include "desktop/gui_layout.h"
|
||||||
|
|
||||||
#include "riscos/gui.h"
|
#include "riscos/gui.h"
|
||||||
#include "riscos/font.h"
|
#include "riscos/font.h"
|
||||||
|
|
||||||
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);
|
|
||||||
static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize,
|
|
||||||
rufl_style *pstyle);
|
|
||||||
static bool nsfont_width(const plot_font_style_t *fstyle,
|
|
||||||
const char *string, size_t length,
|
|
||||||
int *width);
|
|
||||||
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
|
||||||
const char *string, size_t length,
|
|
||||||
int x, size_t *char_offset, int *actual_x);
|
|
||||||
static bool nsfont_split(const plot_font_style_t *fstyle,
|
|
||||||
const char *string, size_t length,
|
|
||||||
int x, size_t *char_offset, int *actual_x);
|
|
||||||
|
|
||||||
/** desktop font, size and style being used */
|
/** desktop font, size and style being used */
|
||||||
char ro_gui_desktop_font_family[80];
|
char ro_gui_desktop_font_family[80];
|
||||||
@ -60,18 +46,70 @@ int ro_gui_desktop_font_size = 12;
|
|||||||
rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400;
|
rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400;
|
||||||
bool no_font_blending = false;
|
bool no_font_blending = false;
|
||||||
|
|
||||||
const struct font_functions nsfont = {
|
|
||||||
nsfont_width,
|
/**
|
||||||
nsfont_position_in_string,
|
* Check that at least Homerton.Medium is available.
|
||||||
nsfont_split
|
*/
|
||||||
};
|
static 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
static 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize font handling.
|
* Initialize font handling.
|
||||||
*
|
*
|
||||||
* Exits through die() on error.
|
* Exits through die() on error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void nsfont_init(void)
|
void nsfont_init(void)
|
||||||
{
|
{
|
||||||
const char *fallback;
|
const char *fallback;
|
||||||
@ -133,28 +171,15 @@ const char *nsfont_fallback_font(void)
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)
|
* bsearch comparison routine
|
||||||
|
*/
|
||||||
|
static int nsfont_list_cmp(const void *keyval, const void *datum)
|
||||||
{
|
{
|
||||||
if (*option && !nsfont_exists(*option)) {
|
const char *key = keyval;
|
||||||
free(*option);
|
const char * const *entry = datum;
|
||||||
*option = 0;
|
return strcasecmp(key, *entry);
|
||||||
}
|
|
||||||
if (!*option) {
|
|
||||||
if (nsfont_exists(family))
|
|
||||||
*option = strdup(family);
|
|
||||||
else
|
|
||||||
*option = strdup(fallback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -164,7 +189,6 @@ void nsfont_check_option(char **option, const char *family,
|
|||||||
* \param font_family name of font family
|
* \param font_family name of font family
|
||||||
* \return true if the family is available
|
* \return true if the family is available
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_exists(const char *font_family)
|
bool nsfont_exists(const char *font_family)
|
||||||
{
|
{
|
||||||
if (bsearch(font_family, rufl_family_list,
|
if (bsearch(font_family, rufl_family_list,
|
||||||
@ -175,49 +199,6 @@ bool nsfont_exists(const char *font_family)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int nsfont_list_cmp(const void *keyval, const void *datum)
|
|
||||||
{
|
|
||||||
const char *key = keyval;
|
|
||||||
const char * const *entry = datum;
|
|
||||||
return strcasecmp(key, *entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
@ -227,8 +208,8 @@ void nsfont_check_fonts(void)
|
|||||||
* \param width updated to width of string[0..length)
|
* \param width updated to width of string[0..length)
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
static nserror
|
||||||
bool nsfont_width(const plot_font_style_t *fstyle,
|
ro_font_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
@ -272,8 +253,8 @@ bool nsfont_width(const plot_font_style_t *fstyle,
|
|||||||
* \param actual_x updated to x coordinate of character closest to x
|
* \param actual_x updated to x coordinate of character closest to x
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
static nserror
|
||||||
bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
ro_font_position(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -330,8 +311,8 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
|||||||
*
|
*
|
||||||
* Returning char_offset == length means no split possible
|
* Returning char_offset == length means no split possible
|
||||||
*/
|
*/
|
||||||
|
static nserror
|
||||||
bool nsfont_split(const plot_font_style_t *fstyle,
|
ro_font_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -407,7 +388,6 @@ bool nsfont_split(const plot_font_style_t *fstyle,
|
|||||||
* \param y y coordinate
|
* \param y y coordinate
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_paint(const plot_font_style_t *fstyle, const char *string,
|
bool nsfont_paint(const plot_font_style_t *fstyle, const char *string,
|
||||||
size_t length, int x, int y)
|
size_t length, int x, int y)
|
||||||
{
|
{
|
||||||
@ -445,7 +425,6 @@ bool nsfont_paint(const plot_font_style_t *fstyle, const char *string,
|
|||||||
* \param font_size updated to font size
|
* \param font_size updated to font size
|
||||||
* \param font_style updated to font style
|
* \param font_style updated to font style
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void nsfont_read_style(const plot_font_style_t *fstyle,
|
void nsfont_read_style(const plot_font_style_t *fstyle,
|
||||||
const char **font_family, unsigned int *font_size,
|
const char **font_family, unsigned int *font_size,
|
||||||
rufl_style *font_style)
|
rufl_style *font_style)
|
||||||
@ -506,8 +485,10 @@ void nsfont_read_style(const plot_font_style_t *fstyle,
|
|||||||
* \param psize receives the font size in 1/16 points
|
* \param psize receives the font size in 1/16 points
|
||||||
* \param pstyle receives the style settings to be passed to rufl
|
* \param pstyle receives the style settings to be passed to rufl
|
||||||
*/
|
*/
|
||||||
|
static void
|
||||||
void ro_gui_wimp_desktop_font(char *family, size_t family_size, int *psize,
|
ro_gui_wimp_desktop_font(char *family,
|
||||||
|
size_t family_size,
|
||||||
|
int *psize,
|
||||||
rufl_style *pstyle)
|
rufl_style *pstyle)
|
||||||
{
|
{
|
||||||
rufl_style style = rufl_WEIGHT_400;
|
rufl_style style = rufl_WEIGHT_400;
|
||||||
@ -591,7 +572,6 @@ failsafe:
|
|||||||
* Retrieve the current desktop font family, size and style from
|
* Retrieve the current desktop font family, size and style from
|
||||||
* the WindowManager in a form suitable for passing to rufl
|
* the WindowManager in a form suitable for passing to rufl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ro_gui_wimp_get_desktop_font(void)
|
void ro_gui_wimp_get_desktop_font(void)
|
||||||
{
|
{
|
||||||
ro_gui_wimp_desktop_font(ro_gui_desktop_font_family,
|
ro_gui_wimp_desktop_font(ro_gui_desktop_font_family,
|
||||||
@ -599,3 +579,12 @@ void ro_gui_wimp_get_desktop_font(void)
|
|||||||
&ro_gui_desktop_font_size,
|
&ro_gui_desktop_font_size,
|
||||||
&ro_gui_desktop_font_style);
|
&ro_gui_desktop_font_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct gui_layout_table layout_table = {
|
||||||
|
.width = ro_font_width,
|
||||||
|
.position = ro_font_position,
|
||||||
|
.split = ro_font_split,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gui_layout_table *riscos_layout_table = &layout_table;
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include <rufl.h>
|
#include <rufl.h>
|
||||||
|
|
||||||
|
struct gui_layout_table *riscos_layout_table;
|
||||||
|
|
||||||
/** desktop font, size and style being used */
|
/** desktop font, size and style being used */
|
||||||
extern char ro_gui_desktop_font_family[];
|
extern char ro_gui_desktop_font_family[];
|
||||||
extern int ro_gui_desktop_font_size;
|
extern int ro_gui_desktop_font_size;
|
||||||
|
@ -2434,6 +2434,7 @@ int main(int argc, char** argv)
|
|||||||
.search = riscos_search_table,
|
.search = riscos_search_table,
|
||||||
.llcache = filesystem_llcache_table,
|
.llcache = filesystem_llcache_table,
|
||||||
.bitmap = riscos_bitmap_table,
|
.bitmap = riscos_bitmap_table,
|
||||||
|
.layout = riscos_layout_table,
|
||||||
};
|
};
|
||||||
|
|
||||||
ret = netsurf_register(&riscos_table);
|
ret = netsurf_register(&riscos_table);
|
||||||
|
Loading…
Reference in New Issue
Block a user