Merged some features from framebuffer freetype impl.

- Set default font for font faces which failed to
   load.
 - Lookup more font faces (Cursive, Fantasy).
This commit is contained in:
Ole Loots 2012-08-25 05:23:10 +02:00
parent ff2f1f1836
commit c5a84e17f7
2 changed files with 106 additions and 63 deletions

View File

@ -23,11 +23,16 @@
#include "desktop/options.h" #include "desktop/options.h"
#include "atari/plot/plot.h" #include "atari/plot/plot.h"
#include "atari/plot/font_freetype.h" #include "atari/plot/font_freetype.h"
#include "atari/findfile.h"
#define DEJAVU_PATH "/usr/share/fonts/truetype/ttf-dejavu/"
#define CACHE_SIZE 2048
#define CACHE_MIN_SIZE (100 * 1024)
#define BOLD_WEIGHT 700
#define DEJAVU_PATH "/usr/share/fonts/truetype/ttf-dejavu/" extern css_fixed nscss_screen_dpi;
extern unsigned long atari_plot_flags; extern unsigned long atari_plot_flags;
extern int atari_plot_vdi_handle; extern int atari_plot_vdi_handle;
@ -123,50 +128,64 @@ ft_new_face(const char *option, const char *resname, const char *fontfile)
newf = font_faces[FONT_FACE_DEFAULT]; /* use default */ newf = font_faces[FONT_FACE_DEFAULT]; /* use default */
} }
return newf; return newf;
} }
static void ft_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec) static void ft_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
{ {
int selected_face = FONT_FACE_DEFAULT; int selected_face = FONT_FACE_DEFAULT;
switch (fstyle->family) { switch (fstyle->family) {
/*
case PLOT_FONT_FAMILY_CURSIVE: case PLOT_FONT_FAMILY_SERIF:
break; if (fstyle->weight >= BOLD_WEIGHT) {
case PLOT_FONT_FAMILY_FANTASY: selected_face = FONT_FACE_SERIF_BOLD;
break; } else {
*/ selected_face = FONT_FACE_SERIF;
case PLOT_FONT_FAMILY_SERIF: }
if (fstyle->weight >= 700) break;
selected_face = FONT_FACE_SERIF_BOLD;
else case PLOT_FONT_FAMILY_MONOSPACE:
selected_face = FONT_FACE_SERIF; if (fstyle->weight >= BOLD_WEIGHT) {
selected_face = FONT_FACE_MONOSPACE_BOLD;
break; } else {
selected_face = FONT_FACE_MONOSPACE;
case PLOT_FONT_FAMILY_MONOSPACE: }
selected_face = FONT_FACE_MONOSPACE; break;
break;
case PLOT_FONT_FAMILY_CURSIVE:
case PLOT_FONT_FAMILY_SANS_SERIF: selected_face = FONT_FACE_CURSIVE;
default: break;
if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE)) {
if (fstyle->weight >= 700) case PLOT_FONT_FAMILY_FANTASY:
selected_face = FONT_FACE_SANS_SERIF_ITALIC_BOLD; selected_face = FONT_FACE_FANTASY;
else break;
selected_face = FONT_FACE_SANS_SERIF_ITALIC;
} else { case PLOT_FONT_FAMILY_SANS_SERIF:
if (fstyle->weight >= 700) default:
selected_face = FONT_FACE_SANS_SERIF_BOLD; if ((fstyle->flags & FONTF_ITALIC) ||
else (fstyle->flags & FONTF_OBLIQUE)) {
selected_face = FONT_FACE_SANS_SERIF; if (fstyle->weight >= BOLD_WEIGHT) {
} selected_face = FONT_FACE_SANS_SERIF_ITALIC_BOLD;
} } else {
selected_face = FONT_FACE_SANS_SERIF_ITALIC;
srec->face_id = (FTC_FaceID)font_faces[selected_face]; }
srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE; } else {
srec->pixel = 0; if (fstyle->weight >= BOLD_WEIGHT) {
srec->x_res = srec->y_res = 72; selected_face = FONT_FACE_SANS_SERIF_BOLD;
} else {
selected_face = FONT_FACE_SANS_SERIF;
}
}
}
srec->face_id = (FTC_FaceID)font_faces[selected_face];
srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE;
srec->pixel = 0;
/* calculate x/y resolution, when nscss_screen_dpi isn't available */
/* 72 is an good value. */
srec->x_res = srec->y_res = FIXTOINT(nscss_screen_dpi);
} }
static FT_Glyph ft_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4) static FT_Glyph ft_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4)
@ -198,7 +217,8 @@ static bool ft_font_init(void)
{ {
FT_Error error; FT_Error error;
FT_ULong max_cache_size; FT_ULong max_cache_size;
FT_UInt max_faces = 6; FT_UInt max_faces = 6;
int i;
/* freetype library initialise */ /* freetype library initialise */
error = FT_Init_FreeType( &library ); error = FT_Init_FreeType( &library );
@ -206,8 +226,12 @@ static bool ft_font_init(void)
LOG(("Freetype could not initialised (code %d)\n", error)); LOG(("Freetype could not initialised (code %d)\n", error));
return false; return false;
} }
max_cache_size = 2 * 1024 *1024; /* 2MB should be enough */ /* set the Glyph cache size up */
max_cache_size = CACHE_SIZE * 1024;
if (max_cache_size < CACHE_MIN_SIZE) {
max_cache_size = CACHE_MIN_SIZE;
}
/* cache manager initialise */ /* cache manager initialise */
error = FTC_Manager_New(library, error = FTC_Manager_New(library,
@ -225,7 +249,11 @@ static bool ft_font_init(void)
error = FTC_CMapCache_New(ft_cmanager, &ft_cmap_cache); error = FTC_CMapCache_New(ft_cmanager, &ft_cmap_cache);
error = FTC_ImageCache_New(ft_cmanager, &ft_image_cache); error = FTC_ImageCache_New(ft_cmanager, &ft_image_cache);
/* Optain font faces */
/* Default font, Sans Serif */
font_faces[FONT_FACE_SANS_SERIF] = NULL; font_faces[FONT_FACE_SANS_SERIF] = NULL;
font_faces[FONT_FACE_SANS_SERIF] = ft_new_face( font_faces[FONT_FACE_SANS_SERIF] = ft_new_face(
nsoption_charp(atari_face_sans_serif), nsoption_charp(atari_face_sans_serif),
@ -234,55 +262,70 @@ static bool ft_font_init(void)
); );
if (font_faces[FONT_FACE_SANS_SERIF] == NULL) { if (font_faces[FONT_FACE_SANS_SERIF] == NULL) {
LOG(("Could not find default font (code %d)\n", error)); LOG(("Could not find default font (code %d)\n", error));
FTC_Manager_Done(ft_cmanager ); FTC_Manager_Done(ft_cmanager);
FT_Done_FreeType(library); FT_Done_FreeType(library);
return false; return false;
} }
/* Sans Serif Bold*/
font_faces[FONT_FACE_SANS_SERIF_BOLD] = font_faces[FONT_FACE_SANS_SERIF_BOLD] =
ft_new_face(nsoption_charp(atari_face_sans_serif_bold), ft_new_face(nsoption_charp(atari_face_sans_serif_bold),
"fonts/ssb.ttf", "fonts/ssb.ttf",
DEJAVU_PATH"DejaVuSans-Bold.ttf"); DEJAVU_PATH"DejaVuSans-Bold.ttf");
/* Sans Serif Italic */
font_faces[FONT_FACE_SANS_SERIF_ITALIC] = font_faces[FONT_FACE_SANS_SERIF_ITALIC] =
ft_new_face(nsoption_charp(atari_face_sans_serif_italic), ft_new_face(nsoption_charp(atari_face_sans_serif_italic),
"fonts/ssi.ttf", "fonts/ssi.ttf",
DEJAVU_PATH"DejaVuSans-Oblique.ttf"); DEJAVU_PATH"DejaVuSans-Oblique.ttf");
/* Sans Serif Italic Bold */
font_faces[FONT_FACE_SANS_SERIF_ITALIC_BOLD] = font_faces[FONT_FACE_SANS_SERIF_ITALIC_BOLD] =
ft_new_face(nsoption_charp(atari_face_sans_serif_italic_bold), ft_new_face(nsoption_charp(atari_face_sans_serif_italic_bold),
"fonts/ssib.ttf", "fonts/ssib.ttf",
DEJAVU_PATH"DejaVuSans-BoldOblique.ttf"); DEJAVU_PATH"DejaVuSans-BoldOblique.ttf");
/* Monospaced */
font_faces[FONT_FACE_MONOSPACE] = font_faces[FONT_FACE_MONOSPACE] =
ft_new_face(nsoption_charp(atari_face_monospace), ft_new_face(nsoption_charp(atari_face_monospace),
"fonts/mono.ttf", "fonts/mono.ttf",
DEJAVU_PATH"DejaVuSansMono.ttf"); DEJAVU_PATH"DejaVuSansMono.ttf");
/* Mospaced Bold */
font_faces[FONT_FACE_MONOSPACE_BOLD] = font_faces[FONT_FACE_MONOSPACE_BOLD] =
ft_new_face(nsoption_charp(atari_face_monospace_bold), ft_new_face(nsoption_charp(atari_face_monospace_bold),
"fonts/monob.ttf", "fonts/monob.ttf",
DEJAVU_PATH"DejaVuSansMono-Bold.ttf"); DEJAVU_PATH"DejaVuSansMono-Bold.ttf");
/* Serif */
font_faces[FONT_FACE_SERIF] = font_faces[FONT_FACE_SERIF] =
ft_new_face(nsoption_charp(atari_face_serif), ft_new_face(nsoption_charp(atari_face_serif),
"fonts/s.ttf", "fonts/s.ttf",
DEJAVU_PATH"DejaVuSerif.ttf"); DEJAVU_PATH"DejaVuSerif.ttf");
/* Serif Bold */
font_faces[FONT_FACE_SERIF_BOLD] = font_faces[FONT_FACE_SERIF_BOLD] =
ft_new_face(nsoption_charp(atari_face_serif_bold), ft_new_face(nsoption_charp(atari_face_serif_bold),
"fonts/sb.ttf", "fonts/sb.ttf",
DEJAVU_PATH"DejaVuSerif-Bold.ttf"); DEJAVU_PATH"DejaVuSerif-Bold.ttf");
/* Cursive */
font_faces[FONT_FACE_CURSIVE] = font_faces[FONT_FACE_CURSIVE] =
ft_new_face(nsoption_charp(atari_face_cursive), ft_new_face(nsoption_charp(atari_face_cursive),
"fonts/cursive.ttf", "fonts/cursive.ttf",
DEJAVU_PATH"DejaVuSansMono-Oblique.ttf"); DEJAVU_PATH"DejaVuSansMono-Oblique.ttf");
/* Fantasy */
font_faces[FONT_FACE_FANTASY] = font_faces[FONT_FACE_FANTASY] =
ft_new_face(nsoption_charp(atari_face_fantasy), ft_new_face(nsoption_charp(atari_face_fantasy),
"fonts/fantasy.ttf", "fonts/fantasy.ttf",
DEJAVU_PATH"DejaVuSerifCondensed-Bold.ttf"); DEJAVU_PATH"DejaVuSerifCondensed-Bold.ttf");
for (i=1; i<FONT_FACE_COUNT; i++) {
if (font_faces[i] == NULL){
font_faces[i] = font_faces[FONT_FACE_SANS_SERIF];
}
}
return true; return true;
} }

View File

@ -48,4 +48,4 @@ struct font_desc {
/* extern int ft_load_type; */ /* extern int ft_load_type; */
int ctor_font_plotter_freetype( FONT_PLOTTER self ); int ctor_font_plotter_freetype( FONT_PLOTTER self );
#endif #endif