request-font
[1/21] from: carl::cybercraft::co::nz at: 18-Jan-2003 15:18
Hi List,
The font requester and related scripts that Gregg Irwin and I have
been slowly working on have reached beta stage and have been added to
the reboltech library.
The idea is that you have two scripts:
One that's specifically for your OS and which creates a text-file of
the font-names on your system. This only needs to be run once.
(Though running it again would be necessary to keep the text-file
up-to-date when the fonts on your system are changed.)
And another that creates the request-font function and loads the
font-names data. (Having this script launched from your user.r is the
obvious way to run it.)
The above would then make the request-font function available to all
the View scripts you ran.
Well, that's the short version anyway. This is the longer one...
To test this, you'll need to get the two scripts (see below) - the
request-font.r script and the get-fonts-[OS-type].r script that
matches your OS. (Only available for Windows and Amiga so far - it's
your job, List, should you choose to accept it, to write the scripts
for the other OSs View supports;)
These two scripts should be downloaded and placed in the same
directory, (I'd suggest making one called fonts or similar in your
View home directory), as request-font.r needs to find the text-file
(called fonts-data.txt) that the get-fonts[OS-type].r script creates.
(Now read the scripts' headers, just in case I'm forgetting something
here...)
After doing the above, first run the get-fonts[OS-type].r script.
This saves in the fonts-data.txt file a list of objects containing
font data. (Just the fonts' names at the moment, but they're stored
in objects in case other data needs to be added in the future.) Note
that as these scripts are seeking information about the fonts on your
system you'll probably get requests to access files outside your View
directory. Say yes to this if you trust these scripts...
If all goes well you can then run request-font.r. Do this from the
View console as the script creates the request-font function which
you'll then be able to test.
And this is where the scripts are...
http://www.reboltech.com/library/scripts/request-font.r
http://www.reboltech.com/library/scripts/get-fonts-windows.r
http://www.reboltech.com/library/scripts/get-fonts-amiga.r
Gregg wrote the get-fonts-windows.r script and I the other two.
Thanks must also go to Phil Bevan for some useful bug-spotting. Plus
this is the post that got this under way...
http://www.escribe.com/internet/rebol/m25079.html
(a very long time ago, Gregg;)
Now some questions:
I make no great claims for the code or interface in font-request, but
I'd like to know if I've chosen a good set of refinements for it and
if the defaults are sensible ones. Getting those right from the
start will make writing alternatives less of a hassle. This is what
I decided on...
>> ? request-font
USAGE:
REQUEST-FONT /title title-line /name font-name /style font-style
/size font-size /color font-color /font font-obj /text string
/effects /keep /multi
DESCRIPTION:
Requests a font-name and optional settings. Returns a
font-object. If more than one font is selected the objects
name will contain a block of names. With /style, /size and
/color, 'keep may be given to keep the previous settings. This
allows you to place the style, size and color fields in the
requester without forcing them to have a specific value.
REQUEST-FONT is a function value.
REFINEMENTS:
/title -- Change heading on request.
title-line -- Title line of request. (Type: string)
/name
font-name -- Font name. Default is font-sans-serif. (Type:
string block)
/style
font-style -- (Type: word block none)
/size
font-size -- (Type: integer none)
/color
font-color -- (Type: tuple word)
/font
font-obj -- Supply a font object. (Type: object)
/text
string -- Supply example text. (Type: string)
/effects -- Allow editing of offset, space, align, valign, shadow
and colors.
/keep -- Keep previous settings and results.
/multi -- Allow more than one font name to be selected.
I thought about having an update button in the requester, (that'd run
get-fonts[OS-type].r), but decided against it in the end, though I'm
still in two minds whether it should be in or not.
We've also thought about having an installer for this too. A good
idea or not, in that it'd mean request-font.r would have to be
included with each OS-specific script, making updating it a bit of a
pain.
And that's it for now. (Be much easier if RT would just add a
font-requester to View of course, but they haven't yet, so...:)
--
Carl Read
[2/21] from: atruter:labyrinth:au at: 18-Jan-2003 14:20
Looks good, well done. The refinements seem not only complete, but
consistent.
I know it's only Beta, but a few other (non-refinement) feedback comments
for you.
1) get-fonts-windows.r works under Win2000 if you change font-dir to
%//winnt/fonts/
, don't know about XP though. Perhaps a series of paths
(under windows) could be searched, or some other way of determining which
flavour of Windows is being run?
2) The request-font dialog needs its text area display increased to
accommodate the largest common/practical font size: 72pt.
3) Pressing "Select" exits the dialog but does not appear to return the
selection?
Looking forward to 1.0.0! ;)
Regards,
Ashley
[3/21] from: carl:cybercraft at: 18-Jan-2003 18:05
On 18-Jan-03, Ashley Truter wrote:
> Looks good, well done. The refinements seem not only complete, but
> consistent.
Thanks.
> I know it's only Beta, but a few other (non-refinement) feedback
> comments for you.
> 1) get-fonts-windows.r works under Win2000 if you change font-dir to
> "%//winnt/fonts/", don't know about XP though. Perhaps a series of
> paths (under windows) could be searched, or some other way of
> determining which flavour of Windows is being run?
Gregg's department. Gregg?
> 2) The request-font dialog needs its text area display increased to
> accommodate the largest common/practical font size: 72pt.
Okay, though it'd be better to make it a resizable window I think. I
didn't try to get too clever with the GUI in the hope we'll have
richer styles to work with sometime soon.
> 3) Pressing "Select" exits the dialog but does not appear to return
> the selection?
It's returning an object. Try...
probe request-font
> Looking forward to 1.0.0! ;)
Oh? I'm looking forward to the Linux support myself. ;-)
--
Carl Read
[4/21] from: greggirwin:mindspring at: 17-Jan-2003 23:28
Hi Ashley,
AT> 1) get-fonts-windows.r works under Win2000 if you change font-dir to
AT> "%//winnt/fonts/", don't know about XP though. Perhaps a series of paths
AT> (under windows) could be searched, or some other way of determining which
AT> flavour of Windows is being run?
I thought about that. What path for XP folks?
-- Gregg
[5/21] from: ammon:addept:ws at: 18-Jan-2003 0:53
windows/fonts
Enjoy!!
Ammon Johnson
CIO of Addept ---------- (www.addept.ws)
435.616.2322 ---------- (ammon AT addept.ws)
[6/21] from: anton:lexicon at: 18-Jan-2003 19:22
Sounds like good work.
Why not have a button in the font-request window
which updates the fonts by running the appropriate
get-fonts-xxx.r file. No need for the user to
worry about which file to download and run.
It can be automatic.
Anton.
[7/21] from: carl:cybercraft at: 18-Jan-2003 22:46
On 18-Jan-03, Anton wrote:
> Sounds like good work.
> Why not have a button in the font-request window
<<quoted lines omitted: 3>>
> It can be automatic.
> Anton.
See what I'd said at the end. ;)
One reason not to include it was that font-request is cross-platform,
but as currently written the get-font scripts have OS-specific
file-names. Some method of determining which script to run based on
View's version number could be worked out though, I'm sure. The
get-fonts scripts might then need to be named get-fonts.3.1.r for
Windows and so on.
Carl.
>> Hi List,
>> The font requester and related scripts that Gregg Irwin and I have
<<quoted lines omitted: 97>>
>> [rebol-request--rebol--com] with "unsubscribe" in the
>> subject, without the quotes.
--
Carl Read
[8/21] from: anton:lexicon at: 18-Jan-2003 22:52
Yep, I see now.
Still, why not have an update button?
Every good font requester has an option
to get the currently installed fonts.
Anton.
[9/21] from: greggirwin:mindspring at: 18-Jan-2003 12:09
Hi Anton,
We could keep the OS-specific names for download, but allow people to
rename them on their local system. The requestor would look for
get-fonts.r (as a standard name) and display an update button if it
exists. Just rename the file to what request-font is looking for and
go from there.
-- Gregg
[10/21] from: carl:cybercraft at: 19-Jan-2003 9:34
On 19-Jan-03, Gregg Irwin wrote:
> Hi Anton,
> We could keep the OS-specific names for download, but allow people
> to rename them on their local system. The requestor would look for
> get-fonts.r (as a standard name) and display an update button if it
> exists. Just rename the file to what request-font is looking for and
> go from there.
I'd thought of that, but by having them have different version numbers
(as I suggested) you can have more than one get-fonts version in the
same directory. I've Windows and Linux on my PC, but my View
directory is the same for both of them, it being in the Window's
partition.
--
Carl Read
[11/21] 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
[12/21] from: anton:lexicon at: 20-Jan-2003 1:04
Carl,
Yes, that worry is unfounded.
Your script will be so well known and
documented that people will trust you. :)
If they don't, they can read the code.
Come on, there's lots of code you run
without reading the code, admit it.
If you don't have some level of trust
you would never get anything done.
I don't like training people to rename
and locate files in the filesystem if
it can be so easily avoided.
So I too would favour a different filename
per platform.
Anton.
[13/21] from: carl:cybercraft at: 20-Jan-2003 19:47
On 20-Jan-03, Anton wrote:
> Carl,
> Yes, that worry is unfounded.
> Your script will be so well known and
> documented that people will trust you. :)
Oh, of course - silly me. ;)
But a font-requester is used by other programs, and while the
requester that's put up may look like my one, it may not be.
> If they don't, they can read the code.
No use if you're not a REBOL programmer.
> Come on, there's lots of code you run
> without reading the code, admit it.
Of course, but it's in a sandbox, remember. Clicking OK at the
permission request takes you out of that safty-zone.
> If you don't have some level of trust
> you would never get anything done.
Sure, but we don't want to get to the point with REBOL where we're
asked for permission so often that we end up clicking on OK as a
reflex action.
I think a better way than an update button on the requester would be
to have it as a choice on the View Desktop. (ie, as a service.)
Apart from being safer, this would better indicate that it's a
REBOL-wide change we're making, whereas in the requester it might
suggest it's just for a specific application. If this is the
approach taken though, the requester will need a Reload button.
> I don't like training people to rename
> and locate files in the filesystem if
> it can be so easily avoided.
> So I too would favour a different filename
> per platform.
I think REBOL's OS version numbers are the way to go.
> Anton.
>>> Still, why not have an update button?
<<quoted lines omitted: 9>>
>> wanted.
>> Carl Read
--
Carl Read
[14/21] from: carl:cybercraft at: 20-Jan-2003 18:37
On 19-Jan-03, Carl Read wrote:
> On 19-Jan-03, Gregg Irwin wrote:
>> Hi Anton,
<<quoted lines omitted: 8>>
> my View directory is the same for both of them, it being in the
> Window's partition.
I've just realised this wouldn't work with the current get-fonts and
request-fonts as the fonts-data.txt file would be holding font names
for a particular OS. So, fonts-data.txt will need an OS-name (or
number) in its file-name too...
--
Carl Read
[15/21] from: anton:lexicon at: 20-Jan-2003 23:17
Carl, you definitely worry too much.
Scanning the fonts directory of the system
is inevitable for this application.
Asking for permission to read/write a system
directory is unavoidable.
For now, don't assume that RT will incorporate
get-fonts into the view desktop.
Just get it going for now and worry about incorporation
later. (It's a good idea, but it will slow you
down a bit if you depend on them absorbing your code.)
Anyway, I'll leave you to it.
I'll more likely use it if it has that feature,
that's all.
Anton.
> On 20-Jan-03, Anton wrote:
> > Carl,
<<quoted lines omitted: 27>>
> > per platform.
> I think REBOL's OS version numbers are the way to go.
I agree here.
[16/21] from: carl:cybercraft at: 21-Jan-2003 8:50
On 21-Jan-03, Anton wrote:
> Carl, you definitely worry too much.
Probably. :) No, I'm thinking about what's the best way for people to
use View.
> Scanning the fonts directory of the system
> is inevitable for this application.
> Asking for permission to read/write a system
> directory is unavoidable.
I know all this. But there's alternatives to having the update button
in the requester.
> For now, don't assume that RT will incorporate
> get-fonts into the view desktop.
I'm not. I'm assuming they'll eventully get around to doing it
themselves. This is just something to get us by till they do.
> Just get it going for now and worry about incorporation
> later. (It's a good idea, but it will slow you
> down a bit if you depend on them absorbing your code.)
It doesn't need RT to do it - assuming we bundle it in an installer
script, that script could add it to the View Desktop as a service.
> Anyway, I'll leave you to it.
> I'll more likely use it if it has that feature,
> that's all.
What do others think?
--
Carl Read
[17/21] from: greggirwin:mindspring at: 21-Jan-2003 10:56
Hi Carl,
>> Anyway, I'll leave you to it.
>> I'll more likely use it if it has that feature,
>> that's all.
CR> What do others think?
I don't know how biased I am, but I don't think other font requestors
have an update button, and I don't think it's a good place for it. How
often do fonts change on your system? Not very in my case. I don't
know what the best solution is, to avoid the security popup but an
automatic system would be best. My second choice would be a utility
(as it is today) that you run to update the list, but not from the
requestor itself I think.
-- Gregg
[18/21] from: atruter:labyrinth:au at: 22-Jan-2003 12:02
> What do others think?
I would prefer the get-fonts script to be run once upon installation (as I
know what I am running at that point) and not have to worry about it again.
In the rare event I update my fonts, I'll manually run get-fonts again.
If fonts are updated regularly, you could do what ref-words does and prompt
for a "rebuild" after a certain amount of [user configurable?] time has
elapsed.
Regards,
Ashley
[19/21] from: ammon:addept:ws at: 21-Jan-2003 20:22
I personally do a considerable amount of Graphics Design and my fonts change
often. Now, why I would want all of those fonts in REBOL, I have no clue,
but...
-- Enjoy!!
Ammon Johnson
CIO of Addept ------ (435.616.2322)
(www.addept.ws) ---- (ammonATaddeptDOTws)
On 01/21/2003 06:02 pm, you wrote:
[20/21] from: anton:lexicon at: 22-Jan-2003 15:45
Exactly. Most font-requesters don't have
an update button because they perform
the update automatically when the window
is opened.
I think since we are causing a security
popup we should have the separate function
triggered by a separate update button.
Anton.
[21/21] from: carl:cybercraft at: 22-Jan-2003 18:17
On 22-Jan-03, Ammon Johnson wrote:
> I personally do a considerable amount of Graphics Design and my
> fonts change often. Now, why I would want all of those fonts in
> REBOL, I have no clue, but...
I think you've been out-voted Ammon. ;)
But anyway, there's a solution that will please everyone, (I hope),
and that is to allow an argument to be added to the request-font.r
script that adds an Update button to the requester. Thus there would
be no update button with...
do %request-font.r
but one would be there with...
do/args 'get-fonts-button
When if doubt, give the user the choice...
--
Carl Read
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted