[REBOL] Re: request-font
From: carl:cybercraft at: 19-Jan-2003 9:25
On 19-Jan-03, Anton wrote:
> Yep, I see now.
> Still, why not have an update button?
> Every good font requester has an option
> to get the currently installed fonts.
It did have to begin with. :) It also needed three scripts to begin
with, but it went through quite a few major changes and I took update
out somewhere along the way.
One possible reason not to include it is the permissions that are
required when updating. I don't like the idea of training people to
hit okay on permissions as a matter of course. Is this an unfounded
worry? Otherwise, there's no reason it can't be added. I had it as
an refinement before, so the button could be left off if not wanted.
Anyway, are any of you interested in doing the scripts for any of the
other platforms? Instructions are in the current get-fonts scripts,
but I'll repeat them here...
---<---
3) * How to write versions of the get-fonts script for other OSs *
All that's required of the script is that it extracts the font
names from those available on the OS and saves them to a file
called fonts-data.txt in the directory the script was run from.
The objects should be made as follows...
make object! [
name: "font name"
]
where "font name" is a string containing a font's name.
How you write the script is up to you, but it should not add
any words to the global context. One way to do this is to
hide the code in a function. For example...
do make function! [/local word1 word2 word3][
...
code using word1, word2 and word3
...
]
Note that the objects do not have to be sorted or checked
for duplicates as this is done by the request-font.r script.
The file-name of the script should reflect the OS it is
written for. ie, get-fonts-[OS-type].r. At the time of
writing (19-Oct-2002) two versions have been written for
the Windows and Amiga OSs. Their scripts are named
get-fonts-windows.r and get-fonts-amiga.r.
Check the list here...
http://www.rebol.com/view-platforms.html
for the OSs that still need a get-fonts-[OS-type].r script
written for them...
---8<---
And, as extracting the font-names for Amiga proved very simple and
didn't require much code, here's that code as an example...
; Enclose code in function to prevent
; words being added to global context
;-------------------------------------
do make function! [/local names file][
; file-path to save block of fonts data to
;------------------------------------------
file: join what-dir %fonts-data.txt
; Get contents of Amiga font directory
;--------------------------------------
if error? try [names: read %/fonts/.][
print "Error attempting to read Amiga fonts: directory!"
halt
]
; Change file-names with a .font extension into an object
; and remove all other file and directory names from the block
;--------------------------------------------------------------
forall names [
either all [file? names/1 %.font = skip tail names/1 -5][
names/1: make object! [
name: to-string copy/part names/1 (length? names/1) - 5
]
][
remove names names: back names
]
]
; Save block of fonts-data objects
;----------------------------------
if error? try [save file head names][
print "Error attempting to save block of Amiga fonts data"
print ["to:" file]
halt
]
]
Gregg's Windows' version extracts TrueType font-names from the fonts
themselves (I believe), should you need an example of how to do that.
--
Carl Read