nsfont_width implemented for Unicode text

cache outline fonts for big speedup

still need to implement other text size functions
and also bold and italic fonts

svn path=/trunk/netsurf/; revision=6095
This commit is contained in:
Chris Young 2009-01-16 20:05:21 +00:00
parent ff6cfea10e
commit cd4f5ebd08
4 changed files with 68 additions and 57 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk> * Copyright 2008,2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
* *
* This file is part of NetSurf, http://www.netsurf-browser.org/ * This file is part of NetSurf, http://www.netsurf-browser.org/
* *

View File

@ -1,6 +1,5 @@
/* /*
* Copyright 2005 James Bursa <bursa@users.sourceforge.net> * Copyright 2008,2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
* 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
* *
* This file is part of NetSurf, http://www.netsurf-browser.org/ * This file is part of NetSurf, http://www.netsurf-browser.org/
* *
@ -33,7 +32,9 @@
#include <proto/Picasso96API.h> #include <proto/Picasso96API.h>
#include <proto/exec.h> #include <proto/exec.h>
#include <graphics/blitattr.h> #include <graphics/blitattr.h>
#include <graphics/composite.h> #include "amiga/options.h"
struct OutlineFont *of[CSS_FONT_FAMILY_NOT_SET];
static bool nsfont_width(const struct css_style *style, static bool nsfont_width(const struct css_style *style,
const char *string, size_t length, const char *string, size_t length,
@ -57,9 +58,19 @@ bool nsfont_width(const struct css_style *style,
const char *string, size_t length, const char *string, size_t length,
int *width) int *width)
{ {
struct TextFont *tfont = ami_open_font(style); struct TextFont *tfont;
*width = TextLength(currp,string,length); //buffer,strlen(buffer));
ami_close_font(tfont); if(option_quick_text)
{
tfont = ami_open_font(style);
*width = TextLength(currp,string,length); //buffer,strlen(buffer));
ami_close_font(tfont);
}
else
{
*width = ami_unicode_text(NULL,string,length,style,0,0,0);
}
return true; return true;
} }
@ -245,34 +256,7 @@ struct OutlineFont *ami_open_outline_font(struct css_style *style)
char *fontname; char *fontname;
WORD ysize; WORD ysize;
switch(style->font_family) ofont = of[style->font_family];
{
case CSS_FONT_FAMILY_SANS_SERIF:
fontname = option_font_sans;
break;
case CSS_FONT_FAMILY_SERIF:
fontname = option_font_serif;
break;
case CSS_FONT_FAMILY_MONOSPACE:
fontname = option_font_mono;
break;
case CSS_FONT_FAMILY_CURSIVE:
fontname = option_font_cursive;
break;
case CSS_FONT_FAMILY_FANTASY:
fontname = option_font_fantasy;
break;
default:
fontname = option_font_sans;
break;
}
if(!(ofont = OpenOutlineFont(fontname,NULL,OFF_OPEN))) return NULL;
/* see diskfont implementation for currently unimplemented bold/italic stuff */ /* see diskfont implementation for currently unimplemented bold/italic stuff */
@ -282,24 +266,14 @@ struct OutlineFont *ami_open_outline_font(struct css_style *style)
ysize = option_font_min_size; ysize = option_font_min_size;
if(ESetInfo(&ofont->olf_EEngine, if(ESetInfo(&ofont->olf_EEngine,
OT_DeviceDPI,(72<<16) | 72, OT_DeviceDPI,(72<<16) | 72,
OT_PointHeight,(ysize<<16), OT_PointHeight,(ysize<<16),
TAG_END) == OTERR_Success) TAG_END) == OTERR_Success)
{ {
return ofont;
}
else
{
CloseOutlineFont(ofont,NULL);
return NULL;
} }
return ofont; return NULL;
}
void ami_close_outline_font(struct OutlineFont *ofont)
{
if(ofont) CloseOutlineFont(ofont,NULL);
} }
void ami_close_font(struct TextFont *tfont) void ami_close_font(struct TextFont *tfont)
@ -311,7 +285,7 @@ void ami_close_font(struct TextFont *tfont)
if(tfont) CloseFont(tfont); if(tfont) CloseFont(tfont);
} }
void ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_style *style,ULONG dx, ULONG dy, ULONG c) ULONG ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_style *style,ULONG dx, ULONG dy, ULONG c)
{ {
WORD *utf16 = NULL; WORD *utf16 = NULL;
struct OutlineFont *ofont; struct OutlineFont *ofont;
@ -329,7 +303,7 @@ void ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_s
if(utf8_to_enc(string,"UTF-16",length,&utf16) != UTF8_CONVERT_OK) return; if(utf8_to_enc(string,"UTF-16",length,&utf16) != UTF8_CONVERT_OK) return;
if(!(ofont = ami_open_outline_font(style))) return; if(!(ofont = ami_open_outline_font(style))) return 0;
SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),TAG_DONE); SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),TAG_DONE);
@ -346,7 +320,9 @@ void ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_s
glyphbm = glyph->glm_BitMap; glyphbm = glyph->glm_BitMap;
if(!glyphbm) continue; if(!glyphbm) continue;
BltBitMapTags(BLITA_SrcX,glyph->glm_BlackLeft, if(rp)
{
BltBitMapTags(BLITA_SrcX,glyph->glm_BlackLeft,
BLITA_SrcY,glyph->glm_BlackTop, BLITA_SrcY,glyph->glm_BlackTop,
BLITA_DestX,dx+x, BLITA_DestX,dx+x,
BLITA_DestY,dy-glyph->glm_Y1, BLITA_DestY,dy-glyph->glm_Y1,
@ -354,10 +330,11 @@ void ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_s
BLITA_Height,glyph->glm_BlackHeight, BLITA_Height,glyph->glm_BlackHeight,
BLITA_Source,glyphbm, BLITA_Source,glyphbm,
BLITA_SrcType,BLITT_ALPHATEMPLATE, BLITA_SrcType,BLITT_ALPHATEMPLATE,
BLITA_Dest,currp, BLITA_Dest,rp,
BLITA_DestType,BLITT_RASTPORT, BLITA_DestType,BLITT_RASTPORT,
BLITA_SrcBytesPerRow,glyph->glm_BMModulo, BLITA_SrcBytesPerRow,glyph->glm_BMModulo,
TAG_DONE); TAG_DONE);
}
x+= glyph->glm_X1; x+= glyph->glm_X1;
@ -370,5 +347,32 @@ void ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_s
} }
ami_close_outline_font(ofont); return x;
}
void ami_init_fonts(void)
{
if(!option_quick_text)
{
of[CSS_FONT_FAMILY_SANS_SERIF] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN);
of[CSS_FONT_FAMILY_SERIF] = OpenOutlineFont(option_font_serif,NULL,OFF_OPEN);
of[CSS_FONT_FAMILY_MONOSPACE] = OpenOutlineFont(option_font_mono,NULL,OFF_OPEN);
of[CSS_FONT_FAMILY_CURSIVE] = OpenOutlineFont(option_font_cursive,NULL,OFF_OPEN);
of[CSS_FONT_FAMILY_FANTASY] = OpenOutlineFont(option_font_fantasy,NULL,OFF_OPEN);
of[CSS_FONT_FAMILY_UNKNOWN] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN);
of[CSS_FONT_FAMILY_NOT_SET] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN);
}
}
void ami_close_fonts(void)
{
int i=0;
if(!option_quick_text)
{
for(i=0;i<=CSS_FONT_FAMILY_NOT_SET;i++)
{
if(of[i]) CloseOutlineFont(of[i],NULL);
}
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk> * Copyright 2008,2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
* *
* This file is part of NetSurf, http://www.netsurf-browser.org/ * This file is part of NetSurf, http://www.netsurf-browser.org/
* *
@ -24,5 +24,8 @@
struct TextFont *ami_open_font(struct css_style *); struct TextFont *ami_open_font(struct css_style *);
void ami_close_font(struct TextFont *tfont); void ami_close_font(struct TextFont *tfont);
void ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_style *style,ULONG x,ULONG y,ULONG c); ULONG ami_unicode_text(struct RastPort *rp,char *string,ULONG length,struct css_style *style,ULONG x,ULONG y,ULONG c);
void ami_init_fonts(void);
void ami_close_fonts(void);
#endif #endif

View File

@ -330,6 +330,8 @@ void gui_init(int argc, char** argv)
if(!option_window_width) option_window_width = 800; if(!option_window_width) option_window_width = 800;
if(!option_window_height) option_window_height = 600; if(!option_window_height) option_window_height = 600;
ami_init_fonts();
plot=amiplot; plot=amiplot;
/* AmiUpdate */ /* AmiUpdate */
@ -1310,6 +1312,8 @@ void gui_quit(void)
FreeVec(glob.tmprasbuf); FreeVec(glob.tmprasbuf);
FreeVec(glob.areabuf); FreeVec(glob.areabuf);
ami_close_fonts();
if(!locked_screen) /* set if we are using somebody else's screen */ if(!locked_screen) /* set if we are using somebody else's screen */
{ {
while(!CloseScreen(scrn)); while(!CloseScreen(scrn));