Aros/開發者/文件/庫/DiskFont
AROS 可以使用兩種不同的字型以及其他字型型別,例如更常見的 TrueType 字型(AROS 使用 FreeType 等效字型),您需要使用另一個庫
字型基本上是字形(字母形狀)、樣式(粗體、普通、斜體)和大小(以字型大小為單位)的混合體。AROS 內建了一個名為 Topaz 的字型,可以隨時訪問。如果使用基於磁碟的字型,則需要使用 diskfont.library 從磁碟載入字型。
自定義格式的位平面資料,以及每個字元的水平偏移量和左右側寬度的元資料。載入器位於 Diskfont.library 中,名為 OpenDiskFont()。載入後,點陣圖字型由 OpenFont() 處理
Wanderer 使用 NULL 字型呼叫 IconList,因為 diskfont.library 無法開啟“arial.font”。另一方面,這是因為 diskfont.library 無法在 FONTS: 中找到 arial.font,因為 ExAll 呼叫在其第一次呼叫時返回 0 (== 完成)。這意味著並非所有字型都被返回,因為傳遞的 1024 位元組緩衝區太小,無法一次性獲取所有字型。
載入磁碟字型
要載入磁碟字型,請使用 OpenDiskFont() 函式。您需要指定一個 TextAttr 結構來指定您需要的字型,命令的格式是
TextFont font = OpenDiskFont(struct TextAttr textAttr)
TextAttr 的格式是
struct TextAttr {
STRPTR ta_Name; /* name of the font */
UWORD ta_YSize; /* height of the font */
UBYTE ta_Style; /* intrinsic font style */
UBYTE ta_Flags; /* font preferences and flags */
};
例如,要指定 Topaz 字型,大小為 11,粗體和斜體
struct TextAttr myta = {
"topaz.font"
11,
FSF_ITALIC | FSF_BOLD,
NULL
};
如果您使用此字型進行繪圖,可以使用 SetFont() 命令更改預設 Rastport 字型,並在使用完後使用 CloseFont() 函式:例如
struct TextFont *myfont, *oldfont;
struct RastPort *myrp;
struct Window *mywin;
if (myfont = OpenDiskFont(&myta))
{
/* you would probably set the font of the rastport you are going to use */
myrp = mywin->RPort
oldfont = myrp->Font;
SetFont(myrp, myfont);
/* perform whatever drawing you need to do */
/* time to clean up. If the rastport is not exclusively yours,
you may need to restore the original font or other Rasport values */
SetFont(myrp, oldfont);
CloseFont(myfont);
}
如果您想在嘗試從磁碟載入字型之前知道程式中有哪些可用字型,可以使用 AvailFonts() 函式,該函式可以讀取記憶體和磁碟中的所有字型,並將它們顯示在 AvailFontsHeader 結構中,隨後是一系列 AvailFonts 結構,供您的程式讀取。在呼叫此函式之前,您需要分配一些記憶體來儲存字型資訊。
LONG error = AvailFonts(struct AvailFontsHeader *buffer, LONG bufBytes, ULONG flags )
例如,
int afShortage, afSize;
struct AvailFontsHeader *afh;
afSize = 400;
do {
afh = (struct AvailFontsHeader *) AllocMem(afSize, 0);
if (afh) {
afShortage = AvailFonts(afh, afSize, AFF_MEMORY|AFF_DISK);
if (afShortage) {
FreeMem(afh, afSize);
afSize += afShortage;
}
}
else {
fail("AllocMem of AvailFonts buffer afh failedn");
break;
}
}while (afShortage);
對於 FontContents(或 TFontContents)結構中描述的每個字型大小,該字型的目錄中都存在一個相應的檔案,其名稱為其大小。例如,對於字型大小 Sapphire-19,Sapphire 目錄中有一個名為 19 的檔案。該檔案基本上是一個 DiskFontHeader,偽裝成一個可載入的 DOS 段,被稱為字型描述符檔案。
對於點陣圖字型,“.font” 檔案是一個 FontContentsHeader 結構
struct FontContentsHeader {
UWORD fch_FileID; /* FCH_ID */
UWORD fch_NumEntries; /* the number of FontContents elements */
struct FontContents fch_FC[]; /* or struct TFontContents fch_TFC[]; */
};
#define MAXFONTPATH 256
其中 fch_FileID 欄位可以是
FCH_ID 0x0f00 uses FontContents structures to describe the available sizes of this font.
TFCH_ID 0x0f02 uses TFontContents structures to describe the available sizes of this font.
FontContents 結構
struct FontContents {
char fc_FileName[MAXFONTPATH];
UWORD fc_YSize;
UBYTE fc_Style;
UBYTE fc_Flags;
};
struct TFontContents {
char tfc_FileName[MAXFONTPATH-2];
UWORD tfc_TagCount; /* including the TAG_DONE tag */
/*
* if tfc_TagCount is non-zero, tfc_FileName is overlaid with
* Text Tags starting at: (struct TagItem *)
* &tfc_FileName[MAXFONTPATH-(tfc_TagCount*sizeof
* (struct TagItem))]
*/
UWORD tfc_YSize;
UBYTE tfc_Style;
UBYTE tfc_Flags;
};
struct DiskFontHeader {
ULONG dfh_NextSegment;
ULONG dfh_ReturnCode;
STRUCT dfh,LN_SIZE;
UWORD dfh_FileID;
UWORD dfh_Revision;
LONG dfh_Segment;
STRUCT dfh,MAXFONTNAME;
STRUCT dfh-TF,tf_SIZEOF;
};
有人知道使用什麼程式生成 ttcourier 字型嗎?它們由 Georg 在 2001 年提交。
據我所知,BitLine(參見 Aminet,附帶原始碼)。使用 diskfont.library 將字型載入到記憶體中,然後將其儲存到磁碟。源字型是 TrueType 字型,diskfont.library 在載入時將其轉換為點陣圖字型(如果有像基於 freetype 的字型引擎,可以處理它)。
這些字型存在一個小問題:字形都與它們框的左側對齊,而不是居中(這是紙張切割錯誤之一)。
快速檢視 ttcourier 字型(使用 sys:tools/fontinfo 和 sys:extras/misc/aminet/ 中的點陣圖字型編輯器“TypeFace”)。似乎只有某些大小(例如 14)存在問題,問題是缺少/為零的字距/間距表。
同樣檢視工作臺/fonts/ 中字型檔案(“14”等)的 svn 日誌,似乎問題可能是當歐元字元被(手動)新增到字型中時發生的(據我所知,使用在 AROS 下執行的 TypeFace 字型編輯器 -> 可能那裡存在一個錯誤),因為我對“14”檔案的初始修訂版進行了快速測試,它似乎沒有缺少字距/間距表。
請注意,根據樣式和其他因素,字型並不總是使用相同的 HIDD 方法渲染。參見 rom/graphics/text.c。截圖中不可見的文字是使用 BlitColorexpansion 方法渲染的文字。
#include <diskfont/diskfont.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/diskfont.h>
#include <proto/utility.h>
#include <proto/graphics.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
struct Library *DiskfontBase;
struct UtilityBase *UtilityBase;
UBYTE *buf;
void cleanup(char *msg)
{
if (msg) printf("aftest: %s\n", msg);
if (buf) FreeVec(buf);
if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
if (DiskfontBase) CloseLibrary(DiskfontBase);
exit(0);
}
void openlibs(void)
{
DiskfontBase = OpenLibrary("diskfont.library", 0);
if (!DiskfontBase) cleanup("Cant open diskfont.library!");
UtilityBase = (struct UtilityBase *) OpenLibrary("utility.library", 0);
if (!UtilityBase) cleanup("Cant open utility.library!");
}
void action(void)
{
struct TextFont *font;
struct TextAttr ta;
ta.ta_Name = "Vera Sans Bold Italic.font";
ta.ta_Name = "xhelvetica.font";
ta.ta_YSize = 11;
ta.ta_Style = 0;
ta.ta_Flags = 0;
font = OpenDiskFont(&ta);
if (font)
{
CloseFont(font);
}
}
int main(void)
{
openlibs();
action();
cleanup(0);
return 0; /* keep compiler happy */
}
struct TextFont *OpenDiskFont(struct TextAttr *textAttr) LONG AvailFonts(STRPTR buffer, LONG bufBytes, LONG flags) AFF_MEMORY AFF_DISK AFF_SCALED AFF_TAGGED struct FontContentsHeader *NewFontContents(BPTR fontsLock, STRPTR fontName) struct DiskFont *NewScaledDiskFont(struct TextFont *sourceFont, struct TextAttr *destTextAttr) void DisposeFontContents(struct FontContentsHeader *fontContentsHeader)