summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-11-27 14:57:32 (GMT)
committer Chris Young <chris@unsatisfactorysoftware.co.uk>2016-11-27 14:57:32 (GMT)
commit20432237883a04677f30f1758979fa0a4b9111e3 (patch)
treeea3ed81ff4d2a3f010ffa30da0700c3a7314c896
parentf8f802cda5f54c0c2b1acd51efc08aa7d4afad1b (diff)
downloadnetsurf-20432237883a04677f30f1758979fa0a4b9111e3.tar.gz
netsurf-20432237883a04677f30f1758979fa0a4b9111e3.tar.bz2
Reduce frequency of diskfont open/close
-rw-r--r--frontends/amiga/font.c2
-rw-r--r--frontends/amiga/font_diskfont.c43
-rw-r--r--frontends/amiga/font_diskfont.h1
3 files changed, 32 insertions, 14 deletions
diff --git a/frontends/amiga/font.c b/frontends/amiga/font.c
index d3b9c32..22a0f4a 100644
--- a/frontends/amiga/font.c
+++ b/frontends/amiga/font.c
@@ -115,6 +115,8 @@ void ami_font_fini(void)
{
if(nsoption_bool(bitmap_fonts) == false) {
ami_font_bullet_fini();
+ } else {
+ ami_font_diskfont_fini();
}
}
diff --git a/frontends/amiga/font_diskfont.c b/frontends/amiga/font_diskfont.c
index 313e992..8593f81 100644
--- a/frontends/amiga/font_diskfont.c
+++ b/frontends/amiga/font_diskfont.c
@@ -39,6 +39,9 @@
#define MAX_FONT_NAME_SIZE 33
+static plot_font_style_t *prev_fstyle = NULL;
+static struct TextFont *prev_font = NULL;
+
static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_style_t *fstyle)
{
struct TextFont *bmfont = NULL;
@@ -46,6 +49,15 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st
char *fontname;
char font[MAX_FONT_NAME_SIZE];
+ if((prev_fstyle != NULL) && (prev_font != NULL) &&
+ (fstyle->family == prev_fstyle->family) &&
+ (fstyle->size == prev_fstyle->size) &&
+ (fstyle->flags == prev_fstyle->flags) &&
+ (fstyle->weight == prev_fstyle->weight)) {
+ LOG("(using current font)");
+ return prev_font;
+ }
+
if(rp == NULL) return NULL;
tattr.ta_Flags = 0;
@@ -87,16 +99,19 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st
tattr.ta_Name = font;
tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE;
LOG("font: %s/%d", tattr.ta_Name, tattr.ta_YSize);
+
+ if(prev_font != NULL) CloseFont(prev_font);
+
if((bmfont = OpenDiskFont(&tattr))) {
SetRPAttrs(rp, RPTAG_Font, bmfont, TAG_DONE);
}
- return bmfont;
-}
+ if(prev_fstyle != NULL) {
+ memcpy(prev_fstyle, fstyle, sizeof(plot_font_style_t));
+ prev_font = bmfont;
+ }
-static void ami_font_bm_close(struct TextFont *bmfont)
-{
- CloseFont(bmfont);
+ return bmfont;
}
static size_t ami_font_bm_convert_local_to_utf8_offset(const char *utf8string, size_t length, UWORD offset)
@@ -125,15 +140,12 @@ static nserror amiga_bm_nsfont_width(const plot_font_style_t *fstyle,
if(bmfont == NULL) return NSERROR_INVALID;
if(utf8_to_local_encoding(string, length, &localtext) != NSERROR_OK) {
- ami_font_bm_close(bmfont);
return NSERROR_INVALID;
}
*width = TextLength(glob->rp, localtext, (UWORD)strlen(localtext));
free(localtext);
- ami_font_bm_close(bmfont);
-
return NSERROR_OK;
}
@@ -164,7 +176,6 @@ static nserror amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyl
if(bmfont == NULL) return NSERROR_INVALID;
if(utf8_to_local_encoding(string, length, &localtext) != NSERROR_OK) {
- ami_font_bm_close(bmfont);
return NSERROR_INVALID;
}
@@ -174,7 +185,6 @@ static nserror amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyl
*actual_x = extent.te_Extent.MaxX;
free(localtext);
- ami_font_bm_close(bmfont);
return NSERROR_OK;
}
@@ -218,7 +228,6 @@ static nserror amiga_bm_nsfont_split(const plot_font_style_t *fstyle,
if(bmfont == NULL) return NSERROR_INVALID;
if(utf8_to_local_encoding(string, length, &localtext) != NSERROR_OK) {
- ami_font_bm_close(bmfont);
return NSERROR_INVALID;
}
@@ -252,7 +261,6 @@ static nserror amiga_bm_nsfont_split(const plot_font_style_t *fstyle,
}
free(localtext);
- ami_font_bm_close(bmfont);
return NSERROR_OK;
}
@@ -273,8 +281,6 @@ static ULONG amiga_bm_nsfont_text(struct RastPort *rp, const char *string, ULONG
free(localtext);
}
- ami_font_bm_close(bmfont);
-
return 0;
}
@@ -289,5 +295,14 @@ void ami_font_diskfont_init(void)
{
/* Set up table */
ami_nsfont = &ami_font_diskfont_table;
+
+ /* Alloc space to hold currently open font - doesn't matter if this fails */
+ prev_fstyle = calloc(1, sizeof(plot_font_style_t));
+}
+
+void ami_font_diskfont_fini(void)
+{
+ if(prev_font != NULL) CloseFont(prev_font);
+ if(prev_fstyle != NULL) free(prev_fstyle);
}
diff --git a/frontends/amiga/font_diskfont.h b/frontends/amiga/font_diskfont.h
index de19e94..1c891d2 100644
--- a/frontends/amiga/font_diskfont.h
+++ b/frontends/amiga/font_diskfont.h
@@ -19,5 +19,6 @@
#ifndef AMIGA_FONT_DISKFONT_H
#define AMIGA_FONT_DISKFONT_H
void ami_font_diskfont_init(void);
+void ami_font_diskfont_fini(void);
#endif