summaryrefslogtreecommitdiff
path: root/amiga/os3support.c
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2015-01-28 18:49:44 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2015-01-28 18:49:44 +0000
commitecdf37c6ac7b72761133b2a749d28ded12ed6c03 (patch)
tree287f8536a4424361e21f491e1c650163f895d74c /amiga/os3support.c
parentfd59fa248a08451d4ff20c4fb91834c13ae405da (diff)
downloadnetsurf-ecdf37c6ac7b72761133b2a749d28ded12ed6c03.tar.gz
netsurf-ecdf37c6ac7b72761133b2a749d28ded12ed6c03.tar.bz2
Fixup font.c a bit better for OS3
Diffstat (limited to 'amiga/os3support.c')
-rw-r--r--amiga/os3support.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/amiga/os3support.c b/amiga/os3support.c
index 3b42685a5..987f18b2b 100644
--- a/amiga/os3support.c
+++ b/amiga/os3support.c
@@ -27,17 +27,123 @@
#include <stdarg.h>
#include <stdio.h>
+#include <proto/bullet.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/utility.h>
+#include <diskfont/diskfonttag.h>
#include <intuition/gadgetclass.h>
+#include "utils/log.h"
+
#define SUCCESS (TRUE)
#define FAILURE (FALSE)
#define NO !
+/* Diskfont */
+struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG flags)
+{
+ BPTR fh = 0;
+ int64 size = 0;
+ struct TagItem *buffer, *ti;
+ STRPTR fname, otagpath;
+ struct BulletBase *BulletBase;
+ struct OutlineFont *of = NULL;
+ struct GlyphEngine *eengine;
+
+ otagpath = (STRPTR)ASPrintf("FONTS:%s.otag", fileName);
+ fh = Open(otagpath, MODE_OLDFILE);
+
+ if(fh == 0) {
+ /*\todo we should be opening the .font file too and checking
+ * for the magic bytes to indicate this is an outline font.
+ */
+ LOG(("Unable to open %s", otagpath));
+ FreeVec(otagpath);
+ return NULL;
+ }
+
+ size = GetFileSize(fh);
+ buffer = (struct TagItem *)AllocVec(size, MEMF_ANY);
+ if(buffer == NULL) {
+ LOG(("Unable to allocate memory"));
+ Close(fh);
+ FreeVec(otagpath);
+ return NULL;
+ }
+
+ Read(fh, buffer, size);
+ Close(fh);
+
+ /* The first tag is supposed to be OT_FileIdent and should equal 'size' */
+ struct TagItem *tag = buffer;
+ if((tag->ti_Tag != OT_FileIdent) || (tag->ti_Data != (ULONG)size)) {
+ LOG(("Invalid OTAG file"));
+ FreeVec(buffer);
+ FreeVec(otagpath);
+ return NULL;
+ }
+
+ /* Relocate all the OT_Indirect tags */
+ while (ti = NextTagItem(&buffer)) {
+ if(ti->ti_Tag & OT_Indirect) {
+ ti->ti_Data += buffer;
+ }
+ }
+
+ /* Find OT_Engine and open the font engine */
+ if(ti = FindTagItem(OT_Engine, buffer)) {
+ LOG(("Using font engine %s", ti->ti_Data));
+ fname = ASPrintf("%s.library", ti->ti_Data);
+ } else {
+ LOG(("Cannot find OT_Engine tag"));
+ FreeVec(buffer);
+ FreeVec(otagpath);
+ return NULL;
+ }
+
+ BulletBase = OpenLibrary(fname, 0L);
+
+ if(BulletBase == NULL) {
+ LOG(("Unable to open %s", fname));
+ FreeVec(buffer);
+ FreeVec(fname);
+ FreeVec(otagpath);
+ }
+
+ FreeVec(fname);
+
+ eengine = OpenEngine();
+
+ SetInfo(eengine,
+ OT_OTagPath, otagpath,
+ OT_OTagList, buffer,
+ TAG_DONE);
+
+ of = AllocVec(sizeof(struct OutlineFont), MEMF_CLEAR);
+ if(of == NULL) return NULL;
+
+ of->BulletBase = BulletBase;
+ of->olf_EEngine = eengine;
+ of->OTagPath = otagpath;
+ of->olf_OTagList = buffer;
+}
+
+void CloseOutlineFont(struct OutlineFont *of, struct List *list)
+{
+ struct BulletBase *BulletBase = of->BulletBase;
+
+ CloseEngine(of->olf_EEngine);
+ CloseLibrary(BulletBase);
+
+ FreeVec(of->OTagPath);
+ FreeVec(of->olf_OTagList);
+ FreeVec(of);
+}
+
+
/* DOS */
int64 GetFileSize(BPTR fh)
{