2012-05-04 23:30:30 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
/** \file
|
|
|
|
* Font glyph scanner for Unicode substitutions.
|
2012-05-04 23:30:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-05-05 19:58:17 +04:00
|
|
|
#include <stdlib.h>
|
2012-05-04 23:30:30 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <proto/diskfont.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/exec.h>
|
2012-05-05 23:09:42 +04:00
|
|
|
#include <proto/intuition.h>
|
2012-05-04 23:30:30 +04:00
|
|
|
#include <diskfont/diskfonttag.h>
|
|
|
|
#include <diskfont/oterrors.h>
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
#include <proto/window.h>
|
|
|
|
#include <proto/layout.h>
|
|
|
|
#include <proto/fuelgauge.h>
|
|
|
|
#include <classes/window.h>
|
|
|
|
#include <gadgets/fuelgauge.h>
|
|
|
|
#include <gadgets/layout.h>
|
|
|
|
|
2012-05-07 18:18:22 +04:00
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
|
2012-05-05 19:58:17 +04:00
|
|
|
#include "amiga/font_scan.h"
|
2012-05-07 18:18:22 +04:00
|
|
|
#include "amiga/gui.h"
|
2012-05-05 18:46:18 +04:00
|
|
|
#include "amiga/object.h"
|
2012-05-07 18:18:22 +04:00
|
|
|
#include "amiga/utf8.h"
|
2012-05-05 18:46:18 +04:00
|
|
|
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2012-05-05 23:09:42 +04:00
|
|
|
#include "utils/log.h"
|
2012-05-07 18:18:22 +04:00
|
|
|
#include "utils/messages.h"
|
2012-05-05 23:09:42 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
FS_OID_MAIN = 0,
|
|
|
|
FS_GID_MAIN,
|
|
|
|
FS_GID_FONTS,
|
|
|
|
FS_GID_GLYPHS,
|
|
|
|
FS_GID_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ami_font_scan_window {
|
|
|
|
struct Window *win;
|
|
|
|
Object *objects[FS_GID_LAST];
|
2012-05-07 18:18:22 +04:00
|
|
|
char *title;
|
|
|
|
char *glyphtext;
|
2012-05-05 23:09:42 +04:00
|
|
|
};
|
|
|
|
|
2012-05-05 19:58:17 +04:00
|
|
|
/**
|
|
|
|
* Lookup a font that contains a UTF-16 codepoint
|
|
|
|
*
|
|
|
|
* \param code UTF-16 codepoint to lookup
|
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers
|
|
|
|
* \return font name or NULL
|
|
|
|
*/
|
2014-05-19 21:39:54 +04:00
|
|
|
const char *ami_font_scan_lookup(const uint16 *code, lwc_string **glypharray)
|
2012-05-05 19:58:17 +04:00
|
|
|
{
|
2013-04-14 19:03:46 +04:00
|
|
|
if(*code >= 0xd800 && *code <= 0xdbff) {
|
|
|
|
/* This is a multi-byte character, we don't support falback for these yet. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(glypharray[*code] == NULL) return NULL;
|
|
|
|
else return lwc_string_data(glypharray[*code]);
|
2012-05-05 19:58:17 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
/**
|
|
|
|
* Open GUI to show font scanning progress
|
|
|
|
*
|
|
|
|
* \param fonts number of fonts that are being scanned
|
|
|
|
* \return pointer to a struct ami_font_scan_window
|
|
|
|
*/
|
|
|
|
struct ami_font_scan_window *ami_font_scan_gui_open(int32 fonts)
|
|
|
|
{
|
2012-05-07 18:18:22 +04:00
|
|
|
struct ami_font_scan_window *fsw =
|
2013-10-12 16:11:13 +04:00
|
|
|
AllocVecTagList(sizeof(struct ami_font_scan_window), NULL);
|
2012-05-07 18:18:22 +04:00
|
|
|
|
|
|
|
if(fsw == NULL) return NULL;
|
|
|
|
|
|
|
|
fsw->title = ami_utf8_easy(messages_get("FontScanning"));
|
|
|
|
fsw->glyphtext = ami_utf8_easy(messages_get("FontGlyphs"));
|
|
|
|
|
|
|
|
fsw->objects[FS_OID_MAIN] = WindowObject,
|
|
|
|
WA_ScreenTitle, nsscreentitle,
|
|
|
|
WA_Title, fsw->title,
|
|
|
|
WA_Activate, TRUE,
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
WA_CloseGadget, FALSE,
|
|
|
|
WA_SizeGadget, TRUE,
|
2013-03-20 12:22:03 +04:00
|
|
|
WA_PubScreen, scrn,
|
2012-05-07 18:18:22 +04:00
|
|
|
WA_BusyPointer, TRUE,
|
|
|
|
WA_Width, 400,
|
|
|
|
WINDOW_UserData, fsw,
|
|
|
|
WINDOW_IconifyGadget, FALSE,
|
|
|
|
WINDOW_Position, WPOS_CENTERSCREEN,
|
|
|
|
WINDOW_LockHeight, TRUE,
|
|
|
|
WINDOW_ParentGroup, fsw->objects[FS_GID_MAIN] = VGroupObject,
|
|
|
|
LAYOUT_AddChild, fsw->objects[FS_GID_FONTS] = FuelGaugeObject,
|
|
|
|
GA_ID, FS_GID_FONTS,
|
|
|
|
GA_Text, fsw->title,
|
|
|
|
FUELGAUGE_Min, 0,
|
|
|
|
FUELGAUGE_Max, fonts,
|
|
|
|
FUELGAUGE_Level, 0,
|
|
|
|
FUELGAUGE_Ticks, 11,
|
|
|
|
FUELGAUGE_ShortTicks, TRUE,
|
|
|
|
FUELGAUGE_Percent, FALSE,
|
|
|
|
FUELGAUGE_Justification, FGJ_CENTER,
|
|
|
|
FuelGaugeEnd,
|
|
|
|
CHILD_NominalSize, TRUE,
|
|
|
|
CHILD_WeightedHeight, 0,
|
|
|
|
LAYOUT_AddChild, fsw->objects[FS_GID_GLYPHS] = FuelGaugeObject,
|
|
|
|
GA_ID, FS_GID_GLYPHS,
|
|
|
|
//GA_Text, "Glyphs",
|
|
|
|
FUELGAUGE_Min, 0x0000,
|
|
|
|
FUELGAUGE_Max, 0xffff,
|
|
|
|
FUELGAUGE_Level, 0,
|
|
|
|
FUELGAUGE_Ticks,11,
|
|
|
|
FUELGAUGE_ShortTicks, TRUE,
|
|
|
|
FUELGAUGE_Percent, FALSE,
|
|
|
|
FUELGAUGE_Justification, FGJ_CENTER,
|
|
|
|
FuelGaugeEnd,
|
|
|
|
CHILD_NominalSize, TRUE,
|
|
|
|
CHILD_WeightedHeight, 0,
|
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
|
|
|
fsw->win = (struct Window *)RA_OpenWindow(fsw->objects[FS_OID_MAIN]);
|
|
|
|
|
|
|
|
return fsw;
|
2012-05-05 23:09:42 +04:00
|
|
|
}
|
|
|
|
|
2012-05-06 21:55:35 +04:00
|
|
|
/**
|
|
|
|
* Update GUI showing font scanning progress
|
|
|
|
*
|
|
|
|
* \param win pointer to a struct ami_font_scan_window
|
|
|
|
* \param font current font being scanned
|
|
|
|
* \param font_num font number being scanned
|
|
|
|
* \param glyphs number of unique glyphs found
|
|
|
|
*/
|
2012-05-07 18:18:22 +04:00
|
|
|
void ami_font_scan_gui_update(struct ami_font_scan_window *fsw, const char *font,
|
2012-05-06 21:55:35 +04:00
|
|
|
ULONG font_num, ULONG glyphs)
|
|
|
|
{
|
2012-05-07 18:18:22 +04:00
|
|
|
ULONG va[2];
|
|
|
|
|
|
|
|
if(fsw) {
|
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)fsw->objects[FS_GID_FONTS],
|
|
|
|
fsw->win, NULL,
|
|
|
|
FUELGAUGE_Level, font_num,
|
|
|
|
GA_Text, font,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
va[0] = glyphs;
|
|
|
|
va[1] = 0;
|
|
|
|
|
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)fsw->objects[FS_GID_GLYPHS],
|
|
|
|
fsw->win, NULL,
|
|
|
|
GA_Text, fsw->glyphtext,
|
|
|
|
FUELGAUGE_VarArgs, va,
|
|
|
|
FUELGAUGE_Level, glyphs,
|
|
|
|
TAG_DONE);
|
2012-05-06 21:55:35 +04:00
|
|
|
} else {
|
|
|
|
printf("Found %ld glyphs\n", glyphs);
|
|
|
|
printf("Scanning font #%ld (%s)...\n", font_num, font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
/**
|
|
|
|
* Close GUI showing font scanning progress
|
|
|
|
*
|
2012-10-08 17:51:48 +04:00
|
|
|
* \param fsw pointer to a struct ami_font_scan_window
|
2012-05-05 23:09:42 +04:00
|
|
|
*/
|
2012-05-07 18:18:22 +04:00
|
|
|
void ami_font_scan_gui_close(struct ami_font_scan_window *fsw)
|
2012-05-05 23:09:42 +04:00
|
|
|
{
|
2012-05-07 18:18:22 +04:00
|
|
|
if(fsw) {
|
|
|
|
DisposeObject(fsw->objects[FS_OID_MAIN]);
|
|
|
|
ami_utf8_free(fsw->title);
|
|
|
|
FreeVec(fsw);
|
2012-05-06 21:55:35 +04:00
|
|
|
}
|
2012-05-05 23:09:42 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
/**
|
|
|
|
* Scan a font for glyphs not present in glypharray.
|
|
|
|
*
|
|
|
|
* \param fontname font to scan
|
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers
|
|
|
|
* \return number of new glyphs found
|
|
|
|
*/
|
|
|
|
ULONG ami_font_scan_font(const char *fontname, lwc_string **glypharray)
|
2012-05-04 23:30:30 +04:00
|
|
|
{
|
|
|
|
struct OutlineFont *ofont;
|
|
|
|
struct MinList *widthlist;
|
|
|
|
struct GlyphWidthEntry *gwnode;
|
|
|
|
ULONG foundglyphs = 0;
|
|
|
|
ULONG serif = 0;
|
2012-05-05 18:46:18 +04:00
|
|
|
lwc_error lerror;
|
2013-04-14 19:03:46 +04:00
|
|
|
ULONG unicoderanges = 0;
|
2012-05-04 23:30:30 +04:00
|
|
|
|
|
|
|
ofont = OpenOutlineFont(fontname, NULL, OFF_OPEN);
|
|
|
|
|
2012-05-05 19:58:17 +04:00
|
|
|
if(!ofont) return 0;
|
2012-05-04 23:30:30 +04:00
|
|
|
|
|
|
|
if(ESetInfo(&ofont->olf_EEngine,
|
|
|
|
OT_PointHeight, 10 * (1 << 16),
|
|
|
|
OT_GlyphCode, 0x0000,
|
|
|
|
OT_GlyphCode2, 0xffff,
|
|
|
|
TAG_END) == OTERR_Success)
|
|
|
|
{
|
|
|
|
if(EObtainInfo(&ofont->olf_EEngine,
|
2013-04-14 19:03:46 +04:00
|
|
|
OT_WidthList, &widthlist,
|
|
|
|
TAG_END) == 0)
|
2012-05-04 23:30:30 +04:00
|
|
|
{
|
|
|
|
gwnode = (struct GlyphWidthEntry *)GetHead((struct List *)widthlist);
|
|
|
|
do {
|
|
|
|
if(gwnode && (glypharray[gwnode->gwe_Code] == NULL)) {
|
2012-05-05 18:46:18 +04:00
|
|
|
lerror = lwc_intern_string(fontname, strlen(fontname) - 5, &glypharray[gwnode->gwe_Code]);
|
|
|
|
if(lerror != lwc_error_ok) continue;
|
2012-05-04 23:30:30 +04:00
|
|
|
foundglyphs++;
|
|
|
|
}
|
|
|
|
} while(gwnode = (struct GlyphWidthEntry *)GetSucc((struct Node *)gwnode));
|
2013-04-14 19:03:46 +04:00
|
|
|
EReleaseInfo(&ofont->olf_EEngine,
|
|
|
|
OT_WidthList, widthlist,
|
|
|
|
TAG_END);
|
2012-05-04 23:30:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-14 19:03:46 +04:00
|
|
|
if(EObtainInfo(&ofont->olf_EEngine, OT_UnicodeRanges, &unicoderanges, TAG_END) == 0) {
|
|
|
|
if(unicoderanges & UCR_SURROGATES) LOG(("%s supports UTF-16 surrogates", fontname));
|
|
|
|
EReleaseInfo(&ofont->olf_EEngine,
|
|
|
|
OT_UnicodeRanges, unicoderanges,
|
|
|
|
TAG_END);
|
|
|
|
}
|
|
|
|
|
2012-05-04 23:30:30 +04:00
|
|
|
CloseOutlineFont(ofont, NULL);
|
|
|
|
|
|
|
|
return foundglyphs;
|
|
|
|
}
|
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
/**
|
|
|
|
* Scan all fonts for glyphs.
|
|
|
|
*
|
2012-10-08 17:51:48 +04:00
|
|
|
* \param list min list
|
|
|
|
* \param win scan window
|
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers
|
2012-05-05 15:09:19 +04:00
|
|
|
* \return number of glyphs found
|
|
|
|
*/
|
2012-05-06 21:55:35 +04:00
|
|
|
ULONG ami_font_scan_fonts(struct MinList *list,
|
|
|
|
struct ami_font_scan_window *win, lwc_string **glypharray)
|
2012-05-05 18:46:18 +04:00
|
|
|
{
|
2012-05-06 21:55:35 +04:00
|
|
|
ULONG found, total = 0, font_num = 0;
|
2012-05-05 18:46:18 +04:00
|
|
|
struct nsObject *node;
|
|
|
|
struct nsObject *nnode;
|
|
|
|
|
|
|
|
if(IsMinListEmpty(list)) return 0;
|
|
|
|
|
|
|
|
node = (struct nsObject *)GetHead((struct List *)list);
|
|
|
|
|
|
|
|
do {
|
|
|
|
nnode = (struct nsObject *)GetSucc((struct Node *)node);
|
2012-05-06 21:55:35 +04:00
|
|
|
ami_font_scan_gui_update(win, node->dtz_Node.ln_Name, font_num, total);
|
2012-10-17 01:10:49 +04:00
|
|
|
LOG(("Scanning %s", node->dtz_Node.ln_Name));
|
2012-05-05 18:46:18 +04:00
|
|
|
found = ami_font_scan_font(node->dtz_Node.ln_Name, glypharray);
|
|
|
|
total += found;
|
2012-10-17 01:10:49 +04:00
|
|
|
LOG(("Found %ld new glyphs (total = %ld)", found, total));
|
2012-05-07 18:18:22 +04:00
|
|
|
font_num++;
|
2012-05-05 18:46:18 +04:00
|
|
|
} while(node = nnode);
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add OS fonts to a list.
|
|
|
|
*
|
|
|
|
* \param list list to add font names to
|
|
|
|
* \return number of fonts found
|
|
|
|
*/
|
|
|
|
ULONG ami_font_scan_list(struct MinList *list)
|
2012-05-04 23:30:30 +04:00
|
|
|
{
|
2014-04-06 02:34:51 +04:00
|
|
|
int afShortage, afSize = 100;
|
2012-05-04 23:30:30 +04:00
|
|
|
struct AvailFontsHeader *afh;
|
|
|
|
struct AvailFonts *af;
|
2012-05-05 23:09:42 +04:00
|
|
|
ULONG found = 0;
|
2012-05-05 18:46:18 +04:00
|
|
|
struct nsObject *node;
|
2012-05-04 23:30:30 +04:00
|
|
|
|
|
|
|
do {
|
2013-10-12 16:11:13 +04:00
|
|
|
if(afh = (struct AvailFontsHeader *)AllocVecTagList(afSize, NULL)) {
|
2012-05-04 23:30:30 +04:00
|
|
|
if(afShortage = AvailFonts(afh, afSize, AFF_DISK | AFF_OTAG | AFF_SCALED)) {
|
|
|
|
FreeVec(afh);
|
|
|
|
afSize += afShortage;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* out of memory, bail out */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} while (afShortage);
|
|
|
|
|
|
|
|
if(afh) {
|
|
|
|
af = (struct AvailFonts *)&(afh[1]);
|
2012-05-05 18:46:18 +04:00
|
|
|
|
2014-04-06 02:34:51 +04:00
|
|
|
for(int i = 0; i < afh->afh_NumEntries; i++) {
|
2012-05-05 18:46:18 +04:00
|
|
|
if(af[i].af_Attr.ta_Style == FS_NORMAL) {
|
2012-10-15 02:01:13 +04:00
|
|
|
if(af[i].af_Attr.ta_Name != NULL) {
|
|
|
|
node = (struct nsObject *)FindIName((struct List *)list,
|
|
|
|
af[i].af_Attr.ta_Name);
|
|
|
|
if(node == NULL) {
|
|
|
|
node = AddObject(list, AMINS_UNKNOWN);
|
|
|
|
if(node) {
|
|
|
|
node->dtz_Node.ln_Name = strdup(af[i].af_Attr.ta_Name);
|
|
|
|
found++;
|
2012-10-17 01:10:49 +04:00
|
|
|
LOG(("Added %s", af[i].af_Attr.ta_Name));
|
2012-10-15 02:01:13 +04:00
|
|
|
}
|
2012-05-05 18:46:18 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-04 23:30:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FreeVec(afh);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-05-05 18:46:18 +04:00
|
|
|
return found;
|
2012-05-04 23:30:30 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
/**
|
|
|
|
* Load a font glyph cache
|
|
|
|
*
|
|
|
|
* \param filename name of cache file to load
|
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers
|
|
|
|
* \return number of glyphs loaded
|
|
|
|
*/
|
|
|
|
ULONG ami_font_scan_load(const char *filename, lwc_string **glypharray)
|
2012-05-04 23:30:30 +04:00
|
|
|
{
|
2012-05-05 15:09:19 +04:00
|
|
|
ULONG found = 0;
|
|
|
|
BPTR fh = 0;
|
2012-05-05 18:46:18 +04:00
|
|
|
lwc_error lerror;
|
|
|
|
char buffer[256];
|
|
|
|
struct RDArgs *rargs = NULL;
|
|
|
|
STRPTR template = "CODE/A,FONT/A";
|
|
|
|
long rarray[] = {0,0};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
A_CODE = 0,
|
|
|
|
A_FONT
|
|
|
|
};
|
|
|
|
|
|
|
|
rargs = AllocDosObjectTags(DOS_RDARGS, TAG_DONE);
|
2012-05-04 23:30:30 +04:00
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
if(fh = FOpen(filename, MODE_OLDFILE, 0)) {
|
2012-05-05 23:09:42 +04:00
|
|
|
LOG(("Loading font glyph cache from %s", filename));
|
2012-05-05 18:46:18 +04:00
|
|
|
|
|
|
|
while(FGets(fh, (UBYTE *)&buffer, 256) != 0)
|
|
|
|
{
|
|
|
|
rargs->RDA_Source.CS_Buffer = (char *)&buffer;
|
|
|
|
rargs->RDA_Source.CS_Length = 256;
|
|
|
|
rargs->RDA_Source.CS_CurChr = 0;
|
|
|
|
|
|
|
|
rargs->RDA_DAList = NULL;
|
|
|
|
rargs->RDA_Buffer = NULL;
|
|
|
|
rargs->RDA_BufSiz = 0;
|
|
|
|
rargs->RDA_ExtHelp = NULL;
|
|
|
|
rargs->RDA_Flags = 0;
|
|
|
|
|
|
|
|
if(ReadArgs(template, rarray, rargs))
|
|
|
|
{
|
|
|
|
lerror = lwc_intern_string((const char *)rarray[A_FONT],
|
|
|
|
strlen((const char *)rarray[A_FONT]),
|
2012-05-05 19:58:17 +04:00
|
|
|
&glypharray[strtoul((const char *)rarray[A_CODE], NULL, 0)]);
|
2012-05-05 18:46:18 +04:00
|
|
|
if(lerror != lwc_error_ok) continue;
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
2012-05-05 15:09:19 +04:00
|
|
|
FClose(fh);
|
|
|
|
}
|
2012-05-04 23:30:30 +04:00
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
return found;
|
|
|
|
}
|
2012-05-04 23:30:30 +04:00
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
/**
|
|
|
|
* Save a font glyph cache
|
|
|
|
*
|
|
|
|
* \param filename name of cache file to save
|
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers
|
|
|
|
*/
|
|
|
|
void ami_font_scan_save(const char *filename, lwc_string **glypharray)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
BPTR fh = 0;
|
2012-05-04 23:30:30 +04:00
|
|
|
|
2012-05-05 15:09:19 +04:00
|
|
|
if(fh = FOpen(filename, MODE_NEWFILE, 0)) {
|
2012-05-05 23:09:42 +04:00
|
|
|
LOG(("Writing font glyph cache to %s", filename));
|
2012-05-05 19:58:17 +04:00
|
|
|
FPrintf(fh, "; This file is auto-generated. To re-create the cache, delete this file.\n");
|
2012-05-05 15:09:19 +04:00
|
|
|
FPrintf(fh, "; This file is parsed using ReadArgs() with the following template:\n");
|
|
|
|
FPrintf(fh, "; CODE/A,FONT/A\n;\n");
|
2012-05-04 23:30:30 +04:00
|
|
|
|
|
|
|
for(i=0x0000; i<=0xffff; i++)
|
|
|
|
{
|
|
|
|
if(glypharray[i]) {
|
2012-05-05 18:46:18 +04:00
|
|
|
FPrintf(fh, "0x%04lx \"%s\"\n", i, lwc_string_data(glypharray[i]));
|
2012-05-04 23:30:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FClose(fh);
|
|
|
|
}
|
2012-05-05 15:09:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalise the font glyph cache.
|
|
|
|
*
|
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers to free
|
|
|
|
*/
|
|
|
|
void ami_font_scan_fini(lwc_string **glypharray)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
for(i=0x0000; i<=0xffff; i++)
|
|
|
|
{
|
|
|
|
if(glypharray[i]) {
|
|
|
|
lwc_string_unref(glypharray[i]);
|
|
|
|
glypharray[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the font glyph cache.
|
|
|
|
* Reads an existing file or, if not present, generates a new cache.
|
|
|
|
*
|
|
|
|
* \param filename cache file to attempt to read
|
2012-05-05 23:09:42 +04:00
|
|
|
* \param entries number of entries in list
|
|
|
|
* \param force_scan force re-creation of cache
|
2012-05-05 15:09:19 +04:00
|
|
|
* \param glypharray an array of 0xffff lwc_string pointers
|
|
|
|
*/
|
2012-05-06 21:55:35 +04:00
|
|
|
void ami_font_scan_init(const char *filename, bool force_scan, bool save,
|
2012-05-05 23:09:42 +04:00
|
|
|
lwc_string **glypharray)
|
2012-05-05 15:09:19 +04:00
|
|
|
{
|
2012-05-05 23:09:42 +04:00
|
|
|
ULONG i, found = 0, entries = 0;
|
|
|
|
struct MinList *list;
|
|
|
|
struct nsObject *node;
|
2012-05-10 02:23:10 +04:00
|
|
|
char *unicode_font, *csv;
|
2012-05-06 21:55:35 +04:00
|
|
|
struct ami_font_scan_window *win = NULL;
|
2012-05-05 15:09:19 +04:00
|
|
|
|
|
|
|
/* Ensure array zeroed */
|
|
|
|
for(i=0x0000; i<=0xffff; i++)
|
|
|
|
glypharray[i] = NULL;
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
if(force_scan == false)
|
|
|
|
found = ami_font_scan_load(filename, glypharray);
|
2012-05-05 15:09:19 +04:00
|
|
|
|
|
|
|
if(found == 0) {
|
2012-05-05 23:09:42 +04:00
|
|
|
if(list = NewObjList()) {
|
|
|
|
|
2012-05-10 02:23:10 +04:00
|
|
|
/* add preferred fonts list */
|
2012-11-09 03:56:42 +04:00
|
|
|
if(nsoption_charp(font_unicode) &&
|
|
|
|
(csv = strdup(nsoption_charp(font_unicode))))
|
2012-05-10 02:23:10 +04:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while(p = strsep(&csv, ",")) {
|
|
|
|
asprintf(&unicode_font, "%s.font", p);
|
|
|
|
if(unicode_font != NULL) {
|
|
|
|
node = AddObject(list, AMINS_UNKNOWN);
|
|
|
|
if(node) node->dtz_Node.ln_Name = unicode_font;
|
|
|
|
entries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(csv);
|
|
|
|
}
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
if(nsoption_bool(font_unicode_only) == false)
|
|
|
|
entries += ami_font_scan_list(list);
|
|
|
|
|
2012-11-08 00:18:33 +04:00
|
|
|
LOG(("Found %ld fonts", entries));
|
2012-05-05 23:09:42 +04:00
|
|
|
|
2012-05-07 18:18:22 +04:00
|
|
|
win = ami_font_scan_gui_open(entries);
|
2012-05-06 21:55:35 +04:00
|
|
|
found = ami_font_scan_fonts(list, win, glypharray);
|
2012-05-07 18:18:22 +04:00
|
|
|
ami_font_scan_gui_close(win);
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
FreeObjList(list);
|
|
|
|
|
2012-05-06 21:55:35 +04:00
|
|
|
if(save == true)
|
|
|
|
ami_font_scan_save(filename, glypharray);
|
2012-05-05 23:09:42 +04:00
|
|
|
}
|
2012-05-05 15:09:19 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 23:09:42 +04:00
|
|
|
LOG(("Initialised with %ld glyphs", found));
|
2012-05-05 15:09:19 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 18:46:18 +04:00
|
|
|
|