[stsf-commit] stsf/STFontServer/dropins/freetype2 ft2_glue.c, 1.2,
1.3
Alexander Gelfenbain
stsf-commit at pdx.freedesktop.org
Fri Jun 4 22:23:06 PDT 2004
- Previous message: [stsf-commit] stsf/STClientLibrary/src STGlyphVector.c, 1.5,
1.6 STLine.c, 1.4, 1.5 libtest.c, 1.4, 1.5 serverconnection.c,
1.9, 1.10
- Next message: [stsf-commit]
stsf/STFontServer/src fontserver.c, 1.5, 1.6 handler.c,
1.7, 1.8 stfs-door.c, 1.8, 1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: adg
Index: ft2_glue.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/dropins/freetype2/ft2_glue.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/ft2_glue.c 25 May 2004 02:47:24 -0000 1.2
+++ b/ft2_glue.c 5 Jun 2004 05:23:03 -0000 1.3
@@ -60,6 +60,7 @@
#include <string.h>
#include <list.h>
+#include <crc32.h>
#include <stsfutil.h>
#include <stmath.h>
#include <stfontserverprivate.h>
@@ -96,6 +97,8 @@
typedef struct {
uint32_t instanceID;
+ int ff_index;
+
FT_Library library;
FT_Face face;
FT_Matrix matrix;
@@ -110,15 +113,58 @@
// 3 - bit-swapped B&W
} ScalerCacheRecord, *ScalerCacheRecordPtr;
+typedef struct {
+ FileImage *fi;
+ int refCnt;
+} FontFileRecord, *FontFileRecordPtr;
#define CACHE_CAPACITY 32 // more than plenty
-// LRU Cache
-static list cache;
+
+static list cache; // LRU Cache
+static FontFileRecord fontfiles[CACHE_CAPACITY];
+
+static void RemoveFontFile(int i)
+{
+ if (fontfiles[i].refCnt > 0) {
+ if (--fontfiles[i].refCnt == 0) {
+ UnloadFile(fontfiles[i].fi);
+ fontfiles[i].fi = NULL;
+ }
+ }
+}
+static int AddFontFile(const char *fname)
+{
+ int i, freeslot = -1;
+
+ for (i=0; i<CACHE_CAPACITY; i++) {
+ if (fontfiles[i].refCnt > 0) {
+ if (!strcmp(fname, fontfiles[i].fi->fname)) {
+ fontfiles[i].refCnt++;
+ return i;
+ }
+ } else {
+ if (freeslot == -1) {
+ freeslot = i;
+ }
+ }
+ }
+ if (freeslot == -1) {
+ ErrorStr("ft2_glue: %s: internal error: could not find a free slot.", __func__);
+ return -1;
+ }
+ if ((fontfiles[freeslot].fi = LoadFile(fname, -1, -1)) == NULL) {
+ ErrorStr("ft2_glue: %s: internal error: could not load a file.", __func__);
+ return -1;
+ }
+ fontfiles[freeslot].refCnt = 1;
+ return freeslot;
+}
static void ScalerCacheRecordDispose(ScalerCacheRecordPtr t)
{
FT_Done_Face(t->face);
FT_Done_FreeType(t->library);
+ RemoveFontFile(t->ff_index);
glue.free(t);
}
@@ -132,6 +178,7 @@
double w, h;
const char *filename;
int lno;
+ int ff_index;
FMatrix tmpmat;
@@ -152,14 +199,19 @@
return 0;
}
- if (FT_New_Face(library, filename, lno, &face)) {
+ if ((ff_index = AddFontFile(filename)) < 0) {
FT_Done_FreeType(library);
return 0;
}
+ if (FT_New_Memory_Face(library, fontfiles[ff_index].fi->ptr, fontfiles[ff_index].fi->len, lno, &face)) {
+ FT_Done_FreeType(library);
+ return 0;
+ }
res = glue.malloc(sizeof(ScalerCacheRecord));
res->instanceID = instance->instanceID;
+ res->ff_index = ff_index;
res->library = library;
res->face = face;
@@ -357,7 +409,7 @@
}
cache = listNewEmpty(); assert(cache != 0);
-
+
/* Initialize the LCD alpha-mask to indexed color conversion */
@@ -643,15 +695,15 @@
ScalerGlueRecord glue = {
- /* uint32_t tag; */ ST_TAG_SCALER,
- /* uint32_t vtag; */ ST_SCALER_FREETYPE2,
- /* uint32_t version; */ 0x02140002,
+ /* uint32_t tag; */ ST_TAG_SCALER,
+ /* uint32_t vtag; */ ST_SCALER_FREETYPE2,
+ /* uint32_t version; */ 0x02140002,
/* const char *shortname; */ "FT2 engine",
- /* const char *longname; */ "FreeType 2.1.4 Engine",
+ /* const char *longname; */ "FreeType Engine",
/* const char *notice; */ "",
- /* uint32_t flags; */ ST_SF_BITMAP | ST_SF_AUTOHINTING | ST_SF_GRAYSCALE | ST_SF_HINTS | ST_SF_LCDOPTIMIZED,
- /* uint32_t fontflags; */ ST_FM_TRUETYPE | ST_FM_TTC | ST_FM_TYPE1 | ST_FM_OPENTYPE_TTF | ST_FM_OPENTYPE_OTF | ST_FM_TRUETYPE_GX | ST_FM_PCF,
+ /* uint32_t flags; */ ST_SF_BITMAP | ST_SF_AUTOHINTING | ST_SF_GRAYSCALE | ST_SF_LCDOPTIMIZED,
+ /* uint32_t fontflags; */ ST_FM_TRUETYPE | ST_FM_TTC | ST_FM_TYPE1 | ST_FM_OPENTYPE_TTF | ST_FM_OPENTYPE_OTF | ST_FM_TRUETYPE_GX | ST_FM_PCF,
/* StartF Init; */ Start,
/* StopF Stop; */ Stop,
@@ -660,7 +712,6 @@
/* RenderGlyphF RenderGlyph; */ RenderGlyph,
/* GetGlyphPointF GetGlyphPoint; */ GetGlyphPoint,
-
/* AllocateF malloc; */ 0,
/* FreeF free; */ 0,
/* ReallocateF realloc; */ 0,
- Previous message: [stsf-commit] stsf/STClientLibrary/src STGlyphVector.c, 1.5,
1.6 STLine.c, 1.4, 1.5 libtest.c, 1.4, 1.5 serverconnection.c,
1.9, 1.10
- Next message: [stsf-commit]
stsf/STFontServer/src fontserver.c, 1.5, 1.6 handler.c,
1.7, 1.8 stfs-door.c, 1.8, 1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the stsf-commit
mailing list