summaryrefslogtreecommitdiff
path: root/framebuffer
diff options
context:
space:
mode:
Diffstat (limited to 'framebuffer')
-rw-r--r--framebuffer/font_freetype.c218
-rw-r--r--framebuffer/options.h38
2 files changed, 190 insertions, 66 deletions
diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c
index bffa8ffa0..ea183ea4b 100644
--- a/framebuffer/font_freetype.c
+++ b/framebuffer/font_freetype.c
@@ -34,7 +34,10 @@
#include "framebuffer/options.h"
#include "framebuffer/findfile.h"
-#define DEJAVU_PATH "/usr/share/fonts/truetype/ttf-dejavu/"
+/* glyph cache minimum size */
+#define CACHE_MIN_SIZE (100 * 1024)
+
+#define BOLD_WEIGHT 700
static FT_Library library;
static FTC_Manager ft_cmanager;
@@ -50,18 +53,23 @@ typedef struct fb_faceid_s {
int cidx; /* character map index for unicode */
} fb_faceid_t;
-/* defines for accesing the faces */
-#define FB_FACE_DEFAULT 0
-#define FB_FACE_SANS_SERIF 0
-#define FB_FACE_SANS_SERIF_BOLD 1
-#define FB_FACE_SANS_SERIF_ITALIC 2
-#define FB_FACE_SANS_SERIF_ITALIC_BOLD 3
-#define FB_FACE_MONOSPACE 4
-#define FB_FACE_SERIF 5
-#define FB_FACE_SERIF_BOLD 6
+enum fb_face_e {
+ FB_FACE_SANS_SERIF = 0,
+ FB_FACE_SANS_SERIF_BOLD = 1,
+ FB_FACE_SANS_SERIF_ITALIC = 2,
+ FB_FACE_SANS_SERIF_ITALIC_BOLD = 3,
+ FB_FACE_SERIF = 4,
+ FB_FACE_SERIF_BOLD = 5,
+ FB_FACE_MONOSPACE = 6,
+ FB_FACE_MONOSPACE_BOLD = 7,
+ FB_FACE_CURSIVE = 8,
+ FB_FACE_FANTASY = 9,
+};
-#define FB_FACE_COUNT 7
+/* defines for accesing the faces */
+#define FB_FACE_DEFAULT 0
+#define FB_FACE_COUNT 10
static fb_faceid_t *fb_faces[FB_FACE_COUNT];
@@ -124,7 +132,7 @@ fb_new_face(const char *option, const char *resname, const char *fontfile)
if (error) {
LOG(("Could not find font face %s (code %d)\n", fontfile, error));
free(newf);
- newf = fb_faces[FB_FACE_DEFAULT]; /* use default */
+ newf = NULL;
}
return newf;
@@ -136,6 +144,7 @@ bool fb_font_init(void)
FT_Error error;
FT_ULong max_cache_size;
FT_UInt max_faces = 6;
+ fb_faceid_t *fb_face;
/* freetype library initialise */
error = FT_Init_FreeType( &library );
@@ -144,7 +153,12 @@ bool fb_font_init(void)
return false;
}
- max_cache_size = 2 * 1024 *1024; /* 2MB should be enough */
+ /* set the Glyph cache size up */
+ max_cache_size = option_fb_font_cachesize * 1024;
+
+ if (max_cache_size < CACHE_MIN_SIZE) {
+ max_cache_size = CACHE_MIN_SIZE;
+ }
/* cache manager initialise */
error = FTC_Manager_New(library,
@@ -164,47 +178,122 @@ bool fb_font_init(void)
error = FTC_ImageCache_New(ft_cmanager, &ft_image_cache);
- fb_faces[FB_FACE_SANS_SERIF] = NULL;
- fb_faces[FB_FACE_SANS_SERIF] =
- fb_new_face(option_fb_face_sans_serif,
- "sans_serif.ttf",
- DEJAVU_PATH"DejaVuSans.ttf");
- if (fb_faces[FB_FACE_SANS_SERIF] == NULL) {
- LOG(("Could not find default font (code %d)\n", error));
- FTC_Manager_Done(ft_cmanager );
+ /* need to obtain the generic font faces */
+
+ /* Start with the sans serif font */
+ fb_face = fb_new_face(option_fb_face_sans_serif,
+ "sans_serif.ttf",
+ NETSURF_FB_FONT_SANS_SERIF);
+ if (fb_face == NULL) {
+ /* The sans serif font is the default and must be found. */
+ LOG(("Could not find the default font\n"));
+ FTC_Manager_Done(ft_cmanager);
FT_Done_FreeType(library);
return false;
- }
+ } else {
+ fb_faces[FB_FACE_SANS_SERIF] = fb_face;
+ }
- fb_faces[FB_FACE_SANS_SERIF_BOLD] =
- fb_new_face(option_fb_face_sans_serif_bold,
+ /* Bold sans serif face */
+ fb_face = fb_new_face(option_fb_face_sans_serif_bold,
"sans_serif_bold.ttf",
- DEJAVU_PATH"DejaVuSans-Bold.ttf");
-
- fb_faces[FB_FACE_SANS_SERIF_ITALIC] =
- fb_new_face(option_fb_face_sans_serif_italic,
- "sans_serif_italic.ttf",
- DEJAVU_PATH"DejaVuSans-Oblique.ttf");
+ NETSURF_FB_FONT_SANS_SERIF_BOLD);
+ if (fb_face == NULL) {
+ /* seperate bold face unavailabe use the normal weight version */
+ fb_faces[FB_FACE_SANS_SERIF_BOLD] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_SANS_SERIF_BOLD] = fb_face;
+ }
- fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] =
- fb_new_face(option_fb_face_sans_serif_italic_bold,
- "sans_serif_italic_bold.ttf",
- DEJAVU_PATH"DejaVuSans-BoldOblique.ttf");
+ /* Italic sans serif face */
+ fb_face = fb_new_face(option_fb_face_sans_serif_italic,
+ "sans_serif_italic.ttf",
+ NETSURF_FB_FONT_SANS_SERIF_ITALIC);
+ if (fb_face == NULL) {
+ /* seperate italic face unavailabe use the normal weight version */
+ fb_faces[FB_FACE_SANS_SERIF_ITALIC] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_SANS_SERIF_ITALIC] = fb_face;
+ }
- fb_faces[FB_FACE_MONOSPACE] =
- fb_new_face(option_fb_face_monospace,
- "monospace.ttf",
- DEJAVU_PATH"DejaVuSansMono.ttf");
+ /* Bold italic sans serif face */
+ fb_face = fb_new_face(option_fb_face_sans_serif_italic_bold,
+ "sans_serif_italic_bold.ttf",
+ NETSURF_FB_FONT_SANS_SERIF_ITALIC_BOLD);
+ if (fb_face == NULL) {
+ /* seperate italic face unavailabe use the normal weight version */
+ fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] = fb_face;
+ }
- fb_faces[FB_FACE_SERIF] =
- fb_new_face(option_fb_face_serif,
+ /* serif face */
+ fb_face = fb_new_face(option_fb_face_serif,
"serif.ttf",
- DEJAVU_PATH"DejaVuSerif.ttf");
+ NETSURF_FB_FONT_SERIF);
+ if (fb_face == NULL) {
+ /* serif face unavailabe use the default */
+ fb_faces[FB_FACE_SERIF] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_SERIF] = fb_face;
+ }
+
+ /* bold serif face*/
+ fb_face = fb_new_face(option_fb_face_serif_bold,
+ "serif_bold.ttf",
+ NETSURF_FB_FONT_SERIF_BOLD);
+ if (fb_face == NULL) {
+ /* bold serif face unavailabe use the normal weight */
+ fb_faces[FB_FACE_SERIF_BOLD] = fb_faces[FB_FACE_SERIF];
+ } else {
+ fb_faces[FB_FACE_SERIF_BOLD] = fb_face;
+ }
+
+
+ /* monospace face */
+ fb_face = fb_new_face(option_fb_face_monospace,
+ "monospace.ttf",
+ NETSURF_FB_FONT_MONOSPACE);
+ if (fb_face == NULL) {
+ /* serif face unavailabe use the default */
+ fb_faces[FB_FACE_MONOSPACE] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_MONOSPACE] = fb_face;
+ }
+
+ /* bold monospace face*/
+ fb_face = fb_new_face(option_fb_face_monospace_bold,
+ "monospace_bold.ttf",
+ NETSURF_FB_FONT_MONOSPACE_BOLD);
+ if (fb_face == NULL) {
+ /* bold serif face unavailabe use the normal weight */
+ fb_faces[FB_FACE_MONOSPACE_BOLD] = fb_faces[FB_FACE_MONOSPACE];
+ } else {
+ fb_faces[FB_FACE_MONOSPACE_BOLD] = fb_face;
+ }
+
+ /* cursive face */
+ fb_face = fb_new_face(option_fb_face_cursive,
+ "cursive.ttf",
+ NETSURF_FB_FONT_CURSIVE);
+ if (fb_face == NULL) {
+ /* cursive face unavailabe use the default */
+ fb_faces[FB_FACE_CURSIVE] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_CURSIVE] = fb_face;
+ }
+
+ /* fantasy face */
+ fb_face = fb_new_face(option_fb_face_fantasy,
+ "fantasy.ttf",
+ NETSURF_FB_FONT_FANTASY);
+ if (fb_face == NULL) {
+ /* fantasy face unavailabe use the default */
+ fb_faces[FB_FACE_FANTASY] = fb_faces[FB_FACE_SANS_SERIF];
+ } else {
+ fb_faces[FB_FACE_FANTASY] = fb_face;
+ }
- fb_faces[FB_FACE_SERIF_BOLD] =
- fb_new_face(option_fb_face_serif_bold,
- "serif_bold.ttf",
- DEJAVU_PATH"DejaVuSerif-Bold.ttf");
/* set the default render mode */
if (option_fb_font_monochrome == true)
@@ -227,37 +316,46 @@ static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
int selected_face = FB_FACE_DEFAULT;
switch (fstyle->family) {
- /*
- case PLOT_FONT_FAMILY_CURSIVE:
- break;
- case PLOT_FONT_FAMILY_FANTASY:
- break;
- */
+
case PLOT_FONT_FAMILY_SERIF:
- if (fstyle->weight >= 700)
+ if (fstyle->weight >= BOLD_WEIGHT) {
selected_face = FB_FACE_SERIF_BOLD;
- else
+ } else {
selected_face = FB_FACE_SERIF;
-
+ }
break;
case PLOT_FONT_FAMILY_MONOSPACE:
- selected_face = FB_FACE_MONOSPACE;
+ if (fstyle->weight >= BOLD_WEIGHT) {
+ selected_face = FB_FACE_MONOSPACE_BOLD;
+ } else {
+ selected_face = FB_FACE_MONOSPACE;
+ }
+ break;
+
+ case PLOT_FONT_FAMILY_CURSIVE:
+ selected_face = FB_FACE_CURSIVE;
+ break;
+
+ case PLOT_FONT_FAMILY_FANTASY:
+ selected_face = FB_FACE_FANTASY;
break;
case PLOT_FONT_FAMILY_SANS_SERIF:
default:
if ((fstyle->flags & FONTF_ITALIC) ||
- (fstyle->flags & FONTF_OBLIQUE)) {
- if (fstyle->weight >= 700)
+ (fstyle->flags & FONTF_OBLIQUE)) {
+ if (fstyle->weight >= BOLD_WEIGHT) {
selected_face = FB_FACE_SANS_SERIF_ITALIC_BOLD;
- else
+ } else {
selected_face = FB_FACE_SANS_SERIF_ITALIC;
+ }
} else {
- if (fstyle->weight >= 700)
+ if (fstyle->weight >= BOLD_WEIGHT) {
selected_face = FB_FACE_SANS_SERIF_BOLD;
- else
+ } else {
selected_face = FB_FACE_SANS_SERIF;
+ }
}
}
diff --git a/framebuffer/options.h b/framebuffer/options.h
index 00d5277f5..0874f11f4 100644
--- a/framebuffer/options.h
+++ b/framebuffer/options.h
@@ -21,25 +21,43 @@
#include "desktop/options.h"
+/* surface options */
+
extern int option_fb_depth;
extern int option_fb_refresh;
extern char *option_fb_device;
extern char *option_fb_input_devpath;
extern char *option_fb_input_glob;
+
+/* toolkit options */
+
extern int option_fb_furniture_size; /* toolkit furniture size */
extern int option_fb_toolbar_size; /* toolbar furniture size */
extern char *option_fb_toolbar_layout; /* toolbar layout */
extern bool option_fb_osk; /* enable on screen keyboard */
-extern bool option_fb_font_monochrome; /* render font monochrome */
+/* font options */
+
+/* render font monochrome */
+extern bool option_fb_font_monochrome;
+/** size of font glyph cache in kilobytes. */
+extern int option_fb_font_cachesize;
+
extern char *option_fb_face_sans_serif; /* default sans face */
extern char *option_fb_face_sans_serif_bold; /* bold sans face */
extern char *option_fb_face_sans_serif_italic; /* bold sans face */
extern char *option_fb_face_sans_serif_italic_bold; /* bold sans face */
-extern char *option_fb_face_monospace; /* monospace face */
+
extern char *option_fb_face_serif; /* serif face */
extern char *option_fb_face_serif_bold; /* bold serif face */
+extern char *option_fb_face_monospace; /* monospace face */
+extern char *option_fb_face_monospace_bold; /* bold monospace face */
+
+extern char *option_fb_face_cursive; /* cursive face */
+extern char *option_fb_face_fantasy; /* fantasy face */
+
+
#define EXTRA_OPTION_DEFINE \
int option_fb_depth = 32; \
int option_fb_refresh = 70; \
@@ -51,13 +69,17 @@ extern char *option_fb_face_serif_bold; /* bold serif face */
char *option_fb_toolbar_layout; \
bool option_fb_osk = false; \
bool option_fb_font_monochrome = false; \
+ int option_fb_font_cachesize = 2048; \
char *option_fb_face_sans_serif; \
char *option_fb_face_sans_serif_bold; \
char *option_fb_face_sans_serif_italic; \
char *option_fb_face_sans_serif_italic_bold; \
- char *option_fb_face_monospace; \
char *option_fb_face_serif; \
- char *option_fb_face_serif_bold;
+ char *option_fb_face_serif_bold; \
+ char *option_fb_face_monospace; \
+ char *option_fb_face_monospace_bold; \
+ char *option_fb_face_cursive; \
+ char *option_fb_face_fantasy;
#define EXTRA_OPTION_TABLE \
{ "fb_depth", OPTION_INTEGER, &option_fb_depth }, \
@@ -70,13 +92,17 @@ extern char *option_fb_face_serif_bold; /* bold serif face */
{ "fb_toolbar_layout", OPTION_STRING, &option_fb_toolbar_layout }, \
{ "fb_osk", OPTION_BOOL, &option_fb_osk }, \
{ "fb_font_monochrome", OPTION_BOOL, &option_fb_font_monochrome }, \
+ { "fb_font_cachesize", OPTION_INTEGER, &option_fb_font_cachesize }, \
{ "fb_face_sans_serif", OPTION_STRING, &option_fb_face_sans_serif }, \
{ "fb_face_sans_serif_bold", OPTION_STRING, &option_fb_face_sans_serif_bold }, \
{ "fb_face_sans_serif_italic", OPTION_STRING, &option_fb_face_sans_serif_italic }, \
{ "fb_face_sans_serif_italic_bold", OPTION_STRING, &option_fb_face_sans_serif_italic_bold }, \
- { "fb_face_monospace", OPTION_STRING, &option_fb_face_monospace }, \
{ "fb_face_serif", OPTION_STRING, &option_fb_face_serif }, \
- { "fb_serif_bold", OPTION_STRING, &option_fb_face_serif_bold }
+ { "fb_serif_bold", OPTION_STRING, &option_fb_face_serif_bold }, \
+ { "fb_face_monospace", OPTION_STRING, &option_fb_face_monospace }, \
+ { "fb_face_monospace_bold", OPTION_STRING, &option_fb_face_monospace_bold }, \
+ { "fb_face_cursive", OPTION_STRING, &option_fb_face_cursive }, \
+ { "fb_face_fantasy", OPTION_STRING, &option_fb_face_fantasy }
#endif